Merge "Move keystone resources in-tree"

This commit is contained in:
Jenkins 2015-06-03 01:58:37 +00:00 committed by Gerrit Code Review
commit fcc176b913
26 changed files with 154 additions and 321 deletions

View File

@ -1,33 +0,0 @@
Keystone plugin for OpenStack heat
==================================
This plugin enables keystone resources in a heat template for
following resources types:
- Keystone role (OS::Keystone::Role)
- Keystone project (OS::Keystone::Project)
- Keystone group (OS::Keystone::Group)
- Keystone user (OS::Keystone::User)
- Keystone service (OS::Keystone::Service)
- Keystone endpoint (OS::Keystone::Endpoint)
And it provides custom constrains for following keystone entities
- Keystone role
- Keystone domain
- Keystone project
- Keystone group
- Keystone service
NOTE: It supports only keystone v3 version
### 1. Install the keystone plugin in heat
NOTE: These instructions assume the value of heat.conf plugin_dirs includes
the default directory /usr/lib/heat.
To install the plugin, from this directory run:
sudo python ./setup.py install
### 2. Restart heat
Only the process "heat-engine" needs to be restarted to load the newly
installed plugin.

View File

@ -1,125 +0,0 @@
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import exceptions
from keystoneclient import exceptions as keystone_exceptions
from heat.engine.clients.os import keystone
from heat.engine import constraints
class KeystoneClientPlugin(keystone.KeystoneClientPlugin):
def get_role_id(self, role):
try:
role_obj = self.client().client.roles.get(role)
return role_obj.id
except keystone_exceptions.NotFound:
role_list = self.client().client.roles.list(name=role)
for role_obj in role_list:
if role_obj.name == role:
return role_obj.id
raise exceptions.KeystoneRoleNotFound(role_id=role)
def get_project_id(self, project):
try:
project_obj = self.client().client.projects.get(project)
return project_obj.id
except keystone_exceptions.NotFound:
project_list = self.client().client.projects.list(name=project)
for project_obj in project_list:
if project_obj.name == project:
return project_obj.id
raise exceptions.KeystoneProjectNotFound(project_id=project)
def get_domain_id(self, domain):
try:
domain_obj = self.client().client.domains.get(domain)
return domain_obj.id
except keystone_exceptions.NotFound:
domain_list = self.client().client.domains.list(name=domain)
for domain_obj in domain_list:
if domain_obj.name == domain:
return domain_obj.id
raise exceptions.KeystoneDomainNotFound(domain_id=domain)
def get_group_id(self, group):
try:
group_obj = self.client().client.groups.get(group)
return group_obj.id
except keystone_exceptions.NotFound:
group_list = self.client().client.groups.list(name=group)
for group_obj in group_list:
if group_obj.name == group:
return group_obj.id
raise exceptions.KeystoneGroupNotFound(group_id=group)
def get_service_id(self, service):
try:
service_obj = self.client().client.services.get(service)
return service_obj.id
except keystone_exceptions.NotFound:
service_list = self.client().client.services.list(name=service)
if len(service_list) == 1:
return service_list[0].id
elif len(service_list) > 1:
raise exceptions.KeystoneServiceNameConflict(service=service)
else:
raise exceptions.KeystoneServiceNotFound(service_id=service)
class KeystoneRoleConstraint(constraints.BaseCustomConstraint):
expected_exceptions = (exceptions.KeystoneRoleNotFound,)
def validate_with_client(self, client, role):
client.client_plugin('keystone').get_role_id(role)
class KeystoneDomainConstraint(constraints.BaseCustomConstraint):
expected_exceptions = (exceptions.KeystoneDomainNotFound,)
def validate_with_client(self, client, domain):
client.client_plugin('keystone').get_domain_id(domain)
class KeystoneProjectConstraint(constraints.BaseCustomConstraint):
expected_exceptions = (exceptions.KeystoneProjectNotFound,)
def validate_with_client(self, client, project):
client.client_plugin('keystone').get_project_id(project)
class KeystoneGroupConstraint(constraints.BaseCustomConstraint):
expected_exceptions = (exceptions.KeystoneGroupNotFound,)
def validate_with_client(self, client, group):
client.client_plugin('keystone').get_group_id(group)
class KeystoneServiceConstraint(constraints.BaseCustomConstraint):
expected_exceptions = (exceptions.KeystoneServiceNotFound,
exceptions.KeystoneServiceNameConflict,)
def validate_with_client(self, client, service):
client.client_plugin('keystone').get_service_id(service)

