From 3932c4e08675218a64f7bc9a4a9cc3f5a2f258bf Mon Sep 17 00:00:00 2001 From: Fernando Ojeda Date: Wed, 27 Jun 2018 15:18:40 -0400 Subject: [PATCH 1/4] Fixed hardware credentials issue. --- SoftLayer/CLI/hardware/credentials.py | 9 ++++- tests/CLI/modules/server_tests.py | 52 +++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/SoftLayer/CLI/hardware/credentials.py b/SoftLayer/CLI/hardware/credentials.py index 786510444..53069c74b 100644 --- a/SoftLayer/CLI/hardware/credentials.py +++ b/SoftLayer/CLI/hardware/credentials.py @@ -4,6 +4,7 @@ import click import SoftLayer +from SoftLayer import exceptions from SoftLayer.CLI import environment from SoftLayer.CLI import formatting from SoftLayer.CLI import helpers @@ -22,6 +23,12 @@ def cli(env, identifier): instance = manager.get_hardware(hardware_id) table = formatting.Table(['username', 'password']) + if 'passwords' not in instance['operatingSystem']: + raise exceptions.SoftLayerError("No passwords found in operatingSystem") + for item in instance['operatingSystem']['passwords']: - table.add_row([item['username'], item['password']]) + if 'password' not in item: + raise exceptions.SoftLayerError("No password found in operatingSystem passwords") + else: + table.add_row([item['username'], item['password']]) env.fout(table) diff --git a/tests/CLI/modules/server_tests.py b/tests/CLI/modules/server_tests.py index a97f20e0a..d384548fe 100644 --- a/tests/CLI/modules/server_tests.py +++ b/tests/CLI/modules/server_tests.py @@ -25,6 +25,58 @@ def test_server_cancel_reasons(self): output = json.loads(result.output) self.assert_no_fail(result) self.assertEqual(len(output), 10) + + def test_server_credentials(self): + result = self.run_command(['hardware', 'credentials', '12345']) + + self.assert_no_fail(result) + self.assertEqual(json.loads(result.output), + [{ + 'username': 'root', + 'password': 'abc123' + }]) + + def test_server_credentials_exception_passwords_not_found(self): + mock = self.set_mock('SoftLayer_Hardware_Server', 'getObject') + mock.return_value = { + "accountId": 11111, + "domain": "chechu.com", + "fullyQualifiedDomainName": "host3.vmware.chechu.com", + "hardwareStatusId": 5, + "hostname": "host3.vmware", + "id": 12345, + "operatingSystem": {} + } + + result = self.run_command(['hardware', 'credentials', '12345']) + + self.assertEqual( + 'No passwords found in operatingSystem', + str(result.exception) + ) + + def test_server_credentials_exception_password_not_found(self): + mock = self.set_mock('SoftLayer_Hardware_Server', 'getObject') + mock.return_value = { + "accountId": 11111, + "domain": "chechu.com", + "fullyQualifiedDomainName": "host3.vmware.chechu.com", + "hardwareStatusId": 5, + "hostname": "host3.vmware", + "id": 12345, + "operatingSystem": { + "hardwareId": 22222, + "id": 333333, + "passwords": [{}] + } + } + + result = self.run_command(['hardware', 'credentials', '12345']) + + self.assertEqual( + 'No password found in operatingSystem passwords', + str(result.exception) + ) def test_server_details(self): result = self.run_command(['server', 'detail', '1234', From 676c2e85acf0d3c69a8c82fb9af2725520259fce Mon Sep 17 00:00:00 2001 From: Fernando Ojeda Date: Wed, 27 Jun 2018 15:35:26 -0400 Subject: [PATCH 2/4] Fixed hardware credentials issue. --- SoftLayer/CLI/hardware/credentials.py | 2 +- tests/CLI/modules/server_tests.py | 44 +++++++++++++-------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/SoftLayer/CLI/hardware/credentials.py b/SoftLayer/CLI/hardware/credentials.py index 53069c74b..ffccbc0ce 100644 --- a/SoftLayer/CLI/hardware/credentials.py +++ b/SoftLayer/CLI/hardware/credentials.py @@ -4,8 +4,8 @@ import click import SoftLayer -from SoftLayer import exceptions from SoftLayer.CLI import environment +from SoftLayer import exceptions from SoftLayer.CLI import formatting from SoftLayer.CLI import helpers diff --git a/tests/CLI/modules/server_tests.py b/tests/CLI/modules/server_tests.py index d384548fe..947ba90b4 100644 --- a/tests/CLI/modules/server_tests.py +++ b/tests/CLI/modules/server_tests.py @@ -25,7 +25,7 @@ def test_server_cancel_reasons(self): output = json.loads(result.output) self.assert_no_fail(result) self.assertEqual(len(output), 10) - + def test_server_credentials(self): result = self.run_command(['hardware', 'credentials', '12345']) @@ -39,14 +39,14 @@ def test_server_credentials(self): def test_server_credentials_exception_passwords_not_found(self): mock = self.set_mock('SoftLayer_Hardware_Server', 'getObject') mock.return_value = { - "accountId": 11111, - "domain": "chechu.com", - "fullyQualifiedDomainName": "host3.vmware.chechu.com", - "hardwareStatusId": 5, - "hostname": "host3.vmware", - "id": 12345, - "operatingSystem": {} - } + "accountId": 11111, + "domain": "chechu.com", + "fullyQualifiedDomainName": "host3.vmware.chechu.com", + "hardwareStatusId": 5, + "hostname": "host3.vmware", + "id": 12345, + "operatingSystem": {} + } result = self.run_command(['hardware', 'credentials', '12345']) @@ -58,17 +58,17 @@ def test_server_credentials_exception_passwords_not_found(self): def test_server_credentials_exception_password_not_found(self): mock = self.set_mock('SoftLayer_Hardware_Server', 'getObject') mock.return_value = { - "accountId": 11111, - "domain": "chechu.com", - "fullyQualifiedDomainName": "host3.vmware.chechu.com", - "hardwareStatusId": 5, - "hostname": "host3.vmware", - "id": 12345, - "operatingSystem": { - "hardwareId": 22222, - "id": 333333, - "passwords": [{}] - } + "accountId": 11111, + "domain": "chechu.com", + "fullyQualifiedDomainName": "host3.vmware.chechu.com", + "hardwareStatusId": 5, + "hostname": "host3.vmware", + "id": 12345, + "operatingSystem": { + "hardwareId": 22222, + "id": 333333, + "passwords": [{}] + } } result = self.run_command(['hardware', 'credentials', '12345']) @@ -365,7 +365,7 @@ def test_create_server_missing_required(self): @mock.patch('SoftLayer.CLI.template.export_to_template') def test_create_server_with_export(self, export_mock): - if(sys.platform.startswith("win")): + if (sys.platform.startswith("win")): self.skipTest("Test doesn't work in Windows") result = self.run_command(['--really', 'server', 'create', '--size=S1270_8GB_2X1TBSATA_NORAID', @@ -439,7 +439,7 @@ def test_edit_server_failed(self, edit_mock): hostname='hardware-test1') def test_edit_server_userfile(self): - if(sys.platform.startswith("win")): + if (sys.platform.startswith("win")): self.skipTest("Test doesn't work in Windows") with tempfile.NamedTemporaryFile() as userfile: userfile.write(b"some data") From 10c432f534e40c2243ad7f46e6eb58ad40ef9da5 Mon Sep 17 00:00:00 2001 From: Fernando Ojeda Date: Wed, 27 Jun 2018 16:01:36 -0400 Subject: [PATCH 3/4] Fixed hardware credentials issue --- SoftLayer/CLI/hardware/credentials.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SoftLayer/CLI/hardware/credentials.py b/SoftLayer/CLI/hardware/credentials.py index ffccbc0ce..a176c4063 100644 --- a/SoftLayer/CLI/hardware/credentials.py +++ b/SoftLayer/CLI/hardware/credentials.py @@ -5,9 +5,9 @@ import SoftLayer from SoftLayer.CLI import environment -from SoftLayer import exceptions from SoftLayer.CLI import formatting from SoftLayer.CLI import helpers +from SoftLayer import exceptions @click.command() From 53fb9e7f30ebe6a468d294b0377ca75611580285 Mon Sep 17 00:00:00 2001 From: Fernando Ojeda Date: Mon, 2 Jul 2018 13:20:57 -0400 Subject: [PATCH 4/4] Fixed hardware credential issue. --- SoftLayer/CLI/hardware/credentials.py | 5 +---- tests/CLI/modules/server_tests.py | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/SoftLayer/CLI/hardware/credentials.py b/SoftLayer/CLI/hardware/credentials.py index a176c4063..3b1c0798a 100644 --- a/SoftLayer/CLI/hardware/credentials.py +++ b/SoftLayer/CLI/hardware/credentials.py @@ -27,8 +27,5 @@ def cli(env, identifier): raise exceptions.SoftLayerError("No passwords found in operatingSystem") for item in instance['operatingSystem']['passwords']: - if 'password' not in item: - raise exceptions.SoftLayerError("No password found in operatingSystem passwords") - else: - table.add_row([item['username'], item['password']]) + table.add_row([item.get('username', 'None'), item.get('password', 'None')]) env.fout(table) diff --git a/tests/CLI/modules/server_tests.py b/tests/CLI/modules/server_tests.py index 947ba90b4..fe42b553d 100644 --- a/tests/CLI/modules/server_tests.py +++ b/tests/CLI/modules/server_tests.py @@ -74,7 +74,7 @@ def test_server_credentials_exception_password_not_found(self): result = self.run_command(['hardware', 'credentials', '12345']) self.assertEqual( - 'No password found in operatingSystem passwords', + 'None', str(result.exception) )