From d555ca100aeb176bc021b8179d2a5cdfe10e168e Mon Sep 17 00:00:00 2001 From: Tom Barron Date: Tue, 9 Dec 2014 04:46:29 -0500 Subject: [PATCH] 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 --- cinder/tests/test_netapp.py | 14 ++++++++++++++ cinder/tests/test_netapp_eseries_iscsi.py | 2 ++ cinder/tests/test_netapp_nfs.py | 3 +++ cinder/volume/drivers/netapp/utils.py | 2 +- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cinder/tests/test_netapp.py b/cinder/tests/test_netapp.py index 26fc57ced..6c02e3270 100644 --- a/cinder/tests/test_netapp.py +++ b/cinder/tests/test_netapp.py @@ -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', diff --git a/cinder/tests/test_netapp_eseries_iscsi.py b/cinder/tests/test_netapp_eseries_iscsi.py index e69f9614f..aeb6720d9 100644 --- a/cinder/tests/test_netapp_eseries_iscsi.py +++ b/cinder/tests/test_netapp_eseries_iscsi.py @@ -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) diff --git a/cinder/tests/test_netapp_nfs.py b/cinder/tests/test_netapp_nfs.py index 63ff70607..0127084ed 100644 --- a/cinder/tests/test_netapp_nfs.py +++ b/cinder/tests/test_netapp_nfs.py @@ -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() diff --git a/cinder/volume/drivers/netapp/utils.py b/cinder/volume/drivers/netapp/utils.py index 2269a35f3..4e7538f32 100644 --- a/cinder/volume/drivers/netapp/utils.py +++ b/cinder/volume/drivers/netapp/utils.py @@ -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: -- 2.45.2