Skip to content

Commit 9e1c595

Browse files
chessbyteNickLaMuro
authored andcommitted
Merge pull request #510 from Fryguy/remove_runcmd
Remove MiqUtil.runcmd in favor of AwesomeSpawn (transferred from ManageIQ/manageiq-gems-pending@6e65e82)
2 parents 3d6df4b + 2b6b9f0 commit 9e1c595

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

lib/manageiq/appliance_console/postgres_admin.rb

+15-11
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def self.logical_volume_path
7171
end
7272

7373
def self.database_size(opts)
74-
result = runcmd("psql", opts, :command => "SELECT pg_database_size('#{opts[:dbname]}');")
74+
result = run_command("psql", opts, :command => "SELECT pg_database_size('#{opts[:dbname]}');")
7575
result.match(/^\s+([0-9]+)\n/)[1].to_i
7676
end
7777

@@ -140,7 +140,7 @@ def self.backup_pg_dump(opts)
140140
args = combine_command_args(opts, :format => "c", :file => opts[:local_file], nil => dbname)
141141
args = handle_multi_value_pg_dump_args!(opts, args)
142142

143-
runcmd_with_logging("pg_dump", opts, args)
143+
run_command_with_logging("pg_dump", opts, args)
144144
opts[:local_file]
145145
end
146146

@@ -177,9 +177,8 @@ def self.backup_pg_compress(opts)
177177
def self.recreate_db(opts)
178178
dbname = opts[:dbname]
179179
opts = opts.merge(:dbname => 'postgres')
180-
runcmd("psql", opts, :command => "DROP DATABASE IF EXISTS #{dbname}")
181-
runcmd("psql", opts,
182-
:command => "CREATE DATABASE #{dbname} WITH OWNER = #{opts[:username] || 'root'} ENCODING = 'UTF8'")
180+
run_command("psql", opts, :command => "DROP DATABASE IF EXISTS #{dbname}")
181+
run_command("psql", opts, :command => "CREATE DATABASE #{dbname} WITH OWNER = #{opts[:username] || 'root'} ENCODING = 'UTF8'")
183182
end
184183

185184
def self.restore_pg_dump(opts)
@@ -199,7 +198,7 @@ def self.restore_pg_dump(opts)
199198
handle_error(cmd, process_status.exitstatus, error_path)
200199
else
201200
args[nil] = opts[:local_file]
202-
runcmd("pg_restore", opts, args)
201+
run_command("pg_restore", opts, args)
203202
end
204203
opts[:local_file]
205204
end
@@ -245,24 +244,29 @@ def self.vacuum(opts)
245244
args[:full] = nil if opts[:full]
246245
args[:verbose] = nil if opts[:verbose]
247246
args[:table] = opts[:table] if opts[:table]
248-
runcmd("vacuumdb", opts, args)
247+
run_command("vacuumdb", opts, args)
249248
end
250249

251250
def self.reindex(opts)
252251
args = {}
253252
args[:table] = opts[:table] if opts[:table]
254-
runcmd("reindexdb", opts, args)
253+
run_command("reindexdb", opts, args)
255254
end
256255

257-
def self.runcmd(cmd_str, opts, args)
258-
runcmd_with_logging(cmd_str, opts, combine_command_args(opts, args))
256+
def self.run_command(cmd_str, opts, args)
257+
run_command_with_logging(cmd_str, opts, combine_command_args(opts, args))
259258
end
260259

261-
def self.runcmd_with_logging(cmd_str, opts, params = {})
260+
def self.run_command_with_logging(cmd_str, opts, params = {})
262261
$log.info("MIQ(#{name}.#{__method__}) Running command... #{AwesomeSpawn.build_command_line(cmd_str, params)}")
263262
AwesomeSpawn.run!(cmd_str, :params => params, :env => pg_env(opts)).output
264263
end
265264

265+
class << self
266+
# Temporary alias due to manageiq core stubbing this method
267+
alias runcmd_with_logging run_command_with_logging
268+
end
269+
266270
private_class_method def self.combine_command_args(opts, args)
267271
default_args = {:no_password => nil}
268272
default_args[:dbname] = opts[:dbname] if opts[:dbname]

spec/postgres_admin_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
end
123123

124124
before do
125-
expect(subject).to receive(:runcmd_with_logging).with("pg_dump", expected_opts, expected_args)
125+
expect(subject).to receive(:run_command_with_logging).with("pg_dump", expected_opts, expected_args)
126126
end
127127

128128
context "with empty args" do

0 commit comments

Comments
 (0)