Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions SoftLayer/CLI/hardware/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 6 additions & 0 deletions SoftLayer/managers/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],'
Expand Down
31 changes: 24 additions & 7 deletions tests/CLI/modules/server_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
)

Expand All @@ -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'])
Expand Down