Skip to content

Commit

Permalink
Changed get_file method to receive a resource as parameter.
Browse files Browse the repository at this point in the history
This change returns settings for passed in resource region/zone/server.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1536524
  • Loading branch information
h-kataria committed May 11, 2018
1 parent 85b25a1 commit 5e943a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/vmdb/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def save(resource = MiqServer.my_server)
end

# NOTE: Used by Configuration -> Advanced
def self.get_file
Vmdb::Settings.encrypt_passwords!(::Settings.to_hash).to_yaml
def self.get_file(resource = MiqServer.my_server)
Vmdb::Settings.encrypt_passwords!(resource.settings_for_resource.to_hash).to_yaml
end

# NOTE: Used by Configuration -> Advanced
Expand Down
22 changes: 17 additions & 5 deletions spec/lib/vmdb/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@
let(:password) { "pa$$w0rd" }
let(:enc_pass) { MiqPassword.encrypt(password) }

it ".get_file" do
stub_settings(:http_proxy => {:default => {:host => "proxy.example.com", :user => "user", :password => password, :port => 80}})
describe ".get_file" do
it "for current server" do
EvmSpecHelper.local_guid_miq_server_zone
stub_settings(:http_proxy => {:default => {:host => "proxy.example.com", :user => "user", :password => password, :port => 80}})

expect(VMDB::Config.get_file).to eq(
"---\n:http_proxy:\n :default:\n :host: proxy.example.com\n :user: user\n :password: #{enc_pass}\n :port: 80\n"
)
expect(VMDB::Config.get_file).to eq(
"---\n:http_proxy:\n :default:\n :host: proxy.example.com\n :user: user\n :password: #{enc_pass}\n :port: 80\n"
)
end

it "for specified resource" do
resource = FactoryGirl.create(:miq_server)
stub_settings(:http_proxy => {:default => {:host => "proxy.example.com", :user => "user", :password => password, :port => 80}})

expect(VMDB::Config.get_file(resource)).to eq(
"---\n:http_proxy:\n :default:\n :host: proxy.example.com\n :user: user\n :password: #{enc_pass}\n :port: 80\n"
)
end
end

context ".save_file" do
Expand Down

0 comments on commit 5e943a4

Please sign in to comment.