Bug 871086

Summary: template export fails: "error: string indices must be integers, not str"
Product: Red Hat Satellite Reporter: Garik Khachikyan <gkhachik>
Component: katello-agentAssignee: Eric Helms <ehelms>
Status: CLOSED ERRATA QA Contact: Garik Khachikyan <gkhachik>
Severity: high Docs Contact:
Priority: unspecified    
Version: 6.0.1CC: achan, cwelton, jlaska, mkoci, mmccune
Target Milestone: UnspecifiedKeywords: Regression, Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
When attempting to export a TDL, and a repository and distributions were not specified, an exception would be shown. This was due to the internal template controller expecting these values to be filled in. This was solved by allowing specific errors to propagate back to the command line interface when the template export fails.
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-12-04 19:57:33 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
katello logs none

Description Garik Khachikyan 2012-10-29 15:19:40 UTC
Created attachment 635047 [details]
katello logs

Description of problem:
CLI call `template export` is broken and returns an exception:
---
error: string indices must be integers, not str (more in the log file /var/log/katello/client.log)
---

Version-Release number of selected component (if applicable):
katello-1.1.12-18.el6cf.noarch
katello-cli-1.1.8-10.el6cf.noarch


How reproducible:
always

Steps to Reproduce:
client remeber your org & create an env: testing

alias kk="katello -uadmin -padmin"
kk template create --name temp1
kk template update --add_parameter hostname --value localhost --name temp1
kk changeset create --name cs2 --environment testing
kk changeset update --add_template temp1 --name cs2 --environment testing
kk changeset promote --name cs2 --environment testing
kk template export --name temp1 --format tdl --file /tmp/temp1.tdl --environment testing
  
Actual results:
error: string indices must be integers, not str (more in the log file /var/log/katello/client.log)

Expected results:
no error, template should get exported (as expected)

Additional info:
katello logs are attached in tarball.

Comment 1 Garik Khachikyan 2012-10-30 12:41:57 UTC
btw: seems that --format json is ok and the problem is with TDL format only.

Comment 2 James Laska 2012-10-31 12:42:06 UTC
I'm not experiencing this problem using the following snap#6 packages ...
* katello-1.1.12-18.el6cf.noarch
* katello-cli-1.1.8-10.el6cf.noarch

> # TEMPLATE=rhel-x86_64-5.8-cf-tools
> # kk template export --environment Dev --org redhat --name "${TEMPLATE}" --file "/var/www/html/templates/Dev/${TEMPLATE}.xml" --format tdl
> Template was exported successfully to file /var/www/html/templates/Dev/rhel-x86_64-5.8-cf-tools.xml


From your /var/log/katello/client.log ...
> 2012-10-29 11:17:55,553 [ERROR][MainThread] error() @ base.py:189 - string indices must be integers, not str
> 2012-10-29 11:17:55,553 [ERROR][MainThread] error() @ base.py:190 - Traceback (most recent call last):
>   File "/usr/lib/python2.6/site-packages/katello/client/cli/base.py", line 202, in main
>     ret_code = super(KatelloCLI, self).main(args, command_name, parent_usage)
>   File "/usr/lib/python2.6/site-packages/katello/client/core/base.py", line 298, in main
>     return subcommand.main(self.args[1:], self.args[0], self._get_usage_line(command_name, parent_usage))
>   File "/usr/lib/python2.6/site-packages/katello/client/core/base.py", line 298, in main
>     return subcommand.main(self.args[1:], self.args[0], self._get_usage_line(command_name, parent_usage))
>   File "/usr/lib/python2.6/site-packages/katello/client/core/base.py", line 392, in main
>     msg = ", ".join(re.args[1]["errors"])
> TypeError: string indices must be integers, not str


This is an error while trying to display an authentication credential error.  Specifically, your auth credentials have failed, and katello is attempting to report that.  

Can you recreate the bug ... but modify /usr/lib/python2.6/site-packages/katello/client/core/base.py ... line#392 

>                     msg = "%s" % re

Comment 3 Garik Khachikyan 2012-10-31 13:24:50 UTC
James,

I did followed exactly the same steps in comment#0.

The alias called kk="katello -uadmin -padmin" is prepared. Also: the one with --format=json is working fine.

So not sure what kind of authentication issue could be there.

I think it is an issue in code that needs to be fixed by developers.

Comment 6 Mike McCune 2012-10-31 18:49:40 UTC
Assigned Eric, will report back on our findings

Comment 7 Eric Helms 2012-11-01 02:09:33 UTC
After following the steps above and perusing the logs, the issue here is not as it seems and is two fold.

1) The steps outlined above should NOT result in an exported TDL (in either xml or json). A TDL requires at least one product and exactly one distribution present.  The steps above contain neither, and thus the user should be presented with: 

"Template cannot be exported: At least repository must be present to export a TDL, Exactly one distribution must be present to export a TDL"

This error message is being improperly handled by the CLI and thus throwing an error.  This is evident by examining the production.log and if you attempt to export the above system template in the UI the user will be presented with the same error notification.

2) The CLI allows for exporting as JSON while the UI does not.  Examining the code for export via JSON, we are not calling the TDL validation code and thus when attempting to export an empty template as JSON the operation succeeds.  But produces an invalid TDL.

Comment 8 Mike McCune 2012-11-01 14:25:49 UTC
Lets fix the CLI code such that it actually renders the correct error message.

Comment 9 Eric Helms 2012-11-02 15:04:55 UTC
Issue fixed as of 754635c7398df598906ab0d2af96f2bcc66dfe54

See also https://github.com/Katello/katello/pull/986

This updates to allow the proper validation error to be displayed to user when using the CLI to export a template that does not meet the criteria of:

1) Having a single distribution
2) Having at least one product

Comment 13 Garik Khachikyan 2012-11-06 16:57:45 UTC
# COMMENT 

the error message part is verified: it correctly now replies: one need to have distribution and repo there.

will check the correct workflow too :)

Comment 14 Corey Welton 2012-11-06 20:24:36 UTC
QE Verified:

[root@se-rhelbox ~]# kk template export --name temp1 --format tdl --file /tmp/temp1.tdl --environment dev --org org2
Template cannot be exported: At least repository must be present to export a TDL, Exactly one distribution must be present to export a TDL


CloudForms System Engine Version: 1.1.12-20.el6cf

Comment 16 errata-xmlrpc 2012-12-04 19:57:33 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.

http://rhn.redhat.com/errata/RHSA-2012-1543.html

Comment 17 Mike McCune 2013-08-16 18:20:36 UTC
getting rid of 6.0.0 version since that doesn't exist