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: 9 additions & 1 deletion SoftLayer/managers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,15 @@ def create_user(self, user_object, password):
:param dictionary user_object: https://softlayer.github.io/reference/datatypes/SoftLayer_User_Customer/
"""
LOGGER.warning("Creating User %s", user_object['username'])
return self.user_service.createObject(user_object, password, None)

try:
return self.user_service.createObject(user_object, password, None)
except exceptions.SoftLayerAPIError as ex:
if ex.faultCode == "SoftLayer_Exception_User_Customer_DelegateIamIdInvitationToPaas":
raise exceptions.SoftLayerError("Your request for a new user was received, but it needs to be "
"processed by the Platform Services API first. Barring any errors on "
"the Platform Services side, your new user should be created shortly.")
raise

def edit_user(self, user_id, user_object):
"""Blindly sends user_object to SoftLayer_User_Customer::editObject
Expand Down
30 changes: 30 additions & 0 deletions tests/managers/user_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,33 @@ def test_get_current_user_mask(self):
result = self.manager.get_current_user(objectmask="mask[id]")
self.assert_called_with('SoftLayer_Account', 'getCurrentUser', mask="mask[id]")
self.assertEqual(result['id'], 12345)

def test_create_user_handle_paas_exception(self):
user_template = {"username": "foobar", "email": "foobar@example.com"}

self.manager.user_service = mock.Mock()

# FaultCode IS NOT SoftLayer_Exception_User_Customer_DelegateIamIdInvitationToPaas
any_error = exceptions.SoftLayerAPIError("SoftLayer_Exception_User_Customer",
"This exception indicates an error")

self.manager.user_service.createObject.side_effect = any_error

try:
self.manager.create_user(user_template, "Pass@123")
except exceptions.SoftLayerAPIError as ex:
self.assertEqual(ex.faultCode, "SoftLayer_Exception_User_Customer")
self.assertEqual(ex.faultString, "This exception indicates an error")

# FaultCode is SoftLayer_Exception_User_Customer_DelegateIamIdInvitationToPaas
paas_error = exceptions.SoftLayerAPIError("SoftLayer_Exception_User_Customer_DelegateIamIdInvitationToPaas",
"This exception does NOT indicate an error")

self.manager.user_service.createObject.side_effect = paas_error

try:
self.manager.create_user(user_template, "Pass@123")
except exceptions.SoftLayerError as ex:
self.assertEqual(ex.args[0], "Your request for a new user was received, but it needs to be processed by "
"the Platform Services API first. Barring any errors on the Platform Services "
"side, your new user should be created shortly.")