From 997b38503b1ced8acab031bbaa24f3d82f1c6336 Mon Sep 17 00:00:00 2001 From: Tao Yang Date: Fri, 2 Mar 2018 17:46:14 +0800 Subject: [PATCH] VMware: fix TypeError while get console log nova.privsep.path.last_bytes needs path instead of FILE. Change-Id: Ifad71b4583b23ff018d757760a7b79f7f838c755 Closes-Bug: #1752824 (cherry picked from commit 87a6bb4184efb0e7da2d8a7ad7f189a3bc4cf03e) --- nova/tests/unit/virt/vmwareapi/test_driver_api.py | 10 ++++------ nova/virt/vmwareapi/driver.py | 7 +++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/nova/tests/unit/virt/vmwareapi/test_driver_api.py b/nova/tests/unit/virt/vmwareapi/test_driver_api.py index a47cc35c3240..2ec68bb06b58 100644 --- a/nova/tests/unit/virt/vmwareapi/test_driver_api.py +++ b/nova/tests/unit/virt/vmwareapi/test_driver_api.py @@ -1705,16 +1705,14 @@ class VMwareAPIVMTestCase(test.NoDBTestCase, self._create_instance() with test.nested( mock.patch('os.path.exists', return_value=True), - mock.patch('{}.open'.format(driver.__name__), create=True), mock.patch('nova.privsep.path.last_bytes') - ) as (fake_exists, fake_open, fake_last_bytes): - fake_open.return_value = mock.MagicMock() - fake_fd = fake_open.return_value.__enter__.return_value + ) as (fake_exists, fake_last_bytes): fake_last_bytes.return_value = b'fira', 0 output = self.conn.get_console_output(self.context, self.instance) fname = self.instance.uuid.replace('-', '') - fake_exists.assert_called_once_with('/opt/vspc/{}'.format(fname)) - fake_last_bytes.assert_called_once_with(fake_fd, + fpath = '/opt/vspc/{}'.format(fname) + fake_exists.assert_called_once_with(fpath) + fake_last_bytes.assert_called_once_with(fpath, driver.MAX_CONSOLE_BYTES) self.assertEqual(b'fira', output) diff --git a/nova/virt/vmwareapi/driver.py b/nova/virt/vmwareapi/driver.py index a78efadb354b..d8a87426f4b6 100644 --- a/nova/virt/vmwareapi/driver.py +++ b/nova/virt/vmwareapi/driver.py @@ -284,10 +284,9 @@ class VMwareVCDriver(driver.ComputeDriver): LOG.warning('The console log is missing. Check your VSPC ' 'configuration', instance=instance) return b"" - with open(path, 'rb') as fp: - read_log_data, remaining = nova.privsep.path.last_bytes( - fp, MAX_CONSOLE_BYTES) - return read_log_data + read_log_data, remaining = nova.privsep.path.last_bytes( + path, MAX_CONSOLE_BYTES) + return read_log_data def _get_vcenter_uuid(self): """Retrieves the vCenter UUID."""