Centralize config option: cluster_heat section

Centralize config option of Cluster Heat section.
Replace oslo_conf cfg to magnum.conf.

Change-Id: I9118eeb17061a0aa26269ea9deaba28e79f28b76
Implements: blueprint centralize-config-magnum
This commit is contained in:
Hieu LE 2016-08-17 14:27:22 +07:00
parent e891d0a20b
commit 8f9eeb801a
9 changed files with 87 additions and 64 deletions

View File

@ -16,7 +16,6 @@ import os
from heatclient.common import template_utils from heatclient.common import template_utils
from heatclient import exc from heatclient import exc
from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from oslo_service import loopingcall from oslo_service import loopingcall
from oslo_utils import importutils from oslo_utils import importutils
@ -30,6 +29,7 @@ from magnum.conductor.handlers.common import cert_manager
from magnum.conductor.handlers.common import trust_manager from magnum.conductor.handlers.common import trust_manager
from magnum.conductor import scale_manager from magnum.conductor import scale_manager
from magnum.conductor import utils as conductor_utils from magnum.conductor import utils as conductor_utils
import magnum.conf
from magnum.drivers.common import template_def from magnum.drivers.common import template_def
from magnum.i18n import _ from magnum.i18n import _
from magnum.i18n import _LE from magnum.i18n import _LE
@ -37,33 +37,7 @@ from magnum.i18n import _LI
from magnum import objects from magnum import objects
from magnum.objects import fields from magnum.objects import fields
CONF = magnum.conf.CONF
cluster_heat_opts = [
cfg.IntOpt('max_attempts',
default=2000,
help=('Number of attempts to query the Heat stack for '
'finding out the status of the created stack and '
'getting template outputs. This value is ignored '
'during cluster creation if timeout is set as the poll '
'will continue until cluster creation either ends '
'or times out.'),
deprecated_group='bay_heat'),
cfg.IntOpt('wait_interval',
default=1,
help=('Sleep time interval between two attempts of querying '
'the Heat stack. This interval is in seconds.'),
deprecated_group='bay_heat'),
cfg.IntOpt('create_timeout',
default=60,
help=('The length of time to let cluster creation continue. '
'This interval is in minutes. The default is 60 minutes.'
),
deprecated_group='bay_heat',
deprecated_name='bay_create_timeout')
]
CONF = cfg.CONF
CONF.register_opts(cluster_heat_opts, group='cluster_heat')
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -108,7 +82,7 @@ def _create_stack(context, osc, cluster, create_timeout):
else: else:
# no create_timeout value was passed in to the request # no create_timeout value was passed in to the request
# so falling back on configuration file value # so falling back on configuration file value
heat_timeout = cfg.CONF.cluster_heat.create_timeout heat_timeout = CONF.cluster_heat.create_timeout
fields = { fields = {
'stack_name': stack_name, 'stack_name': stack_name,
'parameters': heat_params, 'parameters': heat_params,
@ -270,7 +244,7 @@ class Handler(object):
def _poll_and_check(self, osc, cluster): def _poll_and_check(self, osc, cluster):
poller = HeatPoller(osc, cluster) poller = HeatPoller(osc, cluster)
lc = loopingcall.FixedIntervalLoopingCall(f=poller.poll_and_check) lc = loopingcall.FixedIntervalLoopingCall(f=poller.poll_and_check)
lc.start(cfg.CONF.cluster_heat.wait_interval, True) lc.start(CONF.cluster_heat.wait_interval, True)
class HeatPoller(object): class HeatPoller(object):
@ -338,18 +312,18 @@ class HeatPoller(object):
# the loop will end when the stack completes or the timeout occurs # the loop will end when the stack completes or the timeout occurs
if stack.stack_status == fields.ClusterStatus.CREATE_IN_PROGRESS: if stack.stack_status == fields.ClusterStatus.CREATE_IN_PROGRESS:
if (stack.timeout_mins is None and if (stack.timeout_mins is None and
self.attempts > cfg.CONF.cluster_heat.max_attempts): self.attempts > CONF.cluster_heat.max_attempts):
LOG.error(_LE('Cluster check exit after %(attempts)s attempts,' LOG.error(_LE('Cluster check exit after %(attempts)s attempts,'
'stack_id: %(id)s, stack_status: %(status)s') % 'stack_id: %(id)s, stack_status: %(status)s') %
{'attempts': cfg.CONF.cluster_heat.max_attempts, {'attempts': CONF.cluster_heat.max_attempts,
'id': self.cluster.stack_id, 'id': self.cluster.stack_id,
'status': stack.stack_status}) 'status': stack.stack_status})
raise loopingcall.LoopingCallDone() raise loopingcall.LoopingCallDone()
else: else:
if self.attempts > cfg.CONF.cluster_heat.max_attempts: if self.attempts > CONF.cluster_heat.max_attempts:
LOG.error(_LE('Cluster check exit after %(attempts)s attempts,' LOG.error(_LE('Cluster check exit after %(attempts)s attempts,'
'stack_id: %(id)s, stack_status: %(status)s') % 'stack_id: %(id)s, stack_status: %(status)s') %
{'attempts': cfg.CONF.cluster_heat.max_attempts, {'attempts': CONF.cluster_heat.max_attempts,
'id': self.cluster.stack_id, 'id': self.cluster.stack_id,
'status': stack.stack_status}) 'status': stack.stack_status})
raise loopingcall.LoopingCallDone() raise loopingcall.LoopingCallDone()

View File

@ -20,6 +20,7 @@ from magnum.conf import barbican
# from magnum.conf import certificates # 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
from magnum.conf import cluster_heat
from magnum.conf import cluster_templates from magnum.conf import cluster_templates
from magnum.conf import conductor from magnum.conf import conductor
# from magnum.conf import database # from magnum.conf import database
@ -38,6 +39,7 @@ api.register_opts(CONF)
barbican.register_opts(CONF) barbican.register_opts(CONF)
cluster.register_opts(CONF) cluster.register_opts(CONF)
cluster_templates.register_opts(CONF) cluster_templates.register_opts(CONF)
cluster_heat.register_opts(CONF)
# certificates.register_opts(CONF) # certificates.register_opts(CONF)
cinder.register_opts(CONF) cinder.register_opts(CONF)
conductor.register_opts(CONF) conductor.register_opts(CONF)

View File

@ -0,0 +1,52 @@
# 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
cluster_heat_group = cfg.OptGroup(name='cluster_heat',
title='Heat options for Cluster '
'configuration')
cluster_heat_opts = [
cfg.IntOpt('max_attempts',
default=2000,
help=('Number of attempts to query the Heat stack for '
'finding out the status of the created stack and '
'getting template outputs. This value is ignored '
'during cluster creation if timeout is set as the poll '
'will continue until cluster creation either ends '
'or times out.'),
deprecated_group='bay_heat'),
cfg.IntOpt('wait_interval',
default=1,
help=('Sleep time interval between two attempts of querying '
'the Heat stack. This interval is in seconds.'),
deprecated_group='bay_heat'),
cfg.IntOpt('create_timeout',
default=60,
help=('The length of time to let cluster creation continue. '
'This interval is in minutes. The default is 60 minutes.'
),
deprecated_group='bay_heat',
deprecated_name='bay_create_timeout')
]
def register_opts(conf):
conf.register_group(cluster_heat_group)
conf.register_opts(cluster_heat_opts, group=cluster_heat_group)
def list_opts():
return {
cluster_heat_group: cluster_heat_opts
}

View File

@ -23,20 +23,11 @@ revision = '592131657ca1'
down_revision = '4956f03cabad' down_revision = '4956f03cabad'
from alembic import op from alembic import op
from oslo_config import cfg
import magnum.conf
import sqlalchemy as sa import sqlalchemy as sa
from magnum.i18n import _ CONF = magnum.conf.CONF
cluster_heat_opts = [
cfg.StrOpt('cluster_coe',
default='kubernetes',
help=_('Container Orchestration Environments are '
'kubernetes or swarm.'),
deprecated_group='bay_heat')
]
cfg.CONF.register_opts(cluster_heat_opts, group='cluster_heat')
def upgrade(): def upgrade():
@ -48,5 +39,5 @@ def upgrade():
op.execute( op.execute(
baymodel.update().values({ baymodel.update().values({
'coe': op.inline_literal(cfg.CONF.cluster_heat.cluster_coe)}) 'coe': op.inline_literal("kubernetes")})
) )

View File

@ -20,9 +20,10 @@ from magnum.common.cert_manager import local_cert_manager
import magnum.common.exception import magnum.common.exception
import magnum.common.rpc_service import magnum.common.rpc_service
import magnum.common.service import magnum.common.service
import magnum.common.utils
import magnum.common.x509.config import magnum.common.x509.config
import magnum.conductor.handlers.cluster_conductor
import magnum.db import magnum.db
import magnum.drivers.common.template_def
def list_opts(): def list_opts():
@ -37,8 +38,6 @@ def list_opts():
('docker', magnum.common.docker_utils.docker_opts), ('docker', magnum.common.docker_utils.docker_opts),
('trust', magnum.common.keystone.trust_opts), ('trust', magnum.common.keystone.trust_opts),
('x509', magnum.common.x509.config.x509_opts), ('x509', magnum.common.x509.config.x509_opts),
('cluster_heat',
magnum.conductor.handlers.cluster_conductor.cluster_heat_opts),
('certificates', ('certificates',
itertools.chain(magnum.common.cert_manager.cert_manager_opts, itertools.chain(magnum.common.cert_manager.cert_manager_opts,
local_cert_manager.local_cert_manager_opts, local_cert_manager.local_cert_manager_opts,

View File

@ -18,7 +18,6 @@ Tests for `magnum` module.
""" """
import os import os
from oslo_config import cfg
import subprocess import subprocess
import tempfile import tempfile
import time import time
@ -30,7 +29,9 @@ from heatclient import client as heatclient
from k8sclient.client import api_client from k8sclient.client import api_client
from k8sclient.client.apis import apiv_api from k8sclient.client.apis import apiv_api
from keystoneclient.v2_0 import client as ksclient from keystoneclient.v2_0 import client as ksclient
from magnum.common.utils import rmtree_without_raise from magnum.common.utils import rmtree_without_raise
import magnum.conf
from magnum.i18n import _LI from magnum.i18n import _LI
from magnum.tests.functional.common import base from magnum.tests.functional.common import base
from magnum.tests.functional.common import utils from magnum.tests.functional.common import utils
@ -38,6 +39,8 @@ from magnumclient.common.apiclient import exceptions
from magnumclient.common import cliutils from magnumclient.common import cliutils
from magnumclient.v1 import client as v1client from magnumclient.v1 import client as v1client
CONF = magnum.conf.CONF
class BaseMagnumClient(base.BaseMagnumTest): class BaseMagnumClient(base.BaseMagnumTest):
@ -268,9 +271,9 @@ extendedKeyUsage = clientAuth
test_timeout = int(test_timeout) test_timeout = int(test_timeout)
except ValueError: except ValueError:
# If timeout value is invalid, set a default timeout. # If timeout value is invalid, set a default timeout.
test_timeout = cfg.CONF.cluster_heat.create_timeout test_timeout = CONF.cluster_heat.create_timeout
if test_timeout <= 0: if test_timeout <= 0:
test_timeout = cfg.CONF.cluster_heat.create_timeout test_timeout = CONF.cluster_heat.create_timeout
self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) self.useFixture(fixtures.Timeout(test_timeout, gentle=True))

View File

@ -19,12 +19,12 @@ import six
from heatclient import exc from heatclient import exc
import mock import mock
from mock import patch from mock import patch
from oslo_config import cfg
from oslo_service import loopingcall from oslo_service import loopingcall
from pycadf import cadftaxonomy as taxonomy from pycadf import cadftaxonomy as taxonomy
from magnum.common import exception from magnum.common import exception
from magnum.conductor.handlers import cluster_conductor from magnum.conductor.handlers import cluster_conductor
import magnum.conf
from magnum import objects from magnum import objects
from magnum.objects.fields import ClusterStatus as cluster_status from magnum.objects.fields import ClusterStatus as cluster_status
from magnum.tests import base from magnum.tests import base
@ -32,6 +32,8 @@ from magnum.tests import fake_notifier
from magnum.tests.unit.db import base as db_base from magnum.tests.unit.db import base as db_base
from magnum.tests.unit.db import utils from magnum.tests.unit.db import utils
CONF = magnum.conf.CONF
class TestHandler(db_base.DbTestCase): class TestHandler(db_base.DbTestCase):
@ -689,14 +691,14 @@ class TestHeatPoller(base.TestCase):
mock_heat_stack, cluster, poller = self.setup_poll_test() mock_heat_stack, cluster, poller = self.setup_poll_test()
mock_heat_stack.stack_status = cluster_status.DELETE_IN_PROGRESS mock_heat_stack.stack_status = cluster_status.DELETE_IN_PROGRESS
poller.attempts = cfg.CONF.cluster_heat.max_attempts poller.attempts = CONF.cluster_heat.max_attempts
self.assertRaises(loopingcall.LoopingCallDone, poller.poll_and_check) self.assertRaises(loopingcall.LoopingCallDone, poller.poll_and_check)
def test_poll_create_in_prog_max_att_reached_no_timeout(self): def test_poll_create_in_prog_max_att_reached_no_timeout(self):
mock_heat_stack, cluster, poller = self.setup_poll_test() mock_heat_stack, cluster, poller = self.setup_poll_test()
mock_heat_stack.stack_status = cluster_status.CREATE_IN_PROGRESS mock_heat_stack.stack_status = cluster_status.CREATE_IN_PROGRESS
poller.attempts = cfg.CONF.cluster_heat.max_attempts poller.attempts = CONF.cluster_heat.max_attempts
mock_heat_stack.timeout_mins = None mock_heat_stack.timeout_mins = None
self.assertRaises(loopingcall.LoopingCallDone, poller.poll_and_check) self.assertRaises(loopingcall.LoopingCallDone, poller.poll_and_check)
@ -704,7 +706,7 @@ class TestHeatPoller(base.TestCase):
mock_heat_stack, cluster, poller = self.setup_poll_test() mock_heat_stack, cluster, poller = self.setup_poll_test()
mock_heat_stack.stack_status = cluster_status.CREATE_IN_PROGRESS mock_heat_stack.stack_status = cluster_status.CREATE_IN_PROGRESS
poller.attempts = cfg.CONF.cluster_heat.max_attempts poller.attempts = CONF.cluster_heat.max_attempts
mock_heat_stack.timeout_mins = 60 mock_heat_stack.timeout_mins = 60
# since the timeout is set the max attempts gets ignored since # since the timeout is set the max attempts gets ignored since
# the timeout will eventually stop the poller either when # the timeout will eventually stop the poller either when
@ -715,7 +717,7 @@ class TestHeatPoller(base.TestCase):
mock_heat_stack, cluster, poller = self.setup_poll_test() mock_heat_stack, cluster, poller = self.setup_poll_test()
mock_heat_stack.stack_status = cluster_status.CREATE_FAILED mock_heat_stack.stack_status = cluster_status.CREATE_FAILED
poller.attempts = cfg.CONF.cluster_heat.max_attempts poller.attempts = CONF.cluster_heat.max_attempts
mock_heat_stack.timeout_mins = 60 mock_heat_stack.timeout_mins = 60
self.assertRaises(loopingcall.LoopingCallDone, poller.poll_and_check) self.assertRaises(loopingcall.LoopingCallDone, poller.poll_and_check)

View File

@ -279,11 +279,11 @@ class TestClusterConductorWithMesos(base.TestCase):
env_files) env_files)
@patch('magnum.conductor.utils.retrieve_cluster_template') @patch('magnum.conductor.utils.retrieve_cluster_template')
@patch('oslo_config.cfg') @patch('magnum.conf.CONF')
@patch('magnum.common.clients.OpenStackClients') @patch('magnum.common.clients.OpenStackClients')
def setup_poll_test(self, mock_openstack_client, cfg, def setup_poll_test(self, mock_openstack_client, mock_conf,
mock_retrieve_cluster_template): mock_retrieve_cluster_template):
cfg.CONF.cluster_heat.max_attempts = 10 mock_conf.cluster_heat.max_attempts = 10
cluster = mock.MagicMock() cluster = mock.MagicMock()
mock_heat_stack = mock.MagicMock() mock_heat_stack = mock.MagicMock()

View File

@ -389,11 +389,11 @@ class TestClusterConductorWithSwarm(base.TestCase):
env_files) env_files)
@patch('magnum.conductor.utils.retrieve_cluster_template') @patch('magnum.conductor.utils.retrieve_cluster_template')
@patch('oslo_config.cfg') @patch('magnum.conf.CONF')
@patch('magnum.common.clients.OpenStackClients') @patch('magnum.common.clients.OpenStackClients')
def setup_poll_test(self, mock_openstack_client, cfg, def setup_poll_test(self, mock_openstack_client, mock_conf,
mock_retrieve_cluster_template): mock_retrieve_cluster_template):
cfg.CONF.cluster_heat.max_attempts = 10 mock_conf.cluster_heat.max_attempts = 10
cluster = mock.MagicMock() cluster = mock.MagicMock()
mock_heat_stack = mock.MagicMock() mock_heat_stack = mock.MagicMock()