-
Notifications
You must be signed in to change notification settings - Fork 55
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
Collect variable Tower data upon population #92
Collect variable Tower data upon population #92
Conversation
73786c0
to
9aca802
Compare
This pull request is not mergeable. Please rebase and repush. |
e81a0d3
to
f32ebcf
Compare
#89 got merged. Rebased this to resolve conflicts. Reused the |
@Glutexo - Can you resolve the conflicts so we can get this in |
f32ebcf
to
d7a22ad
Compare
Rebased on current master, conflicts resolved. |
d7a22ad
to
4acd332
Compare
Some comments on commit Glutexo@4acd332 lib/tasks_private/spec_helper.rake
|
Checked commit Glutexo@4acd332 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 lib/tasks_private/spec_helper.rake
|
lib/tasks_private/spec_helper.rake
Outdated
del_obj(uri, data['name']) | ||
obj = JSON.parse(@conn.post(uri, data).body) | ||
puts "%s %s %s" % ["Created name=#{obj['name']}".ljust(40), "manager_ref/ems_ref= #{obj['id']}".ljust(30), "url=#{obj['url']}".ljust(10)] | ||
|
||
dumped_data = obj.slice(*dumped_fields) | ||
@tower_data.update { |td| td['items'][obj['name']] = dumped_data } unless dumped_data.empty? |
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.
Can you move the @tower_data.update
part out of this method? Let it just does the creation of object in Tower.
lib/tasks_private/spec_helper.rake
Outdated
|
||
def update | ||
yield @data if block_given? | ||
write |
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.
this write each time something updated seems too much. yeah, it's not a big deal in this rake task. but ....
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.
I agree that this excessive writing just as the whole TowerData class might be an overkill. I’d just like to explain my motivation to that:
Because the population of a Tower instance can easily end with some failure during the process, I wanted to have the YAML file always consistent with what has been actually created in Tower. It’s always possible to revert it and it can serve as a reference.
But as @tumido pointed out, it is not actually necessary, because the YAML is intended to be used solely by Specs. And it can be used only if complete. For reference you can always read the terminal output or actually look into the Tower web UI.
lib/tasks_private/spec_helper.rake
Outdated
end | ||
end | ||
|
||
class TowerData |
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.
This is pretty cool. However, it's overkill in this case and that introduces unnecessary mental weight for forthcoming maintainers. Can we simply dump the collected hash into yml after creating the data set?
spec/support/tower_data_helper.rb
Outdated
@@ -0,0 +1,21 @@ | |||
module Spec |
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.
Similarly here, I think we don't need this to achieve what this PR intends to. In #93 you can simply load from either a given yml file or the default one.
This pull request is not mergeable. Please rebase and repush. |
Each time objects are populated in a Tower instance, some of their properties (ids, timestamps…) change. The same applies to objects counts that can differ from the previous state. This information is used then in the specs. Collect these changing data during their population in Tower instance to a YAML file. This allows to fill the necessary information in the specs after re-recording the cassettes more easily. Eventually it could be used directly from the tests too.
5b7555c
to
09a2540
Compare
@jameswnl I think it is acceptable now. Can you please review it? Thanks 👍 🍷 |
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.
Hey Tom, almost there
lib/tasks_private/spec_helper.rake
Outdated
end | ||
|
||
def v3_2? | ||
@version >= Gem::Version.new('3.2') | ||
end | ||
|
||
def save |
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.
This object is PopulateTower
and so a method named as save
would be ambiguous as to where it's saving to. How about rename it explicitly as to_file
, data_to_file
or dump
?
lib/tasks_private/spec_helper.rake
Outdated
data = JSON.parse(@conn.get(uri).body) | ||
data['results'].each do |item| | ||
obj = get_obj(uri) | ||
obj['results'].each do |item| | ||
next if item['name'] != match_name | ||
puts "Deleting old #{item['name']}: #{item['url']}" | ||
@conn.delete(item['url']) |
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.
Found a bug not related to your changes. We should exit this method here by return @conn.delete(item['url'])
since we found our target. Otherwise, Line 112 will still be executed and is simply doing useless work.
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.
I've refactored the method so it may be a bit cleaner and better to understand what it does. Tell me if you like it 😉 If not, I can revert it.
lib/tasks_private/spec_helper.rake
Outdated
# | ||
require 'faraday' | ||
require 'faraday_middleware' | ||
|
||
MAX_TRIES = 10 | ||
TRY_SLEEP = 2 | ||
DEL_SLEEP = 20 | ||
TOWER_DATA_YAML = ManageIQ::Providers::AnsibleTower::Engine.root.join('spec', 'support', 'tower_data.yml') |
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.
Remove this line and pass the file path as parameter when dumping to file (Line 11). This way just from reading the calling code of this class, people would know what to expect.
And you don't have to split the path into 3 parts, you can simply jam them into 1 literal string being appended to the engine root.
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.
Sure! About the 3 parts.. I just copy-pasted that without thinking, thanks for pointing that out. 🚀
09a2540
to
8b807dc
Compare
|
||
populate.create_dataset | ||
populate.counts | ||
populate.to_file(ManageIQ::Providers::AnsibleTower::Engine.root.join("spec/support/tower_data.yml")) |
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.
single '
😄
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.
Should I open a new PR? 😄
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.
I don’t like the fact that the path is here in the Rake task. Since the YAML is going to be used by the Specs, I’d prefer to have the constant somewhere along them and use it from here.
Merged! ᔧ! 🎉 Thanks guys for taking care of it. I hope this will actually make the use of the Rake task more pleasant for its future users. |
Each time objects are populated in a Tower instance, some of their properties (ids, timestamps…) change. The same applies to objects counts that can differ from the previous state. This information is used then in the specs.
Collect these changing data during their population in Tower instance to a YAML file. This allows to fill the necessary information in the specs after re-recording the cassettes more easily. Eventually it could be used directly from the tests too.
Extracted from #79 for easier review. This part contains only changes to the Rake task. Goes along with #93.
@miq-bot add_reviewer @jameswnl