summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuriy Taraday <yorik.sar@gmail.com>2016-08-29 22:07:16 +0300
committerNikita Zubkov <nzubkov@mirantis.com>2016-09-09 18:22:21 +0300
commitf23d273ee8eea2b377648e92217338242447cd8b (patch)
tree943e314521ba977473d0250ae911d97303d4a5cf
parent8147718cf776dc287b4952cb24f067f0c47991ac (diff)
Fetch transformations configuration from Nailgun settings
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.rst53
-rw-r--r--cluster_upgrade/tests/test_transformations.py36
-rw-r--r--cluster_upgrade/transformations/__init__.py14
3 files changed, 91 insertions, 12 deletions
diff --git a/README.rst b/README.rst
index e8a886c..76e808d 100644
--- a/README.rst
+++ b/README.rst
@@ -6,6 +6,53 @@ cluster upgrading. This extension used by the fuel-octane project.
6 6
7Instalation 7Instalation
8----------- 8-----------
9After installing `fuel-nailgun-extension-cluster-upgrade` package run: 9After installing ``fuel-nailgun-extension-cluster-upgrade`` package run:
101) `nailgun_syncdb` - migrate database 10 #. ``nailgun_syncdb`` - migrate database
112) restart nailgun service 11 #. restart nailgun service
12
13Transformer configuration
14-------------------------
15
16Every transformation manager has default config that hardcoded, but
17you can overwrite this config with your own transformations
18extensions. This could be done by extending ``nailgun/settings.yaml``
19file.
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
32In 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
38on 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
44on 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
51Transformation function must take only one argument - data to
52transform. When you call ``manager.apply(from_version, to_version,
53data)`` all transformer functions ordered by a version called one by
54one, and output of one transformer used as input to the other.
55
56In out example calling ``cluster_manager.apply('6.0', '9.1', data)``
57will 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
23class TestTransformations(nailgun_test_base.BaseUnitTest): 23class 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
15import logging 15import logging
16import threading 16import threading
17 17
18import six
19 18
19import six
20import stevedore 20import stevedore
21 21
22from nailgun.settings import settings
23
22LOG = logging.getLogger(__name__) 24LOG = 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):