From 87c22ec828a72255a03d3923d706a6da57fd9a45 Mon Sep 17 00:00:00 2001 From: Fernando Ojeda Date: Wed, 8 Aug 2018 16:07:06 -0400 Subject: [PATCH] Fixed hardware credentials. --- SoftLayer/CLI/hardware/credentials.py | 10 ++++----- SoftLayer/managers/hardware.py | 6 ++++++ tests/CLI/modules/server_tests.py | 31 +++++++++++++++++++++------ 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/SoftLayer/CLI/hardware/credentials.py b/SoftLayer/CLI/hardware/credentials.py index 3b1c0798a..877d5e9ba 100644 --- a/SoftLayer/CLI/hardware/credentials.py +++ b/SoftLayer/CLI/hardware/credentials.py @@ -23,9 +23,9 @@ 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.get('username', 'None'), item.get('password', 'None')]) + for item in instance['softwareComponents']: + if 'passwords' not in item: + raise exceptions.SoftLayerError("No passwords found in softwareComponents") + for credentials in item['passwords']: + table.add_row([credentials.get('username', 'None'), credentials.get('password', 'None')]) env.fout(table) diff --git a/SoftLayer/managers/hardware.py b/SoftLayer/managers/hardware.py index 7e0c33773..c105b3b5d 100644 --- a/SoftLayer/managers/hardware.py +++ b/SoftLayer/managers/hardware.py @@ -245,6 +245,12 @@ def get_hardware(self, hardware_id, **kwargs): version, referenceCode]], passwords[username,password]],''' + '''softwareComponents[ + softwareLicense[softwareDescription[manufacturer, + name, + version, + referenceCode]], + passwords[username,password]],''' 'billingItem[' 'id,nextInvoiceTotalRecurringAmount,' 'children[nextInvoiceTotalRecurringAmount],' diff --git a/tests/CLI/modules/server_tests.py b/tests/CLI/modules/server_tests.py index fe42b553d..2f26c4ec6 100644 --- a/tests/CLI/modules/server_tests.py +++ b/tests/CLI/modules/server_tests.py @@ -27,6 +27,21 @@ def test_server_cancel_reasons(self): self.assertEqual(len(output), 10) def test_server_credentials(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, + "softwareComponents": [{"passwords": [ + { + "password": "abc123", + "username": "root" + } + ]}] + } result = self.run_command(['hardware', 'credentials', '12345']) self.assert_no_fail(result) @@ -45,13 +60,13 @@ def test_server_credentials_exception_passwords_not_found(self): "hardwareStatusId": 5, "hostname": "host3.vmware", "id": 12345, - "operatingSystem": {} + "softwareComponents": [{}] } result = self.run_command(['hardware', 'credentials', '12345']) self.assertEqual( - 'No passwords found in operatingSystem', + 'No passwords found in softwareComponents', str(result.exception) ) @@ -64,11 +79,13 @@ def test_server_credentials_exception_password_not_found(self): "hardwareStatusId": 5, "hostname": "host3.vmware", "id": 12345, - "operatingSystem": { - "hardwareId": 22222, - "id": 333333, - "passwords": [{}] - } + "softwareComponents": [ + { + "hardwareId": 22222, + "id": 333333, + "passwords": [{}] + } + ] } result = self.run_command(['hardware', 'credentials', '12345'])