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

Extract variable Tower data from tests #93

Merged
merged 4 commits into from
Aug 10, 2018

Conversation

Glutexo
Copy link
Member

@Glutexo Glutexo commented May 29, 2018

Some properties of the records expected in a Tower instance are not
entered directly by the user: ids, timestamps, external data… These
are subject to change with every population and cassette re-recording.

In such case manual update of expectations in specs was
required. Collection of this data to a single resource file allows to
change only this single file instead of hunting the right magic
literals in the specs examples.

Extracted from #79 for easier review. This part contains only changes to the specs. Goes along with #92.

@miq-bot add_reviewer @jameswnl

@miq-bot
Copy link
Member

miq-bot commented May 31, 2018

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

@Glutexo
Copy link
Member Author

Glutexo commented Jun 5, 2018

#91 got merged. Rebased to resolve conflicts: Removed data for Tower v2 tests.

@bronaghs
Copy link

@Glutexo - Can you address the conflicts please so we can get this in.

@Glutexo Glutexo force-pushed the extract_variable_tower_data branch from 86e4a8d to 0f817a0 Compare June 20, 2018 12:39
@Glutexo
Copy link
Member Author

Glutexo commented Jun 20, 2018

Rebased, resolved. VCRs were re-recorded and because of that ids and counts in spec changed. If this gets merged, doing such and update would be easier for anybody. (@jameswnl in this case)

@tumido
Copy link
Member

tumido commented Jul 19, 2018

@jameswnl, can this one please get reviewed so we can slowly get to the point when Stepan's PRs are merged? 😉

@@ -11,6 +11,10 @@
:verify_ssl => false,).tap { |provider| provider.authentications << auth }
end

let(:tower_data) { Spec::Support::TowerDataHelper.tower_data }
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be able to do a YAML.load_file(TOWER_DATA_FILE) where the TOWER_DATA_FILE point to the yaml file.
This way we can eliminate that spec/support/tower_data_helper.rb file which will make @jrafanie 😄

Can either define TOWER_DATA_FILE in spec_helper.rb or even load it up there. But may be other spec experts can help here

Copy link
Contributor

@jameswnl jameswnl left a comment

Choose a reason for hiding this comment

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

Eliminate the need for spec/support/tower_data_helper.rb

@jameswnl
Copy link
Contributor

This is great!

Copy link
Member

@tumido tumido left a comment

Choose a reason for hiding this comment

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

@Glutexo, I've placed some comments inline. I can't get proper data from the tower...

@jameswnl I've removed the helper class and replace it with a shared context fetching the same YAML file in the shared specs wherever it is required.

@@ -14,27 +14,38 @@
end
let(:manager_class) { manager_class }

let(:tower_data) { Spec::Support::TowerDataHelper.tower_data }

let(:targeted_refresh_id) { tower_data['items']['targeted_refresh']['id'] }
Copy link
Member

Choose a reason for hiding this comment

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

@Glutexo, where can I get the targeted_refresh project, please? I'm missing it in all of you PRs unfortunately. It seems this was never added to the rake job for Tower population. I was only able to find a removed mention in a spec in the original PR #79

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 PR extracts the actual data used in the specs. I tried to map it as well as possible to the data created by the Rake task, but still they are more or less independent. If I recall correctly, the ids used here were different from the hello_repo and another_repo, so I created a separate entity for them in the YAML.

This can be resolved when merging with the other PR by using hello_repo instead and changing the data in this spec. This will however require re-recording of the VCRs, which is what I didn’t want to do here. It’s the inconsistency between specs I was talking about with you earlier. :(

let(:targeted_refresh_id) { tower_data['items']['targeted_refresh']['id'] }
let(:targeted_refresh_last_updated) { tower_data['items']['targeted_refresh']['last_updated'].utc }
let(:targeted_refresh_playbooks) { tower_data['items']['targeted_refresh']['playbooks'] }
let(:nonexistent_repo_id) { tower_data['items']['nonexistent_repo']['id'] }
Copy link
Member

Choose a reason for hiding this comment

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

The same case as the previous comment. This PR is the first one mentioning a nonexistent_repo. Is this the same as failed_repo?

Copy link
Member Author

Choose a reason for hiding this comment

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

As the name suggests, a nonexistent_repo is an invalid id. It was used to ensure that the refresher does not even try to load this repo when updating the targeted_refresh one. When merging with the Rake task changes, it would be necessary to create such id. That can be achieved by creating some repo and then deleting it, making sure the id is captured and it neither belongs to any existing project in Tower, nor going to be reused unexpectedly in the future.

@tumido tumido force-pushed the extract_variable_tower_data branch from ab0f83f to d08a72c Compare July 23, 2018 17:22
@tumido tumido force-pushed the extract_variable_tower_data branch 2 times, most recently from 508c13a to 7f4bdfe Compare July 27, 2018 09:13
@miq-bot
Copy link
Member

miq-bot commented Jul 27, 2018

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

Copy link
Member Author

@Glutexo Glutexo left a comment

Choose a reason for hiding this comment

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

Hey, spotted some issues.

@@ -434,6 +434,20 @@ class PopulateTower
last_update = wait_for_project_update(jobless_project)
@conn.delete(last_update['url'])

# Create and remove project - record an collect an ID of missing entity
uri = '/api/v1/projects/'
uri = '/api/v1/projects/'
Copy link
Member Author

Choose a reason for hiding this comment

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

Dupy dupy dupy dup dup dup.

}
nonexistent_project = create_obj(uri, data)
@tower_data[:items][data[:name]] = { :id => nonexistent_project['id'] }
del_obj(uri, data[:name])
Copy link
Member Author

