-
Notifications
You must be signed in to change notification settings - Fork 897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tool to replicate server settings to other servers #15990
Conversation
f794daf
to
e48ebdf
Compare
0fdaf0e
to
83b4720
Compare
@bronaghs @gtanzillo can you help review this? thanks |
tools/replicate_server_settings.rb
Outdated
target_settings = target.get_config("vmdb") | ||
target_settings.config.store_path(*path, values) | ||
|
||
valid, errors = VMDB::Config::Validator.new(settings).validate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jameswnl - should this read:
VMDB::Config::Validator.new(target_settings).validate
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for spotting it! Done now.
Just one question inline @jameswnl |
e507072
to
08663ca
Compare
@miq-bot remove_label wip |
tools/replicate_server_settings.rb
Outdated
server = opts[:serverid] ? MiqServer.find(opts[:serverid]) : MiqServer.my_server | ||
settings = server.get_config("vmdb") | ||
|
||
config = settings.config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the better way to do this would be server.settings_for_resource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
tools/replicate_server_settings.rb
Outdated
target_servers.each do |target| | ||
puts " - replicating to server id=#{target.id}..." | ||
target_settings = target.get_config("vmdb") | ||
target_settings.config.store_path(*path, values) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar thing here, I think you can make use of target.add_settings_for_resource
directly rather than going through the set_config
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Done
tools/replicate_server_settings.rb
Outdated
target_settings = target.get_config("vmdb") | ||
target_settings.config.store_path(*path, values) | ||
|
||
valid, errors = VMDB::Config::Validator.new(target_settings).validate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need to do this, add_settings_for_resource
calls Vmdb::Settings.save!
which does validation for you, plus I don't see invalid config being much of an issue as the settings you're saving have already been saved for a different server 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great! Done
tools/replicate_server_settings.rb
Outdated
|
||
opts = Trollop.options(ARGV) do | ||
banner "USAGE: #{__FILE__} -s <server id> -p <settings path separated by a /> \n" \ | ||
"Example: #{__FILE__} -d -s 1 -p ems/ems_amazon/additiona_instance_types" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo, missing the l
in "additional"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
tools/replicate_server_settings.rb
Outdated
require 'trollop' | ||
|
||
opts = Trollop.options(ARGV) do | ||
banner "USAGE: #{__FILE__} -s <server id> -p <settings path separated by a /> \n" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like something like path/to/the/settings
might be more clear? Especially because />
looks like some kind of closing tag, so it might get ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
08663ca
to
5caa5dc
Compare
5caa5dc
to
6e7206b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we put these methods into a class so that we can write specs for them?
We do this for other high impact tools such as fix_auth and column_ordering.
tools/replicate_server_settings.rb
Outdated
|
||
def construct_setting_tree(path, values) | ||
# construct the partial tree containing the target values | ||
path.reverse.inject(values) { |m, e| {e => m} } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the meanings of m
and e
here? Merged and element? I feel like names would help this to be more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
tools/replicate_server_settings.rb
Outdated
target_servers.each do |target| | ||
puts " - replicating to server id=#{target.id}..." | ||
target.add_settings_for_resource(target_settings) | ||
target.save! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need to save target
here. We are not actually changing anything on that object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good! done
tools/replicate_server_settings.rb
Outdated
puts opts.inspect | ||
Trollop.die :path, "is required" unless opts[:path_given] | ||
|
||
def replicate(opts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be better not using an options hash.
Then you could collapse the first line into a default value:
def replicate(path_string, dry_run, server = MiqServer.my_server)
...
end
Clearly the caller of replicate
would have to change also (to look up the server if given an id, but I don't think that's so bad. Or you could put the "find the source server" logic outside of the replicate method entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
7971b89
to
7af94f6
Compare
Checked commits jameswnl/manageiq@6e7206b~...7af94f6 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
describe "#replicate" do | ||
it "targets only other servers" do | ||
miq_server.add_settings_for_resource(settings) | ||
expect(described_class).to receive(:copy_to).with([miq_server_remote], settings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason that we can't actually check that the setting was saved for the other server here?
Why stub out the call to .copy_to
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wanna check the arguments being passed to it.
I was thinking do we need to check the outcome of add_settings_for_resource
(in copy_to
)? It should be covered by the configuration management aspect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but you're not actually testing that the settings were saved. I'm okay with this either way, I just lean towards not stubbing things if I don't have to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the logic here is, copy_to is simple enough and add_settings_for_resource
is already tested...
I'm okay, with this as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, that's the thinking
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually wrote my feedback for your followup PR before seeing this. I agree, I think the mock here is hiding a larger issue with your class interface and test boundaries: #16023 (review)
@carbonin thanks for the review! |
Just waiting on coveralls ... |
Coveralls is taking too long. |
settings = construct_setting_tree(path, server.settings_for_resource.fetch_path(path).to_h) | ||
|
||
puts "Replicating from server id=#{server.id}, path=#{path_string} to #{target_servers.count} servers" | ||
puts "Settings: #{settings}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch! This was started as a simple tool script that no spec was intended and it outgrew...
I have another PR to silent them coming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR is #16023
@bronaghs this should be portable. |
@simaishi - If we are backporting the first part of the pivotal story (see description above and PR ManageIQ/manageiq-providers-amazon#289) I think we should also backport this PR too Fine BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1557025 |
Tool to replicate server settings to other servers (cherry picked from commit a215bb7) https://bugzilla.redhat.com/show_bug.cgi?id=1557025
Fine backport details:
|
Tool to replicate server settings to other servers (cherry picked from commit a215bb7) https://bugzilla.redhat.com/show_bug.cgi?id=1557025
This is the second part of the pivotal story