-
Notifications
You must be signed in to change notification settings - Fork 8
Add default manifest and API controller for loading it #8
Conversation
@Fryguy now that I'm adding some real Ruby code to this repo, we'll need to set up Ruby unit testing stuff and fix the setup/update scripts (#2), which I could use some help with. Also, based on some discussions with @agrare, I'm not sure exactly how we should move forward with the API for running the data collector and downloading the file. We'll need to:
Are you guys (@Fryguy @agrare) still planning to develop all of the above, or do we need to get some help from @djberg96 and others? I know they are busy with Warm Migration for IMS, and I know you guys are busy too. But I'm a little worried that by offering to help take a stab at some of this stuff I gave the impression that I had it all covered, and if we do really need to get this done for the code freeze on Monday, I don't think I'll be able to build it on time myself considering I'm a JS guy learning Ruby/Rails as I go. Thanks for all the help so far. cc @bthurber |
def index | ||
tmp_manifest_path = '/tmp/migration-analytics-manifest.json' | ||
tmp_manifest = File.file?(tmp_manifest_path) ? parse_json_if_valid(File.read(tmp_manifest_path)) : nil | ||
tmp_manifest_valid = tmp_manifest != nil && tmp_manifest != :invalid |
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.
Maybe we take this one step at a time and just return the builtin manifest for now, then expand to handle user uploaded also
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 can break this into two PRs if you want. But I know Miguel was asking for us to make sure there is always a way for the user to manually upgrade the included manifest, in case we ship this feature and then release some change to the cloud.redhat.com part of Migration Analytics that depends on a newer manifest that hasn't been released built-in yet.
Maybe he'll have an opinion here.. cc @mperezco
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 having it in /tmp
because some systems clear that on reboot and on a schedule as a cron task, but I don't want to hold this PR up while we discuss where the user could upload it.
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.
manifest = tmp_manifest | ||
else | ||
manifest_path = File.join( | ||
Bundler.environment.specs['cfme-migration_analytics'].first.full_gem_path, |
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.
Think you can just do Cfme::MigrationAnalytics::Engine.root.join("config", "default-manifest.json")
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.
Ah, that is better, thanks.
Also, I notice that examples from you and @Fryguy all use double-quotes and I've been using single-quotes in all my Ruby so far, just because that's what we did in v2v. Do you guys have an opinion on which should be used? I can switch them all over to double-quotes.
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.
That's mostly a personal preference, in ruby you can't do string interpolation in a string with single quotes which some people think is a good thing (i.e. it indicates the string is a constant).
Personally I think it looks sloppy having a mixture of ''
and ""
. You have to use ""
if you do any string interpolation, so I tend to just use ""
everywhere.
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.
Sounds good. I agree it's sloppy to have both. Changed them all to ""
.
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 pushed this commit too late to be merged in this PR, so I added it to #10.
@abellotti can you help review this from the API side? |
@mturley I tested with my local changes and I had to re-enable |
|
||
res = { | ||
:tmp_manifest_present => tmp_manifest != nil, | ||
:tmp_manifest_valid => tmp_manifest_valid, |
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.
if this is part of an API response, are these the right key names we want ? tmp_... what if it's in a different location ? I would expect just "manifest_present" and "manifest_valid".
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.
My goal here was to have the UI be able to tell if the manifest being returned is the one built-in on the appliance (the default-manifest.json file being added here) or a file they included in the /tmp/ directory, and whether the latter is being ignored because it's invalid JSON. Maybe it should be "override_manifest_present" and "override_manifest_valid" instead?
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 this feature for now per @agrare 's request.
render_resource :migration_analytics_manifest, res | ||
end | ||
end | ||
end |
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.
we need specs added for the API. so spec/requests/migration_analytics_manifest_spec.rb, maybe look at https://github.com/RedHatCloudForms/cfme-cloud_services/pull/23/files for spec/ files for the api file plus the spec_helper.rb and support/api_request_helpers.rb.
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.
Ok, I'll take a look and try to get these started. I got stuck trying to get the Travis config's Ruby checks to work in this repo though, I may need some help figuring that out (the bin/setup script fails, probably because it was depending on something from https://github.com/martinpovolny/miq_plugin_example that I removed). I have an issue to track that: #2
@agrare we have |
Some comments on commits mturley/cfme-migration_analytics@7e2d7e7~...1c9d3e2 app/controllers/api/migration_analytics_manifest_controller.rb
|
Checked commits mturley/cfme-migration_analytics@7e2d7e7~...1c9d3e2 with ruby 2.4.6, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0 **
|
The only requirement we have is that MA isn't visible as an option under Migration in the UI with the ability to add it back to the menu if needed. Similar to what we did for IMS 1.0 beta. |
Okay thanks @bthurber, I'm fine leaving vmdb_plugin? false for now but we'll need to turn it on for the API to work. Without the UI the API isn't really helpful though anyway so its really just an issue for testing/development. |
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 a good starting point, thanks @mturley !
Add default manifest and API controller for loading it
Add default manifest and API controller for loading it (cherry picked from commit 3847740)
Ivanchuk backport details:
|
This PR adds a copy of the v1.0.0 manifest at
config/default-manifest.json
, and adds a new API endpoint at/api/migration_analytics_manifest
for fetching it in the UI.The API call will:
/tmp/migration-analytics-manifest.json
on the appliance, and use that manifest if it is present and contains valid JSON.tmp_manifest_present
(boolean) - whether or not there is a file at /tmp/migration-analytics-manifest.jsontmp_manifest_valid
(boolean) - whether or not there is a valid JSON file at /tmp/migration-analytics-manifest.jsonpath
(string) - the path to the manifest JSON file being usedbody
(object) - the parsed contents of the manifest JSONWe can use this to load a manifest into the UI, and: