Decouple NVMe tests from os-brick

The existing tests for NVMe with Libvirt were using
APIs inside of os-brick rather than making sure that
we are calling os-brick with the right values.

This patch mocks up the factory function instead and
makes sure we call it with the right values, it also
adds a few more things to test if the root helper and
`device_scan_attempts` are passed down through to
os-brick as well.

Change-Id: I067f9e29b4db3bba0601041cf3603b9653a240b9
This commit is contained in:
Mohammed Naser 2019-09-06 17:47:20 -04:00
parent 31aa0c58c5
commit e840135a17
1 changed files with 11 additions and 5 deletions

View File

@ -15,16 +15,22 @@ import mock
from nova.tests.unit.virt.libvirt.volume import test_volume
from nova.virt.libvirt.volume import nvme
from os_brick.initiator import connector
from os_brick import initiator
class LibvirtNVMEVolumeDriverTestCase(test_volume.LibvirtVolumeBaseTestCase):
@mock.patch('os.path.exists', return_value=True)
def test_libvirt_nvme_driver(self, exists):
libvirt_driver = nvme.LibvirtNVMEVolumeDriver(self.fake_host)
self.assertIsInstance(libvirt_driver.connector,
connector.NVMeConnector)
@mock.patch('nova.utils.get_root_helper')
@mock.patch('os_brick.initiator.connector.InitiatorConnector.factory')
def test_libvirt_nvme_driver(self, mock_factory, mock_helper, exists):
self.flags(num_nvme_discover_tries=3, group='libvirt')
mock_helper.return_value = 'sudo'
nvme.LibvirtNVMEVolumeDriver(self.fake_host)
mock_factory.assert_called_once_with(
initiator.NVME, 'sudo',
device_scan_attempts=3)
def test_libvirt_nvme_driver_connect(self):
nvme_driver = nvme.LibvirtNVMEVolumeDriver(self.fake_host)