Choose a reason for hiding this comment

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

Just remember, that del_obj does some safety sleep. This might be necessary when recreating object that are already present in Tower. It is however useless here, when we just want to delete an object without any intention of creating its replacement.

7f4bdfe#diff-bb7272be93a294c53ae6433eb024074fR108

Copy link
Member

Choose a reason for hiding this comment

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

What's the issue with this? The rake job is run only in case of regenerating VCRs. It doesn't slow down the test run or anything...

Copy link
Member Author

@Glutexo Glutexo Jul 27, 2018

Choose a reason for hiding this comment

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

You just wait a long time for nothing before going to the next step – populating item counts.

@@ -0,0 +1,3 @@
shared_context "uses tower_data.yml" do
let(:tower_data) { YAML.load_file(ManageIQ::Providers::AnsibleTower::Engine.root.join("spec/support/tower_data.yml")) }
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 still don’t like this. Can’t we turn the path into a constant then use it when writing the file by the Rake task?

7f4bdfe#diff-bb7272be93a294c53ae6433eb024074fR11

Copy link
Member

Choose a reason for hiding this comment

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

Why would be a global constant better than a shared context? The context defines the test scope. Global constant would require the file to be loaded for any spec execution within this repo. A shared context allows lazy loading of the file - only if the spec requires it. In other words, this way it is not required to have the YAML present and loaded at all when you're running a spec which doesn't include the context.

Copy link
Member Author

Choose a reason for hiding this comment

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

There is nothing bad with the shared context. I’d just extract the file path to the global content. That is virtually no overhead (as compared to loading and parsing the whole file) for that and then in can be used even outside the specs for writing the file.

@tumido tumido force-pushed the extract_variable_tower_data branch 3 times, most recently from c2466bf to 02bff00 Compare July 27, 2018 11:31
@miq-bot
Copy link
Member

miq-bot commented Aug 1, 2018

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

Glutexo and others added 4 commits August 9, 2018 14:14
Some properties of the records expected in a Tower instance are not
entered directly by the user: ids, timestamps, external data… These
are subject to change with every population and cassette re-recording.

In such case manual update of expectations in specs was
required. Collection of this data to a single resource file allows to
change only this single file instead of hunting the right magic
literals in the specs examples.
@tumido tumido force-pushed the extract_variable_tower_data branch from 02bff00 to 38f0f9a Compare August 9, 2018 13:19
@miq-bot
Copy link
Member

miq-bot commented Aug 9, 2018

Some comments on commits Glutexo/manageiq-providers-ansible_tower@7043e91~...38f0f9a

lib/tasks_private/spec_helper.rake

  • ⚠️ - 493 - Detected puts. Remove all debugging statements.
  • ⚠️ - 498 - Detected puts. Remove all debugging statements.

@miq-bot
Copy link
Member

miq-bot commented Aug 9, 2018

Checked commits Glutexo/manageiq-providers-ansible_tower@7043e91~...38f0f9a with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
5 files checked, 0 offenses detected
Everything looks fine. 🍰

@tumido
Copy link
Member

tumido commented Aug 9, 2018

Should be mergeable again. @jameswnl can you please review and tell me your view on @Glutexo suggestions above? I'd say we pay too much attention to little tiny details, which are not relevant much.

@tumido
Copy link
Member

tumido commented Aug 9, 2018

@miq-bot remove_label unmergeable

@tumido
Copy link
Member

tumido commented Aug 10, 2018

@miq-bot add_label enhancement, test

@jameswnl jameswnl merged commit 7dfefd0 into ManageIQ:master Aug 10, 2018
@Glutexo Glutexo deleted the extract_variable_tower_data branch October 11, 2018 09:25
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.

None yet

5 participants