]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Mock calls to rpm and dpkg from NetApp unit tests
authorTom Barron <tpb@dyncloud.net>
Tue, 9 Dec 2014 09:46:29 +0000 (04:46 -0500)
committerTom Barron <tpb@dyncloud.net>
Fri, 19 Dec 2014 16:17:49 +0000 (16:17 +0000)
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
cinder/tests/test_netapp_eseries_iscsi.py
cinder/tests/test_netapp_nfs.py
cinder/volume/drivers/netapp/utils.py

index 26fc57ced8f4b21316e0113c4dc9ba5b57e170ae..6c02e327008e2a0820a4013656af40c5b9e55241 100644 (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',
index e69f9614fd2b74780071ff21b758d77d2d90302d..aeb6720d9448525cd95556cebcd098d99f2c11ba 100644 (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)
index 63ff706073786f0bc435c8676e2692337d673717..0127084ede817bcb8e030ab83a39294bcc994566 100644 (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()
index 2269a35f392eec57cf3ec78b9c1ae355244b69ae..4e7538f32f65d7e89cba3ebd61e0d916e3eaa01d 100644 (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: