Merge "Add ironicclient"
This commit is contained in:
1
requirements.txt
Normal file → Executable file
1
requirements.txt
Normal file → Executable file
@@ -36,6 +36,7 @@ python-monascaclient>=1.1.0 # Apache-2.0
|
||||
python-neutronclient>=5.1.0 # Apache-2.0
|
||||
python-novaclient>=7.1.0 # Apache-2.0
|
||||
python-openstackclient>=3.3.0 # Apache-2.0
|
||||
python-ironicclient>=1.11.0 # Apache-2.0
|
||||
six>=1.9.0 # MIT
|
||||
SQLAlchemy!=1.1.5,!=1.1.6,!=1.1.7,!=1.1.8,>=1.0.10 # MIT
|
||||
stevedore>=1.20.0 # Apache-2.0
|
||||
|
||||
14
watcher/common/clients.py
Normal file → Executable file
14
watcher/common/clients.py
Normal file → Executable file
@@ -14,6 +14,7 @@ from ceilometerclient import client as ceclient
|
||||
from cinderclient import client as ciclient
|
||||
from glanceclient import client as glclient
|
||||
from gnocchiclient import client as gnclient
|
||||
from ironicclient import client as irclient
|
||||
from keystoneauth1 import loading as ka_loading
|
||||
from keystoneclient import client as keyclient
|
||||
from monascaclient import client as monclient
|
||||
@@ -45,6 +46,7 @@ class OpenStackClients(object):
|
||||
self._ceilometer = None
|
||||
self._monasca = None
|
||||
self._neutron = None
|
||||
self._ironic = None
|
||||
|
||||
def _get_keystone_session(self):
|
||||
auth = ka_loading.load_auth_from_conf_options(CONF,
|
||||
@@ -188,3 +190,15 @@ class OpenStackClients(object):
|
||||
session=self.session)
|
||||
self._neutron.format = 'json'
|
||||
return self._neutron
|
||||
|
||||
@exception.wrap_keystone_exception
|
||||
def ironic(self):
|
||||
if self._ironic:
|
||||
return self._ironic
|
||||
|
||||
ironicclient_version = self._get_client_option('ironic', 'api_version')
|
||||
endpoint_type = self._get_client_option('ironic', 'endpoint_type')
|
||||
self._ironic = irclient.get_client(ironicclient_version,
|
||||
ironic_url=endpoint_type,
|
||||
session=self.session)
|
||||
return self._ironic
|
||||
|
||||
2
watcher/conf/__init__.py
Normal file → Executable file
2
watcher/conf/__init__.py
Normal file → Executable file
@@ -29,6 +29,7 @@ from watcher.conf import decision_engine
|
||||
from watcher.conf import exception
|
||||
from watcher.conf import glance_client
|
||||
from watcher.conf import gnocchi_client
|
||||
from watcher.conf import ironic_client
|
||||
from watcher.conf import monasca_client
|
||||
from watcher.conf import neutron_client
|
||||
from watcher.conf import nova_client
|
||||
@@ -56,3 +57,4 @@ cinder_client.register_opts(CONF)
|
||||
ceilometer_client.register_opts(CONF)
|
||||
neutron_client.register_opts(CONF)
|
||||
clients_auth.register_opts(CONF)
|
||||
ironic_client.register_opts(CONF)
|
||||
|
||||
41
watcher/conf/ironic_client.py
Executable file
41
watcher/conf/ironic_client.py
Executable file
@@ -0,0 +1,41 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2017 ZTE Corp
|
||||
#
|
||||
# Authors: Prudhvi Rao Shedimbi <prudhvi.rao.shedimbi@intel.com>
|
||||
#
|
||||
# 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 oslo_config import cfg
|
||||
|
||||
ironic_client = cfg.OptGroup(name='ironic_client',
|
||||
title='Configuration Options for Ironic')
|
||||
|
||||
IRONIC_CLIENT_OPTS = [
|
||||
cfg.StrOpt('api_version',
|
||||
default=1,
|
||||
help='Version of Ironic API to use in ironicclient.'),
|
||||
cfg.StrOpt('endpoint_type',
|
||||
default='internalURL',
|
||||
help='Type of endpoint to use in ironicclient.'
|
||||
'Supported values: internalURL, publicURL, adminURL'
|
||||
'The default is internalURL.')]
|
||||
|
||||
|
||||
def register_opts(conf):
|
||||
conf.register_group(ironic_client)
|
||||
conf.register_opts(IRONIC_CLIENT_OPTS, group=ironic_client)
|
||||
|
||||
|
||||
def list_opts():
|
||||
return [('ironic_client', IRONIC_CLIENT_OPTS)]
|
||||
40
watcher/tests/common/test_clients.py
Normal file → Executable file
40
watcher/tests/common/test_clients.py
Normal file → Executable file
@@ -17,6 +17,8 @@ from cinderclient.v1 import client as ciclient_v1
|
||||
from glanceclient import client as glclient
|
||||
from gnocchiclient import client as gnclient
|
||||
from gnocchiclient.v1 import client as gnclient_v1
|
||||
from ironicclient import client as irclient
|
||||
from ironicclient.v1 import client as irclient_v1
|
||||
from keystoneauth1 import loading as ka_loading
|
||||
import mock
|
||||
from monascaclient import client as monclient
|
||||
@@ -387,3 +389,41 @@ class TestClients(base.TestCase):
|
||||
monasca = osc.monasca()
|
||||
monasca_cached = osc.monasca()
|
||||
self.assertEqual(monasca, monasca_cached)
|
||||
|
||||
@mock.patch.object(irclient, 'Client')
|
||||
@mock.patch.object(clients.OpenStackClients, 'session')
|
||||
def test_clients_ironic(self, mock_session, mock_call):
|
||||
osc = clients.OpenStackClients()
|
||||
osc._ironic = None
|
||||
osc.ironic()
|
||||
mock_call.assert_called_once_with(
|
||||
CONF.ironic_client.api_version,
|
||||
CONF.ironic_client.endpoint_type,
|
||||
max_retries=None,
|
||||
os_ironic_api_version=None,
|
||||
retry_interval=None,
|
||||
session=mock_session)
|
||||
|
||||
@mock.patch.object(clients.OpenStackClients, 'session')
|
||||
def test_clients_ironic_diff_vers(self, mock_session):
|
||||
CONF.set_override('api_version', '1', group='ironic_client')
|
||||
osc = clients.OpenStackClients()
|
||||
osc._ironic = None
|
||||
osc.ironic()
|
||||
self.assertEqual(irclient_v1.Client, type(osc.ironic()))
|
||||
|
||||
@mock.patch.object(clients.OpenStackClients, 'session')
|
||||
def test_clients_ironic_diff_endpoint(self, mock_session):
|
||||
CONF.set_override('endpoint_type', 'publicURL', group='ironic_client')
|
||||
osc = clients.OpenStackClients()
|
||||
osc._ironic = None
|
||||
osc.ironic()
|
||||
self.assertEqual('publicURL', osc.ironic().http_client.endpoint)
|
||||
|
||||
@mock.patch.object(clients.OpenStackClients, 'session')
|
||||
def test_clients_ironic_cached(self, mock_session):
|
||||
osc = clients.OpenStackClients()
|
||||
osc._ironic = None
|
||||
ironic = osc.ironic()
|
||||
ironic_cached = osc.ironic()
|
||||
self.assertEqual(ironic, ironic_cached)
|
||||
|
||||
2
watcher/tests/conf/test_list_opts.py
Normal file → Executable file
2
watcher/tests/conf/test_list_opts.py
Normal file → Executable file
@@ -31,7 +31,7 @@ class TestListOpts(base.TestCase):
|
||||
'DEFAULT', 'api', 'database', 'watcher_decision_engine',
|
||||
'watcher_applier', 'watcher_planner', 'nova_client',
|
||||
'glance_client', 'gnocchi_client', 'cinder_client',
|
||||
'ceilometer_client', 'monasca_client',
|
||||
'ceilometer_client', 'monasca_client', 'ironic_client',
|
||||
'neutron_client', 'watcher_clients_auth']
|
||||
self.opt_sections = list(dict(opts.list_opts()).keys())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user