From 638e11ad76d60edbdcde9103229a70e31267eb1d Mon Sep 17 00:00:00 2001 From: allmightyspiff Date: Fri, 7 Jul 2017 18:20:43 -0500 Subject: [PATCH 1/5] issues826 added ability to change password of a storage allowed host --- SoftLayer/CLI/block/access/edit.py | 23 ++++++++++ SoftLayer/CLI/routes.py | 1 + SoftLayer/CLI/storage_utils.py | 10 +++++ .../SoftLayer_Network_Storage_Allowed_Host.py | 1 + SoftLayer/managers/block.py | 10 +++++ tests/CLI/modules/block_tests.py | 43 +++---------------- tests/CLI/modules/file_tests.py | 39 ----------------- tests/managers/block_tests.py | 7 +++ tests/managers/file_tests.py | 5 +-- 9 files changed, 58 insertions(+), 81 deletions(-) create mode 100644 SoftLayer/CLI/block/access/edit.py create mode 100644 SoftLayer/fixtures/SoftLayer_Network_Storage_Allowed_Host.py diff --git a/SoftLayer/CLI/block/access/edit.py b/SoftLayer/CLI/block/access/edit.py new file mode 100644 index 000000000..4811cc99f --- /dev/null +++ b/SoftLayer/CLI/block/access/edit.py @@ -0,0 +1,23 @@ +"""Modifies a password for a volume's access""" +# :license: MIT, see LICENSE for more details. + +import click +import SoftLayer +from SoftLayer.CLI import environment + + +@click.command() +@click.argument('access_id') +@click.option('--password', '-p', multiple=False, + help='Password you want to set, this command will fail if the password is not strong') +@environment.pass_env +def cli(env, access_id, password): + """Modifies a password for a volume's access""" + block_manager = SoftLayer.BlockStorageManager(env.client) + + result = block_manager.set_credential_password(access_id=access_id, password=password) + + if result: + click.echo('Password updated for %s' % access_id) + else: + click.echo('FAILED updating password for %s' % access_id) diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py index ae33226bc..d00d50afd 100644 --- a/SoftLayer/CLI/routes.py +++ b/SoftLayer/CLI/routes.py @@ -60,6 +60,7 @@ ('block:access-authorize', 'SoftLayer.CLI.block.access.authorize:cli'), ('block:access-list', 'SoftLayer.CLI.block.access.list:cli'), ('block:access-revoke', 'SoftLayer.CLI.block.access.revoke:cli'), + ('block:access-edit', 'SoftLayer.CLI.block.access.edit:cli'), ('block:replica-failback', 'SoftLayer.CLI.block.replication.failback:cli'), ('block:replica-failover', 'SoftLayer.CLI.block.replication.failover:cli'), ('block:replica-order', 'SoftLayer.CLI.block.replication.order:cli'), diff --git a/SoftLayer/CLI/storage_utils.py b/SoftLayer/CLI/storage_utils.py index dd00596bf..f70c2569f 100644 --- a/SoftLayer/CLI/storage_utils.py +++ b/SoftLayer/CLI/storage_utils.py @@ -75,6 +75,15 @@ def _format_name(obj): allowedHardware.allowedHost.credential.password allowedSubnets.allowedHost.credential.password allowedIpAddresses.allowedHost.credential.password +"""), + column_helper.Column( + 'allowed_host_id', + ('allowedHost', 'id',), + """ +allowedVirtualGuests.allowedHost.id +allowedHardware.allowedHost.id +allowedSubnets.allowedHost.id +allowedIpAddresses.allowedHost.id """), ] @@ -87,4 +96,5 @@ def _format_name(obj): 'host_iqn', 'username', 'password', + 'allowed_host_id', ] diff --git a/SoftLayer/fixtures/SoftLayer_Network_Storage_Allowed_Host.py b/SoftLayer/fixtures/SoftLayer_Network_Storage_Allowed_Host.py new file mode 100644 index 000000000..0582e04b6 --- /dev/null +++ b/SoftLayer/fixtures/SoftLayer_Network_Storage_Allowed_Host.py @@ -0,0 +1 @@ +setCredentialPassword = True diff --git a/SoftLayer/managers/block.py b/SoftLayer/managers/block.py index 6b2dc9d33..817232a4a 100644 --- a/SoftLayer/managers/block.py +++ b/SoftLayer/managers/block.py @@ -553,3 +553,13 @@ def failback_from_replicant(self, volume_id, replicant_id): return self.client.call('Network_Storage', 'failbackFromReplicant', replicant_id, id=volume_id) + + def set_credential_password(self, access_id, password): + """Sets the password for an access host + + :param integer access_id: id of the access host + :param string password: password to set + """ + + return self.client.call('Network_Storage_Allowed_Host', 'setCredentialPassword', + password, id=access_id) diff --git a/tests/CLI/modules/block_tests.py b/tests/CLI/modules/block_tests.py index 87641216e..c41d16b3b 100644 --- a/tests/CLI/modules/block_tests.py +++ b/tests/CLI/modules/block_tests.py @@ -16,44 +16,7 @@ def test_access_list(self): result = self.run_command(['block', 'access-list', '1234']) self.assert_no_fail(result) - self.assertEqual([ - { - 'username': 'joe', - 'name': 'test-server.example.com', - 'type': 'VIRTUAL', - 'host_iqn': 'test-server', - 'password': '12345', - 'private_ip_address': '10.0.0.1', - 'id': 1234, - }, - { - 'username': 'joe', - 'name': 'test-server.example.com', - 'type': 'HARDWARE', - 'host_iqn': 'test-server', - 'password': '12345', - 'private_ip_address': '10.0.0.2', - 'id': 1234, - }, - { - 'username': 'joe', - 'name': '10.0.0.1/24 (backend subnet)', - 'type': 'SUBNET', - 'host_iqn': 'test-server', - 'password': '12345', - 'private_ip_address': None, - 'id': 1234, - }, - { - 'username': 'joe', - 'name': '10.0.0.1 (backend ip)', - 'type': 'IP', - 'host_iqn': 'test-server', - 'password': '12345', - 'private_ip_address': None, - 'id': 1234, - }], - json.loads(result.output),) + self.assert_called_with('SoftLayer_Network_Storage', 'getObject') def test_volume_cancel(self): result = self.run_command([ @@ -511,3 +474,7 @@ def test_duplicate_order(self, order_mock): self.assertEqual(result.output, 'Order #24601 placed successfully!\n' ' > Storage as a Service\n') + + def test_set_password(self): + result = self.run_command(['block', 'access-edit', '1234', '--password=AAAAA']) + self.assert_no_fail(result) diff --git a/tests/CLI/modules/file_tests.py b/tests/CLI/modules/file_tests.py index 5d53210f9..4c96706c5 100644 --- a/tests/CLI/modules/file_tests.py +++ b/tests/CLI/modules/file_tests.py @@ -14,46 +14,7 @@ class FileTests(testing.TestCase): def test_access_list(self): result = self.run_command(['file', 'access-list', '1234']) - self.assert_no_fail(result) - self.assertEqual([ - { - 'username': 'joe', - 'name': 'test-server.example.com', - 'type': 'VIRTUAL', - 'host_iqn': 'test-server', - 'password': '12345', - 'private_ip_address': '10.0.0.1', - 'id': 1234, - }, - { - 'username': 'joe', - 'name': 'test-server.example.com', - 'type': 'HARDWARE', - 'host_iqn': 'test-server', - 'password': '12345', - 'private_ip_address': '10.0.0.2', - 'id': 1234, - }, - { - 'username': 'joe', - 'name': '10.0.0.1/24 (backend subnet)', - 'type': 'SUBNET', - 'host_iqn': 'test-server', - 'password': '12345', - 'private_ip_address': None, - 'id': 1234, - }, - { - 'username': 'joe', - 'name': '10.0.0.1 (backend ip)', - 'type': 'IP', - 'host_iqn': 'test-server', - 'password': '12345', - 'private_ip_address': None, - 'id': 1234, - }], - json.loads(result.output),) def test_authorize_host_to_volume(self): result = self.run_command(['file', 'access-authorize', '12345678', diff --git a/tests/managers/block_tests.py b/tests/managers/block_tests.py index 91909f52c..d58db5d16 100644 --- a/tests/managers/block_tests.py +++ b/tests/managers/block_tests.py @@ -1175,3 +1175,10 @@ def test_order_block_duplicate_endurance(self): 'osFormatType': {'keyName': 'LINUX'}, 'duplicateOriginSnapshotId': 470 },)) + + def test_setCredentialPassword(self): + mock = self.set_mock('SoftLayer_Network_Storage_Allowed_Host', 'setCredentialPassword') + mock.return_value = True + result = self.block.set_credential_password(access_id=102, password='AAAaaa') + self.assertEqual(True, result) + self.assert_called_with('SoftLayer_Network_Storage_Allowed_Host', 'setCredentialPassword') diff --git a/tests/managers/file_tests.py b/tests/managers/file_tests.py index ea313b3dc..b40460331 100644 --- a/tests/managers/file_tests.py +++ b/tests/managers/file_tests.py @@ -58,10 +58,7 @@ def test_deauthorize_host_to_volume(self): identifier=50) def test_get_file_volume_access_list(self): - result = self.file.get_file_volume_access_list(100) - - self.assertEqual(fixtures.SoftLayer_Network_Storage.getObject, result) - + self.file.get_file_volume_access_list(100) self.assert_called_with( 'SoftLayer_Network_Storage', 'getObject', From 4f549263d8a1f59b6092627c6ef27b9d40f6c2b7 Mon Sep 17 00:00:00 2001 From: allmightyspiff Date: Tue, 11 Jul 2017 17:07:49 -0500 Subject: [PATCH 2/5] changed acces-edit to access-password --- SoftLayer/CLI/block/access/{edit.py => password.py} | 2 +- SoftLayer/CLI/routes.py | 2 +- tests/CLI/modules/block_tests.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename SoftLayer/CLI/block/access/{edit.py => password.py} (89%) diff --git a/SoftLayer/CLI/block/access/edit.py b/SoftLayer/CLI/block/access/password.py similarity index 89% rename from SoftLayer/CLI/block/access/edit.py rename to SoftLayer/CLI/block/access/password.py index 4811cc99f..4463fb113 100644 --- a/SoftLayer/CLI/block/access/edit.py +++ b/SoftLayer/CLI/block/access/password.py @@ -7,7 +7,7 @@ @click.command() -@click.argument('access_id') +@click.argument('access_id', help="allowed_host_id for the password you want to change") @click.option('--password', '-p', multiple=False, help='Password you want to set, this command will fail if the password is not strong') @environment.pass_env diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py index d00d50afd..541c9d98e 100644 --- a/SoftLayer/CLI/routes.py +++ b/SoftLayer/CLI/routes.py @@ -60,7 +60,7 @@ ('block:access-authorize', 'SoftLayer.CLI.block.access.authorize:cli'), ('block:access-list', 'SoftLayer.CLI.block.access.list:cli'), ('block:access-revoke', 'SoftLayer.CLI.block.access.revoke:cli'), - ('block:access-edit', 'SoftLayer.CLI.block.access.edit:cli'), + ('block:access-password', 'SoftLayer.CLI.block.access.password:cli'), ('block:replica-failback', 'SoftLayer.CLI.block.replication.failback:cli'), ('block:replica-failover', 'SoftLayer.CLI.block.replication.failover:cli'), ('block:replica-order', 'SoftLayer.CLI.block.replication.order:cli'), diff --git a/tests/CLI/modules/block_tests.py b/tests/CLI/modules/block_tests.py index c41d16b3b..944acb847 100644 --- a/tests/CLI/modules/block_tests.py +++ b/tests/CLI/modules/block_tests.py @@ -476,5 +476,5 @@ def test_duplicate_order(self, order_mock): ' > Storage as a Service\n') def test_set_password(self): - result = self.run_command(['block', 'access-edit', '1234', '--password=AAAAA']) + result = self.run_command(['block', 'access-password', '1234', '--password=AAAAA']) self.assert_no_fail(result) From 67cfb70a7dd0b0ef785e1a7609971715d9cac688 Mon Sep 17 00:00:00 2001 From: allmightyspiff Date: Tue, 11 Jul 2017 17:12:46 -0500 Subject: [PATCH 3/5] fixed documentation --- SoftLayer/CLI/block/access/password.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SoftLayer/CLI/block/access/password.py b/SoftLayer/CLI/block/access/password.py index 4463fb113..b9080c10f 100644 --- a/SoftLayer/CLI/block/access/password.py +++ b/SoftLayer/CLI/block/access/password.py @@ -7,12 +7,12 @@ @click.command() -@click.argument('access_id', help="allowed_host_id for the password you want to change") +@click.argument('access_id', "") @click.option('--password', '-p', multiple=False, help='Password you want to set, this command will fail if the password is not strong') @environment.pass_env def cli(env, access_id, password): - """Modifies a password for a volume's access""" + """Modifies a password for a volume's access, requires the allowed_host_id for the password you want to change""" block_manager = SoftLayer.BlockStorageManager(env.client) result = block_manager.set_credential_password(access_id=access_id, password=password) From e61c34b95ec2b2901caa6bbc7ddd63a632cc47e9 Mon Sep 17 00:00:00 2001 From: allmightyspiff Date: Tue, 11 Jul 2017 17:13:17 -0500 Subject: [PATCH 4/5] fixed documentation --- SoftLayer/CLI/block/access/password.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SoftLayer/CLI/block/access/password.py b/SoftLayer/CLI/block/access/password.py index b9080c10f..458e55255 100644 --- a/SoftLayer/CLI/block/access/password.py +++ b/SoftLayer/CLI/block/access/password.py @@ -7,7 +7,7 @@ @click.command() -@click.argument('access_id', "") +@click.argument('access_id') @click.option('--password', '-p', multiple=False, help='Password you want to set, this command will fail if the password is not strong') @environment.pass_env From d8f0b8258844ca9affc261330ced46937ab926f2 Mon Sep 17 00:00:00 2001 From: allmightyspiff Date: Tue, 11 Jul 2017 17:32:24 -0500 Subject: [PATCH 5/5] conforming with pep standards --- SoftLayer/CLI/block/access/password.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/SoftLayer/CLI/block/access/password.py b/SoftLayer/CLI/block/access/password.py index 458e55255..1046f25d7 100644 --- a/SoftLayer/CLI/block/access/password.py +++ b/SoftLayer/CLI/block/access/password.py @@ -12,7 +12,11 @@ help='Password you want to set, this command will fail if the password is not strong') @environment.pass_env def cli(env, access_id, password): - """Modifies a password for a volume's access, requires the allowed_host_id for the password you want to change""" + """Changes a password for a volume's access. + + access id is the allowed_host_id from slcli block access-list + """ + block_manager = SoftLayer.BlockStorageManager(env.client) result = block_manager.set_credential_password(access_id=access_id, password=password)