Fixup uses of mock in hyperv tests
I ended poking around a bit after mock 1.1.4. The current skip is fixable by using a stateful side effect - the only reason the test ever worked before is that mock 1.0.1 returned the same data from every read call, which was explicitly fixed in Python 3.4. However one of the other 'fixes' was buggy: it works by making the strings match up but the code under test can be broken by not doing the second open/read and it will still pass : thus the test is invalid and should be skipped to avoid incorrect coverage stats. Change-Id: Idec1b6b24e6d9d4a7567ae1f7753bffb9cb8bd5b Closes-Bug: #1473401
This commit is contained in:
parent
00f85052b5
commit
3f9927e399
|
@ -14,7 +14,6 @@
|
|||
|
||||
import mock
|
||||
from oslo_utils import units
|
||||
import testtools
|
||||
|
||||
from nova import test
|
||||
from nova.virt.hyperv import constants
|
||||
|
@ -243,12 +242,18 @@ class VHDUtilsTestCase(VHDUtilsBaseTestCase):
|
|||
self.assertEqual(constants.DISK_FORMAT_VHDX, format)
|
||||
|
||||
def test_get_vhd_format_vhd(self):
|
||||
raise testtools.TestCase.skipException("Bug 1473401")
|
||||
with mock.patch('nova.virt.hyperv.vhdutils.open',
|
||||
mock.mock_open(read_data=vhdutils.VHD_SIGNATURE),
|
||||
mock.mock_open(),
|
||||
create=True) as mock_open:
|
||||
f = mock_open.return_value
|
||||
f.tell.return_value = 1024
|
||||
readdata = ['notthesig', vhdutils.VHD_SIGNATURE]
|
||||
|
||||
def read(*args):
|
||||
for content in readdata:
|
||||
yield content
|
||||
|
||||
f.read.side_effect = read()
|
||||
|
||||
format = self._vhdutils.get_vhd_format(self._FAKE_VHD_PATH)
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import mock
|
|||
from oslo_concurrency import processutils
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import units
|
||||
import unittest2
|
||||
|
||||
from nova import exception
|
||||
from nova.tests.unit import fake_instance
|
||||
|
@ -965,6 +966,7 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
|
|||
self._vmops._MAX_CONSOLE_LOG_FILE_SIZE)
|
||||
fake_iothread.return_value.start.assert_called_once_with()
|
||||
|
||||
@unittest2.skip('mock_open in 1.2 read only works once 1475661')
|
||||
@mock.patch("os.path.exists")
|
||||
def test_get_console_output(self, fake_path_exists):
|
||||
mock_instance = fake_instance.fake_instance_obj(self.context)
|
||||
|
@ -974,7 +976,7 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
|
|||
mock.sentinel.FAKE_PATH, mock.sentinel.FAKE_PATH_ARCHIVED)
|
||||
|
||||
with mock.patch('nova.virt.hyperv.vmops.open',
|
||||
mock.mock_open(read_data=self.FAKE_LOG * 2),
|
||||
mock.mock_open(read_data=self.FAKE_LOG),
|
||||
create=True):
|
||||
instance_log = self._vmops.get_console_output(mock_instance)
|
||||
# get_vm_console_log_paths returns 2 paths.
|
||||
|
|
Loading…
Reference in New Issue