Centralize config option: all clients section

Centralize config option of Barbican, Heat, Cinder, Nova,
Neutron, Magnum, Glance client section.
Replace oslo_conf cfg to magnum.conf and fix bug generate
full sample config options of above clients.

Change-Id: I8279e6bd5d397e98953a72e83b379dfc7c6228a3
Implements: blueprint centralize-config-magnum
Closes-Bug: #1613962
This commit is contained in:
Hieu LE 2016-08-17 11:41:21 +07:00
parent cfe5b4ed5c
commit 44cca296f9
11 changed files with 395 additions and 151 deletions

View File

@ -18,115 +18,14 @@ from heatclient import client as heatclient
from keystoneauth1.exceptions import catalog
from neutronclient.v2_0 import client as neutronclient
from novaclient import client as novaclient
from oslo_config import cfg
from oslo_log import log as logging
from magnum.common import exception
from magnum.common import keystone
from magnum.i18n import _
import magnum.conf
from magnum.i18n import _LW
common_security_opts = [
cfg.StrOpt('ca_file',
help=_('Optional CA cert file to use in SSL connections.')),
cfg.StrOpt('cert_file',
help=_('Optional PEM-formatted certificate chain file.')),
cfg.StrOpt('key_file',
help=_('Optional PEM-formatted file that contains the '
'private key.')),
cfg.BoolOpt('insecure',
default=False,
help=_("If set, then the server's certificate will not "
"be verified."))]
magnum_client_opts = [
cfg.StrOpt('region_name',
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.'))]
heat_client_opts = [
cfg.StrOpt('region_name',
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.StrOpt('api_version',
default='1',
help=_('Version of Heat API to use in heatclient.'))]
glance_client_opts = [
cfg.StrOpt('region_name',
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.StrOpt('api_version',
default='2',
help=_('Version of Glance API to use in glanceclient.'))]
barbican_client_opts = [
cfg.StrOpt('region_name',
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.'))]
nova_client_opts = [
cfg.StrOpt('region_name',
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.StrOpt('api_version',
default='2',
help=_('Version of Nova API to use in novaclient.'))]
neutron_client_opts = [
cfg.StrOpt('region_name',
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.'))]
cinder_client_opts = [
cfg.StrOpt('region_name',
help=_('Region 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')
cfg.CONF.register_opts(nova_client_opts, group='nova_client')
cfg.CONF.register_opts(neutron_client_opts, group='neutron_client')
cfg.CONF.register_opts(cinder_client_opts, group='cinder_client')
cfg.CONF.register_opts(common_security_opts, group='heat_client')
cfg.CONF.register_opts(common_security_opts, group='glance_client')
cfg.CONF.register_opts(common_security_opts, group='nova_client')
cfg.CONF.register_opts(common_security_opts, group='neutron_client')
CONF = magnum.conf.CONF
LOG = logging.getLogger(__name__)
@ -180,7 +79,7 @@ class OpenStackClients(object):
return self._keystone
def _get_client_option(self, client, option):
return getattr(getattr(cfg.CONF, '%s_client' % client), option)
return getattr(getattr(CONF, '%s_client' % client), option)
@exception.wrap_keystone_exception
def heat(self):

View File

@ -16,37 +16,37 @@
from oslo_config import cfg
from magnum.conf import api
# from magnum.conf import barbican
from magnum.conf import barbican
# from magnum.conf import certificates
# from magnum.conf import cinder
from magnum.conf import cinder
# from magnum.conf import cluster
# from magnum.conf import cluster_templates
# from magnum.conf import conductor
# from magnum.conf import database
# from magnum.conf import docker
# from magnum.conf import glance
# from magnum.conf import heat
from magnum.conf import glance
from magnum.conf import heat
# from magnum.conf import keystone
# from magnum.conf import magnum_client
# from magnum.conf import neutron
# from magnum.conf import nova
from magnum.conf import magnum_client
from magnum.conf import neutron
from magnum.conf import nova
# from magnum.conf import x509
CONF = cfg.CONF
api.register_opts(CONF)
# barbican.register_opts(CONF)
barbican.register_opts(CONF)
# cluster.register_opts(CONF)
# cluster_templates.register_opts(CONF)
# certificates.register_opts(CONF)
# cinder.register_opts(CONF)
cinder.register_opts(CONF)
# conductor.register_opts(CONF)
# database.register_opts(CONF)
# docker.register_opts(CONF)
# glance.register_opts(CONF)
# heat.register_opts(CONF)
glance.register_opts(CONF)
heat.register_opts(CONF)
# keystone.register_opts(CONF)
# magnum_client.register_opts(CONF)
# neutron.register_opts(CONF)
# nova.register_opts(CONF)
magnum_client.register_opts(CONF)
neutron.register_opts(CONF)
nova.register_opts(CONF)
# x509.register_opts(CONF)

38
magnum/conf/barbican.py Normal file
View File

@ -0,0 +1,38 @@
# 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
from magnum.i18n import _
barbican_group = cfg.OptGroup(name='barbican_client',
title='Options for the Barbican client')
barbican_client_opts = [
cfg.StrOpt('region_name',
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.'))]
def register_opts(conf):
conf.register_group(barbican_group)
conf.register_opts(barbican_client_opts, group=barbican_group)
def list_opts():
return {
barbican_group: barbican_client_opts
}

34
magnum/conf/cinder.py Normal file
View File

@ -0,0 +1,34 @@
# 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
from magnum.i18n import _
cinder_group = cfg.OptGroup(name='cinder_client',
title='Options for the Cinder client')
cinder_client_opts = [
cfg.StrOpt('region_name',
help=_('Region in Identity service catalog to use for '
'communication with the OpenStack service.'))]
def register_opts(conf):
conf.register_group(cinder_group)
conf.register_opts(cinder_client_opts, group=cinder_group)
def list_opts():
return {
cinder_group: cinder_client_opts
}

61
magnum/conf/glance.py Normal file
View File

@ -0,0 +1,61 @@
# 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 itertools
from oslo_config import cfg
from magnum.i18n import _
glance_group = cfg.OptGroup(name='glance_client',
title='Options for the Glance client')
glance_client_opts = [
cfg.StrOpt('region_name',
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.StrOpt('api_version',
default='2',
help=_('Version of Glance API to use in glanceclient.'))]
common_security_opts = [
cfg.StrOpt('ca_file',
help=_('Optional CA cert file to use in SSL connections.')),
cfg.StrOpt('cert_file',
help=_('Optional PEM-formatted certificate chain file.')),
cfg.StrOpt('key_file',
help=_('Optional PEM-formatted file that contains the '
'private key.')),
cfg.BoolOpt('insecure',
default=False,
help=_("If set, then the server's certificate will not "
"be verified."))]
ALL_OPTS = list(itertools.chain(
glance_client_opts,
common_security_opts
))
def register_opts(conf):
conf.register_group(glance_group)
conf.register_opts(ALL_OPTS, group=glance_group)
def list_opts():
return {
glance_group: ALL_OPTS
}

61
magnum/conf/heat.py Normal file
View File

@ -0,0 +1,61 @@
# 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 itertools
from oslo_config import cfg
from magnum.i18n import _
heat_group = cfg.OptGroup(name='heat_client',
title='Options for the Heat client')
heat_client_opts = [
cfg.StrOpt('region_name',
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.StrOpt('api_version',
default='1',
help=_('Version of Heat API to use in heatclient.'))]
common_security_opts = [
cfg.StrOpt('ca_file',
help=_('Optional CA cert file to use in SSL connections.')),
cfg.StrOpt('cert_file',
help=_('Optional PEM-formatted certificate chain file.')),
cfg.StrOpt('key_file',
help=_('Optional PEM-formatted file that contains the '
'private key.')),
cfg.BoolOpt('insecure',
default=False,
help=_("If set, then the server's certificate will not "
"be verified."))]
ALL_OPTS = list(itertools.chain(
heat_client_opts,
common_security_opts
))
def register_opts(conf):
conf.register_group(heat_group)
conf.register_opts(ALL_OPTS, group=heat_group)
def list_opts():
return {
heat_group: ALL_OPTS
}

View File

@ -0,0 +1,38 @@
# 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
from magnum.i18n import _
magnum_client_group = cfg.OptGroup(name='magnum_client',
title='Options for the Magnum client')
magnum_client_opts = [
cfg.StrOpt('region_name',
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.'))]
def register_opts(conf):
conf.register_group(magnum_client_group)
conf.register_opts(magnum_client_opts, group=magnum_client_group)
def list_opts():
return {
magnum_client_group: magnum_client_opts
}

58
magnum/conf/neutron.py Normal file
View File

@ -0,0 +1,58 @@
# 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 itertools
from oslo_config import cfg
from magnum.i18n import _
neutron_group = cfg.OptGroup(name='neutron_client',
title='Options for the neutron client')
neutron_client_opts = [
cfg.StrOpt('region_name',
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.'))]
common_security_opts = [
cfg.StrOpt('ca_file',
help=_('Optional CA cert file to use in SSL connections.')),
cfg.StrOpt('cert_file',
help=_('Optional PEM-formatted certificate chain file.')),
cfg.StrOpt('key_file',
help=_('Optional PEM-formatted file that contains the '
'private key.')),
cfg.BoolOpt('insecure',
default=False,
help=_("If set, then the server's certificate will not "
"be verified."))]
ALL_OPTS = list(itertools.chain(
neutron_client_opts,
common_security_opts
))
def register_opts(conf):
conf.register_group(neutron_group)
conf.register_opts(ALL_OPTS, group=neutron_group)
def list_opts():
return {
neutron_group: ALL_OPTS
}

61
magnum/conf/nova.py Normal file
View File

@ -0,0 +1,61 @@
# 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 itertools
from oslo_config import cfg
from magnum.i18n import _
nova_group = cfg.OptGroup(name='nova_client',
title='Options for the nova client')
nova_client_opts = [
cfg.StrOpt('region_name',
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.StrOpt('api_version',
default='2',
help=_('Version of Nova API to use in novaclient.'))]
common_security_opts = [
cfg.StrOpt('ca_file',
help=_('Optional CA cert file to use in SSL connections.')),
cfg.StrOpt('cert_file',
help=_('Optional PEM-formatted certificate chain file.')),
cfg.StrOpt('key_file',
help=_('Optional PEM-formatted file that contains the '
'private key.')),
cfg.BoolOpt('insecure',
default=False,
help=_("If set, then the server's certificate will not "
"be verified."))]
ALL_OPTS = list(itertools.chain(
nova_client_opts,
common_security_opts
))
def register_opts(conf):
conf.register_group(nova_group)
conf.register_opts(ALL_OPTS, group=nova_group)
def list_opts():
return {
nova_group: ALL_OPTS
}

View File

@ -18,7 +18,6 @@ import itertools
import magnum.api.validation
import magnum.common.cert_manager
from magnum.common.cert_manager import local_cert_manager
import magnum.common.clients
import magnum.common.exception
import magnum.common.rpc_service
import magnum.common.service
@ -42,13 +41,6 @@ def list_opts():
('database', magnum.db.sql_opts),
('docker', magnum.common.docker_utils.docker_opts),
('trust', magnum.common.keystone.trust_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),
('cinder_client', magnum.common.clients.cinder_client_opts),
('nova_client', magnum.common.clients.nova_client_opts),
('neutron_client', magnum.common.clients.neutron_client_opts),
('x509', magnum.common.x509.config.x509_opts),
('cluster_heat',
magnum.conductor.handlers.cluster_conductor.cluster_heat_opts),

View File

@ -16,26 +16,28 @@ from heatclient import client as heatclient
import mock
from neutronclient.v2_0 import client as neutronclient
from novaclient import client as novaclient
from oslo_config import cfg
from magnum.common import clients
from magnum.common import exception
import magnum.conf
from magnum.tests import base
CONF = magnum.conf.CONF
class ClientsTest(base.BaseTestCase):
def setUp(self):
super(ClientsTest, self).setUp()
cfg.CONF.set_override('auth_uri', 'http://server.test:5000/v2.0',
group='keystone_authtoken')
cfg.CONF.import_opt('api_version', 'magnum.common.clients',
group='nova_client')
cfg.CONF.import_opt('api_version', 'magnum.common.clients',
group='heat_client')
cfg.CONF.import_opt('api_version', 'magnum.common.clients',
group='glance_client')
CONF.set_override('auth_uri', 'http://server.test:5000/v2.0',
group='keystone_authtoken')
CONF.import_opt('api_version', 'magnum.common.clients',
group='nova_client')
CONF.import_opt('api_version', 'magnum.common.clients',
group='heat_client')
CONF.import_opt('api_version', 'magnum.common.clients',
group='glance_client')
@mock.patch.object(clients.OpenStackClients, 'keystone')
def test_url_for(self, mock_keystone):
@ -50,10 +52,10 @@ class ClientsTest(base.BaseTestCase):
def test_magnum_url(self, mock_keystone):
fake_region = 'fake_region'
fake_endpoint = 'fake_endpoint'
cfg.CONF.set_override('region_name', fake_region,
group='magnum_client')
cfg.CONF.set_override('endpoint_type', fake_endpoint,
group='magnum_client')
CONF.set_override('region_name', fake_region,
group='magnum_client')
CONF.set_override('endpoint_type', fake_endpoint,
group='magnum_client')
obj = clients.OpenStackClients(None)
obj.magnum_url()
@ -76,7 +78,7 @@ class ClientsTest(base.BaseTestCase):
obj._heat = None
obj.heat()
mock_call.assert_called_once_with(
cfg.CONF.heat_client.api_version,
CONF.heat_client.api_version,
endpoint='url_from_keystone', username=None,
cert_file=None, token='3bcc3d3a03f44e3d8377f9247b0ad155',
auth_url='keystone_url', ca_file=None, key_file=None,
@ -89,7 +91,7 @@ class ClientsTest(base.BaseTestCase):
self._test_clients_heat(None)
def test_clients_heat_region(self):
cfg.CONF.set_override('region_name', 'myregion', group='heat_client')
CONF.set_override('region_name', 'myregion', group='heat_client')
self._test_clients_heat('myregion')
def test_clients_heat_noauth(self):
@ -133,7 +135,7 @@ class ClientsTest(base.BaseTestCase):
obj._glance = None
obj.glance()
mock_call.assert_called_once_with(
cfg.CONF.glance_client.api_version,
CONF.glance_client.api_version,
endpoint='url_from_keystone', username=None,
token='3bcc3d3a03f44e3d8377f9247b0ad155',
auth_url='keystone_url',
@ -146,7 +148,7 @@ class ClientsTest(base.BaseTestCase):
self._test_clients_glance(None)
def test_clients_glance_region(self):
cfg.CONF.set_override('region_name', 'myregion', group='glance_client')
CONF.set_override('region_name', 'myregion', group='glance_client')
self._test_clients_glance('myregion')
def test_clients_glance_noauth(self):
@ -203,8 +205,8 @@ class ClientsTest(base.BaseTestCase):
self._test_clients_barbican(None)
def test_clients_barbican_region(self):
cfg.CONF.set_override('region_name', 'myregion',
group='barbican_client')
CONF.set_override('region_name', 'myregion',
group='barbican_client')
self._test_clients_barbican('myregion')
def test_clients_barbican_noauth(self):
@ -248,7 +250,7 @@ class ClientsTest(base.BaseTestCase):
obj = clients.OpenStackClients(con)
obj._nova = None
obj.nova()
mock_call.assert_called_once_with(cfg.CONF.nova_client.api_version,
mock_call.assert_called_once_with(CONF.nova_client.api_version,
auth_token=con.auth_token,
cacert=None, insecure=False)
mock_url.assert_called_once_with(service_type='compute',
@ -259,7 +261,7 @@ class ClientsTest(base.BaseTestCase):
self._test_clients_nova(None)
def test_clients_nova_region(self):
cfg.CONF.set_override('region_name', 'myregion', group='nova_client')
CONF.set_override('region_name', 'myregion', group='nova_client')
self._test_clients_nova('myregion')
def test_clients_nova_noauth(self):
@ -295,8 +297,8 @@ class ClientsTest(base.BaseTestCase):
def _test_clients_neutron(self, expected_region_name, mock_auth, mock_url,
mock_call):
fake_endpoint_type = 'fake_endpoint_type'
cfg.CONF.set_override('endpoint_type', fake_endpoint_type,
group='neutron_client')
CONF.set_override('endpoint_type', fake_endpoint_type,
group='neutron_client')
mock_auth.__get__ = mock.Mock(return_value="keystone_url")
con = mock.MagicMock()
con.auth_token = "3bcc3d3a03f44e3d8377f9247b0ad155"
@ -319,8 +321,8 @@ class ClientsTest(base.BaseTestCase):
self._test_clients_neutron(None)
def test_clients_neutron_region(self):
cfg.CONF.set_override('region_name', 'myregion',
group='neutron_client')
CONF.set_override('region_name', 'myregion',
group='neutron_client')
self._test_clients_neutron('myregion')
def test_clients_neutron_noauth(self):