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

Use UUID to ensure the uniqueness of job template name #16672

Merged
merged 1 commit into from
Dec 18, 2017
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
Expand Up @@ -15,15 +15,17 @@ def run(options, userid = nil)
# return provider raw object
def raw_create_job_template(options)
job_template_klass = ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScript
job_template_klass.raw_create_in_provider(manager, build_parameter_list(options))
jt_options = build_parameter_list(options)
_log.info("Creating job template with options (#{jt_options})")
job_template_klass.raw_create_in_provider(manager, jt_options)
end

private

def build_parameter_list(options)
params = {
:name => options[:template_name] || "#{name}_#{Time.zone.now.to_i}",
:description => options[:description] || '',
:name => options[:template_name] || "#{name}_#{SecureRandom.uuid}",
:description => options[:description] || "Created on #{Time.zone.now}",
:project => configuration_script_source.manager_ref,
:playbook => name,
:become_enabled => options[:become_enabled].present?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def start
def create_inventory
set_status('creating inventory')

inventory_name = "#{playbook.name}_#{Time.zone.now.to_i}"
inventory_name = "#{playbook.name}_#{SecureRandom.uuid}"

_log.info("Creating inventory #{inventory_name} including hosts (#{options[:hosts]})")
options[:inventory] = ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Inventory
.raw_create_inventory(playbook.manager, inventory_name, options[:hosts]).id
save!
Expand Down Expand Up @@ -162,7 +164,7 @@ def temp_configuration_script
end

def delete_inventory
return unless options[:inventory]
return true unless options[:inventory]
playbook.manager.with_provider_connection do |connection|
connection.api.inventories.find(options[:inventory]).destroy!
end
Expand All @@ -173,6 +175,7 @@ def delete_inventory
end

def delete_job_template
return true unless options[:job_template_ref]
temp_configuration_script.raw_delete_in_provider
rescue => err
# log the error but do not treat the playbook running as failure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
it 'creates an inventory and moves on to create_job_template' do
# Also test signal with queue
subject.send(:minimize_indirect=, false)
expect(SecureRandom).to receive(:uuid).and_return('random-uuid')
expect(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Inventory).to receive(:raw_create_inventory).and_return(double(:id => 'inv1'))
expect(subject).to receive(:queue_signal).with(:create_job_template, :deliver_on => nil)
subject.create_inventory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
)

allow(subject).to receive(:configuration_script_source).and_return(double(:manager_ref => 'mref'))
expect(SecureRandom).to receive(:uuid).and_return('random-uuid')
expect(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScript)
.to receive(:raw_create_in_provider).with(instance_of(manager.class), option_matcher)
subject.raw_create_job_template(options)
Expand Down