diff options
Diffstat (limited to 'openstackclient/tests')
53 files changed, 3375 insertions, 3263 deletions
diff --git a/openstackclient/tests/functional/volume/base.py b/openstackclient/tests/functional/volume/base.py index 041d8d07..f15a3145 100644 --- a/openstackclient/tests/functional/volume/base.py +++ b/openstackclient/tests/functional/volume/base.py @@ -16,11 +16,18 @@ from openstackclient.tests.functional import base class BaseVolumeTests(base.TestCase): - """Base class for Volume functional tests. """ + """Base class for Volume functional tests.""" @classmethod - def wait_for_status(cls, check_type, check_name, desired_status, - wait=120, interval=5, failures=None): + def wait_for_status( + cls, + check_type, + check_name, + desired_status, + wait=120, + interval=5, + failures=None, + ): current_status = "notset" if failures is None: failures = ['error'] @@ -32,23 +39,31 @@ class BaseVolumeTests(base.TestCase): ) current_status = output['status'] if current_status == desired_status: - print('{} {} now has status {}' - .format(check_type, check_name, current_status)) + print( + '{} {} now has status {}'.format( + check_type, check_name, current_status + ) + ) return - print('Checking {} {} Waiting for {} current status: {}' - .format(check_type, check_name, - desired_status, current_status)) + print( + 'Checking {} {} Waiting for {} current status: {}'.format( + check_type, check_name, desired_status, current_status + ) + ) if current_status in failures: raise Exception( - 'Current status {} of {} {} is one of failures {}' - .format(current_status, check_type, check_name, failures)) + 'Current status {} of {} {} is one of failures {}'.format( + current_status, check_type, check_name, failures + ) + ) time.sleep(interval) total_sleep += interval cls.assertOutput(desired_status, current_status) @classmethod - def wait_for_delete(cls, check_type, check_name, wait=120, interval=5, - name_field=None): + def wait_for_delete( + cls, check_type, check_name, wait=120, interval=5, name_field=None + ): total_sleep = 0 name_field = name_field or 'Name' while total_sleep < wait: @@ -57,9 +72,15 @@ class BaseVolumeTests(base.TestCase): if check_name not in names: print('{} {} is now deleted'.format(check_type, check_name)) return - print('Checking {} {} Waiting for deleted' - .format(check_type, check_name)) + print( + 'Checking {} {} Waiting for deleted'.format( + check_type, check_name + ) + ) time.sleep(interval) total_sleep += interval - raise Exception('Timeout: {} {} was not deleted in {} seconds' - .format(check_type, check_name, wait)) + raise Exception( + 'Timeout: {} {} was not deleted in {} seconds'.format( + check_type, check_name, wait + ) + ) diff --git a/openstackclient/tests/functional/volume/v1/test_qos.py b/openstackclient/tests/functional/volume/v1/test_qos.py index c449938e..cabcd19e 100644 --- a/openstackclient/tests/functional/volume/v1/test_qos.py +++ b/openstackclient/tests/functional/volume/v1/test_qos.py @@ -16,31 +16,23 @@ from openstackclient.tests.functional.volume.v1 import common class QosTests(common.BaseVolumeTests): - """Functional tests for volume qos. """ + """Functional tests for volume qos.""" def test_volume_qos_create_list(self): """Test create, list, delete multiple""" name1 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume qos create ' + - name1, + 'volume qos create ' + name1, parse_output=True, ) - self.assertEqual( - name1, - cmd_output['name'] - ) + self.assertEqual(name1, cmd_output['name']) name2 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume qos create ' + - name2, + 'volume qos create ' + name2, parse_output=True, ) - self.assertEqual( - name2, - cmd_output['name'] - ) + self.assertEqual(name2, cmd_output['name']) # Test list cmd_output = self.openstack( @@ -60,67 +52,43 @@ class QosTests(common.BaseVolumeTests): name = uuid.uuid4().hex cmd_output = self.openstack( - 'volume qos create ' + - '--consumer front-end ' - '--property Alpha=a ' + - name, + 'volume qos create ' + '--consumer front-end ' + '--property Alpha=a ' + name, parse_output=True, ) self.addCleanup(self.openstack, 'volume qos delete ' + name) - self.assertEqual( - name, - cmd_output['name'] - ) + self.assertEqual(name, cmd_output['name']) - self.assertEqual( - "front-end", - cmd_output['consumer'] - ) + self.assertEqual("front-end", cmd_output['consumer']) # Test volume qos set raw_output = self.openstack( - 'volume qos set ' + - '--property Alpha=c ' + - '--property Beta=b ' + - name, + 'volume qos set ' + + '--property Alpha=c ' + + '--property Beta=b ' + + name, ) self.assertOutput('', raw_output) # Test volume qos show cmd_output = self.openstack( - 'volume qos show ' + - name, + 'volume qos show ' + name, parse_output=True, ) - self.assertEqual( - name, - cmd_output['name'] - ) - self.assertEqual( - {'Alpha': 'c', 'Beta': 'b'}, - cmd_output['properties'] - ) + self.assertEqual(name, cmd_output['name']) + self.assertEqual({'Alpha': 'c', 'Beta': 'b'}, cmd_output['properties']) # Test volume qos unset raw_output = self.openstack( - 'volume qos unset ' + - '--property Alpha ' + - name, + 'volume qos unset ' + '--property Alpha ' + name, ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume qos show ' + - name, + 'volume qos show ' + name, parse_output=True, ) - self.assertEqual( - name, - cmd_output['name'] - ) - self.assertEqual( - {'Beta': 'b'}, - cmd_output['properties'] - ) + self.assertEqual(name, cmd_output['name']) + self.assertEqual({'Beta': 'b'}, cmd_output['properties']) # TODO(qiangjiahui): Add tests for associate and disassociate volume type diff --git a/openstackclient/tests/functional/volume/v1/test_service.py b/openstackclient/tests/functional/volume/v1/test_service.py index 7de2de55..0f510a8a 100644 --- a/openstackclient/tests/functional/volume/v1/test_service.py +++ b/openstackclient/tests/functional/volume/v1/test_service.py @@ -24,22 +24,16 @@ class VolumeServiceTests(common.BaseVolumeTests): # Test volume service list --service cmd_output = self.openstack( - 'volume service list ' + - '--service ' + - services[0], + 'volume service list ' + '--service ' + services[0], parse_output=True, ) for x in cmd_output: - self.assertEqual( - services[0], - x['Binary'] - ) + self.assertEqual(services[0], x['Binary']) # TODO(zhiyong.dai): test volume service list --host after solving # https://bugs.launchpad.net/python-openstackclient/+bug/1664451 def test_volume_service_set(self): - # Get a service and host cmd_output = self.openstack( 'volume service list', @@ -50,9 +44,7 @@ class VolumeServiceTests(common.BaseVolumeTests): # Test volume service set --enable raw_output = self.openstack( - 'volume service set --enable ' + - host_1 + ' ' + - service_1 + 'volume service set --enable ' + host_1 + ' ' + service_1 ) self.assertOutput('', raw_output) @@ -60,20 +52,19 @@ class VolumeServiceTests(common.BaseVolumeTests): 'volume service list --long', parse_output=True, ) - self.assertEqual( - 'enabled', - cmd_output[0]['Status'] - ) + self.assertEqual('enabled', cmd_output[0]['Status']) self.assertIsNone(cmd_output[0]['Disabled Reason']) # Test volume service set --disable and --disable-reason disable_reason = 'disable_reason' raw_output = self.openstack( - 'volume service set --disable ' + - '--disable-reason ' + - disable_reason + ' ' + - host_1 + ' ' + - service_1 + 'volume service set --disable ' + + '--disable-reason ' + + disable_reason + + ' ' + + host_1 + + ' ' + + service_1 ) self.assertOutput('', raw_output) @@ -81,11 +72,5 @@ class VolumeServiceTests(common.BaseVolumeTests): 'volume service list --long', parse_output=True, ) - self.assertEqual( - 'disabled', - cmd_output[0]['Status'] - ) - self.assertEqual( - disable_reason, - cmd_output[0]['Disabled Reason'] - ) + self.assertEqual('disabled', cmd_output[0]['Status']) + self.assertEqual(disable_reason, cmd_output[0]['Disabled Reason']) diff --git a/openstackclient/tests/functional/volume/v1/test_snapshot.py b/openstackclient/tests/functional/volume/v1/test_snapshot.py index c8c956d1..52877d5a 100644 --- a/openstackclient/tests/functional/volume/v1/test_snapshot.py +++ b/openstackclient/tests/functional/volume/v1/test_snapshot.py @@ -16,7 +16,7 @@ from openstackclient.tests.functional.volume.v1 import common class VolumeSnapshotTests(common.BaseVolumeTests): - """Functional tests for volume snapshot. """ + """Functional tests for volume snapshot.""" VOLLY = uuid.uuid4().hex @@ -25,9 +25,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): super(VolumeSnapshotTests, cls).setUpClass() # create a volume for all tests to create snapshot cmd_output = cls.openstack( - 'volume create ' + - '--size 1 ' + - cls.VOLLY, + 'volume create ' + '--size 1 ' + cls.VOLLY, parse_output=True, ) cls.wait_for_status('volume', cls.VOLLY, 'available') @@ -46,9 +44,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): """Test create, delete multiple""" name1 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume snapshot create ' + - name1 + - ' --volume ' + self.VOLLY, + 'volume snapshot create ' + name1 + ' --volume ' + self.VOLLY, parse_output=True, ) self.assertEqual( @@ -58,9 +54,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): name2 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume snapshot create ' + - name2 + - ' --volume ' + self.VOLLY, + 'volume snapshot create ' + name2 + ' --volume ' + self.VOLLY, parse_output=True, ) self.assertEqual( @@ -72,7 +66,8 @@ class VolumeSnapshotTests(common.BaseVolumeTests): self.wait_for_status('volume snapshot', name2, 'available') del_output = self.openstack( - 'volume snapshot delete ' + name1 + ' ' + name2) + 'volume snapshot delete ' + name1 + ' ' + name2 + ) self.assertOutput('', del_output) self.wait_for_delete('volume snapshot', name1) self.wait_for_delete('volume snapshot', name2) @@ -81,9 +76,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): """Test create, list filter""" name1 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume snapshot create ' + - name1 + - ' --volume ' + self.VOLLY, + 'volume snapshot create ' + name1 + ' --volume ' + self.VOLLY, parse_output=True, ) self.addCleanup(self.wait_for_delete, 'volume snapshot', name1) @@ -104,9 +97,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): name2 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume snapshot create ' + - name2 + - ' --volume ' + self.VOLLY, + 'volume snapshot create ' + name2 + ' --volume ' + self.VOLLY, parse_output=True, ) self.addCleanup(self.wait_for_delete, 'volume snapshot', name2) @@ -127,9 +118,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): # Test list --long, --status cmd_output = self.openstack( - 'volume snapshot list ' + - '--long ' + - '--status error', + 'volume snapshot list ' + '--long ' + '--status error', parse_output=True, ) names = [x["Name"] for x in cmd_output] @@ -138,8 +127,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): # Test list --volume cmd_output = self.openstack( - 'volume snapshot list ' + - '--volume ' + self.VOLLY, + 'volume snapshot list ' + '--volume ' + self.VOLLY, parse_output=True, ) names = [x["Name"] for x in cmd_output] @@ -148,8 +136,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): # Test list --name cmd_output = self.openstack( - 'volume snapshot list ' + - '--name ' + name1, + 'volume snapshot list ' + '--name ' + name1, parse_output=True, ) names = [x["Name"] for x in cmd_output] @@ -161,10 +148,11 @@ class VolumeSnapshotTests(common.BaseVolumeTests): name = uuid.uuid4().hex new_name = name + "_" cmd_output = self.openstack( - 'volume snapshot create ' + - '--volume ' + self.VOLLY + - ' --description aaaa ' + - name, + 'volume snapshot create ' + + '--volume ' + + self.VOLLY + + ' --description aaaa ' + + name, parse_output=True, ) self.addCleanup(self.wait_for_delete, 'volume snapshot', new_name) @@ -185,19 +173,19 @@ class VolumeSnapshotTests(common.BaseVolumeTests): # Test volume snapshot set raw_output = self.openstack( - 'volume snapshot set ' + - '--name ' + new_name + - ' --description bbbb ' + - '--property Alpha=a ' + - '--property Beta=b ' + - name, + 'volume snapshot set ' + + '--name ' + + new_name + + ' --description bbbb ' + + '--property Alpha=a ' + + '--property Beta=b ' + + name, ) self.assertOutput('', raw_output) # Show snapshot set result cmd_output = self.openstack( - 'volume snapshot show ' + - new_name, + 'volume snapshot show ' + new_name, parse_output=True, ) self.assertEqual( @@ -219,15 +207,12 @@ class VolumeSnapshotTests(common.BaseVolumeTests): # Test volume unset raw_output = self.openstack( - 'volume snapshot unset ' + - '--property Alpha ' + - new_name, + 'volume snapshot unset ' + '--property Alpha ' + new_name, ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume snapshot show ' + - new_name, + 'volume snapshot show ' + new_name, parse_output=True, ) self.assertEqual( @@ -237,14 +222,11 @@ class VolumeSnapshotTests(common.BaseVolumeTests): # Test volume snapshot set --no-property raw_output = self.openstack( - 'volume snapshot set ' + - '--no-property ' + - new_name, + 'volume snapshot set ' + '--no-property ' + new_name, ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume snapshot show ' + - new_name, + 'volume snapshot show ' + new_name, parse_output=True, ) self.assertEqual({}, cmd_output["properties"]) diff --git a/openstackclient/tests/functional/volume/v1/test_transfer_request.py b/openstackclient/tests/functional/volume/v1/test_transfer_request.py index 0ee73d8a..37aa4ca2 100644 --- a/openstackclient/tests/functional/volume/v1/test_transfer_request.py +++ b/openstackclient/tests/functional/volume/v1/test_transfer_request.py @@ -16,7 +16,7 @@ from openstackclient.tests.functional.volume.v1 import common class TransferRequestTests(common.BaseVolumeTests): - """Functional tests for transfer request. """ + """Functional tests for transfer request.""" NAME = uuid.uuid4().hex VOLUME_NAME = uuid.uuid4().hex @@ -36,7 +36,8 @@ class TransferRequestTests(common.BaseVolumeTests): def tearDownClass(cls): try: raw_output_volume = cls.openstack( - 'volume delete ' + cls.VOLUME_NAME) + 'volume delete ' + cls.VOLUME_NAME + ) cls.assertOutput('', raw_output_volume) finally: super(TransferRequestTests, cls).tearDownClass() @@ -55,9 +56,10 @@ class TransferRequestTests(common.BaseVolumeTests): # create volume transfer request for the volume # and get the auth_key of the new transfer request cmd_output = self.openstack( - 'volume transfer request create ' + - volume_name + - ' --name ' + name, + 'volume transfer request create ' + + volume_name + + ' --name ' + + name, parse_output=True, ) auth_key = cmd_output['auth_key'] @@ -65,30 +67,32 @@ class TransferRequestTests(common.BaseVolumeTests): # accept the volume transfer request output = self.openstack( - 'volume transfer request accept ' + - name + ' ' + - '--auth-key ' + auth_key, + 'volume transfer request accept ' + + name + + ' ' + + '--auth-key ' + + auth_key, parse_output=True, ) self.assertEqual(name, output.get('name')) # the volume transfer will be removed by default after accepted # so just need to delete the volume here - raw_output = self.openstack( - 'volume delete ' + volume_name) + raw_output = self.openstack('volume delete ' + volume_name) self.assertEqual('', raw_output) def test_volume_transfer_request_list_show(self): name = uuid.uuid4().hex cmd_output = self.openstack( - 'volume transfer request create ' + - ' --name ' + name + ' ' + - self.VOLUME_NAME, + 'volume transfer request create ' + + ' --name ' + + name + + ' ' + + self.VOLUME_NAME, parse_output=True, ) self.addCleanup( - self.openstack, - 'volume transfer request delete ' + name + self.openstack, 'volume transfer request delete ' + name ) self.assertOutput(name, cmd_output['name']) auth_key = cmd_output['auth_key'] @@ -101,8 +105,7 @@ class TransferRequestTests(common.BaseVolumeTests): self.assertIn(name, [req['Name'] for req in cmd_output]) cmd_output = self.openstack( - 'volume transfer request show ' + - name, + 'volume transfer request show ' + name, parse_output=True, ) self.assertEqual(name, cmd_output['name']) diff --git a/openstackclient/tests/functional/volume/v1/test_volume.py b/openstackclient/tests/functional/volume/v1/test_volume.py index 727ee73b..7c6cc035 100644 --- a/openstackclient/tests/functional/volume/v1/test_volume.py +++ b/openstackclient/tests/functional/volume/v1/test_volume.py @@ -16,15 +16,13 @@ from openstackclient.tests.functional.volume.v1 import common class VolumeTests(common.BaseVolumeTests): - """Functional tests for volume. """ + """Functional tests for volume.""" def test_volume_create_and_delete(self): """Test create, delete multiple""" name1 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume create ' + - '--size 1 ' + - name1, + 'volume create ' + '--size 1 ' + name1, parse_output=True, ) self.assertEqual( @@ -34,9 +32,7 @@ class VolumeTests(common.BaseVolumeTests): name2 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume create ' + - '--size 2 ' + - name2, + 'volume create ' + '--size 2 ' + name2, parse_output=True, ) self.assertEqual( @@ -53,9 +49,7 @@ class VolumeTests(common.BaseVolumeTests): """Test create, list filter""" name1 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume create ' + - '--size 1 ' + - name1, + 'volume create ' + '--size 1 ' + name1, parse_output=True, ) self.addCleanup(self.openstack, 'volume delete ' + name1) @@ -67,9 +61,7 @@ class VolumeTests(common.BaseVolumeTests): name2 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume create ' + - '--size 2 ' + - name2, + 'volume create ' + '--size 2 ' + name2, parse_output=True, ) self.addCleanup(self.openstack, 'volume delete ' + name2) @@ -98,8 +90,7 @@ class VolumeTests(common.BaseVolumeTests): # Test list --name cmd_output = self.openstack( - 'volume list ' + - '--name ' + name1, + 'volume list ' + '--name ' + name1, parse_output=True, ) names = [x["Name"] for x in cmd_output] @@ -110,11 +101,11 @@ class VolumeTests(common.BaseVolumeTests): """Tests create volume, set, unset, show, delete""" name = uuid.uuid4().hex cmd_output = self.openstack( - 'volume create ' + - '--size 1 ' + - '--description aaaa ' + - '--property Alpha=a ' + - name, + 'volume create ' + + '--size 1 ' + + '--description aaaa ' + + '--property Alpha=a ' + + name, parse_output=True, ) self.assertEqual( @@ -143,21 +134,21 @@ class VolumeTests(common.BaseVolumeTests): new_name = uuid.uuid4().hex self.addCleanup(self.openstack, 'volume delete ' + new_name) raw_output = self.openstack( - 'volume set ' + - '--name ' + new_name + - ' --size 2 ' + - '--description bbbb ' + - '--no-property ' + - '--property Beta=b ' + - '--property Gamma=c ' + - '--bootable ' + - name, + 'volume set ' + + '--name ' + + new_name + + ' --size 2 ' + + '--description bbbb ' + + '--no-property ' + + '--property Beta=b ' + + '--property Gamma=c ' + + '--bootable ' + + name, ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume show ' + - new_name, + 'volume show ' + new_name, parse_output=True, ) self.assertEqual( @@ -183,15 +174,12 @@ class VolumeTests(common.BaseVolumeTests): # Test volume unset raw_output = self.openstack( - 'volume unset ' + - '--property Beta ' + - new_name, + 'volume unset ' + '--property Beta ' + new_name, ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume show ' + - new_name, + 'volume show ' + new_name, parse_output=True, ) self.assertEqual( @@ -203,10 +191,7 @@ class VolumeTests(common.BaseVolumeTests): """Test backward compatibility of create, list, show""" name1 = uuid.uuid4().hex output = self.openstack( - 'volume create ' + - '-c display_name -c id ' + - '--size 1 ' + - name1, + 'volume create ' + '-c display_name -c id ' + '--size 1 ' + name1, parse_output=True, ) self.assertIn('display_name', output) @@ -220,25 +205,21 @@ class VolumeTests(common.BaseVolumeTests): self.wait_for_status("volume", name1, "available") output = self.openstack( - 'volume list ' + - '-c "Display Name"', + 'volume list ' + '-c "Display Name"', parse_output=True, ) for each_volume in output: self.assertIn('Display Name', each_volume) output = self.openstack( - 'volume list ' + - '-c "Name"', + 'volume list ' + '-c "Name"', parse_output=True, ) for each_volume in output: self.assertIn('Name', each_volume) output = self.openstack( - 'volume show ' + - '-c display_name -c id ' + - name1, + 'volume show ' + '-c display_name -c id ' + name1, parse_output=True, ) self.assertIn('display_name', output) diff --git a/openstackclient/tests/functional/volume/v1/test_volume_type.py b/openstackclient/tests/functional/volume/v1/test_volume_type.py index 037d45f0..6448af6e 100644 --- a/openstackclient/tests/functional/volume/v1/test_volume_type.py +++ b/openstackclient/tests/functional/volume/v1/test_volume_type.py @@ -17,19 +17,17 @@ from openstackclient.tests.functional.volume.v1 import common class VolumeTypeTests(common.BaseVolumeTests): - """Functional tests for volume type. """ + """Functional tests for volume type.""" def test_volume_type_create_list(self): name = uuid.uuid4().hex cmd_output = self.openstack( - 'volume type create --private ' + - name, + 'volume type create --private ' + name, parse_output=True, ) self.addCleanup( self.openstack, - 'volume type delete ' + - name, + 'volume type delete ' + name, ) self.assertEqual(name, cmd_output['name']) @@ -52,14 +50,10 @@ class VolumeTypeTests(common.BaseVolumeTests): def test_volume_type_set_unset_properties(self): name = uuid.uuid4().hex cmd_output = self.openstack( - 'volume type create --private ' + - name, + 'volume type create --private ' + name, parse_output=True, ) - self.addCleanup( - self.openstack, - 'volume type delete ' + name - ) + self.addCleanup(self.openstack, 'volume type delete ' + name) self.assertEqual(name, cmd_output['name']) raw_output = self.openstack( @@ -72,9 +66,7 @@ class VolumeTypeTests(common.BaseVolumeTests): ) self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties']) - raw_output = self.openstack( - 'volume type unset --property a %s' % name - ) + raw_output = self.openstack('volume type unset --property a %s' % name) self.assertEqual("", raw_output) cmd_output = self.openstack( 'volume type show %s' % name, @@ -85,14 +77,10 @@ class VolumeTypeTests(common.BaseVolumeTests): def test_volume_type_set_unset_multiple_properties(self): name = uuid.uuid4().hex cmd_output = self.openstack( - 'volume type create --private ' + - name, + 'volume type create --private ' + name, parse_output=True, ) - self.addCleanup( - self.openstack, - 'volume type delete ' + name - ) + self.addCleanup(self.openstack, 'volume type delete ' + name) self.assertEqual(name, cmd_output['name']) raw_output = self.openstack( @@ -138,12 +126,14 @@ class VolumeTypeTests(common.BaseVolumeTests): '--encryption-provider LuksEncryptor ' '--encryption-cipher aes-xts-plain64 ' '--encryption-key-size 128 ' - '--encryption-control-location front-end ' + - encryption_type) - expected = {'provider': 'LuksEncryptor', - 'cipher': 'aes-xts-plain64', - 'key_size': 128, - 'control_location': 'front-end'} + '--encryption-control-location front-end ' + encryption_type + ) + expected = { + 'provider': 'LuksEncryptor', + 'cipher': 'aes-xts-plain64', + 'key_size': 128, + 'control_location': 'front-end', + } for attr, value in expected.items(): self.assertEqual(value, cmd_output['encryption'][attr]) # test show encryption type @@ -151,10 +141,12 @@ class VolumeTypeTests(common.BaseVolumeTests): 'volume type show --encryption-type ' + encryption_type, parse_output=True, ) - expected = {'provider': 'LuksEncryptor', - 'cipher': 'aes-xts-plain64', - 'key_size': 128, - 'control_location': 'front-end'} + expected = { + 'provider': 'LuksEncryptor', + 'cipher': 'aes-xts-plain64', + 'key_size': 128, + 'control_location': 'front-end', + } for attr, value in expected.items(): self.assertEqual(value, cmd_output['encryption'][attr]) # test list encryption type @@ -162,12 +154,15 @@ class VolumeTypeTests(common.BaseVolumeTests): 'volume type list --encryption-type', parse_output=True, ) - encryption_output = [t['Encryption'] for t in cmd_output - if t['Name'] == encryption_type][0] - expected = {'provider': 'LuksEncryptor', - 'cipher': 'aes-xts-plain64', - 'key_size': 128, - 'control_location': 'front-end'} + encryption_output = [ + t['Encryption'] for t in cmd_output if t['Name'] == encryption_type + ][0] + expected = { + 'provider': 'LuksEncryptor', + 'cipher': 'aes-xts-plain64', + 'key_size': 128, + 'control_location': 'front-end', + } for attr, value in expected.items(): self.assertEqual(value, encryption_output[attr]) # test set new encryption type @@ -176,8 +171,8 @@ class VolumeTypeTests(common.BaseVolumeTests): '--encryption-provider LuksEncryptor ' '--encryption-cipher aes-xts-plain64 ' '--encryption-key-size 128 ' - '--encryption-control-location front-end ' + - self.NAME) + '--encryption-control-location front-end ' + self.NAME + ) self.assertEqual('', raw_output) name = uuid.uuid4().hex @@ -195,10 +190,12 @@ class VolumeTypeTests(common.BaseVolumeTests): 'volume type show --encryption-type ' + name, parse_output=True, ) - expected = {'provider': 'LuksEncryptor', - 'cipher': 'aes-xts-plain64', - 'key_size': 128, - 'control_location': 'front-end'} + expected = { + 'provider': 'LuksEncryptor', + 'cipher': 'aes-xts-plain64', + 'key_size': 128, + 'control_location': 'front-end', + } for attr, value in expected.items(): self.assertEqual(value, cmd_output['encryption'][attr]) # test unset encryption type diff --git a/openstackclient/tests/functional/volume/v2/common.py b/openstackclient/tests/functional/volume/v2/common.py index 7e3a8084..f15d4d96 100644 --- a/openstackclient/tests/functional/volume/v2/common.py +++ b/openstackclient/tests/functional/volume/v2/common.py @@ -16,7 +16,7 @@ from openstackclient.tests.functional.volume import base class BaseVolumeTests(base.BaseVolumeTests): - """Base class for Volume functional tests. """ + """Base class for Volume functional tests.""" @classmethod def setUpClass(cls): diff --git a/openstackclient/tests/functional/volume/v2/test_qos.py b/openstackclient/tests/functional/volume/v2/test_qos.py index 0a540573..4f07084a 100644 --- a/openstackclient/tests/functional/volume/v2/test_qos.py +++ b/openstackclient/tests/functional/volume/v2/test_qos.py @@ -16,31 +16,23 @@ from openstackclient.tests.functional.volume.v2 import common class QosTests(common.BaseVolumeTests): - """Functional tests for volume qos. """ + """Functional tests for volume qos.""" def test_volume_qos_create_delete_list(self): """Test create, list, delete multiple""" name1 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume qos create ' + - name1, + 'volume qos create ' + name1, parse_output=True, ) - self.assertEqual( - name1, - cmd_output['name'] - ) + self.assertEqual(name1, cmd_output['name']) name2 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume qos create ' + - name2, + 'volume qos create ' + name2, parse_output=True, ) - self.assertEqual( - name2, - cmd_output['name'] - ) + self.assertEqual(name2, cmd_output['name']) # Test list cmd_output = self.openstack( @@ -60,126 +52,84 @@ class QosTests(common.BaseVolumeTests): name = uuid.uuid4().hex cmd_output = self.openstack( - 'volume qos create ' + - '--consumer front-end ' - '--property Alpha=a ' + - name, + 'volume qos create ' + '--consumer front-end ' + '--property Alpha=a ' + name, parse_output=True, ) self.addCleanup(self.openstack, 'volume qos delete ' + name) - self.assertEqual( - name, - cmd_output['name'] - ) + self.assertEqual(name, cmd_output['name']) - self.assertEqual( - "front-end", - cmd_output['consumer'] - ) - self.assertEqual( - {'Alpha': 'a'}, - cmd_output['properties'] - ) + self.assertEqual("front-end", cmd_output['consumer']) + self.assertEqual({'Alpha': 'a'}, cmd_output['properties']) # Test volume qos set raw_output = self.openstack( - 'volume qos set ' + - '--property Alpha=c ' + - '--property Beta=b ' + - name, + 'volume qos set ' + + '--property Alpha=c ' + + '--property Beta=b ' + + name, ) self.assertOutput('', raw_output) # Test volume qos show cmd_output = self.openstack( - 'volume qos show ' + - name, + 'volume qos show ' + name, parse_output=True, ) - self.assertEqual( - name, - cmd_output['name'] - ) - self.assertEqual( - {'Alpha': 'c', 'Beta': 'b'}, - cmd_output['properties'] - ) + self.assertEqual(name, cmd_output['name']) + self.assertEqual({'Alpha': 'c', 'Beta': 'b'}, cmd_output['properties']) # Test volume qos unset raw_output = self.openstack( - 'volume qos unset ' + - '--property Alpha ' + - name, + 'volume qos unset ' + '--property Alpha ' + name, ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume qos show ' + - name, + 'volume qos show ' + name, parse_output=True, ) - self.assertEqual( - name, - cmd_output['name'] - ) - self.assertEqual( - {'Beta': 'b'}, - cmd_output['properties'] - ) + self.assertEqual(name, cmd_output['name']) + self.assertEqual({'Beta': 'b'}, cmd_output['properties']) def test_volume_qos_asso_disasso(self): """Tests associate and disassociate qos with volume type""" vol_type1 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume type create ' + - vol_type1, + 'volume type create ' + vol_type1, parse_output=True, ) - self.assertEqual( - vol_type1, - cmd_output['name'] - ) + self.assertEqual(vol_type1, cmd_output['name']) self.addCleanup(self.openstack, 'volume type delete ' + vol_type1) vol_type2 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume type create ' + - vol_type2, + 'volume type create ' + vol_type2, parse_output=True, ) - self.assertEqual( - vol_type2, - cmd_output['name'] - ) + self.assertEqual(vol_type2, cmd_output['name']) self.addCleanup(self.openstack, 'volume type delete ' + vol_type2) name = uuid.uuid4().hex cmd_output = self.openstack( - 'volume qos create ' + - name, + 'volume qos create ' + name, parse_output=True, ) - self.assertEqual( - name, - cmd_output['name'] - ) + self.assertEqual(name, cmd_output['name']) self.addCleanup(self.openstack, 'volume qos delete ' + name) # Test associate raw_output = self.openstack( - 'volume qos associate ' + - name + ' ' + vol_type1 + 'volume qos associate ' + name + ' ' + vol_type1 ) self.assertOutput('', raw_output) raw_output = self.openstack( - 'volume qos associate ' + - name + ' ' + vol_type2 + 'volume qos associate ' + name + ' ' + vol_type2 ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume qos show ' + - name, + 'volume qos show ' + name, parse_output=True, ) types = cmd_output["associations"] @@ -188,14 +138,15 @@ class QosTests(common.BaseVolumeTests): # Test disassociate raw_output = self.openstack( - 'volume qos disassociate ' + - '--volume-type ' + vol_type1 + - ' ' + name + 'volume qos disassociate ' + + '--volume-type ' + + vol_type1 + + ' ' + + name ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume qos show ' + - name, + 'volume qos show ' + name, parse_output=True, ) types = cmd_output["associations"] @@ -204,13 +155,11 @@ class QosTests(common.BaseVolumeTests): # Test disassociate --all raw_output = self.openstack( - 'volume qos associate ' + - name + ' ' + vol_type1 + 'volume qos associate ' + name + ' ' + vol_type1 ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume qos show ' + - name, + 'volume qos show ' + name, parse_output=True, ) types = cmd_output["associations"] @@ -218,13 +167,11 @@ class QosTests(common.BaseVolumeTests): self.assertIn(vol_type2, types) raw_output = self.openstack( - 'volume qos disassociate ' + - '--all ' + name + 'volume qos disassociate ' + '--all ' + name ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume qos show ' + - name, + 'volume qos show ' + name, parse_output=True, ) self.assertNotIn("associations", cmd_output.keys()) diff --git a/openstackclient/tests/functional/volume/v2/test_service.py b/openstackclient/tests/functional/volume/v2/test_service.py index 5794f81f..1101affc 100644 --- a/openstackclient/tests/functional/volume/v2/test_service.py +++ b/openstackclient/tests/functional/volume/v2/test_service.py @@ -25,32 +25,21 @@ class VolumeServiceTests(common.BaseVolumeTests): # Test volume service list --service cmd_output = self.openstack( - 'volume service list ' + - '--service ' + - services[0], + 'volume service list ' + '--service ' + services[0], parse_output=True, ) for x in cmd_output: - self.assertEqual( - services[0], - x['Binary'] - ) + self.assertEqual(services[0], x['Binary']) # Test volume service list --host cmd_output = self.openstack( - 'volume service list ' + - '--host ' + - hosts[0], + 'volume service list ' + '--host ' + hosts[0], parse_output=True, ) for x in cmd_output: - self.assertIn( - hosts[0], - x['Host'] - ) + self.assertIn(hosts[0], x['Host']) def test_volume_service_set(self): - # Get a service and host cmd_output = self.openstack( 'volume service list', @@ -61,9 +50,7 @@ class VolumeServiceTests(common.BaseVolumeTests): # Test volume service set --enable raw_output = self.openstack( - 'volume service set --enable ' + - host_1 + ' ' + - service_1 + 'volume service set --enable ' + host_1 + ' ' + service_1 ) self.assertOutput('', raw_output) @@ -71,22 +58,19 @@ class VolumeServiceTests(common.BaseVolumeTests): 'volume service list --long', parse_output=True, ) - self.assertEqual( - 'enabled', - cmd_output[0]['Status'] - ) - self.assertIsNone( - cmd_output[0]['Disabled Reason'] - ) + self.assertEqual('enabled', cmd_output[0]['Status']) + self.assertIsNone(cmd_output[0]['Disabled Reason']) # Test volume service set --disable and --disable-reason disable_reason = 'disable_reason' raw_output = self.openstack( - 'volume service set --disable ' + - '--disable-reason ' + - disable_reason + ' ' + - host_1 + ' ' + - service_1 + 'volume service set --disable ' + + '--disable-reason ' + + disable_reason + + ' ' + + host_1 + + ' ' + + service_1 ) self.assertOutput('', raw_output) @@ -94,11 +78,5 @@ class VolumeServiceTests(common.BaseVolumeTests): 'volume service list --long', parse_output=True, ) - self.assertEqual( - 'disabled', - cmd_output[0]['Status'] - ) - self.assertEqual( - disable_reason, - cmd_output[0]['Disabled Reason'] - ) + self.assertEqual('disabled', cmd_output[0]['Status']) + self.assertEqual(disable_reason, cmd_output[0]['Disabled Reason']) diff --git a/openstackclient/tests/functional/volume/v2/test_transfer_request.py b/openstackclient/tests/functional/volume/v2/test_transfer_request.py index ac71cba2..07d70f0f 100644 --- a/openstackclient/tests/functional/volume/v2/test_transfer_request.py +++ b/openstackclient/tests/functional/volume/v2/test_transfer_request.py @@ -16,7 +16,7 @@ from openstackclient.tests.functional.volume.v2 import common class TransferRequestTests(common.BaseVolumeTests): - """Functional tests for transfer request. """ + """Functional tests for transfer request.""" API_VERSION = '2' @@ -26,27 +26,31 @@ class TransferRequestTests(common.BaseVolumeTests): # create a volume cmd_output = self.openstack( - 'volume create ' + - '--size 1 ' + - volume_name, + 'volume create ' + '--size 1 ' + volume_name, parse_output=True, ) self.assertEqual(volume_name, cmd_output['name']) self.addCleanup( self.openstack, - '--os-volume-api-version ' + self.API_VERSION + ' ' + - 'volume delete ' + - volume_name + '--os-volume-api-version ' + + self.API_VERSION + + ' ' + + 'volume delete ' + + volume_name, ) self.wait_for_status("volume", volume_name, "available") # create volume transfer request for the volume # and get the auth_key of the new transfer request cmd_output = self.openstack( - '--os-volume-api-version ' + self.API_VERSION + ' ' + - 'volume transfer request create ' + - ' --name ' + xfer_name + ' ' + - volume_name, + '--os-volume-api-version ' + + self.API_VERSION + + ' ' + + 'volume transfer request create ' + + ' --name ' + + xfer_name + + ' ' + + volume_name, parse_output=True, ) self.assertEqual(xfer_name, cmd_output['name']) @@ -57,10 +61,14 @@ class TransferRequestTests(common.BaseVolumeTests): # accept the volume transfer request cmd_output = self.openstack( - '--os-volume-api-version ' + self.API_VERSION + ' ' + - 'volume transfer request accept ' + - '--auth-key ' + auth_key + ' ' + - xfer_id, + '--os-volume-api-version ' + + self.API_VERSION + + ' ' + + 'volume transfer request accept ' + + '--auth-key ' + + auth_key + + ' ' + + xfer_id, parse_output=True, ) self.assertEqual(xfer_name, cmd_output['name']) @@ -72,25 +80,29 @@ class TransferRequestTests(common.BaseVolumeTests): # create a volume cmd_output = self.openstack( - 'volume create ' + - '--size 1 ' + - volume_name, + 'volume create ' + '--size 1 ' + volume_name, parse_output=True, ) self.assertEqual(volume_name, cmd_output['name']) self.addCleanup( self.openstack, - '--os-volume-api-version ' + self.API_VERSION + ' ' + - 'volume delete ' + - volume_name + '--os-volume-api-version ' + + self.API_VERSION + + ' ' + + 'volume delete ' + + volume_name, ) self.wait_for_status("volume", volume_name, "available") cmd_output = self.openstack( - '--os-volume-api-version ' + self.API_VERSION + ' ' + - 'volume transfer request create ' + - ' --name ' + xfer_name + ' ' + - volume_name, + '--os-volume-api-version ' + + self.API_VERSION + + ' ' + + 'volume transfer request create ' + + ' --name ' + + xfer_name + + ' ' + + volume_name, parse_output=True, ) self.assertEqual(xfer_name, cmd_output['name']) @@ -100,16 +112,20 @@ class TransferRequestTests(common.BaseVolumeTests): self.wait_for_status("volume", volume_name, "awaiting-transfer") cmd_output = self.openstack( - '--os-volume-api-version ' + self.API_VERSION + ' ' + - 'volume transfer request list', + '--os-volume-api-version ' + + self.API_VERSION + + ' ' + + 'volume transfer request list', parse_output=True, ) self.assertIn(xfer_name, [req['Name'] for req in cmd_output]) cmd_output = self.openstack( - '--os-volume-api-version ' + self.API_VERSION + ' ' + - 'volume transfer request show ' + - xfer_id, + '--os-volume-api-version ' + + self.API_VERSION + + ' ' + + 'volume transfer request show ' + + xfer_id, parse_output=True, ) self.assertEqual(xfer_name, cmd_output['name']) @@ -120,8 +136,10 @@ class TransferRequestTests(common.BaseVolumeTests): # to become 'available' before attempting to delete # the volume. cmd_output = self.openstack( - '--os-volume-api-version ' + self.API_VERSION + ' ' + - 'volume transfer request delete ' + - xfer_id + '--os-volume-api-version ' + + self.API_VERSION + + ' ' + + 'volume transfer request delete ' + + xfer_id ) self.wait_for_status("volume", volume_name, "available") diff --git a/openstackclient/tests/functional/volume/v2/test_volume.py b/openstackclient/tests/functional/volume/v2/test_volume.py index 832dabe6..46678587 100644 --- a/openstackclient/tests/functional/volume/v2/test_volume.py +++ b/openstackclient/tests/functional/volume/v2/test_volume.py @@ -16,15 +16,13 @@ from openstackclient.tests.functional.volume.v2 import common class VolumeTests(common.BaseVolumeTests): - """Functional tests for volume. """ + """Functional tests for volume.""" def test_volume_delete(self): """Test create, delete multiple""" name1 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume create ' + - '--size 1 ' + - name1, + 'volume create ' + '--size 1 ' + name1, parse_output=True, ) self.assertEqual( @@ -34,9 +32,7 @@ class VolumeTests(common.BaseVolumeTests): name2 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume create ' + - '--size 2 ' + - name2, + 'volume create ' + '--size 2 ' + name2, parse_output=True, ) self.assertEqual( @@ -53,9 +49,7 @@ class VolumeTests(common.BaseVolumeTests): """Test create, list filter""" name1 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume create ' + - '--size 1 ' + - name1, + 'volume create ' + '--size 1 ' + name1, parse_output=True, ) self.addCleanup(self.openstack, 'volume delete ' + name1) @@ -67,9 +61,7 @@ class VolumeTests(common.BaseVolumeTests): name2 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume create ' + - '--size 2 ' + - name2, + 'volume create ' + '--size 2 ' + name2, parse_output=True, ) self.addCleanup(self.openstack, 'volume delete ' + name2) @@ -78,17 +70,12 @@ class VolumeTests(common.BaseVolumeTests): cmd_output["size"], ) self.wait_for_status("volume", name2, "available") - raw_output = self.openstack( - 'volume set ' + - '--state error ' + - name2 - ) + raw_output = self.openstack('volume set ' + '--state error ' + name2) self.assertOutput('', raw_output) # Test list --long cmd_output = self.openstack( - 'volume list ' + - '--long', + 'volume list ' + '--long', parse_output=True, ) names = [x["Name"] for x in cmd_output] @@ -97,8 +84,7 @@ class VolumeTests(common.BaseVolumeTests): # Test list --status cmd_output = self.openstack( - 'volume list ' + - '--status error', + 'volume list ' + '--status error', parse_output=True, ) names = [x["Name"] for x in cmd_output] @@ -113,11 +99,11 @@ class VolumeTests(common.BaseVolumeTests): name = uuid.uuid4().hex new_name = name + "_" cmd_output = self.openstack( - 'volume create ' + - '--size 1 ' + - '--description aaaa ' + - '--property Alpha=a ' + - name, + 'volume create ' + + '--size 1 ' + + '--description aaaa ' + + '--property Alpha=a ' + + name, parse_output=True, ) self.addCleanup(self.openstack, 'volume delete ' + new_name) @@ -145,23 +131,23 @@ class VolumeTests(common.BaseVolumeTests): # Test volume set raw_output = self.openstack( - 'volume set ' + - '--name ' + new_name + - ' --size 2 ' + - '--description bbbb ' + - '--no-property ' + - '--property Beta=b ' + - '--property Gamma=c ' + - '--image-property a=b ' + - '--image-property c=d ' + - '--bootable ' + - name, + 'volume set ' + + '--name ' + + new_name + + ' --size 2 ' + + '--description bbbb ' + + '--no-property ' + + '--property Beta=b ' + + '--property Gamma=c ' + + '--image-property a=b ' + + '--image-property c=d ' + + '--bootable ' + + name, ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume show ' + - new_name, + 'volume show ' + new_name, parse_output=True, ) self.assertEqual( @@ -191,16 +177,15 @@ class VolumeTests(common.BaseVolumeTests): # Test volume unset raw_output = self.openstack( - 'volume unset ' + - '--property Beta ' + - '--image-property a ' + - new_name, + 'volume unset ' + + '--property Beta ' + + '--image-property a ' + + new_name, ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume show ' + - new_name, + 'volume show ' + new_name, parse_output=True, ) self.assertEqual( @@ -219,9 +204,7 @@ class VolumeTests(common.BaseVolumeTests): snapshot_name = uuid.uuid4().hex # Make a snapshot cmd_output = self.openstack( - 'volume create ' + - '--size 1 ' + - volume_name, + 'volume create ' + '--size 1 ' + volume_name, parse_output=True, ) self.wait_for_status("volume", volume_name, "available") @@ -230,9 +213,10 @@ class VolumeTests(common.BaseVolumeTests): cmd_output["name"], ) cmd_output = self.openstack( - 'volume snapshot create ' + - snapshot_name + - ' --volume ' + volume_name, + 'volume snapshot create ' + + snapshot_name + + ' --volume ' + + volume_name, parse_output=True, ) self.wait_for_status("volume snapshot", snapshot_name, "available") @@ -240,9 +224,7 @@ class VolumeTests(common.BaseVolumeTests): name = uuid.uuid4().hex # Create volume from snapshot cmd_output = self.openstack( - 'volume create ' + - '--snapshot ' + snapshot_name + - ' ' + name, + 'volume create ' + '--snapshot ' + snapshot_name + ' ' + name, parse_output=True, ) self.addCleanup(self.openstack, 'volume delete ' + name) @@ -254,8 +236,7 @@ class VolumeTests(common.BaseVolumeTests): self.wait_for_status("volume", name, "available") # Delete snapshot - raw_output = self.openstack( - 'volume snapshot delete ' + snapshot_name) + raw_output = self.openstack('volume snapshot delete ' + snapshot_name) self.assertOutput('', raw_output) # Deleting snapshot may take time. If volume snapshot still exists when # a parent volume delete is requested, the volume deletion will fail. @@ -265,9 +246,7 @@ class VolumeTests(common.BaseVolumeTests): """Test backward compatibility of list command""" name1 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume create ' + - '--size 1 ' + - name1, + 'volume create ' + '--size 1 ' + name1, parse_output=True, ) self.addCleanup(self.openstack, 'volume delete ' + name1) @@ -279,8 +258,7 @@ class VolumeTests(common.BaseVolumeTests): # Test list -c "Display Name" cmd_output = self.openstack( - 'volume list ' + - '-c "Display Name"', + 'volume list ' + '-c "Display Name"', parse_output=True, ) for each_volume in cmd_output: @@ -288,8 +266,7 @@ class VolumeTests(common.BaseVolumeTests): # Test list -c "Name" cmd_output = self.openstack( - 'volume list ' + - '-c "Name"', + 'volume list ' + '-c "Name"', parse_output=True, ) for each_volume in cmd_output: diff --git a/openstackclient/tests/functional/volume/v2/test_volume_backup.py b/openstackclient/tests/functional/volume/v2/test_volume_backup.py index 07bd2d16..e6f7dec9 100644 --- a/openstackclient/tests/functional/volume/v2/test_volume_backup.py +++ b/openstackclient/tests/functional/volume/v2/test_volume_backup.py @@ -16,7 +16,7 @@ from openstackclient.tests.functional.volume.v2 import common class VolumeBackupTests(common.BaseVolumeTests): - """Functional tests for volume backups. """ + """Functional tests for volume backups.""" def setUp(self): super(VolumeBackupTests, self).setUp() @@ -34,29 +34,26 @@ class VolumeBackupTests(common.BaseVolumeTests): vol_id = uuid.uuid4().hex # create a volume self.openstack( - 'volume create ' + - '--size 1 ' + - vol_id, + 'volume create ' + '--size 1 ' + vol_id, parse_output=True, ) self.wait_for_status("volume", vol_id, "available") # create a backup backup = self.openstack( - 'volume backup create ' + - vol_id, + 'volume backup create ' + vol_id, parse_output=True, ) self.wait_for_status("volume backup", backup['id'], "available") # restore the backup backup_restored = self.openstack( - 'volume backup restore %s %s' - % (backup['id'], vol_id), + 'volume backup restore %s %s' % (backup['id'], vol_id), parse_output=True, ) self.assertEqual(backup_restored['backup_id'], backup['id']) self.wait_for_status("volume backup", backup['id'], "available") - self.wait_for_status("volume", backup_restored['volume_id'], - "available") + self.wait_for_status( + "volume", backup_restored['volume_id'], "available" + ) self.addCleanup(self.openstack, 'volume delete %s' % vol_id) diff --git a/openstackclient/tests/functional/volume/v2/test_volume_snapshot.py b/openstackclient/tests/functional/volume/v2/test_volume_snapshot.py index 12fdad2c..7aefdf29 100644 --- a/openstackclient/tests/functional/volume/v2/test_volume_snapshot.py +++ b/openstackclient/tests/functional/volume/v2/test_volume_snapshot.py @@ -16,7 +16,7 @@ from openstackclient.tests.functional.volume.v2 import common class VolumeSnapshotTests(common.BaseVolumeTests): - """Functional tests for volume snapshot. """ + """Functional tests for volume snapshot.""" VOLLY = uuid.uuid4().hex @@ -25,9 +25,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): super(VolumeSnapshotTests, cls).setUpClass() # create a volume for all tests to create snapshot cmd_output = cls.openstack( - 'volume create ' + - '--size 1 ' + - cls.VOLLY, + 'volume create ' + '--size 1 ' + cls.VOLLY, parse_output=True, ) cls.wait_for_status('volume', cls.VOLLY, 'available') @@ -37,8 +35,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): def tearDownClass(cls): try: cls.wait_for_status('volume', cls.VOLLY, 'available') - raw_output = cls.openstack( - 'volume delete --force ' + cls.VOLLY) + raw_output = cls.openstack('volume delete --force ' + cls.VOLLY) cls.assertOutput('', raw_output) finally: super(VolumeSnapshotTests, cls).tearDownClass() @@ -47,9 +44,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): """Test create, delete multiple""" name1 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume snapshot create ' + - name1 + - ' --volume ' + self.VOLLY, + 'volume snapshot create ' + name1 + ' --volume ' + self.VOLLY, parse_output=True, ) self.assertEqual( @@ -59,9 +54,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): name2 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume snapshot create ' + - name2 + - ' --volume ' + self.VOLLY, + 'volume snapshot create ' + name2 + ' --volume ' + self.VOLLY, parse_output=True, ) self.assertEqual( @@ -73,7 +66,8 @@ class VolumeSnapshotTests(common.BaseVolumeTests): self.wait_for_status('volume snapshot', name2, 'available') del_output = self.openstack( - 'volume snapshot delete ' + name1 + ' ' + name2) + 'volume snapshot delete ' + name1 + ' ' + name2 + ) self.assertOutput('', del_output) self.wait_for_delete('volume snapshot', name1) self.wait_for_delete('volume snapshot', name2) @@ -82,9 +76,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): """Test create, list filter""" name1 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume snapshot create ' + - name1 + - ' --volume ' + self.VOLLY, + 'volume snapshot create ' + name1 + ' --volume ' + self.VOLLY, parse_output=True, ) self.addCleanup(self.wait_for_delete, 'volume snapshot', name1) @@ -105,9 +97,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): name2 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume snapshot create ' + - name2 + - ' --volume ' + self.VOLLY, + 'volume snapshot create ' + name2 + ' --volume ' + self.VOLLY, parse_output=True, ) self.addCleanup(self.wait_for_delete, 'volume snapshot', name2) @@ -127,17 +117,13 @@ class VolumeSnapshotTests(common.BaseVolumeTests): self.wait_for_status('volume snapshot', name2, 'available') raw_output = self.openstack( - 'volume snapshot set ' + - '--state error_deleting ' + - name2 + 'volume snapshot set ' + '--state error_deleting ' + name2 ) self.assertOutput('', raw_output) # Test list --long, --status cmd_output = self.openstack( - 'volume snapshot list ' + - '--long ' + - '--status error_deleting', + 'volume snapshot list ' + '--long ' + '--status error_deleting', parse_output=True, ) names = [x["Name"] for x in cmd_output] @@ -145,17 +131,13 @@ class VolumeSnapshotTests(common.BaseVolumeTests): self.assertIn(name2, names) raw_output = self.openstack( - 'volume snapshot set ' + - '--state error ' + - name2 + 'volume snapshot set ' + '--state error ' + name2 ) self.assertOutput('', raw_output) # Test list --long, --status cmd_output = self.openstack( - 'volume snapshot list ' + - '--long ' + - '--status error', + 'volume snapshot list ' + '--long ' + '--status error', parse_output=True, ) names = [x["Name"] for x in cmd_output] @@ -164,8 +146,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): # Test list --volume cmd_output = self.openstack( - 'volume snapshot list ' + - '--volume ' + self.VOLLY, + 'volume snapshot list ' + '--volume ' + self.VOLLY, parse_output=True, ) names = [x["Name"] for x in cmd_output] @@ -174,8 +155,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): # Test list --name cmd_output = self.openstack( - 'volume snapshot list ' + - '--name ' + name1, + 'volume snapshot list ' + '--name ' + name1, parse_output=True, ) names = [x["Name"] for x in cmd_output] @@ -187,11 +167,12 @@ class VolumeSnapshotTests(common.BaseVolumeTests): name = uuid.uuid4().hex new_name = name + "_" cmd_output = self.openstack( - 'volume snapshot create ' + - '--volume ' + self.VOLLY + - ' --description aaaa ' + - '--property Alpha=a ' + - name, + 'volume snapshot create ' + + '--volume ' + + self.VOLLY + + ' --description aaaa ' + + '--property Alpha=a ' + + name, parse_output=True, ) self.addCleanup(self.wait_for_delete, 'volume snapshot', new_name) @@ -216,19 +197,19 @@ class VolumeSnapshotTests(common.BaseVolumeTests): # Test volume snapshot set raw_output = self.openstack( - 'volume snapshot set ' + - '--name ' + new_name + - ' --description bbbb ' + - '--property Alpha=c ' + - '--property Beta=b ' + - name, + 'volume snapshot set ' + + '--name ' + + new_name + + ' --description bbbb ' + + '--property Alpha=c ' + + '--property Beta=b ' + + name, ) self.assertOutput('', raw_output) # Show snapshot set result cmd_output = self.openstack( - 'volume snapshot show ' + - new_name, + 'volume snapshot show ' + new_name, parse_output=True, ) self.assertEqual( @@ -250,15 +231,12 @@ class VolumeSnapshotTests(common.BaseVolumeTests): # Test volume snapshot unset raw_output = self.openstack( - 'volume snapshot unset ' + - '--property Alpha ' + - new_name, + 'volume snapshot unset ' + '--property Alpha ' + new_name, ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume snapshot show ' + - new_name, + 'volume snapshot show ' + new_name, parse_output=True, ) self.assertEqual( @@ -268,14 +246,11 @@ class VolumeSnapshotTests(common.BaseVolumeTests): # Test volume snapshot set --no-property raw_output = self.openstack( - 'volume snapshot set ' + - '--no-property ' + - new_name, + 'volume snapshot set ' + '--no-property ' + new_name, ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume snapshot show ' + - new_name, + 'volume snapshot show ' + new_name, parse_output=True, ) self.assertNotIn( diff --git a/openstackclient/tests/functional/volume/v2/test_volume_type.py b/openstackclient/tests/functional/volume/v2/test_volume_type.py index 5cad9297..b9bbcfc3 100644 --- a/openstackclient/tests/functional/volume/v2/test_volume_type.py +++ b/openstackclient/tests/functional/volume/v2/test_volume_type.py @@ -17,13 +17,12 @@ from openstackclient.tests.functional.volume.v2 import common class VolumeTypeTests(common.BaseVolumeTests): - """Functional tests for volume type. """ + """Functional tests for volume type.""" def test_volume_type_create_list(self): name = uuid.uuid4().hex cmd_output = self.openstack( - 'volume type create --private ' + - name, + 'volume type create --private ' + name, parse_output=True, ) self.addCleanup( @@ -51,14 +50,10 @@ class VolumeTypeTests(common.BaseVolumeTests): def test_volume_type_set_unset_properties(self): name = uuid.uuid4().hex cmd_output = self.openstack( - 'volume type create --private ' + - name, + 'volume type create --private ' + name, parse_output=True, ) - self.addCleanup( - self.openstack, - 'volume type delete ' + name - ) + self.addCleanup(self.openstack, 'volume type delete ' + name) self.assertEqual(name, cmd_output['name']) raw_output = self.openstack( @@ -71,9 +66,7 @@ class VolumeTypeTests(common.BaseVolumeTests): ) self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties']) - raw_output = self.openstack( - 'volume type unset --property a %s' % name - ) + raw_output = self.openstack('volume type unset --property a %s' % name) self.assertEqual("", raw_output) cmd_output = self.openstack( 'volume type show %s' % name, @@ -84,14 +77,10 @@ class VolumeTypeTests(common.BaseVolumeTests): def test_volume_type_set_unset_multiple_properties(self): name = uuid.uuid4().hex cmd_output = self.openstack( - 'volume type create --private ' + - name, + 'volume type create --private ' + name, parse_output=True, ) - self.addCleanup( - self.openstack, - 'volume type delete ' + name - ) + self.addCleanup(self.openstack, 'volume type delete ' + name) self.assertEqual(name, cmd_output['name']) raw_output = self.openstack( @@ -117,14 +106,10 @@ class VolumeTypeTests(common.BaseVolumeTests): def test_volume_type_set_unset_project(self): name = uuid.uuid4().hex cmd_output = self.openstack( - 'volume type create --private ' + - name, + 'volume type create --private ' + name, parse_output=True, ) - self.addCleanup( - self.openstack, - 'volume type delete ' + name - ) + self.addCleanup(self.openstack, 'volume type delete ' + name) self.assertEqual(name, cmd_output['name']) raw_output = self.openstack( @@ -161,14 +146,15 @@ class VolumeTypeTests(common.BaseVolumeTests): '--encryption-provider LuksEncryptor ' '--encryption-cipher aes-xts-plain64 ' '--encryption-key-size 128 ' - '--encryption-control-location front-end ' + - encryption_type, + '--encryption-control-location front-end ' + encryption_type, parse_output=True, ) - expected = {'provider': 'LuksEncryptor', - 'cipher': 'aes-xts-plain64', - 'key_size': 128, - 'control_location': 'front-end'} + expected = { + 'provider': 'LuksEncryptor', + 'cipher': 'aes-xts-plain64', + 'key_size': 128, + 'control_location': 'front-end', + } for attr, value in expected.items(): self.assertEqual(value, cmd_output['encryption'][attr]) # test show encryption type @@ -176,10 +162,12 @@ class VolumeTypeTests(common.BaseVolumeTests): 'volume type show --encryption-type ' + encryption_type, parse_output=True, ) - expected = {'provider': 'LuksEncryptor', - 'cipher': 'aes-xts-plain64', - 'key_size': 128, - 'control_location': 'front-end'} + expected = { + 'provider': 'LuksEncryptor', + 'cipher': 'aes-xts-plain64', + 'key_size': 128, + 'control_location': 'front-end', + } for attr, value in expected.items(): self.assertEqual(value, cmd_output['encryption'][attr]) # test list encryption type @@ -187,35 +175,39 @@ class VolumeTypeTests(common.BaseVolumeTests): 'volume type list --encryption-type', parse_output=True, ) - encryption_output = [t['Encryption'] for t in cmd_output - if t['Name'] == encryption_type][0] - expected = {'provider': 'LuksEncryptor', - 'cipher': 'aes-xts-plain64', - 'key_size': 128, - 'control_location': 'front-end'} + encryption_output = [ + t['Encryption'] for t in cmd_output if t['Name'] == encryption_type + ][0] + expected = { + 'provider': 'LuksEncryptor', + 'cipher': 'aes-xts-plain64', + 'key_size': 128, + 'control_location': 'front-end', + } for attr, value in expected.items(): self.assertEqual(value, encryption_output[attr]) # test set existing encryption type raw_output = self.openstack( 'volume type set ' '--encryption-key-size 256 ' - '--encryption-control-location back-end ' + - encryption_type) + '--encryption-control-location back-end ' + encryption_type + ) self.assertEqual('', raw_output) cmd_output = self.openstack( 'volume type show --encryption-type ' + encryption_type, parse_output=True, ) - expected = {'provider': 'LuksEncryptor', - 'cipher': 'aes-xts-plain64', - 'key_size': 256, - 'control_location': 'back-end'} + expected = { + 'provider': 'LuksEncryptor', + 'cipher': 'aes-xts-plain64', + 'key_size': 256, + 'control_location': 'back-end', + } for attr, value in expected.items(): self.assertEqual(value, cmd_output['encryption'][attr]) # test set new encryption type cmd_output = self.openstack( - 'volume type create --private ' + - name, + 'volume type create --private ' + name, parse_output=True, ) self.addCleanup( @@ -229,18 +221,20 @@ class VolumeTypeTests(common.BaseVolumeTests): '--encryption-provider LuksEncryptor ' '--encryption-cipher aes-xts-plain64 ' '--encryption-key-size 128 ' - '--encryption-control-location front-end ' + - name) + '--encryption-control-location front-end ' + name + ) self.assertEqual('', raw_output) cmd_output = self.openstack( 'volume type show --encryption-type ' + name, parse_output=True, ) - expected = {'provider': 'LuksEncryptor', - 'cipher': 'aes-xts-plain64', - 'key_size': 128, - 'control_location': 'front-end'} + expected = { + 'provider': 'LuksEncryptor', + 'cipher': 'aes-xts-plain64', + 'key_size': 128, + 'control_location': 'front-end', + } for attr, value in expected.items(): self.assertEqual(value, cmd_output['encryption'][attr]) # test unset encryption type diff --git a/openstackclient/tests/functional/volume/v3/common.py b/openstackclient/tests/functional/volume/v3/common.py index 29f769b6..cbab3927 100644 --- a/openstackclient/tests/functional/volume/v3/common.py +++ b/openstackclient/tests/functional/volume/v3/common.py @@ -16,7 +16,7 @@ from openstackclient.tests.functional.volume import base class BaseVolumeTests(base.BaseVolumeTests): - """Base class for Volume functional tests. """ + """Base class for Volume functional tests.""" @classmethod def setUpClass(cls): diff --git a/openstackclient/tests/functional/volume/v3/test_qos.py b/openstackclient/tests/functional/volume/v3/test_qos.py index 51578e14..2a09e549 100644 --- a/openstackclient/tests/functional/volume/v3/test_qos.py +++ b/openstackclient/tests/functional/volume/v3/test_qos.py @@ -16,31 +16,23 @@ from openstackclient.tests.functional.volume.v3 import common class QosTests(common.BaseVolumeTests): - """Functional tests for volume qos. """ + """Functional tests for volume qos.""" def test_volume_qos_create_delete_list(self): """Test create, list, delete multiple""" name1 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume qos create ' + - name1, + 'volume qos create ' + name1, parse_output=True, ) - self.assertEqual( - name1, - cmd_output['name'] - ) + self.assertEqual(name1, cmd_output['name']) name2 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume qos create ' + - name2, + 'volume qos create ' + name2, parse_output=True, ) - self.assertEqual( - name2, - cmd_output['name'] - ) + self.assertEqual(name2, cmd_output['name']) # Test list cmd_output = self.openstack( @@ -60,126 +52,84 @@ class QosTests(common.BaseVolumeTests): name = uuid.uuid4().hex cmd_output = self.openstack( - 'volume qos create ' + - '--consumer front-end ' - '--property Alpha=a ' + - name, + 'volume qos create ' + '--consumer front-end ' + '--property Alpha=a ' + name, parse_output=True, ) self.addCleanup(self.openstack, 'volume qos delete ' + name) - self.assertEqual( - name, - cmd_output['name'] - ) + self.assertEqual(name, cmd_output['name']) - self.assertEqual( - "front-end", - cmd_output['consumer'] - ) - self.assertEqual( - {'Alpha': 'a'}, - cmd_output['properties'] - ) + self.assertEqual("front-end", cmd_output['consumer']) + self.assertEqual({'Alpha': 'a'}, cmd_output['properties']) # Test volume qos set raw_output = self.openstack( - 'volume qos set ' + - '--property Alpha=c ' + - '--property Beta=b ' + - name, + 'volume qos set ' + + '--property Alpha=c ' + + '--property Beta=b ' + + name, ) self.assertOutput('', raw_output) # Test volume qos show cmd_output = self.openstack( - 'volume qos show ' + - name, + 'volume qos show ' + name, parse_output=True, ) - self.assertEqual( - name, - cmd_output['name'] - ) - self.assertEqual( - {'Alpha': 'c', 'Beta': 'b'}, - cmd_output['properties'] - ) + self.assertEqual(name, cmd_output['name']) + self.assertEqual({'Alpha': 'c', 'Beta': 'b'}, cmd_output['properties']) # Test volume qos unset raw_output = self.openstack( - 'volume qos unset ' + - '--property Alpha ' + - name, + 'volume qos unset ' + '--property Alpha ' + name, ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume qos show ' + - name, + 'volume qos show ' + name, parse_output=True, ) - self.assertEqual( - name, - cmd_output['name'] - ) - self.assertEqual( - {'Beta': 'b'}, - cmd_output['properties'] - ) + self.assertEqual(name, cmd_output['name']) + self.assertEqual({'Beta': 'b'}, cmd_output['properties']) def test_volume_qos_asso_disasso(self): """Tests associate and disassociate qos with volume type""" vol_type1 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume type create ' + - vol_type1, + 'volume type create ' + vol_type1, parse_output=True, ) - self.assertEqual( - vol_type1, - cmd_output['name'] - ) + self.assertEqual(vol_type1, cmd_output['name']) self.addCleanup(self.openstack, 'volume type delete ' + vol_type1) vol_type2 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume type create ' + - vol_type2, + 'volume type create ' + vol_type2, parse_output=True, ) - self.assertEqual( - vol_type2, - cmd_output['name'] - ) + self.assertEqual(vol_type2, cmd_output['name']) self.addCleanup(self.openstack, 'volume type delete ' + vol_type2) name = uuid.uuid4().hex cmd_output = self.openstack( - 'volume qos create ' + - name, + 'volume qos create ' + name, parse_output=True, ) - self.assertEqual( - name, - cmd_output['name'] - ) + self.assertEqual(name, cmd_output['name']) self.addCleanup(self.openstack, 'volume qos delete ' + name) # Test associate raw_output = self.openstack( - 'volume qos associate ' + - name + ' ' + vol_type1 + 'volume qos associate ' + name + ' ' + vol_type1 ) self.assertOutput('', raw_output) raw_output = self.openstack( - 'volume qos associate ' + - name + ' ' + vol_type2 + 'volume qos associate ' + name + ' ' + vol_type2 ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume qos show ' + - name, + 'volume qos show ' + name, parse_output=True, ) types = cmd_output["associations"] @@ -188,14 +138,15 @@ class QosTests(common.BaseVolumeTests): # Test disassociate raw_output = self.openstack( - 'volume qos disassociate ' + - '--volume-type ' + vol_type1 + - ' ' + name + 'volume qos disassociate ' + + '--volume-type ' + + vol_type1 + + ' ' + + name ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume qos show ' + - name, + 'volume qos show ' + name, parse_output=True, ) types = cmd_output["associations"] @@ -204,13 +155,11 @@ class QosTests(common.BaseVolumeTests): # Test disassociate --all raw_output = self.openstack( - 'volume qos associate ' + - name + ' ' + vol_type1 + 'volume qos associate ' + name + ' ' + vol_type1 ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume qos show ' + - name, + 'volume qos show ' + name, parse_output=True, ) types = cmd_output["associations"] @@ -218,13 +167,11 @@ class QosTests(common.BaseVolumeTests): self.assertIn(vol_type2, types) raw_output = self.openstack( - 'volume qos disassociate ' + - '--all ' + name + 'volume qos disassociate ' + '--all ' + name ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume qos show ' + - name, + 'volume qos show ' + name, parse_output=True, ) self.assertNotIn("associations", cmd_output.keys()) diff --git a/openstackclient/tests/functional/volume/v3/test_transfer_request.py b/openstackclient/tests/functional/volume/v3/test_transfer_request.py index 449fa08e..c9bdbc48 100644 --- a/openstackclient/tests/functional/volume/v3/test_transfer_request.py +++ b/openstackclient/tests/functional/volume/v3/test_transfer_request.py @@ -16,7 +16,7 @@ from openstackclient.tests.functional.volume.v3 import common class TransferRequestTests(common.BaseVolumeTests): - """Functional tests for transfer request. """ + """Functional tests for transfer request.""" API_VERSION = '3' @@ -26,26 +26,31 @@ class TransferRequestTests(common.BaseVolumeTests): # create a volume cmd_output = self.openstack( - 'volume create ' + - '--size 1 ' + - volume_name, + 'volume create ' + '--size 1 ' + volume_name, parse_output=True, ) self.assertEqual(volume_name, cmd_output['name']) self.addCleanup( self.openstack, - '--os-volume-api-version ' + self.API_VERSION + ' ' + - 'volume delete ' + - volume_name + '--os-volume-api-version ' + + self.API_VERSION + + ' ' + + 'volume delete ' + + volume_name, ) self.wait_for_status("volume", volume_name, "available") # create volume transfer request for the volume # and get the auth_key of the new transfer request cmd_output = self.openstack( - '--os-volume-api-version ' + self.API_VERSION + ' ' + - 'volume transfer request create ' + - ' --name ' + xfer_name + ' ' + volume_name, + '--os-volume-api-version ' + + self.API_VERSION + + ' ' + + 'volume transfer request create ' + + ' --name ' + + xfer_name + + ' ' + + volume_name, parse_output=True, ) self.assertEqual(xfer_name, cmd_output['name']) @@ -56,9 +61,14 @@ class TransferRequestTests(common.BaseVolumeTests): # accept the volume transfer request cmd_output = self.openstack( - '--os-volume-api-version ' + self.API_VERSION + ' ' + - 'volume transfer request accept ' + - '--auth-key ' + auth_key + ' ' + xfer_id, + '--os-volume-api-version ' + + self.API_VERSION + + ' ' + + 'volume transfer request accept ' + + '--auth-key ' + + auth_key + + ' ' + + xfer_id, parse_output=True, ) self.assertEqual(xfer_name, cmd_output['name']) @@ -70,23 +80,29 @@ class TransferRequestTests(common.BaseVolumeTests): # create a volume cmd_output = self.openstack( - 'volume create ' + - '--size 1 ' + volume_name, + 'volume create ' + '--size 1 ' + volume_name, parse_output=True, ) self.assertEqual(volume_name, cmd_output['name']) self.addCleanup( self.openstack, - '--os-volume-api-version ' + self.API_VERSION + ' ' + - 'volume delete ' + - volume_name + '--os-volume-api-version ' + + self.API_VERSION + + ' ' + + 'volume delete ' + + volume_name, ) self.wait_for_status("volume", volume_name, "available") cmd_output = self.openstack( - '--os-volume-api-version ' + self.API_VERSION + ' ' + - 'volume transfer request create ' + - ' --name ' + xfer_name + ' ' + volume_name, + '--os-volume-api-version ' + + self.API_VERSION + + ' ' + + 'volume transfer request create ' + + ' --name ' + + xfer_name + + ' ' + + volume_name, parse_output=True, ) self.assertEqual(xfer_name, cmd_output['name']) @@ -96,16 +112,20 @@ class TransferRequestTests(common.BaseVolumeTests): self.wait_for_status("volume", volume_name, "awaiting-transfer") cmd_output = self.openstack( - '--os-volume-api-version ' + self.API_VERSION + ' ' + - 'volume transfer request list', + '--os-volume-api-version ' + + self.API_VERSION + + ' ' + + 'volume transfer request list', parse_output=True, ) self.assertIn(xfer_name, [req['Name'] for req in cmd_output]) cmd_output = self.openstack( - '--os-volume-api-version ' + self.API_VERSION + ' ' + - 'volume transfer request show ' + - xfer_id, + '--os-volume-api-version ' + + self.API_VERSION + + ' ' + + 'volume transfer request show ' + + xfer_id, parse_output=True, ) self.assertEqual(xfer_name, cmd_output['name']) @@ -116,8 +136,10 @@ class TransferRequestTests(common.BaseVolumeTests): # to become 'available' before attempting to delete # the volume. cmd_output = self.openstack( - '--os-volume-api-version ' + self.API_VERSION + ' ' + - 'volume transfer request delete ' + - xfer_id + '--os-volume-api-version ' + + self.API_VERSION + + ' ' + + 'volume transfer request delete ' + + xfer_id ) self.wait_for_status("volume", volume_name, "available") diff --git a/openstackclient/tests/functional/volume/v3/test_volume.py b/openstackclient/tests/functional/volume/v3/test_volume.py index 8a394e75..244fe91c 100644 --- a/openstackclient/tests/functional/volume/v3/test_volume.py +++ b/openstackclient/tests/functional/volume/v3/test_volume.py @@ -16,7 +16,7 @@ from openstackclient.tests.functional.volume.v3 import common class VolumeTests(common.BaseVolumeTests): - """Functional tests for volume. """ + """Functional tests for volume.""" def test_volume_delete(self): """Test create, delete multiple""" @@ -70,11 +70,7 @@ class VolumeTests(common.BaseVolumeTests): cmd_output["size"], ) self.wait_for_status("volume", name2, "available") - raw_output = self.openstack( - 'volume set ' + - '--state error ' + - name2 - ) + raw_output = self.openstack('volume set ' + '--state error ' + name2) self.assertOutput('', raw_output) # Test list --long @@ -103,11 +99,11 @@ class VolumeTests(common.BaseVolumeTests): name = uuid.uuid4().hex new_name = name + "_" cmd_output = self.openstack( - 'volume create ' + - '--size 1 ' + - '--description aaaa ' + - '--property Alpha=a ' + - name, + 'volume create ' + + '--size 1 ' + + '--description aaaa ' + + '--property Alpha=a ' + + name, parse_output=True, ) self.addCleanup(self.openstack, 'volume delete ' + new_name) @@ -135,17 +131,18 @@ class VolumeTests(common.BaseVolumeTests): # Test volume set raw_output = self.openstack( - 'volume set ' + - '--name ' + new_name + - ' --size 2 ' + - '--description bbbb ' + - '--no-property ' + - '--property Beta=b ' + - '--property Gamma=c ' + - '--image-property a=b ' + - '--image-property c=d ' + - '--bootable ' + - name, + 'volume set ' + + '--name ' + + new_name + + ' --size 2 ' + + '--description bbbb ' + + '--no-property ' + + '--property Beta=b ' + + '--property Gamma=c ' + + '--image-property a=b ' + + '--image-property c=d ' + + '--bootable ' + + name, ) self.assertOutput('', raw_output) self.wait_for_status("volume", new_name, "available") @@ -181,10 +178,10 @@ class VolumeTests(common.BaseVolumeTests): # Test volume unset raw_output = self.openstack( - 'volume unset ' + - '--property Beta ' + - '--image-property a ' + - new_name, + 'volume unset ' + + '--property Beta ' + + '--image-property a ' + + new_name, ) self.assertOutput('', raw_output) @@ -217,9 +214,10 @@ class VolumeTests(common.BaseVolumeTests): cmd_output["name"], ) cmd_output = self.openstack( - 'volume snapshot create ' + - snapshot_name + - ' --volume ' + volume_name, + 'volume snapshot create ' + + snapshot_name + + ' --volume ' + + volume_name, parse_output=True, ) self.wait_for_status("volume snapshot", snapshot_name, "available") @@ -227,9 +225,7 @@ class VolumeTests(common.BaseVolumeTests): name = uuid.uuid4().hex # Create volume from snapshot cmd_output = self.openstack( - 'volume create ' + - '--snapshot ' + snapshot_name + - ' ' + name, + 'volume create ' + '--snapshot ' + snapshot_name + ' ' + name, parse_output=True, ) self.addCleanup(self.openstack, 'volume delete ' + name) @@ -241,8 +237,7 @@ class VolumeTests(common.BaseVolumeTests): self.wait_for_status("volume", name, "available") # Delete snapshot - raw_output = self.openstack( - 'volume snapshot delete ' + snapshot_name) + raw_output = self.openstack('volume snapshot delete ' + snapshot_name) self.assertOutput('', raw_output) # Deleting snapshot may take time. If volume snapshot still exists when # a parent volume delete is requested, the volume deletion will fail. diff --git a/openstackclient/tests/functional/volume/v3/test_volume_snapshot.py b/openstackclient/tests/functional/volume/v3/test_volume_snapshot.py index 7b2d88d0..b9e86a93 100644 --- a/openstackclient/tests/functional/volume/v3/test_volume_snapshot.py +++ b/openstackclient/tests/functional/volume/v3/test_volume_snapshot.py @@ -16,7 +16,7 @@ from openstackclient.tests.functional.volume.v3 import common class VolumeSnapshotTests(common.BaseVolumeTests): - """Functional tests for volume snapshot. """ + """Functional tests for volume snapshot.""" VOLLY = uuid.uuid4().hex @@ -25,9 +25,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): super(VolumeSnapshotTests, cls).setUpClass() # create a volume for all tests to create snapshot cmd_output = cls.openstack( - 'volume create ' + - '--size 1 ' + - cls.VOLLY, + 'volume create ' + '--size 1 ' + cls.VOLLY, parse_output=True, ) cls.wait_for_status('volume', cls.VOLLY, 'available') @@ -37,8 +35,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): def tearDownClass(cls): try: cls.wait_for_status('volume', cls.VOLLY, 'available') - raw_output = cls.openstack( - 'volume delete --force ' + cls.VOLLY) + raw_output = cls.openstack('volume delete --force ' + cls.VOLLY) cls.assertOutput('', raw_output) finally: super(VolumeSnapshotTests, cls).tearDownClass() @@ -47,9 +44,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): """Test create, delete multiple""" name1 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume snapshot create ' + - name1 + - ' --volume ' + self.VOLLY, + 'volume snapshot create ' + name1 + ' --volume ' + self.VOLLY, parse_output=True, ) self.assertEqual( @@ -59,9 +54,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): name2 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume snapshot create ' + - name2 + - ' --volume ' + self.VOLLY, + 'volume snapshot create ' + name2 + ' --volume ' + self.VOLLY, parse_output=True, ) self.assertEqual( @@ -73,7 +66,8 @@ class VolumeSnapshotTests(common.BaseVolumeTests): self.wait_for_status('volume snapshot', name2, 'available') del_output = self.openstack( - 'volume snapshot delete ' + name1 + ' ' + name2) + 'volume snapshot delete ' + name1 + ' ' + name2 + ) self.assertOutput('', del_output) self.wait_for_delete('volume snapshot', name1) self.wait_for_delete('volume snapshot', name2) @@ -82,9 +76,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): """Test create, list filter""" name1 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume snapshot create ' + - name1 + - ' --volume ' + self.VOLLY, + 'volume snapshot create ' + name1 + ' --volume ' + self.VOLLY, parse_output=True, ) self.addCleanup(self.wait_for_delete, 'volume snapshot', name1) @@ -105,9 +97,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): name2 = uuid.uuid4().hex cmd_output = self.openstack( - 'volume snapshot create ' + - name2 + - ' --volume ' + self.VOLLY, + 'volume snapshot create ' + name2 + ' --volume ' + self.VOLLY, parse_output=True, ) self.addCleanup(self.wait_for_delete, 'volume snapshot', name2) @@ -126,17 +116,13 @@ class VolumeSnapshotTests(common.BaseVolumeTests): ) self.wait_for_status('volume snapshot', name2, 'available') raw_output = self.openstack( - 'volume snapshot set ' + - '--state error ' + - name2 + 'volume snapshot set ' + '--state error ' + name2 ) self.assertOutput('', raw_output) # Test list --long, --status cmd_output = self.openstack( - 'volume snapshot list ' + - '--long ' + - '--status error', + 'volume snapshot list ' + '--long ' + '--status error', parse_output=True, ) names = [x["Name"] for x in cmd_output] @@ -145,8 +131,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): # Test list --volume cmd_output = self.openstack( - 'volume snapshot list ' + - '--volume ' + self.VOLLY, + 'volume snapshot list ' + '--volume ' + self.VOLLY, parse_output=True, ) names = [x["Name"] for x in cmd_output] @@ -155,8 +140,7 @@ class VolumeSnapshotTests(common.BaseVolumeTests): # Test list --name cmd_output = self.openstack( - 'volume snapshot list ' + - '--name ' + name1, + 'volume snapshot list ' + '--name ' + name1, parse_output=True, ) names = [x["Name"] for x in cmd_output] @@ -168,11 +152,12 @@ class VolumeSnapshotTests(common.BaseVolumeTests): name = uuid.uuid4().hex new_name = name + "_" cmd_output = self.openstack( - 'volume snapshot create ' + - '--volume ' + self.VOLLY + - ' --description aaaa ' + - '--property Alpha=a ' + - name, + 'volume snapshot create ' + + '--volume ' + + self.VOLLY + + ' --description aaaa ' + + '--property Alpha=a ' + + name, parse_output=True, ) self.addCleanup(self.wait_for_delete, 'volume snapshot', new_name) @@ -197,19 +182,19 @@ class VolumeSnapshotTests(common.BaseVolumeTests): # Test volume snapshot set raw_output = self.openstack( - 'volume snapshot set ' + - '--name ' + new_name + - ' --description bbbb ' + - '--property Alpha=c ' + - '--property Beta=b ' + - name, + 'volume snapshot set ' + + '--name ' + + new_name + + ' --description bbbb ' + + '--property Alpha=c ' + + '--property Beta=b ' + + name, ) self.assertOutput('', raw_output) # Show snapshot set result cmd_output = self.openstack( - 'volume snapshot show ' + - new_name, + 'volume snapshot show ' + new_name, parse_output=True, ) self.assertEqual( @@ -231,15 +216,12 @@ class VolumeSnapshotTests(common.BaseVolumeTests): # Test volume snapshot unset raw_output = self.openstack( - 'volume snapshot unset ' + - '--property Alpha ' + - new_name, + 'volume snapshot unset ' + '--property Alpha ' + new_name, ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume snapshot show ' + - new_name, + 'volume snapshot show ' + new_name, parse_output=True, ) self.assertEqual( @@ -249,14 +231,11 @@ class VolumeSnapshotTests(common.BaseVolumeTests): # Test volume snapshot set --no-property raw_output = self.openstack( - 'volume snapshot set ' + - '--no-property ' + - new_name, + 'volume snapshot set ' + '--no-property ' + new_name, ) self.assertOutput('', raw_output) cmd_output = self.openstack( - 'volume snapshot show ' + - new_name, + 'volume snapshot show ' + new_name, parse_output=True, ) self.assertNotIn( diff --git a/openstackclient/tests/functional/volume/v3/test_volume_type.py b/openstackclient/tests/functional/volume/v3/test_volume_type.py index 18e46c52..4edb3416 100644 --- a/openstackclient/tests/functional/volume/v3/test_volume_type.py +++ b/openstackclient/tests/functional/volume/v3/test_volume_type.py @@ -17,13 +17,12 @@ from openstackclient.tests.functional.volume.v3 import common class VolumeTypeTests(common.BaseVolumeTests): - """Functional tests for volume type. """ + """Functional tests for volume type.""" def test_volume_type_create_list(self): name = uuid.uuid4().hex cmd_output = self.openstack( - 'volume type create --private ' + - name, + 'volume type create --private ' + name, parse_output=True, ) self.addCleanup( @@ -51,14 +50,10 @@ class VolumeTypeTests(common.BaseVolumeTests): def test_volume_type_set_unset_properties(self): name = uuid.uuid4().hex cmd_output = self.openstack( - 'volume type create --private ' + - name, + 'volume type create --private ' + name, parse_output=True, ) - self.addCleanup( - self.openstack, - 'volume type delete ' + name - ) + self.addCleanup(self.openstack, 'volume type delete ' + name) self.assertEqual(name, cmd_output['name']) raw_output = self.openstack( @@ -71,9 +66,7 @@ class VolumeTypeTests(common.BaseVolumeTests): ) self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties']) - raw_output = self.openstack( - 'volume type unset --property a %s' % name - ) + raw_output = self.openstack('volume type unset --property a %s' % name) self.assertEqual("", raw_output) cmd_output = self.openstack( 'volume type show %s' % name, @@ -84,14 +77,10 @@ class VolumeTypeTests(common.BaseVolumeTests): def test_volume_type_set_unset_multiple_properties(self): name = uuid.uuid4().hex cmd_output = self.openstack( - 'volume type create --private ' + - name, + 'volume type create --private ' + name, parse_output=True, ) - self.addCleanup( - self.openstack, - 'volume type delete ' + name - ) + self.addCleanup(self.openstack, 'volume type delete ' + name) self.assertEqual(name, cmd_output['name']) raw_output = self.openstack( @@ -117,14 +106,10 @@ class VolumeTypeTests(common.BaseVolumeTests): def test_volume_type_set_unset_project(self): name = uuid.uuid4().hex cmd_output = self.openstack( - 'volume type create --private ' + - name, + 'volume type create --private ' + name, parse_output=True, ) - self.addCleanup( - self.openstack, - 'volume type delete ' + name - ) + self.addCleanup(self.openstack, 'volume type delete ' + name) self.assertEqual(name, cmd_output['name']) raw_output = self.openstack( @@ -161,14 +146,15 @@ class VolumeTypeTests(common.BaseVolumeTests): '--encryption-provider LuksEncryptor ' '--encryption-cipher aes-xts-plain64 ' '--encryption-key-size 128 ' - '--encryption-control-location front-end ' + - encryption_type, + '--encryption-control-location front-end ' + encryption_type, parse_output=True, ) - expected = {'provider': 'LuksEncryptor', - 'cipher': 'aes-xts-plain64', - 'key_size': 128, - 'control_location': 'front-end'} + expected = { + 'provider': 'LuksEncryptor', + 'cipher': 'aes-xts-plain64', + 'key_size': 128, + 'control_location': 'front-end', + } for attr, value in expected.items(): self.assertEqual(value, cmd_output['encryption'][attr]) # test show encryption type @@ -176,10 +162,12 @@ class VolumeTypeTests(common.BaseVolumeTests): 'volume type show --encryption-type ' + encryption_type, parse_output=True, ) - expected = {'provider': 'LuksEncryptor', - 'cipher': 'aes-xts-plain64', - 'key_size': 128, - 'control_location': 'front-end'} + expected = { + 'provider': 'LuksEncryptor', + 'cipher': 'aes-xts-plain64', + 'key_size': 128, + 'control_location': 'front-end', + } for attr, value in expected.items(): self.assertEqual(value, cmd_output['encryption'][attr]) # test list encryption type @@ -187,35 +175,39 @@ class VolumeTypeTests(common.BaseVolumeTests): 'volume type list --encryption-type', parse_output=True, ) - encryption_output = [t['Encryption'] for t in cmd_output - if t['Name'] == encryption_type][0] - expected = {'provider': 'LuksEncryptor', - 'cipher': 'aes-xts-plain64', - 'key_size': 128, - 'control_location': 'front-end'} + encryption_output = [ + t['Encryption'] for t in cmd_output if t['Name'] == encryption_type + ][0] + expected = { + 'provider': 'LuksEncryptor', + 'cipher': 'aes-xts-plain64', + 'key_size': 128, + 'control_location': 'front-end', + } for attr, value in expected.items(): self.assertEqual(value, encryption_output[attr]) # test set existing encryption type raw_output = self.openstack( 'volume type set ' '--encryption-key-size 256 ' - '--encryption-control-location back-end ' + - encryption_type) + '--encryption-control-location back-end ' + encryption_type + ) self.assertEqual('', raw_output) cmd_output = self.openstack( 'volume type show --encryption-type ' + encryption_type, parse_output=True, ) - expected = {'provider': 'LuksEncryptor', - 'cipher': 'aes-xts-plain64', - 'key_size': 256, - 'control_location': 'back-end'} + expected = { + 'provider': 'LuksEncryptor', + 'cipher': 'aes-xts-plain64', + 'key_size': 256, + 'control_location': 'back-end', + } for attr, value in expected.items(): self.assertEqual(value, cmd_output['encryption'][attr]) # test set new encryption type cmd_output = self.openstack( - 'volume type create --private ' + - name, + 'volume type create --private ' + name, parse_output=True, ) self.addCleanup( @@ -229,18 +221,20 @@ class VolumeTypeTests(common.BaseVolumeTests): '--encryption-provider LuksEncryptor ' '--encryption-cipher aes-xts-plain64 ' '--encryption-key-size 128 ' - '--encryption-control-location front-end ' + - name) + '--encryption-control-location front-end ' + name + ) self.assertEqual('', raw_output) cmd_output = self.openstack( 'volume type show --encryption-type ' + name, parse_output=True, ) - expected = {'provider': 'LuksEncryptor', - 'cipher': 'aes-xts-plain64', - 'key_size': 128, - 'control_location': 'front-end'} + expected = { + 'provider': 'LuksEncryptor', + 'cipher': 'aes-xts-plain64', + 'key_size': 128, + 'control_location': 'front-end', + } for attr, value in expected.items(): self.assertEqual(value, cmd_output['encryption'][attr]) # test unset encryption type diff --git a/openstackclient/tests/unit/volume/test_find_resource.py b/openstackclient/tests/unit/volume/test_find_resource.py index 208f55b9..e1514b01 100644 --- a/openstackclient/tests/unit/volume/test_find_resource.py +++ b/openstackclient/tests/unit/volume/test_find_resource.py @@ -36,7 +36,6 @@ NAME = 'PhilSpector' class TestFindResourceVolumes(test_utils.TestCase): - def setUp(self): super(TestFindResourceVolumes, self).setUp() api = mock.Mock() @@ -44,8 +43,7 @@ class TestFindResourceVolumes(test_utils.TestCase): api.client.get = mock.Mock() resp = mock.Mock() body = {"volumes": [{"id": ID, 'display_name': NAME}]} - api.client.get.side_effect = [Exception("Not found"), - (resp, body)] + api.client.get.side_effect = [Exception("Not found"), (resp, body)] self.manager = volumes.VolumeManager(api) def test_find(self): @@ -54,12 +52,15 @@ class TestFindResourceVolumes(test_utils.TestCase): self.assertEqual(NAME, result.display_name) def test_not_find(self): - self.assertRaises(exceptions.CommandError, utils.find_resource, - self.manager, 'GeorgeMartin') + self.assertRaises( + exceptions.CommandError, + utils.find_resource, + self.manager, + 'GeorgeMartin', + ) class TestFindResourceVolumeSnapshots(test_utils.TestCase): - def setUp(self): super(TestFindResourceVolumeSnapshots, self).setUp() api = mock.Mock() @@ -67,8 +68,7 @@ class TestFindResourceVolumeSnapshots(test_utils.TestCase): api.client.get = mock.Mock() resp = mock.Mock() body = {"snapshots": [{"id": ID, 'display_name': NAME}]} - api.client.get.side_effect = [Exception("Not found"), - (resp, body)] + api.client.get.side_effect = [Exception("Not found"), (resp, body)] self.manager = volume_snapshots.SnapshotManager(api) def test_find(self): @@ -77,5 +77,9 @@ class TestFindResourceVolumeSnapshots(test_utils.TestCase): self.assertEqual(NAME, result.display_name) def test_not_find(self): - self.assertRaises(exceptions.CommandError, utils.find_resource, - self.manager, 'GeorgeMartin') + self.assertRaises( + exceptions.CommandError, + utils.find_resource, + self.manager, + 'GeorgeMartin', + ) diff --git a/openstackclient/tests/unit/volume/v1/test_qos_specs.py b/openstackclient/tests/unit/volume/v1/test_qos_specs.py index f5b35143..7e26e223 100644 --- a/openstackclient/tests/unit/volume/v1/test_qos_specs.py +++ b/openstackclient/tests/unit/volume/v1/test_qos_specs.py @@ -26,7 +26,6 @@ from openstackclient.volume.v1 import qos_specs class TestQos(volume_fakes.TestVolumev1): - def setUp(self): super().setUp() @@ -38,7 +37,6 @@ class TestQos(volume_fakes.TestVolumev1): class TestQosAssociate(TestQos): - volume_type = volume_fakes.create_one_volume_type() qos_spec = volume_fakes.create_one_qos() @@ -51,33 +49,23 @@ class TestQosAssociate(TestQos): self.cmd = qos_specs.AssociateQos(self.app, None) def test_qos_associate(self): - arglist = [ - self.qos_spec.id, - self.volume_type.id - ] + arglist = [self.qos_spec.id, self.volume_type.id] verifylist = [ ('qos_spec', self.qos_spec.id), - ('volume_type', self.volume_type.id) + ('volume_type', self.volume_type.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.qos_mock.associate.assert_called_with( - self.qos_spec.id, - self.volume_type.id + self.qos_spec.id, self.volume_type.id ) self.assertIsNone(result) class TestQosCreate(TestQos): - - columns = ( - 'consumer', - 'id', - 'name', - 'properties' - ) + columns = ('consumer', 'id', 'name', 'properties') def setUp(self): super().setUp() @@ -86,7 +74,7 @@ class TestQosCreate(TestQos): self.new_qos_spec.consumer, self.new_qos_spec.id, self.new_qos_spec.name, - format_columns.DictColumn(self.new_qos_spec.specs) + format_columns.DictColumn(self.new_qos_spec.specs), ) self.qos_mock.create.return_value = self.new_qos_spec # Get the command object to test @@ -104,8 +92,7 @@ class TestQosCreate(TestQos): columns, data = self.cmd.take_action(parsed_args) self.qos_mock.create.assert_called_with( - self.new_qos_spec.name, - {'consumer': 'both'} + self.new_qos_spec.name, {'consumer': 'both'} ) self.assertEqual(self.columns, columns) @@ -113,7 +100,8 @@ class TestQosCreate(TestQos): def test_qos_create_with_consumer(self): arglist = [ - '--consumer', self.new_qos_spec.consumer, + '--consumer', + self.new_qos_spec.consumer, self.new_qos_spec.name, ] verifylist = [ @@ -125,17 +113,19 @@ class TestQosCreate(TestQos): columns, data = self.cmd.take_action(parsed_args) self.qos_mock.create.assert_called_with( - self.new_qos_spec.name, - {'consumer': self.new_qos_spec.consumer} + self.new_qos_spec.name, {'consumer': self.new_qos_spec.consumer} ) self.assertEqual(self.columns, columns) self.assertCountEqual(self.datalist, data) def test_qos_create_with_properties(self): arglist = [ - '--consumer', self.new_qos_spec.consumer, - '--property', 'foo=bar', - '--property', 'iops=9001', + '--consumer', + self.new_qos_spec.consumer, + '--property', + 'foo=bar', + '--property', + 'iops=9001', self.new_qos_spec.name, ] verifylist = [ @@ -148,10 +138,10 @@ class TestQosCreate(TestQos): columns, data = self.cmd.take_action(parsed_args) self.new_qos_spec.specs.update( - {'consumer': self.new_qos_spec.consumer}) + {'consumer': self.new_qos_spec.consumer} + ) self.qos_mock.create.assert_called_with( - self.new_qos_spec.name, - self.new_qos_spec.specs + self.new_qos_spec.name, self.new_qos_spec.specs ) self.assertEqual(self.columns, columns) @@ -159,24 +149,18 @@ class TestQosCreate(TestQos): class TestQosDelete(TestQos): - qos_specs = volume_fakes.create_qoses(count=2) def setUp(self): super().setUp() - self.qos_mock.get = ( - volume_fakes.get_qoses(self.qos_specs)) + self.qos_mock.get = volume_fakes.get_qoses(self.qos_specs) # Get the command object to test self.cmd = qos_specs.DeleteQos(self.app, None) def test_qos_delete_with_id(self): - arglist = [ - self.qos_specs[0].id - ] - verifylist = [ - ('qos_specs', [self.qos_specs[0].id]) - ] + arglist = [self.qos_specs[0].id] + verifylist = [('qos_specs', [self.qos_specs[0].id])] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) @@ -185,12 +169,8 @@ class TestQosDelete(TestQos): self.assertIsNone(result) def test_qos_delete_with_name(self): - arglist = [ - self.qos_specs[0].name - ] - verifylist = [ - ('qos_specs', [self.qos_specs[0].name]) - ] + arglist = [self.qos_specs[0].name] + verifylist = [('qos_specs', [self.qos_specs[0].name])] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) @@ -199,14 +179,8 @@ class TestQosDelete(TestQos): self.assertIsNone(result) def test_qos_delete_with_force(self): - arglist = [ - '--force', - self.qos_specs[0].id - ] - verifylist = [ - ('force', True), - ('qos_specs', [self.qos_specs[0].id]) - ] + arglist = ['--force', self.qos_specs[0].id] + verifylist = [('force', True), ('qos_specs', [self.qos_specs[0].id])] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) @@ -243,14 +217,16 @@ class TestQosDelete(TestQos): parsed_args = self.check_parser(self.cmd, arglist, verifylist) find_mock_result = [self.qos_specs[0], exceptions.CommandError] - with mock.patch.object(utils, 'find_resource', - side_effect=find_mock_result) as find_mock: + with mock.patch.object( + utils, 'find_resource', side_effect=find_mock_result + ) as find_mock: try: self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: self.assertEqual( - '1 of 2 QoS specifications failed to delete.', str(e)) + '1 of 2 QoS specifications failed to delete.', str(e) + ) find_mock.assert_any_call(self.qos_mock, self.qos_specs[0].id) find_mock.assert_any_call(self.qos_mock, 'unexist_qos') @@ -262,7 +238,6 @@ class TestQosDelete(TestQos): class TestQosDisassociate(TestQos): - volume_type = volume_fakes.create_one_volume_type() qos_spec = volume_fakes.create_one_qos() @@ -276,7 +251,8 @@ class TestQosDisassociate(TestQos): def test_qos_disassociate_with_volume_type(self): arglist = [ - '--volume-type', self.volume_type.id, + '--volume-type', + self.volume_type.id, self.qos_spec.id, ] verifylist = [ @@ -288,8 +264,7 @@ class TestQosDisassociate(TestQos): result = self.cmd.take_action(parsed_args) self.qos_mock.disassociate.assert_called_with( - self.qos_spec.id, - self.volume_type.id + self.qos_spec.id, self.volume_type.id ) self.assertIsNone(result) @@ -298,9 +273,7 @@ class TestQosDisassociate(TestQos): '--all', self.qos_spec.id, ] - verifylist = [ - ('qos_spec', self.qos_spec.id) - ] + verifylist = [('qos_spec', self.qos_spec.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) @@ -310,7 +283,6 @@ class TestQosDisassociate(TestQos): class TestQosList(TestQos): - qos_specs = volume_fakes.create_qoses(count=2) qos_association = volume_fakes.create_one_qos_association() @@ -323,13 +295,15 @@ class TestQosList(TestQos): ) data = [] for q in qos_specs: - data.append(( - q.id, - q.name, - q.consumer, - format_columns.ListColumn([qos_association.name]), - format_columns.DictColumn(q.specs), - )) + data.append( + ( + q.id, + q.name, + q.consumer, + format_columns.ListColumn([qos_association.name]), + format_columns.DictColumn(q.specs), + ) + ) def setUp(self): super().setUp() @@ -381,7 +355,6 @@ class TestQosList(TestQos): class TestQosSet(TestQos): - qos_spec = volume_fakes.create_one_qos() def setUp(self): @@ -393,8 +366,10 @@ class TestQosSet(TestQos): def test_qos_set_with_properties_with_id(self): arglist = [ - '--property', 'foo=bar', - '--property', 'iops=9001', + '--property', + 'foo=bar', + '--property', + 'iops=9001', self.qos_spec.id, ] verifylist = [ @@ -406,14 +381,12 @@ class TestQosSet(TestQos): result = self.cmd.take_action(parsed_args) self.qos_mock.set_keys.assert_called_with( - self.qos_spec.id, - self.qos_spec.specs + self.qos_spec.id, self.qos_spec.specs ) self.assertIsNone(result) class TestQosShow(TestQos): - qos_spec = volume_fakes.create_one_qos() qos_association = volume_fakes.create_one_qos_association() @@ -425,27 +398,15 @@ class TestQosShow(TestQos): self.cmd = qos_specs.ShowQos(self.app, None) def test_qos_show(self): - arglist = [ - self.qos_spec.id - ] - verifylist = [ - ('qos_spec', self.qos_spec.id) - ] + arglist = [self.qos_spec.id] + verifylist = [('qos_spec', self.qos_spec.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.qos_mock.get.assert_called_with( - self.qos_spec.id - ) + self.qos_mock.get.assert_called_with(self.qos_spec.id) - collist = ( - 'associations', - 'consumer', - 'id', - 'name', - 'properties' - ) + collist = ('associations', 'consumer', 'id', 'name', 'properties') self.assertEqual(collist, columns) datalist = ( format_columns.ListColumn([self.qos_association.name]), @@ -458,7 +419,6 @@ class TestQosShow(TestQos): class TestQosUnset(TestQos): - qos_spec = volume_fakes.create_one_qos() def setUp(self): @@ -470,8 +430,10 @@ class TestQosUnset(TestQos): def test_qos_unset_with_properties(self): arglist = [ - '--property', 'iops', - '--property', 'foo', + '--property', + 'iops', + '--property', + 'foo', self.qos_spec.id, ] verifylist = [ @@ -483,8 +445,7 @@ class TestQosUnset(TestQos): result = self.cmd.take_action(parsed_args) self.qos_mock.unset_keys.assert_called_with( - self.qos_spec.id, - ['iops', 'foo'] + self.qos_spec.id, ['iops', 'foo'] ) self.assertIsNone(result) diff --git a/openstackclient/tests/unit/volume/v1/test_service.py b/openstackclient/tests/unit/volume/v1/test_service.py index a199c913..4d32b63e 100644 --- a/openstackclient/tests/unit/volume/v1/test_service.py +++ b/openstackclient/tests/unit/volume/v1/test_service.py @@ -19,7 +19,6 @@ from openstackclient.volume.v1 import service class TestService(volume_fakes.TestVolumev1): - def setUp(self): super().setUp() @@ -29,7 +28,6 @@ class TestService(volume_fakes.TestVolumev1): class TestServiceList(TestService): - # The service to be listed services = volume_fakes.create_one_service() @@ -43,8 +41,10 @@ class TestServiceList(TestService): def test_service_list(self): arglist = [ - '--host', self.services.host, - '--service', self.services.binary, + '--host', + self.services.host, + '--service', + self.services.binary, ] verifylist = [ ('host', self.services.host), @@ -69,14 +69,16 @@ class TestServiceList(TestService): # confirming if all expected columns are present in the result. self.assertEqual(expected_columns, columns) - datalist = (( - self.services.binary, - self.services.host, - self.services.zone, - self.services.status, - self.services.state, - self.services.updated_at, - ), ) + datalist = ( + ( + self.services.binary, + self.services.host, + self.services.zone, + self.services.status, + self.services.state, + self.services.updated_at, + ), + ) # confirming if all expected values are present in the result. self.assertEqual(datalist, tuple(data)) @@ -89,19 +91,20 @@ class TestServiceList(TestService): # checking if prohibited columns are present in output self.assertNotIn("Disabled Reason", columns) - self.assertNotIn(self.services.disabled_reason, - tuple(data)) + self.assertNotIn(self.services.disabled_reason, tuple(data)) def test_service_list_with_long_option(self): arglist = [ - '--host', self.services.host, - '--service', self.services.binary, - '--long' + '--host', + self.services.host, + '--service', + self.services.binary, + '--long', ] verifylist = [ ('host', self.services.host), ('service', self.services.binary), - ('long', True) + ('long', True), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -117,21 +120,23 @@ class TestServiceList(TestService): 'Status', 'State', 'Updated At', - 'Disabled Reason' + 'Disabled Reason', ] # confirming if all expected columns are present in the result. self.assertEqual(expected_columns, columns) - datalist = (( - self.services.binary, - self.services.host, - self.services.zone, - self.services.status, - self.services.state, - self.services.updated_at, - self.services.disabled_reason, - ), ) + datalist = ( + ( + self.services.binary, + self.services.host, + self.services.zone, + self.services.status, + self.services.state, + self.services.updated_at, + self.services.disabled_reason, + ), + ) # confirming if all expected values are present in the result. self.assertEqual(datalist, tuple(data)) @@ -143,7 +148,6 @@ class TestServiceList(TestService): class TestServiceSet(TestService): - service = volume_fakes.create_one_service() def setUp(self): @@ -188,8 +192,7 @@ class TestServiceSet(TestService): result = self.cmd.take_action(parsed_args) self.service_mock.enable.assert_called_with( - self.service.host, - self.service.binary + self.service.host, self.service.binary ) self.service_mock.disable.assert_not_called() self.service_mock.disable_log_reason.assert_not_called() @@ -211,8 +214,7 @@ class TestServiceSet(TestService): result = self.cmd.take_action(parsed_args) self.service_mock.disable.assert_called_with( - self.service.host, - self.service.binary + self.service.host, self.service.binary ) self.service_mock.enable.assert_not_called() self.service_mock.disable_log_reason.assert_not_called() @@ -222,7 +224,8 @@ class TestServiceSet(TestService): reason = 'earthquake' arglist = [ '--disable', - '--disable-reason', reason, + '--disable-reason', + reason, self.service.host, self.service.binary, ] @@ -237,16 +240,15 @@ class TestServiceSet(TestService): result = self.cmd.take_action(parsed_args) self.service_mock.disable_log_reason.assert_called_with( - self.service.host, - self.service.binary, - reason + self.service.host, self.service.binary, reason ) self.assertIsNone(result) def test_service_set_only_with_disable_reason(self): reason = 'earthquake' arglist = [ - '--disable-reason', reason, + '--disable-reason', + reason, self.service.host, self.service.binary, ] @@ -260,14 +262,18 @@ class TestServiceSet(TestService): self.cmd.take_action(parsed_args) self.fail("CommandError should be raised.") except exceptions.CommandError as e: - self.assertEqual("Cannot specify option --disable-reason without " - "--disable specified.", str(e)) + self.assertEqual( + "Cannot specify option --disable-reason without " + "--disable specified.", + str(e), + ) def test_service_set_enable_with_disable_reason(self): reason = 'earthquake' arglist = [ '--enable', - '--disable-reason', reason, + '--disable-reason', + reason, self.service.host, self.service.binary, ] @@ -282,5 +288,8 @@ class TestServiceSet(TestService): self.cmd.take_action(parsed_args) self.fail("CommandError should be raised.") except exceptions.CommandError as e: - self.assertEqual("Cannot specify option --disable-reason without " - "--disable specified.", str(e)) + self.assertEqual( + "Cannot specify option --disable-reason without " + "--disable specified.", + str(e), + ) diff --git a/openstackclient/tests/unit/volume/v1/test_transfer_request.py b/openstackclient/tests/unit/volume/v1/test_transfer_request.py index 97700fbb..e342d38c 100644 --- a/openstackclient/tests/unit/volume/v1/test_transfer_request.py +++ b/openstackclient/tests/unit/volume/v1/test_transfer_request.py @@ -23,7 +23,6 @@ from openstackclient.volume.v1 import volume_transfer_request class TestTransfer(volume_fakes.TestVolumev1): - def setUp(self): super().setUp() @@ -37,7 +36,6 @@ class TestTransfer(volume_fakes.TestVolumev1): class TestTransferAccept(TestTransfer): - columns = ( 'id', 'name', @@ -59,11 +57,13 @@ class TestTransferAccept(TestTransfer): # Get the command object to test self.cmd = volume_transfer_request.AcceptTransferRequest( - self.app, None) + self.app, None + ) def test_transfer_accept(self): arglist = [ - '--auth-key', 'key_value', + '--auth-key', + 'key_value', self.volume_transfer.id, ] verifylist = [ @@ -101,7 +101,6 @@ class TestTransferAccept(TestTransfer): class TestTransferCreate(TestTransfer): - volume = volume_fakes.create_one_volume() columns = ( @@ -135,7 +134,8 @@ class TestTransferCreate(TestTransfer): # Get the command object to test self.cmd = volume_transfer_request.CreateTransferRequest( - self.app, None) + self.app, None + ) def test_transfer_create_without_name(self): arglist = [ @@ -148,14 +148,14 @@ class TestTransferCreate(TestTransfer): columns, data = self.cmd.take_action(parsed_args) - self.transfer_mock.create.assert_called_once_with( - self.volume.id, None) + self.transfer_mock.create.assert_called_once_with(self.volume.id, None) self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) def test_transfer_create_with_name(self): arglist = [ - '--name', self.volume_transfer.name, + '--name', + self.volume_transfer.name, self.volume.id, ] verifylist = [ @@ -167,13 +167,14 @@ class TestTransferCreate(TestTransfer): columns, data = self.cmd.take_action(parsed_args) self.transfer_mock.create.assert_called_once_with( - self.volume.id, self.volume_transfer.name,) + self.volume.id, + self.volume_transfer.name, + ) self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) class TestTransferDelete(TestTransfer): - volume_transfers = volume_fakes.create_transfers(count=2) def setUp(self): @@ -186,21 +187,19 @@ class TestTransferDelete(TestTransfer): # Get the command object to mock self.cmd = volume_transfer_request.DeleteTransferRequest( - self.app, None) + self.app, None + ) def test_transfer_delete(self): - arglist = [ - self.volume_transfers[0].id - ] - verifylist = [ - ("transfer_request", [self.volume_transfers[0].id]) - ] + arglist = [self.volume_transfers[0].id] + verifylist = [("transfer_request", [self.volume_transfers[0].id])] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.transfer_mock.delete.assert_called_with( - self.volume_transfers[0].id) + self.volume_transfers[0].id + ) self.assertIsNone(result) def test_delete_multiple_transfers(self): @@ -232,17 +231,21 @@ class TestTransferDelete(TestTransfer): parsed_args = self.check_parser(self.cmd, arglist, verifylist) find_mock_result = [self.volume_transfers[0], exceptions.CommandError] - with mock.patch.object(utils, 'find_resource', - side_effect=find_mock_result) as find_mock: + with mock.patch.object( + utils, 'find_resource', side_effect=find_mock_result + ) as find_mock: try: self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual('1 of 2 volume transfer requests failed ' - 'to delete', str(e)) + self.assertEqual( + '1 of 2 volume transfer requests failed ' 'to delete', + str(e), + ) find_mock.assert_any_call( - self.transfer_mock, self.volume_transfers[0].id) + self.transfer_mock, self.volume_transfers[0].id + ) find_mock.assert_any_call(self.transfer_mock, 'unexist_transfer') self.assertEqual(2, find_mock.call_count) @@ -252,7 +255,6 @@ class TestTransferDelete(TestTransfer): class TestTransferList(TestTransfer): - # The Transfers to be listed volume_transfers = volume_fakes.create_one_transfer() @@ -283,28 +285,25 @@ class TestTransferList(TestTransfer): # confirming if all expected columns are present in the result. self.assertEqual(expected_columns, columns) - datalist = (( - self.volume_transfers.id, - self.volume_transfers.name, - self.volume_transfers.volume_id, - ), ) + datalist = ( + ( + self.volume_transfers.id, + self.volume_transfers.name, + self.volume_transfers.volume_id, + ), + ) # confirming if all expected values are present in the result. self.assertEqual(datalist, tuple(data)) # checking if proper call was made to list volume_transfers self.transfer_mock.list.assert_called_with( - detailed=True, - search_opts={'all_tenants': 0} + detailed=True, search_opts={'all_tenants': 0} ) def test_transfer_list_with_argument(self): - arglist = [ - "--all-projects" - ] - verifylist = [ - ("all_projects", True) - ] + arglist = ["--all-projects"] + verifylist = [("all_projects", True)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -322,24 +321,24 @@ class TestTransferList(TestTransfer): # confirming if all expected columns are present in the result. self.assertEqual(expected_columns, columns) - datalist = (( - self.volume_transfers.id, - self.volume_transfers.name, - self.volume_transfers.volume_id, - ), ) + datalist = ( + ( + self.volume_transfers.id, + self.volume_transfers.name, + self.volume_transfers.volume_id, + ), + ) # confirming if all expected values are present in the result. self.assertEqual(datalist, tuple(data)) # checking if proper call was made to list volume_transfers self.transfer_mock.list.assert_called_with( - detailed=True, - search_opts={'all_tenants': 1} + detailed=True, search_opts={'all_tenants': 1} ) class TestTransferShow(TestTransfer): - columns = ( 'created_at', 'id', @@ -363,8 +362,7 @@ class TestTransferShow(TestTransfer): self.transfer_mock.get.return_value = self.volume_transfer # Get the command object to test - self.cmd = volume_transfer_request.ShowTransferRequest( - self.app, None) + self.cmd = volume_transfer_request.ShowTransferRequest(self.app, None) def test_transfer_show(self): arglist = [ @@ -377,7 +375,6 @@ class TestTransferShow(TestTransfer): columns, data = self.cmd.take_action(parsed_args) - self.transfer_mock.get.assert_called_once_with( - self.volume_transfer.id) + self.transfer_mock.get.assert_called_once_with(self.volume_transfer.id) self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) diff --git a/openstackclient/tests/unit/volume/v1/test_type.py b/openstackclient/tests/unit/volume/v1/test_type.py index c8788249..425c164f 100644 --- a/openstackclient/tests/unit/volume/v1/test_type.py +++ b/openstackclient/tests/unit/volume/v1/test_type.py @@ -25,7 +25,6 @@ from openstackclient.volume.v1 import volume_type class TestType(volume_fakes.TestVolumev1): - def setUp(self): super().setUp() @@ -33,12 +32,12 @@ class TestType(volume_fakes.TestVolumev1): self.types_mock.reset_mock() self.encryption_types_mock = ( - self.app.client_manager.volume.volume_encryption_types) + self.app.client_manager.volume.volume_encryption_types + ) self.encryption_types_mock.reset_mock() class TestTypeCreate(TestType): - columns = ( 'description', 'id', @@ -110,10 +109,14 @@ class TestTypeCreate(TestType): self.new_volume_type.name, ) arglist = [ - '--encryption-provider', 'LuksEncryptor', - '--encryption-cipher', 'aes-xts-plain64', - '--encryption-key-size', '128', - '--encryption-control-location', 'front-end', + '--encryption-provider', + 'LuksEncryptor', + '--encryption-cipher', + 'aes-xts-plain64', + '--encryption-key-size', + '128', + '--encryption-control-location', + 'front-end', self.new_volume_type.name, ] verifylist = [ @@ -144,7 +147,6 @@ class TestTypeCreate(TestType): class TestTypeDelete(TestType): - volume_types = volume_fakes.create_volume_types(count=2) def setUp(self): @@ -157,12 +159,8 @@ class TestTypeDelete(TestType): self.cmd = volume_type.DeleteVolumeType(self.app, None) def test_type_delete(self): - arglist = [ - self.volume_types[0].id - ] - verifylist = [ - ("volume_types", [self.volume_types[0].id]) - ] + arglist = [self.volume_types[0].id] + verifylist = [("volume_types", [self.volume_types[0].id])] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) @@ -199,17 +197,18 @@ class TestTypeDelete(TestType): parsed_args = self.check_parser(self.cmd, arglist, verifylist) find_mock_result = [self.volume_types[0], exceptions.CommandError] - with mock.patch.object(utils, 'find_resource', - side_effect=find_mock_result) as find_mock: + with mock.patch.object( + utils, 'find_resource', side_effect=find_mock_result + ) as find_mock: try: self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual('1 of 2 volume types failed to delete.', - str(e)) + self.assertEqual( + '1 of 2 volume types failed to delete.', str(e) + ) - find_mock.assert_any_call( - self.types_mock, self.volume_types[0].id) + find_mock.assert_any_call(self.types_mock, self.volume_types[0].id) find_mock.assert_any_call(self.types_mock, 'unexist_type') self.assertEqual(2, find_mock.call_count) @@ -219,7 +218,6 @@ class TestTypeDelete(TestType): class TestTypeList(TestType): - volume_types = volume_fakes.create_volume_types() columns = [ @@ -227,28 +225,27 @@ class TestTypeList(TestType): "Name", "Is Public", ] - columns_long = [ - "ID", - "Name", - "Is Public", - "Properties" - ] + columns_long = ["ID", "Name", "Is Public", "Properties"] data = [] for t in volume_types: - data.append(( - t.id, - t.name, - t.is_public, - )) + data.append( + ( + t.id, + t.name, + t.is_public, + ) + ) data_long = [] for t in volume_types: - data_long.append(( - t.id, - t.name, - t.is_public, - format_columns.DictColumn(t.extra_specs), - )) + data_long.append( + ( + t.id, + t.name, + t.is_public, + format_columns.DictColumn(t.extra_specs), + ) + ) def setUp(self): super().setUp() @@ -300,21 +297,25 @@ class TestTypeList(TestType): "Encryption", ] encryption_data = [] - encryption_data.append(( - self.volume_types[0].id, - self.volume_types[0].name, - self.volume_types[0].is_public, - volume_type.EncryptionInfoColumn( + encryption_data.append( + ( self.volume_types[0].id, - {self.volume_types[0].id: encryption_info}), - )) - encryption_data.append(( - self.volume_types[1].id, - self.volume_types[1].name, - self.volume_types[1].is_public, - volume_type.EncryptionInfoColumn( - self.volume_types[1].id, {}), - )) + self.volume_types[0].name, + self.volume_types[0].is_public, + volume_type.EncryptionInfoColumn( + self.volume_types[0].id, + {self.volume_types[0].id: encryption_info}, + ), + ) + ) + encryption_data.append( + ( + self.volume_types[1].id, + self.volume_types[1].name, + self.volume_types[1].is_public, + volume_type.EncryptionInfoColumn(self.volume_types[1].id, {}), + ) + ) self.encryption_types_mock.list.return_value = [encryption_type] arglist = [ @@ -333,7 +334,6 @@ class TestTypeList(TestType): class TestTypeSet(TestType): - volume_type = volume_fakes.create_one_volume_type( methods={'set_keys': None}, ) @@ -361,7 +361,8 @@ class TestTypeSet(TestType): def test_type_set_property(self): arglist = [ - '--property', 'myprop=myvalue', + '--property', + 'myprop=myvalue', self.volume_type.id, ] verifylist = [ @@ -372,15 +373,20 @@ class TestTypeSet(TestType): result = self.cmd.take_action(parsed_args) self.volume_type.set_keys.assert_called_once_with( - {'myprop': 'myvalue'}) + {'myprop': 'myvalue'} + ) self.assertIsNone(result) def test_type_set_new_encryption(self): arglist = [ - '--encryption-provider', 'LuksEncryptor', - '--encryption-cipher', 'aes-xts-plain64', - '--encryption-key-size', '128', - '--encryption-control-location', 'front-end', + '--encryption-provider', + 'LuksEncryptor', + '--encryption-cipher', + 'aes-xts-plain64', + '--encryption-key-size', + '128', + '--encryption-control-location', + 'front-end', self.volume_type.id, ] verifylist = [ @@ -407,9 +413,12 @@ class TestTypeSet(TestType): def test_type_set_new_encryption_without_provider(self): arglist = [ - '--encryption-cipher', 'aes-xts-plain64', - '--encryption-key-size', '128', - '--encryption-control-location', 'front-end', + '--encryption-cipher', + 'aes-xts-plain64', + '--encryption-key-size', + '128', + '--encryption-control-location', + 'front-end', self.volume_type.id, ] verifylist = [ @@ -423,15 +432,15 @@ class TestTypeSet(TestType): self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual("Command Failed: One or more of" - " the operations failed", - str(e)) + self.assertEqual( + "Command Failed: One or more of" " the operations failed", + str(e), + ) self.encryption_types_mock.create.assert_not_called() self.encryption_types_mock.update.assert_not_called() class TestTypeShow(TestType): - columns = ( 'description', 'id', @@ -449,7 +458,7 @@ class TestTypeShow(TestType): self.volume_type.id, True, self.volume_type.name, - format_columns.DictColumn(self.volume_type.extra_specs) + format_columns.DictColumn(self.volume_type.extra_specs), ) self.types_mock.get.return_value = self.volume_type @@ -458,9 +467,7 @@ class TestTypeShow(TestType): self.cmd = volume_type.ShowVolumeType(self.app, None) def test_type_show(self): - arglist = [ - self.volume_type.id - ] + arglist = [self.volume_type.id] verifylist = [ ("volume_type", self.volume_type.id), ("encryption_type", False), @@ -500,15 +507,12 @@ class TestTypeShow(TestType): self.volume_type.id, True, self.volume_type.name, - format_columns.DictColumn(self.volume_type.extra_specs) + format_columns.DictColumn(self.volume_type.extra_specs), ) - arglist = [ - '--encryption-type', - self.volume_type.id - ] + arglist = ['--encryption-type', self.volume_type.id] verifylist = [ ('encryption_type', True), - ("volume_type", self.volume_type.id) + ("volume_type", self.volume_type.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -520,7 +524,6 @@ class TestTypeShow(TestType): class TestTypeUnset(TestType): - volume_type = volume_fakes.create_one_volume_type( methods={'unset_keys': None}, ) @@ -535,8 +538,10 @@ class TestTypeUnset(TestType): def test_type_unset_property(self): arglist = [ - '--property', 'property', - '--property', 'multi_property', + '--property', + 'property', + '--property', + 'multi_property', self.volume_type.id, ] verifylist = [ @@ -549,24 +554,29 @@ class TestTypeUnset(TestType): result = self.cmd.take_action(parsed_args) self.volume_type.unset_keys.assert_called_once_with( - ['property', 'multi_property']) + ['property', 'multi_property'] + ) self.encryption_types_mock.delete.assert_not_called() self.assertIsNone(result) def test_type_unset_failed_with_missing_volume_type_argument(self): arglist = [ - '--property', 'property', - '--property', 'multi_property', + '--property', + 'property', + '--property', + 'multi_property', ] verifylist = [ ('property', ['property', 'multi_property']), ] - self.assertRaises(tests_utils.ParserException, - self.check_parser, - self.cmd, - arglist, - verifylist) + self.assertRaises( + tests_utils.ParserException, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) def test_type_unset_nothing(self): arglist = [ @@ -598,7 +608,6 @@ class TestTypeUnset(TestType): class TestColumns(TestType): - def test_encryption_info_column_with_info(self): fake_volume_type = volume_fakes.create_one_volume_type() type_id = fake_volume_type.id @@ -609,10 +618,12 @@ class TestColumns(TestType): 'key_size': None, 'control_location': 'front-end', } - col = volume_type.EncryptionInfoColumn(type_id, - {type_id: encryption_info}) - self.assertEqual(utils.format_dict(encryption_info), - col.human_readable()) + col = volume_type.EncryptionInfoColumn( + type_id, {type_id: encryption_info} + ) + self.assertEqual( + utils.format_dict(encryption_info), col.human_readable() + ) self.assertEqual(encryption_info, col.machine_readable()) def test_encryption_info_column_without_info(self): diff --git a/openstackclient/tests/unit/volume/v1/test_volume.py b/openstackclient/tests/unit/volume/v1/test_volume.py index b46a608d..60d6ead7 100644 --- a/openstackclient/tests/unit/volume/v1/test_volume.py +++ b/openstackclient/tests/unit/volume/v1/test_volume.py @@ -29,7 +29,6 @@ from openstackclient.volume.v1 import volume class TestVolume(volume_fakes.TestVolumev1): - def setUp(self): super().setUp() @@ -57,7 +56,6 @@ class TestVolume(volume_fakes.TestVolumev1): class TestVolumeCreate(TestVolume): - project = identity_fakes.FakeProject.create_one_project() user = identity_fakes.FakeUser.create_one_user() @@ -100,7 +98,8 @@ class TestVolumeCreate(TestVolume): def test_volume_create_min_options(self): arglist = [ - '--size', str(self.new_volume.size), + '--size', + str(self.new_volume.size), self.new_volume.display_name, ] verifylist = [ @@ -137,10 +136,14 @@ class TestVolumeCreate(TestVolume): def test_volume_create_options(self): arglist = [ - '--size', str(self.new_volume.size), - '--description', self.new_volume.display_description, - '--type', self.new_volume.volume_type, - '--availability-zone', self.new_volume.availability_zone, + '--size', + str(self.new_volume.size), + '--description', + self.new_volume.display_description, + '--type', + self.new_volume.volume_type, + '--availability-zone', + self.new_volume.availability_zone, self.new_volume.display_name, ] verifylist = [ @@ -186,9 +189,12 @@ class TestVolumeCreate(TestVolume): self.users_mock.get.return_value = self.user arglist = [ - '--size', str(self.new_volume.size), - '--project', self.project.id, - '--user', self.user.id, + '--size', + str(self.new_volume.size), + '--project', + self.project.id, + '--user', + self.user.id, self.new_volume.display_name, ] verifylist = [ @@ -233,9 +239,12 @@ class TestVolumeCreate(TestVolume): self.users_mock.get.return_value = self.user arglist = [ - '--size', str(self.new_volume.size), - '--project', self.project.name, - '--user', self.user.name, + '--size', + str(self.new_volume.size), + '--project', + self.project.name, + '--user', + self.user.name, self.new_volume.display_name, ] verifylist = [ @@ -275,9 +284,12 @@ class TestVolumeCreate(TestVolume): def test_volume_create_properties(self): arglist = [ - '--property', 'Alpha=a', - '--property', 'Beta=b', - '--size', str(self.new_volume.size), + '--property', + 'Alpha=a', + '--property', + 'Beta=b', + '--size', + str(self.new_volume.size), self.new_volume.display_name, ] verifylist = [ @@ -319,8 +331,10 @@ class TestVolumeCreate(TestVolume): self.images_mock.get.return_value = image arglist = [ - '--image', image.id, - '--size', str(self.new_volume.size), + '--image', + image.id, + '--size', + str(self.new_volume.size), self.new_volume.display_name, ] verifylist = [ @@ -362,8 +376,10 @@ class TestVolumeCreate(TestVolume): self.images_mock.get.return_value = image arglist = [ - '--image', image.name, - '--size', str(self.new_volume.size), + '--image', + image.name, + '--size', + str(self.new_volume.size), self.new_volume.display_name, ] verifylist = [ @@ -403,7 +419,8 @@ class TestVolumeCreate(TestVolume): def test_volume_create_with_source(self): self.volumes_mock.get.return_value = self.new_volume arglist = [ - '--source', self.new_volume.id, + '--source', + self.new_volume.id, self.new_volume.display_name, ] verifylist = [ @@ -435,7 +452,8 @@ class TestVolumeCreate(TestVolume): arglist = [ '--bootable', '--read-only', - '--size', str(self.new_volume.size), + '--size', + str(self.new_volume.size), self.new_volume.display_name, ] verifylist = [ @@ -447,8 +465,7 @@ class TestVolumeCreate(TestVolume): ('name', self.new_volume.display_name), ] - parsed_args = self.check_parser( - self.cmd, arglist, verifylist) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) @@ -469,16 +486,19 @@ class TestVolumeCreate(TestVolume): self.assertEqual(self.columns, columns) self.assertCountEqual(self.datalist, data) self.volumes_mock.set_bootable.assert_called_with( - self.new_volume.id, True) + self.new_volume.id, True + ) self.volumes_mock.update_readonly_flag.assert_called_with( - self.new_volume.id, True) + self.new_volume.id, True + ) @mock.patch.object(utils, 'wait_for_status', return_value=True) def test_volume_create_with_nonbootable_and_readwrite(self, mock_wait): arglist = [ '--non-bootable', '--read-write', - '--size', str(self.new_volume.size), + '--size', + str(self.new_volume.size), self.new_volume.display_name, ] verifylist = [ @@ -490,8 +510,7 @@ class TestVolumeCreate(TestVolume): ('name', self.new_volume.display_name), ] - parsed_args = self.check_parser( - self.cmd, arglist, verifylist) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) @@ -512,25 +531,28 @@ class TestVolumeCreate(TestVolume): self.assertEqual(self.columns, columns) self.assertCountEqual(self.datalist, data) self.volumes_mock.set_bootable.assert_called_with( - self.new_volume.id, False) + self.new_volume.id, False + ) self.volumes_mock.update_readonly_flag.assert_called_with( - self.new_volume.id, False) + self.new_volume.id, False + ) @mock.patch.object(volume.LOG, 'error') @mock.patch.object(utils, 'wait_for_status', return_value=True) def test_volume_create_with_bootable_and_readonly_fail( - self, mock_wait, mock_error): - - self.volumes_mock.set_bootable.side_effect = ( - exceptions.CommandError()) + self, mock_wait, mock_error + ): + self.volumes_mock.set_bootable.side_effect = exceptions.CommandError() self.volumes_mock.update_readonly_flag.side_effect = ( - exceptions.CommandError()) + exceptions.CommandError() + ) arglist = [ '--bootable', '--read-only', - '--size', str(self.new_volume.size), + '--size', + str(self.new_volume.size), self.new_volume.display_name, ] verifylist = [ @@ -542,8 +564,7 @@ class TestVolumeCreate(TestVolume): ('name', self.new_volume.display_name), ] - parsed_args = self.check_parser( - self.cmd, arglist, verifylist) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) @@ -565,18 +586,22 @@ class TestVolumeCreate(TestVolume): self.assertEqual(self.columns, columns) self.assertCountEqual(self.datalist, data) self.volumes_mock.set_bootable.assert_called_with( - self.new_volume.id, True) + self.new_volume.id, True + ) self.volumes_mock.update_readonly_flag.assert_called_with( - self.new_volume.id, True) + self.new_volume.id, True + ) @mock.patch.object(volume.LOG, 'error') @mock.patch.object(utils, 'wait_for_status', return_value=False) def test_volume_create_non_available_with_readonly( - self, mock_wait, mock_error): + self, mock_wait, mock_error + ): arglist = [ '--non-bootable', '--read-only', - '--size', str(self.new_volume.size), + '--size', + str(self.new_volume.size), self.new_volume.display_name, ] verifylist = [ @@ -588,8 +613,7 @@ class TestVolumeCreate(TestVolume): ('name', self.new_volume.display_name), ] - parsed_args = self.check_parser( - self.cmd, arglist, verifylist) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) @@ -620,15 +644,20 @@ class TestVolumeCreate(TestVolume): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) + self.assertRaises( + exceptions.CommandError, self.cmd.take_action, parsed_args + ) def test_volume_create_with_multi_source(self): arglist = [ - '--image', 'source_image', - '--source', 'source_volume', - '--snapshot', 'source_snapshot', - '--size', str(self.new_volume.size), + '--image', + 'source_image', + '--source', + 'source_volume', + '--snapshot', + 'source_snapshot', + '--size', + str(self.new_volume.size), self.new_volume.display_name, ] verifylist = [ @@ -639,13 +668,20 @@ class TestVolumeCreate(TestVolume): ('name', self.new_volume.display_name), ] - self.assertRaises(tests_utils.ParserException, self.check_parser, - self.cmd, arglist, verifylist) + self.assertRaises( + tests_utils.ParserException, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) def test_volume_create_backward_compatibility(self): arglist = [ - '-c', 'display_name', - '--size', str(self.new_volume.size), + '-c', + 'display_name', + '--size', + str(self.new_volume.size), self.new_volume.display_name, ] verifylist = [ @@ -676,7 +712,6 @@ class TestVolumeCreate(TestVolume): class TestVolumeDelete(TestVolume): - def setUp(self): super().setUp() @@ -688,9 +723,7 @@ class TestVolumeDelete(TestVolume): def test_volume_delete_one_volume(self): volumes = self.setup_volumes_mock(count=1) - arglist = [ - volumes[0].id - ] + arglist = [volumes[0].id] verifylist = [ ("force", False), ("volumes", [volumes[0].id]), @@ -732,14 +765,14 @@ class TestVolumeDelete(TestVolume): parsed_args = self.check_parser(self.cmd, arglist, verifylist) find_mock_result = [volumes[0], exceptions.CommandError] - with mock.patch.object(utils, 'find_resource', - side_effect=find_mock_result) as find_mock: + with mock.patch.object( + utils, 'find_resource', side_effect=find_mock_result + ) as find_mock: try: self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual('1 of 2 volumes failed to delete.', - str(e)) + self.assertEqual('1 of 2 volumes failed to delete.', str(e)) find_mock.assert_any_call(self.volumes_mock, volumes[0].id) find_mock.assert_any_call(self.volumes_mock, 'unexist_volume') @@ -767,7 +800,6 @@ class TestVolumeDelete(TestVolume): class TestVolumeList(TestVolume): - _volume = volume_fakes.create_one_volume() columns = ( 'ID', @@ -812,7 +844,8 @@ class TestVolumeList(TestVolume): def test_volume_list_name(self): arglist = [ - '--name', self._volume.display_name, + '--name', + self._volume.display_name, ] verifylist = [ ('long', False), @@ -829,7 +862,8 @@ class TestVolumeList(TestVolume): def test_volume_list_status(self): arglist = [ - '--status', self._volume.status, + '--status', + self._volume.status, ] verifylist = [ ('long', False), @@ -889,22 +923,26 @@ class TestVolumeList(TestVolume): ) self.assertEqual(collist, columns) - datalist = (( - self._volume.id, - self._volume.display_name, - self._volume.status, - self._volume.size, - self._volume.volume_type, - self._volume.bootable, - volume.AttachmentsColumn(self._volume.attachments), - format_columns.DictColumn(self._volume.metadata), - ), ) + datalist = ( + ( + self._volume.id, + self._volume.display_name, + self._volume.status, + self._volume.size, + self._volume.volume_type, + self._volume.bootable, + volume.AttachmentsColumn(self._volume.attachments), + format_columns.DictColumn(self._volume.metadata), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_with_limit_and_offset(self): arglist = [ - '--limit', '2', - '--offset', '5', + '--limit', + '2', + '--offset', + '5', ] verifylist = [ ('long', False), @@ -932,17 +970,24 @@ class TestVolumeList(TestVolume): def test_volume_list_negative_limit(self): arglist = [ - "--limit", "-2", + "--limit", + "-2", ] verifylist = [ ("limit", -2), ] - self.assertRaises(argparse.ArgumentTypeError, self.check_parser, - self.cmd, arglist, verifylist) + self.assertRaises( + argparse.ArgumentTypeError, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) def test_volume_list_backward_compatibility(self): arglist = [ - '-c', 'Display Name', + '-c', + 'Display Name', ] verifylist = [ ('columns', ['Display Name']), @@ -963,7 +1008,6 @@ class TestVolumeList(TestVolume): class TestVolumeMigrate(TestVolume): - _volume = volume_fakes.create_one_volume() def setUp(self): @@ -976,7 +1020,8 @@ class TestVolumeMigrate(TestVolume): def test_volume_migrate(self): arglist = [ - "--host", "host@backend-name#pool", + "--host", + "host@backend-name#pool", self._volume.id, ] verifylist = [ @@ -989,13 +1034,15 @@ class TestVolumeMigrate(TestVolume): result = self.cmd.take_action(parsed_args) self.volumes_mock.get.assert_called_once_with(self._volume.id) self.volumes_mock.migrate_volume.assert_called_once_with( - self._volume.id, "host@backend-name#pool", False) + self._volume.id, "host@backend-name#pool", False + ) self.assertIsNone(result) def test_volume_migrate_with_option(self): arglist = [ "--force-host-copy", - "--host", "host@backend-name#pool", + "--host", + "host@backend-name#pool", self._volume.id, ] verifylist = [ @@ -1008,7 +1055,8 @@ class TestVolumeMigrate(TestVolume): result = self.cmd.take_action(parsed_args) self.volumes_mock.get.assert_called_once_with(self._volume.id) self.volumes_mock.migrate_volume.assert_called_once_with( - self._volume.id, "host@backend-name#pool", True) + self._volume.id, "host@backend-name#pool", True + ) self.assertIsNone(result) def test_volume_migrate_without_host(self): @@ -1020,12 +1068,16 @@ class TestVolumeMigrate(TestVolume): ("volume", self._volume.id), ] - self.assertRaises(tests_utils.ParserException, self.check_parser, - self.cmd, arglist, verifylist) + self.assertRaises( + tests_utils.ParserException, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) class TestVolumeSet(TestVolume): - _volume = volume_fakes.create_one_volume() def setUp(self): @@ -1055,7 +1107,8 @@ class TestVolumeSet(TestVolume): def test_volume_set_name(self): arglist = [ - '--name', 'qwerty', + '--name', + 'qwerty', self._volume.display_name, ] verifylist = [ @@ -1073,15 +1126,13 @@ class TestVolumeSet(TestVolume): kwargs = { 'display_name': 'qwerty', } - self.volumes_mock.update.assert_called_with( - self._volume.id, - **kwargs - ) + self.volumes_mock.update.assert_called_with(self._volume.id, **kwargs) self.assertIsNone(result) def test_volume_set_description(self): arglist = [ - '--description', 'new desc', + '--description', + 'new desc', self._volume.display_name, ] verifylist = [ @@ -1099,15 +1150,13 @@ class TestVolumeSet(TestVolume): kwargs = { 'display_description': 'new desc', } - self.volumes_mock.update.assert_called_with( - self._volume.id, - **kwargs - ) + self.volumes_mock.update.assert_called_with(self._volume.id, **kwargs) self.assertIsNone(result) def test_volume_set_size(self): arglist = [ - '--size', '130', + '--size', + '130', self._volume.display_name, ] verifylist = [ @@ -1123,16 +1172,14 @@ class TestVolumeSet(TestVolume): # Set expected values size = 130 - self.volumes_mock.extend.assert_called_with( - self._volume.id, - size - ) + self.volumes_mock.extend.assert_called_with(self._volume.id, size) self.assertIsNone(result) def test_volume_set_size_smaller(self): self._volume.status = 'available' arglist = [ - '--size', '1', + '--size', + '1', self._volume.display_name, ] verifylist = [ @@ -1144,14 +1191,15 @@ class TestVolumeSet(TestVolume): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.assertRaises(exceptions.CommandError, - self.cmd.take_action, - parsed_args) + self.assertRaises( + exceptions.CommandError, self.cmd.take_action, parsed_args + ) def test_volume_set_size_not_available(self): self._volume.status = 'error' arglist = [ - '--size', '130', + '--size', + '130', self._volume.display_name, ] verifylist = [ @@ -1163,14 +1211,15 @@ class TestVolumeSet(TestVolume): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.assertRaises(exceptions.CommandError, - self.cmd.take_action, - parsed_args) + self.assertRaises( + exceptions.CommandError, self.cmd.take_action, parsed_args + ) def test_volume_set_property(self): arglist = [ '--no-property', - '--property', 'myprop=myvalue', + '--property', + 'myprop=myvalue', self._volume.display_name, ] verifylist = [ @@ -1183,23 +1232,19 @@ class TestVolumeSet(TestVolume): ('property', {'myprop': 'myvalue'}), ('volume', self._volume.display_name), ('bootable', False), - ('non_bootable', False) + ('non_bootable', False), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) # Set expected values - metadata = { - 'myprop': 'myvalue' - } + metadata = {'myprop': 'myvalue'} self.volumes_mock.set_metadata.assert_called_with( - self._volume.id, - metadata + self._volume.id, metadata ) self.volumes_mock.delete_metadata.assert_called_with( - self._volume.id, - self._volume.metadata.keys() + self._volume.id, self._volume.metadata.keys() ) self.volumes_mock.update_readonly_flag.assert_not_called() self.assertIsNone(result) @@ -1207,69 +1252,64 @@ class TestVolumeSet(TestVolume): def test_volume_set_bootable(self): arglist = [ ['--bootable', self._volume.id], - ['--non-bootable', self._volume.id] + ['--non-bootable', self._volume.id], ] verifylist = [ [ ('bootable', True), ('non_bootable', False), - ('volume', self._volume.id) + ('volume', self._volume.id), ], [ ('bootable', False), ('non_bootable', True), - ('volume', self._volume.id) - ] + ('volume', self._volume.id), + ], ] for index in range(len(arglist)): parsed_args = self.check_parser( - self.cmd, arglist[index], verifylist[index]) + self.cmd, arglist[index], verifylist[index] + ) self.cmd.take_action(parsed_args) self.volumes_mock.set_bootable.assert_called_with( - self._volume.id, verifylist[index][0][1]) + self._volume.id, verifylist[index][0][1] + ) def test_volume_set_readonly(self): - arglist = [ - '--read-only', - self._volume.id - ] + arglist = ['--read-only', self._volume.id] verifylist = [ ('read_only', True), ('read_write', False), - ('volume', self._volume.id) + ('volume', self._volume.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.volumes_mock.update_readonly_flag.assert_called_once_with( - self._volume.id, - True) + self._volume.id, True + ) self.assertIsNone(result) def test_volume_set_read_write(self): - arglist = [ - '--read-write', - self._volume.id - ] + arglist = ['--read-write', self._volume.id] verifylist = [ ('read_only', False), ('read_write', True), - ('volume', self._volume.id) + ('volume', self._volume.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.volumes_mock.update_readonly_flag.assert_called_once_with( - self._volume.id, - False) + self._volume.id, False + ) self.assertIsNone(result) class TestVolumeShow(TestVolume): - columns = ( 'attachments', 'availability_zone', @@ -1307,12 +1347,8 @@ class TestVolumeShow(TestVolume): self.cmd = volume.ShowVolume(self.app, None) def test_volume_show(self): - arglist = [ - self._volume.id - ] - verifylist = [ - ("volume", self._volume.id) - ] + arglist = [self._volume.id] + verifylist = [("volume", self._volume.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) @@ -1323,7 +1359,8 @@ class TestVolumeShow(TestVolume): def test_volume_show_backward_compatibility(self): arglist = [ - '-c', 'display_name', + '-c', + 'display_name', self._volume.id, ] verifylist = [ @@ -1342,7 +1379,6 @@ class TestVolumeShow(TestVolume): class TestVolumeUnset(TestVolume): - _volume = volume_fakes.create_one_volume() def setUp(self): @@ -1369,7 +1405,8 @@ class TestVolumeUnset(TestVolume): def test_volume_unset_property(self): arglist = [ - '--property', 'myprop', + '--property', + 'myprop', self._volume.display_name, ] verifylist = [ @@ -1387,15 +1424,15 @@ class TestVolumeUnset(TestVolume): class TestColumns(TestVolume): - def test_attachments_column_without_server_cache(self): _volume = volume_fakes.create_one_volume() server_id = _volume.attachments[0]['server_id'] device = _volume.attachments[0]['device'] col = volume.AttachmentsColumn(_volume.attachments, {}) - self.assertEqual('Attached to %s on %s ' % (server_id, device), - col.human_readable()) + self.assertEqual( + 'Attached to %s on %s ' % (server_id, device), col.human_readable() + ) self.assertEqual(_volume.attachments, col.machine_readable()) def test_attachments_column_with_server_cache(self): @@ -1410,5 +1447,6 @@ class TestColumns(TestVolume): col = volume.AttachmentsColumn(_volume.attachments, server_cache) self.assertEqual( 'Attached to %s on %s ' % ('fake-server-name', device), - col.human_readable()) + col.human_readable(), + ) self.assertEqual(_volume.attachments, col.machine_readable()) diff --git a/openstackclient/tests/unit/volume/v1/test_volume_backup.py b/openstackclient/tests/unit/volume/v1/test_volume_backup.py index b705b4b9..971aebd8 100644 --- a/openstackclient/tests/unit/volume/v1/test_volume_backup.py +++ b/openstackclient/tests/unit/volume/v1/test_volume_backup.py @@ -23,7 +23,6 @@ from openstackclient.volume.v1 import volume_backup class TestBackup(volume_fakes.TestVolumev1): - def setUp(self): super().setUp() @@ -38,7 +37,6 @@ class TestBackup(volume_fakes.TestVolumev1): class TestBackupCreate(TestBackup): - volume = volume_fakes.create_one_volume() columns = ( @@ -79,9 +77,12 @@ class TestBackupCreate(TestBackup): def test_backup_create(self): arglist = [ - "--name", self.new_backup.name, - "--description", self.new_backup.description, - "--container", self.new_backup.container, + "--name", + self.new_backup.name, + "--description", + self.new_backup.description, + "--container", + self.new_backup.container, self.new_backup.volume_id, ] verifylist = [ @@ -105,8 +106,10 @@ class TestBackupCreate(TestBackup): def test_backup_create_without_name(self): arglist = [ - "--description", self.new_backup.description, - "--container", self.new_backup.container, + "--description", + self.new_backup.description, + "--container", + self.new_backup.container, self.new_backup.volume_id, ] verifylist = [ @@ -129,7 +132,6 @@ class TestBackupCreate(TestBackup): class TestBackupDelete(TestBackup): - backups = volume_fakes.create_backups(count=2) def setUp(self): @@ -142,18 +144,13 @@ class TestBackupDelete(TestBackup): self.cmd = volume_backup.DeleteVolumeBackup(self.app, None) def test_backup_delete(self): - arglist = [ - self.backups[0].id - ] - verifylist = [ - ("backups", [self.backups[0].id]) - ] + arglist = [self.backups[0].id] + verifylist = [("backups", [self.backups[0].id])] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) - self.backups_mock.delete.assert_called_with( - self.backups[0].id) + self.backups_mock.delete.assert_called_with(self.backups[0].id) self.assertIsNone(result) def test_delete_multiple_backups(self): @@ -185,14 +182,14 @@ class TestBackupDelete(TestBackup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) find_mock_result = [self.backups[0], exceptions.CommandError] - with mock.patch.object(utils, 'find_resource', - side_effect=find_mock_result) as find_mock: + with mock.patch.object( + utils, 'find_resource', side_effect=find_mock_result + ) as find_mock: try: self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual('1 of 2 backups failed to delete.', - str(e)) + self.assertEqual('1 of 2 backups failed to delete.', str(e)) find_mock.assert_any_call(self.backups_mock, self.backups[0].id) find_mock.assert_any_call(self.backups_mock, 'unexist_backup') @@ -204,7 +201,6 @@ class TestBackupDelete(TestBackup): class TestBackupList(TestBackup): - volume = volume_fakes.create_one_volume() backups = volume_fakes.create_backups( attrs={'volume_id': volume.display_name}, @@ -226,25 +222,29 @@ class TestBackupList(TestBackup): data = [] for b in backups: - data.append(( - b.id, - b.name, - b.description, - b.status, - b.size, - )) + data.append( + ( + b.id, + b.name, + b.description, + b.status, + b.size, + ) + ) data_long = [] for b in backups: - data_long.append(( - b.id, - b.name, - b.description, - b.status, - b.size, - b.availability_zone, - volume_backup.VolumeIdColumn(b.volume_id), - b.container, - )) + data_long.append( + ( + b.id, + b.name, + b.description, + b.status, + b.size, + b.availability_zone, + volume_backup.VolumeIdColumn(b.volume_id), + b.container, + ) + ) def setUp(self): super().setUp() @@ -284,10 +284,13 @@ class TestBackupList(TestBackup): def test_backup_list_with_options(self): arglist = [ "--long", - "--name", self.backups[0].name, - "--status", "error", - "--volume", self.volume.id, - "--all-projects" + "--name", + self.backups[0].name, + "--status", + "error", + "--volume", + self.volume.id, + "--all-projects", ] verifylist = [ ("long", True), @@ -315,7 +318,6 @@ class TestBackupList(TestBackup): class TestBackupRestore(TestBackup): - volume = volume_fakes.create_one_volume() backup = volume_fakes.create_one_backup( attrs={'volume_id': volume.id}, @@ -345,8 +347,7 @@ class TestBackupRestore(TestBackup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) - self.restores_mock.restore.assert_called_with(self.backup.id, - None) + self.restores_mock.restore.assert_called_with(self.backup.id, None) self.assertIsNotNone(result) def test_backup_restore_with_existing_volume(self): @@ -362,7 +363,8 @@ class TestBackupRestore(TestBackup): result = self.cmd.take_action(parsed_args) self.restores_mock.restore.assert_called_with( - self.backup.id, self.backup.volume_id, + self.backup.id, + self.backup.volume_id, ) self.assertIsNotNone(result) @@ -377,7 +379,8 @@ class TestBackupRestore(TestBackup): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) with mock.patch.object( - utils, 'find_resource', + utils, + 'find_resource', side_effect=exceptions.CommandError(), ): self.assertRaises( @@ -388,7 +391,6 @@ class TestBackupRestore(TestBackup): class TestBackupShow(TestBackup): - columns = ( 'availability_zone', 'container', @@ -422,12 +424,8 @@ class TestBackupShow(TestBackup): self.cmd = volume_backup.ShowVolumeBackup(self.app, None) def test_backup_show(self): - arglist = [ - self.backup.id - ] - verifylist = [ - ("backup", self.backup.id) - ] + arglist = [self.backup.id] + verifylist = [("backup", self.backup.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) diff --git a/openstackclient/tests/unit/volume/v2/fakes.py b/openstackclient/tests/unit/volume/v2/fakes.py index a3ef142f..81e3a8a2 100644 --- a/openstackclient/tests/unit/volume/v2/fakes.py +++ b/openstackclient/tests/unit/volume/v2/fakes.py @@ -1182,12 +1182,12 @@ class FakeLimits(object): @property def absolute(self): - for (name, value) in self.absolute_limits_attrs.items(): + for name, value in self.absolute_limits_attrs.items(): yield FakeAbsoluteLimit(name, value) def absolute_limits(self): reference_data = [] - for (name, value) in self.absolute_limits_attrs.items(): + for name, value in self.absolute_limits_attrs.items(): reference_data.append((name, value)) return reference_data diff --git a/openstackclient/tests/unit/volume/v2/test_backup_record.py b/openstackclient/tests/unit/volume/v2/test_backup_record.py index aa9a25a2..4933af16 100644 --- a/openstackclient/tests/unit/volume/v2/test_backup_record.py +++ b/openstackclient/tests/unit/volume/v2/test_backup_record.py @@ -17,7 +17,6 @@ from openstackclient.volume.v2 import backup_record class TestBackupRecord(volume_fakes.TestVolume): - def setUp(self): super().setUp() @@ -26,7 +25,6 @@ class TestBackupRecord(volume_fakes.TestVolume): class TestBackupRecordExport(TestBackupRecord): - new_backup = volume_fakes.create_one_backup( attrs={'volume_id': 'a54708a2-0388-4476-a909-09579f885c25'}, ) @@ -81,7 +79,6 @@ class TestBackupRecordExport(TestBackupRecord): class TestBackupRecordImport(TestBackupRecord): - new_backup = volume_fakes.create_one_backup( attrs={'volume_id': 'a54708a2-0388-4476-a909-09579f885c25'}, ) @@ -101,8 +98,10 @@ class TestBackupRecordImport(TestBackupRecord): "fake_backup_record_data", ] verifylist = [ - ("backup_service", - "cinder.backup.drivers.swift.SwiftBackupDriver"), + ( + "backup_service", + "cinder.backup.drivers.swift.SwiftBackupDriver", + ), ("backup_metadata", "fake_backup_record_data"), ] diff --git a/openstackclient/tests/unit/volume/v2/test_consistency_group.py b/openstackclient/tests/unit/volume/v2/test_consistency_group.py index c5537ed8..52376204 100644 --- a/openstackclient/tests/unit/volume/v2/test_consistency_group.py +++ b/openstackclient/tests/unit/volume/v2/test_consistency_group.py @@ -24,21 +24,19 @@ from openstackclient.volume.v2 import consistency_group class TestConsistencyGroup(volume_fakes.TestVolume): - def setUp(self): super().setUp() # Get a shortcut to the TransferManager Mock self.consistencygroups_mock = ( - self.app.client_manager.volume.consistencygroups) + self.app.client_manager.volume.consistencygroups + ) self.consistencygroups_mock.reset_mock() - self.cgsnapshots_mock = ( - self.app.client_manager.volume.cgsnapshots) + self.cgsnapshots_mock = self.app.client_manager.volume.cgsnapshots self.cgsnapshots_mock.reset_mock() - self.volumes_mock = ( - self.app.client_manager.volume.volumes) + self.volumes_mock = self.app.client_manager.volume.volumes self.volumes_mock.reset_mock() self.types_mock = self.app.client_manager.volume.volume_types @@ -46,17 +44,16 @@ class TestConsistencyGroup(volume_fakes.TestVolume): class TestConsistencyGroupAddVolume(TestConsistencyGroup): - _consistency_group = volume_fakes.create_one_consistency_group() def setUp(self): super().setUp() - self.consistencygroups_mock.get.return_value = ( - self._consistency_group) + self.consistencygroups_mock.get.return_value = self._consistency_group # Get the command object to test - self.cmd = \ - consistency_group.AddVolumeToConsistencyGroup(self.app, None) + self.cmd = consistency_group.AddVolumeToConsistencyGroup( + self.app, None + ) def test_add_one_volume_to_consistency_group(self): volume = volume_fakes.create_one_volume() @@ -78,8 +75,7 @@ class TestConsistencyGroupAddVolume(TestConsistencyGroup): 'add_volumes': volume.id, } self.consistencygroups_mock.update.assert_called_once_with( - self._consistency_group.id, - **kwargs + self._consistency_group.id, **kwargs ) self.assertIsNone(result) @@ -104,14 +100,14 @@ class TestConsistencyGroupAddVolume(TestConsistencyGroup): 'add_volumes': volumes[0].id + ',' + volumes[1].id, } self.consistencygroups_mock.update.assert_called_once_with( - self._consistency_group.id, - **kwargs + self._consistency_group.id, **kwargs ) self.assertIsNone(result) @mock.patch.object(consistency_group.LOG, 'error') def test_add_multiple_volumes_to_consistency_group_with_exception( - self, mock_error, + self, + mock_error, ): volume = volume_fakes.create_one_volume() arglist = [ @@ -126,20 +122,22 @@ class TestConsistencyGroupAddVolume(TestConsistencyGroup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) - find_mock_result = [volume, - exceptions.CommandError, - self._consistency_group] - with mock.patch.object(utils, 'find_resource', - side_effect=find_mock_result) as find_mock: + find_mock_result = [ + volume, + exceptions.CommandError, + self._consistency_group, + ] + with mock.patch.object( + utils, 'find_resource', side_effect=find_mock_result + ) as find_mock: result = self.cmd.take_action(parsed_args) mock_error.assert_called_with("1 of 2 volumes failed to add.") self.assertIsNone(result) - find_mock.assert_any_call(self.consistencygroups_mock, - self._consistency_group.id) - find_mock.assert_any_call(self.volumes_mock, - volume.id) - find_mock.assert_any_call(self.volumes_mock, - 'unexist_volume') + find_mock.assert_any_call( + self.consistencygroups_mock, self._consistency_group.id + ) + find_mock.assert_any_call(self.volumes_mock, volume.id) + find_mock.assert_any_call(self.volumes_mock, 'unexist_volume') self.assertEqual(3, find_mock.call_count) self.consistencygroups_mock.update.assert_called_once_with( self._consistency_group.id, add_volumes=volume.id @@ -147,7 +145,6 @@ class TestConsistencyGroupAddVolume(TestConsistencyGroup): class TestConsistencyGroupCreate(TestConsistencyGroup): - volume_type = volume_fakes.create_one_volume_type() new_consistency_group = volume_fakes.create_one_consistency_group() consistency_group_snapshot = ( @@ -176,22 +173,28 @@ class TestConsistencyGroupCreate(TestConsistencyGroup): def setUp(self): super().setUp() self.consistencygroups_mock.create.return_value = ( - self.new_consistency_group) + self.new_consistency_group + ) self.consistencygroups_mock.create_from_src.return_value = ( - self.new_consistency_group) + self.new_consistency_group + ) self.consistencygroups_mock.get.return_value = ( - self.new_consistency_group) + self.new_consistency_group + ) self.types_mock.get.return_value = self.volume_type self.cgsnapshots_mock.get.return_value = ( - self.consistency_group_snapshot) + self.consistency_group_snapshot + ) # Get the command object to test self.cmd = consistency_group.CreateConsistencyGroup(self.app, None) def test_consistency_group_create(self): arglist = [ - '--volume-type', self.volume_type.id, - '--description', self.new_consistency_group.description, + '--volume-type', + self.volume_type.id, + '--description', + self.new_consistency_group.description, '--availability-zone', self.new_consistency_group.availability_zone, self.new_consistency_group.name, @@ -199,16 +202,17 @@ class TestConsistencyGroupCreate(TestConsistencyGroup): verifylist = [ ('volume_type', self.volume_type.id), ('description', self.new_consistency_group.description), - ('availability_zone', - self.new_consistency_group.availability_zone), + ( + 'availability_zone', + self.new_consistency_group.availability_zone, + ), ('name', self.new_consistency_group.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.types_mock.get.assert_called_once_with( - self.volume_type.id) + self.types_mock.get.assert_called_once_with(self.volume_type.id) self.consistencygroups_mock.get.assert_not_called() self.consistencygroups_mock.create.assert_called_once_with( self.volume_type.id, @@ -222,23 +226,26 @@ class TestConsistencyGroupCreate(TestConsistencyGroup): def test_consistency_group_create_without_name(self): arglist = [ - '--volume-type', self.volume_type.id, - '--description', self.new_consistency_group.description, + '--volume-type', + self.volume_type.id, + '--description', + self.new_consistency_group.description, '--availability-zone', self.new_consistency_group.availability_zone, ] verifylist = [ ('volume_type', self.volume_type.id), ('description', self.new_consistency_group.description), - ('availability_zone', - self.new_consistency_group.availability_zone), + ( + 'availability_zone', + self.new_consistency_group.availability_zone, + ), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.types_mock.get.assert_called_once_with( - self.volume_type.id) + self.types_mock.get.assert_called_once_with(self.volume_type.id) self.consistencygroups_mock.get.assert_not_called() self.consistencygroups_mock.create.assert_called_once_with( self.volume_type.id, @@ -252,8 +259,10 @@ class TestConsistencyGroupCreate(TestConsistencyGroup): def test_consistency_group_create_from_source(self): arglist = [ - '--consistency-group-source', self.new_consistency_group.id, - '--description', self.new_consistency_group.description, + '--consistency-group-source', + self.new_consistency_group.id, + '--description', + self.new_consistency_group.description, self.new_consistency_group.name, ] verifylist = [ @@ -267,7 +276,8 @@ class TestConsistencyGroupCreate(TestConsistencyGroup): self.types_mock.get.assert_not_called() self.consistencygroups_mock.get.assert_called_once_with( - self.new_consistency_group.id) + self.new_consistency_group.id + ) self.consistencygroups_mock.create_from_src.assert_called_with( None, self.new_consistency_group.id, @@ -280,8 +290,10 @@ class TestConsistencyGroupCreate(TestConsistencyGroup): def test_consistency_group_create_from_snapshot(self): arglist = [ - '--consistency-group-snapshot', self.consistency_group_snapshot.id, - '--description', self.new_consistency_group.description, + '--consistency-group-snapshot', + self.consistency_group_snapshot.id, + '--description', + self.new_consistency_group.description, self.new_consistency_group.name, ] verifylist = [ @@ -295,7 +307,8 @@ class TestConsistencyGroupCreate(TestConsistencyGroup): self.types_mock.get.assert_not_called() self.cgsnapshots_mock.get.assert_called_once_with( - self.consistency_group_snapshot.id) + self.consistency_group_snapshot.id + ) self.consistencygroups_mock.create_from_src.assert_called_with( self.consistency_group_snapshot.id, None, @@ -308,9 +321,7 @@ class TestConsistencyGroupCreate(TestConsistencyGroup): class TestConsistencyGroupDelete(TestConsistencyGroup): - - consistency_groups =\ - volume_fakes.create_consistency_groups(count=2) + consistency_groups = volume_fakes.create_consistency_groups(count=2) def setUp(self): super().setUp() @@ -324,18 +335,15 @@ class TestConsistencyGroupDelete(TestConsistencyGroup): self.cmd = consistency_group.DeleteConsistencyGroup(self.app, None) def test_consistency_group_delete(self): - arglist = [ - self.consistency_groups[0].id - ] - verifylist = [ - ("consistency_groups", [self.consistency_groups[0].id]) - ] + arglist = [self.consistency_groups[0].id] + verifylist = [("consistency_groups", [self.consistency_groups[0].id])] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.consistencygroups_mock.delete.assert_called_with( - self.consistency_groups[0].id, False) + self.consistency_groups[0].id, False + ) self.assertIsNone(result) def test_consistency_group_delete_with_force(self): @@ -345,14 +353,15 @@ class TestConsistencyGroupDelete(TestConsistencyGroup): ] verifylist = [ ('force', True), - ("consistency_groups", [self.consistency_groups[0].id]) + ("consistency_groups", [self.consistency_groups[0].id]), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.consistencygroups_mock.delete.assert_called_with( - self.consistency_groups[0].id, True) + self.consistency_groups[0].id, True + ) self.assertIsNone(result) def test_delete_multiple_consistency_groups(self): @@ -383,21 +392,27 @@ class TestConsistencyGroupDelete(TestConsistencyGroup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) - find_mock_result = [self.consistency_groups[0], - exceptions.CommandError] - with mock.patch.object(utils, 'find_resource', - side_effect=find_mock_result) as find_mock: + find_mock_result = [ + self.consistency_groups[0], + exceptions.CommandError, + ] + with mock.patch.object( + utils, 'find_resource', side_effect=find_mock_result + ) as find_mock: try: self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual('1 of 2 consistency groups failed to delete.', - str(e)) + self.assertEqual( + '1 of 2 consistency groups failed to delete.', str(e) + ) - find_mock.assert_any_call(self.consistencygroups_mock, - self.consistency_groups[0].id) - find_mock.assert_any_call(self.consistencygroups_mock, - 'unexist_consistency_group') + find_mock.assert_any_call( + self.consistencygroups_mock, self.consistency_groups[0].id + ) + find_mock.assert_any_call( + self.consistencygroups_mock, 'unexist_consistency_group' + ) self.assertEqual(2, find_mock.call_count) self.consistencygroups_mock.delete.assert_called_once_with( @@ -406,7 +421,6 @@ class TestConsistencyGroupDelete(TestConsistencyGroup): class TestConsistencyGroupList(TestConsistencyGroup): - consistency_groups = volume_fakes.create_consistency_groups(count=2) columns = [ @@ -424,21 +438,25 @@ class TestConsistencyGroupList(TestConsistencyGroup): ] data = [] for c in consistency_groups: - data.append(( - c.id, - c.status, - c.name, - )) + data.append( + ( + c.id, + c.status, + c.name, + ) + ) data_long = [] for c in consistency_groups: - data_long.append(( - c.id, - c.status, - c.availability_zone, - c.name, - c.description, - format_columns.ListColumn(c.volume_types) - )) + data_long.append( + ( + c.id, + c.status, + c.availability_zone, + c.name, + c.description, + format_columns.ListColumn(c.volume_types), + ) + ) def setUp(self): super().setUp() @@ -458,14 +476,13 @@ class TestConsistencyGroupList(TestConsistencyGroup): columns, data = self.cmd.take_action(parsed_args) self.consistencygroups_mock.list.assert_called_once_with( - detailed=True, search_opts={'all_tenants': False}) + detailed=True, search_opts={'all_tenants': False} + ) self.assertEqual(self.columns, columns) self.assertCountEqual(self.data, list(data)) def test_consistency_group_list_with_all_project(self): - arglist = [ - "--all-projects" - ] + arglist = ["--all-projects"] verifylist = [ ("all_projects", True), ("long", False), @@ -475,7 +492,8 @@ class TestConsistencyGroupList(TestConsistencyGroup): columns, data = self.cmd.take_action(parsed_args) self.consistencygroups_mock.list.assert_called_once_with( - detailed=True, search_opts={'all_tenants': True}) + detailed=True, search_opts={'all_tenants': True} + ) self.assertEqual(self.columns, columns) self.assertCountEqual(self.data, list(data)) @@ -492,23 +510,23 @@ class TestConsistencyGroupList(TestConsistencyGroup): columns, data = self.cmd.take_action(parsed_args) self.consistencygroups_mock.list.assert_called_once_with( - detailed=True, search_opts={'all_tenants': False}) + detailed=True, search_opts={'all_tenants': False} + ) self.assertEqual(self.columns_long, columns) self.assertCountEqual(self.data_long, list(data)) class TestConsistencyGroupRemoveVolume(TestConsistencyGroup): - _consistency_group = volume_fakes.create_one_consistency_group() def setUp(self): super().setUp() - self.consistencygroups_mock.get.return_value = ( - self._consistency_group) + self.consistencygroups_mock.get.return_value = self._consistency_group # Get the command object to test - self.cmd = \ - consistency_group.RemoveVolumeFromConsistencyGroup(self.app, None) + self.cmd = consistency_group.RemoveVolumeFromConsistencyGroup( + self.app, None + ) def test_remove_one_volume_from_consistency_group(self): volume = volume_fakes.create_one_volume() @@ -530,8 +548,7 @@ class TestConsistencyGroupRemoveVolume(TestConsistencyGroup): 'remove_volumes': volume.id, } self.consistencygroups_mock.update.assert_called_once_with( - self._consistency_group.id, - **kwargs + self._consistency_group.id, **kwargs ) self.assertIsNone(result) @@ -556,8 +573,7 @@ class TestConsistencyGroupRemoveVolume(TestConsistencyGroup): 'remove_volumes': volumes[0].id + ',' + volumes[1].id, } self.consistencygroups_mock.update.assert_called_once_with( - self._consistency_group.id, - **kwargs + self._consistency_group.id, **kwargs ) self.assertIsNone(result) @@ -579,20 +595,22 @@ class TestConsistencyGroupRemoveVolume(TestConsistencyGroup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) - find_mock_result = [volume, - exceptions.CommandError, - self._consistency_group] - with mock.patch.object(utils, 'find_resource', - side_effect=find_mock_result) as find_mock: + find_mock_result = [ + volume, + exceptions.CommandError, + self._consistency_group, + ] + with mock.patch.object( + utils, 'find_resource', side_effect=find_mock_result + ) as find_mock: result = self.cmd.take_action(parsed_args) mock_error.assert_called_with("1 of 2 volumes failed to remove.") self.assertIsNone(result) - find_mock.assert_any_call(self.consistencygroups_mock, - self._consistency_group.id) - find_mock.assert_any_call(self.volumes_mock, - volume.id) - find_mock.assert_any_call(self.volumes_mock, - 'unexist_volume') + find_mock.assert_any_call( + self.consistencygroups_mock, self._consistency_group.id + ) + find_mock.assert_any_call(self.volumes_mock, volume.id) + find_mock.assert_any_call(self.volumes_mock, 'unexist_volume') self.assertEqual(3, find_mock.call_count) self.consistencygroups_mock.update.assert_called_once_with( self._consistency_group.id, remove_volumes=volume.id @@ -600,21 +618,20 @@ class TestConsistencyGroupRemoveVolume(TestConsistencyGroup): class TestConsistencyGroupSet(TestConsistencyGroup): - consistency_group = volume_fakes.create_one_consistency_group() def setUp(self): super().setUp() - self.consistencygroups_mock.get.return_value = ( - self.consistency_group) + self.consistencygroups_mock.get.return_value = self.consistency_group # Get the command object to test self.cmd = consistency_group.SetConsistencyGroup(self.app, None) def test_consistency_group_set_name(self): new_name = 'new_name' arglist = [ - '--name', new_name, + '--name', + new_name, self.consistency_group.id, ] verifylist = [ @@ -631,15 +648,15 @@ class TestConsistencyGroupSet(TestConsistencyGroup): 'name': new_name, } self.consistencygroups_mock.update.assert_called_once_with( - self.consistency_group.id, - **kwargs + self.consistency_group.id, **kwargs ) self.assertIsNone(result) def test_consistency_group_set_description(self): new_description = 'new_description' arglist = [ - '--description', new_description, + '--description', + new_description, self.consistency_group.id, ] verifylist = [ @@ -656,8 +673,7 @@ class TestConsistencyGroupSet(TestConsistencyGroup): 'description': new_description, } self.consistencygroups_mock.update.assert_called_once_with( - self.consistency_group.id, - **kwargs + self.consistency_group.id, **kwargs ) self.assertIsNone(result) @@ -690,15 +706,12 @@ class TestConsistencyGroupShow(TestConsistencyGroup): self.cmd = consistency_group.ShowConsistencyGroup(self.app, None) def test_consistency_group_show(self): - arglist = [ - self.consistency_group.id - ] - verifylist = [ - ("consistency_group", self.consistency_group.id) - ] + arglist = [self.consistency_group.id] + verifylist = [("consistency_group", self.consistency_group.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) self.consistencygroups_mock.get.assert_called_once_with( - self.consistency_group.id) + self.consistency_group.id + ) self.assertEqual(self.columns, columns) self.assertCountEqual(self.data, data) diff --git a/openstackclient/tests/unit/volume/v2/test_consistency_group_snapshot.py b/openstackclient/tests/unit/volume/v2/test_consistency_group_snapshot.py index e3c738c8..873f9d0b 100644 --- a/openstackclient/tests/unit/volume/v2/test_consistency_group_snapshot.py +++ b/openstackclient/tests/unit/volume/v2/test_consistency_group_snapshot.py @@ -19,21 +19,19 @@ from openstackclient.volume.v2 import consistency_group_snapshot class TestConsistencyGroupSnapshot(volume_fakes.TestVolume): - def setUp(self): super(TestConsistencyGroupSnapshot, self).setUp() # Get a shortcut to the TransferManager Mock - self.cgsnapshots_mock = ( - self.app.client_manager.volume.cgsnapshots) + self.cgsnapshots_mock = self.app.client_manager.volume.cgsnapshots self.cgsnapshots_mock.reset_mock() self.consistencygroups_mock = ( - self.app.client_manager.volume.consistencygroups) + self.app.client_manager.volume.consistencygroups + ) self.consistencygroups_mock.reset_mock() class TestConsistencyGroupSnapshotCreate(TestConsistencyGroupSnapshot): - _consistency_group_snapshot = ( volume_fakes.create_one_consistency_group_snapshot() ) @@ -59,18 +57,21 @@ class TestConsistencyGroupSnapshotCreate(TestConsistencyGroupSnapshot): def setUp(self): super(TestConsistencyGroupSnapshotCreate, self).setUp() self.cgsnapshots_mock.create.return_value = ( - self._consistency_group_snapshot) - self.consistencygroups_mock.get.return_value = ( - self.consistency_group) + self._consistency_group_snapshot + ) + self.consistencygroups_mock.get.return_value = self.consistency_group # Get the command object to test - self.cmd = (consistency_group_snapshot. - CreateConsistencyGroupSnapshot(self.app, None)) + self.cmd = consistency_group_snapshot.CreateConsistencyGroupSnapshot( + self.app, None + ) def test_consistency_group_snapshot_create(self): arglist = [ - '--consistency-group', self.consistency_group.id, - '--description', self._consistency_group_snapshot.description, + '--consistency-group', + self.consistency_group.id, + '--description', + self._consistency_group_snapshot.description, self._consistency_group_snapshot.name, ] verifylist = [ @@ -83,7 +84,8 @@ class TestConsistencyGroupSnapshotCreate(TestConsistencyGroupSnapshot): columns, data = self.cmd.take_action(parsed_args) self.consistencygroups_mock.get.assert_called_once_with( - self.consistency_group.id) + self.consistency_group.id + ) self.cgsnapshots_mock.create.assert_called_once_with( self.consistency_group.id, name=self._consistency_group_snapshot.name, @@ -95,7 +97,8 @@ class TestConsistencyGroupSnapshotCreate(TestConsistencyGroupSnapshot): def test_consistency_group_snapshot_create_no_consistency_group(self): arglist = [ - '--description', self._consistency_group_snapshot.description, + '--description', + self._consistency_group_snapshot.description, self._consistency_group_snapshot.name, ] verifylist = [ @@ -107,7 +110,8 @@ class TestConsistencyGroupSnapshotCreate(TestConsistencyGroupSnapshot): columns, data = self.cmd.take_action(parsed_args) self.consistencygroups_mock.get.assert_called_once_with( - self._consistency_group_snapshot.name) + self._consistency_group_snapshot.name + ) self.cgsnapshots_mock.create.assert_called_once_with( self.consistency_group.id, name=self._consistency_group_snapshot.name, @@ -119,7 +123,6 @@ class TestConsistencyGroupSnapshotCreate(TestConsistencyGroupSnapshot): class TestConsistencyGroupSnapshotDelete(TestConsistencyGroupSnapshot): - consistency_group_snapshots = ( volume_fakes.create_consistency_group_snapshots(count=2) ) @@ -135,23 +138,25 @@ class TestConsistencyGroupSnapshotDelete(TestConsistencyGroupSnapshot): self.cgsnapshots_mock.delete.return_value = None # Get the command object to mock - self.cmd = (consistency_group_snapshot. - DeleteConsistencyGroupSnapshot(self.app, None)) + self.cmd = consistency_group_snapshot.DeleteConsistencyGroupSnapshot( + self.app, None + ) def test_consistency_group_snapshot_delete(self): - arglist = [ - self.consistency_group_snapshots[0].id - ] + arglist = [self.consistency_group_snapshots[0].id] verifylist = [ - ("consistency_group_snapshot", - [self.consistency_group_snapshots[0].id]) + ( + "consistency_group_snapshot", + [self.consistency_group_snapshots[0].id], + ) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.cgsnapshots_mock.delete.assert_called_once_with( - self.consistency_group_snapshots[0].id) + self.consistency_group_snapshots[0].id + ) self.assertIsNone(result) def test_multiple_consistency_group_snapshots_delete(self): @@ -173,7 +178,6 @@ class TestConsistencyGroupSnapshotDelete(TestConsistencyGroupSnapshot): class TestConsistencyGroupSnapshotList(TestConsistencyGroupSnapshot): - consistency_group_snapshots = ( volume_fakes.create_consistency_group_snapshots(count=2) ) @@ -194,32 +198,36 @@ class TestConsistencyGroupSnapshotList(TestConsistencyGroupSnapshot): ] data = [] for c in consistency_group_snapshots: - data.append(( - c.id, - c.status, - c.name, - )) + data.append( + ( + c.id, + c.status, + c.name, + ) + ) data_long = [] for c in consistency_group_snapshots: - data_long.append(( - c.id, - c.status, - c.consistencygroup_id, - c.name, - c.description, - c.created_at, - )) + data_long.append( + ( + c.id, + c.status, + c.consistencygroup_id, + c.name, + c.description, + c.created_at, + ) + ) def setUp(self): super(TestConsistencyGroupSnapshotList, self).setUp() self.cgsnapshots_mock.list.return_value = ( - self.consistency_group_snapshots) + self.consistency_group_snapshots + ) self.consistencygroups_mock.get.return_value = self.consistency_group # Get the command to test - self.cmd = ( - consistency_group_snapshot. - ListConsistencyGroupSnapshot(self.app, None) + self.cmd = consistency_group_snapshot.ListConsistencyGroupSnapshot( + self.app, None ) def test_consistency_group_snapshot_list_without_options(self): @@ -240,7 +248,8 @@ class TestConsistencyGroupSnapshotList(TestConsistencyGroupSnapshot): 'consistencygroup_id': None, } self.cgsnapshots_mock.list.assert_called_once_with( - detailed=True, search_opts=search_opts) + detailed=True, search_opts=search_opts + ) self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) @@ -264,15 +273,18 @@ class TestConsistencyGroupSnapshotList(TestConsistencyGroupSnapshot): 'consistencygroup_id': None, } self.cgsnapshots_mock.list.assert_called_once_with( - detailed=True, search_opts=search_opts) + detailed=True, search_opts=search_opts + ) self.assertEqual(self.columns_long, columns) self.assertEqual(self.data_long, list(data)) def test_consistency_group_snapshot_list_with_options(self): arglist = [ "--all-project", - "--status", self.consistency_group_snapshots[0].status, - "--consistency-group", self.consistency_group.id, + "--status", + self.consistency_group_snapshots[0].status, + "--consistency-group", + self.consistency_group.id, ] verifylist = [ ("all_projects", True), @@ -290,15 +302,16 @@ class TestConsistencyGroupSnapshotList(TestConsistencyGroupSnapshot): 'consistencygroup_id': self.consistency_group.id, } self.consistencygroups_mock.get.assert_called_once_with( - self.consistency_group.id) + self.consistency_group.id + ) self.cgsnapshots_mock.list.assert_called_once_with( - detailed=True, search_opts=search_opts) + detailed=True, search_opts=search_opts + ) self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) class TestConsistencyGroupSnapshotShow(TestConsistencyGroupSnapshot): - _consistency_group_snapshot = ( volume_fakes.create_one_consistency_group_snapshot() ) @@ -324,20 +337,21 @@ class TestConsistencyGroupSnapshotShow(TestConsistencyGroupSnapshot): super(TestConsistencyGroupSnapshotShow, self).setUp() self.cgsnapshots_mock.get.return_value = ( - self._consistency_group_snapshot) - self.cmd = (consistency_group_snapshot. - ShowConsistencyGroupSnapshot(self.app, None)) + self._consistency_group_snapshot + ) + self.cmd = consistency_group_snapshot.ShowConsistencyGroupSnapshot( + self.app, None + ) def test_consistency_group_snapshot_show(self): - arglist = [ - self._consistency_group_snapshot.id - ] + arglist = [self._consistency_group_snapshot.id] verifylist = [ ("consistency_group_snapshot", self._consistency_group_snapshot.id) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) self.cgsnapshots_mock.get.assert_called_once_with( - self._consistency_group_snapshot.id) + self._consistency_group_snapshot.id + ) self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) diff --git a/openstackclient/tests/unit/volume/v2/test_qos_specs.py b/openstackclient/tests/unit/volume/v2/test_qos_specs.py index 6f258dd5..994bcf96 100644 --- a/openstackclient/tests/unit/volume/v2/test_qos_specs.py +++ b/openstackclient/tests/unit/volume/v2/test_qos_specs.py @@ -26,7 +26,6 @@ from openstackclient.volume.v2 import qos_specs class TestQos(volume_fakes.TestVolume): - def setUp(self): super(TestQos, self).setUp() @@ -38,7 +37,6 @@ class TestQos(volume_fakes.TestVolume): class TestQosAssociate(TestQos): - volume_type = volume_fakes.create_one_volume_type() qos_spec = volume_fakes.create_one_qos() @@ -51,33 +49,23 @@ class TestQosAssociate(TestQos): self.cmd = qos_specs.AssociateQos(self.app, None) def test_qos_associate(self): - arglist = [ - self.qos_spec.id, - self.volume_type.id - ] + arglist = [self.qos_spec.id, self.volume_type.id] verifylist = [ ('qos_spec', self.qos_spec.id), - ('volume_type', self.volume_type.id) + ('volume_type', self.volume_type.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.qos_mock.associate.assert_called_with( - self.qos_spec.id, - self.volume_type.id + self.qos_spec.id, self.volume_type.id ) self.assertIsNone(result) class TestQosCreate(TestQos): - - columns = ( - 'consumer', - 'id', - 'name', - 'properties' - ) + columns = ('consumer', 'id', 'name', 'properties') def setUp(self): super(TestQosCreate, self).setUp() @@ -89,7 +77,7 @@ class TestQosCreate(TestQos): self.new_qos_spec.consumer, self.new_qos_spec.id, self.new_qos_spec.name, - format_columns.DictColumn(self.new_qos_spec.specs) + format_columns.DictColumn(self.new_qos_spec.specs), ) # Get the command object to test @@ -107,8 +95,7 @@ class TestQosCreate(TestQos): columns, data = self.cmd.take_action(parsed_args) self.qos_mock.create.assert_called_with( - self.new_qos_spec.name, - {'consumer': 'both'} + self.new_qos_spec.name, {'consumer': 'both'} ) self.assertEqual(self.columns, columns) @@ -116,7 +103,8 @@ class TestQosCreate(TestQos): def test_qos_create_with_consumer(self): arglist = [ - '--consumer', self.new_qos_spec.consumer, + '--consumer', + self.new_qos_spec.consumer, self.new_qos_spec.name, ] verifylist = [ @@ -128,8 +116,7 @@ class TestQosCreate(TestQos): columns, data = self.cmd.take_action(parsed_args) self.qos_mock.create.assert_called_with( - self.new_qos_spec.name, - {'consumer': self.new_qos_spec.consumer} + self.new_qos_spec.name, {'consumer': self.new_qos_spec.consumer} ) self.assertEqual(self.columns, columns) @@ -137,9 +124,12 @@ class TestQosCreate(TestQos): def test_qos_create_with_properties(self): arglist = [ - '--consumer', self.new_qos_spec.consumer, - '--property', 'foo=bar', - '--property', 'iops=9001', + '--consumer', + self.new_qos_spec.consumer, + '--property', + 'foo=bar', + '--property', + 'iops=9001', self.new_qos_spec.name, ] verifylist = [ @@ -153,9 +143,11 @@ class TestQosCreate(TestQos): self.qos_mock.create.assert_called_with( self.new_qos_spec.name, - {'consumer': self.new_qos_spec.consumer, - 'foo': 'bar', - 'iops': '9001'} + { + 'consumer': self.new_qos_spec.consumer, + 'foo': 'bar', + 'iops': '9001', + }, ) self.assertEqual(self.columns, columns) @@ -163,47 +155,33 @@ class TestQosCreate(TestQos): class TestQosDelete(TestQos): - qos_specs = volume_fakes.create_qoses(count=2) def setUp(self): super(TestQosDelete, self).setUp() - self.qos_mock.get = ( - volume_fakes.get_qoses(self.qos_specs)) + self.qos_mock.get = volume_fakes.get_qoses(self.qos_specs) # Get the command object to test self.cmd = qos_specs.DeleteQos(self.app, None) def test_qos_delete(self): - arglist = [ - self.qos_specs[0].id - ] - verifylist = [ - ('qos_specs', [self.qos_specs[0].id]) - ] + arglist = [self.qos_specs[0].id] + verifylist = [('qos_specs', [self.qos_specs[0].id])] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) - self.qos_mock.delete.assert_called_with( - self.qos_specs[0].id, False) + self.qos_mock.delete.assert_called_with(self.qos_specs[0].id, False) self.assertIsNone(result) def test_qos_delete_with_force(self): - arglist = [ - '--force', - self.qos_specs[0].id - ] - verifylist = [ - ('force', True), - ('qos_specs', [self.qos_specs[0].id]) - ] + arglist = ['--force', self.qos_specs[0].id] + verifylist = [('force', True), ('qos_specs', [self.qos_specs[0].id])] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) - self.qos_mock.delete.assert_called_with( - self.qos_specs[0].id, True) + self.qos_mock.delete.assert_called_with(self.qos_specs[0].id, True) self.assertIsNone(result) def test_delete_multiple_qoses(self): @@ -235,14 +213,16 @@ class TestQosDelete(TestQos): parsed_args = self.check_parser(self.cmd, arglist, verifylist) find_mock_result = [self.qos_specs[0], exceptions.CommandError] - with mock.patch.object(utils, 'find_resource', - side_effect=find_mock_result) as find_mock: + with mock.patch.object( + utils, 'find_resource', side_effect=find_mock_result + ) as find_mock: try: self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: self.assertEqual( - '1 of 2 QoS specifications failed to delete.', str(e)) + '1 of 2 QoS specifications failed to delete.', str(e) + ) find_mock.assert_any_call(self.qos_mock, self.qos_specs[0].id) find_mock.assert_any_call(self.qos_mock, 'unexist_qos') @@ -254,7 +234,6 @@ class TestQosDelete(TestQos): class TestQosDisassociate(TestQos): - volume_type = volume_fakes.create_one_volume_type() qos_spec = volume_fakes.create_one_qos() @@ -268,7 +247,8 @@ class TestQosDisassociate(TestQos): def test_qos_disassociate_with_volume_type(self): arglist = [ - '--volume-type', self.volume_type.id, + '--volume-type', + self.volume_type.id, self.qos_spec.id, ] verifylist = [ @@ -280,8 +260,7 @@ class TestQosDisassociate(TestQos): result = self.cmd.take_action(parsed_args) self.qos_mock.disassociate.assert_called_with( - self.qos_spec.id, - self.volume_type.id + self.qos_spec.id, self.volume_type.id ) self.assertIsNone(result) @@ -290,9 +269,7 @@ class TestQosDisassociate(TestQos): '--all', self.qos_spec.id, ] - verifylist = [ - ('qos_spec', self.qos_spec.id) - ] + verifylist = [('qos_spec', self.qos_spec.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) @@ -302,7 +279,6 @@ class TestQosDisassociate(TestQos): class TestQosList(TestQos): - qos_specs = volume_fakes.create_qoses(count=2) qos_association = volume_fakes.create_one_qos_association() @@ -315,13 +291,15 @@ class TestQosList(TestQos): ) data = [] for q in qos_specs: - data.append(( - q.id, - q.name, - q.consumer, - format_columns.ListColumn([qos_association.name]), - format_columns.DictColumn(q.specs), - )) + data.append( + ( + q.id, + q.name, + q.consumer, + format_columns.ListColumn([qos_association.name]), + format_columns.DictColumn(q.specs), + ) + ) def setUp(self): super(TestQosList, self).setUp() @@ -373,7 +351,6 @@ class TestQosList(TestQos): class TestQosSet(TestQos): - qos_spec = volume_fakes.create_one_qos() def setUp(self): @@ -385,8 +362,10 @@ class TestQosSet(TestQos): def test_qos_set_with_properties_with_id(self): arglist = [ - '--property', 'foo=bar', - '--property', 'iops=9001', + '--property', + 'foo=bar', + '--property', + 'iops=9001', self.qos_spec.id, ] verifylist = [ @@ -398,24 +377,16 @@ class TestQosSet(TestQos): result = self.cmd.take_action(parsed_args) self.qos_mock.set_keys.assert_called_with( - self.qos_spec.id, - self.qos_spec.specs + self.qos_spec.id, self.qos_spec.specs ) self.assertIsNone(result) class TestQosShow(TestQos): - qos_spec = volume_fakes.create_one_qos() qos_association = volume_fakes.create_one_qos_association() - columns = ( - 'associations', - 'consumer', - 'id', - 'name', - 'properties' - ) + columns = ('associations', 'consumer', 'id', 'name', 'properties') data = ( format_columns.ListColumn([qos_association.name]), qos_spec.consumer, @@ -434,26 +405,19 @@ class TestQosShow(TestQos): self.cmd = qos_specs.ShowQos(self.app, None) def test_qos_show(self): - arglist = [ - self.qos_spec.id - ] - verifylist = [ - ('qos_spec', self.qos_spec.id) - ] + arglist = [self.qos_spec.id] + verifylist = [('qos_spec', self.qos_spec.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.qos_mock.get.assert_called_with( - self.qos_spec.id - ) + self.qos_mock.get.assert_called_with(self.qos_spec.id) self.assertEqual(self.columns, columns) self.assertCountEqual(self.data, tuple(data)) class TestQosUnset(TestQos): - qos_spec = volume_fakes.create_one_qos() def setUp(self): @@ -465,8 +429,10 @@ class TestQosUnset(TestQos): def test_qos_unset_with_properties(self): arglist = [ - '--property', 'iops', - '--property', 'foo', + '--property', + 'iops', + '--property', + 'foo', self.qos_spec.id, ] verifylist = [ @@ -478,7 +444,6 @@ class TestQosUnset(TestQos): result = self.cmd.take_action(parsed_args) self.qos_mock.unset_keys.assert_called_with( - self.qos_spec.id, - ['iops', 'foo'] + self.qos_spec.id, ['iops', 'foo'] ) self.assertIsNone(result) diff --git a/openstackclient/tests/unit/volume/v2/test_service.py b/openstackclient/tests/unit/volume/v2/test_service.py index e9e39f41..90fd08ba 100644 --- a/openstackclient/tests/unit/volume/v2/test_service.py +++ b/openstackclient/tests/unit/volume/v2/test_service.py @@ -19,7 +19,6 @@ from openstackclient.volume.v2 import service class TestService(volume_fakes.TestVolume): - def setUp(self): super().setUp() @@ -29,7 +28,6 @@ class TestService(volume_fakes.TestVolume): class TestServiceList(TestService): - # The service to be listed services = volume_fakes.create_one_service() @@ -43,8 +41,10 @@ class TestServiceList(TestService): def test_service_list(self): arglist = [ - '--host', self.services.host, - '--service', self.services.binary, + '--host', + self.services.host, + '--service', + self.services.binary, ] verifylist = [ ('host', self.services.host), @@ -69,14 +69,16 @@ class TestServiceList(TestService): # confirming if all expected columns are present in the result. self.assertEqual(expected_columns, columns) - datalist = (( - self.services.binary, - self.services.host, - self.services.zone, - self.services.status, - self.services.state, - self.services.updated_at, - ), ) + datalist = ( + ( + self.services.binary, + self.services.host, + self.services.zone, + self.services.status, + self.services.state, + self.services.updated_at, + ), + ) # confirming if all expected values are present in the result. self.assertEqual(datalist, tuple(data)) @@ -89,19 +91,20 @@ class TestServiceList(TestService): # checking if prohibited columns are present in output self.assertNotIn("Disabled Reason", columns) - self.assertNotIn(self.services.disabled_reason, - tuple(data)) + self.assertNotIn(self.services.disabled_reason, tuple(data)) def test_service_list_with_long_option(self): arglist = [ - '--host', self.services.host, - '--service', self.services.binary, - '--long' + '--host', + self.services.host, + '--service', + self.services.binary, + '--long', ] verifylist = [ ('host', self.services.host), ('service', self.services.binary), - ('long', True) + ('long', True), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -117,21 +120,23 @@ class TestServiceList(TestService): 'Status', 'State', 'Updated At', - 'Disabled Reason' + 'Disabled Reason', ] # confirming if all expected columns are present in the result. self.assertEqual(expected_columns, columns) - datalist = (( - self.services.binary, - self.services.host, - self.services.zone, - self.services.status, - self.services.state, - self.services.updated_at, - self.services.disabled_reason, - ), ) + datalist = ( + ( + self.services.binary, + self.services.host, + self.services.zone, + self.services.status, + self.services.state, + self.services.updated_at, + self.services.disabled_reason, + ), + ) # confirming if all expected values are present in the result. self.assertEqual(datalist, tuple(data)) @@ -143,7 +148,6 @@ class TestServiceList(TestService): class TestServiceSet(TestService): - service = volume_fakes.create_one_service() def setUp(self): @@ -188,8 +192,7 @@ class TestServiceSet(TestService): result = self.cmd.take_action(parsed_args) self.service_mock.enable.assert_called_with( - self.service.host, - self.service.binary + self.service.host, self.service.binary ) self.service_mock.disable.assert_not_called() self.service_mock.disable_log_reason.assert_not_called() @@ -211,8 +214,7 @@ class TestServiceSet(TestService): result = self.cmd.take_action(parsed_args) self.service_mock.disable.assert_called_with( - self.service.host, - self.service.binary + self.service.host, self.service.binary ) self.service_mock.enable.assert_not_called() self.service_mock.disable_log_reason.assert_not_called() @@ -222,7 +224,8 @@ class TestServiceSet(TestService): reason = 'earthquake' arglist = [ '--disable', - '--disable-reason', reason, + '--disable-reason', + reason, self.service.host, self.service.binary, ] @@ -237,16 +240,15 @@ class TestServiceSet(TestService): result = self.cmd.take_action(parsed_args) self.service_mock.disable_log_reason.assert_called_with( - self.service.host, - self.service.binary, - reason + self.service.host, self.service.binary, reason ) self.assertIsNone(result) def test_service_set_only_with_disable_reason(self): reason = 'earthquake' arglist = [ - '--disable-reason', reason, + '--disable-reason', + reason, self.service.host, self.service.binary, ] @@ -260,14 +262,18 @@ class TestServiceSet(TestService): self.cmd.take_action(parsed_args) self.fail("CommandError should be raised.") except exceptions.CommandError as e: - self.assertEqual("Cannot specify option --disable-reason without " - "--disable specified.", str(e)) + self.assertEqual( + "Cannot specify option --disable-reason without " + "--disable specified.", + str(e), + ) def test_service_set_enable_with_disable_reason(self): reason = 'earthquake' arglist = [ '--enable', - '--disable-reason', reason, + '--disable-reason', + reason, self.service.host, self.service.binary, ] @@ -282,5 +288,8 @@ class TestServiceSet(TestService): self.cmd.take_action(parsed_args) self.fail("CommandError should be raised.") except exceptions.CommandError as e: - self.assertEqual("Cannot specify option --disable-reason without " - "--disable specified.", str(e)) + self.assertEqual( + "Cannot specify option --disable-reason without " + "--disable specified.", + str(e), + ) diff --git a/openstackclient/tests/unit/volume/v2/test_type.py b/openstackclient/tests/unit/volume/v2/test_type.py index 1cb46c45..b387f54c 100644 --- a/openstackclient/tests/unit/volume/v2/test_type.py +++ b/openstackclient/tests/unit/volume/v2/test_type.py @@ -26,7 +26,6 @@ from openstackclient.volume.v2 import volume_type class TestType(volume_fakes.TestVolume): - def setUp(self): super().setUp() @@ -34,11 +33,13 @@ class TestType(volume_fakes.TestVolume): self.types_mock.reset_mock() self.types_access_mock = ( - self.app.client_manager.volume.volume_type_access) + self.app.client_manager.volume.volume_type_access + ) self.types_access_mock.reset_mock() self.encryption_types_mock = ( - self.app.client_manager.volume.volume_encryption_types) + self.app.client_manager.volume.volume_encryption_types + ) self.encryption_types_mock.reset_mock() self.projects_mock = self.app.client_manager.identity.projects @@ -46,7 +47,6 @@ class TestType(volume_fakes.TestVolume): class TestTypeCreate(TestType): - project = identity_fakes.FakeProject.create_one_project() columns = ( 'description', @@ -73,7 +73,8 @@ class TestTypeCreate(TestType): def test_type_create_public(self): arglist = [ - "--description", self.new_volume_type.description, + "--description", + self.new_volume_type.description, "--public", self.new_volume_type.name, ] @@ -97,9 +98,11 @@ class TestTypeCreate(TestType): def test_type_create_private(self): arglist = [ - "--description", self.new_volume_type.description, + "--description", + self.new_volume_type.description, "--private", - "--project", self.project.id, + "--project", + self.project.id, self.new_volume_type.name, ] verifylist = [ @@ -123,7 +126,8 @@ class TestTypeCreate(TestType): def test_public_type_create_with_project(self): arglist = [ - '--project', self.project.id, + '--project', + self.project.id, self.new_volume_type.name, ] verifylist = [ @@ -132,9 +136,9 @@ class TestTypeCreate(TestType): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.assertRaises(exceptions.CommandError, - self.cmd.take_action, - parsed_args) + self.assertRaises( + exceptions.CommandError, self.cmd.take_action, parsed_args + ) def test_type_create_with_encryption(self): encryption_info = { @@ -166,10 +170,14 @@ class TestTypeCreate(TestType): self.new_volume_type.name, ) arglist = [ - '--encryption-provider', 'LuksEncryptor', - '--encryption-cipher', 'aes-xts-plain64', - '--encryption-key-size', '128', - '--encryption-control-location', 'front-end', + '--encryption-provider', + 'LuksEncryptor', + '--encryption-cipher', + 'aes-xts-plain64', + '--encryption-key-size', + '128', + '--encryption-control-location', + 'front-end', self.new_volume_type.name, ] verifylist = [ @@ -201,7 +209,6 @@ class TestTypeCreate(TestType): class TestTypeDelete(TestType): - volume_types = volume_fakes.create_volume_types(count=2) def setUp(self): @@ -216,12 +223,8 @@ class TestTypeDelete(TestType): self.cmd = volume_type.DeleteVolumeType(self.app, None) def test_type_delete(self): - arglist = [ - self.volume_types[0].id - ] - verifylist = [ - ("volume_types", [self.volume_types[0].id]) - ] + arglist = [self.volume_types[0].id] + verifylist = [("volume_types", [self.volume_types[0].id])] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) @@ -258,16 +261,17 @@ class TestTypeDelete(TestType): parsed_args = self.check_parser(self.cmd, arglist, verifylist) find_mock_result = [self.volume_types[0], exceptions.CommandError] - with mock.patch.object(utils, 'find_resource', - side_effect=find_mock_result) as find_mock: + with mock.patch.object( + utils, 'find_resource', side_effect=find_mock_result + ) as find_mock: try: self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual('1 of 2 volume types failed to delete.', - str(e)) - find_mock.assert_any_call( - self.types_mock, self.volume_types[0].id) + self.assertEqual( + '1 of 2 volume types failed to delete.', str(e) + ) + find_mock.assert_any_call(self.types_mock, self.volume_types[0].id) find_mock.assert_any_call(self.types_mock, 'unexist_type') self.assertEqual(2, find_mock.call_count) @@ -277,7 +281,6 @@ class TestTypeDelete(TestType): class TestTypeList(TestType): - volume_types = volume_fakes.create_volume_types() columns = [ @@ -285,31 +288,28 @@ class TestTypeList(TestType): "Name", "Is Public", ] - columns_long = columns + [ - "Description", - "Properties" - ] - data_with_default_type = [( - volume_types[0].id, - volume_types[0].name, - True - )] + columns_long = columns + ["Description", "Properties"] + data_with_default_type = [(volume_types[0].id, volume_types[0].name, True)] data = [] for t in volume_types: - data.append(( - t.id, - t.name, - t.is_public, - )) + data.append( + ( + t.id, + t.name, + t.is_public, + ) + ) data_long = [] for t in volume_types: - data_long.append(( - t.id, - t.name, - t.is_public, - t.description, - format_columns.DictColumn(t.extra_specs), - )) + data_long.append( + ( + t.id, + t.name, + t.is_public, + t.description, + format_columns.DictColumn(t.extra_specs), + ) + ) def setUp(self): super().setUp() @@ -401,21 +401,25 @@ class TestTypeList(TestType): "Encryption", ] encryption_data = [] - encryption_data.append(( - self.volume_types[0].id, - self.volume_types[0].name, - self.volume_types[0].is_public, - volume_type.EncryptionInfoColumn( + encryption_data.append( + ( self.volume_types[0].id, - {self.volume_types[0].id: encryption_info}), - )) - encryption_data.append(( - self.volume_types[1].id, - self.volume_types[1].name, - self.volume_types[1].is_public, - volume_type.EncryptionInfoColumn( - self.volume_types[1].id, {}), - )) + self.volume_types[0].name, + self.volume_types[0].is_public, + volume_type.EncryptionInfoColumn( + self.volume_types[0].id, + {self.volume_types[0].id: encryption_info}, + ), + ) + ) + encryption_data.append( + ( + self.volume_types[1].id, + self.volume_types[1].name, + self.volume_types[1].is_public, + volume_type.EncryptionInfoColumn(self.volume_types[1].id, {}), + ) + ) self.encryption_types_mock.list.return_value = [encryption_type] arglist = [ @@ -434,7 +438,6 @@ class TestTypeList(TestType): class TestTypeSet(TestType): - project = identity_fakes.FakeProject.create_one_project() volume_type = volume_fakes.create_one_volume_type( methods={'set_keys': None}, @@ -455,7 +458,8 @@ class TestTypeSet(TestType): def test_type_set_name(self): new_name = 'new_name' arglist = [ - '--name', new_name, + '--name', + new_name, self.volume_type.id, ] verifylist = [ @@ -473,15 +477,15 @@ class TestTypeSet(TestType): 'name': new_name, } self.types_mock.update.assert_called_with( - self.volume_type.id, - **kwargs + self.volume_type.id, **kwargs ) self.assertIsNone(result) def test_type_set_description(self): new_desc = 'new_desc' arglist = [ - '--description', new_desc, + '--description', + new_desc, self.volume_type.id, ] verifylist = [ @@ -499,14 +503,14 @@ class TestTypeSet(TestType): 'description': new_desc, } self.types_mock.update.assert_called_with( - self.volume_type.id, - **kwargs + self.volume_type.id, **kwargs ) self.assertIsNone(result) def test_type_set_property(self): arglist = [ - '--property', 'myprop=myvalue', + '--property', + 'myprop=myvalue', self.volume_type.id, ] verifylist = [ @@ -519,12 +523,14 @@ class TestTypeSet(TestType): result = self.cmd.take_action(parsed_args) self.volume_type.set_keys.assert_called_once_with( - {'myprop': 'myvalue'}) + {'myprop': 'myvalue'} + ) self.assertIsNone(result) def test_type_set_not_called_without_project_argument(self): arglist = [ - '--project', '', + '--project', + '', self.volume_type.id, ] verifylist = [ @@ -541,21 +547,25 @@ class TestTypeSet(TestType): def test_type_set_failed_with_missing_volume_type_argument(self): arglist = [ - '--project', 'identity_fakes.project_id', + '--project', + 'identity_fakes.project_id', ] verifylist = [ ('project', 'identity_fakes.project_id'), ] - self.assertRaises(tests_utils.ParserException, - self.check_parser, - self.cmd, - arglist, - verifylist) + self.assertRaises( + tests_utils.ParserException, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) def test_type_set_project_access(self): arglist = [ - '--project', self.project.id, + '--project', + self.project.id, self.volume_type.id, ] verifylist = [ @@ -573,13 +583,18 @@ class TestTypeSet(TestType): ) def test_type_set_new_encryption(self): - self.encryption_types_mock.update.side_effect = ( - exceptions.NotFound('NotFound')) + self.encryption_types_mock.update.side_effect = exceptions.NotFound( + 'NotFound' + ) arglist = [ - '--encryption-provider', 'LuksEncryptor', - '--encryption-cipher', 'aes-xts-plain64', - '--encryption-key-size', '128', - '--encryption-control-location', 'front-end', + '--encryption-provider', + 'LuksEncryptor', + '--encryption-cipher', + 'aes-xts-plain64', + '--encryption-key-size', + '128', + '--encryption-control-location', + 'front-end', self.volume_type.id, ] verifylist = [ @@ -610,12 +625,14 @@ class TestTypeSet(TestType): @mock.patch.object(utils, 'find_resource') def test_type_set_existing_encryption(self, mock_find): - mock_find.side_effect = [self.volume_type, - "existing_encryption_type"] + mock_find.side_effect = [self.volume_type, "existing_encryption_type"] arglist = [ - '--encryption-provider', 'LuksEncryptor', - '--encryption-cipher', 'aes-xts-plain64', - '--encryption-control-location', 'front-end', + '--encryption-provider', + 'LuksEncryptor', + '--encryption-cipher', + 'aes-xts-plain64', + '--encryption-control-location', + 'front-end', self.volume_type.id, ] verifylist = [ @@ -640,12 +657,16 @@ class TestTypeSet(TestType): self.assertIsNone(result) def test_type_set_new_encryption_without_provider(self): - self.encryption_types_mock.update.side_effect = ( - exceptions.NotFound('NotFound')) + self.encryption_types_mock.update.side_effect = exceptions.NotFound( + 'NotFound' + ) arglist = [ - '--encryption-cipher', 'aes-xts-plain64', - '--encryption-key-size', '128', - '--encryption-control-location', 'front-end', + '--encryption-cipher', + 'aes-xts-plain64', + '--encryption-key-size', + '128', + '--encryption-control-location', + 'front-end', self.volume_type.id, ] verifylist = [ @@ -659,9 +680,10 @@ class TestTypeSet(TestType): self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual("Command Failed: One or more of" - " the operations failed", - str(e)) + self.assertEqual( + "Command Failed: One or more of" " the operations failed", + str(e), + ) body = { 'cipher': 'aes-xts-plain64', 'key_size': 128, @@ -675,7 +697,6 @@ class TestTypeSet(TestType): class TestTypeShow(TestType): - columns = ( 'access_project_ids', 'description', @@ -695,7 +716,7 @@ class TestTypeShow(TestType): self.volume_type.id, True, self.volume_type.name, - format_columns.DictColumn(self.volume_type.extra_specs) + format_columns.DictColumn(self.volume_type.extra_specs), ) self.types_mock.get.return_value = self.volume_type @@ -704,12 +725,10 @@ class TestTypeShow(TestType): self.cmd = volume_type.ShowVolumeType(self.app, None) def test_type_show(self): - arglist = [ - self.volume_type.id - ] + arglist = [self.volume_type.id] verifylist = [ ("encryption_type", False), - ("volume_type", self.volume_type.id) + ("volume_type", self.volume_type.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -720,12 +739,8 @@ class TestTypeShow(TestType): self.assertCountEqual(self.data, data) def test_type_show_with_access(self): - arglist = [ - self.volume_type.id - ] - verifylist = [ - ("volume_type", self.volume_type.id) - ] + arglist = [self.volume_type.id] + verifylist = [("volume_type", self.volume_type.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) private_type = volume_fakes.create_one_volume_type( @@ -744,9 +759,11 @@ class TestTypeShow(TestType): ): columns, data = self.cmd.take_action(parsed_args) self.types_mock.get.assert_called_once_with( - self.volume_type.id) + self.volume_type.id + ) self.types_access_mock.list.assert_called_once_with( - private_type.id) + private_type.id + ) self.assertEqual(self.columns, columns) private_type_data = ( @@ -755,31 +772,31 @@ class TestTypeShow(TestType): private_type.id, private_type.is_public, private_type.name, - format_columns.DictColumn(private_type.extra_specs) + format_columns.DictColumn(private_type.extra_specs), ) self.assertCountEqual(private_type_data, data) def test_type_show_with_list_access_exec(self): - arglist = [ - self.volume_type.id - ] - verifylist = [ - ("volume_type", self.volume_type.id) - ] + arglist = [self.volume_type.id] + verifylist = [("volume_type", self.volume_type.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) private_type = volume_fakes.create_one_volume_type( attrs={'is_public': False}, ) - with mock.patch.object(self.types_mock, 'get', - return_value=private_type): - with mock.patch.object(self.types_access_mock, 'list', - side_effect=Exception()): + with mock.patch.object( + self.types_mock, 'get', return_value=private_type + ): + with mock.patch.object( + self.types_access_mock, 'list', side_effect=Exception() + ): columns, data = self.cmd.take_action(parsed_args) self.types_mock.get.assert_called_once_with( - self.volume_type.id) + self.volume_type.id + ) self.types_access_mock.list.assert_called_once_with( - private_type.id) + private_type.id + ) self.assertEqual(self.columns, columns) private_type_data = ( @@ -788,7 +805,7 @@ class TestTypeShow(TestType): private_type.id, private_type.is_public, private_type.name, - format_columns.DictColumn(private_type.extra_specs) + format_columns.DictColumn(private_type.extra_specs), ) self.assertCountEqual(private_type_data, data) @@ -821,15 +838,12 @@ class TestTypeShow(TestType): self.volume_type.id, True, self.volume_type.name, - format_columns.DictColumn(self.volume_type.extra_specs) + format_columns.DictColumn(self.volume_type.extra_specs), ) - arglist = [ - '--encryption-type', - self.volume_type.id - ] + arglist = ['--encryption-type', self.volume_type.id] verifylist = [ ('encryption_type', True), - ("volume_type", self.volume_type.id) + ("volume_type", self.volume_type.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -841,7 +855,6 @@ class TestTypeShow(TestType): class TestTypeUnset(TestType): - project = identity_fakes.FakeProject.create_one_project() volume_type = volume_fakes.create_one_volume_type( methods={'unset_keys': None}, @@ -860,8 +873,10 @@ class TestTypeUnset(TestType): def test_type_unset(self): arglist = [ - '--property', 'property', - '--property', 'multi_property', + '--property', + 'property', + '--property', + 'multi_property', self.volume_type.id, ] verifylist = [ @@ -873,12 +888,14 @@ class TestTypeUnset(TestType): result = self.cmd.take_action(parsed_args) self.volume_type.unset_keys.assert_called_once_with( - ['property', 'multi_property']) + ['property', 'multi_property'] + ) self.assertIsNone(result) def test_type_unset_project_access(self): arglist = [ - '--project', self.project.id, + '--project', + self.project.id, self.volume_type.id, ] verifylist = [ @@ -897,7 +914,8 @@ class TestTypeUnset(TestType): def test_type_unset_not_called_without_project_argument(self): arglist = [ - '--project', '', + '--project', + '', self.volume_type.id, ] verifylist = [ @@ -915,17 +933,20 @@ class TestTypeUnset(TestType): def test_type_unset_failed_with_missing_volume_type_argument(self): arglist = [ - '--project', 'identity_fakes.project_id', + '--project', + 'identity_fakes.project_id', ] verifylist = [ ('project', 'identity_fakes.project_id'), ] - self.assertRaises(tests_utils.ParserException, - self.check_parser, - self.cmd, - arglist, - verifylist) + self.assertRaises( + tests_utils.ParserException, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) def test_type_unset_encryption_type(self): arglist = [ @@ -944,7 +965,6 @@ class TestTypeUnset(TestType): class TestColumns(TestType): - def test_encryption_info_column_with_info(self): fake_volume_type = volume_fakes.create_one_volume_type() type_id = fake_volume_type.id @@ -955,10 +975,12 @@ class TestColumns(TestType): 'key_size': None, 'control_location': 'front-end', } - col = volume_type.EncryptionInfoColumn(type_id, - {type_id: encryption_info}) - self.assertEqual(utils.format_dict(encryption_info), - col.human_readable()) + col = volume_type.EncryptionInfoColumn( + type_id, {type_id: encryption_info} + ) + self.assertEqual( + utils.format_dict(encryption_info), col.human_readable() + ) self.assertEqual(encryption_info, col.machine_readable()) def test_encryption_info_column_without_info(self): diff --git a/openstackclient/tests/unit/volume/v2/test_volume.py b/openstackclient/tests/unit/volume/v2/test_volume.py index 0419acef..8a743725 100644 --- a/openstackclient/tests/unit/volume/v2/test_volume.py +++ b/openstackclient/tests/unit/volume/v2/test_volume.py @@ -29,7 +29,6 @@ from openstackclient.volume.v2 import volume class TestVolume(volume_fakes.TestVolume): - def setUp(self): super().setUp() @@ -55,7 +54,8 @@ class TestVolume(volume_fakes.TestVolume): self.types_mock.reset_mock() self.consistencygroups_mock = ( - self.app.client_manager.volume.consistencygroups) + self.app.client_manager.volume.consistencygroups + ) self.consistencygroups_mock.reset_mock() def setup_volumes_mock(self, count): @@ -66,7 +66,6 @@ class TestVolume(volume_fakes.TestVolume): class TestVolumeCreate(TestVolume): - project = identity_fakes.FakeProject.create_one_project() user = identity_fakes.FakeUser.create_one_user() @@ -109,7 +108,8 @@ class TestVolumeCreate(TestVolume): def test_volume_create_min_options(self): arglist = [ - '--size', str(self.new_volume.size), + '--size', + str(self.new_volume.size), ] verifylist = [ ('size', self.new_volume.size), @@ -143,12 +143,18 @@ class TestVolumeCreate(TestVolume): consistency_group = volume_fakes.create_one_consistency_group() self.consistencygroups_mock.get.return_value = consistency_group arglist = [ - '--size', str(self.new_volume.size), - '--description', self.new_volume.description, - '--type', self.new_volume.volume_type, - '--availability-zone', self.new_volume.availability_zone, - '--consistency-group', consistency_group.id, - '--hint', 'k=v', + '--size', + str(self.new_volume.size), + '--description', + self.new_volume.description, + '--type', + self.new_volume.volume_type, + '--availability-zone', + self.new_volume.availability_zone, + '--consistency-group', + consistency_group.id, + '--hint', + 'k=v', self.new_volume.name, ] verifylist = [ @@ -187,9 +193,12 @@ class TestVolumeCreate(TestVolume): def test_volume_create_properties(self): arglist = [ - '--property', 'Alpha=a', - '--property', 'Beta=b', - '--size', str(self.new_volume.size), + '--property', + 'Alpha=a', + '--property', + 'Beta=b', + '--size', + str(self.new_volume.size), self.new_volume.name, ] verifylist = [ @@ -227,8 +236,10 @@ class TestVolumeCreate(TestVolume): self.find_image_mock.return_value = image arglist = [ - '--image', image.id, - '--size', str(self.new_volume.size), + '--image', + image.id, + '--size', + str(self.new_volume.size), self.new_volume.name, ] verifylist = [ @@ -266,8 +277,10 @@ class TestVolumeCreate(TestVolume): self.find_image_mock.return_value = image arglist = [ - '--image', image.name, - '--size', str(self.new_volume.size), + '--image', + image.name, + '--size', + str(self.new_volume.size), self.new_volume.name, ] verifylist = [ @@ -304,7 +317,8 @@ class TestVolumeCreate(TestVolume): snapshot = volume_fakes.create_one_snapshot() self.new_volume.snapshot_id = snapshot.id arglist = [ - '--snapshot', self.new_volume.snapshot_id, + '--snapshot', + self.new_volume.snapshot_id, self.new_volume.name, ] verifylist = [ @@ -342,7 +356,8 @@ class TestVolumeCreate(TestVolume): backup = volume_fakes.create_one_backup() self.new_volume.backup_id = backup.id arglist = [ - '--backup', self.new_volume.backup_id, + '--backup', + self.new_volume.backup_id, self.new_volume.name, ] verifylist = [ @@ -353,8 +368,9 @@ class TestVolumeCreate(TestVolume): self.backups_mock.get.return_value = backup - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.47') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.47' + ) # In base command class ShowOne in cliff, abstract method take_action() # returns a two-part tuple with a tuple of column names and a tuple of @@ -383,7 +399,8 @@ class TestVolumeCreate(TestVolume): backup = volume_fakes.create_one_backup() self.new_volume.backup_id = backup.id arglist = [ - '--backup', self.new_volume.backup_id, + '--backup', + self.new_volume.backup_id, self.new_volume.name, ] verifylist = [ @@ -394,14 +411,16 @@ class TestVolumeCreate(TestVolume): self.backups_mock.get.return_value = backup - exc = self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) + exc = self.assertRaises( + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn("--os-volume-api-version 3.47 or greater", str(exc)) def test_volume_create_with_source_volume(self): source_vol = "source_vol" arglist = [ - '--source', self.new_volume.id, + '--source', + self.new_volume.id, source_vol, ] verifylist = [ @@ -440,7 +459,8 @@ class TestVolumeCreate(TestVolume): arglist = [ '--bootable', '--read-only', - '--size', str(self.new_volume.size), + '--size', + str(self.new_volume.size), self.new_volume.name, ] verifylist = [ @@ -452,8 +472,7 @@ class TestVolumeCreate(TestVolume): ('name', self.new_volume.name), ] - parsed_args = self.check_parser( - self.cmd, arglist, verifylist) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) @@ -475,16 +494,19 @@ class TestVolumeCreate(TestVolume): self.assertEqual(self.columns, columns) self.assertCountEqual(self.datalist, data) self.volumes_mock.set_bootable.assert_called_with( - self.new_volume.id, True) + self.new_volume.id, True + ) self.volumes_mock.update_readonly_flag.assert_called_with( - self.new_volume.id, True) + self.new_volume.id, True + ) @mock.patch.object(utils, 'wait_for_status', return_value=True) def test_volume_create_with_nonbootable_and_readwrite(self, mock_wait): arglist = [ '--non-bootable', '--read-write', - '--size', str(self.new_volume.size), + '--size', + str(self.new_volume.size), self.new_volume.name, ] verifylist = [ @@ -496,8 +518,7 @@ class TestVolumeCreate(TestVolume): ('name', self.new_volume.name), ] - parsed_args = self.check_parser( - self.cmd, arglist, verifylist) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) @@ -519,25 +540,28 @@ class TestVolumeCreate(TestVolume): self.assertEqual(self.columns, columns) self.assertCountEqual(self.datalist, data) self.volumes_mock.set_bootable.assert_called_with( - self.new_volume.id, False) + self.new_volume.id, False + ) self.volumes_mock.update_readonly_flag.assert_called_with( - self.new_volume.id, False) + self.new_volume.id, False + ) @mock.patch.object(volume.LOG, 'error') @mock.patch.object(utils, 'wait_for_status', return_value=True) def test_volume_create_with_bootable_and_readonly_fail( - self, mock_wait, mock_error): - - self.volumes_mock.set_bootable.side_effect = ( - exceptions.CommandError()) + self, mock_wait, mock_error + ): + self.volumes_mock.set_bootable.side_effect = exceptions.CommandError() self.volumes_mock.update_readonly_flag.side_effect = ( - exceptions.CommandError()) + exceptions.CommandError() + ) arglist = [ '--bootable', '--read-only', - '--size', str(self.new_volume.size), + '--size', + str(self.new_volume.size), self.new_volume.name, ] verifylist = [ @@ -549,8 +573,7 @@ class TestVolumeCreate(TestVolume): ('name', self.new_volume.name), ] - parsed_args = self.check_parser( - self.cmd, arglist, verifylist) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) @@ -573,19 +596,24 @@ class TestVolumeCreate(TestVolume): self.assertEqual(self.columns, columns) self.assertCountEqual(self.datalist, data) self.volumes_mock.set_bootable.assert_called_with( - self.new_volume.id, True) + self.new_volume.id, True + ) self.volumes_mock.update_readonly_flag.assert_called_with( - self.new_volume.id, True) + self.new_volume.id, True + ) @mock.patch.object(volume.LOG, 'error') @mock.patch.object(utils, 'wait_for_status', return_value=False) def test_volume_create_non_available_with_readonly( - self, mock_wait, mock_error, + self, + mock_wait, + mock_error, ): arglist = [ '--non-bootable', '--read-only', - '--size', str(self.new_volume.size), + '--size', + str(self.new_volume.size), self.new_volume.name, ] verifylist = [ @@ -597,8 +625,7 @@ class TestVolumeCreate(TestVolume): ('name', self.new_volume.name), ] - parsed_args = self.check_parser( - self.cmd, arglist, verifylist) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) @@ -630,15 +657,20 @@ class TestVolumeCreate(TestVolume): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) + self.assertRaises( + exceptions.CommandError, self.cmd.take_action, parsed_args + ) def test_volume_create_with_multi_source(self): arglist = [ - '--image', 'source_image', - '--source', 'source_volume', - '--snapshot', 'source_snapshot', - '--size', str(self.new_volume.size), + '--image', + 'source_image', + '--source', + 'source_volume', + '--snapshot', + 'source_snapshot', + '--size', + str(self.new_volume.size), self.new_volume.name, ] verifylist = [ @@ -649,12 +681,16 @@ class TestVolumeCreate(TestVolume): ('name', self.new_volume.name), ] - self.assertRaises(tests_utils.ParserException, self.check_parser, - self.cmd, arglist, verifylist) + self.assertRaises( + tests_utils.ParserException, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) class TestVolumeDelete(TestVolume): - def setUp(self): super().setUp() @@ -666,9 +702,7 @@ class TestVolumeDelete(TestVolume): def test_volume_delete_one_volume(self): volumes = self.setup_volumes_mock(count=1) - arglist = [ - volumes[0].id - ] + arglist = [volumes[0].id] verifylist = [ ("force", False), ("purge", False), @@ -679,7 +713,8 @@ class TestVolumeDelete(TestVolume): result = self.cmd.take_action(parsed_args) self.volumes_mock.delete.assert_called_once_with( - volumes[0].id, cascade=False) + volumes[0].id, cascade=False + ) self.assertIsNone(result) def test_volume_delete_multi_volumes(self): @@ -714,21 +749,22 @@ class TestVolumeDelete(TestVolume): parsed_args = self.check_parser(self.cmd, arglist, verifylist) find_mock_result = [volumes[0], exceptions.CommandError] - with mock.patch.object(utils, 'find_resource', - side_effect=find_mock_result) as find_mock: + with mock.patch.object( + utils, 'find_resource', side_effect=find_mock_result + ) as find_mock: try: self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual('1 of 2 volumes failed to delete.', - str(e)) + self.assertEqual('1 of 2 volumes failed to delete.', str(e)) find_mock.assert_any_call(self.volumes_mock, volumes[0].id) find_mock.assert_any_call(self.volumes_mock, 'unexist_volume') self.assertEqual(2, find_mock.call_count) self.volumes_mock.delete.assert_called_once_with( - volumes[0].id, cascade=False) + volumes[0].id, cascade=False + ) def test_volume_delete_with_purge(self): volumes = self.setup_volumes_mock(count=1) @@ -747,7 +783,8 @@ class TestVolumeDelete(TestVolume): result = self.cmd.take_action(parsed_args) self.volumes_mock.delete.assert_called_once_with( - volumes[0].id, cascade=True) + volumes[0].id, cascade=True + ) self.assertIsNone(result) def test_volume_delete_with_force(self): @@ -771,7 +808,6 @@ class TestVolumeDelete(TestVolume): class TestVolumeList(TestVolume): - project = identity_fakes.FakeProject.create_one_project() user = identity_fakes.FakeUser.create_one_user() @@ -825,18 +861,21 @@ class TestVolumeList(TestVolume): self.assertEqual(self.columns, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - volume.AttachmentsColumn(self.mock_volume.attachments), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + volume.AttachmentsColumn(self.mock_volume.attachments), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_project(self): arglist = [ - '--project', self.project.name, + '--project', + self.project.name, ] verifylist = [ ('project', self.project.name), @@ -865,19 +904,23 @@ class TestVolumeList(TestVolume): self.assertEqual(self.columns, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - volume.AttachmentsColumn(self.mock_volume.attachments), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + volume.AttachmentsColumn(self.mock_volume.attachments), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_project_domain(self): arglist = [ - '--project', self.project.name, - '--project-domain', self.project.domain_id, + '--project', + self.project.name, + '--project-domain', + self.project.domain_id, ] verifylist = [ ('project', self.project.name), @@ -907,18 +950,21 @@ class TestVolumeList(TestVolume): self.assertEqual(self.columns, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - volume.AttachmentsColumn(self.mock_volume.attachments), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + volume.AttachmentsColumn(self.mock_volume.attachments), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_user(self): arglist = [ - '--user', self.user.name, + '--user', + self.user.name, ] verifylist = [ ('user', self.user.name), @@ -946,19 +992,23 @@ class TestVolumeList(TestVolume): ) self.assertEqual(self.columns, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - volume.AttachmentsColumn(self.mock_volume.attachments), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + volume.AttachmentsColumn(self.mock_volume.attachments), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_user_domain(self): arglist = [ - '--user', self.user.name, - '--user-domain', self.user.domain_id, + '--user', + self.user.name, + '--user-domain', + self.user.domain_id, ] verifylist = [ ('user', self.user.name), @@ -988,18 +1038,21 @@ class TestVolumeList(TestVolume): self.assertEqual(self.columns, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - volume.AttachmentsColumn(self.mock_volume.attachments), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + volume.AttachmentsColumn(self.mock_volume.attachments), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_name(self): arglist = [ - '--name', self.mock_volume.name, + '--name', + self.mock_volume.name, ] verifylist = [ ('long', False), @@ -1028,18 +1081,21 @@ class TestVolumeList(TestVolume): self.assertEqual(self.columns, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - volume.AttachmentsColumn(self.mock_volume.attachments), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + volume.AttachmentsColumn(self.mock_volume.attachments), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_status(self): arglist = [ - '--status', self.mock_volume.status, + '--status', + self.mock_volume.status, ] verifylist = [ ('long', False), @@ -1068,13 +1124,15 @@ class TestVolumeList(TestVolume): self.assertEqual(self.columns, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - volume.AttachmentsColumn(self.mock_volume.attachments), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + volume.AttachmentsColumn(self.mock_volume.attachments), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_all_projects(self): @@ -1108,13 +1166,15 @@ class TestVolumeList(TestVolume): self.assertEqual(self.columns, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - volume.AttachmentsColumn(self.mock_volume.attachments), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + volume.AttachmentsColumn(self.mock_volume.attachments), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_long(self): @@ -1159,22 +1219,26 @@ class TestVolumeList(TestVolume): ] self.assertEqual(collist, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - self.mock_volume.volume_type, - self.mock_volume.bootable, - volume.AttachmentsColumn(self.mock_volume.attachments), - format_columns.DictColumn(self.mock_volume.metadata), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + self.mock_volume.volume_type, + self.mock_volume.bootable, + volume.AttachmentsColumn(self.mock_volume.attachments), + format_columns.DictColumn(self.mock_volume.metadata), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_with_marker_and_limit(self): arglist = [ - "--marker", self.mock_volume.id, - "--limit", "2", + "--marker", + self.mock_volume.id, + "--limit", + "2", ] verifylist = [ ('long', False), @@ -1190,13 +1254,15 @@ class TestVolumeList(TestVolume): self.assertEqual(self.columns, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - volume.AttachmentsColumn(self.mock_volume.attachments), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + volume.AttachmentsColumn(self.mock_volume.attachments), + ), + ) self.volumes_mock.list.assert_called_once_with( marker=self.mock_volume.id, @@ -1206,23 +1272,31 @@ class TestVolumeList(TestVolume): 'project_id': None, 'user_id': None, 'name': None, - 'all_tenants': False, } + 'all_tenants': False, + }, ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_negative_limit(self): arglist = [ - "--limit", "-2", + "--limit", + "-2", ] verifylist = [ ("limit", -2), ] - self.assertRaises(argparse.ArgumentTypeError, self.check_parser, - self.cmd, arglist, verifylist) + self.assertRaises( + argparse.ArgumentTypeError, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) def test_volume_list_backward_compatibility(self): arglist = [ - '-c', 'Display Name', + '-c', + 'Display Name', ] verifylist = [ ('columns', ['Display Name']), @@ -1258,7 +1332,6 @@ class TestVolumeList(TestVolume): class TestVolumeMigrate(TestVolume): - _volume = volume_fakes.create_one_volume() def setUp(self): @@ -1271,7 +1344,8 @@ class TestVolumeMigrate(TestVolume): def test_volume_migrate(self): arglist = [ - "--host", "host@backend-name#pool", + "--host", + "host@backend-name#pool", self._volume.id, ] verifylist = [ @@ -1285,14 +1359,16 @@ class TestVolumeMigrate(TestVolume): result = self.cmd.take_action(parsed_args) self.volumes_mock.get.assert_called_once_with(self._volume.id) self.volumes_mock.migrate_volume.assert_called_once_with( - self._volume.id, "host@backend-name#pool", False, False) + self._volume.id, "host@backend-name#pool", False, False + ) self.assertIsNone(result) def test_volume_migrate_with_option(self): arglist = [ "--force-host-copy", "--lock-volume", - "--host", "host@backend-name#pool", + "--host", + "host@backend-name#pool", self._volume.id, ] verifylist = [ @@ -1306,7 +1382,8 @@ class TestVolumeMigrate(TestVolume): result = self.cmd.take_action(parsed_args) self.volumes_mock.get.assert_called_once_with(self._volume.id) self.volumes_mock.migrate_volume.assert_called_once_with( - self._volume.id, "host@backend-name#pool", True, True) + self._volume.id, "host@backend-name#pool", True, True + ) self.assertIsNone(result) def test_volume_migrate_without_host(self): @@ -1319,12 +1396,16 @@ class TestVolumeMigrate(TestVolume): ("volume", self._volume.id), ] - self.assertRaises(tests_utils.ParserException, self.check_parser, - self.cmd, arglist, verifylist) + self.assertRaises( + tests_utils.ParserException, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) class TestVolumeSet(TestVolume): - volume_type = volume_fakes.create_one_volume_type() def setUp(self): @@ -1339,33 +1420,38 @@ class TestVolumeSet(TestVolume): def test_volume_set_property(self): arglist = [ - '--property', 'a=b', - '--property', 'c=d', + '--property', + 'a=b', + '--property', + 'c=d', self.new_volume.id, ] verifylist = [ ('property', {'a': 'b', 'c': 'd'}), ('volume', self.new_volume.id), ('bootable', False), - ('non_bootable', False) + ('non_bootable', False), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) self.cmd.take_action(parsed_args) self.volumes_mock.set_metadata.assert_called_with( - self.new_volume.id, parsed_args.property) + self.new_volume.id, parsed_args.property + ) def test_volume_set_image_property(self): arglist = [ - '--image-property', 'Alpha=a', - '--image-property', 'Beta=b', + '--image-property', + 'Alpha=a', + '--image-property', + 'Beta=b', self.new_volume.id, ] verifylist = [ ('image_property', {'Alpha': 'a', 'Beta': 'b'}), ('volume', self.new_volume.id), ('bootable', False), - ('non_bootable', False) + ('non_bootable', False), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -1373,211 +1459,192 @@ class TestVolumeSet(TestVolume): # returns nothing self.cmd.take_action(parsed_args) self.volumes_mock.set_image_metadata.assert_called_with( - self.new_volume.id, parsed_args.image_property) + self.new_volume.id, parsed_args.image_property + ) def test_volume_set_state(self): - arglist = [ - '--state', 'error', - self.new_volume.id - ] + arglist = ['--state', 'error', self.new_volume.id] verifylist = [ ('read_only', False), ('read_write', False), ('state', 'error'), - ('volume', self.new_volume.id) + ('volume', self.new_volume.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.volumes_mock.reset_state.assert_called_with( - self.new_volume.id, 'error') + self.new_volume.id, 'error' + ) self.volumes_mock.update_readonly_flag.assert_not_called() self.assertIsNone(result) def test_volume_set_state_failed(self): self.volumes_mock.reset_state.side_effect = exceptions.CommandError() - arglist = [ - '--state', 'error', - self.new_volume.id - ] - verifylist = [ - ('state', 'error'), - ('volume', self.new_volume.id) - ] + arglist = ['--state', 'error', self.new_volume.id] + verifylist = [('state', 'error'), ('volume', self.new_volume.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) try: self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual('One or more of the set operations failed', - str(e)) + self.assertEqual( + 'One or more of the set operations failed', str(e) + ) self.volumes_mock.reset_state.assert_called_with( - self.new_volume.id, 'error') + self.new_volume.id, 'error' + ) def test_volume_set_attached(self): - arglist = [ - '--attached', - self.new_volume.id - ] + arglist = ['--attached', self.new_volume.id] verifylist = [ ('attached', True), ('detached', False), - ('volume', self.new_volume.id) + ('volume', self.new_volume.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.volumes_mock.reset_state.assert_called_with( - self.new_volume.id, attach_status='attached', state=None) + self.new_volume.id, attach_status='attached', state=None + ) self.assertIsNone(result) def test_volume_set_detached(self): - arglist = [ - '--detached', - self.new_volume.id - ] + arglist = ['--detached', self.new_volume.id] verifylist = [ ('attached', False), ('detached', True), - ('volume', self.new_volume.id) + ('volume', self.new_volume.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.volumes_mock.reset_state.assert_called_with( - self.new_volume.id, attach_status='detached', state=None) + self.new_volume.id, attach_status='detached', state=None + ) self.assertIsNone(result) def test_volume_set_bootable(self): arglist = [ ['--bootable', self.new_volume.id], - ['--non-bootable', self.new_volume.id] + ['--non-bootable', self.new_volume.id], ] verifylist = [ [ ('bootable', True), ('non_bootable', False), - ('volume', self.new_volume.id) + ('volume', self.new_volume.id), ], [ ('bootable', False), ('non_bootable', True), - ('volume', self.new_volume.id) - ] + ('volume', self.new_volume.id), + ], ] for index in range(len(arglist)): parsed_args = self.check_parser( - self.cmd, arglist[index], verifylist[index]) + self.cmd, arglist[index], verifylist[index] + ) self.cmd.take_action(parsed_args) self.volumes_mock.set_bootable.assert_called_with( - self.new_volume.id, verifylist[index][0][1]) + self.new_volume.id, verifylist[index][0][1] + ) def test_volume_set_readonly(self): - arglist = [ - '--read-only', - self.new_volume.id - ] + arglist = ['--read-only', self.new_volume.id] verifylist = [ ('read_only', True), ('read_write', False), - ('volume', self.new_volume.id) + ('volume', self.new_volume.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.volumes_mock.update_readonly_flag.assert_called_once_with( - self.new_volume.id, - True) + self.new_volume.id, True + ) self.assertIsNone(result) def test_volume_set_read_write(self): - arglist = [ - '--read-write', - self.new_volume.id - ] + arglist = ['--read-write', self.new_volume.id] verifylist = [ ('read_only', False), ('read_write', True), - ('volume', self.new_volume.id) + ('volume', self.new_volume.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.volumes_mock.update_readonly_flag.assert_called_once_with( - self.new_volume.id, - False) + self.new_volume.id, False + ) self.assertIsNone(result) def test_volume_set_type(self): - arglist = [ - '--type', self.volume_type.id, - self.new_volume.id - ] + arglist = ['--type', self.volume_type.id, self.new_volume.id] verifylist = [ ('retype_policy', None), ('type', self.volume_type.id), - ('volume', self.new_volume.id) + ('volume', self.new_volume.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.volumes_mock.retype.assert_called_once_with( - self.new_volume.id, - self.volume_type.id, - 'never') + self.new_volume.id, self.volume_type.id, 'never' + ) self.assertIsNone(result) def test_volume_set_type_with_policy(self): arglist = [ - '--retype-policy', 'on-demand', - '--type', self.volume_type.id, - self.new_volume.id + '--retype-policy', + 'on-demand', + '--type', + self.volume_type.id, + self.new_volume.id, ] verifylist = [ ('retype_policy', 'on-demand'), ('type', self.volume_type.id), - ('volume', self.new_volume.id) + ('volume', self.new_volume.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.volumes_mock.retype.assert_called_once_with( - self.new_volume.id, - self.volume_type.id, - 'on-demand') + self.new_volume.id, self.volume_type.id, 'on-demand' + ) self.assertIsNone(result) @mock.patch.object(volume.LOG, 'warning') def test_volume_set_with_only_retype_policy(self, mock_warning): - arglist = [ - '--retype-policy', 'on-demand', - self.new_volume.id - ] + arglist = ['--retype-policy', 'on-demand', self.new_volume.id] verifylist = [ ('retype_policy', 'on-demand'), - ('volume', self.new_volume.id) + ('volume', self.new_volume.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.volumes_mock.retype.assert_not_called() - mock_warning.assert_called_with("'--retype-policy' option will " - "not work without '--type' option") + mock_warning.assert_called_with( + "'--retype-policy' option will " "not work without '--type' option" + ) self.assertIsNone(result) class TestVolumeShow(TestVolume): - def setUp(self): super().setUp() @@ -1587,12 +1654,8 @@ class TestVolumeShow(TestVolume): self.cmd = volume.ShowVolume(self.app, None) def test_volume_show(self): - arglist = [ - self._volume.id - ] - verifylist = [ - ("volume", self._volume.id) - ] + arglist = [self._volume.id] + verifylist = [("volume", self._volume.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) @@ -1609,7 +1672,6 @@ class TestVolumeShow(TestVolume): class TestVolumeUnset(TestVolume): - def setUp(self): super().setUp() @@ -1623,11 +1685,12 @@ class TestVolumeUnset(TestVolume): self.cmd_unset = volume.UnsetVolume(self.app, None) def test_volume_unset_image_property(self): - # Arguments for setting image properties arglist = [ - '--image-property', 'Alpha=a', - '--image-property', 'Beta=b', + '--image-property', + 'Alpha=a', + '--image-property', + 'Beta=b', self.new_volume.id, ] verifylist = [ @@ -1642,30 +1705,35 @@ class TestVolumeUnset(TestVolume): # Arguments for unsetting image properties arglist_unset = [ - '--image-property', 'Alpha', + '--image-property', + 'Alpha', self.new_volume.id, ] verifylist_unset = [ ('image_property', ['Alpha']), ('volume', self.new_volume.id), ] - parsed_args_unset = self.check_parser(self.cmd_unset, - arglist_unset, - verifylist_unset) + parsed_args_unset = self.check_parser( + self.cmd_unset, arglist_unset, verifylist_unset + ) # In base command class ShowOne in cliff, abstract method take_action() # returns nothing self.cmd_unset.take_action(parsed_args_unset) self.volumes_mock.delete_image_metadata.assert_called_with( - self.new_volume.id, parsed_args_unset.image_property) + self.new_volume.id, parsed_args_unset.image_property + ) def test_volume_unset_image_property_fail(self): self.volumes_mock.delete_image_metadata.side_effect = ( - exceptions.CommandError()) + exceptions.CommandError() + ) arglist = [ - '--image-property', 'Alpha', - '--property', 'Beta', + '--image-property', + 'Alpha', + '--property', + 'Beta', self.new_volume.id, ] verifylist = [ @@ -1673,31 +1741,33 @@ class TestVolumeUnset(TestVolume): ('property', ['Beta']), ('volume', self.new_volume.id), ] - parsed_args = self.check_parser( - self.cmd_unset, arglist, verifylist) + parsed_args = self.check_parser(self.cmd_unset, arglist, verifylist) try: self.cmd_unset.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual('One or more of the unset operations failed', - str(e)) + self.assertEqual( + 'One or more of the unset operations failed', str(e) + ) self.volumes_mock.delete_image_metadata.assert_called_with( - self.new_volume.id, parsed_args.image_property) + self.new_volume.id, parsed_args.image_property + ) self.volumes_mock.delete_metadata.assert_called_with( - self.new_volume.id, parsed_args.property) + self.new_volume.id, parsed_args.property + ) class TestColumns(TestVolume): - def test_attachments_column_without_server_cache(self): _volume = volume_fakes.create_one_volume() server_id = _volume.attachments[0]['server_id'] device = _volume.attachments[0]['device'] col = volume.AttachmentsColumn(_volume.attachments, {}) - self.assertEqual('Attached to %s on %s ' % (server_id, device), - col.human_readable()) + self.assertEqual( + 'Attached to %s on %s ' % (server_id, device), col.human_readable() + ) self.assertEqual(_volume.attachments, col.machine_readable()) def test_attachments_column_with_server_cache(self): @@ -1712,5 +1782,6 @@ class TestColumns(TestVolume): col = volume.AttachmentsColumn(_volume.attachments, server_cache) self.assertEqual( 'Attached to %s on %s ' % ('fake-server-name', device), - col.human_readable()) + col.human_readable(), + ) self.assertEqual(_volume.attachments, col.machine_readable()) diff --git a/openstackclient/tests/unit/volume/v2/test_volume_backend.py b/openstackclient/tests/unit/volume/v2/test_volume_backend.py index 6c64f645..5c80d9e6 100644 --- a/openstackclient/tests/unit/volume/v2/test_volume_backend.py +++ b/openstackclient/tests/unit/volume/v2/test_volume_backend.py @@ -105,9 +105,7 @@ class TestListVolumePool(volume_fakes.TestVolume): # confirming if all expected columns are present in the result. self.assertEqual(expected_columns, columns) - datalist = (( - self.pools.name, - ), ) + datalist = ((self.pools.name,),) # confirming if all expected values are present in the result. self.assertEqual(datalist, tuple(data)) @@ -122,12 +120,8 @@ class TestListVolumePool(volume_fakes.TestVolume): self.assertNotIn("storage_protocol", columns) def test_service_list_with_long_option(self): - arglist = [ - '--long' - ] - verifylist = [ - ('long', True) - ] + arglist = ['--long'] + verifylist = [('long', True)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) # In base command class Lister in cliff, abstract method take_action() @@ -149,16 +143,18 @@ class TestListVolumePool(volume_fakes.TestVolume): # confirming if all expected columns are present in the result. self.assertEqual(expected_columns, columns) - datalist = (( - self.pools.name, - self.pools.storage_protocol, - self.pools.thick_provisioning_support, - self.pools.thin_provisioning_support, - self.pools.total_volumes, - self.pools.total_capacity_gb, - self.pools.allocated_capacity_gb, - self.pools.max_over_subscription_ratio, - ), ) + datalist = ( + ( + self.pools.name, + self.pools.storage_protocol, + self.pools.thick_provisioning_support, + self.pools.thin_provisioning_support, + self.pools.total_volumes, + self.pools.total_capacity_gb, + self.pools.allocated_capacity_gb, + self.pools.max_over_subscription_ratio, + ), + ) # confirming if all expected values are present in the result. self.assertEqual(datalist, tuple(data)) diff --git a/openstackclient/tests/unit/volume/v2/test_volume_backup.py b/openstackclient/tests/unit/volume/v2/test_volume_backup.py index 7d00b8bf..82adea1f 100644 --- a/openstackclient/tests/unit/volume/v2/test_volume_backup.py +++ b/openstackclient/tests/unit/volume/v2/test_volume_backup.py @@ -24,7 +24,6 @@ from openstackclient.volume.v2 import volume_backup class TestBackup(volume_fakes.TestVolume): - def setUp(self): super().setUp() @@ -39,11 +38,11 @@ class TestBackup(volume_fakes.TestVolume): class TestBackupCreate(TestBackup): - volume = volume_fakes.create_one_volume() snapshot = volume_fakes.create_one_snapshot() new_backup = volume_fakes.create_one_backup( - attrs={'volume_id': volume.id, 'snapshot_id': snapshot.id}) + attrs={'volume_id': volume.id, 'snapshot_id': snapshot.id} + ) columns = ( 'availability_zone', @@ -82,12 +81,16 @@ class TestBackupCreate(TestBackup): def test_backup_create(self): arglist = [ - "--name", self.new_backup.name, - "--description", self.new_backup.description, - "--container", self.new_backup.container, + "--name", + self.new_backup.name, + "--description", + self.new_backup.description, + "--container", + self.new_backup.container, "--force", "--incremental", - "--snapshot", self.new_backup.snapshot_id, + "--snapshot", + self.new_backup.snapshot_id, self.new_backup.volume_id, ] verifylist = [ @@ -116,12 +119,15 @@ class TestBackupCreate(TestBackup): self.assertEqual(self.data, data) def test_backup_create_with_properties(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.43') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.43' + ) arglist = [ - "--property", "foo=bar", - "--property", "wow=much-cool", + "--property", + "foo=bar", + "--property", + "wow=much-cool", self.new_backup.volume_id, ] verifylist = [ @@ -145,12 +151,15 @@ class TestBackupCreate(TestBackup): self.assertEqual(self.data, data) def test_backup_create_with_properties_pre_v343(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.42') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.42' + ) arglist = [ - "--property", "foo=bar", - "--property", "wow=much-cool", + "--property", + "foo=bar", + "--property", + "wow=much-cool", self.new_backup.volume_id, ] verifylist = [ @@ -160,17 +169,18 @@ class TestBackupCreate(TestBackup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn("--os-volume-api-version 3.43 or greater", str(exc)) def test_backup_create_with_availability_zone(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.51') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.51' + ) arglist = [ - "--availability-zone", "my-az", + "--availability-zone", + "my-az", self.new_backup.volume_id, ] verifylist = [ @@ -194,11 +204,13 @@ class TestBackupCreate(TestBackup): self.assertEqual(self.data, data) def test_backup_create_with_availability_zone_pre_v351(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.50') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.50' + ) arglist = [ - "--availability-zone", "my-az", + "--availability-zone", + "my-az", self.new_backup.volume_id, ] verifylist = [ @@ -208,15 +220,16 @@ class TestBackupCreate(TestBackup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn("--os-volume-api-version 3.51 or greater", str(exc)) def test_backup_create_without_name(self): arglist = [ - "--description", self.new_backup.description, - "--container", self.new_backup.container, + "--description", + self.new_backup.description, + "--container", + self.new_backup.container, self.new_backup.volume_id, ] verifylist = [ @@ -241,32 +254,25 @@ class TestBackupCreate(TestBackup): class TestBackupDelete(TestBackup): - backups = volume_fakes.create_backups(count=2) def setUp(self): super().setUp() - self.backups_mock.get = ( - volume_fakes.get_backups(self.backups)) + self.backups_mock.get = volume_fakes.get_backups(self.backups) self.backups_mock.delete.return_value = None # Get the command object to mock self.cmd = volume_backup.DeleteVolumeBackup(self.app, None) def test_backup_delete(self): - arglist = [ - self.backups[0].id - ] - verifylist = [ - ("backups", [self.backups[0].id]) - ] + arglist = [self.backups[0].id] + verifylist = [("backups", [self.backups[0].id])] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) - self.backups_mock.delete.assert_called_with( - self.backups[0].id, False) + self.backups_mock.delete.assert_called_with(self.backups[0].id, False) self.assertIsNone(result) def test_backup_delete_with_force(self): @@ -274,10 +280,7 @@ class TestBackupDelete(TestBackup): '--force', self.backups[0].id, ] - verifylist = [ - ('force', True), - ("backups", [self.backups[0].id]) - ] + verifylist = [('force', True), ("backups", [self.backups[0].id])] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) @@ -314,14 +317,14 @@ class TestBackupDelete(TestBackup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) find_mock_result = [self.backups[0], exceptions.CommandError] - with mock.patch.object(utils, 'find_resource', - side_effect=find_mock_result) as find_mock: + with mock.patch.object( + utils, 'find_resource', side_effect=find_mock_result + ) as find_mock: try: self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual('1 of 2 backups failed to delete.', - str(e)) + self.assertEqual('1 of 2 backups failed to delete.', str(e)) find_mock.assert_any_call(self.backups_mock, self.backups[0].id) find_mock.assert_any_call(self.backups_mock, 'unexist_backup') @@ -333,10 +336,10 @@ class TestBackupDelete(TestBackup): class TestBackupList(TestBackup): - volume = volume_fakes.create_one_volume() backups = volume_fakes.create_backups( - attrs={'volume_id': volume.name}, count=3) + attrs={'volume_id': volume.name}, count=3 + ) columns = ( 'ID', @@ -353,25 +356,29 @@ class TestBackupList(TestBackup): data = [] for b in backups: - data.append(( - b.id, - b.name, - b.description, - b.status, - b.size, - )) + data.append( + ( + b.id, + b.name, + b.description, + b.status, + b.size, + ) + ) data_long = [] for b in backups: - data_long.append(( - b.id, - b.name, - b.description, - b.status, - b.size, - b.availability_zone, - volume_backup.VolumeIdColumn(b.volume_id), - b.container, - )) + data_long.append( + ( + b.id, + b.name, + b.description, + b.status, + b.size, + b.availability_zone, + volume_backup.VolumeIdColumn(b.volume_id), + b.container, + ) + ) def setUp(self): super().setUp() @@ -417,12 +424,17 @@ class TestBackupList(TestBackup): def test_backup_list_with_options(self): arglist = [ "--long", - "--name", self.backups[0].name, - "--status", "error", - "--volume", self.volume.id, - "--marker", self.backups[0].id, + "--name", + self.backups[0].name, + "--status", + "error", + "--volume", + self.volume.id, + "--marker", + self.backups[0].id, "--all-projects", - "--limit", "3", + "--limit", + "3", ] verifylist = [ ("long", True), @@ -455,7 +467,6 @@ class TestBackupList(TestBackup): class TestBackupRestore(TestBackup): - volume = volume_fakes.create_one_volume() backup = volume_fakes.create_one_backup( attrs={'volume_id': volume.id}, @@ -477,9 +488,7 @@ class TestBackupRestore(TestBackup): def test_backup_restore(self): self.volumes_mock.get.side_effect = exceptions.CommandError() self.volumes_mock.find.side_effect = exceptions.CommandError() - arglist = [ - self.backup.id - ] + arglist = [self.backup.id] verifylist = [ ("backup", self.backup.id), ("volume", None), @@ -488,7 +497,9 @@ class TestBackupRestore(TestBackup): result = self.cmd.take_action(parsed_args) self.restores_mock.restore.assert_called_with( - self.backup.id, None, None, + self.backup.id, + None, + None, ) self.assertIsNotNone(result) @@ -507,7 +518,9 @@ class TestBackupRestore(TestBackup): result = self.cmd.take_action(parsed_args) self.restores_mock.restore.assert_called_with( - self.backup.id, None, self.backup.volume_id, + self.backup.id, + None, + self.backup.volume_id, ) self.assertIsNotNone(result) @@ -526,7 +539,9 @@ class TestBackupRestore(TestBackup): result = self.cmd.take_action(parsed_args) self.restores_mock.restore.assert_called_with( - self.backup.id, self.volume.id, None, + self.backup.id, + self.volume.id, + None, ) self.assertIsNotNone(result) @@ -549,7 +564,6 @@ class TestBackupRestore(TestBackup): class TestBackupSet(TestBackup): - backup = volume_fakes.create_one_backup( attrs={'metadata': {'wow': 'cool'}}, ) @@ -563,11 +577,13 @@ class TestBackupSet(TestBackup): self.cmd = volume_backup.SetVolumeBackup(self.app, None) def test_backup_set_name(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.9') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.9' + ) arglist = [ - '--name', 'new_name', + '--name', + 'new_name', self.backup.id, ] verifylist = [ @@ -580,15 +596,18 @@ class TestBackupSet(TestBackup): # returns nothing result = self.cmd.take_action(parsed_args) self.backups_mock.update.assert_called_once_with( - self.backup.id, **{'name': 'new_name'}) + self.backup.id, **{'name': 'new_name'} + ) self.assertIsNone(result) def test_backup_set_name_pre_v39(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.8') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.8' + ) arglist = [ - '--name', 'new_name', + '--name', + 'new_name', self.backup.id, ] verifylist = [ @@ -598,17 +617,18 @@ class TestBackupSet(TestBackup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn("--os-volume-api-version 3.9 or greater", str(exc)) def test_backup_set_description(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.9') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.9' + ) arglist = [ - '--description', 'new_description', + '--description', + 'new_description', self.backup.id, ] verifylist = [ @@ -621,21 +641,20 @@ class TestBackupSet(TestBackup): result = self.cmd.take_action(parsed_args) # Set expected values - kwargs = { - 'description': 'new_description' - } + kwargs = {'description': 'new_description'} self.backups_mock.update.assert_called_once_with( - self.backup.id, - **kwargs + self.backup.id, **kwargs ) self.assertIsNone(result) def test_backup_set_description_pre_v39(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.8') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.8' + ) arglist = [ - '--description', 'new_description', + '--description', + 'new_description', self.backup.id, ] verifylist = [ @@ -646,52 +665,43 @@ class TestBackupSet(TestBackup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn("--os-volume-api-version 3.9 or greater", str(exc)) def test_backup_set_state(self): - arglist = [ - '--state', 'error', - self.backup.id - ] - verifylist = [ - ('state', 'error'), - ('backup', self.backup.id) - ] + arglist = ['--state', 'error', self.backup.id] + verifylist = [('state', 'error'), ('backup', self.backup.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.backups_mock.reset_state.assert_called_once_with( - self.backup.id, 'error') + self.backup.id, 'error' + ) self.assertIsNone(result) def test_backup_set_state_failed(self): self.backups_mock.reset_state.side_effect = exceptions.CommandError() - arglist = [ - '--state', 'error', - self.backup.id - ] - verifylist = [ - ('state', 'error'), - ('backup', self.backup.id) - ] + arglist = ['--state', 'error', self.backup.id] + verifylist = [('state', 'error'), ('backup', self.backup.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) try: self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual('One or more of the set operations failed', - str(e)) + self.assertEqual( + 'One or more of the set operations failed', str(e) + ) self.backups_mock.reset_state.assert_called_with( - self.backup.id, 'error') + self.backup.id, 'error' + ) def test_backup_set_no_property(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.43') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.43' + ) arglist = [ '--no-property', @@ -710,14 +720,14 @@ class TestBackupSet(TestBackup): 'metadata': {}, } self.backups_mock.update.assert_called_once_with( - self.backup.id, - **kwargs + self.backup.id, **kwargs ) self.assertIsNone(result) def test_backup_set_no_property_pre_v343(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.42') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.42' + ) arglist = [ '--no-property', @@ -730,17 +740,18 @@ class TestBackupSet(TestBackup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn("--os-volume-api-version 3.43 or greater", str(exc)) def test_backup_set_property(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.43') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.43' + ) arglist = [ - '--property', 'foo=bar', + '--property', + 'foo=bar', self.backup.id, ] verifylist = [ @@ -756,17 +767,18 @@ class TestBackupSet(TestBackup): 'metadata': {'wow': 'cool', 'foo': 'bar'}, } self.backups_mock.update.assert_called_once_with( - self.backup.id, - **kwargs + self.backup.id, **kwargs ) self.assertIsNone(result) def test_backup_set_property_pre_v343(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.42') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.42' + ) arglist = [ - '--property', 'foo=bar', + '--property', + 'foo=bar', self.backup.id, ] verifylist = [ @@ -776,14 +788,12 @@ class TestBackupSet(TestBackup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn("--os-volume-api-version 3.43 or greater", str(exc)) class TestBackupUnset(TestBackup): - backup = volume_fakes.create_one_backup( attrs={'metadata': {'foo': 'bar'}}, ) @@ -797,11 +807,13 @@ class TestBackupUnset(TestBackup): self.cmd = volume_backup.UnsetVolumeBackup(self.app, None) def test_backup_unset_property(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.43') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.43' + ) arglist = [ - '--property', 'foo', + '--property', + 'foo', self.backup.id, ] verifylist = [ @@ -817,17 +829,18 @@ class TestBackupUnset(TestBackup): 'metadata': {}, } self.backups_mock.update.assert_called_once_with( - self.backup.id, - **kwargs + self.backup.id, **kwargs ) self.assertIsNone(result) def test_backup_unset_property_pre_v343(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.42') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.42' + ) arglist = [ - '--property', 'foo', + '--property', + 'foo', self.backup.id, ] verifylist = [ @@ -837,14 +850,12 @@ class TestBackupUnset(TestBackup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn("--os-volume-api-version 3.43 or greater", str(exc)) class TestBackupShow(TestBackup): - backup = volume_fakes.create_one_backup() columns = ( @@ -880,12 +891,8 @@ class TestBackupShow(TestBackup): self.cmd = volume_backup.ShowVolumeBackup(self.app, None) def test_backup_show(self): - arglist = [ - self.backup.id - ] - verifylist = [ - ("backup", self.backup.id) - ] + arglist = [self.backup.id] + verifylist = [("backup", self.backup.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) diff --git a/openstackclient/tests/unit/volume/v2/test_volume_host.py b/openstackclient/tests/unit/volume/v2/test_volume_host.py index 730085a3..7d976c91 100644 --- a/openstackclient/tests/unit/volume/v2/test_volume_host.py +++ b/openstackclient/tests/unit/volume/v2/test_volume_host.py @@ -17,7 +17,6 @@ from openstackclient.volume.v2 import volume_host class TestVolumeHost(volume_fakes.TestVolume): - def setUp(self): super().setUp() @@ -26,7 +25,6 @@ class TestVolumeHost(volume_fakes.TestVolume): class TestVolumeHostSet(TestVolumeHost): - service = volume_fakes.create_one_service() def setUp(self): @@ -88,7 +86,6 @@ class TestVolumeHostSet(TestVolumeHost): class TestVolumeHostFailover(TestVolumeHost): - service = volume_fakes.create_one_service() def setUp(self): @@ -101,7 +98,8 @@ class TestVolumeHostFailover(TestVolumeHost): def test_volume_host_failover(self): arglist = [ - '--volume-backend', 'backend_test', + '--volume-backend', + 'backend_test', self.service.host, ] verifylist = [ @@ -113,5 +111,6 @@ class TestVolumeHostFailover(TestVolumeHost): result = self.cmd.take_action(parsed_args) self.host_mock.failover_host.assert_called_with( - self.service.host, 'backend_test') + self.service.host, 'backend_test' + ) self.assertIsNone(result) diff --git a/openstackclient/tests/unit/volume/v2/test_volume_snapshot.py b/openstackclient/tests/unit/volume/v2/test_volume_snapshot.py index 6cffcaac..f8120a15 100644 --- a/openstackclient/tests/unit/volume/v2/test_volume_snapshot.py +++ b/openstackclient/tests/unit/volume/v2/test_volume_snapshot.py @@ -26,7 +26,6 @@ from openstackclient.volume.v2 import volume_snapshot class TestVolumeSnapshot(volume_fakes.TestVolume): - def setUp(self): super().setUp() @@ -39,7 +38,6 @@ class TestVolumeSnapshot(volume_fakes.TestVolume): class TestVolumeSnapshotCreate(TestVolumeSnapshot): - columns = ( 'created_at', 'description', @@ -56,7 +54,8 @@ class TestVolumeSnapshotCreate(TestVolumeSnapshot): self.volume = volume_fakes.create_one_volume() self.new_snapshot = volume_fakes.create_one_snapshot( - attrs={'volume_id': self.volume.id}) + attrs={'volume_id': self.volume.id} + ) self.data = ( self.new_snapshot.created_at, @@ -77,11 +76,15 @@ class TestVolumeSnapshotCreate(TestVolumeSnapshot): def test_snapshot_create(self): arglist = [ - "--volume", self.new_snapshot.volume_id, - "--description", self.new_snapshot.description, + "--volume", + self.new_snapshot.volume_id, + "--description", + self.new_snapshot.description, "--force", - '--property', 'Alpha=a', - '--property', 'Beta=b', + '--property', + 'Alpha=a', + '--property', + 'Beta=b', self.new_snapshot.name, ] verifylist = [ @@ -107,7 +110,8 @@ class TestVolumeSnapshotCreate(TestVolumeSnapshot): def test_snapshot_create_without_name(self): arglist = [ - "--volume", self.new_snapshot.volume_id, + "--volume", + self.new_snapshot.volume_id, ] verifylist = [ ("volume", self.new_snapshot.volume_id), @@ -122,21 +126,21 @@ class TestVolumeSnapshotCreate(TestVolumeSnapshot): def test_snapshot_create_without_volume(self): arglist = [ - "--description", self.new_snapshot.description, + "--description", + self.new_snapshot.description, "--force", - self.new_snapshot.name + self.new_snapshot.name, ] verifylist = [ ("description", self.new_snapshot.description), ("force", True), - ("snapshot_name", self.new_snapshot.name) + ("snapshot_name", self.new_snapshot.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.volumes_mock.get.assert_called_once_with( - self.new_snapshot.name) + self.volumes_mock.get.assert_called_once_with(self.new_snapshot.name) self.snapshots_mock.create.assert_called_once_with( self.new_snapshot.volume_id, force=True, @@ -149,13 +153,18 @@ class TestVolumeSnapshotCreate(TestVolumeSnapshot): def test_snapshot_create_with_remote_source(self): arglist = [ - '--remote-source', 'source-name=test_source_name', - '--remote-source', 'source-id=test_source_id', - '--volume', self.new_snapshot.volume_id, + '--remote-source', + 'source-name=test_source_name', + '--remote-source', + 'source-id=test_source_id', + '--volume', + self.new_snapshot.volume_id, self.new_snapshot.name, ] - ref_dict = {'source-name': 'test_source_name', - 'source-id': 'test_source_id'} + ref_dict = { + 'source-name': 'test_source_name', + 'source-id': 'test_source_id', + } verifylist = [ ('remote_source', ref_dict), ('volume', self.new_snapshot.volume_id), @@ -178,49 +187,39 @@ class TestVolumeSnapshotCreate(TestVolumeSnapshot): class TestVolumeSnapshotDelete(TestVolumeSnapshot): - snapshots = volume_fakes.create_snapshots(count=2) def setUp(self): super().setUp() - self.snapshots_mock.get = ( - volume_fakes.get_snapshots(self.snapshots)) + self.snapshots_mock.get = volume_fakes.get_snapshots(self.snapshots) self.snapshots_mock.delete.return_value = None # Get the command object to mock self.cmd = volume_snapshot.DeleteVolumeSnapshot(self.app, None) def test_snapshot_delete(self): - arglist = [ - self.snapshots[0].id - ] - verifylist = [ - ("snapshots", [self.snapshots[0].id]) - ] + arglist = [self.snapshots[0].id] + verifylist = [("snapshots", [self.snapshots[0].id])] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.snapshots_mock.delete.assert_called_with( - self.snapshots[0].id, False) + self.snapshots[0].id, False + ) self.assertIsNone(result) def test_snapshot_delete_with_force(self): - arglist = [ - '--force', - self.snapshots[0].id - ] - verifylist = [ - ('force', True), - ("snapshots", [self.snapshots[0].id]) - ] + arglist = ['--force', self.snapshots[0].id] + verifylist = [('force', True), ("snapshots", [self.snapshots[0].id])] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.snapshots_mock.delete.assert_called_with( - self.snapshots[0].id, True) + self.snapshots[0].id, True + ) self.assertIsNone(result) def test_delete_multiple_snapshots(self): @@ -252,17 +251,18 @@ class TestVolumeSnapshotDelete(TestVolumeSnapshot): parsed_args = self.check_parser(self.cmd, arglist, verifylist) find_mock_result = [self.snapshots[0], exceptions.CommandError] - with mock.patch.object(utils, 'find_resource', - side_effect=find_mock_result) as find_mock: + with mock.patch.object( + utils, 'find_resource', side_effect=find_mock_result + ) as find_mock: try: self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual('1 of 2 snapshots failed to delete.', - str(e)) + self.assertEqual('1 of 2 snapshots failed to delete.', str(e)) find_mock.assert_any_call( - self.snapshots_mock, self.snapshots[0].id) + self.snapshots_mock, self.snapshots[0].id + ) find_mock.assert_any_call(self.snapshots_mock, 'unexist_snapshot') self.assertEqual(2, find_mock.call_count) @@ -272,47 +272,42 @@ class TestVolumeSnapshotDelete(TestVolumeSnapshot): class TestVolumeSnapshotList(TestVolumeSnapshot): - volume = volume_fakes.create_one_volume() project = project_fakes.FakeProject.create_one_project() snapshots = volume_fakes.create_snapshots( - attrs={'volume_id': volume.name}, count=3) - - columns = [ - "ID", - "Name", - "Description", - "Status", - "Size" - ] - columns_long = columns + [ - "Created At", - "Volume", - "Properties" - ] + attrs={'volume_id': volume.name}, count=3 + ) + + columns = ["ID", "Name", "Description", "Status", "Size"] + columns_long = columns + ["Created At", "Volume", "Properties"] data = [] for s in snapshots: - data.append(( - s.id, - s.name, - s.description, - s.status, - s.size, - )) + data.append( + ( + s.id, + s.name, + s.description, + s.status, + s.size, + ) + ) data_long = [] for s in snapshots: - data_long.append(( - s.id, - s.name, - s.description, - s.status, - s.size, - s.created_at, - volume_snapshot.VolumeIdColumn( - s.volume_id, volume_cache={volume.id: volume}), - format_columns.DictColumn(s.metadata), - )) + data_long.append( + ( + s.id, + s.name, + s.description, + s.status, + s.size, + s.created_at, + volume_snapshot.VolumeIdColumn( + s.volume_id, volume_cache={volume.id: volume} + ), + format_columns.DictColumn(s.metadata), + ) + ) def setUp(self): super().setUp() @@ -326,23 +321,21 @@ class TestVolumeSnapshotList(TestVolumeSnapshot): def test_snapshot_list_without_options(self): arglist = [] - verifylist = [ - ('all_projects', False), - ('long', False) - ] + verifylist = [('all_projects', False), ('long', False)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) self.snapshots_mock.list.assert_called_once_with( - limit=None, marker=None, + limit=None, + marker=None, search_opts={ 'all_tenants': False, 'name': None, 'status': None, 'project_id': None, - 'volume_id': None - } + 'volume_id': None, + }, ) self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) @@ -350,9 +343,12 @@ class TestVolumeSnapshotList(TestVolumeSnapshot): def test_snapshot_list_with_options(self): arglist = [ "--long", - "--limit", "2", - "--project", self.project.id, - "--marker", self.snapshots[0].id, + "--limit", + "2", + "--project", + self.project.id, + "--marker", + self.snapshots[0].id, ] verifylist = [ ("long", True), @@ -373,8 +369,8 @@ class TestVolumeSnapshotList(TestVolumeSnapshot): 'project_id': self.project.id, 'name': None, 'status': None, - 'volume_id': None - } + 'volume_id': None, + }, ) self.assertEqual(self.columns_long, columns) self.assertEqual(self.data_long, list(data)) @@ -383,30 +379,29 @@ class TestVolumeSnapshotList(TestVolumeSnapshot): arglist = [ '--all-projects', ] - verifylist = [ - ('long', False), - ('all_projects', True) - ] + verifylist = [('long', False), ('all_projects', True)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) self.snapshots_mock.list.assert_called_once_with( - limit=None, marker=None, + limit=None, + marker=None, search_opts={ 'all_tenants': True, 'name': None, 'status': None, 'project_id': None, - 'volume_id': None - } + 'volume_id': None, + }, ) self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) def test_snapshot_list_name_option(self): arglist = [ - '--name', self.snapshots[0].name, + '--name', + self.snapshots[0].name, ] verifylist = [ ('all_projects', False), @@ -418,21 +413,23 @@ class TestVolumeSnapshotList(TestVolumeSnapshot): columns, data = self.cmd.take_action(parsed_args) self.snapshots_mock.list.assert_called_once_with( - limit=None, marker=None, + limit=None, + marker=None, search_opts={ 'all_tenants': False, 'name': self.snapshots[0].name, 'status': None, 'project_id': None, - 'volume_id': None - } + 'volume_id': None, + }, ) self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) def test_snapshot_list_status_option(self): arglist = [ - '--status', self.snapshots[0].status, + '--status', + self.snapshots[0].status, ] verifylist = [ ('all_projects', False), @@ -444,21 +441,23 @@ class TestVolumeSnapshotList(TestVolumeSnapshot): columns, data = self.cmd.take_action(parsed_args) self.snapshots_mock.list.assert_called_once_with( - limit=None, marker=None, + limit=None, + marker=None, search_opts={ 'all_tenants': False, 'name': None, 'status': self.snapshots[0].status, 'project_id': None, - 'volume_id': None - } + 'volume_id': None, + }, ) self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) def test_snapshot_list_volumeid_option(self): arglist = [ - '--volume', self.volume.id, + '--volume', + self.volume.id, ] verifylist = [ ('all_projects', False), @@ -470,31 +469,37 @@ class TestVolumeSnapshotList(TestVolumeSnapshot): columns, data = self.cmd.take_action(parsed_args) self.snapshots_mock.list.assert_called_once_with( - limit=None, marker=None, + limit=None, + marker=None, search_opts={ 'all_tenants': False, 'name': None, 'status': None, 'project_id': None, - 'volume_id': self.volume.id - } + 'volume_id': self.volume.id, + }, ) self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) def test_snapshot_list_negative_limit(self): arglist = [ - "--limit", "-2", + "--limit", + "-2", ] verifylist = [ ("limit", -2), ] - self.assertRaises(argparse.ArgumentTypeError, self.check_parser, - self.cmd, arglist, verifylist) + self.assertRaises( + argparse.ArgumentTypeError, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) class TestVolumeSnapshotSet(TestVolumeSnapshot): - snapshot = volume_fakes.create_one_snapshot() def setUp(self): @@ -524,9 +529,12 @@ class TestVolumeSnapshotSet(TestVolumeSnapshot): def test_snapshot_set_name_and_property(self): arglist = [ - "--name", "new_snapshot", - "--property", "x=y", - "--property", "foo=foo", + "--name", + "new_snapshot", + "--property", + "x=y", + "--property", + "foo=foo", self.snapshot.id, ] new_property = {"x": "y", "foo": "foo"} @@ -543,7 +551,8 @@ class TestVolumeSnapshotSet(TestVolumeSnapshot): "name": "new_snapshot", } self.snapshots_mock.update.assert_called_with( - self.snapshot.id, **kwargs) + self.snapshot.id, **kwargs + ) self.snapshots_mock.set_metadata.assert_called_with( self.snapshot.id, new_property ) @@ -573,7 +582,8 @@ class TestVolumeSnapshotSet(TestVolumeSnapshot): def test_snapshot_set_with_no_property_and_property(self): arglist = [ "--no-property", - "--property", "foo_1=bar_1", + "--property", + "foo_1=bar_1", self.snapshot.id, ] verifylist = [ @@ -591,58 +601,52 @@ class TestVolumeSnapshotSet(TestVolumeSnapshot): self.snapshot.id, ["foo"] ) self.snapshots_mock.set_metadata.assert_called_once_with( - self.snapshot.id, {"foo_1": "bar_1"}) + self.snapshot.id, {"foo_1": "bar_1"} + ) self.assertIsNone(result) def test_snapshot_set_state_to_error(self): - arglist = [ - "--state", "error", - self.snapshot.id - ] - verifylist = [ - ("state", "error"), - ("snapshot", self.snapshot.id) - ] + arglist = ["--state", "error", self.snapshot.id] + verifylist = [("state", "error"), ("snapshot", self.snapshot.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.snapshots_mock.reset_state.assert_called_with( - self.snapshot.id, "error") + self.snapshot.id, "error" + ) self.assertIsNone(result) def test_volume_set_state_failed(self): self.snapshots_mock.reset_state.side_effect = exceptions.CommandError() - arglist = [ - '--state', 'error', - self.snapshot.id - ] - verifylist = [ - ('state', 'error'), - ('snapshot', self.snapshot.id) - ] + arglist = ['--state', 'error', self.snapshot.id] + verifylist = [('state', 'error'), ('snapshot', self.snapshot.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) try: self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual('One or more of the set operations failed', - str(e)) + self.assertEqual( + 'One or more of the set operations failed', str(e) + ) self.snapshots_mock.reset_state.assert_called_once_with( - self.snapshot.id, 'error') + self.snapshot.id, 'error' + ) def test_volume_set_name_and_state_failed(self): self.snapshots_mock.reset_state.side_effect = exceptions.CommandError() arglist = [ - '--state', 'error', - "--name", "new_snapshot", - self.snapshot.id + '--state', + 'error', + "--name", + "new_snapshot", + self.snapshot.id, ] verifylist = [ ('state', 'error'), ("name", "new_snapshot"), - ('snapshot', self.snapshot.id) + ('snapshot', self.snapshot.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -650,19 +654,21 @@ class TestVolumeSnapshotSet(TestVolumeSnapshot): self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual('One or more of the set operations failed', - str(e)) + self.assertEqual( + 'One or more of the set operations failed', str(e) + ) kwargs = { "name": "new_snapshot", } self.snapshots_mock.update.assert_called_once_with( - self.snapshot.id, **kwargs) + self.snapshot.id, **kwargs + ) self.snapshots_mock.reset_state.assert_called_once_with( - self.snapshot.id, 'error') + self.snapshot.id, 'error' + ) class TestVolumeSnapshotShow(TestVolumeSnapshot): - columns = ( 'created_at', 'description', @@ -695,12 +701,8 @@ class TestVolumeSnapshotShow(TestVolumeSnapshot): self.cmd = volume_snapshot.ShowVolumeSnapshot(self.app, None) def test_snapshot_show(self): - arglist = [ - self.snapshot.id - ] - verifylist = [ - ("snapshot", self.snapshot.id) - ] + arglist = [self.snapshot.id] + verifylist = [("snapshot", self.snapshot.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) @@ -711,7 +713,6 @@ class TestVolumeSnapshotShow(TestVolumeSnapshot): class TestVolumeSnapshotUnset(TestVolumeSnapshot): - snapshot = volume_fakes.create_one_snapshot() def setUp(self): @@ -724,7 +725,8 @@ class TestVolumeSnapshotUnset(TestVolumeSnapshot): def test_snapshot_unset(self): arglist = [ - "--property", "foo", + "--property", + "foo", self.snapshot.id, ] verifylist = [ diff --git a/openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py b/openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py index c8c6fac9..706783bd 100644 --- a/openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py +++ b/openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py @@ -25,7 +25,6 @@ from openstackclient.volume.v2 import volume_transfer_request class TestTransfer(volume_fakes.TestVolume): - def setUp(self): super().setUp() @@ -39,7 +38,6 @@ class TestTransfer(volume_fakes.TestVolume): class TestTransferAccept(TestTransfer): - columns = ( 'id', 'name', @@ -61,11 +59,13 @@ class TestTransferAccept(TestTransfer): # Get the command object to test self.cmd = volume_transfer_request.AcceptTransferRequest( - self.app, None) + self.app, None + ) def test_transfer_accept(self): arglist = [ - '--auth-key', 'key_value', + '--auth-key', + 'key_value', self.volume_transfer.id, ] verifylist = [ @@ -104,7 +104,6 @@ class TestTransferAccept(TestTransfer): class TestTransferCreate(TestTransfer): - volume = volume_fakes.create_one_volume() columns = ( @@ -138,7 +137,8 @@ class TestTransferCreate(TestTransfer): # Get the command object to test self.cmd = volume_transfer_request.CreateTransferRequest( - self.app, None) + self.app, None + ) def test_transfer_create_without_name(self): arglist = [ @@ -151,14 +151,14 @@ class TestTransferCreate(TestTransfer): columns, data = self.cmd.take_action(parsed_args) - self.transfer_mock.create.assert_called_once_with( - self.volume.id, None) + self.transfer_mock.create.assert_called_once_with(self.volume.id, None) self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) def test_transfer_create_with_name(self): arglist = [ - '--name', self.volume_transfer.name, + '--name', + self.volume_transfer.name, self.volume.id, ] verifylist = [ @@ -170,13 +170,16 @@ class TestTransferCreate(TestTransfer): columns, data = self.cmd.take_action(parsed_args) self.transfer_mock.create.assert_called_once_with( - self.volume.id, self.volume_transfer.name,) + self.volume.id, + self.volume_transfer.name, + ) self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) def test_transfer_create_with_no_snapshots(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.55') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.55' + ) arglist = [ '--no-snapshots', @@ -192,13 +195,15 @@ class TestTransferCreate(TestTransfer): columns, data = self.cmd.take_action(parsed_args) self.transfer_mock.create.assert_called_once_with( - self.volume.id, None, no_snapshots=True) + self.volume.id, None, no_snapshots=True + ) self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) def test_transfer_create_pre_v355(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.54') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.54' + ) arglist = [ '--no-snapshots', @@ -212,16 +217,14 @@ class TestTransferCreate(TestTransfer): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.55 or greater is required', - str(exc)) + '--os-volume-api-version 3.55 or greater is required', str(exc) + ) class TestTransferDelete(TestTransfer): - volume_transfers = volume_fakes.create_transfers(count=2) def setUp(self): @@ -234,21 +237,19 @@ class TestTransferDelete(TestTransfer): # Get the command object to mock self.cmd = volume_transfer_request.DeleteTransferRequest( - self.app, None) + self.app, None + ) def test_transfer_delete(self): - arglist = [ - self.volume_transfers[0].id - ] - verifylist = [ - ("transfer_request", [self.volume_transfers[0].id]) - ] + arglist = [self.volume_transfers[0].id] + verifylist = [("transfer_request", [self.volume_transfers[0].id])] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.transfer_mock.delete.assert_called_with( - self.volume_transfers[0].id) + self.volume_transfers[0].id + ) self.assertIsNone(result) def test_delete_multiple_transfers(self): @@ -280,17 +281,21 @@ class TestTransferDelete(TestTransfer): parsed_args = self.check_parser(self.cmd, arglist, verifylist) find_mock_result = [self.volume_transfers[0], exceptions.CommandError] - with mock.patch.object(utils, 'find_resource', - side_effect=find_mock_result) as find_mock: + with mock.patch.object( + utils, 'find_resource', side_effect=find_mock_result + ) as find_mock: try: self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual('1 of 2 volume transfer requests failed ' - 'to delete', str(e)) + self.assertEqual( + '1 of 2 volume transfer requests failed ' 'to delete', + str(e), + ) find_mock.assert_any_call( - self.transfer_mock, self.volume_transfers[0].id) + self.transfer_mock, self.volume_transfers[0].id + ) find_mock.assert_any_call(self.transfer_mock, 'unexist_transfer') self.assertEqual(2, find_mock.call_count) @@ -300,7 +305,6 @@ class TestTransferDelete(TestTransfer): class TestTransferList(TestTransfer): - # The Transfers to be listed volume_transfers = volume_fakes.create_one_transfer() @@ -331,28 +335,25 @@ class TestTransferList(TestTransfer): # confirming if all expected columns are present in the result. self.assertEqual(expected_columns, columns) - datalist = (( - self.volume_transfers.id, - self.volume_transfers.name, - self.volume_transfers.volume_id, - ), ) + datalist = ( + ( + self.volume_transfers.id, + self.volume_transfers.name, + self.volume_transfers.volume_id, + ), + ) # confirming if all expected values are present in the result. self.assertEqual(datalist, tuple(data)) # checking if proper call was made to list volume_transfers self.transfer_mock.list.assert_called_with( - detailed=True, - search_opts={'all_tenants': 0} + detailed=True, search_opts={'all_tenants': 0} ) def test_transfer_list_with_argument(self): - arglist = [ - "--all-projects" - ] - verifylist = [ - ("all_projects", True) - ] + arglist = ["--all-projects"] + verifylist = [("all_projects", True)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -370,24 +371,24 @@ class TestTransferList(TestTransfer): # confirming if all expected columns are present in the result. self.assertEqual(expected_columns, columns) - datalist = (( - self.volume_transfers.id, - self.volume_transfers.name, - self.volume_transfers.volume_id, - ), ) + datalist = ( + ( + self.volume_transfers.id, + self.volume_transfers.name, + self.volume_transfers.volume_id, + ), + ) # confirming if all expected values are present in the result. self.assertEqual(datalist, tuple(data)) # checking if proper call was made to list volume_transfers self.transfer_mock.list.assert_called_with( - detailed=True, - search_opts={'all_tenants': 1} + detailed=True, search_opts={'all_tenants': 1} ) class TestTransferShow(TestTransfer): - columns = ( 'created_at', 'id', @@ -411,8 +412,7 @@ class TestTransferShow(TestTransfer): self.transfer_mock.get.return_value = self.volume_transfer # Get the command object to test - self.cmd = volume_transfer_request.ShowTransferRequest( - self.app, None) + self.cmd = volume_transfer_request.ShowTransferRequest(self.app, None) def test_transfer_show(self): arglist = [ @@ -425,7 +425,6 @@ class TestTransferShow(TestTransfer): columns, data = self.cmd.take_action(parsed_args) - self.transfer_mock.get.assert_called_once_with( - self.volume_transfer.id) + self.transfer_mock.get.assert_called_once_with(self.volume_transfer.id) self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) diff --git a/openstackclient/tests/unit/volume/v3/fakes.py b/openstackclient/tests/unit/volume/v3/fakes.py index 62383580..c8b8e9f4 100644 --- a/openstackclient/tests/unit/volume/v3/fakes.py +++ b/openstackclient/tests/unit/volume/v3/fakes.py @@ -455,7 +455,8 @@ def create_service_log_level_entry(attrs=None): service_log_level_info.update(attrs) service_log_level = fakes.FakeResource( - None, service_log_level_info, loaded=True) + None, service_log_level_info, loaded=True + ) return service_log_level @@ -481,10 +482,13 @@ def create_cleanup_records(): cleaning_records.append(cleaning_work_info) unavailable_records.append(unavailable_work_info) - cleaning = [fakes.FakeResource( - None, obj, loaded=True) for obj in cleaning_records] - unavailable = [fakes.FakeResource( - None, obj, loaded=True) for obj in unavailable_records] + cleaning = [ + fakes.FakeResource(None, obj, loaded=True) for obj in cleaning_records + ] + unavailable = [ + fakes.FakeResource(None, obj, loaded=True) + for obj in unavailable_records + ] return cleaning, unavailable @@ -513,7 +517,8 @@ def create_volume_manage_list_records(count=2): volume_manage_list = [] for i in range(count): volume_manage_list.append( - create_one_manage_record({'size': str(i + 1)})) + create_one_manage_record({'size': str(i + 1)}) + ) return volume_manage_list @@ -522,6 +527,7 @@ def create_snapshot_manage_list_records(count=2): snapshot_manage_list = [] for i in range(count): snapshot_manage_list.append( - create_one_manage_record({'size': str(i + 1)}, snapshot=True)) + create_one_manage_record({'size': str(i + 1)}, snapshot=True) + ) return snapshot_manage_list diff --git a/openstackclient/tests/unit/volume/v3/test_block_storage_cleanup.py b/openstackclient/tests/unit/volume/v3/test_block_storage_cleanup.py index b48ce2f9..7739dbc2 100644 --- a/openstackclient/tests/unit/volume/v3/test_block_storage_cleanup.py +++ b/openstackclient/tests/unit/volume/v3/test_block_storage_cleanup.py @@ -20,7 +20,6 @@ from openstackclient.volume.v3 import block_storage_cleanup class TestBlockStorage(volume_fakes.TestVolume): - def setUp(self): super().setUp() @@ -30,7 +29,6 @@ class TestBlockStorage(volume_fakes.TestVolume): class TestBlockStorageCleanup(TestBlockStorage): - cleaning, unavailable = volume_fakes.create_cleanup_records() def setUp(self): @@ -39,15 +37,14 @@ class TestBlockStorageCleanup(TestBlockStorage): self.worker_mock.clean.return_value = (self.cleaning, self.unavailable) # Get the command object to test - self.cmd = \ - block_storage_cleanup.BlockStorageCleanup(self.app, None) + self.cmd = block_storage_cleanup.BlockStorageCleanup(self.app, None) def test_cleanup(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.24') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.24' + ) - arglist = [ - ] + arglist = [] verifylist = [ ('cluster', None), ('host', None), @@ -62,22 +59,12 @@ class TestBlockStorageCleanup(TestBlockStorage): expected_columns = ('ID', 'Cluster Name', 'Host', 'Binary', 'Status') cleaning_data = tuple( - ( - obj.id, - obj.cluster_name, - obj.host, - obj.binary, - 'Cleaning' - ) for obj in self.cleaning + (obj.id, obj.cluster_name, obj.host, obj.binary, 'Cleaning') + for obj in self.cleaning ) unavailable_data = tuple( - ( - obj.id, - obj.cluster_name, - obj.host, - obj.binary, - 'Unavailable' - ) for obj in self.unavailable + (obj.id, obj.cluster_name, obj.host, obj.binary, 'Unavailable') + for obj in self.unavailable ) expected_data = cleaning_data + unavailable_data columns, data = self.cmd.take_action(parsed_args) @@ -91,8 +78,7 @@ class TestBlockStorageCleanup(TestBlockStorage): self.worker_mock.clean.assert_called_once_with() def test_block_storage_cleanup_pre_324(self): - arglist = [ - ] + arglist = [] verifylist = [ ('cluster', None), ('host', None), @@ -104,14 +90,17 @@ class TestBlockStorageCleanup(TestBlockStorage): ('service_id', None), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - exc = self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) + exc = self.assertRaises( + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.24 or greater is required', str(exc)) + '--os-volume-api-version 3.24 or greater is required', str(exc) + ) def test_cleanup_with_args(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.24') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.24' + ) fake_cluster = 'fake-cluster' fake_host = 'fake-host' @@ -120,14 +109,20 @@ class TestBlockStorageCleanup(TestBlockStorage): fake_resource_type = 'Volume' fake_service_id = 1 arglist = [ - '--cluster', fake_cluster, - '--host', fake_host, - '--binary', fake_binary, + '--cluster', + fake_cluster, + '--host', + fake_host, + '--binary', + fake_binary, '--down', '--enabled', - '--resource-id', fake_resource_id, - '--resource-type', fake_resource_type, - '--service-id', str(fake_service_id), + '--resource-id', + fake_resource_id, + '--resource-type', + fake_resource_type, + '--service-id', + str(fake_service_id), ] verifylist = [ ('cluster', fake_cluster), @@ -143,22 +138,12 @@ class TestBlockStorageCleanup(TestBlockStorage): expected_columns = ('ID', 'Cluster Name', 'Host', 'Binary', 'Status') cleaning_data = tuple( - ( - obj.id, - obj.cluster_name, - obj.host, - obj.binary, - 'Cleaning' - ) for obj in self.cleaning + (obj.id, obj.cluster_name, obj.host, obj.binary, 'Cleaning') + for obj in self.cleaning ) unavailable_data = tuple( - ( - obj.id, - obj.cluster_name, - obj.host, - obj.binary, - 'Unavailable' - ) for obj in self.unavailable + (obj.id, obj.cluster_name, obj.host, obj.binary, 'Unavailable') + for obj in self.unavailable ) expected_data = cleaning_data + unavailable_data columns, data = self.cmd.take_action(parsed_args) @@ -175,4 +160,5 @@ class TestBlockStorageCleanup(TestBlockStorage): disabled=False, resource_id=fake_resource_id, resource_type=fake_resource_type, - service_id=fake_service_id) + service_id=fake_service_id, + ) diff --git a/openstackclient/tests/unit/volume/v3/test_block_storage_cluster.py b/openstackclient/tests/unit/volume/v3/test_block_storage_cluster.py index fdfd1100..c6ba6340 100644 --- a/openstackclient/tests/unit/volume/v3/test_block_storage_cluster.py +++ b/openstackclient/tests/unit/volume/v3/test_block_storage_cluster.py @@ -18,7 +18,6 @@ from openstackclient.volume.v3 import block_storage_cluster class TestBlockStorageCluster(volume_fakes.TestVolume): - def setUp(self): super().setUp() @@ -28,7 +27,6 @@ class TestBlockStorageCluster(volume_fakes.TestVolume): class TestBlockStorageClusterList(TestBlockStorageCluster): - # The cluster to be listed fake_clusters = volume_fakes.create_clusters() @@ -38,15 +36,16 @@ class TestBlockStorageClusterList(TestBlockStorageCluster): self.cluster_mock.list.return_value = self.fake_clusters # Get the command object to test - self.cmd = \ - block_storage_cluster.ListBlockStorageCluster(self.app, None) + self.cmd = block_storage_cluster.ListBlockStorageCluster( + self.app, None + ) def test_cluster_list(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.7') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.7' + ) - arglist = [ - ] + arglist = [] verifylist = [ ('cluster', None), ('binary', None), @@ -65,7 +64,8 @@ class TestBlockStorageClusterList(TestBlockStorageCluster): cluster.binary, cluster.state, cluster.status, - ) for cluster in self.fake_clusters + ) + for cluster in self.fake_clusters ) columns, data = self.cmd.take_action(parsed_args) @@ -84,16 +84,21 @@ class TestBlockStorageClusterList(TestBlockStorageCluster): ) def test_cluster_list_with_full_options(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.7') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.7' + ) arglist = [ - '--cluster', 'foo', - '--binary', 'bar', + '--cluster', + 'foo', + '--binary', + 'bar', '--up', '--disabled', - '--num-hosts', '5', - '--num-down-hosts', '0', + '--num-hosts', + '5', + '--num-down-hosts', + '0', '--long', ] verifylist = [ @@ -131,7 +136,8 @@ class TestBlockStorageClusterList(TestBlockStorageCluster): cluster.disabled_reason, cluster.created_at, cluster.updated_at, - ) for cluster in self.fake_clusters + ) + for cluster in self.fake_clusters ) columns, data = self.cmd.take_action(parsed_args) @@ -150,11 +156,11 @@ class TestBlockStorageClusterList(TestBlockStorageCluster): ) def test_cluster_list_pre_v37(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.6') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.6' + ) - arglist = [ - ] + arglist = [] verifylist = [ ('cluster', None), ('binary', None), @@ -167,15 +173,14 @@ class TestBlockStorageClusterList(TestBlockStorageCluster): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.7 or greater is required', str(exc)) + '--os-volume-api-version 3.7 or greater is required', str(exc) + ) class TestBlockStorageClusterSet(TestBlockStorageCluster): - cluster = volume_fakes.create_one_cluster() columns = ( 'Name', @@ -213,12 +218,12 @@ class TestBlockStorageClusterSet(TestBlockStorageCluster): self.cluster_mock.update.return_value = self.cluster - self.cmd = \ - block_storage_cluster.SetBlockStorageCluster(self.app, None) + self.cmd = block_storage_cluster.SetBlockStorageCluster(self.app, None) def test_cluster_set(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.7') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.7' + ) arglist = [ '--enable', @@ -245,13 +250,16 @@ class TestBlockStorageClusterSet(TestBlockStorageCluster): ) def test_cluster_set_disable_with_reason(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.7') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.7' + ) arglist = [ - '--binary', self.cluster.binary, + '--binary', + self.cluster.binary, '--disable', - '--disable-reason', 'foo', + '--disable-reason', + 'foo', self.cluster.name, ] verifylist = [ @@ -274,11 +282,13 @@ class TestBlockStorageClusterSet(TestBlockStorageCluster): ) def test_cluster_set_only_with_disable_reason(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.7') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.7' + ) arglist = [ - '--disable-reason', 'foo', + '--disable-reason', + 'foo', self.cluster.name, ] verifylist = [ @@ -290,19 +300,21 @@ class TestBlockStorageClusterSet(TestBlockStorageCluster): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - "Cannot specify --disable-reason without --disable", str(exc)) + "Cannot specify --disable-reason without --disable", str(exc) + ) def test_cluster_set_enable_with_disable_reason(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.7') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.7' + ) arglist = [ '--enable', - '--disable-reason', 'foo', + '--disable-reason', + 'foo', self.cluster.name, ] verifylist = [ @@ -314,15 +326,16 @@ class TestBlockStorageClusterSet(TestBlockStorageCluster): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - "Cannot specify --disable-reason without --disable", str(exc)) + "Cannot specify --disable-reason without --disable", str(exc) + ) def test_cluster_set_pre_v37(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.6') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.6' + ) arglist = [ '--enable', @@ -338,15 +351,14 @@ class TestBlockStorageClusterSet(TestBlockStorageCluster): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.7 or greater is required', str(exc)) + '--os-volume-api-version 3.7 or greater is required', str(exc) + ) class TestBlockStorageClusterShow(TestBlockStorageCluster): - cluster = volume_fakes.create_one_cluster() columns = ( 'Name', @@ -384,15 +396,18 @@ class TestBlockStorageClusterShow(TestBlockStorageCluster): self.cluster_mock.show.return_value = self.cluster - self.cmd = \ - block_storage_cluster.ShowBlockStorageCluster(self.app, None) + self.cmd = block_storage_cluster.ShowBlockStorageCluster( + self.app, None + ) def test_cluster_show(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.7') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.7' + ) arglist = [ - '--binary', self.cluster.binary, + '--binary', + self.cluster.binary, self.cluster.name, ] verifylist = [ @@ -412,11 +427,13 @@ class TestBlockStorageClusterShow(TestBlockStorageCluster): ) def test_cluster_show_pre_v37(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.6') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.6' + ) arglist = [ - '--binary', self.cluster.binary, + '--binary', + self.cluster.binary, self.cluster.name, ] verifylist = [ @@ -427,8 +444,8 @@ class TestBlockStorageClusterShow(TestBlockStorageCluster): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.7 or greater is required', str(exc)) + '--os-volume-api-version 3.7 or greater is required', str(exc) + ) diff --git a/openstackclient/tests/unit/volume/v3/test_block_storage_log_level.py b/openstackclient/tests/unit/volume/v3/test_block_storage_log_level.py index 35ea6274..769954a2 100644 --- a/openstackclient/tests/unit/volume/v3/test_block_storage_log_level.py +++ b/openstackclient/tests/unit/volume/v3/test_block_storage_log_level.py @@ -22,7 +22,6 @@ from openstackclient.volume.v3 import block_storage_log_level as service class TestService(volume_fakes.TestVolume): - def setUp(self): super().setUp() @@ -32,7 +31,6 @@ class TestService(volume_fakes.TestVolume): class TestBlockStorageLogLevelList(TestService): - service_log = volume_fakes.create_service_log_level_entry() def setUp(self): @@ -44,12 +42,16 @@ class TestBlockStorageLogLevelList(TestService): self.cmd = service.BlockStorageLogLevelList(self.app, None) def test_block_storage_log_level_list(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.32') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.32' + ) arglist = [ - '--host', self.service_log.host, - '--service', self.service_log.binary, - '--log-prefix', self.service_log.prefix, + '--host', + self.service_log.host, + '--service', + self.service_log.binary, + '--log-prefix', + self.service_log.prefix, ] verifylist = [ ('host', self.service_log.host), @@ -70,12 +72,14 @@ class TestBlockStorageLogLevelList(TestService): # confirming if all expected columns are present in the result. self.assertEqual(expected_columns, columns) - datalist = (( - self.service_log.binary, - self.service_log.host, - self.service_log.prefix, - self.service_log.level, - ), ) + datalist = ( + ( + self.service_log.binary, + self.service_log.host, + self.service_log.prefix, + self.service_log.level, + ), + ) # confirming if all expected values are present in the result. self.assertEqual(datalist, tuple(data)) @@ -89,9 +93,12 @@ class TestBlockStorageLogLevelList(TestService): def test_block_storage_log_level_list_pre_332(self): arglist = [ - '--host', self.service_log.host, - '--service', 'cinder-api', - '--log-prefix', 'cinder_test.api.common', + '--host', + self.service_log.host, + '--service', + 'cinder-api', + '--log-prefix', + 'cinder_test.api.common', ] verifylist = [ ('host', self.service_log.host), @@ -100,18 +107,24 @@ class TestBlockStorageLogLevelList(TestService): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - exc = self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) + exc = self.assertRaises( + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.32 or greater is required', str(exc)) + '--os-volume-api-version 3.32 or greater is required', str(exc) + ) def test_block_storage_log_level_list_invalid_service_name(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.32') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.32' + ) arglist = [ - '--host', self.service_log.host, - '--service', 'nova-api', - '--log-prefix', 'cinder_test.api.common', + '--host', + self.service_log.host, + '--service', + 'nova-api', + '--log-prefix', + 'cinder_test.api.common', ] verifylist = [ ('host', self.service_log.host), @@ -119,13 +132,17 @@ class TestBlockStorageLogLevelList(TestService): ('log_prefix', 'cinder_test.api.common'), ] - self.assertRaises(tests_utils.ParserException, self.check_parser, - self.cmd, arglist, verifylist) + self.assertRaises( + tests_utils.ParserException, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) @ddt.ddt class TestBlockStorageLogLevelSet(TestService): - service_log = volume_fakes.create_service_log_level_entry() def setUp(self): @@ -135,13 +152,17 @@ class TestBlockStorageLogLevelSet(TestService): self.cmd = service.BlockStorageLogLevelSet(self.app, None) def test_block_storage_log_level_set(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.32') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.32' + ) arglist = [ 'ERROR', - '--host', self.service_log.host, - '--service', self.service_log.binary, - '--log-prefix', self.service_log.prefix, + '--host', + self.service_log.host, + '--service', + self.service_log.binary, + '--log-prefix', + self.service_log.prefix, ] verifylist = [ ('level', 'ERROR'), @@ -164,9 +185,12 @@ class TestBlockStorageLogLevelSet(TestService): def test_block_storage_log_level_set_pre_332(self): arglist = [ 'ERROR', - '--host', self.service_log.host, - '--service', 'cinder-api', - '--log-prefix', 'cinder_test.api.common', + '--host', + self.service_log.host, + '--service', + 'cinder-api', + '--log-prefix', + 'cinder_test.api.common', ] verifylist = [ ('level', 'ERROR'), @@ -176,19 +200,25 @@ class TestBlockStorageLogLevelSet(TestService): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - exc = self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) + exc = self.assertRaises( + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.32 or greater is required', str(exc)) + '--os-volume-api-version 3.32 or greater is required', str(exc) + ) def test_block_storage_log_level_set_invalid_service_name(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.32') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.32' + ) arglist = [ 'ERROR', - '--host', self.service_log.host, - '--service', 'nova-api', - '--log-prefix', 'cinder.api.common', + '--host', + self.service_log.host, + '--service', + 'nova-api', + '--log-prefix', + 'cinder.api.common', ] verifylist = [ ('level', 'ERROR'), @@ -197,18 +227,27 @@ class TestBlockStorageLogLevelSet(TestService): ('log_prefix', 'cinder.api.common'), ] - self.assertRaises(tests_utils.ParserException, self.check_parser, - self.cmd, arglist, verifylist) + self.assertRaises( + tests_utils.ParserException, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) @ddt.data('WARNING', 'info', 'Error', 'debuG', 'fake-log-level') def test_block_storage_log_level_set_log_level(self, log_level): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.32') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.32' + ) arglist = [ log_level, - '--host', self.service_log.host, - '--service', 'cinder-api', - '--log-prefix', 'cinder.api.common', + '--host', + self.service_log.host, + '--service', + 'cinder-api', + '--log-prefix', + 'cinder.api.common', ] verifylist = [ ('level', log_level.upper()), @@ -218,8 +257,13 @@ class TestBlockStorageLogLevelSet(TestService): ] if log_level == 'fake-log-level': - self.assertRaises(tests_utils.ParserException, self.check_parser, - self.cmd, arglist, verifylist) + self.assertRaises( + tests_utils.ParserException, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) else: parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -230,4 +274,5 @@ class TestBlockStorageLogLevelSet(TestService): level=log_level.upper(), server=self.service_log.host, binary=self.service_log.binary, - prefix=self.service_log.prefix) + prefix=self.service_log.prefix, + ) diff --git a/openstackclient/tests/unit/volume/v3/test_block_storage_manage.py b/openstackclient/tests/unit/volume/v3/test_block_storage_manage.py index afd0fd35..27a7bf35 100644 --- a/openstackclient/tests/unit/volume/v3/test_block_storage_manage.py +++ b/openstackclient/tests/unit/volume/v3/test_block_storage_manage.py @@ -21,7 +21,6 @@ from openstackclient.volume.v3 import block_storage_manage class TestBlockStorageManage(v2_volume_fakes.TestVolume): - def setUp(self): super().setUp() @@ -32,22 +31,24 @@ class TestBlockStorageManage(v2_volume_fakes.TestVolume): class TestBlockStorageVolumeManage(TestBlockStorageManage): - volume_manage_list = volume_fakes.create_volume_manage_list_records() def setUp(self): super().setUp() self.volumes_mock.list_manageable.return_value = ( - self.volume_manage_list) + self.volume_manage_list + ) # Get the command object to test self.cmd = block_storage_manage.BlockStorageManageVolumes( - self.app, None) + self.app, None + ) def test_block_storage_volume_manage_list(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.8') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.8' + ) host = 'fake_host' arglist = [ host, @@ -108,51 +109,65 @@ class TestBlockStorageVolumeManage(TestBlockStorageManage): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - exc = self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) + exc = self.assertRaises( + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.8 or greater is required', str(exc)) + '--os-volume-api-version 3.8 or greater is required', str(exc) + ) def test_block_storage_volume_manage_pre_317(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.16') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.16' + ) cluster = 'fake_cluster' arglist = [ - '--cluster', cluster, + '--cluster', + cluster, ] verifylist = [ ('cluster', cluster), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - exc = self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) + exc = self.assertRaises( + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.17 or greater is required', str(exc)) + '--os-volume-api-version 3.17 or greater is required', str(exc) + ) self.assertIn('--cluster', str(exc)) def test_block_storage_volume_manage_host_and_cluster(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.17') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.17' + ) host = 'fake_host' cluster = 'fake_cluster' arglist = [ host, - '--cluster', cluster, + '--cluster', + cluster, ] verifylist = [ ('host', host), ('cluster', cluster), ] - exc = self.assertRaises(tests_utils.ParserException, - self.check_parser, self.cmd, - arglist, verifylist) + exc = self.assertRaises( + tests_utils.ParserException, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) self.assertIn( - 'argument --cluster: not allowed with argument <host>', str(exc)) + 'argument --cluster: not allowed with argument <host>', str(exc) + ) def test_block_storage_volume_manage_list_all_args(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.8') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.8' + ) host = 'fake_host' detailed = True marker = 'fake_marker' @@ -161,11 +176,16 @@ class TestBlockStorageVolumeManage(TestBlockStorageManage): sort = 'size:asc' arglist = [ host, - '--detailed', str(detailed), - '--marker', marker, - '--limit', limit, - '--offset', offset, - '--sort', sort, + '--detailed', + str(detailed), + '--marker', + marker, + '--limit', + limit, + '--offset', + offset, + '--sort', + sort, ] verifylist = [ ('host', host), @@ -220,22 +240,24 @@ class TestBlockStorageVolumeManage(TestBlockStorageManage): class TestBlockStorageSnapshotManage(TestBlockStorageManage): - snapshot_manage_list = volume_fakes.create_snapshot_manage_list_records() def setUp(self): super().setUp() self.snapshots_mock.list_manageable.return_value = ( - self.snapshot_manage_list) + self.snapshot_manage_list + ) # Get the command object to test self.cmd = block_storage_manage.BlockStorageManageSnapshots( - self.app, None) + self.app, None + ) def test_block_storage_snapshot_manage_list(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.8') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.8' + ) host = 'fake_host' arglist = [ host, @@ -298,51 +320,65 @@ class TestBlockStorageSnapshotManage(TestBlockStorageManage): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - exc = self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) + exc = self.assertRaises( + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.8 or greater is required', str(exc)) + '--os-volume-api-version 3.8 or greater is required', str(exc) + ) def test_block_storage_volume_manage_pre_317(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.16') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.16' + ) cluster = 'fake_cluster' arglist = [ - '--cluster', cluster, + '--cluster', + cluster, ] verifylist = [ ('cluster', cluster), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - exc = self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) + exc = self.assertRaises( + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.17 or greater is required', str(exc)) + '--os-volume-api-version 3.17 or greater is required', str(exc) + ) self.assertIn('--cluster', str(exc)) def test_block_storage_volume_manage_host_and_cluster(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.17') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.17' + ) host = 'fake_host' cluster = 'fake_cluster' arglist = [ host, - '--cluster', cluster, + '--cluster', + cluster, ] verifylist = [ ('host', host), ('cluster', cluster), ] - exc = self.assertRaises(tests_utils.ParserException, - self.check_parser, self.cmd, - arglist, verifylist) + exc = self.assertRaises( + tests_utils.ParserException, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) self.assertIn( - 'argument --cluster: not allowed with argument <host>', str(exc)) + 'argument --cluster: not allowed with argument <host>', str(exc) + ) def test_block_storage_volume_manage_list_all_args(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.8') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.8' + ) host = 'fake_host' detailed = True marker = 'fake_marker' @@ -351,11 +387,16 @@ class TestBlockStorageSnapshotManage(TestBlockStorageManage): sort = 'size:asc' arglist = [ host, - '--detailed', str(detailed), - '--marker', marker, - '--limit', limit, - '--offset', offset, - '--sort', sort, + '--detailed', + str(detailed), + '--marker', + marker, + '--limit', + limit, + '--offset', + offset, + '--sort', + sort, ] verifylist = [ ('host', host), diff --git a/openstackclient/tests/unit/volume/v3/test_block_storage_resource_filter.py b/openstackclient/tests/unit/volume/v3/test_block_storage_resource_filter.py index 086339ff..782da15d 100644 --- a/openstackclient/tests/unit/volume/v3/test_block_storage_resource_filter.py +++ b/openstackclient/tests/unit/volume/v3/test_block_storage_resource_filter.py @@ -18,34 +18,38 @@ from openstackclient.volume.v3 import block_storage_resource_filter class TestBlockStorageResourceFilter(volume_fakes.TestVolume): - def setUp(self): super().setUp() # Get a shortcut to the ResourceFilterManager Mock - self.resource_filter_mock = \ + self.resource_filter_mock = ( self.app.client_manager.volume.resource_filters + ) self.resource_filter_mock.reset_mock() class TestBlockStorageResourceFilterList(TestBlockStorageResourceFilter): - # The resource filters to be listed fake_resource_filters = volume_fakes.create_resource_filters() def setUp(self): super().setUp() - self.resource_filter_mock.list.return_value = \ + self.resource_filter_mock.list.return_value = ( self.fake_resource_filters + ) # Get the command object to test - self.cmd = block_storage_resource_filter\ - .ListBlockStorageResourceFilter(self.app, None) + self.cmd = ( + block_storage_resource_filter.ListBlockStorageResourceFilter( + self.app, None + ) + ) def test_resource_filter_list(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.33') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.33' + ) arglist = [] verifylist = [] @@ -56,7 +60,8 @@ class TestBlockStorageResourceFilterList(TestBlockStorageResourceFilter): ( resource_filter.resource, resource_filter.filters, - ) for resource_filter in self.fake_resource_filters + ) + for resource_filter in self.fake_resource_filters ) columns, data = self.cmd.take_action(parsed_args) @@ -67,39 +72,44 @@ class TestBlockStorageResourceFilterList(TestBlockStorageResourceFilter): self.resource_filter_mock.list.assert_called_with() def test_resource_filter_list_pre_v333(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.32') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.32' + ) arglist = [] verifylist = [] parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.33 or greater is required', str(exc)) + '--os-volume-api-version 3.33 or greater is required', str(exc) + ) class TestBlockStorageResourceFilterShow(TestBlockStorageResourceFilter): - # The resource filters to be listed fake_resource_filter = volume_fakes.create_one_resource_filter() def setUp(self): super().setUp() - self.resource_filter_mock.list.return_value = \ - iter([self.fake_resource_filter]) + self.resource_filter_mock.list.return_value = iter( + [self.fake_resource_filter] + ) # Get the command object to test - self.cmd = block_storage_resource_filter\ - .ShowBlockStorageResourceFilter(self.app, None) + self.cmd = ( + block_storage_resource_filter.ShowBlockStorageResourceFilter( + self.app, None + ) + ) def test_resource_filter_show(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.33') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.33' + ) arglist = [ self.fake_resource_filter.resource, @@ -123,8 +133,9 @@ class TestBlockStorageResourceFilterShow(TestBlockStorageResourceFilter): self.resource_filter_mock.list.assert_called_with(resource='volume') def test_resource_filter_show_pre_v333(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.32') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.32' + ) arglist = [ self.fake_resource_filter.resource, @@ -135,8 +146,8 @@ class TestBlockStorageResourceFilterShow(TestBlockStorageResourceFilter): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.33 or greater is required', str(exc)) + '--os-volume-api-version 3.33 or greater is required', str(exc) + ) diff --git a/openstackclient/tests/unit/volume/v3/test_volume.py b/openstackclient/tests/unit/volume/v3/test_volume.py index ed72bfa1..507edc42 100644 --- a/openstackclient/tests/unit/volume/v3/test_volume.py +++ b/openstackclient/tests/unit/volume/v3/test_volume.py @@ -25,7 +25,6 @@ from openstackclient.volume.v3 import volume class TestVolumeSummary(volume_fakes.TestVolume): - columns = [ 'Total Count', 'Total Size', @@ -41,15 +40,18 @@ class TestVolumeSummary(volume_fakes.TestVolume): self.return_dict = { 'volume-summary': { 'total_count': 2, - 'total_size': self.mock_vol_1.size + self.mock_vol_2.size}} + 'total_size': self.mock_vol_1.size + self.mock_vol_2.size, + } + } self.volumes_mock.summary.return_value = self.return_dict # Get the command object to test self.cmd = volume.VolumeSummary(self.app, None) def test_volume_summary(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.12') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.12' + ) arglist = [ '--all-projects', ] @@ -66,9 +68,7 @@ class TestVolumeSummary(volume_fakes.TestVolume): self.assertEqual(self.columns, columns) - datalist = ( - 2, - self.mock_vol_1.size + self.mock_vol_2.size) + datalist = (2, self.mock_vol_1.size + self.mock_vol_2.size) self.assertCountEqual(datalist, tuple(data)) def test_volume_summary_pre_312(self): @@ -81,16 +81,16 @@ class TestVolumeSummary(volume_fakes.TestVolume): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.12 or greater is required', - str(exc)) + '--os-volume-api-version 3.12 or greater is required', str(exc) + ) def test_volume_summary_with_metadata(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.36') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.36' + ) combine_meta = {**self.mock_vol_1.metadata, **self.mock_vol_2.metadata} meta_dict = copy.deepcopy(self.return_dict) @@ -119,12 +119,12 @@ class TestVolumeSummary(volume_fakes.TestVolume): datalist = ( 2, self.mock_vol_1.size + self.mock_vol_2.size, - format_columns.DictColumn(combine_meta)) + format_columns.DictColumn(combine_meta), + ) self.assertCountEqual(datalist, tuple(data)) class TestVolumeRevertToSnapshot(volume_fakes.TestVolume): - def setUp(self): super().setUp() @@ -134,7 +134,8 @@ class TestVolumeRevertToSnapshot(volume_fakes.TestVolume): self.snapshots_mock.reset_mock() self.mock_volume = volume_fakes.create_one_volume() self.mock_snapshot = volume_fakes.create_one_snapshot( - attrs={'volume_id': self.volumes_mock.id}) + attrs={'volume_id': self.volumes_mock.id} + ) # Get the command object to test self.cmd = volume.VolumeRevertToSnapshot(self.app, None) @@ -149,16 +150,16 @@ class TestVolumeRevertToSnapshot(volume_fakes.TestVolume): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.40 or greater is required', - str(exc)) + '--os-volume-api-version 3.40 or greater is required', str(exc) + ) def test_volume_revert_to_snapshot(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.40') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.40' + ) arglist = [ self.mock_snapshot.id, ] @@ -168,8 +169,9 @@ class TestVolumeRevertToSnapshot(volume_fakes.TestVolume): parsed_args = self.check_parser(self.cmd, arglist, verifylist) find_mock_result = [self.mock_snapshot, self.mock_volume] - with mock.patch.object(utils, 'find_resource', - side_effect=find_mock_result) as find_mock: + with mock.patch.object( + utils, 'find_resource', side_effect=find_mock_result + ) as find_mock: self.cmd.take_action(parsed_args) self.volumes_mock.revert_to_snapshot.assert_called_once_with( diff --git a/openstackclient/tests/unit/volume/v3/test_volume_attachment.py b/openstackclient/tests/unit/volume/v3/test_volume_attachment.py index c0bf5ae7..783f4552 100644 --- a/openstackclient/tests/unit/volume/v3/test_volume_attachment.py +++ b/openstackclient/tests/unit/volume/v3/test_volume_attachment.py @@ -21,15 +21,15 @@ from openstackclient.volume.v3 import volume_attachment class TestVolumeAttachment(volume_fakes.TestVolume): - def setUp(self): super().setUp() self.volumes_mock = self.app.client_manager.volume.volumes self.volumes_mock.reset_mock() - self.volume_attachments_mock = \ + self.volume_attachments_mock = ( self.app.client_manager.volume.attachments + ) self.volume_attachments_mock.reset_mock() self.projects_mock = self.app.client_manager.identity.projects @@ -40,7 +40,6 @@ class TestVolumeAttachment(volume_fakes.TestVolume): class TestVolumeAttachmentCreate(TestVolumeAttachment): - volume = volume_fakes.create_one_volume() server = compute_fakes.FakeServer.create_one_server() volume_attachment = volume_fakes.create_one_volume_attachment( @@ -74,14 +73,16 @@ class TestVolumeAttachmentCreate(TestVolumeAttachment): self.volumes_mock.get.return_value = self.volume self.servers_mock.get.return_value = self.server # VolumeAttachmentManager.create returns a dict - self.volume_attachments_mock.create.return_value = \ + self.volume_attachments_mock.create.return_value = ( self.volume_attachment.to_dict() + ) self.cmd = volume_attachment.CreateVolumeAttachment(self.app, None) def test_volume_attachment_create(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.27') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.27' + ) arglist = [ self.volume.id, @@ -107,27 +108,38 @@ class TestVolumeAttachmentCreate(TestVolumeAttachment): self.volumes_mock.get.assert_called_once_with(self.volume.id) self.servers_mock.get.assert_called_once_with(self.server.id) self.volume_attachments_mock.create.assert_called_once_with( - self.volume.id, {}, self.server.id, None, + self.volume.id, + {}, + self.server.id, + None, ) self.assertEqual(self.columns, columns) self.assertCountEqual(self.data, data) def test_volume_attachment_create_with_connect(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.54') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.54' + ) arglist = [ self.volume.id, self.server.id, '--connect', - '--initiator', 'iqn.1993-08.org.debian:01:cad181614cec', - '--ip', '192.168.1.20', - '--host', 'my-host', - '--platform', 'x86_64', - '--os-type', 'linux2', + '--initiator', + 'iqn.1993-08.org.debian:01:cad181614cec', + '--ip', + '192.168.1.20', + '--host', + 'my-host', + '--platform', + 'x86_64', + '--os-type', + 'linux2', '--multipath', - '--mountpoint', '/dev/vdb', - '--mode', 'null', + '--mountpoint', + '/dev/vdb', + '--mode', + 'null', ] verifylist = [ ('volume', self.volume.id), @@ -146,27 +158,33 @@ class TestVolumeAttachmentCreate(TestVolumeAttachment): columns, data = self.cmd.take_action(parsed_args) - connect_info = dict([ - ('initiator', 'iqn.1993-08.org.debian:01:cad181614cec'), - ('ip', '192.168.1.20'), - ('host', 'my-host'), - ('platform', 'x86_64'), - ('os_type', 'linux2'), - ('multipath', True), - ('mountpoint', '/dev/vdb'), - ]) + connect_info = dict( + [ + ('initiator', 'iqn.1993-08.org.debian:01:cad181614cec'), + ('ip', '192.168.1.20'), + ('host', 'my-host'), + ('platform', 'x86_64'), + ('os_type', 'linux2'), + ('multipath', True), + ('mountpoint', '/dev/vdb'), + ] + ) self.volumes_mock.get.assert_called_once_with(self.volume.id) self.servers_mock.get.assert_called_once_with(self.server.id) self.volume_attachments_mock.create.assert_called_once_with( - self.volume.id, connect_info, self.server.id, 'null', + self.volume.id, + connect_info, + self.server.id, + 'null', ) self.assertEqual(self.columns, columns) self.assertCountEqual(self.data, data) def test_volume_attachment_create_pre_v327(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.26') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.26' + ) arglist = [ self.volume.id, @@ -179,21 +197,22 @@ class TestVolumeAttachmentCreate(TestVolumeAttachment): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.27 or greater is required', - str(exc)) + '--os-volume-api-version 3.27 or greater is required', str(exc) + ) def test_volume_attachment_create_with_mode_pre_v354(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.53') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.53' + ) arglist = [ self.volume.id, self.server.id, - '--mode', 'rw', + '--mode', + 'rw', ] verifylist = [ ('volume', self.volume.id), @@ -203,21 +222,22 @@ class TestVolumeAttachmentCreate(TestVolumeAttachment): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.54 or greater is required', - str(exc)) + '--os-volume-api-version 3.54 or greater is required', str(exc) + ) def test_volume_attachment_create_with_connect_missing_arg(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.54') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.54' + ) arglist = [ self.volume.id, self.server.id, - '--initiator', 'iqn.1993-08.org.debian:01:cad181614cec', + '--initiator', + 'iqn.1993-08.org.debian:01:cad181614cec', ] verifylist = [ ('volume', self.volume.id), @@ -228,16 +248,14 @@ class TestVolumeAttachmentCreate(TestVolumeAttachment): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - 'You must specify the --connect option for any', - str(exc)) + 'You must specify the --connect option for any', str(exc) + ) class TestVolumeAttachmentDelete(TestVolumeAttachment): - volume_attachment = volume_fakes.create_one_volume_attachment() def setUp(self): @@ -248,8 +266,9 @@ class TestVolumeAttachmentDelete(TestVolumeAttachment): self.cmd = volume_attachment.DeleteVolumeAttachment(self.app, None) def test_volume_attachment_delete(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.27') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.27' + ) arglist = [ self.volume_attachment.id, @@ -267,8 +286,9 @@ class TestVolumeAttachmentDelete(TestVolumeAttachment): self.assertIsNone(result) def test_volume_attachment_delete_pre_v327(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.26') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.26' + ) arglist = [ self.volume_attachment.id, @@ -279,16 +299,14 @@ class TestVolumeAttachmentDelete(TestVolumeAttachment): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.27 or greater is required', - str(exc)) + '--os-volume-api-version 3.27 or greater is required', str(exc) + ) class TestVolumeAttachmentSet(TestVolumeAttachment): - volume_attachment = volume_fakes.create_one_volume_attachment() columns = ( @@ -315,24 +333,32 @@ class TestVolumeAttachmentSet(TestVolumeAttachment): def setUp(self): super().setUp() - self.volume_attachments_mock.update.return_value = \ + self.volume_attachments_mock.update.return_value = ( self.volume_attachment + ) self.cmd = volume_attachment.SetVolumeAttachment(self.app, None) def test_volume_attachment_set(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.27') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.27' + ) arglist = [ self.volume_attachment.id, - '--initiator', 'iqn.1993-08.org.debian:01:cad181614cec', - '--ip', '192.168.1.20', - '--host', 'my-host', - '--platform', 'x86_64', - '--os-type', 'linux2', + '--initiator', + 'iqn.1993-08.org.debian:01:cad181614cec', + '--ip', + '192.168.1.20', + '--host', + 'my-host', + '--platform', + 'x86_64', + '--os-type', + 'linux2', '--multipath', - '--mountpoint', '/dev/vdb', + '--mountpoint', + '/dev/vdb', ] verifylist = [ ('attachment', self.volume_attachment.id), @@ -348,29 +374,34 @@ class TestVolumeAttachmentSet(TestVolumeAttachment): columns, data = self.cmd.take_action(parsed_args) - connect_info = dict([ - ('initiator', 'iqn.1993-08.org.debian:01:cad181614cec'), - ('ip', '192.168.1.20'), - ('host', 'my-host'), - ('platform', 'x86_64'), - ('os_type', 'linux2'), - ('multipath', True), - ('mountpoint', '/dev/vdb'), - ]) + connect_info = dict( + [ + ('initiator', 'iqn.1993-08.org.debian:01:cad181614cec'), + ('ip', '192.168.1.20'), + ('host', 'my-host'), + ('platform', 'x86_64'), + ('os_type', 'linux2'), + ('multipath', True), + ('mountpoint', '/dev/vdb'), + ] + ) self.volume_attachments_mock.update.assert_called_once_with( - self.volume_attachment.id, connect_info, + self.volume_attachment.id, + connect_info, ) self.assertEqual(self.columns, columns) self.assertCountEqual(self.data, data) def test_volume_attachment_set_pre_v327(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.26') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.26' + ) arglist = [ self.volume_attachment.id, - '--initiator', 'iqn.1993-08.org.debian:01:cad181614cec', + '--initiator', + 'iqn.1993-08.org.debian:01:cad181614cec', ] verifylist = [ ('attachment', self.volume_attachment.id), @@ -379,16 +410,14 @@ class TestVolumeAttachmentSet(TestVolumeAttachment): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.27 or greater is required', - str(exc)) + '--os-volume-api-version 3.27 or greater is required', str(exc) + ) class TestVolumeAttachmentComplete(TestVolumeAttachment): - volume_attachment = volume_fakes.create_one_volume_attachment() def setUp(self): @@ -399,8 +428,9 @@ class TestVolumeAttachmentComplete(TestVolumeAttachment): self.cmd = volume_attachment.CompleteVolumeAttachment(self.app, None) def test_volume_attachment_complete(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.44') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.44' + ) arglist = [ self.volume_attachment.id, @@ -418,8 +448,9 @@ class TestVolumeAttachmentComplete(TestVolumeAttachment): self.assertIsNone(result) def test_volume_attachment_complete_pre_v344(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.43') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.43' + ) arglist = [ self.volume_attachment.id, @@ -430,16 +461,14 @@ class TestVolumeAttachmentComplete(TestVolumeAttachment): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.44 or greater is required', - str(exc)) + '--os-volume-api-version 3.44 or greater is required', str(exc) + ) class TestVolumeAttachmentList(TestVolumeAttachment): - project = identity_fakes.FakeProject.create_one_project() volume_attachments = volume_fakes.create_volume_attachments() @@ -455,21 +484,24 @@ class TestVolumeAttachmentList(TestVolumeAttachment): volume_attachment.volume_id, volume_attachment.instance, volume_attachment.status, - ) for volume_attachment in volume_attachments + ) + for volume_attachment in volume_attachments ] def setUp(self): super().setUp() self.projects_mock.get.return_value = self.project - self.volume_attachments_mock.list.return_value = \ + self.volume_attachments_mock.list.return_value = ( self.volume_attachments + ) self.cmd = volume_attachment.ListVolumeAttachment(self.app, None) def test_volume_attachment_list(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.27') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.27' + ) arglist = [] verifylist = [ @@ -498,15 +530,21 @@ class TestVolumeAttachmentList(TestVolumeAttachment): self.assertCountEqual(tuple(self.data), data) def test_volume_attachment_list_with_options(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.27') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.27' + ) arglist = [ - '--project', self.project.name, - '--volume-id', 'volume-id', - '--status', 'attached', - '--marker', 'volume-attachment-id', - '--limit', '2', + '--project', + self.project.name, + '--volume-id', + 'volume-id', + '--status', + 'attached', + '--marker', + 'volume-attachment-id', + '--limit', + '2', ] verifylist = [ ('project', self.project.name), @@ -534,8 +572,9 @@ class TestVolumeAttachmentList(TestVolumeAttachment): self.assertCountEqual(tuple(self.data), data) def test_volume_attachment_list_pre_v327(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.26') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.26' + ) arglist = [] verifylist = [ @@ -549,9 +588,8 @@ class TestVolumeAttachmentList(TestVolumeAttachment): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.27 or greater is required', - str(exc)) + '--os-volume-api-version 3.27 or greater is required', str(exc) + ) diff --git a/openstackclient/tests/unit/volume/v3/test_volume_group.py b/openstackclient/tests/unit/volume/v3/test_volume_group.py index 78717de8..e79eefb5 100644 --- a/openstackclient/tests/unit/volume/v3/test_volume_group.py +++ b/openstackclient/tests/unit/volume/v3/test_volume_group.py @@ -21,27 +21,27 @@ from openstackclient.volume.v3 import volume_group class TestVolumeGroup(volume_fakes.TestVolume): - def setUp(self): super().setUp() self.volume_groups_mock = self.app.client_manager.volume.groups self.volume_groups_mock.reset_mock() - self.volume_group_types_mock = \ + self.volume_group_types_mock = ( self.app.client_manager.volume.group_types + ) self.volume_group_types_mock.reset_mock() self.volume_types_mock = self.app.client_manager.volume.volume_types self.volume_types_mock.reset_mock() - self.volume_group_snapshots_mock = \ + self.volume_group_snapshots_mock = ( self.app.client_manager.volume.group_snapshots + ) self.volume_group_snapshots_mock.reset_mock() class TestVolumeGroupCreate(TestVolumeGroup): - fake_volume_type = volume_fakes.create_one_volume_type() fake_volume_group_type = volume_fakes.create_one_volume_group_type() fake_volume_group = volume_fakes.create_one_volume_group( @@ -50,8 +50,9 @@ class TestVolumeGroupCreate(TestVolumeGroup): 'volume_types': [fake_volume_type.id], }, ) - fake_volume_group_snapshot = \ + fake_volume_group_snapshot = ( volume_fakes.create_one_volume_group_snapshot() + ) columns = ( 'ID', @@ -84,24 +85,30 @@ class TestVolumeGroupCreate(TestVolumeGroup): super().setUp() self.volume_types_mock.get.return_value = self.fake_volume_type - self.volume_group_types_mock.get.return_value = \ + self.volume_group_types_mock.get.return_value = ( self.fake_volume_group_type + ) self.volume_groups_mock.create.return_value = self.fake_volume_group self.volume_groups_mock.get.return_value = self.fake_volume_group - self.volume_groups_mock.create_from_src.return_value = \ + self.volume_groups_mock.create_from_src.return_value = ( self.fake_volume_group - self.volume_group_snapshots_mock.get.return_value = \ + ) + self.volume_group_snapshots_mock.get.return_value = ( self.fake_volume_group_snapshot + ) self.cmd = volume_group.CreateVolumeGroup(self.app, None) def test_volume_group_create(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.13') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.13' + ) arglist = [ - '--volume-group-type', self.fake_volume_group_type.id, - '--volume-type', self.fake_volume_type.id, + '--volume-group-type', + self.fake_volume_group_type.id, + '--volume-type', + self.fake_volume_type.id, ] verifylist = [ ('volume_group_type', self.fake_volume_group_type.id), @@ -115,9 +122,11 @@ class TestVolumeGroupCreate(TestVolumeGroup): columns, data = self.cmd.take_action(parsed_args) self.volume_group_types_mock.get.assert_called_once_with( - self.fake_volume_group_type.id) + self.fake_volume_group_type.id + ) self.volume_types_mock.get.assert_called_once_with( - self.fake_volume_type.id) + self.fake_volume_type.id + ) self.volume_groups_mock.create.assert_called_once_with( self.fake_volume_group_type.id, self.fake_volume_type.id, @@ -129,8 +138,9 @@ class TestVolumeGroupCreate(TestVolumeGroup): self.assertCountEqual(self.data, data) def test_volume_group_create__legacy(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.13') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.13' + ) arglist = [ self.fake_volume_group_type.id, @@ -149,9 +159,11 @@ class TestVolumeGroupCreate(TestVolumeGroup): columns, data = self.cmd.take_action(parsed_args) self.volume_group_types_mock.get.assert_called_once_with( - self.fake_volume_group_type.id) + self.fake_volume_group_type.id + ) self.volume_types_mock.get.assert_called_once_with( - self.fake_volume_type.id) + self.fake_volume_type.id + ) self.volume_groups_mock.create.assert_called_once_with( self.fake_volume_group_type.id, self.fake_volume_type.id, @@ -168,11 +180,13 @@ class TestVolumeGroupCreate(TestVolumeGroup): ) def test_volume_group_create_no_volume_type(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.13') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.13' + ) arglist = [ - '--volume-group-type', self.fake_volume_group_type.id, + '--volume-group-type', + self.fake_volume_group_type.id, ] verifylist = [ ('volume_group_type', self.fake_volume_group_type.id), @@ -183,23 +197,28 @@ class TestVolumeGroupCreate(TestVolumeGroup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--volume-types is a required argument when creating ', - str(exc)) + '--volume-types is a required argument when creating ', str(exc) + ) def test_volume_group_create_with_options(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.13') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.13' + ) arglist = [ - '--volume-group-type', self.fake_volume_group_type.id, - '--volume-type', self.fake_volume_type.id, - '--name', 'foo', - '--description', 'hello, world', - '--availability-zone', 'bar', + '--volume-group-type', + self.fake_volume_group_type.id, + '--volume-type', + self.fake_volume_type.id, + '--name', + 'foo', + '--description', + 'hello, world', + '--availability-zone', + 'bar', ] verifylist = [ ('volume_group_type', self.fake_volume_group_type.id), @@ -213,9 +232,11 @@ class TestVolumeGroupCreate(TestVolumeGroup): columns, data = self.cmd.take_action(parsed_args) self.volume_group_types_mock.get.assert_called_once_with( - self.fake_volume_group_type.id) + self.fake_volume_group_type.id + ) self.volume_types_mock.get.assert_called_once_with( - self.fake_volume_type.id) + self.fake_volume_type.id + ) self.volume_groups_mock.create.assert_called_once_with( self.fake_volume_group_type.id, self.fake_volume_type.id, @@ -227,12 +248,15 @@ class TestVolumeGroupCreate(TestVolumeGroup): self.assertCountEqual(self.data, data) def test_volume_group_create_pre_v313(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.12') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.12' + ) arglist = [ - '--volume-group-type', self.fake_volume_group_type.id, - '--volume-type', self.fake_volume_type.id, + '--volume-group-type', + self.fake_volume_group_type.id, + '--volume-type', + self.fake_volume_type.id, ] verifylist = [ ('volume_group_type', self.fake_volume_group_type.id), @@ -244,19 +268,20 @@ class TestVolumeGroupCreate(TestVolumeGroup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.13 or greater is required', - str(exc)) + '--os-volume-api-version 3.13 or greater is required', str(exc) + ) def test_volume_group_create_from_source_group(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.14') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.14' + ) arglist = [ - '--source-group', self.fake_volume_group.id, + '--source-group', + self.fake_volume_group.id, ] verifylist = [ ('source_group', self.fake_volume_group.id), @@ -266,8 +291,11 @@ class TestVolumeGroupCreate(TestVolumeGroup): columns, data = self.cmd.take_action(parsed_args) self.volume_groups_mock.get.assert_has_calls( - [mock.call(self.fake_volume_group.id), - mock.call(self.fake_volume_group.id)]) + [ + mock.call(self.fake_volume_group.id), + mock.call(self.fake_volume_group.id), + ] + ) self.volume_groups_mock.create_from_src.assert_called_once_with( None, self.fake_volume_group.id, @@ -278,11 +306,13 @@ class TestVolumeGroupCreate(TestVolumeGroup): self.assertCountEqual(self.data, data) def test_volume_group_create_from_group_snapshot(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.14') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.14' + ) arglist = [ - '--group-snapshot', self.fake_volume_group_snapshot.id, + '--group-snapshot', + self.fake_volume_group_snapshot.id, ] verifylist = [ ('group_snapshot', self.fake_volume_group_snapshot.id), @@ -292,9 +322,11 @@ class TestVolumeGroupCreate(TestVolumeGroup): columns, data = self.cmd.take_action(parsed_args) self.volume_group_snapshots_mock.get.assert_called_once_with( - self.fake_volume_group_snapshot.id) + self.fake_volume_group_snapshot.id + ) self.volume_groups_mock.get.assert_called_once_with( - self.fake_volume_group.id) + self.fake_volume_group.id + ) self.volume_groups_mock.create_from_src.assert_called_once_with( self.fake_volume_group_snapshot.id, None, @@ -305,11 +337,13 @@ class TestVolumeGroupCreate(TestVolumeGroup): self.assertCountEqual(self.data, data) def test_volume_group_create_from_src_pre_v314(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.13') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.13' + ) arglist = [ - '--source-group', self.fake_volume_group.id, + '--source-group', + self.fake_volume_group.id, ] verifylist = [ ('source_group', self.fake_volume_group.id), @@ -317,38 +351,42 @@ class TestVolumeGroupCreate(TestVolumeGroup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.14 or greater is required', - str(exc)) + '--os-volume-api-version 3.14 or greater is required', str(exc) + ) def test_volume_group_create_from_src_source_group_group_snapshot(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.14') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.14' + ) arglist = [ - '--source-group', self.fake_volume_group.id, - '--group-snapshot', self.fake_volume_group_snapshot.id, + '--source-group', + self.fake_volume_group.id, + '--group-snapshot', + self.fake_volume_group_snapshot.id, ] verifylist = [ ('source_group', self.fake_volume_group.id), ('group_snapshot', self.fake_volume_group_snapshot.id), ] - exc = self.assertRaises(tests_utils.ParserException, - self.check_parser, - self.cmd, - arglist, - verifylist) + exc = self.assertRaises( + tests_utils.ParserException, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) self.assertIn( '--group-snapshot: not allowed with argument --source-group', - str(exc)) + str(exc), + ) class TestVolumeGroupDelete(TestVolumeGroup): - fake_volume_group = volume_fakes.create_one_volume_group() def setUp(self): @@ -360,8 +398,9 @@ class TestVolumeGroupDelete(TestVolumeGroup): self.cmd = volume_group.DeleteVolumeGroup(self.app, None) def test_volume_group_delete(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.13') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.13' + ) arglist = [ self.fake_volume_group.id, @@ -376,13 +415,15 @@ class TestVolumeGroupDelete(TestVolumeGroup): result = self.cmd.take_action(parsed_args) self.volume_groups_mock.delete.assert_called_once_with( - self.fake_volume_group.id, delete_volumes=True, + self.fake_volume_group.id, + delete_volumes=True, ) self.assertIsNone(result) def test_volume_group_delete_pre_v313(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.12') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.12' + ) arglist = [ self.fake_volume_group.id, @@ -394,16 +435,14 @@ class TestVolumeGroupDelete(TestVolumeGroup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.13 or greater is required', - str(exc)) + '--os-volume-api-version 3.13 or greater is required', str(exc) + ) class TestVolumeGroupSet(TestVolumeGroup): - fake_volume_group = volume_fakes.create_one_volume_group() columns = ( @@ -442,13 +481,16 @@ class TestVolumeGroupSet(TestVolumeGroup): self.cmd = volume_group.SetVolumeGroup(self.app, None) def test_volume_group_set(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.13') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.13' + ) arglist = [ self.fake_volume_group.id, - '--name', 'foo', - '--description', 'hello, world', + '--name', + 'foo', + '--description', + 'hello, world', ] verifylist = [ ('group', self.fake_volume_group.id), @@ -460,14 +502,17 @@ class TestVolumeGroupSet(TestVolumeGroup): columns, data = self.cmd.take_action(parsed_args) self.volume_groups_mock.update.assert_called_once_with( - self.fake_volume_group.id, name='foo', description='hello, world', + self.fake_volume_group.id, + name='foo', + description='hello, world', ) self.assertEqual(self.columns, columns) self.assertCountEqual(self.data, data) def test_volume_group_with_enable_replication_option(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.38') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.38' + ) arglist = [ self.fake_volume_group.id, @@ -482,18 +527,22 @@ class TestVolumeGroupSet(TestVolumeGroup): columns, data = self.cmd.take_action(parsed_args) self.volume_groups_mock.enable_replication.assert_called_once_with( - self.fake_volume_group.id) + self.fake_volume_group.id + ) self.assertEqual(self.columns, columns) self.assertCountEqual(self.data, data) def test_volume_group_set_pre_v313(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.12') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.12' + ) arglist = [ self.fake_volume_group.id, - '--name', 'foo', - '--description', 'hello, world', + '--name', + 'foo', + '--description', + 'hello, world', ] verifylist = [ ('group', self.fake_volume_group.id), @@ -503,16 +552,16 @@ class TestVolumeGroupSet(TestVolumeGroup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.13 or greater is required', - str(exc)) + '--os-volume-api-version 3.13 or greater is required', str(exc) + ) def test_volume_group_with_enable_replication_option_pre_v338(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.37') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.37' + ) arglist = [ self.fake_volume_group.id, @@ -525,16 +574,14 @@ class TestVolumeGroupSet(TestVolumeGroup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.38 or greater is required', - str(exc)) + '--os-volume-api-version 3.38 or greater is required', str(exc) + ) class TestVolumeGroupList(TestVolumeGroup): - fake_volume_groups = volume_fakes.create_volume_groups() columns = ( @@ -547,7 +594,8 @@ class TestVolumeGroupList(TestVolumeGroup): fake_volume_group.id, fake_volume_group.status, fake_volume_group.name, - ) for fake_volume_group in fake_volume_groups + ) + for fake_volume_group in fake_volume_groups ] def setUp(self): @@ -558,8 +606,9 @@ class TestVolumeGroupList(TestVolumeGroup): self.cmd = volume_group.ListVolumeGroup(self.app, None) def test_volume_group_list(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.13') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.13' + ) arglist = [ '--all-projects', @@ -580,8 +629,9 @@ class TestVolumeGroupList(TestVolumeGroup): self.assertCountEqual(tuple(self.data), data) def test_volume_group_list_pre_v313(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.12') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.12' + ) arglist = [ '--all-projects', @@ -592,16 +642,14 @@ class TestVolumeGroupList(TestVolumeGroup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.13 or greater is required', - str(exc)) + '--os-volume-api-version 3.13 or greater is required', str(exc) + ) class TestVolumeGroupFailover(TestVolumeGroup): - fake_volume_group = volume_fakes.create_one_volume_group() def setUp(self): @@ -613,13 +661,15 @@ class TestVolumeGroupFailover(TestVolumeGroup): self.cmd = volume_group.FailoverVolumeGroup(self.app, None) def test_volume_group_failover(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.38') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.38' + ) arglist = [ self.fake_volume_group.id, '--allow-attached-volume', - '--secondary-backend-id', 'foo', + '--secondary-backend-id', + 'foo', ] verifylist = [ ('group', self.fake_volume_group.id), @@ -638,13 +688,15 @@ class TestVolumeGroupFailover(TestVolumeGroup): self.assertIsNone(result) def test_volume_group_failover_pre_v338(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.37') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.37' + ) arglist = [ self.fake_volume_group.id, '--allow-attached-volume', - '--secondary-backend-id', 'foo', + '--secondary-backend-id', + 'foo', ] verifylist = [ ('group', self.fake_volume_group.id), @@ -654,9 +706,8 @@ class TestVolumeGroupFailover(TestVolumeGroup): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.38 or greater is required', - str(exc)) + '--os-volume-api-version 3.38 or greater is required', str(exc) + ) diff --git a/openstackclient/tests/unit/volume/v3/test_volume_group_snapshot.py b/openstackclient/tests/unit/volume/v3/test_volume_group_snapshot.py index 2a5a30f0..664e56e6 100644 --- a/openstackclient/tests/unit/volume/v3/test_volume_group_snapshot.py +++ b/openstackclient/tests/unit/volume/v3/test_volume_group_snapshot.py @@ -18,23 +18,23 @@ from openstackclient.volume.v3 import volume_group_snapshot class TestVolumeGroupSnapshot(volume_fakes.TestVolume): - def setUp(self): super().setUp() self.volume_groups_mock = self.app.client_manager.volume.groups self.volume_groups_mock.reset_mock() - self.volume_group_snapshots_mock = \ + self.volume_group_snapshots_mock = ( self.app.client_manager.volume.group_snapshots + ) self.volume_group_snapshots_mock.reset_mock() class TestVolumeGroupSnapshotCreate(TestVolumeGroupSnapshot): - fake_volume_group = volume_fakes.create_one_volume_group() - fake_volume_group_snapshot = \ + fake_volume_group_snapshot = ( volume_fakes.create_one_volume_group_snapshot() + ) columns = ( 'ID', @@ -57,17 +57,21 @@ class TestVolumeGroupSnapshotCreate(TestVolumeGroupSnapshot): super().setUp() self.volume_groups_mock.get.return_value = self.fake_volume_group - self.volume_group_snapshots_mock.create.return_value = \ + self.volume_group_snapshots_mock.create.return_value = ( self.fake_volume_group_snapshot - self.volume_group_snapshots_mock.get.return_value = \ + ) + self.volume_group_snapshots_mock.get.return_value = ( self.fake_volume_group_snapshot + ) self.cmd = volume_group_snapshot.CreateVolumeGroupSnapshot( - self.app, None) + self.app, None + ) def test_volume_group_snapshot_create(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.14') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.14' + ) arglist = [ self.fake_volume_group.id, @@ -82,21 +86,27 @@ class TestVolumeGroupSnapshotCreate(TestVolumeGroupSnapshot): columns, data = self.cmd.take_action(parsed_args) self.volume_groups_mock.get.assert_called_once_with( - self.fake_volume_group.id) + self.fake_volume_group.id + ) self.volume_group_snapshots_mock.create.assert_called_once_with( - self.fake_volume_group.id, None, None, + self.fake_volume_group.id, + None, + None, ) self.assertEqual(self.columns, columns) self.assertCountEqual(self.data, data) def test_volume_group_snapshot_create_with_options(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.14') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.14' + ) arglist = [ self.fake_volume_group.id, - '--name', 'foo', - '--description', 'hello, world', + '--name', + 'foo', + '--description', + 'hello, world', ] verifylist = [ ('volume_group', self.fake_volume_group.id), @@ -108,16 +118,20 @@ class TestVolumeGroupSnapshotCreate(TestVolumeGroupSnapshot): columns, data = self.cmd.take_action(parsed_args) self.volume_groups_mock.get.assert_called_once_with( - self.fake_volume_group.id) + self.fake_volume_group.id + ) self.volume_group_snapshots_mock.create.assert_called_once_with( - self.fake_volume_group.id, 'foo', 'hello, world', + self.fake_volume_group.id, + 'foo', + 'hello, world', ) self.assertEqual(self.columns, columns) self.assertCountEqual(self.data, data) def test_volume_group_snapshot_create_pre_v314(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.13') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.13' + ) arglist = [ self.fake_volume_group.id, @@ -130,32 +144,34 @@ class TestVolumeGroupSnapshotCreate(TestVolumeGroupSnapshot): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.14 or greater is required', - str(exc)) + '--os-volume-api-version 3.14 or greater is required', str(exc) + ) class TestVolumeGroupSnapshotDelete(TestVolumeGroupSnapshot): - - fake_volume_group_snapshot = \ + fake_volume_group_snapshot = ( volume_fakes.create_one_volume_group_snapshot() + ) def setUp(self): super().setUp() - self.volume_group_snapshots_mock.get.return_value = \ + self.volume_group_snapshots_mock.get.return_value = ( self.fake_volume_group_snapshot + ) self.volume_group_snapshots_mock.delete.return_value = None self.cmd = volume_group_snapshot.DeleteVolumeGroupSnapshot( - self.app, None) + self.app, None + ) def test_volume_group_snapshot_delete(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.14') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.14' + ) arglist = [ self.fake_volume_group_snapshot.id, @@ -173,8 +189,9 @@ class TestVolumeGroupSnapshotDelete(TestVolumeGroupSnapshot): self.assertIsNone(result) def test_volume_group_snapshot_delete_pre_v314(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.13') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.13' + ) arglist = [ self.fake_volume_group_snapshot.id, @@ -185,16 +202,14 @@ class TestVolumeGroupSnapshotDelete(TestVolumeGroupSnapshot): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.14 or greater is required', - str(exc)) + '--os-volume-api-version 3.14 or greater is required', str(exc) + ) class TestVolumeGroupSnapshotList(TestVolumeGroupSnapshot): - fake_volume_group_snapshots = volume_fakes.create_volume_group_snapshots() columns = ( @@ -207,21 +222,25 @@ class TestVolumeGroupSnapshotList(TestVolumeGroupSnapshot): fake_volume_group_snapshot.id, fake_volume_group_snapshot.status, fake_volume_group_snapshot.name, - ) for fake_volume_group_snapshot in fake_volume_group_snapshots + ) + for fake_volume_group_snapshot in fake_volume_group_snapshots ] def setUp(self): super().setUp() - self.volume_group_snapshots_mock.list.return_value = \ + self.volume_group_snapshots_mock.list.return_value = ( self.fake_volume_group_snapshots + ) self.cmd = volume_group_snapshot.ListVolumeGroupSnapshot( - self.app, None) + self.app, None + ) def test_volume_group_snapshot_list(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.14') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.14' + ) arglist = [ '--all-projects', @@ -242,20 +261,19 @@ class TestVolumeGroupSnapshotList(TestVolumeGroupSnapshot): self.assertCountEqual(tuple(self.data), data) def test_volume_group_snapshot_list_pre_v314(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.13') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.13' + ) - arglist = [ - ] + arglist = [] verifylist = [ ('all_projects', False), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.14 or greater is required', - str(exc)) + '--os-volume-api-version 3.14 or greater is required', str(exc) + ) diff --git a/openstackclient/tests/unit/volume/v3/test_volume_group_type.py b/openstackclient/tests/unit/volume/v3/test_volume_group_type.py index 34b4e501..7ea2a2da 100644 --- a/openstackclient/tests/unit/volume/v3/test_volume_group_type.py +++ b/openstackclient/tests/unit/volume/v3/test_volume_group_type.py @@ -21,17 +21,16 @@ from openstackclient.volume.v3 import volume_group_type class TestVolumeGroupType(volume_fakes.TestVolume): - def setUp(self): super().setUp() - self.volume_group_types_mock = \ + self.volume_group_types_mock = ( self.app.client_manager.volume.group_types + ) self.volume_group_types_mock.reset_mock() class TestVolumeGroupTypeCreate(TestVolumeGroupType): - maxDiff = 2000 fake_volume_group_type = volume_fakes.create_one_volume_group_type() @@ -54,14 +53,16 @@ class TestVolumeGroupTypeCreate(TestVolumeGroupType): def setUp(self): super().setUp() - self.volume_group_types_mock.create.return_value = \ + self.volume_group_types_mock.create.return_value = ( self.fake_volume_group_type + ) self.cmd = volume_group_type.CreateVolumeGroupType(self.app, None) def test_volume_group_type_create(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.11') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.11' + ) arglist = [ self.fake_volume_group_type.name, @@ -76,19 +77,20 @@ class TestVolumeGroupTypeCreate(TestVolumeGroupType): columns, data = self.cmd.take_action(parsed_args) self.volume_group_types_mock.create.assert_called_once_with( - self.fake_volume_group_type.name, - None, - True) + self.fake_volume_group_type.name, None, True + ) self.assertEqual(self.columns, columns) self.assertCountEqual(self.data, data) def test_volume_group_type_create_with_options(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.11') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.11' + ) arglist = [ self.fake_volume_group_type.name, - '--description', 'foo', + '--description', + 'foo', '--private', ] verifylist = [ @@ -101,15 +103,15 @@ class TestVolumeGroupTypeCreate(TestVolumeGroupType): columns, data = self.cmd.take_action(parsed_args) self.volume_group_types_mock.create.assert_called_once_with( - self.fake_volume_group_type.name, - 'foo', - False) + self.fake_volume_group_type.name, 'foo', False + ) self.assertEqual(self.columns, columns) self.assertCountEqual(self.data, data) def test_volume_group_type_create_pre_v311(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.10') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.10' + ) arglist = [ self.fake_volume_group_type.name, @@ -122,30 +124,30 @@ class TestVolumeGroupTypeCreate(TestVolumeGroupType): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.11 or greater is required', - str(exc)) + '--os-volume-api-version 3.11 or greater is required', str(exc) + ) class TestVolumeGroupTypeDelete(TestVolumeGroupType): - fake_volume_group_type = volume_fakes.create_one_volume_group_type() def setUp(self): super().setUp() - self.volume_group_types_mock.get.return_value = \ + self.volume_group_types_mock.get.return_value = ( self.fake_volume_group_type + ) self.volume_group_types_mock.delete.return_value = None self.cmd = volume_group_type.DeleteVolumeGroupType(self.app, None) def test_volume_group_type_delete(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.11') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.11' + ) arglist = [ self.fake_volume_group_type.id, @@ -163,8 +165,9 @@ class TestVolumeGroupTypeDelete(TestVolumeGroupType): self.assertIsNone(result) def test_volume_group_type_delete_pre_v311(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.10') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.10' + ) arglist = [ self.fake_volume_group_type.id, @@ -175,16 +178,14 @@ class TestVolumeGroupTypeDelete(TestVolumeGroupType): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.11 or greater is required', - str(exc)) + '--os-volume-api-version 3.11 or greater is required', str(exc) + ) class TestVolumeGroupTypeSet(TestVolumeGroupType): - fake_volume_group_type = volume_fakes.create_one_volume_group_type( methods={ 'get_keys': {'foo': 'bar'}, @@ -211,25 +212,31 @@ class TestVolumeGroupTypeSet(TestVolumeGroupType): def setUp(self): super().setUp() - self.volume_group_types_mock.get.return_value = \ + self.volume_group_types_mock.get.return_value = ( self.fake_volume_group_type - self.volume_group_types_mock.update.return_value = \ + ) + self.volume_group_types_mock.update.return_value = ( self.fake_volume_group_type + ) self.cmd = volume_group_type.SetVolumeGroupType(self.app, None) def test_volume_group_type_set(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.11') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.11' + ) self.fake_volume_group_type.set_keys.return_value = None arglist = [ self.fake_volume_group_type.id, - '--name', 'foo', - '--description', 'hello, world', + '--name', + 'foo', + '--description', + 'hello, world', '--public', - '--property', 'fizz=buzz', + '--property', + 'fizz=buzz', ] verifylist = [ ('group_type', self.fake_volume_group_type.id), @@ -256,13 +263,15 @@ class TestVolumeGroupTypeSet(TestVolumeGroupType): self.assertCountEqual(self.data, data) def test_volume_group_type_with_no_property_option(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.11') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.11' + ) arglist = [ self.fake_volume_group_type.id, '--no-property', - '--property', 'fizz=buzz', + '--property', + 'fizz=buzz', ] verifylist = [ ('group_type', self.fake_volume_group_type.id), @@ -277,21 +286,26 @@ class TestVolumeGroupTypeSet(TestVolumeGroupType): columns, data = self.cmd.take_action(parsed_args) self.volume_group_types_mock.get.assert_called_once_with( - self.fake_volume_group_type.id) + self.fake_volume_group_type.id + ) self.fake_volume_group_type.get_keys.assert_called_once_with() self.fake_volume_group_type.unset_keys.assert_called_once_with( - {'foo': 'bar'}.keys()) + {'foo': 'bar'}.keys() + ) self.assertEqual(self.columns, columns) self.assertCountEqual(self.data, data) def test_volume_group_type_set_pre_v311(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.10') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.10' + ) arglist = [ self.fake_volume_group_type.id, - '--name', 'foo', - '--description', 'hello, world', + '--name', + 'foo', + '--description', + 'hello, world', ] verifylist = [ ('group_type', self.fake_volume_group_type.id), @@ -304,16 +318,14 @@ class TestVolumeGroupTypeSet(TestVolumeGroupType): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.11 or greater is required', - str(exc)) + '--os-volume-api-version 3.11 or greater is required', str(exc) + ) class TestVolumeGroupTypeUnset(TestVolumeGroupType): - fake_volume_group_type = volume_fakes.create_one_volume_group_type( methods={'unset_keys': None}, ) @@ -336,18 +348,21 @@ class TestVolumeGroupTypeUnset(TestVolumeGroupType): def setUp(self): super().setUp() - self.volume_group_types_mock.get.return_value = \ + self.volume_group_types_mock.get.return_value = ( self.fake_volume_group_type + ) self.cmd = volume_group_type.UnsetVolumeGroupType(self.app, None) def test_volume_group_type_unset(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.11') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.11' + ) arglist = [ self.fake_volume_group_type.id, - '--property', 'fizz', + '--property', + 'fizz', ] verifylist = [ ('group_type', self.fake_volume_group_type.id), @@ -357,22 +372,27 @@ class TestVolumeGroupTypeUnset(TestVolumeGroupType): columns, data = self.cmd.take_action(parsed_args) - self.volume_group_types_mock.get.assert_has_calls([ - mock.call(self.fake_volume_group_type.id), - mock.call(self.fake_volume_group_type.id), - ]) + self.volume_group_types_mock.get.assert_has_calls( + [ + mock.call(self.fake_volume_group_type.id), + mock.call(self.fake_volume_group_type.id), + ] + ) self.fake_volume_group_type.unset_keys.assert_called_once_with( - ['fizz']) + ['fizz'] + ) self.assertEqual(self.columns, columns) self.assertCountEqual(self.data, data) def test_volume_group_type_unset_pre_v311(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.10') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.10' + ) arglist = [ self.fake_volume_group_type.id, - '--property', 'fizz', + '--property', + 'fizz', ] verifylist = [ ('group_type', self.fake_volume_group_type.id), @@ -381,16 +401,14 @@ class TestVolumeGroupTypeUnset(TestVolumeGroupType): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.11 or greater is required', - str(exc)) + '--os-volume-api-version 3.11 or greater is required', str(exc) + ) class TestVolumeGroupTypeList(TestVolumeGroupType): - fake_volume_group_types = volume_fakes.create_volume_group_types() columns = ( @@ -405,25 +423,28 @@ class TestVolumeGroupTypeList(TestVolumeGroupType): fake_volume_group_type.name, fake_volume_group_type.is_public, fake_volume_group_type.group_specs, - ) for fake_volume_group_type in fake_volume_group_types + ) + for fake_volume_group_type in fake_volume_group_types ] def setUp(self): super().setUp() - self.volume_group_types_mock.list.return_value = \ + self.volume_group_types_mock.list.return_value = ( self.fake_volume_group_types - self.volume_group_types_mock.default.return_value = \ + ) + self.volume_group_types_mock.default.return_value = ( self.fake_volume_group_types[0] + ) self.cmd = volume_group_type.ListVolumeGroupType(self.app, None) def test_volume_group_type_list(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.11') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.11' + ) - arglist = [ - ] + arglist = [] verifylist = [ ('show_default', False), ] @@ -436,8 +457,9 @@ class TestVolumeGroupTypeList(TestVolumeGroupType): self.assertCountEqual(tuple(self.data), data) def test_volume_group_type_list_with_default_option(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.11') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.11' + ) arglist = [ '--default', @@ -454,19 +476,17 @@ class TestVolumeGroupTypeList(TestVolumeGroupType): self.assertCountEqual(tuple([self.data[0]]), data) def test_volume_group_type_list_pre_v311(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.10') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.10' + ) - arglist = [ - ] - verifylist = [ - ] + arglist = [] + verifylist = [] parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.11 or greater is required', - str(exc)) + '--os-volume-api-version 3.11 or greater is required', str(exc) + ) diff --git a/openstackclient/tests/unit/volume/v3/test_volume_message.py b/openstackclient/tests/unit/volume/v3/test_volume_message.py index 45b0747e..652deb64 100644 --- a/openstackclient/tests/unit/volume/v3/test_volume_message.py +++ b/openstackclient/tests/unit/volume/v3/test_volume_message.py @@ -21,7 +21,6 @@ from openstackclient.volume.v3 import volume_message class TestVolumeMessage(volume_fakes.TestVolume): - def setUp(self): super().setUp() @@ -33,7 +32,6 @@ class TestVolumeMessage(volume_fakes.TestVolume): class TestVolumeMessageDelete(TestVolumeMessage): - fake_messages = volume_fakes.create_volume_messages(count=2) def setUp(self): @@ -48,8 +46,9 @@ class TestVolumeMessageDelete(TestVolumeMessage): self.cmd = volume_message.DeleteMessage(self.app, None) def test_message_delete(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.3') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.3' + ) arglist = [ self.fake_messages[0].id, @@ -62,12 +61,14 @@ class TestVolumeMessageDelete(TestVolumeMessage): result = self.cmd.take_action(parsed_args) self.volume_messages_mock.delete.assert_called_with( - self.fake_messages[0].id) + self.fake_messages[0].id + ) self.assertIsNone(result) def test_message_delete_multiple_messages(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.3') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.3' + ) arglist = [ self.fake_messages[0].id, @@ -87,8 +88,9 @@ class TestVolumeMessageDelete(TestVolumeMessage): self.assertIsNone(result) def test_message_delete_multiple_messages_with_exception(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.3') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.3' + ) arglist = [ self.fake_messages[0].id, @@ -101,22 +103,26 @@ class TestVolumeMessageDelete(TestVolumeMessage): parsed_args = self.check_parser(self.cmd, arglist, verifylist) self.volume_messages_mock.delete.side_effect = [ - self.fake_messages[0], exceptions.CommandError] + self.fake_messages[0], + exceptions.CommandError, + ] exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertEqual('Failed to delete 1 of 2 messages.', str(exc)) self.volume_messages_mock.delete.assert_any_call( - self.fake_messages[0].id) + self.fake_messages[0].id + ) self.volume_messages_mock.delete.assert_any_call('invalid_message') self.assertEqual(2, self.volume_messages_mock.delete.call_count) def test_message_delete_pre_v33(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.2') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.2' + ) arglist = [ self.fake_messages[0].id, @@ -127,16 +133,14 @@ class TestVolumeMessageDelete(TestVolumeMessage): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.3 or greater is required', - str(exc)) + '--os-volume-api-version 3.3 or greater is required', str(exc) + ) class TestVolumeMessageList(TestVolumeMessage): - fake_project = identity_fakes.FakeProject.create_one_project() fake_messages = volume_fakes.create_volume_messages(count=3) @@ -153,17 +157,19 @@ class TestVolumeMessageList(TestVolumeMessage): ) data = [] for fake_message in fake_messages: - data.append(( - fake_message.id, - fake_message.event_id, - fake_message.resource_type, - fake_message.resource_uuid, - fake_message.message_level, - fake_message.user_message, - fake_message.request_id, - fake_message.created_at, - fake_message.guaranteed_until, - )) + data.append( + ( + fake_message.id, + fake_message.event_id, + fake_message.resource_type, + fake_message.resource_uuid, + fake_message.message_level, + fake_message.user_message, + fake_message.request_id, + fake_message.created_at, + fake_message.guaranteed_until, + ) + ) def setUp(self): super().setUp() @@ -174,8 +180,9 @@ class TestVolumeMessageList(TestVolumeMessage): self.cmd = volume_message.ListMessages(self.app, None) def test_message_list(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.3') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.3' + ) arglist = [] verifylist = [ @@ -199,13 +206,17 @@ class TestVolumeMessageList(TestVolumeMessage): self.assertCountEqual(self.data, list(data)) def test_message_list_with_options(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.3') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.3' + ) arglist = [ - '--project', self.fake_project.name, - '--marker', self.fake_messages[0].id, - '--limit', '3', + '--project', + self.fake_project.name, + '--marker', + self.fake_messages[0].id, + '--limit', + '3', ] verifylist = [ ('project', self.fake_project.name), @@ -228,8 +239,9 @@ class TestVolumeMessageList(TestVolumeMessage): self.assertCountEqual(self.data, list(data)) def test_message_list_pre_v33(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.2') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.2' + ) arglist = [] verifylist = [ @@ -241,16 +253,14 @@ class TestVolumeMessageList(TestVolumeMessage): parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.3 or greater is required', - str(exc)) + '--os-volume-api-version 3.3 or greater is required', str(exc) + ) class TestVolumeMessageShow(TestVolumeMessage): - fake_message = volume_fakes.create_one_volume_message() columns = ( @@ -284,15 +294,12 @@ class TestVolumeMessageShow(TestVolumeMessage): self.cmd = volume_message.ShowMessage(self.app, None) def test_message_show(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.3') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.3' + ) - arglist = [ - self.fake_message.id - ] - verifylist = [ - ('message_id', self.fake_message.id) - ] + arglist = [self.fake_message.id] + verifylist = [('message_id', self.fake_message.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) @@ -302,21 +309,17 @@ class TestVolumeMessageShow(TestVolumeMessage): self.assertEqual(self.data, data) def test_message_show_pre_v33(self): - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.2') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.2' + ) - arglist = [ - self.fake_message.id - ] - verifylist = [ - ('message_id', self.fake_message.id) - ] + arglist = [self.fake_message.id] + verifylist = [('message_id', self.fake_message.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) exc = self.assertRaises( - exceptions.CommandError, - self.cmd.take_action, - parsed_args) + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn( - '--os-volume-api-version 3.3 or greater is required', - str(exc)) + '--os-volume-api-version 3.3 or greater is required', str(exc) + ) |