View File

@ -1,40 +0,0 @@
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from heat.common import exception
from heat.common.i18n import _
class KeystoneRoleNotFound(exception.HeatException):
msg_fmt = _("Keystone role %(role_id)s does not found")
class KeystoneProjectNotFound(exception.HeatException):
msg_fmt = _("Keystone project %(project_id)s does not found")
class KeystoneDomainNotFound(exception.HeatException):
msg_fmt = _("Keystone domain %(domain_id)s does not found")
class KeystoneGroupNotFound(exception.HeatException):
msg_fmt = _("Keystone group %(group_id)s does not found")
class KeystoneServiceNotFound(exception.HeatException):
msg_fmt = _("Keystone service %(service_id)s does not found")
class KeystoneServiceNameConflict(exception.HeatException):
msg_fmt = _("Keystone has more than one service with same name "
"%(service)s. Please use service id instead of name")

View File

@ -1,42 +0,0 @@
[metadata]
name = heat-contrib-keystone
summary = Heat resources for Keystone
description-file =
README.md
author = OpenStack
author-email = openstack-dev@lists.openstack.org
home-page = http://www.openstack.org/
classifier =
Environment :: OpenStack
Intended Audience :: Information Technology
Intended Audience :: System Administrators
License :: OSI Approved :: Apache Software License
Operating System :: POSIX :: Linux
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 2.6
[files]
packages =
heat_keystone
# Copy to /usr/lib/heat for plugin loading
data_files =
lib/heat/keystone = heat_keystone/resources/*
[entry_points]
heat.clients =
keystone=heat_keystone.client:KeystoneClientPlugin
heat.constraints =
keystone.role=heat_keystone.client:KeystoneRoleConstraint
keystone.domain=heat_keystone.client:KeystoneDomainConstraint
keystone.project=heat_keystone.client:KeystoneProjectConstraint
keystone.group=heat_keystone.client:KeystoneGroupConstraint
keystone.service=heat_keystone.client:KeystoneServiceConstraint
[global]
setup-hooks =
pbr.hooks.setup_hook

View File

@ -1,29 +0,0 @@
#!/usr/bin/env python
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT
import setuptools
# In python < 2.7.4, a lazy loading of package `pbr` will break
# setuptools if some other modules registered functions in `atexit`.
# solution from: http://bugs.python.org/issue15881#msg170215
try:
import multiprocessing # noqa
except ImportError:
pass
setuptools.setup(
setup_requires=['pbr'],
pbr=True)

View File

@ -456,7 +456,7 @@ class EventSendFailed(HeatException):
class ServiceNotFound(HeatException):
msg_fmt = _("Service %(service_id)s does not found")
msg_fmt = _("Service %(service_id)s not found")
class UnsupportedObjectError(HeatException):
@ -481,3 +481,28 @@ class ReadOnlyFieldError(HeatException):
class ObjectFieldInvalid(HeatException):
msg_fmt = _('Field %(field)s of %(objname)s is not an instance of Field')
class KeystoneRoleNotFound(HeatException):
msg_fmt = _("Keystone role %(role_id)s not found")
class KeystoneProjectNotFound(HeatException):
msg_fmt = _("Keystone project %(project_id)s not found")
class KeystoneDomainNotFound(HeatException):
msg_fmt = _("Keystone domain %(domain_id)s not found")
class KeystoneGroupNotFound(HeatException):
msg_fmt = _("Keystone group %(group_id)s not found")
class KeystoneServiceNotFound(HeatException):
msg_fmt = _("Keystone service %(service_id)s not found")
class KeystoneServiceNameConflict(HeatException):
msg_fmt = _("Keystone has more than one service with same name "
"%(service)s. Please use service id instead of name")

View File

@ -13,8 +13,10 @@
from keystoneclient import exceptions
from heat.common import exception
from heat.common import heat_keystoneclient as hkc
from heat.engine.clients import client_plugin
from heat.engine import constraints
class KeystoneClientPlugin(client_plugin.ClientPlugin):
@ -32,3 +34,106 @@ class KeystoneClientPlugin(client_plugin.ClientPlugin):
def is_conflict(self, ex):
return isinstance(ex, exceptions.Conflict)
def get_role_id(self, role):
try:
role_obj = self.client().client.roles.get(role)
return role_obj.id
except exceptions.NotFound:
role_list = self.client().client.roles.list(name=role)
for role_obj in role_list:
if role_obj.name == role:
return role_obj.id
raise exception.KeystoneRoleNotFound(role_id=role)
def get_project_id(self, project):
try:
project_obj = self.client().client.projects.get(project)
return project_obj.id
except exceptions.NotFound:
project_list = self.client().client.projects.list(name=project)
for project_obj in project_list:
if project_obj.name == project:
return project_obj.id
raise exception.KeystoneProjectNotFound(project_id=project)
def get_domain_id(self, domain):
try:
domain_obj = self.client().client.domains.get(domain)
return domain_obj.id
except exceptions.NotFound:
domain_list = self.client().client.domains.list(name=domain)
for domain_obj in domain_list:
if domain_obj.name == domain:
return domain_obj.id
raise exception.KeystoneDomainNotFound(domain_id=domain)
def get_group_id(self, group):
try:
group_obj = self.client().client.groups.get(group)
return group_obj.id
except exceptions.NotFound:
group_list = self.client().client.groups.list(name=group)
for group_obj in group_list:
if group_obj.name == group:
return group_obj.id
raise exception.KeystoneGroupNotFound(group_id=group)
def get_service_id(self, service):
try:
service_obj = self.client().client.services.get(service)
return service_obj.id
except exceptions.NotFound:
service_list = self.client().client.services.list(name=service)
if len(service_list) == 1:
return service_list[0].id
elif len(service_list) > 1:
raise exception.KeystoneServiceNameConflict(service=service)
else:
raise exception.KeystoneServiceNotFound(service_id=service)
class KeystoneRoleConstraint(constraints.BaseCustomConstraint):
expected_exceptions = (exception.KeystoneRoleNotFound,)
def validate_with_client(self, client, role):
client.client_plugin('keystone').get_role_id(role)
class KeystoneDomainConstraint(constraints.BaseCustomConstraint):
expected_exceptions = (exception.KeystoneDomainNotFound,)
def validate_with_client(self, client, domain):
client.client_plugin('keystone').get_domain_id(domain)
class KeystoneProjectConstraint(constraints.BaseCustomConstraint):
expected_exceptions = (exception.KeystoneProjectNotFound,)
def validate_with_client(self, client, project):
client.client_plugin('keystone').get_project_id(project)
class KeystoneGroupConstraint(constraints.BaseCustomConstraint):
expected_exceptions = (exception.KeystoneGroupNotFound,)
def validate_with_client(self, client, group):
client.client_plugin('keystone').get_group_id(group)
class KeystoneServiceConstraint(constraints.BaseCustomConstraint):
expected_exceptions = (exception.KeystoneServiceNotFound,
exception.KeystoneServiceNameConflict,)
def validate_with_client(self, client, service):
client.client_plugin('keystone').get_service_id(service)

View File

@ -16,15 +16,15 @@ import six
from keystoneclient import exceptions as keystone_exceptions
from .. import client # noqa
from .. import exceptions # noqa
from heat.common import exception
from heat.engine.clients.os import keystone as client
from heat.tests import common
class KeystoneRoleConstraintTest(common.HeatTestCase):
def test_expected_exceptions(self):
self.assertEqual((exceptions.KeystoneRoleNotFound,),
self.assertEqual((exception.KeystoneRoleNotFound,),
client.KeystoneRoleConstraint.expected_exceptions,
"KeystoneRoleConstraint expected exceptions error")
@ -44,7 +44,7 @@ class KeystoneRoleConstraintTest(common.HeatTestCase):
class KeystoneProjectConstraintTest(common.HeatTestCase):
def test_expected_exceptions(self):
self.assertEqual((exceptions.KeystoneProjectNotFound,),
self.assertEqual((exception.KeystoneProjectNotFound,),
client.KeystoneProjectConstraint.expected_exceptions,
"KeystoneProjectConstraint expected exceptions error")
@ -64,7 +64,7 @@ class KeystoneProjectConstraintTest(common.HeatTestCase):
class KeystoneGroupConstraintTest(common.HeatTestCase):
def test_expected_exceptions(self):
self.assertEqual((exceptions.KeystoneGroupNotFound,),
self.assertEqual((exception.KeystoneGroupNotFound,),
client.KeystoneGroupConstraint.expected_exceptions,
"KeystoneGroupConstraint expected exceptions error")
@ -84,7 +84,7 @@ class KeystoneGroupConstraintTest(common.HeatTestCase):
class KeystoneDomainConstraintTest(common.HeatTestCase):
def test_expected_exceptions(self):
self.assertEqual((exceptions.KeystoneDomainNotFound,),
self.assertEqual((exception.KeystoneDomainNotFound,),
client.KeystoneDomainConstraint.expected_exceptions,
"KeystoneDomainConstraint expected exceptions error")
@ -106,8 +106,8 @@ class KeystoneServiceConstraintTest(common.HeatTestCase):
sample_uuid = '477e8273-60a7-4c41-b683-fdb0bc7cd151'
def test_expected_exceptions(self):
self.assertEqual((exceptions.KeystoneServiceNotFound,
exceptions.KeystoneServiceNameConflict,),
self.assertEqual((exception.KeystoneServiceNotFound,
exception.KeystoneServiceNameConflict,),
client.KeystoneServiceConstraint.expected_exceptions,
"KeystoneServiceConstraint expected exceptions error")
@ -187,7 +187,7 @@ class KeystoneClientPluginServiceTest(common.HeatTestCase):
context=mock.MagicMock()
)
ex = self.assertRaises(exceptions.KeystoneServiceNameConflict,
ex = self.assertRaises(exception.KeystoneServiceNameConflict,
client_plugin.get_service_id,
self.sample_name)
msg = ("Keystone has more than one service with same name "
@ -207,9 +207,9 @@ class KeystoneClientPluginServiceTest(common.HeatTestCase):
context=mock.MagicMock()
)
ex = self.assertRaises(exceptions.KeystoneServiceNotFound,
ex = self.assertRaises(exception.KeystoneServiceNotFound,
client_plugin.get_service_id,
self.sample_name)
msg = ("Keystone service %s does not found" %
msg = ("Keystone service %s not found" %
self.sample_name)
self.assertEqual(msg, six.text_type(ex))

View File

@ -15,14 +15,12 @@ import mock
from heat.engine import constraints
from heat.engine import properties
from heat.engine import resource
from heat.engine.resources.openstack.keystone import endpoint
from heat.engine import stack
from heat.engine import template
from heat.tests import common
from heat.tests import utils
from ..resources import endpoint # noqa
keystone_endpoint_template = {
'heat_template_version': '2015-04-30',
'resources': {
@ -48,10 +46,6 @@ class KeystoneEndpointTest(common.HeatTestCase):
self.ctx = utils.dummy_context()
# For unit testing purpose. Register resource provider explicitly.
resource._register_class(RESOURCE_TYPE,
endpoint.KeystoneEndpoint)
self.stack = stack.Stack(
self.ctx, 'test_stack_keystone',
template.Template(keystone_endpoint_template)

View File

@ -15,14 +15,12 @@ import mock
from heat.engine import constraints
from heat.engine import properties
from heat.engine import resource
from heat.engine.resources.openstack.keystone import group
from heat.engine import stack
from heat.engine import template
from heat.tests import common
from heat.tests import utils
from ..resources import group # noqa
keystone_group_template = {
'heat_template_version': '2013-05-23',
'resources': {
@ -46,9 +44,6 @@ class KeystoneGroupTest(common.HeatTestCase):
self.ctx = utils.dummy_context()
# For unit testing purpose. Register resource provider explicitly.
resource._register_class(RESOURCE_TYPE, group.KeystoneGroup)
self.stack = stack.Stack(
self.ctx, 'test_stack_keystone',
template.Template(keystone_group_template)

View File

@ -15,14 +15,12 @@ import mock
from heat.engine import constraints
from heat.engine import properties
from heat.engine import resource
from heat.engine.resources.openstack.keystone import project
from heat.engine import stack
from heat.engine import template
from heat.tests import common
from heat.tests import utils
from ..resources import project # noqa
keystone_project_template = {
'heat_template_version': '2013-05-23',
'resources': {
@ -47,9 +45,6 @@ class KeystoneProjectTest(common.HeatTestCase):
self.ctx = utils.dummy_context()
# For unit testing purpose. Register resource provider explicitly.
resource._register_class(RESOURCE_TYPE, project.KeystoneProject)
self.stack = stack.Stack(
self.ctx, 'test_stack_keystone',
template.Template(keystone_project_template)

View File

@ -13,14 +13,12 @@
import mock
from heat.engine import resource
from heat.engine.resources.openstack.keystone import role
from heat.engine import stack
from heat.engine import template
from heat.tests import common
from heat.tests import utils
from ..resources import role # noqa
keystone_role_template = {
'heat_template_version': '2013-05-23',
'resources': {
@ -42,9 +40,6 @@ class KeystoneRoleTest(common.HeatTestCase):
self.ctx = utils.dummy_context()
# For unit testing purpose. Register resource provider explicitly.
resource._register_class(RESOURCE_TYPE, role.KeystoneRole)
self.stack = stack.Stack(
self.ctx, 'test_stack_keystone',
template.Template(keystone_role_template)

View File

@ -16,13 +16,12 @@ import mock
from heat.common import exception
from heat.engine import properties
from heat.engine import resource
from heat.engine.resources.openstack.keystone import role_assignments
from heat.engine import stack
from heat.engine import template
from heat.tests import common
from heat.tests import utils
from ..resources import role_assignments # noqa
RESOURCE_TYPE = 'OS::Keystone::DummyRoleAssignment'
keystone_role_assignment_template = {

View File

@ -14,14 +14,12 @@
import mock
from heat.engine import properties
from heat.engine import resource
from heat.engine.resources.openstack.keystone import service
from heat.engine import stack
from heat.engine import template
from heat.tests import common
from heat.tests import utils
from ..resources import service # noqa
keystone_service_template = {
'heat_template_version': '2015-04-30',
'resources': {
@ -45,10 +43,6 @@ class KeystoneServiceTest(common.HeatTestCase):
self.ctx = utils.dummy_context()
# For unit testing purpose. Register resource provider explicitly.
resource._register_class(RESOURCE_TYPE,
service.KeystoneService)
self.stack = stack.Stack(
self.ctx, 'test_stack_keystone',
template.Template(keystone_service_template)

View File

@ -13,14 +13,12 @@
import mock
from heat.engine import resource
from heat.engine.resources.openstack.keystone import user
from heat.engine import stack
from heat.engine import template
from heat.tests import common
from heat.tests import utils
from ..resources import user # noqa
keystone_user_template = {
'heat_template_version': '2013-05-23',
'resources': {
@ -50,9 +48,6 @@ class KeystoneUserTest(common.HeatTestCase):
self.ctx = utils.dummy_context()
# For unit testing purpose. Register resource provider explicitly.
resource._register_class(RESOURCE_TYPE, user.KeystoneUser)
self.stack = stack.Stack(
self.ctx, 'test_stack_keystone',
template.Template(keystone_user_template)

View File

@ -77,6 +77,11 @@ heat.constraints =
ip_addr = heat.engine.clients.os.neutron:IPConstraint
mac_addr = heat.engine.clients.os.neutron:MACConstraint
net_cidr = heat.engine.clients.os.neutron:CIDRConstraint
keystone.role = heat.engine.clients.os.keystone:KeystoneRoleConstraint
keystone.domain = heat.engine.clients.os.keystone:KeystoneDomainConstraint
keystone.project = heat.engine.clients.os.keystone:KeystoneProjectConstraint
keystone.group = heat.engine.clients.os.keystone:KeystoneGroupConstraint
keystone.service = heat.engine.clients.os.keystone:KeystoneServiceConstraint
heat.stack_lifecycle_plugins =