Fix barbican resources
Various fixes to barbican resources: * Handle change in keystone management * Fix exception handling * Remove outdated validation Change-Id: I0c582fc8ec5b17079735411fb8c365fab4d3a697
This commit is contained in:
parent
1664382aea
commit
798ed7f3d4
|
@ -23,13 +23,11 @@ except ImportError:
|
|||
class BarbicanClientPlugin(client_plugin.ClientPlugin):
|
||||
|
||||
def _create(self):
|
||||
keystone_client = self.clients.client('keystone').client
|
||||
endpoint_type = self._get_client_option('barbican', 'endpoint_type')
|
||||
endpoint = self.url_for(service_type='key-manager',
|
||||
endpoint_type=endpoint_type)
|
||||
# Remove version if set
|
||||
endpoint = endpoint.rsplit("/", 1)[0]
|
||||
self._keystone_session.auth = self.context.auth_plugin
|
||||
client = barbican_client.Client(
|
||||
session=keystone_client.session, endpoint=endpoint)
|
||||
session=self._keystone_session, endpoint=endpoint)
|
||||
|
||||
return client
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
from heat.common import exception
|
||||
|
@ -23,9 +22,6 @@ from heat.engine import properties
|
|||
from heat.engine import resource
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Order(resource.Resource):
|
||||
|
||||
PROPERTIES = (
|
||||
|
@ -133,7 +129,7 @@ class Order(resource.Resource):
|
|||
client = self.barbican()
|
||||
try:
|
||||
client.orders.delete(self.resource_id)
|
||||
except client.barbican_client.HTTPClientError as exc:
|
||||
except Exception as exc:
|
||||
# This is the only exception the client raises
|
||||
# Inspecting the message to see if it's a 'Not Found'
|
||||
if 'Not Found' not in six.text_type(exc):
|
||||
|
|
|
@ -11,10 +11,8 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
from heat.common import exception
|
||||
from heat.common.i18n import _
|
||||
from heat.engine import attributes
|
||||
from heat.engine import clients
|
||||
|
@ -23,9 +21,6 @@ from heat.engine import properties
|
|||
from heat.engine import resource
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Secret(resource.Resource):
|
||||
|
||||
PROPERTIES = (
|
||||
|
@ -64,7 +59,6 @@ class Secret(resource.Resource):
|
|||
PAYLOAD_CONTENT_ENCODING: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('The encoding format used to provide the payload data.'),
|
||||
default='base64',
|
||||
constraints=[
|
||||
constraints.AllowedValues([
|
||||
'base64',
|
||||
|
@ -110,20 +104,6 @@ class Secret(resource.Resource):
|
|||
def barbican(self):
|
||||
return self.client('barbican')
|
||||
|
||||
def validate(self):
|
||||
super(Secret, self).validate()
|
||||
self._validate_payload()
|
||||
|
||||
def _validate_payload(self):
|
||||
'''Payload is optional, but requires content type if provided.'''
|
||||
|
||||
payload = self.properties.get(self.PAYLOAD)
|
||||
content_type = self.properties.get(self.PAYLOAD_CONTENT_TYPE)
|
||||
if bool(payload) != bool(content_type):
|
||||
msg = _("'payload' and 'payload_content_type' must both be "
|
||||
"provided or omitted.")
|
||||
raise exception.StackValidationFailed(message=msg)
|
||||
|
||||
def handle_create(self):
|
||||
info = dict(self.properties)
|
||||
secret = self.barbican().secrets.create(**info)
|
||||
|
@ -138,7 +118,7 @@ class Secret(resource.Resource):
|
|||
client = self.barbican()
|
||||
try:
|
||||
client.secrets.delete(self.resource_id)
|
||||
except client.barbican_client.HTTPClientError as exc:
|
||||
except Exception as exc:
|
||||
# This is the only exception the client raises
|
||||
# Inspecting the message to see if it's a 'Not Found'
|
||||
if 'Not Found' not in six.text_type(exc):
|
||||
|
|
|
@ -144,23 +144,6 @@ class TestSecret(common.HeatTestCase):
|
|||
self._create_resource, defn.name, defn,
|
||||
self.stack)
|
||||
|
||||
def test_validate_payload_and_content_type(self):
|
||||
props = {'payload_content_type': 'text/plain'}
|
||||
defn = rsrc_defn.ResourceDefinition('nopayload',
|
||||
'OS::Barbican::Secret',
|
||||
props)
|
||||
res = self._create_resource(defn.name, defn, self.stack)
|
||||
exc = self.assertRaises(exception.StackValidationFailed, res.validate)
|
||||
self.assertIn('payload', six.text_type(exc))
|
||||
self.assertIn('payload_content_type', six.text_type(exc))
|
||||
|
||||
defn = rsrc_defn.ResourceDefinition('notype', 'OS::Barbican::Secret',
|
||||
{'payload': 'foo'})
|
||||
res = self._create_resource(defn.name, defn, self.stack)
|
||||
exc = self.assertRaises(exception.StackValidationFailed, res.validate)
|
||||
self.assertIn('payload', six.text_type(exc))
|
||||
self.assertIn('payload_content_type', six.text_type(exc))
|
||||
|
||||
def test_delete_secret(self):
|
||||
self.assertEqual('foo_id', self.res.resource_id)
|
||||
|
||||
|
|
Loading…
Reference in New Issue