-
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
Allow OrchestrationTemplate subclass to customize md5 calculation #17126
Allow OrchestrationTemplate subclass to customize md5 calculation #17126
Conversation
@Ladas I assigned you since you're usually involved in refresher stuff. Please let me know if I'm wrong. |
|
||
it "uses parent if type is not present" do | ||
expect(ManageIQ::Providers::Vmware::CloudManager::OrchestrationTemplate).not_to receive(:calc_md5) | ||
expect(described_class).not_to receive(:calc_md5).at_least(:once) |
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.
why not_to
? shouldn't it call the parent to calculate the md5?
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.
Ha! Typo! But it seems like .at_least(:once)
makes it ignore the not_to
since it works both with
.not_to receive(:calc_md5).at_least(:once)
or with
.to receive(:calc_md5).at_least(:once)
Thanks for noticing, I've updated the code.
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.
It actually freaks me out that it works either way, is this something to be reported to rspec guys? I mean, when both .to
and .not_to
are passing at the same time, it's kind of breaking the core principal of computer science 😄
@@ -36,6 +36,24 @@ | |||
expect(@existing_record).not_to eq(OrchestrationTemplate.find_or_create_by_contents(@query_hash)[0]) | |||
expect(OrchestrationTemplate.count).to eq(2) | |||
end | |||
|
|||
it "uses subclass if type is present" do | |||
expect(ManageIQ::Providers::Vmware::CloudManager::OrchestrationTemplate).to receive(:calc_md5).at_least(:once) |
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.
why at_lease(:once)
? can it be called more than once?
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.
In fact it gets called twice:
- 1st time in L46
md5s << klass.calc_md5(with_universal_newline(hash[:content]))
- 2nd time in L56
template = create!(hash.except(:md5))
because of this hook https://github.com/manageiq/manageiq/blob/master/app/models/orchestration_template.rb#L64
Theoretically I could test for :twice
but would prefer to keep it more general, should you agree.
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.
Oh, yes, it is called twice. Then I think at_least(:once)
is ok.
928981a
to
b448e6c
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.
Thanks for a review @bzwei , I've updated the code accordingly. Please let me know if you prefer me to use :twice
instead of .at_least(:once)
.
@@ -36,6 +36,24 @@ | |||
expect(@existing_record).not_to eq(OrchestrationTemplate.find_or_create_by_contents(@query_hash)[0]) | |||
expect(OrchestrationTemplate.count).to eq(2) | |||
end | |||
|
|||
it "uses subclass if type is present" do | |||
expect(ManageIQ::Providers::Vmware::CloudManager::OrchestrationTemplate).to receive(:calc_md5).at_least(:once) |
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.
In fact it gets called twice:
- 1st time in L46
md5s << klass.calc_md5(with_universal_newline(hash[:content]))
- 2nd time in L56
template = create!(hash.except(:md5))
because of this hook https://github.com/manageiq/manageiq/blob/master/app/models/orchestration_template.rb#L64
Theoretically I could test for :twice
but would prefer to keep it more general, should you agree.
|
||
it "uses parent if type is not present" do | ||
expect(ManageIQ::Providers::Vmware::CloudManager::OrchestrationTemplate).not_to receive(:calc_md5) | ||
expect(described_class).not_to receive(:calc_md5).at_least(:once) |
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.
Ha! Typo! But it seems like .at_least(:once)
makes it ignore the not_to
since it works both with
.not_to receive(:calc_md5).at_least(:once)
or with
.to receive(:calc_md5).at_least(:once)
Thanks for noticing, I've updated the code.
end | ||
|
||
it "uses parent if type is not present" do | ||
expect(ManageIQ::Providers::Vmware::CloudManager::OrchestrationTemplate).not_to receive(:calc_md5) |
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.
Do not need this line. It is meaningless.
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.
Removed
Currently, md5 checksum is forcibly calculated on entire orchestration template text content: ``` OrchestrationTemplate.calc_md5(text) ``` But this is not always feasible. VMware vCloud, for example, yields randomly ordered elements in XML even when describing the very same orchestration template, hence the MD5 checksum differs. Therefore we need to be able to customize the way the MD5 checksum is calculated. With this commit we make sure that calc_md5 function from the subclass is used: ``` ManageIQ::Providers::Vmware::CloudManager::OrchestrationTemplate.calc_md5(text) ``` Only this way, we're able to customize what part of the XML will actually be used to calculate MD5 checksum. Signed-off-by: Miha Pleško <[email protected]>
b448e6c
to
4df94a0
Compare
Checked commit miha-plesko@4df94a0 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
@gmcculloug can you merge it? |
…-md5 Allow OrchestrationTemplate subclass to customize md5 calculation (cherry picked from commit fbdd937) https://bugzilla.redhat.com/show_bug.cgi?id=1559628
Gaprindashvili backport details:
|
Currently, md5 checksum is forcibly calculated on entire orchestration template text content:
But this is not always feasible. VMware vCloud, for example, yields randomly ordered elements in XML even when describing the very same orchestration template, hence the MD5 checksum differs. Therefore we need to be able to customize the way the MD5 checksum is calculated.
With this commit we make sure that calc_md5 function from the subclass is used:
Only this way we're able to customize what part of the XML will actually be used to calculate MD5 checksum.
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1553699
@miq-bot assign @Ladas
@miq-bot add_label enhancement,gaprindashvili/yes
/cc @bzwei @agrare @gberginc