Update Barbican resources to match library changes
This patch updates both Barbican resources and the client to match recent changes in python-barbicanclient. Closes-Bug: #1396283 Change-Id: I7a785fd68ffdcda0e622d576a555b3699c706b77
This commit is contained in:
parent
5596e63263
commit
a041681099
@ -16,18 +16,20 @@ from heat.engine.clients import client_plugin
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from barbicanclient import client as barbican_client
|
from barbicanclient import client as barbican_client
|
||||||
from barbicanclient.common import auth
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
barbican_client = None
|
barbican_client = None
|
||||||
auth = None
|
|
||||||
|
|
||||||
|
|
||||||
class BarbicanClientPlugin(client_plugin.ClientPlugin):
|
class BarbicanClientPlugin(client_plugin.ClientPlugin):
|
||||||
|
|
||||||
def _create(self):
|
def _create(self):
|
||||||
|
|
||||||
keystone_client = self.clients.client('keystone').client
|
keystone_client = self.clients.client('keystone').client
|
||||||
auth_plugin = auth.KeystoneAuthV2(keystone=keystone_client)
|
endpoint_type = self._get_client_option('barbican', 'endpoint_type')
|
||||||
client = barbican_client.Client(auth_plugin=auth_plugin)
|
endpoint = self.url_for(service_type='key-manager',
|
||||||
|
endpoint_type=endpoint_type)
|
||||||
|
# Remove version if set
|
||||||
|
endpoint = endpoint.rsplit("/", 1)[0]
|
||||||
|
client = barbican_client.Client(
|
||||||
|
session=keystone_client.session, endpoint=endpoint)
|
||||||
|
|
||||||
return client
|
return client
|
||||||
|
@ -109,13 +109,13 @@ class Order(resource.Resource):
|
|||||||
|
|
||||||
def handle_create(self):
|
def handle_create(self):
|
||||||
info = dict(self.properties)
|
info = dict(self.properties)
|
||||||
order = self.barbican().orders.Order(**info)
|
order = self.barbican().orders.create_key(**info)
|
||||||
order_ref = order.submit()
|
order_ref = order.submit()
|
||||||
self.resource_id_set(order_ref)
|
self.resource_id_set(order_ref)
|
||||||
return order_ref
|
return order_ref
|
||||||
|
|
||||||
def check_create_complete(self, order_href):
|
def check_create_complete(self, order_href):
|
||||||
order = self.barbican().orders.Order(order_href)
|
order = self.barbican().orders.get(order_href)
|
||||||
|
|
||||||
if order.status == 'ERROR':
|
if order.status == 'ERROR':
|
||||||
reason = order.error_reason
|
reason = order.error_reason
|
||||||
@ -140,7 +140,7 @@ class Order(resource.Resource):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
def _resolve_attribute(self, name):
|
def _resolve_attribute(self, name):
|
||||||
order = self.barbican().orders.Order(self.resource_id)
|
order = self.barbican().orders.get(self.resource_id)
|
||||||
return getattr(order, name)
|
return getattr(order, name)
|
||||||
|
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ class Secret(resource.Resource):
|
|||||||
|
|
||||||
def handle_create(self):
|
def handle_create(self):
|
||||||
info = dict(self.properties)
|
info = dict(self.properties)
|
||||||
secret = self.barbican().secrets.Secret(**info)
|
secret = self.barbican().secrets.create(**info)
|
||||||
secret_ref = secret.store()
|
secret_ref = secret.store()
|
||||||
self.resource_id_set(secret_ref)
|
self.resource_id_set(secret_ref)
|
||||||
return secret_ref
|
return secret_ref
|
||||||
@ -145,7 +145,7 @@ class Secret(resource.Resource):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
def _resolve_attribute(self, name):
|
def _resolve_attribute(self, name):
|
||||||
secret = self.barbican().secrets.Secret(self.resource_id)
|
secret = self.barbican().secrets.get(self.resource_id)
|
||||||
|
|
||||||
if name == self.DECRYPTED_PAYLOAD:
|
if name == self.DECRYPTED_PAYLOAD:
|
||||||
return secret.payload
|
return secret.payload
|
||||||
|
@ -77,7 +77,7 @@ class TestOrder(common.HeatTestCase):
|
|||||||
def _create_resource(self, name, snippet, stack):
|
def _create_resource(self, name, snippet, stack):
|
||||||
res = order.Order(name, snippet, stack)
|
res = order.Order(name, snippet, stack)
|
||||||
res.check_create_complete = mock.Mock(return_value=True)
|
res.check_create_complete = mock.Mock(return_value=True)
|
||||||
self.barbican.orders.Order.return_value = FakeOrder(name)
|
self.barbican.orders.create_key.return_value = FakeOrder(name)
|
||||||
scheduler.TaskRunner(res.create)()
|
scheduler.TaskRunner(res.create)()
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ class TestOrder(common.HeatTestCase):
|
|||||||
res = self._create_resource('foo', self.res_template, self.stack)
|
res = self._create_resource('foo', self.res_template, self.stack)
|
||||||
expected_state = (res.CREATE, res.COMPLETE)
|
expected_state = (res.CREATE, res.COMPLETE)
|
||||||
self.assertEqual(expected_state, res.state)
|
self.assertEqual(expected_state, res.state)
|
||||||
args = self.barbican.orders.Order.call_args[1]
|
args = self.barbican.orders.create_key.call_args[1]
|
||||||
self.assertEqual('foobar-order', args['name'])
|
self.assertEqual('foobar-order', args['name'])
|
||||||
self.assertEqual('aes', args['algorithm'])
|
self.assertEqual('aes', args['algorithm'])
|
||||||
self.assertEqual('cbc', args['mode'])
|
self.assertEqual('cbc', args['mode'])
|
||||||
@ -98,7 +98,7 @@ class TestOrder(common.HeatTestCase):
|
|||||||
mock_order.secret_ref = 'test-secret-ref'
|
mock_order.secret_ref = 'test-secret-ref'
|
||||||
|
|
||||||
res = self._create_resource('foo', self.res_template, self.stack)
|
res = self._create_resource('foo', self.res_template, self.stack)
|
||||||
self.barbican.orders.Order.return_value = mock_order
|
self.barbican.orders.get.return_value = mock_order
|
||||||
|
|
||||||
self.assertEqual('test-order-ref', res.FnGetAtt('order_ref'))
|
self.assertEqual('test-order-ref', res.FnGetAtt('order_ref'))
|
||||||
self.assertEqual('test-secret-ref', res.FnGetAtt('secret_ref'))
|
self.assertEqual('test-secret-ref', res.FnGetAtt('secret_ref'))
|
||||||
@ -106,15 +106,15 @@ class TestOrder(common.HeatTestCase):
|
|||||||
def test_attributes_handle_exceptions(self):
|
def test_attributes_handle_exceptions(self):
|
||||||
mock_order = mock.Mock()
|
mock_order = mock.Mock()
|
||||||
res = self._create_resource('foo', self.res_template, self.stack)
|
res = self._create_resource('foo', self.res_template, self.stack)
|
||||||
self.barbican.orders.Order.return_value = mock_order
|
self.barbican.orders.get.return_value = mock_order
|
||||||
|
|
||||||
self.barbican.barbican_client.HTTPClientError = Exception
|
self.barbican.barbican_client.HTTPClientError = Exception
|
||||||
self.barbican.orders.Order.side_effect = Exception('boom')
|
self.barbican.orders.get.side_effect = Exception('boom')
|
||||||
self.assertRaises(self.barbican.barbican_client.HTTPClientError,
|
self.assertRaises(self.barbican.barbican_client.HTTPClientError,
|
||||||
res.FnGetAtt, 'order_ref')
|
res.FnGetAtt, 'order_ref')
|
||||||
|
|
||||||
def test_create_order_sets_resource_id(self):
|
def test_create_order_sets_resource_id(self):
|
||||||
self.barbican.orders.Order.return_value = FakeOrder('foo')
|
self.barbican.orders.create_key.return_value = FakeOrder('foo')
|
||||||
res = self._create_resource('foo', self.res_template, self.stack)
|
res = self._create_resource('foo', self.res_template, self.stack)
|
||||||
|
|
||||||
self.assertEqual('foo', res.resource_id)
|
self.assertEqual('foo', res.resource_id)
|
||||||
@ -122,7 +122,7 @@ class TestOrder(common.HeatTestCase):
|
|||||||
def test_create_order_defaults_to_octet_stream(self):
|
def test_create_order_defaults_to_octet_stream(self):
|
||||||
res = self._create_resource('foo', self.res_template, self.stack)
|
res = self._create_resource('foo', self.res_template, self.stack)
|
||||||
|
|
||||||
args = self.barbican.orders.Order.call_args[1]
|
args = self.barbican.orders.create_key.call_args[1]
|
||||||
self.assertEqual('application/octet-stream',
|
self.assertEqual('application/octet-stream',
|
||||||
args[res.PAYLOAD_CONTENT_TYPE])
|
args[res.PAYLOAD_CONTENT_TYPE])
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ class TestOrder(common.HeatTestCase):
|
|||||||
self.props)
|
self.props)
|
||||||
res = self._create_resource(defn.name, defn, self.stack)
|
res = self._create_resource(defn.name, defn, self.stack)
|
||||||
|
|
||||||
args = self.barbican.orders.Order.call_args[1]
|
args = self.barbican.orders.create_key.call_args[1]
|
||||||
self.assertEqual(content_type, args[res.PAYLOAD_CONTENT_TYPE])
|
self.assertEqual(content_type, args[res.PAYLOAD_CONTENT_TYPE])
|
||||||
|
|
||||||
def test_create_order_other_content_types_now_allowed(self):
|
def test_create_order_other_content_types_now_allowed(self):
|
||||||
@ -146,7 +146,7 @@ class TestOrder(common.HeatTestCase):
|
|||||||
scheduler.TaskRunner(res.create))
|
scheduler.TaskRunner(res.create))
|
||||||
|
|
||||||
def test_delete_order(self):
|
def test_delete_order(self):
|
||||||
self.barbican.orders.Order.return_value = 'foo'
|
self.barbican.orders.create_key.return_value = 'foo'
|
||||||
res = self._create_resource('foo', self.res_template, self.stack)
|
res = self._create_resource('foo', self.res_template, self.stack)
|
||||||
self.assertEqual('foo', res.resource_id)
|
self.assertEqual('foo', res.resource_id)
|
||||||
|
|
||||||
@ -176,16 +176,16 @@ class TestOrder(common.HeatTestCase):
|
|||||||
res = order.Order('foo', self.res_template, self.stack)
|
res = order.Order('foo', self.res_template, self.stack)
|
||||||
|
|
||||||
mock_active = mock.Mock(status='ACTIVE')
|
mock_active = mock.Mock(status='ACTIVE')
|
||||||
self.barbican.orders.Order.return_value = mock_active
|
self.barbican.orders.get.return_value = mock_active
|
||||||
self.assertTrue(res.check_create_complete('foo'))
|
self.assertTrue(res.check_create_complete('foo'))
|
||||||
|
|
||||||
mock_not_active = mock.Mock(status='PENDING')
|
mock_not_active = mock.Mock(status='PENDING')
|
||||||
self.barbican.orders.Order.return_value = mock_not_active
|
self.barbican.orders.get.return_value = mock_not_active
|
||||||
self.assertFalse(res.check_create_complete('foo'))
|
self.assertFalse(res.check_create_complete('foo'))
|
||||||
|
|
||||||
mock_not_active = mock.Mock(status='ERROR', error_reason='foo',
|
mock_not_active = mock.Mock(status='ERROR', error_reason='foo',
|
||||||
error_status_code=500)
|
error_status_code=500)
|
||||||
self.barbican.orders.Order.return_value = mock_not_active
|
self.barbican.orders.get.return_value = mock_not_active
|
||||||
exc = self.assertRaises(exception.Error,
|
exc = self.assertRaises(exception.Error,
|
||||||
res.check_create_complete, 'foo')
|
res.check_create_complete, 'foo')
|
||||||
self.assertIn('foo', six.text_type(exc))
|
self.assertIn('foo', six.text_type(exc))
|
||||||
|
@ -73,20 +73,20 @@ class TestSecret(common.HeatTestCase):
|
|||||||
|
|
||||||
def _create_resource(self, name, snippet, stack):
|
def _create_resource(self, name, snippet, stack):
|
||||||
res = secret.Secret(name, snippet, stack)
|
res = secret.Secret(name, snippet, stack)
|
||||||
self.barbican.secrets.Secret.return_value = FakeSecret(name + '_id')
|
self.barbican.secrets.create.return_value = FakeSecret(name + '_id')
|
||||||
scheduler.TaskRunner(res.create)()
|
scheduler.TaskRunner(res.create)()
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def test_create_secret(self):
|
def test_create_secret(self):
|
||||||
expected_state = (self.res.CREATE, self.res.COMPLETE)
|
expected_state = (self.res.CREATE, self.res.COMPLETE)
|
||||||
self.assertEqual(expected_state, self.res.state)
|
self.assertEqual(expected_state, self.res.state)
|
||||||
args = self.barbican.secrets.Secret.call_args[1]
|
args = self.barbican.secrets.create.call_args[1]
|
||||||
self.assertEqual('foobar-secret', args['name'])
|
self.assertEqual('foobar-secret', args['name'])
|
||||||
|
|
||||||
def test_attributes(self):
|
def test_attributes(self):
|
||||||
mock_secret = mock.Mock()
|
mock_secret = mock.Mock()
|
||||||
mock_secret.status = 'test-status'
|
mock_secret.status = 'test-status'
|
||||||
self.barbican.secrets.Secret.return_value = mock_secret
|
self.barbican.secrets.get.return_value = mock_secret
|
||||||
mock_secret.payload = 'foo'
|
mock_secret.payload = 'foo'
|
||||||
|
|
||||||
self.assertEqual('test-status', self.res.FnGetAtt('status'))
|
self.assertEqual('test-status', self.res.FnGetAtt('status'))
|
||||||
@ -94,7 +94,7 @@ class TestSecret(common.HeatTestCase):
|
|||||||
|
|
||||||
def test_attributes_handles_exceptions(self):
|
def test_attributes_handles_exceptions(self):
|
||||||
self.barbican.barbican_client.HTTPClientError = Exception
|
self.barbican.barbican_client.HTTPClientError = Exception
|
||||||
self.barbican.secrets.Secret.side_effect = Exception('boom')
|
self.barbican.secrets.get.side_effect = Exception('boom')
|
||||||
self.assertRaises(self.barbican.barbican_client.HTTPClientError,
|
self.assertRaises(self.barbican.barbican_client.HTTPClientError,
|
||||||
self.res.FnGetAtt, 'order_ref')
|
self.res.FnGetAtt, 'order_ref')
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ class TestSecret(common.HeatTestCase):
|
|||||||
props)
|
props)
|
||||||
res = self._create_resource(defn.name, defn, self.stack)
|
res = self._create_resource(defn.name, defn, self.stack)
|
||||||
|
|
||||||
args = self.barbican.secrets.Secret.call_args[1]
|
args = self.barbican.secrets.create.call_args[1]
|
||||||
self.assertEqual('foobar', args[res.PAYLOAD])
|
self.assertEqual('foobar', args[res.PAYLOAD])
|
||||||
self.assertEqual(content_type, args[res.PAYLOAD_CONTENT_TYPE])
|
self.assertEqual(content_type, args[res.PAYLOAD_CONTENT_TYPE])
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ class TestSecret(common.HeatTestCase):
|
|||||||
props)
|
props)
|
||||||
res = self._create_resource(defn.name, defn, self.stack)
|
res = self._create_resource(defn.name, defn, self.stack)
|
||||||
|
|
||||||
args = self.barbican.secrets.Secret.call_args[1]
|
args = self.barbican.secrets.create.call_args[1]
|
||||||
self.assertEqual('foobar', args[res.PAYLOAD])
|
self.assertEqual('foobar', args[res.PAYLOAD])
|
||||||
self.assertEqual(content_type, args[res.PAYLOAD_CONTENT_TYPE])
|
self.assertEqual(content_type, args[res.PAYLOAD_CONTENT_TYPE])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user