diff options
author | Takashi NATSUME <natsume.takashi@lab.ntt.co.jp> | 2018-10-04 12:02:07 +0900 |
---|---|---|
committer | Matt Riedemann <mriedem.os@gmail.com> | 2018-10-24 11:53:05 -0400 |
commit | 087af50d8a76adb0f00ca8e55473923dc61c5106 (patch) | |
tree | d0627672454177d9b568c34c17261e53fc4d7350 | |
parent | 5610ebd10d18ac6db204d31e8b4341a33a31e327 (diff) | |
download | python-novaclient-087af50d8a76adb0f00ca8e55473923dc61c5106.tar.gz |
Follow up "Fix up userdata argument to rebuild"
This patch is a follow-up patch for
I9752d849aa0e6cf608db0def3ca89565cff4debc.
* Add checking a message of an exception in the unit test
* Add 'with' statement when opening a file
* Fix descriptions in the release note
Change-Id: I2c399490f320a202b41a8f8d36710a36621c4853
(cherry picked from commit 47dc339ab9bb2985d750dae11d0b3b8b2c85d2b2)
-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 3d07ade8..ac63b66c 100644 --- a/novaclient/tests/unit/v2/test_shell.py +++ b/novaclient/tests/unit/v2/test_shell.py @@ -1756,8 +1756,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 4f713906..e7a856ec 100644 --- a/novaclient/v2/shell.py +++ b/novaclient/v2/shell.py @@ -398,7 +398,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") % @@ -416,7 +417,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") % @@ -1895,7 +1897,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. |