Fix tests, add remove_public_key
The tests for VitualMachineSerializer were wrong. The manager now contains a function to remove public keys from a user
This commit is contained in:
parent
d229d124e9
commit
06f372e56d
2 changed files with 54 additions and 39 deletions
|
|
@ -479,3 +479,45 @@ class OpenNebulaManager():
|
|||
|
||||
except ConnectionError:
|
||||
raise
|
||||
|
||||
def remove_public_key(self, user, public_key=''):
|
||||
"""
|
||||
|
||||
Args:
|
||||
user (CustomUser): Dynamicweb user
|
||||
public_key (string): Public key to be removed to the user
|
||||
|
||||
Raises:
|
||||
KeyDoesNotExistsError: If replace is False and the user already has a
|
||||
public key
|
||||
WrongNameError: If no openebula user with this credentials exists
|
||||
ConnectionError: If the connection to the opennebula server can't be
|
||||
established
|
||||
|
||||
Returns:
|
||||
True if public_key was removed
|
||||
|
||||
"""
|
||||
|
||||
try:
|
||||
open_user = self._get_user(user)
|
||||
try:
|
||||
old_key = open_user.template.ssh_public_key
|
||||
if public_key not in old_key:
|
||||
raise KeyDoesNotExistsError()
|
||||
if '\n{}'.format(public_key) in old_key:
|
||||
public_key = old_key.replace('\n{}'.format(public_key), '')
|
||||
else:
|
||||
public_key = old_key.replace(public_key, '')
|
||||
|
||||
except AttributeError:
|
||||
raise KeyDoesNotExistsError()
|
||||
|
||||
self.oneadmin_client.call('user.update', open_user.id,
|
||||
'<CONTEXT><SSH_PUBLIC_KEY>{key}</SSH_PUBLIC_KEY></CONTEXT>'.format(key=public_key))
|
||||
return True
|
||||
except WrongNameError:
|
||||
raise
|
||||
|
||||
except ConnectionError:
|
||||
raise
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue