Skip to content
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

Merged
merged 2 commits into from
Sep 20, 2017

Conversation

jameswnl
Copy link
Contributor

@jameswnl jameswnl commented Sep 18, 2017

This is the second part of the pivotal story

@miq-bot miq-bot added the wip label Sep 18, 2017
@jameswnl jameswnl force-pushed the rep-server-settings branch 2 times, most recently from 0fdaf0e to 83b4720 Compare September 19, 2017 01:02
@chessbyte chessbyte changed the title [WIP]Tool to replicate server settings to other servers [WIP] Tool to replicate server settings to other servers Sep 19, 2017
@jameswnl
Copy link
Contributor Author

@bronaghs @gtanzillo can you help review this?

thanks

target_settings = target.get_config("vmdb")
target_settings.config.store_path(*path, values)

valid, errors = VMDB::Config::Validator.new(settings).validate

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 ?

Copy link
Contributor Author

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.

@bronaghs
Copy link

Just one question inline @jameswnl
Can you add a PR description.
We want to add videos where possible to help other teams understand new features, maybe you could add a video for this.

@jameswnl jameswnl force-pushed the rep-server-settings branch 2 times, most recently from e507072 to 08663ca Compare September 19, 2017 15:22
@jameswnl jameswnl changed the title [WIP] Tool to replicate server settings to other servers Tool to replicate server settings to other servers Sep 19, 2017
@jameswnl
Copy link
Contributor Author

@miq-bot remove_label wip

server = opts[:serverid] ? MiqServer.find(opts[:serverid]) : MiqServer.my_server
settings = server.get_config("vmdb")

config = settings.config
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

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)
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Done

target_settings = target.get_config("vmdb")
target_settings.config.store_path(*path, values)

valid, errors = VMDB::Config::Validator.new(target_settings).validate
Copy link
Member

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 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great! Done


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"
Copy link
Member

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"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

require 'trollop'

opts = Trollop.options(ARGV) do
banner "USAGE: #{__FILE__} -s <server id> -p <settings path separated by a /> \n" \
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Copy link
Member

@carbonin carbonin left a 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.


def construct_setting_tree(path, values)
# construct the partial tree containing the target values
path.reverse.inject(values) { |m, e| {e => m} }
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

target_servers.each do |target|
puts " - replicating to server id=#{target.id}..."
target.add_settings_for_resource(target_settings)
target.save!
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good! done

puts opts.inspect
Trollop.die :path, "is required" unless opts[:path_given]

def replicate(opts)
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@miq-bot
Copy link
Member

miq-bot commented Sep 20, 2017

Checked commits jameswnl/manageiq@6e7206b~...7af94f6 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
3 files checked, 0 offenses detected
Everything looks fine. 👍

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)
Copy link
Member

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?

Copy link
Contributor Author

@jameswnl jameswnl Sep 20, 2017

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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
👍

Copy link
Member

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 carbonin assigned carbonin and unassigned gtanzillo Sep 20, 2017
@jameswnl
Copy link
Contributor Author

@carbonin thanks for the review!

@carbonin
Copy link
Member

Just waiting on coveralls ...

@carbonin
Copy link
Member

Coveralls is taking too long.

@carbonin carbonin added this to the Sprint 70 Ending Oct 2, 2017 milestone Sep 20, 2017
@carbonin carbonin merged commit a215bb7 into ManageIQ:master Sep 20, 2017
@jameswnl jameswnl deleted the rep-server-settings branch September 21, 2017 00:51
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}"
Copy link
Member

@chrisarcand chrisarcand Sep 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NoooOooooOoooooooo

:trollface:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

giphy

Copy link
Contributor Author

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.

Copy link
Contributor Author

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
Copy link

@jameswnl - Can you see any reason why this cannot be backported to FINE?
cc @simaishi

@jameswnl
Copy link
Contributor Author

@bronaghs this should be portable.

@bronaghs
Copy link

@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

simaishi pushed a commit that referenced this pull request Apr 9, 2018
Tool to replicate server settings to other servers
(cherry picked from commit a215bb7)

https://bugzilla.redhat.com/show_bug.cgi?id=1557025
@simaishi
Copy link
Contributor

simaishi commented Apr 9, 2018

Fine backport details:

$ git log -1
commit 1efe7a4aff9ce4d2027c9de2fd0f5715b9a5eb46
Author: Nick Carboni <[email protected]>
Date:   Wed Sep 20 17:23:27 2017 -0400

    Merge pull request #15990 from jameswnl/rep-server-settings
    
    Tool to replicate server settings to other servers
    (cherry picked from commit a215bb733535f250c58c18c555793b9b09cc805e)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1557025

d-m-u pushed a commit to d-m-u/manageiq that referenced this pull request Jun 6, 2018
Tool to replicate server settings to other servers
(cherry picked from commit a215bb7)

https://bugzilla.redhat.com/show_bug.cgi?id=1557025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants