-
Notifications
You must be signed in to change notification settings - Fork 121
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
Refactoring cloud vm provisioning profile methods #354
Merged
mkanoor
merged 2 commits into
ManageIQ:master
from
pkomanek:refactoring_cloud_vm_provisioning_profile_methods
Jul 13, 2018
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
56 changes: 39 additions & 17 deletions
56
...nt/automate/ManageIQ/Cloud/VM/Provisioning/Profile.class/__methods__/get_deploy_dialog.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,48 @@ | ||
# | ||
# Description: Dynamically choose dialog based on Category:environment chosen in pre-dialog | ||
# | ||
module ManageIQ | ||
module Automate | ||
module Cloud | ||
module VM | ||
module Provisioning | ||
module Profile | ||
class GetDeployDialog | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
end | ||
|
||
# Set to true to dynamically choose dialog name based on environment tag | ||
run_env_dialog = false | ||
# Set run_env_dialog to true to dynamically choose dialog name based on environment tag | ||
def main(run_env_dialog = false) | ||
if run_env_dialog | ||
# Get incoming environment tags from pre-dialog | ||
dialog_input_vm_tags = @handle.root['dialog_input_vm_tags'] | ||
|
||
if run_env_dialog | ||
# Get incoming environment tags from pre-dialog | ||
dialog_input_vm_tags = $evm.root['dialog_input_vm_tags'] | ||
# Use a regular expression to grab the environment from the incoming tag category | ||
# I.e. environment/dev for Category:environment Tag:dev | ||
regex = /(.*)(\/)(\w*)/i | ||
|
||
# Use a regular expression to grab the environment from the incoming tag category | ||
# I.e. environment/dev for Category:environment Tag:dev | ||
regex = /(.*)(\/)(\w*)/i | ||
# If the regular express matches dynamically choose the next dialog | ||
if regex =~ dialog_input_vm_tags | ||
cat = Regexp.last_match[1] | ||
tag = Regexp.last_match[3] | ||
@handle.log("info", "Category: <#{cat}> Tag: <#{tag}>") | ||
dialog_name = "miq_provision_dialogs-deploy-#{tag}" | ||
|
||
# If the regular express matches dynamically choose the next dialog | ||
if regex =~ dialog_input_vm_tags | ||
cat = Regexp.last_match[1] | ||
tag = Regexp.last_match[3] | ||
$evm.log("info", "Category: <#{cat}> Tag: <#{tag}>") | ||
dialog_name = 'miq_provision_dialogs-deploy-#{tag}' | ||
## Set dialog name in the root object to be picked up by dialogs | ||
@handle.root['dialog_name'] = dialog_name | ||
@handle.log("info", "Launching <#{dialog_name}>") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
## Set dialog name in the root object to be picked up by dialogs | ||
$evm.root['dialog_name'] = dialog_name | ||
$evm.log("info", "Launching <#{dialog_name}>") | ||
end | ||
|
||
if $PROGRAM_NAME == __FILE__ | ||
ManageIQ::Automate::Cloud::VM::Provisioning::Profile::GetDeployDialog.new.main | ||
end |
44 changes: 32 additions & 12 deletions
44
...utomate/ManageIQ/Cloud/VM/Provisioning/Profile.class/__methods__/vm_dialog_name_prefix.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,40 @@ | ||
# | ||
# Description: This is the default method to determine the dialog prefix name to use | ||
# | ||
module ManageIQ | ||
module Automate | ||
module Cloud | ||
module VM | ||
module Provisioning | ||
module Profile | ||
class VmDialogNamePrefix | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
end | ||
|
||
platform = $evm.root['platform'] | ||
$evm.log("info", "Detected Platform:<#{platform}>") | ||
# Set run_env_dialog to true to dynamically choose dialog name based on environment tag | ||
def main | ||
platform = @handle.root['platform'] | ||
@handle.log("info", "Detected Platform:<#{platform}>") | ||
|
||
if platform.nil? | ||
source_id = $evm.root['dialog_input_src_vm_id'] | ||
source = $evm.vmdb('vm_or_template', source_id) unless source_id.nil? | ||
if source | ||
platform = source.model_suffix.downcase | ||
else | ||
platform = "vmware" | ||
if platform.nil? | ||
source_id = @handle.root['dialog_input_src_vm_id'] | ||
source = @handle.vmdb('vm_or_template', source_id) unless source_id.nil? | ||
platform = source ? source.model_suffix.downcase : "vmware" | ||
end | ||
|
||
dialog_name_prefix = "miq_provision_#{platform}_dialogs" | ||
@handle.object['dialog_name_prefix'] = dialog_name_prefix | ||
@handle.log("info", "Platform:<#{platform}> dialog_name_prefix:<#{dialog_name_prefix}>") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
dialog_name_prefix = "miq_provision_#{platform}_dialogs" | ||
$evm.object['dialog_name_prefix'] = dialog_name_prefix | ||
$evm.log("info", "Platform:<#{platform}> dialog_name_prefix:<#{dialog_name_prefix}>") | ||
if $PROGRAM_NAME == __FILE__ | ||
ManageIQ::Automate::Cloud::VM::Provisioning::Profile::VmDialogNamePrefix.new.main | ||
end |
35 changes: 35 additions & 0 deletions
35
...tomate/ManageIQ/Cloud/VM/Provisioning/Profile.class/__methods__/get_deploy_dialog_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require_domain_file | ||
|
||
describe ManageIQ::Automate::Cloud::VM::Provisioning::Profile::GetDeployDialog do | ||
let(:cat) { 'environment' } | ||
let(:tag) { 'dev' } | ||
let(:root_hash) { { 'dialog_input_vm_tags' => "#{cat}/#{tag}" } } | ||
let(:root_object) { Spec::Support::MiqAeMockObject.new(root_hash) } | ||
|
||
let(:ae_service) do | ||
Spec::Support::MiqAeMockService.new(root_object).tap do |service| | ||
current_object = Spec::Support::MiqAeMockObject.new | ||
current_object.parent = root_object | ||
service.object = current_object | ||
end | ||
end | ||
|
||
it 'sets dialog name in the root object' do | ||
described_class.new(ae_service).main(true) | ||
expect(ae_service.root['dialog_name']).to(eq("miq_provision_dialogs-deploy-#{tag}")) | ||
end | ||
|
||
context 'does not set dialog name' do | ||
it '#not matching dialog_input_vm_tags attribute' do | ||
ae_service.root['dialog_input_vm_tags'] = 'not_matching_string' | ||
described_class.new(ae_service).main(true) | ||
expect(ae_service.root['dialog_name']).to(eq(nil)) | ||
end | ||
|
||
it '#run_env_dialog flag is false' do | ||
expect(ae_service).not_to(receive(:log)) | ||
described_class.new(ae_service).main | ||
expect(ae_service.root['dialog_name']).to(eq(nil)) | ||
end | ||
end | ||
end | ||
35 changes: 35 additions & 0 deletions
35
...te/ManageIQ/Cloud/VM/Provisioning/Profile.class/__methods__/vm_dialog_name_prefix_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require_domain_file | ||
|
||
describe ManageIQ::Automate::Cloud::VM::Provisioning::Profile::VmDialogNamePrefix do | ||
let(:platform) { 'test_platform' } | ||
let(:root_hash) { { 'platform' => platform } } | ||
let(:root_object) { Spec::Support::MiqAeMockObject.new(root_hash) } | ||
let(:vm_template) { FactoryGirl.create(:template_amazon) } | ||
let(:svc_vm_template) { MiqAeMethodService::MiqAeServiceVmOrTemplate.find(vm_template.id) } | ||
|
||
let(:ae_service) do | ||
Spec::Support::MiqAeMockService.new(root_object).tap do |service| | ||
current_object = Spec::Support::MiqAeMockObject.new | ||
current_object.parent = root_object | ||
service.object = current_object | ||
end | ||
end | ||
|
||
it "sets dialog_name_prefix from 'root['platform']'" do | ||
described_class.new(ae_service).main | ||
expect(ae_service.object['dialog_name_prefix']).to(eq("miq_provision_#{platform}_dialogs")) | ||
end | ||
|
||
it 'sets dialog_name_prefix from vmdb' do | ||
ae_service.root['platform'] = nil | ||
ae_service.root['dialog_input_src_vm_id'] = svc_vm_template.id | ||
described_class.new(ae_service).main | ||
expect(ae_service.object['dialog_name_prefix']).to(eq("miq_provision_#{svc_vm_template.model_suffix.downcase}_dialogs")) | ||
end | ||
|
||
it 'sets default dialog_name_prefix' do | ||
ae_service.root['platform'] = nil | ||
described_class.new(ae_service).main | ||
expect(ae_service.object['dialog_name_prefix']).to(eq("miq_provision_vmware_dialogs")) | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@pkomanek
Have you run it with export CI=1
and seen the coverage
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.
@mkanoor
Yes, I did. All lines are covered (except the last condition outside the class and modules).