mirror of
https://github.com/OpenKMIP/PyKMIP.git
synced 2025-07-21 21:14:24 +02:00
Merge pull request #266 from vbnmmnbv/activate_pie
Add Activate operation support for pie client
This commit is contained in:
commit
1a8a31af49
@ -506,6 +506,40 @@ class ProxyKmipClient(api.KmipClient):
|
|||||||
message = result.result_message.value
|
message = result.result_message.value
|
||||||
raise exceptions.KmipOperationFailure(status, reason, message)
|
raise exceptions.KmipOperationFailure(status, reason, message)
|
||||||
|
|
||||||
|
def activate(self, uid):
|
||||||
|
"""
|
||||||
|
Activate a managed object stored by a KMIP appliance.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
uid (string): The unique ID of the managed object to activate.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ClientConnectionNotOpen: if the client connection is unusable
|
||||||
|
KmipOperationFailure: if the operation result is a failure
|
||||||
|
TypeError: if the input argument is invalid
|
||||||
|
"""
|
||||||
|
# Check input
|
||||||
|
if not isinstance(uid, six.string_types):
|
||||||
|
raise TypeError("uid must be a string")
|
||||||
|
|
||||||
|
# Verify that operations can be given at this time
|
||||||
|
if not self._is_open:
|
||||||
|
raise exceptions.ClientConnectionNotOpen()
|
||||||
|
|
||||||
|
# Activate the managed object and handle the results
|
||||||
|
result = self.proxy.activate(uid)
|
||||||
|
|
||||||
|
status = result.result_status.value
|
||||||
|
if status == enums.ResultStatus.SUCCESS:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
reason = result.result_reason.value
|
||||||
|
message = result.result_message.value
|
||||||
|
raise exceptions.KmipOperationFailure(status, reason, message)
|
||||||
|
|
||||||
def destroy(self, uid):
|
def destroy(self, uid):
|
||||||
"""
|
"""
|
||||||
Destroy a managed object stored by a KMIP appliance.
|
Destroy a managed object stored by a KMIP appliance.
|
||||||
|
@ -884,6 +884,71 @@ class TestProxyKmipClient(testtools.TestCase):
|
|||||||
self.assertRaisesRegexp(
|
self.assertRaisesRegexp(
|
||||||
KmipOperationFailure, error_msg, client.get_attribute_list, *args)
|
KmipOperationFailure, error_msg, client.get_attribute_list, *args)
|
||||||
|
|
||||||
|
@mock.patch('kmip.pie.client.KMIPProxy',
|
||||||
|
mock.MagicMock(spec_set=KMIPProxy))
|
||||||
|
def test_activate(self):
|
||||||
|
"""
|
||||||
|
Test that the client can activate a secret.
|
||||||
|
"""
|
||||||
|
status = enums.ResultStatus.SUCCESS
|
||||||
|
result = results.OperationResult(contents.ResultStatus(status))
|
||||||
|
|
||||||
|
with ProxyKmipClient() as client:
|
||||||
|
client.proxy.activate.return_value = result
|
||||||
|
result = client.activate(
|
||||||
|
'aaaaaaaa-1111-2222-3333-ffffffffffff')
|
||||||
|
client.proxy.activate.assert_called_with(
|
||||||
|
'aaaaaaaa-1111-2222-3333-ffffffffffff')
|
||||||
|
self.assertEqual(None, result)
|
||||||
|
|
||||||
|
@mock.patch('kmip.pie.client.KMIPProxy',
|
||||||
|
mock.MagicMock(spec_set=KMIPProxy))
|
||||||
|
def test_activate_on_invalid_uid(self):
|
||||||
|
"""
|
||||||
|
Test that a TypeError exception is raised when trying to activate a
|
||||||
|
secret with an invalid ID.
|
||||||
|
"""
|
||||||
|
args = [0]
|
||||||
|
with ProxyKmipClient() as client:
|
||||||
|
self.assertRaises(TypeError, client.activate, *args)
|
||||||
|
|
||||||
|
@mock.patch('kmip.pie.client.KMIPProxy',
|
||||||
|
mock.MagicMock(spec_set=KMIPProxy))
|
||||||
|
def test_activate_on_closed(self):
|
||||||
|
"""
|
||||||
|
Test that a ClientConnectionNotOpen exception is raised when trying
|
||||||
|
to activate a secret on an unopened client connection.
|
||||||
|
"""
|
||||||
|
client = ProxyKmipClient()
|
||||||
|
args = ['aaaaaaaa-1111-2222-3333-ffffffffffff']
|
||||||
|
self.assertRaises(
|
||||||
|
ClientConnectionNotOpen, client.activate, *args)
|
||||||
|
|
||||||
|
@mock.patch('kmip.pie.client.KMIPProxy',
|
||||||
|
mock.MagicMock(spec_set=KMIPProxy))
|
||||||
|
def test_activate_on_operation_failure(self):
|
||||||
|
"""
|
||||||
|
Test that a KmipOperationFailure exception is raised when the
|
||||||
|
backend fails to activate a secret.
|
||||||
|
"""
|
||||||
|
status = enums.ResultStatus.OPERATION_FAILED
|
||||||
|
reason = enums.ResultReason.GENERAL_FAILURE
|
||||||
|
message = "Test failure message"
|
||||||
|
|
||||||
|
result = results.OperationResult(
|
||||||
|
contents.ResultStatus(status),
|
||||||
|
contents.ResultReason(reason),
|
||||||
|
contents.ResultMessage(message))
|
||||||
|
error_msg = str(KmipOperationFailure(status, reason, message))
|
||||||
|
|
||||||
|
client = ProxyKmipClient()
|
||||||
|
client.open()
|
||||||
|
client.proxy.activate.return_value = result
|
||||||
|
args = ['id']
|
||||||
|
|
||||||
|
self.assertRaisesRegexp(
|
||||||
|
KmipOperationFailure, error_msg, client.activate, *args)
|
||||||
|
|
||||||
@mock.patch('kmip.pie.client.KMIPProxy',
|
@mock.patch('kmip.pie.client.KMIPProxy',
|
||||||
mock.MagicMock(spec_set=KMIPProxy))
|
mock.MagicMock(spec_set=KMIPProxy))
|
||||||
def test_destroy(self):
|
def test_destroy(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user