Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1528535 - Job Template Sync fails if taxonomy is used in template
Summary: Job Template Sync fails if taxonomy is used in template
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Remote Execution
Version: 6.3.0
Hardware: x86_64
OS: All
medium
medium
Target Milestone: 6.4.0
Assignee: satellite6-bugs
QA Contact: Jameer Pathan
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-12-22 04:45 UTC by Ranjan Kumar
Modified: 2021-12-10 15:30 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-10-16 19:30:51 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Ranjan Kumar 2017-12-22 04:45:22 UTC
Description of problem: Unable to sync job template when Organization, Location associate based on metadata. 

Version-Release number of selected component (if applicable): 6.3.0 beta

How reproducible: Always

Here is sample job Template

<%#
kind: job_template
name: Package Action - SSH Default
model: JobTemplate
job_category: Packages
organizations:
- Test
locations:
- Redhat
description_format: "%{action} package(s) %{package}"
provider_type: SSH
%>

<%
  supported_families = ['Redhat', 'Debian', 'Suse']
  render_error(N_('Unsupported or no operating system found for this host.')) unless @host.operatingsystem && supported_families.include?(@host.operatingsystem.family)
-%>
#!/bin/bash

# Helper function that exits with a particular message and code.
#
# Usage:
#   exit_with_message "Could not do a thing" 2
#
function exit_with_message {
  echo "${1}, exiting..."
  exit $2
}



Steps to Reproduce:
1. Sync above template in git repository in job_templates directories
2. Run below command to sync template from git repo
#foreman-rake templates:sync repo=https://github.com/ranjan/template.git branch=master verbose=true associate=always dirname=/job_templates prefix=JOB_DEBUG  --trace

Actual results:

** Invoke templates:sync (first_time)
** Invoke templates:import (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute templates:import
rake aborted!
ActiveRecord::AssociationTypeMismatch: Taxonomy(#49368880) expected, got String(#9429080)
/opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/associations/association.rb:218:in `raise_on_type_mismatch!'
/opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/associations/collection_association.rb:365:in `block in replace'
/opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/associations/collection_association.rb:365:in `each'
/opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/associations/collection_association.rb:365:in `replace'
/opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/associations/collection_association.rb:47:in `writer'
/opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/associations/builder/association.rb:123:in `organizations='
/opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/attribute_assignment.rb:54:in `public_send'
/opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/attribute_assignment.rb:54:in `_assign_attribute'
/opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/attribute_assignment.rb:41:in `block in assign_attributes'
/opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/attribute_assignment.rb:35:in `each'
/opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/attribute_assignment.rb:35:in `assign_attributes'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_remote_execution-1.3.7/app/models/job_template.rb:103:in `block in import_parsed'
/opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
/opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/transactions.rb:220:in `transaction'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_remote_execution-1.3.7/app/models/job_template.rb:88:in `import_parsed'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_remote_execution-1.3.7/app/models/job_template_importer.rb:12:in `import!'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_remote_execution-1.3.7/app/models/job_template.rb:83:in `import!'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_templates-5.0.1/app/services/foreman_templates/template_importer.rb:72:in `block in parse_files!'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_templates-5.0.1/app/services/foreman_templates/template_importer.rb:51:in `each'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_templates-5.0.1/app/services/foreman_templates/template_importer.rb:51:in `parse_files!'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_templates-5.0.1/app/services/foreman_templates/template_importer.rb:41:in `import_from_git'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_templates-5.0.1/app/services/foreman_templates/template_importer.rb:20:in `import!'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_templates-5.0.1/lib/tasks/foreman_templates_tasks.rake:27:in `block (2 levels) in <top (required)>'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/opt/rh/rh-ruby23/root/usr/share/ruby/monitor.rb:214:in `mon_synchronize'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:201:in `block in invoke_prerequisites'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:199:in `each'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:199:in `invoke_prerequisites'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
/opt/rh/rh-ruby23/root/usr/share/ruby/monitor.rb:214:in `mon_synchronize'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/opt/rh/rh-ruby23/root/usr/share/gems/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
/opt/rh/rh-ruby23/root/usr/bin/rake:23:in `load'
/opt/rh/rh-ruby23/root/usr/bin/rake:23:in `<main>'
Tasks: TOP => templates:sync => templates:import


Expected results: It should sync job template and associate with orgnizaiton and location based on given metadata

Comment 2 Marek Hulan 2018-03-21 06:23:08 UTC
This should be resolved by http://projects.theforeman.org/issues/22375 which unifies how importing works for all template types.

Comment 3 Jameer Pathan 2018-08-17 10:39:30 UTC
Verified:

# rpm -qa | grep satellite-6.4
satellite-6.4.0-10.beta.el7sat.noarch

@satellite 6.4.0 snap 17

steps:

<%#
kind: job_template
name: Package Action - SSH Default
model: JobTemplate
job_category: Packages
organizations:
- Test
locations:
- Redhat
description_format: "%{action} package(s) %{package}"
provider_type: SSH
%>

<%
  supported_families = ['Redhat', 'Debian', 'Suse']
  render_error(N_('Unsupported or no operating system found for this host.')) unless @host.operatingsystem && supported_families.include?(@host.operatingsystem.family)
-%>
#!/bin/bash

# Helper function that exits with a particular message and code.
#
# Usage:
#   exit_with_message "Could not do a thing" 2
#
function exit_with_message {
  echo "${1}, exiting..."
  exit $2
}

1. Sync above template in git repository in job_templates directories
2. Run below command to sync template from git repo
#foreman-rake templates:sync repo=https://github.com/jameerpathan111/community-template.git branch=develop verbose=true associate=always dirname=/job_templates prefix=JOB_DEBUG  --trace

# hammer job-template info --id 136
ID:            136
Name:          JOB_DEBUGPackage Action - SSH Default
Job Category:  Packages
Provider:      SSH
Type:          job_template
Inputs:        


Locations:     
    Redhat
Organizations: 
    Test



Observation:

It syncs job template and associate it with orgnizaiton and location based on given metadata.

Comment 4 Bryan Kearney 2018-10-16 19:30:51 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2018:2927


Note You need to log in before you can comment on or make changes to this bug.