diff --git a/hpe3parclient/http.py b/hpe3parclient/http.py index decfc32f..58120e26 100644 --- a/hpe3parclient/http.py +++ b/hpe3parclient/http.py @@ -167,12 +167,13 @@ def _http_log_req(self, args, kwargs): string_parts.append(header) HTTPJSONRESTClient._logger.debug("\nREQ: %s\n" % "".join(string_parts)) + if 'body' in kwargs: if 'password' in kwargs['body']: kwargs['body']['password'] = "********" HTTPJSONRESTClient._logger.debug("REQ BODY: %s\n" % (kwargs['body'])) - + def _http_log_resp(self, resp, body): if not self.http_log_debug: return diff --git a/test/test_HPE3ParClient_host.py b/test/test_HPE3ParClient_host.py index f5f30bfd..4a0e0468 100644 --- a/test/test_HPE3ParClient_host.py +++ b/test/test_HPE3ParClient_host.py @@ -15,7 +15,7 @@ """Test class of 3PAR Client handling Host.""" from test import HPE3ParClient_base as hpe3parbase - +import mock from hpe3parclient import exceptions # Insert colons into time string to match WWN format. @@ -615,7 +615,6 @@ def test_5_query_host_wwn(self): optional = {'domain': DOMAIN} fc = [WWN1] self.cl.createHost(HOST_NAME1, None, fc, optional) - hosts = self.cl.queryHost(wwns=[fc.pop().replace(':', '')]) self.assertIsNotNone(hosts) self.assertEqual(1, hosts['total']) @@ -645,9 +644,12 @@ def test_5_query_host_iqn_and_wwn(self): self.assertIn(HOST_NAME2, [host['name'] for host in hosts['members']]) self.printFooter('query_host_iqn_and_wwn') - def test_6_find_host(self): + @mock.patch('hpe3parclient.client.HPE3ParClient._run') + @mock.patch('hpe3parclient.client.HPE3ParClient.deleteHost') + def test_6_find_host(self, mock_deletehost, mock_run): self.printHeader('find_host_wwn') - + mock_run.return_value = 'host name' + mock_deletehost.return_value = None hosts = self.cl.findHost(wwn=WWN1) if hosts is not None: diff --git a/test/test_HPE3ParClient_system.py b/test/test_HPE3ParClient_system.py index 2afbf055..dc85aaa9 100644 --- a/test/test_HPE3ParClient_system.py +++ b/test/test_HPE3ParClient_system.py @@ -16,6 +16,7 @@ from testconfig import config import unittest +import mock from test import HPE3ParClient_base as hpe3parbase from hpe3parclient import exceptions @@ -30,7 +31,8 @@ def tearDown(self): # very last, tear down base class super(HPE3ParClientSystemTestCase, self).tearDown() - def test_get_patch(self): + @mock.patch('hpe3parclient.client.HPE3ParClient._run') + def test_get_patch(self, mockrun): """This can work with or without a patch, but you need to manually enter a valid one or use the bogus one. @@ -43,7 +45,7 @@ def test_get_patch(self): # # bogus patch name that should consistently be not recognized: patch_id = 'P16-BOGUS' - + mockrun.return_value = ["Patch P16-BOGUS not recognized"] result = self.cl.getPatch(patch_id) self.assertIsNotNone(result) if len(result) > 1: diff --git a/test/test_HPE3ParClient_volume.py b/test/test_HPE3ParClient_volume.py index 6b6dbea1..ed1e0c76 100644 --- a/test/test_HPE3ParClient_volume.py +++ b/test/test_HPE3ParClient_volume.py @@ -17,7 +17,7 @@ import time import unittest from testconfig import config - +import mock from test import HPE3ParClient_base as hpe3parbase from hpe3parclient import exceptions @@ -2019,17 +2019,20 @@ def test_22_failover_remote_copy_group(self): self.printFooter('failover_remote_copy_group') - def test_23_get_volume_snapshots(self): + @mock.patch('hpe3parclient.client.HPE3ParClient._run') + def test_23_get_volume_snapshots(self, mock_run): # Create volume and snaphot it optional = {'snapCPG': CPG_NAME1} self.cl.createVolume(VOLUME_NAME1, CPG_NAME1, SIZE, optional) self.cl.createSnapshot(SNAP_NAME1, VOLUME_NAME1) self.cl.createSnapshot(SNAP_NAME2, VOLUME_NAME1) - + mock_run.return_value = ["MiB)- Id Name Prov Compr Dedup Type CopyOf BsId Rd -Detailed_State-Snp Usr VSize", + "1, .srdata ,full ,NA, NA, base ,--- 1, RW ,normal ,0,882", + "2 ,SNAP_UNIT_TEST1,full,NA,NA,base, --- 1,RW,normal,0,882", + "3,SNAP_UNIT_TEST2,full,NA,NA,base,--- 1,RW,normal,0,882"] # Get the volumes snapshots snapshots = self.cl.getVolumeSnapshots(VOLUME_NAME1) - # Set snapshot names. If the test is not against a live array, we # need to add the snapshot suffix. if not is_live_test(): @@ -2041,15 +2044,20 @@ def test_23_get_volume_snapshots(self): self.assertEqual([SNAP_NAME1, SNAP_NAME2], snapshots) # Test where volume does not exist + mock_run.return_value = ["MiB)- Id Name Prov Compr Dedup Type CopyOf BsId Rd -Detailed_State-Snp Usr VSize", + "", + "", + ""] snapshots = self.cl.getVolumeSnapshots("BAD_VOL") # An empty list is returned if the volume does not exist self.assertEqual([], snapshots) - def test_24_set_qos(self): + @mock.patch('hpe3parclient.client.HPE3ParClient._run') + def test_24_set_qos(self, mock_run): self.printHeader('set_qos') self.cl.createVolumeSet(VOLUME_SET_NAME4, comment="Unit test volume set 4") - + mock_run.return_value="QOS Exception" self.assertRaises( exceptions.SetQOSRuleException, self.cl.setQOSRule, @@ -2057,6 +2065,7 @@ def test_24_set_qos(self): max_io = 300 max_bw = 1024 + mock_run.return_value = None self.cl.setQOSRule(VOLUME_SET_NAME4, max_io, max_bw) self.cl.setQOSRule(VOLUME_SET_NAME4, max_io) self.cl.setQOSRule(VOLUME_SET_NAME4, max_bw)