Skip to content

Commit 3932c4e

Browse files
author
Fernando Ojeda
committed
Fixed hardware credentials issue.
1 parent 32a6e43 commit 3932c4e

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

SoftLayer/CLI/hardware/credentials.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import click
55

66
import SoftLayer
7+
from SoftLayer import exceptions
78
from SoftLayer.CLI import environment
89
from SoftLayer.CLI import formatting
910
from SoftLayer.CLI import helpers
@@ -22,6 +23,12 @@ def cli(env, identifier):
2223
instance = manager.get_hardware(hardware_id)
2324

2425
table = formatting.Table(['username', 'password'])
26+
if 'passwords' not in instance['operatingSystem']:
27+
raise exceptions.SoftLayerError("No passwords found in operatingSystem")
28+
2529
for item in instance['operatingSystem']['passwords']:
26-
table.add_row([item['username'], item['password']])
30+
if 'password' not in item:
31+
raise exceptions.SoftLayerError("No password found in operatingSystem passwords")
32+
else:
33+
table.add_row([item['username'], item['password']])
2734
env.fout(table)

tests/CLI/modules/server_tests.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,58 @@ def test_server_cancel_reasons(self):
2525
output = json.loads(result.output)
2626
self.assert_no_fail(result)
2727
self.assertEqual(len(output), 10)
28+
29+
def test_server_credentials(self):
30+
result = self.run_command(['hardware', 'credentials', '12345'])
31+
32+
self.assert_no_fail(result)
33+
self.assertEqual(json.loads(result.output),
34+
[{
35+
'username': 'root',
36+
'password': 'abc123'
37+
}])
38+
39+
def test_server_credentials_exception_passwords_not_found(self):
40+
mock = self.set_mock('SoftLayer_Hardware_Server', 'getObject')
41+
mock.return_value = {
42+
"accountId": 11111,
43+
"domain": "chechu.com",
44+
"fullyQualifiedDomainName": "host3.vmware.chechu.com",
45+
"hardwareStatusId": 5,
46+
"hostname": "host3.vmware",
47+
"id": 12345,
48+
"operatingSystem": {}
49+
}
50+
51+
result = self.run_command(['hardware', 'credentials', '12345'])
52+
53+
self.assertEqual(
54+
'No passwords found in operatingSystem',
55+
str(result.exception)
56+
)
57+
58+
def test_server_credentials_exception_password_not_found(self):
59+
mock = self.set_mock('SoftLayer_Hardware_Server', 'getObject')
60+
mock.return_value = {
61+
"accountId": 11111,
62+
"domain": "chechu.com",
63+
"fullyQualifiedDomainName": "host3.vmware.chechu.com",
64+
"hardwareStatusId": 5,
65+
"hostname": "host3.vmware",
66+
"id": 12345,
67+
"operatingSystem": {
68+
"hardwareId": 22222,
69+
"id": 333333,
70+
"passwords": [{}]
71+
}
72+
}
73+
74+
result = self.run_command(['hardware', 'credentials', '12345'])
75+
76+
self.assertEqual(
77+
'No password found in operatingSystem passwords',
78+
str(result.exception)
79+
)
2880

2981
def test_server_details(self):
3082
result = self.run_command(['server', 'detail', '1234',

0 commit comments

Comments
 (0)