Merge "Fetch transformations configuration from Nailgun settings"
This commit is contained in:
commit
ce58ef1d7e
53
README.rst
53
README.rst
|
@ -6,6 +6,53 @@ cluster upgrading. This extension used by the fuel-octane project.
|
|||
|
||||
Instalation
|
||||
-----------
|
||||
After installing `fuel-nailgun-extension-cluster-upgrade` package run:
|
||||
1) `nailgun_syncdb` - migrate database
|
||||
2) restart nailgun service
|
||||
After installing ``fuel-nailgun-extension-cluster-upgrade`` package run:
|
||||
#. ``nailgun_syncdb`` - migrate database
|
||||
#. 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``.
|
||||
|
|
|
@ -22,13 +22,36 @@ from ..transformations import vip
|
|||
|
||||
|
||||
class TestTransformations(nailgun_test_base.BaseUnitTest):
|
||||
def test_get_config(self):
|
||||
config = object()
|
||||
|
||||
def _test_get_config(self, def_config, settings, expected_result):
|
||||
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):
|
||||
p = mock.patch("stevedore.ExtensionManager", spec=['__call__'])
|
||||
|
@ -154,8 +177,9 @@ class TestTransformations(nailgun_test_base.BaseUnitTest):
|
|||
),
|
||||
])
|
||||
|
||||
@mock.patch.object(transformations.Manager, 'get_config')
|
||||
@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_load.return_value = [
|
||||
(version.StrictVersion('7.0'), [mock_trans.a, mock_trans.b]),
|
||||
|
|
|
@ -15,10 +15,12 @@ import distutils.version
|
|||
import logging
|
||||
import threading
|
||||
|
||||
import six
|
||||
|
||||
import six
|
||||
import stevedore
|
||||
|
||||
from nailgun.settings import settings
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -37,8 +39,14 @@ class Manager(object):
|
|||
|
||||
@classmethod
|
||||
def get_config(cls, name):
|
||||
# TODO(yorik-sar): merge actual config with defaults
|
||||
return cls.default_config
|
||||
res = cls.default_config.copy()
|
||||
try:
|
||||
conf = settings.config['CLUSTER_UPGRADE']['transformations'][name]
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
res.update(conf)
|
||||
return res
|
||||
|
||||
@staticmethod
|
||||
def load_transformers(name, config):
|
||||
|
|
Loading…
Reference in New Issue