Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Fixed
is checked out). (improvement) #4366
* st2 login now exits with non zero exit code when login fails due to invalid credentials.
(improvement) #4338
* Fix ``st2 key load`` that errors when importing an empty file #4393

2.9.0 - September 16, 2018
--------------------------
Expand Down
6 changes: 5 additions & 1 deletion st2client/st2client/commands/keyvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,16 @@ def run(self, args, **kwargs):
# load the data (JSON/YAML) from the file
kvps = resource.load_meta_file(file_path)

instances = []
# bail out if file was empty
if not kvps:
return instances

# if the data is not a list (ie. it's a single entry)
# then make it a list so our process loop is generic
if not isinstance(kvps, list):
kvps = [kvps]

instances = []
for item in kvps:
# parse required KeyValuePair properties
name = item['name']
Expand Down
14 changes: 14 additions & 0 deletions st2client/tests/unit/test_keyvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,17 @@ def test_load_keyvalue_bad_file_extension(self):
finally:
os.close(fd)
os.unlink(path)

def test_load_keyvalue_empty_file(self):
"""
Loading K/V from an empty file shouldn't throw an error
"""
fd, path = tempfile.mkstemp(suffix='.yaml')
try:
args = ['key', 'load', path]
retcode = self.shell.run(args)
self.assertIn('No matching items found', self.stdout.getvalue())
self.assertEqual(retcode, 0)
finally:
os.close(fd)
os.unlink(path)