Bug 1134526

Summary: hammer import template-snippet fails with TypeError:can't convert nil into String while processing CSV line
Product: Red Hat Satellite Reporter: Lukas Pramuk <lpramuk>
Component: TransitionsAssignee: Tomas Lestach <tlestach>
Status: CLOSED CURRENTRELEASE QA Contact: Roman Plevka <rplevka>
Severity: medium Docs Contact: Roman Plevka <rplevka>
Priority: unspecified    
Version: UnspecifiedCC: bkearney, cperry, ggainey, rplevka
Target Milestone: UnspecifiedKeywords: Reopened
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-08-12 13:56:46 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:
Bug Depends On:    
Bug Blocks: 1125243    

Description Lukas Pramuk 2014-08-27 16:43:25 UTC
Description of problem:
hammer import template-snippet fails with TypeError:can't convert nil into String while processing CSV line when importing from an empty csv file.

Version-Release number of selected component (if applicable):
rubygem-hammer_cli_import-0.10.2-1.el6.noarch

How reproducible:
100%

Steps to Reproduce:
0. prepare an empty kickstart-scripts.csv with just header there
1. # hammer import template-snippet --verbose --csv-file /tmp/exports/kickstart-scripts.csv
Importing from /tmp/exports/kickstart-scripts.csv
Caught TypeError:can't convert nil into String while processing CSV line:
{"data"=>nil, "chroot"=>nil, "script_type"=>nil, "script_name"=>nil, "interpreter"=>nil, "kickstart_label"=>nil, "org_id"=>nil, "position"=>nil, "id"=>nil}
/usr/lib/ruby/gems/1.8/gems/hammer_cli_import-0.10.2/lib/hammer_cli_import/templatesnippet.rb:41:in `+'
/usr/lib/ruby/gems/1.8/gems/hammer_cli_import-0.10.2/lib/hammer_cli_import/templatesnippet.rb:41:in `mk_snippet_hash'
/usr/lib/ruby/gems/1.8/gems/hammer_cli_import-0.10.2/lib/hammer_cli_import/templatesnippet.rb:57:in `import_single_row'
/usr/lib/ruby/gems/1.8/gems/hammer_cli_import-0.10.2/lib/hammer_cli_import/base.rb:471:in `call'
/usr/lib/ruby/gems/1.8/gems/hammer_cli_import-0.10.2/lib/hammer_cli_import/base.rb:471:in `cvs_iterate'
/usr/lib/ruby/gems/1.8/gems/hammer_cli_import-0.10.2/lib/hammer_cli_import/importtools.rb:295:in `call'
/usr/lib/ruby/gems/1.8/gems/hammer_cli_import-0.10.2/lib/hammer_cli_import/importtools.rb:295:in `handle_missing_and_supress'
/usr/lib/ruby/gems/1.8/gems/hammer_cli_import-0.10.2/lib/hammer_cli_import/base.rb:470:in `cvs_iterate'
/usr/lib/ruby/gems/1.8/gems/hammer_cli_import-0.10.2/lib/hammer_cli_import/csvhelper.rb:52:in `csv_each'
/usr/lib/ruby/gems/1.8/gems/fastercsv-1.5.4/lib/faster_csv.rb:1545:in `each'
/usr/lib/ruby/gems/1.8/gems/hammer_cli_import-0.10.2/lib/hammer_cli_import/csvhelper.rb:43:in `csv_each'
/usr/lib/ruby/gems/1.8/gems/hammer_cli_import-0.10.2/lib/hammer_cli_import/base.rb:469:in `cvs_iterate'
/usr/lib/ruby/gems/1.8/gems/hammer_cli_import-0.10.2/lib/hammer_cli_import/base.rb:477:in `import'
/usr/lib/ruby/gems/1.8/gems/hammer_cli_import-0.10.2/lib/hammer_cli_import/base.rb:513:in `execute'
/usr/lib/ruby/gems/1.8/gems/clamp-0.6.2/lib/clamp/command.rb:67:in `run'
/usr/lib/ruby/gems/1.8/gems/hammer_cli-0.1.1/lib/hammer_cli/./apipie/../abstract.rb:22:in `run'
/usr/lib/ruby/gems/1.8/gems/clamp-0.6.2/lib/clamp/subcommand/execution.rb:11:in `execute'
/usr/lib/ruby/gems/1.8/gems/clamp-0.6.2/lib/clamp/command.rb:67:in `run'
/usr/lib/ruby/gems/1.8/gems/hammer_cli-0.1.1/lib/hammer_cli/./apipie/../abstract.rb:22:in `run'
/usr/lib/ruby/gems/1.8/gems/clamp-0.6.2/lib/clamp/subcommand/execution.rb:11:in `execute'
/usr/lib/ruby/gems/1.8/gems/clamp-0.6.2/lib/clamp/command.rb:67:in `run'
/usr/lib/ruby/gems/1.8/gems/hammer_cli-0.1.1/lib/hammer_cli/./apipie/../abstract.rb:22:in `run'
/usr/lib/ruby/gems/1.8/gems/clamp-0.6.2/lib/clamp/command.rb:125:in `run'
/usr/lib/ruby/gems/1.8/gems/hammer_cli-0.1.1/bin/hammer:102
/usr/bin/hammer:19:in `load'
/usr/bin/hammer:19
Summary
  No action taken.


