Fetch transformations configuration from Nailgun settings
Change-Id: Ic03f729c738745ff18c849cb4f3a4b5b8d3fe90c Closes-Bug: #1618177
This commit is contained in:
parent
8147718cf7
commit
f23d273ee8
53
README.rst
53
README.rst
|
@ -6,6 +6,53 @@ cluster upgrading. This extension used by the fuel-octane project.
|
||||||
|
|
||||||
Instalation
|
Instalation
|
||||||
-----------
|
-----------
|
||||||
After installing `fuel-nailgun-extension-cluster-upgrade` package run:
|
After installing ``fuel-nailgun-extension-cluster-upgrade`` package run:
|
||||||
1) `nailgun_syncdb` - migrate database
|
#. ``nailgun_syncdb`` - migrate database
|
||||||
2) restart nailgun service
|
#. restart nailgun service
|
||||||
|
|
||||||
|
Transformer configuration
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
Every transformation manager has default config that hardcoded, but
|
||||||
|
you can overwrite this config with your own transformations
|
||||||
|
extensions. This could be done by extending ``nailgun/settings.yaml``
|
||||||
|
file.
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
|
||||||
|
::
|
||||||
|
CLUSTER_UPGRADE:
|
||||||
|
transformations:
|
||||||
|
cluster:
|
||||||
|
7.0: [transform_vips]
|
||||||
|
9.0: [first_transformation, second_transformation]
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
In extension you should define a entrypoint is such way:
|
||||||
|
|
||||||
|
::
|
||||||
|
nailgun.cluster_upgrade.transformations.cluster.7.0 =
|
||||||
|
transform_vips = my_project.transformations:transform_cluster_vips
|
||||||
|
|
||||||
|
on first line we have entripoint name where
|
||||||
|
* ``nailgun.cluster_upgrade.transformations`` - namespace where all
|
||||||
|
transformations defined.
|
||||||
|
* ``cluster`` - name of object which data transformed
|
||||||
|
* ``7.0`` - cluster version where these transformations should happen
|
||||||
|
|
||||||
|
on the second line
|
||||||
|
* ``transform_vips`` - unique transformation name that you can use in
|
||||||
|
configuration file or in transformation manager
|
||||||
|
* ``my_project.transformations`` - module name
|
||||||
|
* ``transform_cluster_vips`` - transformer function name
|
||||||
|
|
||||||
|
|
||||||
|
Transformation function must take only one argument - data to
|
||||||
|
transform. When you call ``manager.apply(from_version, to_version,
|
||||||
|
data)`` all transformer functions ordered by a version called one by
|
||||||
|
one, and output of one transformer used as input to the other.
|
||||||
|
|
||||||
|
In out example calling ``cluster_manager.apply('6.0', '9.1', data)``
|
||||||
|
will call three functions ``transform_vips``,
|
||||||
|
``first_transformation``, ``second_transformation``.
|
||||||
|
|
|
@ -21,13 +21,36 @@ from ..transformations import cluster
|
||||||
|
|
||||||
|
|
||||||
class TestTransformations(nailgun_test_base.BaseUnitTest):
|
class TestTransformations(nailgun_test_base.BaseUnitTest):
|
||||||
def test_get_config(self):
|
def _test_get_config(self, def_config, settings, expected_result):
|
||||||
config = object()
|
|
||||||
|
|
||||||
class Manager(transformations.Manager):
|
class Manager(transformations.Manager):
|
||||||
default_config = config
|
default_config = def_config
|
||||||
|
|
||||||
self.assertIs(config, Manager.get_config('testname'))
|
with mock.patch("nailgun.settings.settings.config", new=settings):
|
||||||
|
result = Manager.get_config('testname')
|
||||||
|
|
||||||
|
self.assertEqual(expected_result, result)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _trans_settings(config):
|
||||||
|
return {'CLUSTER_UPGRADE': {'transformations': {'testname': config}}}
|
||||||
|
|
||||||
|
def test_get_config_default(self):
|
||||||
|
config = {'9.0': []}
|
||||||
|
self._test_get_config(config, {}, config)
|
||||||
|
|
||||||
|
def test_get_config_no_overwrite(self):
|
||||||
|
self._test_get_config(
|
||||||
|
{'9.0': ['a']},
|
||||||
|
self._trans_settings({'8.0': ['b']}),
|
||||||
|
{'8.0': ['b'], '9.0': ['a']},
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_get_config_overwrite(self):
|
||||||
|
self._test_get_config(
|
||||||
|
{'9.0': ['a']},
|
||||||
|
self._trans_settings({'8.0': ['b'], '9.0': ['c']}),
|
||||||
|
{'8.0': ['b'], '9.0': ['c']},
|
||||||
|
)
|
||||||
|
|
||||||
def setup_extension_manager(self, extensions):
|
def setup_extension_manager(self, extensions):
|
||||||
p = mock.patch("stevedore.ExtensionManager", spec=['__call__'])
|
p = mock.patch("stevedore.ExtensionManager", spec=['__call__'])
|
||||||
|
@ -153,8 +176,9 @@ class TestTransformations(nailgun_test_base.BaseUnitTest):
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@mock.patch.object(transformations.Manager, 'get_config')
|
||||||
@mock.patch.object(transformations.Manager, 'load_transformers')
|
@mock.patch.object(transformations.Manager, 'load_transformers')
|
||||||
def test_apply(self, mock_load):
|
def test_apply(self, mock_load, mock_config):
|
||||||
mock_trans = mock.Mock()
|
mock_trans = mock.Mock()
|
||||||
mock_load.return_value = [
|
mock_load.return_value = [
|
||||||
(version.StrictVersion('7.0'), [mock_trans.a, mock_trans.b]),
|
(version.StrictVersion('7.0'), [mock_trans.a, mock_trans.b]),
|
||||||
|
|
|
@ -15,10 +15,12 @@ import distutils.version
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
|
import six
|
||||||
import stevedore
|
import stevedore
|
||||||
|
|
||||||
|
from nailgun.settings import settings
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,8 +39,14 @@ class Manager(object):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_config(cls, name):
|
def get_config(cls, name):
|
||||||
# TODO(yorik-sar): merge actual config with defaults
|
res = cls.default_config.copy()
|
||||||
return cls.default_config
|
try:
|
||||||
|
conf = settings.config['CLUSTER_UPGRADE']['transformations'][name]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
res.update(conf)
|
||||||
|
return res
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load_transformers(name, config):
|
def load_transformers(name, config):
|
||||||
|
|
Loading…
Reference in New Issue