Merge "Add barbicanclient support in Magnum."

This commit is contained in:
Jenkins
2015-08-12 09:03:09 +00:00
committed by Gerrit Code Review
5 changed files with 107 additions and 0 deletions
+15
View File
@@ -237,6 +237,21 @@
#max_limit = 1000
[barbican_client]
#
# From magnum
#
# Region in Identity service catalog to use for communication with the
# OpenStack service. (string value)
#region_name = <None>
# Type of endpoint in Identity service catalog to use for
# communication with the OpenStack service. (string value)
#endpoint_type = publicURL
[bay]
#
+30
View File
@@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from barbicanclient import client as barbicanclient
from glanceclient.v2 import client as glanceclient
from heatclient.v1 import client as heatclient
from oslo_config import cfg
@@ -69,9 +70,21 @@ glance_client_opts = [
'Type of endpoint in Identity service catalog to use '
'for communication with the OpenStack service.'))]
barbican_client_opts = [
cfg.StrOpt('region_name',
default=None,
help=_('Region in Identity service catalog to use for '
'communication with the OpenStack service.')),
cfg.StrOpt('endpoint_type',
default='publicURL',
help=_(
'Type of endpoint in Identity service catalog to use '
'for communication with the OpenStack service.'))]
cfg.CONF.register_opts(magnum_client_opts, group='magnum_client')
cfg.CONF.register_opts(heat_client_opts, group='heat_client')
cfg.CONF.register_opts(glance_client_opts, group='glance_client')
cfg.CONF.register_opts(barbican_client_opts, group='barbican_client')
class OpenStackClients(object):
@@ -82,6 +95,7 @@ class OpenStackClients(object):
self._keystone = None
self._heat = None
self._glance = None
self._barbican = None
def url_for(self, **kwargs):
return self.keystone().client.service_catalog.url_for(**kwargs)
@@ -157,3 +171,19 @@ class OpenStackClients(object):
self._glance = glanceclient.Client(**args)
return self._glance
@exception.wrap_keystone_exception
def barbican(self):
if self._barbican:
return self._barbican
endpoint_type = self._get_client_option('barbican', 'endpoint_type')
region_name = self._get_client_option('barbican', 'region_name')
endpoint = self.url_for(service_type='key-manager',
endpoint_type=endpoint_type,
region_name=region_name)
session = self.keystone()._client.session
self._barbican = barbicanclient.Client(session=session,
endpoint=endpoint)
return self._barbican
+1
View File
@@ -45,6 +45,7 @@ def list_opts():
('magnum_client', magnum.common.clients.magnum_client_opts),
('heat_client', magnum.common.clients.heat_client_opts),
('glance_client', magnum.common.clients.glance_client_opts),
('barbican_client', magnum.common.clients.barbican_client_opts),
('bay_heat', magnum.conductor.handlers.bay_conductor.bay_heat_opts),
('kubernetes',
magnum.conductor.k8s_api.kubernetes_opts),
+60
View File
@@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from barbicanclient import client as barbicanclient
from glanceclient.v2 import client as glanceclient
from heatclient.v1 import client as heatclient
import mock
@@ -158,3 +159,62 @@ class ClientsTest(base.BaseTestCase):
glance = obj.glance()
glance_cached = obj.glance()
self.assertEqual(glance, glance_cached)
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(barbicanclient, 'Client')
@mock.patch.object(clients.OpenStackClients, 'url_for')
def _test_clients_barbican(self, expected_region_name, mock_url,
mock_call, mock_keystone):
con = mock.MagicMock()
con.auth_url = "keystone_url"
mock_url.return_value = "url_from_keystone"
keystone = mock.MagicMock()
keystone._client.session = mock.MagicMock()
mock_keystone.return_value = keystone
obj = clients.OpenStackClients(con)
obj._barbican = None
obj.barbican()
mock_call.assert_called_once_with(
endpoint='url_from_keystone',
session=keystone._client.session)
mock_keystone.assert_called_once_with()
mock_url.assert_called_once_with(service_type='key-manager',
endpoint_type='publicURL',
region_name=expected_region_name)
def test_clients_barbican(self):
self._test_clients_barbican(None)
def test_clients_barbican_region(self):
cfg.CONF.set_override('region_name', 'myregion',
group='barbican_client')
self._test_clients_barbican('myregion')
def test_clients_barbican_noauth(self):
con = mock.MagicMock()
con.auth_token = None
con.auth_token_info = None
auth_url = mock.PropertyMock(name="auth_url",
return_value="keystone_url")
type(con).auth_url = auth_url
con.get_url_for = mock.Mock(name="get_url_for")
con.get_url_for.return_value = "url_from_keystone"
obj = clients.OpenStackClients(con)
obj._barbican = None
self.assertRaises(exception.AuthorizationFailure, obj.barbican)
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(clients.OpenStackClients, 'url_for')
def test_clients_barbican_cached(self, mock_url, mock_keystone):
con = mock.MagicMock()
con.auth_url = "keystone_url"
mock_url.return_value = "url_from_keystone"
keystone = mock.MagicMock()
keystone._client.session = mock.MagicMock()
mock_keystone.return_value = keystone
obj = clients.OpenStackClients(con)
obj._barbican = None
barbican = obj.barbican()
barbican_cached = obj.barbican()
self.assertEqual(barbican, barbican_cached)
+1
View File
@@ -35,6 +35,7 @@ oslo.reports>=0.1.0 # Apache-2.0
paramiko>=1.13.0
pbr<2.0,>=1.4
pecan>=0.8.0
python-barbicanclient>=3.0.1
python-glanceclient>=0.18.0
python-heatclient>=0.3.0
python-keystoneclient>=1.6.0