Skip to content

Commit 04f237d

Browse files
Merge pull request #1018 from FernandoOjeda/fo_hardware_credentials
Fixed hardware credentials.
2 parents 86e036f + 87c22ec commit 04f237d

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

SoftLayer/CLI/hardware/credentials.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def cli(env, identifier):
2323
instance = manager.get_hardware(hardware_id)
2424

2525
table = formatting.Table(['username', 'password'])
26-
if 'passwords' not in instance['operatingSystem']:
27-
raise exceptions.SoftLayerError("No passwords found in operatingSystem")
28-
29-
for item in instance['operatingSystem']['passwords']:
30-
table.add_row([item.get('username', 'None'), item.get('password', 'None')])
26+
for item in instance['softwareComponents']:
27+
if 'passwords' not in item:
28+
raise exceptions.SoftLayerError("No passwords found in softwareComponents")
29+
for credentials in item['passwords']:
30+
table.add_row([credentials.get('username', 'None'), credentials.get('password', 'None')])
3131
env.fout(table)

SoftLayer/managers/hardware.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ def get_hardware(self, hardware_id, **kwargs):
245245
version,
246246
referenceCode]],
247247
passwords[username,password]],'''
248+
'''softwareComponents[
249+
softwareLicense[softwareDescription[manufacturer,
250+
name,
251+
version,
252+
referenceCode]],
253+
passwords[username,password]],'''
248254
'billingItem['
249255
'id,nextInvoiceTotalRecurringAmount,'
250256
'children[nextInvoiceTotalRecurringAmount],'

tests/CLI/modules/server_tests.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ def test_server_cancel_reasons(self):
2727
self.assertEqual(len(output), 10)
2828

2929
def test_server_credentials(self):
30+
mock = self.set_mock('SoftLayer_Hardware_Server', 'getObject')
31+
mock.return_value = {
32+
"accountId": 11111,
33+
"domain": "chechu.com",
34+
"fullyQualifiedDomainName": "host3.vmware.chechu.com",
35+
"hardwareStatusId": 5,
36+
"hostname": "host3.vmware",
37+
"id": 12345,
38+
"softwareComponents": [{"passwords": [
39+
{
40+
"password": "abc123",
41+
"username": "root"
42+
}
43+
]}]
44+
}
3045
result = self.run_command(['hardware', 'credentials', '12345'])
3146

3247
self.assert_no_fail(result)
@@ -45,13 +60,13 @@ def test_server_credentials_exception_passwords_not_found(self):
4560
"hardwareStatusId": 5,
4661
"hostname": "host3.vmware",
4762
"id": 12345,
48-
"operatingSystem": {}
63+
"softwareComponents": [{}]
4964
}
5065

5166
result = self.run_command(['hardware', 'credentials', '12345'])
5267

5368
self.assertEqual(
54-
'No passwords found in operatingSystem',
69+
'No passwords found in softwareComponents',
5570
str(result.exception)
5671
)
5772

@@ -64,11 +79,13 @@ def test_server_credentials_exception_password_not_found(self):
6479
"hardwareStatusId": 5,
6580
"hostname": "host3.vmware",
6681
"id": 12345,
67-
"operatingSystem": {
68-
"hardwareId": 22222,
69-
"id": 333333,
70-
"passwords": [{}]
71-
}
82+
"softwareComponents": [
83+
{
84+
"hardwareId": 22222,
85+
"id": 333333,
86+
"passwords": [{}]
87+
}
88+
]
7289
}
7390

7491
result = self.run_command(['hardware', 'credentials', '12345'])

0 commit comments

Comments
 (0)