Skip to content

Commit 89a65e1

Browse files
Merge pull request #1909 from softlayer/issues1905
Fixed an issue with 'slcli event-log get'
2 parents 298cb14 + ffbd240 commit 89a65e1

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

SoftLayer/CLI/event_log/get.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import SoftLayer
77
from SoftLayer.CLI import environment
8-
from SoftLayer.CLI import exceptions
8+
from SoftLayer import exceptions
99
from SoftLayer import utils
1010

1111

@@ -40,6 +40,7 @@ def cli(env, date_min, date_max, obj_event, obj_id, obj_type, utc_offset, metada
4040
request_filter = event_mgr.build_filter(date_min, date_max, obj_event, obj_id, obj_type, utc_offset)
4141
logs = event_mgr.get_event_logs(request_filter)
4242
log_time = "%Y-%m-%dT%H:%M:%S.%f%z"
43+
# A list of IDs that we have looked up user information about.
4344
user_data = {}
4445

4546
if metadata:
@@ -59,9 +60,11 @@ def cli(env, date_min, date_max, obj_event, obj_id, obj_type, utc_offset, metada
5960
if username is None:
6061
try:
6162
username = user_mgr.get_user(log['userId'], "mask[username]")['username']
62-
user_data[log['userId']] = username
63+
# Some users might not be able to access information about this specific userId
6364
except exceptions.SoftLayerAPIError:
6465
username = log['userId']
66+
# This keeps track of any users we asked the API about, so we can make fewer calls.
67+
user_data[log['userId']] = username
6568
user = username
6669

6770
if metadata:

tests/CLI/modules/event_log_tests.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import json
88

9+
from SoftLayer import SoftLayerAPIError
910
from SoftLayer import testing
1011

1112

@@ -91,3 +92,16 @@ def test_get_unlimited_events(self):
9192
self.assert_no_fail(result)
9293
self.assert_called_with('SoftLayer_Event_Log', 'getAllObjects')
9394
self.assertEqual(8, result.output.count("\n"))
95+
96+
def test_issues1905(self):
97+
"""https://github.com/softlayer/softlayer-python/issues/1905"""
98+
getUser = self.set_mock('SoftLayer_User_Customer', 'getObject')
99+
getUser.side_effect = SoftLayerAPIError(
100+
"SoftLayer_Exception_PermissionDenied",
101+
"You do not have permission to access this user")
102+
result = self.run_command(['event-log', 'get', '-l -1'])
103+
self.assert_no_fail(result)
104+
self.assert_called_with('SoftLayer_Event_Log', 'getAllObjects')
105+
self.assert_called_with('SoftLayer_User_Customer', 'getObject', identifier=400)
106+
user_calls = self.calls('SoftLayer_User_Customer', 'getObject')
107+
self.assertEqual(1, len(user_calls))

tests/CLI/modules/sshkey_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def test_print_key(self):
118118
{'id': 1234, 'label': 'label', 'notes': 'notes'})
119119

120120
def test_print_key_file(self):
121-
if(sys.platform.startswith("win")):
121+
if (sys.platform.startswith("win")):
122122
self.skipTest("Test doesn't work in Windows")
123123
with tempfile.NamedTemporaryFile() as sshkey_file:
124124
service = self.client['Security_Ssh_Key']

tests/CLI/modules/vs/vs_create_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ def test_create_vs_no_confirm(self, confirm_mock):
693693
self.assertEqual(result.exit_code, 2)
694694

695695
def test_create_vs_export(self):
696-
if(sys.platform.startswith("win")):
696+
if (sys.platform.startswith("win")):
697697
self.skipTest("Test doesn't work in Windows")
698698
with tempfile.NamedTemporaryFile() as config_file:
699699
result = self.run_command(['vs', 'create', '--hostname', 'TEST', '--export', config_file.name,

0 commit comments

Comments
 (0)