Skip to content

Commit

Permalink
Merge pull request #14328 from bzwei/multiple_retirement_eps
Browse files Browse the repository at this point in the history
catalog item accepts remove_resources option
  • Loading branch information
gmcculloug authored Mar 15, 2017
2 parents 0c6b077 + 5183ef0 commit 4d88fff
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
23 changes: 19 additions & 4 deletions app/models/service_template_ansible_playbook.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
class ServiceTemplateAnsiblePlaybook < ServiceTemplateGeneric
RETIREMENT_ENTRY_POINTS = {
'yes_without_playbook' => '/Service/Generic/StateMachines/GenericLifecycle/Retire_Basic_Resource',
'no_without_playbook' => '/Service/Generic/StateMachines/GenericLifecycle/Retire_Basic_Resource_None',
'no_with_playbook' => '/Service/Generic/StateMachines/GenericLifecycle/Retire_Advanced_Resource_None',
'pre_with_playbook' => '/Service/Generic/StateMachines/GenericLifecycle/Retire_Advanced_Resource_Pre',
'post_with_playbook' => '/Service/Generic/StateMachines/GenericLifecycle/Retire_Advanced_Resource_Post'
}.freeze
private_constant :RETIREMENT_ENTRY_POINTS

def self.default_provisioning_entry_point(_service_type)
'/Service/Generic/StateMachines/GenericLifecycle/provision'
end

def self.default_retirement_entry_point
'/Service/Generic/StateMachines/GenericLifecycle/retire'
RETIREMENT_ENTRY_POINTS['yes_without_playbook']
end

def job_template(action)
Expand Down Expand Up @@ -66,7 +75,7 @@ def self.prepare_job_template_and_dialog(action, service_name, description, conf

def self.create_job_templates(service_name, description, config_info, auth_user)
[:provision, :retirement, :reconfigure].each_with_object({}) do |action, hash|
next unless config_info[action]
next unless config_info[action] && config_info[action].key?(:playbook_id)
hash[action] = { :configuration_template => create_job_template("miq_#{service_name}_#{action}", description, config_info[action], auth_user) }
end
end
Expand Down Expand Up @@ -108,10 +117,16 @@ def self.build_parameter_list(name, description, info)
private_class_method :build_parameter_list

def self.validate_config_info(info)
info[:provision][:fqname] ||= default_provisioning_entry_point('atomic') if info.key?(:provision)
info[:retirement][:fqname] ||= default_retirement_entry_point if info.key?(:retirement)
info[:provision][:fqname] ||= default_provisioning_entry_point('atomic') if info.key?(:provision)
info[:reconfigure][:fqname] ||= default_reconfiguration_entry_point if info.key?(:reconfigure)

if info.key?(:retirement)
info[:retirement][:fqname] ||= RETIREMENT_ENTRY_POINTS[info[:retirement][:remove_resources]]
info[:retirement][:fqname] ||= default_retirement_entry_point
else
info[:retirement] = {:fqname => default_retirement_entry_point}
end

# TODO: Add more validation for required fields

info
Expand Down
41 changes: 40 additions & 1 deletion spec/models/service_template_ansible_playbook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
end
end

describe '#create_catalog_item' do
describe '.create_catalog_item' do
it 'creates and returns a catalog item' do
expect(described_class)
.to receive(:create_job_templates).and_return(:provision => {:configuration_template => job_template})
Expand All @@ -147,4 +147,43 @@
expect(service_template.options[:config_info]).to include(saved_options)
end
end

describe '.validate_config_info' do
context 'provisioning entry point is given' do
it 'keeps the given entry point' do
opts = described_class.send(:validate_config_info, :provision => {:fqname => 'a/b/c'})
expect(opts[:provision][:fqname]).to eq('a/b/c')
end
end

context 'provisioning entry point is not given' do
it 'sets the default entry point' do
opts = described_class.send(:validate_config_info, :provision => {})
expect(opts[:provision][:fqname]).to eq(described_class.default_provisioning_entry_point('atomic'))
end
end

context 'retirement entry point is given' do
it 'keeps the given entry point' do
opts = described_class.send(:validate_config_info, :retirement => {:fqname => 'a/b/c'})
expect(opts[:retirement][:fqname]).to eq('a/b/c')
end
end

context 'retirement entry point is not given' do
it 'sets the default entry point' do
opts = described_class.send(:validate_config_info, {})
expect(opts[:retirement][:fqname]).to eq(described_class.default_retirement_entry_point)
end
end

context 'with remove_resources in retirement option' do
it 'sets the corresponding entry point' do
%w(yes_without_playbook no_without_playbook no_with_playbook pre_with_playbook post_with_playbook).each do |opt|
opts = described_class.send(:validate_config_info, :retirement => {:remove_resources => opt})
expect(opts[:retirement][:fqname]).to eq(described_class.const_get(:RETIREMENT_ENTRY_POINTS)[opt])
end
end
end
end
end

0 comments on commit 4d88fff

Please sign in to comment.