]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Mock socket.gethostbyaddr in test_v7000_fcp
authorMichal Dulko <michal.dulko@intel.com>
Wed, 1 Jul 2015 06:41:03 +0000 (08:41 +0200)
committerMichal Dulko <michal.dulko@intel.com>
Wed, 1 Jul 2015 06:41:03 +0000 (08:41 +0200)
Currently test_v7000_fcp doesn't mock socket.gethostbyaddr and
hardcodes expected response to be google-public-dns-a.google.com
(as it is querying for 8.8.8.8 as IP). This introduces dependency on
external DNS lookup to pass unit tests and causes problems with
running tests behind a proxy.

This commit mocks socket.gethostbyaddr in the problematic test.

Change-Id: I3a0288d8e51c832a72e16e23af5adbee990f9e20
Closes-Bug: 1470113

cinder/tests/unit/test_v7000_fcp.py

index 4f12eea8a4db2993e66a919a104bb6472608d69e..50273ba4464f39fe1e664a6e249b8393cf67df75 100644 (file)
@@ -95,7 +95,7 @@ PHY_DEVICES_RESPONSE = {
           'is_foreign': True,
           'name': 'BKSC:OTHDISK-MFCN01.000',
           'object_id': '84b834fb-1f4d-5d3b-b7ae-5796f9868151',
-          'owner': 'google-public-dns-a.google.com',
+          'owner': 'example.com',
           'pool': None,
           'product': 'OTHDISK-MFCN01',
           'scsi_address':
@@ -121,7 +121,7 @@ PHY_DEVICES_RESPONSE = {
           'is_foreign': False,
           'name': 'BKSC:OTHDISK-MFCN08.000',
           'object_id': '8555b888-bf43-5083-a433-f0c7b0282370',
-          'owner': 'google-public-dns-a.google.com',
+          'owner': 'example.com',
           'pool':
           {'name': 'mga-pool',
            'object_id': '0818d3de-4437-535f-9cac-cc100a2c9313'},
@@ -331,10 +331,19 @@ class V7000FCPDriverTestCase(test.TestCase):
         self.driver._update_volume_stats.assert_called_with()
         self.assertEqual(self.driver.stats, result)
 
-    def test_update_volume_stats(self):
+    @mock.patch('socket.gethostbyaddr')
+    def test_update_volume_stats(self, mock_gethost):
         """Makes a mock query to the backend to collect
            stats on all physical devices.
         """
+
+        def gethostbyaddr(addr):
+            if addr == '8.8.8.8' or addr == 'example.com':
+                return ('example.com', [], ['8.8.8.8'])
+            else:
+                return ('a.b.c.d', [], addr)
+        mock_gethost.side_effect = gethostbyaddr
+
         backend_name = self.conf.volume_backend_name
         vendor_name = "Violin Memory, Inc."
         tot_gb = 2046