Skip to content
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 available_os_types method for miq_ae_orchestrations. #12211

Merged
merged 2 commits into from
Nov 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,28 +1,58 @@
#
# Description: provide the dynamic list content from available operating systems
#
os_list = {'unknown' => '<Unknown>', 'linux' => 'Linux', 'windows' => 'Windows'}
selected_os = 'unknown'
module ManageIQ
module Automate
module Cloud
module Orchestration
module Operations
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

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

dialog_field = $evm.object
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_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
end
end
end
end
end

if __FILE__ == $PROGRAM_NAME
ManageIQ::Automate::Cloud::Orchestration::Operations::AvailableOsTypes.new.main
end

This file was deleted.

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