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

Add a concern for storing and accessing embedded ansible object ids #14377

Merged

Conversation

carbonin
Copy link
Member

This will allow us to determine the ansible side object to relate new objects to.

This also frees us from having to store an extra flag in our inventory to identify which objects are the "system created" ones and which are the other objects that may be artifacts of running jobs.

https://www.pivotaltracker.com/story/show/140098929

default_ansible_objects.find_by(:name => name).try(:value).try(:to_i)
end

def set_default_ansible_object(name, value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Will the value be tower ref id?

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 will be the tower side database id, this PR allows it to be any value, but we're setting it to the id in the other PR here https://github.com/ManageIQ/manageiq/pull/14283/files#diff-45e99ec23caedc019723f05f7817652eR22

raise DefaultAnsibleObjectError, "#{name} object already exists with value #{current_value}"
end

default_ansible_objects.create(:name => name, :value => value)
Copy link
Member

Choose a reason for hiding this comment

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

All of this feels like default_ansible_objects.find_or_initialize_by(:name => name).update_attributes(:value => value). This will be a noop if the record already exists or have the same existing value. Not sure why you need the check on lines 58-60

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 specifically wanted to disallow changing the value once it was created. I feel like that could lead to some really weird issues.

Do you think that's necessary?

expect { subject.public_send("default_#{obj_name}=", obj_name.length + 1) }.to raise_error(described_class::DefaultAnsibleObjectError)
end

it "#default_#{obj_name}= raises an error if we try to set to a new value" do
Copy link
Member

Choose a reason for hiding this comment

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

Looks like you have a duplicate test here.

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 thanks I think I meant this to test that it worked if we tried to set the value to the same value ... Good catch!

end

context "with attributes saved" do
before do
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 you can use a before(:context) here to create all four records up front rather than creating four records before each test (16 times)

Copy link
Member Author

Choose a reason for hiding this comment

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

That doesn't work because subject is per example.

Copy link
Member

@Fryguy Fryguy Mar 20, 2017

Choose a reason for hiding this comment

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

Not a fan of before(:context) for the same reason we don't do before(:all) or before(:suite). You're just begging for test contamination. Incidentally before(:context) is just a synonym for before(:all)

module ManageIQ::Providers::EmbeddedAnsible::Provider::DefaultAnsibleObjects
extend ActiveSupport::Concern

class DefaultAnsibleObjectError < RuntimeError; end
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 should this live with the rest of our exceptions, not in this class.

@miq-bot
Copy link
Member

miq-bot commented Mar 17, 2017

This pull request is not mergeable. Please rebase and repush.

@carbonin carbonin force-pushed the add_custom_attrs_for_default_ansible_objs branch from a74ccc6 to 2cdc2a5 Compare March 17, 2017 19:41
…ct ids

This will allow us to determine the ansible side object to relate
new objects to.

This also frees us from having to store an extra flag in our inventory
to identify which objects are the "system created" ones and which
are the other objects that may be artifacts of running jobs.

https://www.pivotaltracker.com/story/show/140098929
@carbonin carbonin force-pushed the add_custom_attrs_for_default_ansible_objs branch from 2cdc2a5 to 5921219 Compare March 17, 2017 20:31
@@ -2,4 +2,44 @@

describe ManageIQ::Providers::EmbeddedAnsible::Provider do
it_behaves_like 'ansible provider'

subject { FactoryGirl.build(:provider_embedded_ansible) }
Copy link
Member Author

Choose a reason for hiding this comment

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

From #14283 (comment)

@bdunne
Why not FactoryGirl.create rather than adding the subject.save in the before block?

@carbonin
Ah, I think this was a rebase issue. I started this branch before #14383 was merged so instead of changing the subject for all the tests, I saved the record in just my context, during the rebase I think this line got left here.

I'll refactor in a new commit so that the individual specs define the subject rather than the shared example.

Thanks for catching this.

This ensures that the specific provider under test implements
the defined behavior rather than just running the same set of
specs twice (what was being done with the shared subject).

Intorduced in eb6be29
@miq-bot
Copy link
Member

miq-bot commented Mar 20, 2017

Checked commits carbonin/manageiq@5921219~...06a52e2 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
5 files checked, 0 offenses detected
Everything looks good. ⭐

@gmcculloug
Copy link
Member

@bzwei @Fryguy Anything else here or is it good to merge?

@Fryguy Fryguy merged commit c69de02 into ManageIQ:master Mar 20, 2017
@Fryguy Fryguy added this to the Sprint 57 Ending Mar 27, 2017 milestone Mar 20, 2017
@Fryguy Fryguy assigned Fryguy and unassigned blomquisg Mar 20, 2017
@carbonin carbonin deleted the add_custom_attrs_for_default_ansible_objs branch May 18, 2017 17:14
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.

7 participants