From 2b67bf8c9cf1f776dec39330c1f56008eed36d77 Mon Sep 17 00:00:00 2001 From: Fernando Ojeda Date: Wed, 25 Jul 2018 12:56:53 -0400 Subject: [PATCH] Fixed the nas credentials issue. --- SoftLayer/CLI/nas/credentials.py | 4 ++-- tests/CLI/modules/nas_tests.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/SoftLayer/CLI/nas/credentials.py b/SoftLayer/CLI/nas/credentials.py index 43c829d70..513ea100a 100644 --- a/SoftLayer/CLI/nas/credentials.py +++ b/SoftLayer/CLI/nas/credentials.py @@ -17,6 +17,6 @@ def cli(env, identifier): nw_mgr = SoftLayer.NetworkManager(env.client) result = nw_mgr.get_nas_credentials(identifier) table = formatting.Table(['username', 'password']) - table.add_row([result['username'], - result['password']]) + table.add_row([result.get('username', 'None'), + result.get('password', 'None')]) env.fout(table) diff --git a/tests/CLI/modules/nas_tests.py b/tests/CLI/modules/nas_tests.py index 01e0c8c8a..9c2e6869c 100644 --- a/tests/CLI/modules/nas_tests.py +++ b/tests/CLI/modules/nas_tests.py @@ -19,3 +19,32 @@ def test_list_nas(self): 'server': '127.0.0.1', 'id': 1, 'size': 10}]) + + def test_nas_credentials(self): + result = self.run_command(['nas', 'credentials', '12345']) + self.assert_no_fail(result) + self.assertEqual(json.loads(result.output), + [{ + 'password': '', + 'username': 'username' + }]) + + def test_server_credentials_exception_password_not_found(self): + mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') + + mock.return_value = { + "accountId": 11111, + "capacityGb": 20, + "id": 22222, + "nasType": "NAS", + "serviceProviderId": 1, + "username": "SL01SEV307", + "credentials": [] + } + + result = self.run_command(['nas', 'credentials', '12345']) + + self.assertEqual( + 'None', + str(result.exception) + )