Skip to content

Commit b8bc75a

Browse files
Merge pull request #987 from FernandoOjeda/fo_hardware_credentials
Fixed hardware credentials issue.
2 parents bdf4ade + 53fb9e7 commit b8bc75a

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

SoftLayer/CLI/hardware/credentials.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from SoftLayer.CLI import environment
88
from SoftLayer.CLI import formatting
99
from SoftLayer.CLI import helpers
10+
from SoftLayer import exceptions
1011

1112

1213
@click.command()
@@ -22,6 +23,9 @@ 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+
table.add_row([item.get('username', 'None'), item.get('password', 'None')])
2731
env.fout(table)

tests/CLI/modules/server_tests.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,58 @@ def test_server_cancel_reasons(self):
2626
self.assert_no_fail(result)
2727
self.assertEqual(len(output), 10)
2828

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+
'None',
78+
str(result.exception)
79+
)
80+
2981
def test_server_details(self):
3082
result = self.run_command(['server', 'detail', '1234',
3183
'--passwords', '--price'])
@@ -313,7 +365,7 @@ def test_create_server_missing_required(self):
313365

314366
@mock.patch('SoftLayer.CLI.template.export_to_template')
315367
def test_create_server_with_export(self, export_mock):
316-
if(sys.platform.startswith("win")):
368+
if (sys.platform.startswith("win")):
317369
self.skipTest("Test doesn't work in Windows")
318370
result = self.run_command(['--really', 'server', 'create',
319371
'--size=S1270_8GB_2X1TBSATA_NORAID',
@@ -387,7 +439,7 @@ def test_edit_server_failed(self, edit_mock):
387439
hostname='hardware-test1')
388440

389441
def test_edit_server_userfile(self):
390-
if(sys.platform.startswith("win")):
442+
if (sys.platform.startswith("win")):
391443
self.skipTest("Test doesn't work in Windows")
392444
with tempfile.NamedTemporaryFile() as userfile:
393445
userfile.write(b"some data")

0 commit comments

Comments
 (0)