diff options
author | Yuriy Taraday <yorik.sar@gmail.com> | 2016-08-29 22:07:16 +0300 |
---|---|---|
committer | Nikita Zubkov <nzubkov@mirantis.com> | 2016-09-09 18:22:21 +0300 |
commit | f23d273ee8eea2b377648e92217338242447cd8b (patch) | |
tree | 943e314521ba977473d0250ae911d97303d4a5cf | |
parent | 8147718cf776dc287b4952cb24f067f0c47991ac (diff) |
Fetch transformations configuration from Nailgun settings
Change-Id: Ic03f729c738745ff18c849cb4f3a4b5b8d3fe90c
Closes-Bug: #1618177
Notes
Notes (review):
Code-Review+2: Ilya Kharin <akscram@gmail.com>
Code-Review+2: Sergey Abramov <sabramov@mirantis.com>
Workflow+1: Ilya Kharin <akscram@gmail.com>
Verified+2: Jenkins
Submitted-by: Jenkins
Submitted-at: Wed, 14 Sep 2016 13:56:30 +0000
Reviewed-on: https://review.openstack.org/362327
Project: openstack/fuel-nailgun-extension-cluster-upgrade
Branch: refs/heads/master
-rw-r--r-- | README.rst | 53 | ||||
-rw-r--r-- | cluster_upgrade/tests/test_transformations.py | 36 | ||||
-rw-r--r-- | cluster_upgrade/transformations/__init__.py | 14 |
3 files changed, 91 insertions, 12 deletions
@@ -6,6 +6,53 @@ cluster upgrading. This extension used by the fuel-octane project. | |||
6 | 6 | ||
7 | Instalation | 7 | Instalation |
8 | ----------- | 8 | ----------- |
9 | After installing `fuel-nailgun-extension-cluster-upgrade` package run: | 9 | After installing ``fuel-nailgun-extension-cluster-upgrade`` package run: |
10 | 1) `nailgun_syncdb` - migrate database | 10 | #. ``nailgun_syncdb`` - migrate database |
11 | 2) restart nailgun service | 11 | #. restart nailgun service |
12 | |||
13 | Transformer configuration | ||
14 | ------------------------- | ||
15 | |||
16 | Every transformation manager has default config that hardcoded, but | ||
17 | you can overwrite this config with your own transformations | ||
18 | extensions. This could be done by extending ``nailgun/settings.yaml`` | ||
19 | file. | ||
20 | |||
21 | **Example** | ||
22 | |||
23 | :: | ||
24 | CLUSTER_UPGRADE: | ||
25 | transformations: | ||
26 | cluster: | ||
27 | 7.0: [transform_vips] | ||
28 | 9.0: [first_transformation, second_transformation] | ||
29 | |||
30 | ... | ||
31 | |||
32 | In extension you should define a entrypoint is such way: | ||
33 | |||
34 | :: | ||
35 | nailgun.cluster_upgrade.transformations.cluster.7.0 = | ||
36 | transform_vips = my_project.transformations:transform_cluster_vips | ||
37 | |||
38 | on first line we have entripoint name where | ||
39 | * ``nailgun.cluster_upgrade.transformations`` - namespace where all | ||
40 | transformations defined. | ||
41 | * ``cluster`` - name of object which data transformed | ||
42 | * ``7.0`` - cluster version where these transformations should happen | ||
43 | |||
44 | on the second line | ||
45 | * ``transform_vips`` - unique transformation name that you can use in | ||
46 | configuration file or in transformation manager | ||
47 | * ``my_project.transformations`` - module name | ||
48 | * ``transform_cluster_vips`` - transformer function name | ||
49 | |||
50 | |||
51 | Transformation function must take only one argument - data to | ||
52 | transform. When you call ``manager.apply(from_version, to_version, | ||
53 | data)`` all transformer functions ordered by a version called one by | ||
54 | one, and output of one transformer used as input to the other. | ||
55 | |||
56 | In out example calling ``cluster_manager.apply('6.0', '9.1', data)`` | ||
57 | will call three functions ``transform_vips``, | ||
58 | ``first_transformation``, ``second_transformation``. | ||
diff --git a/cluster_upgrade/tests/test_transformations.py b/cluster_upgrade/tests/test_transformations.py index 880ee2d..f970702 100644 --- a/cluster_upgrade/tests/test_transformations.py +++ b/cluster_upgrade/tests/test_transformations.py | |||
@@ -21,13 +21,36 @@ from ..transformations import cluster | |||
21 | 21 | ||
22 | 22 | ||
23 | class TestTransformations(nailgun_test_base.BaseUnitTest): | 23 | class TestTransformations(nailgun_test_base.BaseUnitTest): |
24 | def test_get_config(self): | 24 | def _test_get_config(self, def_config, settings, expected_result): |
25 | config = object() | ||
26 | |||
27 | class Manager(transformations.Manager): | 25 | class Manager(transformations.Manager): |
28 | default_config = config | 26 | default_config = def_config |
27 | |||
28 | with mock.patch("nailgun.settings.settings.config", new=settings): | ||
29 | result = Manager.get_config('testname') | ||
30 | |||
31 | self.assertEqual(expected_result, result) | ||
32 | |||
33 | @staticmethod | ||
34 | def _trans_settings(config): | ||
35 | return {'CLUSTER_UPGRADE': {'transformations': {'testname': config}}} | ||
29 | 36 | ||
30 | self.assertIs(config, Manager.get_config('testname')) | 37 | def test_get_config_default(self): |
38 | config = {'9.0': []} | ||
39 | self._test_get_config(config, {}, config) | ||
40 | |||
41 | def test_get_config_no_overwrite(self): | ||
42 | self._test_get_config( | ||
43 | {'9.0': ['a']}, | ||
44 | self._trans_settings({'8.0': ['b']}), | ||
45 | {'8.0': ['b'], '9.0': ['a']}, | ||
46 | ) | ||
47 | |||
48 | def test_get_config_overwrite(self): | ||
49 | self._test_get_config( | ||
50 | {'9.0': ['a']}, | ||
51 | self._trans_settings({'8.0': ['b'], '9.0': ['c']}), | ||
52 | {'8.0': ['b'], '9.0': ['c']}, | ||
53 | ) | ||
31 | 54 | ||
32 | def setup_extension_manager(self, extensions): | 55 | def setup_extension_manager(self, extensions): |
33 | p = mock.patch("stevedore.ExtensionManager", spec=['__call__']) | 56 | p = mock.patch("stevedore.ExtensionManager", spec=['__call__']) |
@@ -153,8 +176,9 @@ class TestTransformations(nailgun_test_base.BaseUnitTest): | |||
153 | ), | 176 | ), |
154 | ]) | 177 | ]) |
155 | 178 | ||
179 | @mock.patch.object(transformations.Manager, 'get_config') | ||
156 | @mock.patch.object(transformations.Manager, 'load_transformers') | 180 | @mock.patch.object(transformations.Manager, 'load_transformers') |
157 | def test_apply(self, mock_load): | 181 | def test_apply(self, mock_load, mock_config): |
158 | mock_trans = mock.Mock() | 182 | mock_trans = mock.Mock() |
159 | mock_load.return_value = [ | 183 | mock_load.return_value = [ |
160 | (version.StrictVersion('7.0'), [mock_trans.a, mock_trans.b]), | 184 | (version.StrictVersion('7.0'), [mock_trans.a, mock_trans.b]), |
diff --git a/cluster_upgrade/transformations/__init__.py b/cluster_upgrade/transformations/__init__.py index 7e1d861..b7d33af 100644 --- a/cluster_upgrade/transformations/__init__.py +++ b/cluster_upgrade/transformations/__init__.py | |||
@@ -15,10 +15,12 @@ import distutils.version | |||
15 | import logging | 15 | import logging |
16 | import threading | 16 | import threading |
17 | 17 | ||
18 | import six | ||
19 | 18 | ||
19 | import six | ||
20 | import stevedore | 20 | import stevedore |
21 | 21 | ||
22 | from nailgun.settings import settings | ||
23 | |||
22 | LOG = logging.getLogger(__name__) | 24 | LOG = logging.getLogger(__name__) |
23 | 25 | ||
24 | 26 | ||
@@ -37,8 +39,14 @@ class Manager(object): | |||
37 | 39 | ||
38 | @classmethod | 40 | @classmethod |
39 | def get_config(cls, name): | 41 | def get_config(cls, name): |
40 | # TODO(yorik-sar): merge actual config with defaults | 42 | res = cls.default_config.copy() |
41 | return cls.default_config | 43 | try: |
44 | conf = settings.config['CLUSTER_UPGRADE']['transformations'][name] | ||
45 | except KeyError: | ||
46 | pass | ||
47 | else: | ||
48 | res.update(conf) | ||
49 | return res | ||
42 | 50 | ||
43 | @staticmethod | 51 | @staticmethod |
44 | def load_transformers(name, config): | 52 | def load_transformers(name, config): |