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."""