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

Synchronize provider with server when zone changes #18272

Conversation

jrafanie
Copy link
Member

@jrafanie jrafanie commented Dec 6, 2018

If an appliance's zone (or hostname/ipaddress) changes, we don't update the related "hidden" provider's zone (and URL), requiring users to restart the embedded ansible role or reboot the whole appliance. This PR checks for these changes and updates the provider.

I added a commit to check for URL changes, in case they renamed the appliance (hostname) or the ip address. I can do this as a followup if need be, but it's a tiny change so I included it.

https://bugzilla.redhat.com/show_bug.cgi?id=1656308

@jrafanie jrafanie added the bug label Dec 6, 2018
@jrafanie jrafanie requested a review from carbonin December 6, 2018 22:12
@jrafanie jrafanie force-pushed the synchronize_provider_with_server_when_zone_changes branch from 579a921 to f4725de Compare December 6, 2018 22:18
@@ -99,7 +99,13 @@
runner.instance_variable_set(:@job_data_retention, ::Settings.embedded_ansible.job_data_retention_days)
end

after do
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this block? Doesn't the runner get re-evaluated for each example? It's defined in a let

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, good point... I could have sworn they were class methods but clearly not... I'll verify but yeah, I think the runner should be new for each example.

@@ -133,12 +139,48 @@

it "sets the embedded ansible job data retention value when the setting changes" do
allow(embedded_ansible_instance).to receive(:alive?).and_return(true)
allow(runner).to receive(:provider).and_return(provider)
Copy link
Member

Choose a reason for hiding this comment

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

Why can this be removed here, but not in the other examples above it?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was part of my change to add the after....I can remove this change if I remove the after.

We only needed this line in the other examples because we set an expectation on the provider object in those examples... therefore, we needed to make sure the runner.provider returns this object and not the completely different ruby object returned from first_or_initialize from the "normal" provider method.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think I'd prefer to remove the after block and add this back.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good

provider.save!
end

def provider_matches_server?
Copy link
Member

@carbonin carbonin Dec 6, 2018

Choose a reason for hiding this comment

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

I think we could probably name this better as it's handling both the time aspect as well as the matching.

Unfortunately the best I could come up with was synchronize_provider_with_server?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was first matches_stuff?, I renamed it and gave up because it won't matter until a few eyes come up with a better name.

I'm glad you win the 🏆 of "find the part Joe bailed on trying to name correctly."

Copy link
Member Author

Choose a reason for hiding this comment

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

I like synchronize_provider_with_server

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm, that's funny... looking at it now, I like provider_out_of_sync_with_server?

Copy link
Member Author

Choose a reason for hiding this comment

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

lol, double negative... provider_in_sync_with_server?

@@ -109,7 +115,7 @@
end

context "with a provider" do
let(:provider) { FactoryGirl.create(:provider_embedded_ansible, :with_authentication) }
let!(:provider) { FactoryGirl.create(:provider_embedded_ansible, :with_authentication) }
Copy link
Member Author

Choose a reason for hiding this comment

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

This was added because all examples were already calling provider and my new example wasn't, but still needed it created.

@carbonin
Copy link
Member

carbonin commented Dec 7, 2018

As for updating just the zone (fixing only the bug) vs updating the zone and URL, I prefer fixing both.

The simplicity of this change which refactors existing, tested, code into a new method which is called additional times feels more stable than implementing something new, or changing the existing code block to update only the zone while leaving the URL alone.

@jrafanie jrafanie force-pushed the synchronize_provider_with_server_when_zone_changes branch from f4725de to 4685f22 Compare December 7, 2018 16:41
@jrafanie jrafanie force-pushed the synchronize_provider_with_server_when_zone_changes branch from 4685f22 to 52497e4 Compare December 7, 2018 16:42
@miq-bot
Copy link
Member

miq-bot commented Dec 7, 2018

Checked commits jrafanie/manageiq@62049ee~...52497e4 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 👍

@@ -22,6 +23,7 @@ def heartbeat
end

def do_work
synchronize_provider_with_server unless provider_in_sync_with_server?
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this new method name looks better... @carbonin what do you think?

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 same problem is still there.

The name only mentions that we're checking the properties, not that we are also returning true based on some timeframe. It doesn't really matter though. I'm not going to hold this up for a better name though.

@carbonin carbonin self-assigned this Dec 7, 2018
@carbonin carbonin merged commit a2592e8 into ManageIQ:master Dec 7, 2018
@carbonin carbonin added this to the Sprint 101 Ending Dec 17, 2018 milestone Dec 7, 2018
@jrafanie jrafanie deleted the synchronize_provider_with_server_when_zone_changes branch December 10, 2018 15:53
simaishi pushed a commit that referenced this pull request Dec 11, 2018
…ver_when_zone_changes

Synchronize provider with server when zone changes

(cherry picked from commit a2592e8)

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

Hammer backport details:

$ git log -1
commit fd990a963179821d5f1aa1d5c8d00424435635c1
Author: Nick Carboni <[email protected]>
Date:   Fri Dec 7 14:45:57 2018 -0500

    Merge pull request #18272 from jrafanie/synchronize_provider_with_server_when_zone_changes
    
    Synchronize provider with server when zone changes
    
    (cherry picked from commit a2592e80358a82c550eda205267e1bd421dcc97a)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1656308

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.

4 participants