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

Allow OrchestrationTemplate subclass to customize md5 calculation #17126

Merged
merged 1 commit into from
Mar 14, 2018

Conversation

miha-plesko
Copy link
Contributor

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.

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

@miha-plesko miha-plesko changed the title Allow OrchestraionTemplate subclass to customize md5 calculation Allow OrchestrationTemplate subclass to customize md5 calculation Mar 9, 2018
@miha-plesko
Copy link
Contributor Author

@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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

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?

Copy link
Contributor Author

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:

Theoretically I could test for :twice but would prefer to keep it more general, should you agree.

Copy link
Contributor

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.

@miha-plesko miha-plesko force-pushed the subclass-can-override-calc-md5 branch from 928981a to b448e6c Compare March 9, 2018 15:34
Copy link
Contributor Author

@miha-plesko miha-plesko left a 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)
Copy link
Contributor Author

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:

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)
Copy link
Contributor Author

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.

@miha-plesko
Copy link
Contributor Author

@bzwei if I understand correctly we only need to hit the green button here, right?

@miq-bot assign @bzwei

@miq-bot miq-bot assigned bzwei and unassigned Ladas Mar 12, 2018
end

it "uses parent if type is not present" do
expect(ManageIQ::Providers::Vmware::CloudManager::OrchestrationTemplate).not_to receive(:calc_md5)
Copy link
Contributor

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.

Copy link
Contributor Author

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 <miha.plesko@xlab.si>
@miha-plesko miha-plesko force-pushed the subclass-can-override-calc-md5 branch from b448e6c to 4df94a0 Compare March 14, 2018 15:09
@miq-bot
Copy link
Member

miq-bot commented Mar 14, 2018

Checked commit miha-plesko@4df94a0 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. 🍪

@bzwei
Copy link
Contributor

bzwei commented Mar 14, 2018

@gmcculloug can you merge it?

@agrare agrare self-assigned this Mar 14, 2018
@agrare agrare merged commit fbdd937 into ManageIQ:master Mar 14, 2018
@agrare agrare added this to the Sprint 82 Ending Mar 26, 2018 milestone Mar 14, 2018
simaishi pushed a commit that referenced this pull request Mar 22, 2018
…-md5

Allow OrchestrationTemplate subclass to customize md5 calculation
(cherry picked from commit fbdd937)

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

Gaprindashvili backport details:

$ git log -1
commit 25209f34a9ea398c073aaea01099084323feb708
Author: Adam Grare <agrare@redhat.com>
Date:   Wed Mar 14 17:03:55 2018 -0400

    Merge pull request #17126 from miha-plesko/subclass-can-override-calc-md5
    
    Allow OrchestrationTemplate subclass to customize md5 calculation
    (cherry picked from commit fbdd937efefcbc407d32136183417b95de761f97)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1559628

@miha-plesko miha-plesko deleted the subclass-can-override-calc-md5 branch January 7, 2019 08:22
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.

6 participants