Repository: softlayer/softlayer-python
Pull request #1018 (2018-08-08 20:13:16)

Fixed hardware credentials.
Fixed hardware credentials https://github.com/softlayer/softlayer-python/issues/1013.


Patch:
diff --git a/SoftLayer/CLI/hardware/credentials.py b/SoftLayer/CLI/hardware/credentials.py
index 3b1c0798..877d5e9b 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 7e0c3377..c105b3b5 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],'


Test patch:
diff --git a/tests/CLI/modules/server_tests.py b/tests/CLI/modules/server_tests.py
index fe42b553..2f26c4ec 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'])