Skip to content

Commit 39a47d7

Browse files
committed
Update ServiceTemplateTerraformEnterprise
1 parent 043617e commit 39a47d7

File tree

3 files changed

+21
-71
lines changed

3 files changed

+21
-71
lines changed

app/models/manageiq/providers/terraform_enterprise/automation_manager/provision/state_machine.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def succeeded?
3939
end
4040

4141
def mark_as_completed
42-
update_and_notify_parent(:state => 'provisioned')
42+
update_and_notify_parent(:state => "finished", :message => "Stack provision is complete")
4343
signal :finish
4444
end
4545

Lines changed: 7 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,17 @@
11
class ServiceTemplateTerraformEnterprise < ServiceTemplate
2-
include ServiceConfigurationMixin
32
include ServiceTemplateAutomationMixin
43

5-
alias terraform_workspace configuration_script
6-
alias terraform_workspace= configuration_script=
7-
8-
def self.default_provisioning_entry_point(_service_type)
9-
'/AutomationManagement/TerraformEnterprise/Service/Provisioning/StateMachines/Provision/CatalogItemInitialization'
10-
end
11-
12-
def self.default_reconfiguration_entry_point
13-
nil
14-
end
15-
16-
def self.default_retirement_entry_point
17-
nil
18-
end
19-
20-
def self.create_catalog_item(options, _auth_user = nil)
4+
def self.create_catalog_item(options, auth_user = nil)
215
transaction do
226
create_from_options(options).tap do |service_template|
23-
config_info = validate_config_info(options)
24-
25-
service_template.terraform_workspace = if config_info[:configuration_script_id]
26-
ConfigurationScript.find(config_info[:configuration_script_id])
27-
else
28-
config_info[:configuration]
29-
end
7+
config_info = options[:config_info].except(:provision, :retirement, :reconfigure)
308

31-
service_template.create_resource_actions(config_info)
9+
wf_class = ManageIQ::Providers::TerraformEnterprise::AutomationManager::ProvisionWorkflow
10+
wf = wf_class.new(config_info, auth_user)
11+
request = wf.make_request(nil, config_info)
12+
service_template.add_resource(request)
13+
service_template.create_resource_actions(options[:config_info])
3214
end
3315
end
3416
end
35-
36-
def create_subtasks(_parent_service_task, _parent_service)
37-
# no sub task is needed for this service
38-
[]
39-
end
40-
41-
def my_zone
42-
configuration_script.manager.try(:my_zone)
43-
end
44-
45-
def self.validate_config_info(options)
46-
config_info = options[:config_info] || {}
47-
config_info[:provision][:fqname] ||= default_provisioning_entry_point(SERVICE_TYPE_ATOMIC) if config_info.key?(:provision)
48-
49-
raise _("Must provide a configuration_script_id") if config_info[:configuration_script_id].nil?
50-
51-
config_info
52-
end
53-
54-
private
55-
56-
def update_service_resources(config_info, _auth_user = nil)
57-
return if !config_info.key?(:configuration_script_id) || config_info[:configuration_script_id] == configuration_script&.id
58-
59-
service_resources.find_by(:resource_type => 'ConfigurationScriptBase').destroy
60-
self.configuration_script = ConfigurationScriptBase.find(config_info[:configuration_script_id])
61-
end
62-
63-
def validate_update_config_info(options)
64-
super
65-
66-
return unless options.key?(:config_info)
67-
68-
self.class.validate_config_info(options)
69-
end
7017
end

spec/models/service_template_terraform_enterprise_spec.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
RSpec.describe ServiceTemplateTerraformEnterprise do
2-
let(:terraform_enterprise) { FactoryBot.create(:ems_terraform_enterprise) }
3-
let(:configuration_script) { FactoryBot.create(:configuration_script_terraform_enterprise, :manager => terraform_enterprise) }
4-
let(:service_dialog) { FactoryBot.create(:dialog) }
5-
let(:provision_resource_action) { FactoryBot.create(:resource_action, :action => 'Provision') }
2+
let(:user) { FactoryBot.create(:user_with_email_and_group) }
3+
let(:terraform_enterprise) { FactoryBot.create(:ems_terraform_enterprise) }
4+
let(:configuration_script) { FactoryBot.create(:configuration_script_terraform_enterprise, :manager => terraform_enterprise) }
5+
let(:service_dialog) { FactoryBot.create(:dialog) }
6+
let(:provision_resource_action) { FactoryBot.create(:resource_action, :action => 'Provision') }
67
let(:catalog_item_options) do
78
{
89
:name => "Terraform Enterprise",
@@ -11,31 +12,33 @@
1112
:display => "false",
1213
:description => "a description",
1314
:config_info => {
14-
:configuration_script_id => configuration_script.id,
15-
:provision => {
15+
:owner_email => user.email,
16+
:source_id => configuration_script.id,
17+
:provision => {
1618
:fqname => provision_resource_action.fqname,
1719
:dialog_id => service_dialog.id
1820
}
1921
}
2022
}
2123
end
2224

25+
before { MiqDialog.seed }
26+
2327
describe ".create_catalog_item" do
2428
it "creates and returns a terraform enterprise catalog item" do
25-
service_template = described_class.create_catalog_item(catalog_item_options)
29+
service_template = described_class.create_catalog_item(catalog_item_options, user)
2630

2731
expect(service_template.name).to eq("Terraform Enterprise")
2832
expect(service_template.service_resources.count).to eq(1)
2933
expect(service_template.dialogs.first).to eq(service_dialog)
3034
expect(service_template.resource_actions.pluck(:action)).to match_array(%w[Provision])
31-
expect(service_template.configuration_script).to eq(configuration_script)
3235
expect(service_template.config_info).to eq(catalog_item_options[:config_info])
3336
end
3437

3538
it "raises an exception if configuration_script_id is missing" do
36-
catalog_item_options[:config_info].delete(:configuration_script_id)
39+
catalog_item_options[:config_info].delete(:source_id)
3740

38-
expect { described_class.create_catalog_item(catalog_item_options) }
41+
expect { described_class.create_catalog_item(catalog_item_options, user) }
3942
.to raise_error(StandardError, "Must provide a configuration_script_id")
4043
end
4144
end

0 commit comments

Comments
 (0)