diff options
author | Zuul <zuul@review.openstack.org> | 2019-03-28 23:02:17 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2019-03-28 23:02:17 +0000 |
commit | aa52486f21c7f4959fa6837afe8c5bc83eafdc31 (patch) | |
tree | cb5cac7f00357fbf863bf6869a42da17c79506df | |
parent | d2b913f505d317d0aaf09c8034692a988fded242 (diff) | |
parent | 777ca6f22da405641a685b444dbfc39a93886b0b (diff) | |
download | python-novaclient-aa52486f21c7f4959fa6837afe8c5bc83eafdc31.tar.gz |
Merge "Follow up "Fix up userdata argument to rebuild"" into stable/queens
-rw-r--r-- | novaclient/tests/unit/v2/test_shell.py | 7 | ||||
-rw-r--r-- | novaclient/v2/shell.py | 9 | ||||
-rw-r--r-- | releasenotes/notes/fix-rebuild-userdata-9315e5784feb8ba9.yaml | 5 |
3 files changed, 14 insertions, 7 deletions
diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py index 8bdacda2..667ee6a0 100644 --- a/novaclient/tests/unit/v2/test_shell.py +++ b/novaclient/tests/unit/v2/test_shell.py @@ -1622,8 +1622,11 @@ class ShellTest(utils.TestCase): 'no_such_file') cmd = ('rebuild sample-server %s --user-data %s' % (FAKE_UUID_1, invalid_file)) - self.assertRaises(exceptions.CommandError, self.run_command, cmd, - api_version='2.57') + ex = self.assertRaises(exceptions.CommandError, self.run_command, cmd, + api_version='2.57') + self.assertIn("Can't open '%(user_data)s': " + "[Errno 2] No such file or directory: '%(user_data)s'" % + {'user_data': invalid_file}, six.text_type(ex)) def test_rebuild_unset_user_data(self): self.run_command('rebuild sample-server %s --user-data-unset' % diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py index b47ba6dc..1d85194b 100644 --- a/novaclient/v2/shell.py +++ b/novaclient/v2/shell.py @@ -397,7 +397,8 @@ def _boot(cs, args): for f in args.files: try: dst, src = f.split('=', 1) - files[dst] = open(src) + with open(src) as fo: + files[dst] = fo.read() except IOError as e: raise exceptions.CommandError( _("Can't open '%(src)s': %(exc)s") % @@ -415,7 +416,8 @@ def _boot(cs, args): if args.user_data: try: - userdata = open(args.user_data) + with open(args.user_data) as f: + userdata = f.read() except IOError as e: raise exceptions.CommandError(_("Can't open '%(user_data)s': " "%(exc)s") % @@ -1851,7 +1853,8 @@ def do_rebuild(cs, args): "'--user-data'.")) elif args.user_data: try: - kwargs['userdata'] = open(args.user_data) + with open(args.user_data) as f: + kwargs['userdata'] = f.read() except IOError as e: raise exceptions.CommandError( _("Can't open '%(user_data)s': %(exc)s") % { diff --git a/releasenotes/notes/fix-rebuild-userdata-9315e5784feb8ba9.yaml b/releasenotes/notes/fix-rebuild-userdata-9315e5784feb8ba9.yaml index 4d540758..32065a11 100644 --- a/releasenotes/notes/fix-rebuild-userdata-9315e5784feb8ba9.yaml +++ b/releasenotes/notes/fix-rebuild-userdata-9315e5784feb8ba9.yaml @@ -1,5 +1,6 @@ --- fixes: - | - The user data argument to rebuild was passing the filename as is as userdata. - Now this passes the contents of the filename as intended. + The user data argument in the ``nova rebuild`` command was passing + the filename as userdata. Now this passes the contents of the file + as intended. |