From 099bc0c1228671d48312a662415119bfa9dd80ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Kom=C3=A1nek?= Date: Wed, 26 Oct 2016 17:37:09 +0200 Subject: [PATCH 1/2] Refactoring the available_os_types method for the automate Cloud Orchestration. --- .../__methods__/available_os_types.rb | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_os_types.rb b/db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_os_types.rb index af3ba30cf87..7dffdcc7976 100644 --- a/db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_os_types.rb +++ b/db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_os_types.rb @@ -1,28 +1,46 @@ # # Description: provide the dynamic list content from available operating systems # -os_list = {'unknown' => '', 'linux' => 'Linux', 'windows' => 'Windows'} -selected_os = 'unknown' +class AvailableOsTypes + def initialize(handle = $evm) + @handle = handle + end -image_name = $evm.root["dialog_param_userImageName"] -if image_name.present? - selected_img = $evm.vmdb(:miq_template).find_by_uid_ems(image_name) - selected_os = (selected_img.hardware.try(:guest_os) || "unknown").downcase -end + def main + fill_dialog_field(fetch_selected_os) + end + + def fetch_selected_os + selected_os = 'unknown' + image_name = @handle.root["dialog_param_userImageName"] + if image_name.present? + selected_img = @handle.vmdb(:miq_template).find_by_uid_ems(image_name) + selected_os = (selected_img.hardware.try(:guest_os) || "unknown").downcase + end + selected_os + end -dialog_field = $evm.object + def fill_dialog_field(selected_os) + os_list = {'unknown' => '', 'linux' => 'Linux', 'windows' => 'Windows'} + dialog_field = @handle.object -# sort_by: value / description / none -dialog_field["sort_by"] = "description" + # sort_by: value / description / none + dialog_field["sort_by"] = "description" -# sort_order: ascending / descending -dialog_field["sort_order"] = "ascending" + # sort_order: ascending / descending + dialog_field["sort_order"] = "ascending" -# data_type: string / integer -dialog_field["data_type"] = "string" + # data_type: string / integer + dialog_field["data_type"] = "string" -# required: true / false -dialog_field["required"] = "true" + # required: true / false + dialog_field["required"] = "true" -dialog_field["values"] = os_list -dialog_field["default_value"] = selected_os + dialog_field["values"] = os_list + dialog_field["default_value"] = selected_os + end +end + +if __FILE__ == $PROGRAM_NAME + AvailableOsTypes.new.main +end From f49398d1f5c1c935ca92a3d885bf38760314d766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Kom=C3=A1nek?= Date: Wed, 26 Oct 2016 17:38:33 +0200 Subject: [PATCH 2/2] Refactoring the available_os_types spec for the automate Cloud Orchestration. --- .../__methods__/available_os_types.rb | 86 +++++++++++-------- .../available_os_types_spec.rb | 30 ------- .../__methods__/available_os_types_spec.rb | 42 +++++++++ 3 files changed, 91 insertions(+), 67 deletions(-) delete mode 100644 spec/automation/unit/method_validation/available_os_types_spec.rb create mode 100644 spec/db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_os_types_spec.rb diff --git a/db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_os_types.rb b/db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_os_types.rb index 7dffdcc7976..8064021da25 100644 --- a/db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_os_types.rb +++ b/db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_os_types.rb @@ -1,46 +1,58 @@ # # Description: provide the dynamic list content from available operating systems # -class AvailableOsTypes - def initialize(handle = $evm) - @handle = handle - end - - def main - fill_dialog_field(fetch_selected_os) - end - - def fetch_selected_os - selected_os = 'unknown' - image_name = @handle.root["dialog_param_userImageName"] - if image_name.present? - selected_img = @handle.vmdb(:miq_template).find_by_uid_ems(image_name) - selected_os = (selected_img.hardware.try(:guest_os) || "unknown").downcase +module ManageIQ + module Automate + module Cloud + module Orchestration + module Operations + class AvailableOsTypes + def initialize(handle = $evm) + @handle = handle + end + + def main + fill_dialog_field(fetch_selected_os) + end + + private + + def fetch_selected_os + selected_os = 'unknown' + image_name = @handle.root["dialog_param_userImageName"] + if image_name.present? + selected_img = @handle.vmdb(:miq_template).find_by_uid_ems(image_name) + selected_os = (selected_img.hardware.try(:guest_os) || "unknown").downcase + end + selected_os + end + + def fill_dialog_field(selected_os) + os_list = {'unknown' => '', 'linux' => 'Linux', 'windows' => 'Windows'} + dialog_field = @handle.object + + # sort_by: value / description / none + dialog_field["sort_by"] = "description" + + # sort_order: ascending / descending + dialog_field["sort_order"] = "ascending" + + # data_type: string / integer + dialog_field["data_type"] = "string" + + # required: true / false + dialog_field["required"] = "true" + + dialog_field["values"] = os_list + dialog_field["default_value"] = selected_os + end + end + end + end end - selected_os - end - - def fill_dialog_field(selected_os) - os_list = {'unknown' => '', 'linux' => 'Linux', 'windows' => 'Windows'} - dialog_field = @handle.object - - # sort_by: value / description / none - dialog_field["sort_by"] = "description" - - # sort_order: ascending / descending - dialog_field["sort_order"] = "ascending" - - # data_type: string / integer - dialog_field["data_type"] = "string" - - # required: true / false - dialog_field["required"] = "true" - - dialog_field["values"] = os_list - dialog_field["default_value"] = selected_os end end if __FILE__ == $PROGRAM_NAME - AvailableOsTypes.new.main + ManageIQ::Automate::Cloud::Orchestration::Operations::AvailableOsTypes.new.main end diff --git a/spec/automation/unit/method_validation/available_os_types_spec.rb b/spec/automation/unit/method_validation/available_os_types_spec.rb deleted file mode 100644 index 55f6a64d2ec..00000000000 --- a/spec/automation/unit/method_validation/available_os_types_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -describe "Available_Os_Types Method Validation" do - let(:user) { FactoryGirl.create(:user_with_group) } - os_list = {'unknown' => '', 'linux' => 'Linux', 'windows' => 'Windows'} - before do - @ins = "/Cloud/Orchestration/Operations/Methods/Available_Os_Types" - end - - let(:service_template) do - hw1 = FactoryGirl.create(:hardware, :guest_os => 'windows') - @img1 = FactoryGirl.create(:template_openstack, :uid_ems => 'uid1', :hardware => hw1) - - hw2 = FactoryGirl.create(:hardware, :guest_os => 'linux') - @img2 = FactoryGirl.create(:template_openstack, :uid_ems => 'uid2', :hardware => hw2) - - ems = FactoryGirl.create(:ems_openstack, :miq_templates => [@img1, @img2]) - FactoryGirl.create(:service_template_orchestration, :orchestration_manager => ems) - end - - it "provides all os types and default to unknown" do - ws = MiqAeEngine.instantiate("#{@ins}?ServiceTemplate::service_template=#{service_template.id}", user) - expect(ws.root["values"]).to include(os_list) - expect(ws.root["default_value"]).to eq('unknown') - end - - it "provides all os types and auto selects the type based on the user selection of an image" do - ws = MiqAeEngine.instantiate("#{@ins}?ServiceTemplate::service_template=#{service_template.id}&dialog_param_userImageName=uid1", user) - expect(ws.root["values"]).to include(os_list) - expect(ws.root["default_value"]).to eq('windows') - end -end diff --git a/spec/db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_os_types_spec.rb b/spec/db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_os_types_spec.rb new file mode 100644 index 00000000000..0b7ab050d11 --- /dev/null +++ b/spec/db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_os_types_spec.rb @@ -0,0 +1,42 @@ +require Rails.root.join('db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations' \ + '/Methods.class/__methods__/available_os_types.rb').to_s + +describe ManageIQ::Automate::Cloud::Orchestration::Operations::AvailableOsTypes do + os_list = {'unknown' => '', 'linux' => 'Linux', 'windows' => 'Windows'} + let(:service_template) do + hw1 = FactoryGirl.create(:hardware, :guest_os => 'windows') + img1 = FactoryGirl.create(:template_openstack, :uid_ems => 'uid1', :hardware => hw1) + + hw2 = FactoryGirl.create(:hardware, :guest_os => 'linux') + img2 = FactoryGirl.create(:template_openstack, :uid_ems => 'uid2', :hardware => hw2) + + ems = FactoryGirl.create(:ems_openstack, :miq_templates => [img1, img2]) + FactoryGirl.create(:service_template_orchestration, :orchestration_manager => ems) + end + let(:root_hash) do + { 'service_template' => MiqAeMethodService::MiqAeServiceServiceTemplate.find(service_template.id) } + end + 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 "provides all os types and default to unknown" do + described_class.new(ae_service).main + + expect(ae_service["values"]).to include(os_list) + expect(ae_service["default_value"]).to eq('unknown') + end + + it "provides all os types and auto selects the type based on the user selection of an image" do + ae_service.root["dialog_param_userImageName"] = 'uid1' + described_class.new(ae_service).main + + expect(ae_service["values"]).to include(os_list) + expect(ae_service["default_value"]).to eq('windows') + end +end