-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12212 from pkomanek/refactoring_available_resourc…
…e_groups Refactoring available_resource_groups method for miq_ae_orchestrations
- Loading branch information
Showing
3 changed files
with
148 additions
and
93 deletions.
There are no files selected for viewing
68 changes: 52 additions & 16 deletions
68
...eIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_resource_groups.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,25 +1,61 @@ | ||
# | ||
# Description: provide the dynamic list content from available resource groups | ||
# | ||
rg_list = {nil => "<New resource group>"} | ||
service = $evm.root.attributes["service_template"] || $evm.root.attributes["service"] | ||
if service.respond_to?(:orchestration_manager) && service.orchestration_manager | ||
service.orchestration_manager.resource_groups.each { |t| rg_list[t.name] = t.name } | ||
end | ||
module ManageIQ | ||
module Automate | ||
module Cloud | ||
module Orchestration | ||
module Operations | ||
class AvailableResoureceGroups | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
end | ||
|
||
def main | ||
fill_dialog_field(fetch_list_data) | ||
end | ||
|
||
private | ||
|
||
def fetch_list_data | ||
service = @handle.root.attributes["service_template"] || @handle.root.attributes["service"] | ||
rs_groups = service.try(:orchestration_manager).try(:resource_groups) | ||
|
||
rs_list = {} | ||
rs_groups.each { |rs| rs_list[rs.name] = rs.name } if rs_groups | ||
|
||
return nil => "<none>" if rs_list.blank? | ||
|
||
dialog_field = $evm.object | ||
rs_list[nil] = "<select>" if rs_list.length > 1 | ||
rs_list | ||
end | ||
|
||
# sort_by: value / description / none | ||
dialog_field["sort_by"] = "description" | ||
def fill_dialog_field(list) | ||
dialog_field = @handle.object | ||
|
||
# sort_order: ascending / descending | ||
dialog_field["sort_order"] = "ascending" | ||
# sort_by: value / description / none | ||
dialog_field["sort_by"] = "description" | ||
|
||
# data_type: string / integer | ||
dialog_field["data_type"] = "string" | ||
# sort_order: ascending / descending | ||
dialog_field["sort_order"] = "ascending" | ||
|
||
# required: true / false | ||
dialog_field["required"] = "false" | ||
# data_type: string / integer | ||
dialog_field["data_type"] = "string" | ||
|
||
dialog_field["values"] = rg_list | ||
dialog_field["default_value"] = nil | ||
# required: true / false | ||
dialog_field["required"] = "false" | ||
|
||
dialog_field["values"] = list | ||
|
||
dialog_field["default_value"] = list.length == 1 ? list.keys.first : nil | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
if __FILE__ == $PROGRAM_NAME | ||
ManageIQ::Automate::Cloud::Orchestration::Operations::AvailableResoureceGroups.new.main | ||
end |
77 changes: 0 additions & 77 deletions
77
spec/automation/unit/method_validation/available_resource_groups_spec.rb
This file was deleted.
Oops, something went wrong.
96 changes: 96 additions & 0 deletions
96
...loud/Orchestration/Operations/Methods.class/__methods__/available_resource_groups_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,96 @@ | ||
require Rails.root.join('db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations' \ | ||
'/Methods.class/__methods__/available_resource_groups.rb').to_s | ||
|
||
describe ManageIQ::Automate::Cloud::Orchestration::Operations::AvailableResoureceGroups do | ||
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 | ||
|
||
shared_examples_for "#having only default value" do | ||
let(:default_desc_blank) { "<none>" } | ||
|
||
it "provides only default value to the resource group list" do | ||
described_class.new(ae_service).main | ||
|
||
expect(ae_service["values"]).to eq(nil => default_desc_blank) | ||
end | ||
end | ||
|
||
shared_examples_for "#having all of the resource groups" do | ||
let(:default_desc) { "<select>" } | ||
let(:rgroup1) { FactoryGirl.create(:resource_group) } | ||
let(:rgroup2) { FactoryGirl.create(:resource_group) } | ||
let(:ems) do | ||
FactoryGirl.create(:ems_azure, :resource_groups => [rgroup1, rgroup2]) | ||
end | ||
|
||
it "finds all the resource groups and populates the list" do | ||
described_class.new(ae_service).main | ||
|
||
expect(ae_service["values"]).to include( | ||
nil => default_desc, | ||
rgroup1.name => rgroup1.name, | ||
rgroup2.name => rgroup2.name) | ||
end | ||
end | ||
|
||
context "workspace has no service template" do | ||
let(:root_hash) { {} } | ||
|
||
it_behaves_like "#having only default value" | ||
end | ||
|
||
context "workspace has service template other than orchestration" do | ||
let(:service_template) { FactoryGirl.create(:service_template) } | ||
|
||
it_behaves_like "#having only default value" | ||
end | ||
|
||
context "workspace has orchestration service template" do | ||
context 'with orchestration_manager' do | ||
let(:service_template) do | ||
FactoryGirl.create(:service_template_orchestration, :orchestration_manager => ems) | ||
end | ||
|
||
it_behaves_like "#having all of the resource groups" | ||
end | ||
|
||
context 'without orchestration_manager' do | ||
let(:service_template) do | ||
FactoryGirl.create(:service_template_orchestration) | ||
end | ||
|
||
it_behaves_like "#having only default value" | ||
end | ||
end | ||
|
||
context "workspace has orchestration service" do | ||
let(:root_hash) do | ||
{ 'service_template' => MiqAeMethodService::MiqAeServiceService.find(service_template.id) } | ||
end | ||
|
||
context 'with orchestration_manager' do | ||
let(:service_template) do | ||
FactoryGirl.create(:service_orchestration, :orchestration_manager => ems) | ||
end | ||
|
||
it_behaves_like "#having all of the resource groups" | ||
end | ||
|
||
context 'without orchestration_manager' do | ||
let(:service_template) do | ||
FactoryGirl.create(:service_orchestration) | ||
end | ||
|
||
it_behaves_like "#having only default value" | ||
end | ||
end | ||
end |