Skip to content

Commit

Permalink
Merge pull request #16672 from bzwei/unique_jt_name
Browse files Browse the repository at this point in the history
Use UUID to ensure the uniqueness of job template name
(cherry picked from commit 80c69ec)

https://bugzilla.redhat.com/show_bug.cgi?id=1527560
  • Loading branch information
gmcculloug authored and simaishi committed Dec 19, 2017
1 parent e37bb36 commit 137b7e1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
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

0 comments on commit 137b7e1

Please sign in to comment.