Mock calls to rpm and dpkg from NetApp unit tests

This patch fixes an issue wherein several NetApp unit tests ran
OS rpm or dpkg commands because the callouts to these commands
were not mocked out during driver initialization.

It also replaces 'rpm -qa' with 'rpm -q' when that command is
invoked since the latter also works and is faster.

Closes-Bug: 1393545
Change-Id: I3d5cfeb2ee39ecb6af5b312dfa6c2a585cf8e0e3
This commit is contained in:
Tom Barron
2014-12-09 04:46:29 -05:00
parent 6037adfb4a
commit d555ca100a
4 changed files with 20 additions and 1 deletions

View File

@@ -37,6 +37,8 @@ from cinder.volume.drivers.netapp.options import netapp_cluster_opts
from cinder.volume.drivers.netapp.options import netapp_connection_opts
from cinder.volume.drivers.netapp.options import netapp_provisioning_opts
from cinder.volume.drivers.netapp.options import netapp_transport_opts
from cinder.volume.drivers.netapp import utils
LOG = logging.getLogger("cinder.volume.driver")
@@ -552,6 +554,7 @@ class NetAppDirectCmodeISCSIDriverTestCase(test.TestCase):
self.stubs.Set(
ssc_cmode, 'refresh_cluster_ssc',
lambda a, b, c, synchronous: None)
self.mock_object(utils, 'OpenStackInfo')
configuration = self._set_config(create_configuration())
driver = common.NetAppDriver(configuration=configuration)
self.stubs.Set(httplib, 'HTTPConnection',
@@ -577,6 +580,7 @@ class NetAppDirectCmodeISCSIDriverTestCase(test.TestCase):
self.driver.check_for_setup_error()
def test_do_setup_all_default(self):
self.mock_object(utils, 'OpenStackInfo')
configuration = self._set_config(create_configuration())
driver = common.NetAppDriver(configuration=configuration)
driver.do_setup(context='')
@@ -587,6 +591,7 @@ class NetAppDirectCmodeISCSIDriverTestCase(test.TestCase):
@mock.patch.object(client_base.Client, 'get_ontapi_version',
mock.Mock(return_value=(1, 20)))
def test_do_setup_http_default_port(self):
self.mock_object(utils, 'OpenStackInfo')
configuration = self._set_config(create_configuration())
configuration.netapp_transport_type = 'http'
driver = common.NetAppDriver(configuration=configuration)
@@ -598,6 +603,7 @@ class NetAppDirectCmodeISCSIDriverTestCase(test.TestCase):
@mock.patch.object(client_base.Client, 'get_ontapi_version',
mock.Mock(return_value=(1, 20)))
def test_do_setup_https_default_port(self):
self.mock_object(utils, 'OpenStackInfo')
configuration = self._set_config(create_configuration())
configuration.netapp_transport_type = 'https'
driver = common.NetAppDriver(configuration=configuration)
@@ -610,6 +616,7 @@ class NetAppDirectCmodeISCSIDriverTestCase(test.TestCase):
@mock.patch.object(client_base.Client, 'get_ontapi_version',
mock.Mock(return_value=(1, 20)))
def test_do_setup_http_non_default_port(self):
self.mock_object(utils, 'OpenStackInfo')
configuration = self._set_config(create_configuration())
configuration.netapp_server_port = 81
driver = common.NetAppDriver(configuration=configuration)
@@ -621,6 +628,7 @@ class NetAppDirectCmodeISCSIDriverTestCase(test.TestCase):
@mock.patch.object(client_base.Client, 'get_ontapi_version',
mock.Mock(return_value=(1, 20)))
def test_do_setup_https_non_default_port(self):
self.mock_object(utils, 'OpenStackInfo')
configuration = self._set_config(create_configuration())
configuration.netapp_transport_type = 'https'
configuration.netapp_server_port = 446
@@ -677,6 +685,7 @@ class NetAppDirectCmodeISCSIDriverTestCase(test.TestCase):
raise AssertionError('Target portal is none')
def test_vol_stats(self):
self.mock_object(client_base.Client, 'provide_ems')
stats = self.driver.get_volume_stats(refresh=True)
self.assertEqual(stats['vendor_name'], 'NetApp')
@@ -716,6 +725,7 @@ class NetAppDriverNegativeTestCase(test.TestCase):
super(NetAppDriverNegativeTestCase, self).setUp()
def test_incorrect_family(self):
self.mock_object(utils, 'OpenStackInfo')
configuration = create_configuration()
configuration.netapp_storage_family = 'xyz_abc'
try:
@@ -725,6 +735,7 @@ class NetAppDriverNegativeTestCase(test.TestCase):
pass
def test_incorrect_protocol(self):
self.mock_object(utils, 'OpenStackInfo')
configuration = create_configuration()
configuration.netapp_storage_family = 'ontap'
configuration.netapp_storage_protocol = 'ontap'
@@ -735,6 +746,7 @@ class NetAppDriverNegativeTestCase(test.TestCase):
pass
def test_non_netapp_driver(self):
self.mock_object(utils, 'OpenStackInfo')
configuration = create_configuration()
common.netapp_unified_plugin_registry['test_family'] =\
{'iscsi': 'cinder.volume.drivers.arbitrary.IscsiDriver'}
@@ -1175,6 +1187,7 @@ class NetAppDirect7modeISCSIDriverTestCase_NV(
super(NetAppDirect7modeISCSIDriverTestCase_NV, self).setUp()
def _custom_setup(self):
self.mock_object(utils, 'OpenStackInfo')
configuration = self._set_config(create_configuration())
driver = common.NetAppDriver(configuration=configuration)
self.stubs.Set(httplib, 'HTTPConnection',
@@ -1230,6 +1243,7 @@ class NetAppDirect7modeISCSIDriverTestCase_WV(
super(NetAppDirect7modeISCSIDriverTestCase_WV, self).setUp()
def _custom_setup(self):
self.mock_object(utils, 'OpenStackInfo')
configuration = self._set_config(create_configuration())
driver = common.NetAppDriver(configuration=configuration)
self.stubs.Set(httplib, 'HTTPConnection',

View File

@@ -35,6 +35,7 @@ from cinder.volume.drivers.netapp.eseries.iscsi import LOG as driver_log
from cinder.volume.drivers.netapp.eseries import utils
from cinder.volume.drivers.netapp.options import netapp_basicauth_opts
from cinder.volume.drivers.netapp.options import netapp_eseries_opts
import cinder.volume.drivers.netapp.utils as na_utils
LOG = logging.getLogger(__name__)
@@ -639,6 +640,7 @@ class NetAppEseriesISCSIDriverTestCase(test.TestCase):
self._custom_setup()
def _custom_setup(self):
self.mock_object(na_utils, 'OpenStackInfo')
configuration = self._set_config(create_configuration())
self.driver = common.NetAppDriver(configuration=configuration)
self.mock_object(requests, 'Session', FakeEseriesHTTPSession)

View File

@@ -119,6 +119,7 @@ class NetAppCmodeNfsDriverTestCase(test.TestCase):
self._custom_setup()
def _custom_setup(self):
self.mock_object(utils, 'OpenStackInfo')
kwargs = {}
kwargs['netapp_mode'] = 'proxy'
kwargs['configuration'] = create_configuration()
@@ -880,6 +881,7 @@ class NetAppCmodeNfsDriverOnlyTestCase(test.TestCase):
self._custom_setup()
def _custom_setup(self):
self.mock_object(utils, 'OpenStackInfo')
kwargs = {}
kwargs['netapp_mode'] = 'proxy'
kwargs['configuration'] = create_configuration()
@@ -1183,6 +1185,7 @@ class NetApp7modeNfsDriverTestCase(NetAppCmodeNfsDriverTestCase):
"""Test direct NetApp C Mode driver."""
def _custom_setup(self):
self.mock_object(utils, 'OpenStackInfo')
self._driver = netapp_nfs_7mode.NetApp7modeNfsDriver(
configuration=create_configuration())
self._driver.zapi_client = mock.Mock()

View File

@@ -224,7 +224,7 @@ class OpenStackInfo(object):
def _update_info_from_rpm(self):
LOG.debug('Trying rpm command.')
try:
out, err = putils.execute("rpm", "-qa", "--queryformat",
out, err = putils.execute("rpm", "-q", "--queryformat",
"'%{version}\t%{release}\t%{vendor}'",
self.PACKAGE_NAME)
if not out: