-
Notifications
You must be signed in to change notification settings - Fork 896
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring the available_os_types spec for the automate Cloud Orches…
…tration.
- Loading branch information
Showing
3 changed files
with
91 additions
and
67 deletions.
There are no files selected for viewing
86 changes: 49 additions & 37 deletions
86
...e/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_os_types.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,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' => '<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' => '<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 |
30 changes: 0 additions & 30 deletions
30
spec/automation/unit/method_validation/available_os_types_spec.rb
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
...ageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_os_types_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,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' => '<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 |