Actual results:
traceback shown

Expected results:
no traceback

Comment 1 RHEL Program Management 2014-08-27 16:53:15 UTC
Since this issue was entered in Red Hat Bugzilla, the release flag has been
set to ? to ensure that it is properly evaluated for this release.

Comment 3 Tomas Lestach 2014-08-28 15:14:28 UTC
Having empty csv file
$ cat data/kss.csv
id,org_id,script_name,kickstart_id,kickstart_label,position,script_type,chroot,interpreter,data
$ hammer import template-snippet --verbose --csv-file data/kss.csv --verbose
Importing from data/kss.csv
Summary
  No action taken.

what looks good.


Having (note the extra empty line)
$ cat data/kss.csv
id,org_id,script_name,kickstart_id,kickstart_label,position,script_type,chroot,interpreter,data

$ hammer import template-snippet --verbose --csv-file data/kss.csv --verbose
fails with the reported exception. But this is *not* a valid csv file.

Closing NOTABUG.

Comment 4 Grant Gainey 2015-05-15 14:53:45 UTC
But we fixed it anyway:

hammer_cli_import.github 0d2b0d19dbfe0301ca8cc2b1d93b4f274c674dca

    prevent nil exception
    addressing:
    Caught TypeError:no implicit conversion of nil into String while processing CSV line:
    ...
    /usr/share/gems/gems/hammer_cli_import-0.10.6.3/lib/hammer_cli_import/templatesnippet.rb:41:in `+'
    /usr/share/gems/gems/hammer_cli_import-0.10.6.3/lib/hammer_cli_import/templatesnippet.rb:41:in `mk_snippet_hash'
    /usr/share/gems/gems/hammer_cli_import-0.10.6.3/lib/hammer_cli_import/templatesnippet.rb:57:in `import_single_row'
    /usr/share/gems/gems/hammer_cli_import-0.10.6.3/lib/hammer_cli_import/base.rb:511:in `call'
    /usr/share/gems/gems/hammer_cli_import-0.10.6.3/lib/hammer_cli_import/base.rb:511:in `block (2 levels) in cvs_iterate'
    /usr/share/gems/gems/hammer_cli_import-0.10.6.3/lib/hammer_cli_import/importtools.rb:302:in `call'
    /usr/share/gems/gems/hammer_cli_import-0.10.6.3/lib/hammer_cli_import/importtools.rb:302:in `handle_missing_and_supress'
    /usr/share/gems/gems/hammer_cli_import-0.10.6.3/lib/hammer_cli_import/base.rb:510:in `block in cvs_iterate'
    ...

Comment 7 Roman Plevka 2015-05-21 12:46:33 UTC
VERIFIED.

reproduced with ver: hammer_cli_import (0.10.6)
tested with version: hammer_cli_import (0.10.14)

# cat kickstart-scripts2.csv 
id,org_id,script_name,kickstart_id,kickstart_label,position,script_type,chroot,interpreter,data

#
# hammer import template-snippet --verbose --csv-file kickstart-scripts2.csv
Importing from kickstart-scripts2.csv
Creating new template snippet: ----
Summary
  Created 1 template snippet.

The patch has a side effect though.
An empty snippet is being created:

# hammer template list
---|-------------------------------|----------
ID | NAME                          | TYPE     
---|-------------------------------|----------
51 | ----                          | snippet  
---|-------------------------------|----------


I believe a proper csv validation is needed to be implemented for all the import subcommands. I've filed another ticket for this: BZ #1223776

Comment 8 Bryan Kearney 2015-08-11 13:30:37 UTC
This bug is slated to be released with Satellite 6.1.

Comment 9 Bryan Kearney 2015-08-12 13:56:46 UTC
This bug was fixed in version 6.1.1 of Satellite which was released on 12 August, 2015.