Add glance client to solum
Glance client will be used to store LanguagePacks into glance using tags to filter them. Fixes bug 1301427 Change-Id: I7adc75babb4770976aa1462d45b7e1d01c64adb4
This commit is contained in:
@@ -488,6 +488,17 @@
|
||||
#wait_interval=5
|
||||
|
||||
|
||||
[glance_client]
|
||||
|
||||
#
|
||||
# Options defined in solum.common.clients
|
||||
#
|
||||
|
||||
# Type of endpoint in Identity service catalog to use for
|
||||
# communication with the Glance service. (string value)
|
||||
#endpoint_type=publicURL
|
||||
|
||||
|
||||
[heat_client]
|
||||
|
||||
#
|
||||
|
||||
@@ -7,6 +7,7 @@ oslo.config>=1.2.0
|
||||
oslo.messaging>=1.3.0a9
|
||||
pbr>=0.6,<1.0
|
||||
pecan>=0.4.5
|
||||
python-glanceclient>=0.9.0
|
||||
python-heatclient>=0.2.3
|
||||
python-keystoneclient>=0.7.0
|
||||
python-swiftclient>=1.6
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from glanceclient import client as glanceclient
|
||||
from heatclient import client as heatclient
|
||||
from keystoneclient.v2_0 import client as ksclient
|
||||
from oslo.config import cfg
|
||||
@@ -30,6 +31,13 @@ LOG = logging.getLogger(__name__)
|
||||
# There is a place holder bug here:
|
||||
# https://bugs.launchpad.net/solum/+bug/1292334
|
||||
# that we use to track this.
|
||||
glance_client_opts = [
|
||||
cfg.StrOpt('endpoint_type',
|
||||
default='publicURL',
|
||||
help=_(
|
||||
'Type of endpoint in Identity service catalog to use '
|
||||
'for communication with the Glance service.'))]
|
||||
|
||||
heat_client_opts = [
|
||||
cfg.StrOpt('endpoint_type',
|
||||
default='publicURL',
|
||||
@@ -48,7 +56,6 @@ heat_client_opts = [
|
||||
help=_("If set, then the server's certificate will not "
|
||||
"be verified."))]
|
||||
|
||||
|
||||
swift_client_opts = [
|
||||
cfg.StrOpt('endpoint_type',
|
||||
default='publicURL',
|
||||
@@ -61,6 +68,7 @@ swift_client_opts = [
|
||||
default=False,
|
||||
help=_("If set the server certificate will not be verified."))]
|
||||
|
||||
cfg.CONF.register_opts(glance_client_opts, group='glance_client')
|
||||
cfg.CONF.register_opts(heat_client_opts, group='heat_client')
|
||||
cfg.CONF.register_opts(swift_client_opts, group='swift_client')
|
||||
|
||||
@@ -71,6 +79,7 @@ class OpenStackClients(object):
|
||||
def __init__(self, context):
|
||||
self.context = context
|
||||
self._keystone = None
|
||||
self._glance = None
|
||||
self._heat = None
|
||||
self._swift = None
|
||||
|
||||
@@ -94,6 +103,21 @@ class OpenStackClients(object):
|
||||
def _get_client_option(self, client, option):
|
||||
return getattr(getattr(cfg.CONF, '%s_client' % client), option)
|
||||
|
||||
@exception.wrap_keystone_exception
|
||||
def glance(self):
|
||||
if self._glance:
|
||||
return self._glance
|
||||
|
||||
args = {
|
||||
'token': self.auth_token,
|
||||
}
|
||||
endpoint_type = self._get_client_option('glance', 'endpoint_type')
|
||||
endpoint = self.context.get_url_for(service_type='image',
|
||||
endpoint_type=endpoint_type)
|
||||
self._glance = glanceclient.Client('1', endpoint, **args)
|
||||
|
||||
return self._glance
|
||||
|
||||
@exception.wrap_keystone_exception
|
||||
def heat(self):
|
||||
if self._heat:
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
import mock
|
||||
|
||||
from glanceclient import client as glanceclient
|
||||
from heatclient import client as heatclient
|
||||
|
||||
from solum.common import clients
|
||||
@@ -22,6 +23,50 @@ from swiftclient import client as swiftclient
|
||||
|
||||
class ClientsTest(base.BaseTestCase):
|
||||
|
||||
@mock.patch.object(glanceclient, 'Client')
|
||||
def test_clients_glance(self, mock_call):
|
||||
con = mock.MagicMock()
|
||||
con.tenant = "b363706f891f48019483f8bd6503c54d"
|
||||
con.auth_token = "3bcc3d3a03f44e3d8377f9247b0ad155"
|
||||
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._glance = None
|
||||
obj.glance()
|
||||
mock_call.assert_called_once_with(
|
||||
'1', 'url_from_keystone', token='3bcc3d3a03f44e3d8377f9247b0ad155')
|
||||
|
||||
def test_clients_glance_noauth(self):
|
||||
con = mock.MagicMock()
|
||||
con.auth_token = None
|
||||
con.tenant = "b363706f891f48019483f8bd6503c54d"
|
||||
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._glance = None
|
||||
self.assertRaises(exception.AuthorizationFailure, obj.glance)
|
||||
|
||||
def test_clients_glance_cached(self):
|
||||
con = mock.MagicMock()
|
||||
con.tenant = "b363706f891f48019483f8bd6503c54d"
|
||||
con.auth_token = "3bcc3d3a03f44e3d8377f9247b0ad155"
|
||||
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._glance = None
|
||||
glance = obj.glance()
|
||||
glance_cached = obj.glance()
|
||||
self.assertEqual(glance, glance_cached)
|
||||
|
||||
@mock.patch.object(heatclient, 'Client')
|
||||
def test_clients_heat(self, mock_call):
|
||||
con = mock.MagicMock()
|
||||
|
||||
Reference in New Issue
Block a user