summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-09-14 13:56:30 +0000
committerGerrit Code Review <review@openstack.org>2016-09-14 13:56:31 +0000
commitce58ef1d7e278b4d7ae6a676a5b1881a528e066d (patch)
treefe3ec4fea12e62cddcb8b147fe52183c2cad7b05
parent6e7303d27650513bffd72afd95e055b7c20bc0e2 (diff)
parentf23d273ee8eea2b377648e92217338242447cd8b (diff)
Merge "Fetch transformations configuration from Nailgun settings"
-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 19069a1..d192f28 100644
--- a/cluster_upgrade/tests/test_transformations.py
+++ b/cluster_upgrade/tests/test_transformations.py
@@ -22,13 +22,36 @@ from ..transformations import vip
22 22
23 23
24class TestTransformations(nailgun_test_base.BaseUnitTest): 24class TestTransformations(nailgun_test_base.BaseUnitTest):
25 def test_get_config(self): 25 def _test_get_config(self, def_config, settings, expected_result):
26 config = object()
27
28 class Manager(transformations.Manager): 26 class Manager(transformations.Manager):
29 default_config = config 27 default_config = def_config
28
29 with mock.patch("nailgun.settings.settings.config", new=settings):
30 result = Manager.get_config('testname')
31
32 self.assertEqual(expected_result, result)
33
34 @staticmethod
35 def _trans_settings(config):
36 return {'CLUSTER_UPGRADE': {'transformations': {'testname': config}}}
30 37
31 self.assertIs(config, Manager.get_config('testname')) 38 def test_get_config_default(self):
39 config = {'9.0': []}
40 self._test_get_config(config, {}, config)
41
42 def test_get_config_no_overwrite(self):
43 self._test_get_config(
44 {'9.0': ['a']},
45 self._trans_settings({'8.0': ['b']}),
46 {'8.0': ['b'], '9.0': ['a']},
47 )
48
49 def test_get_config_overwrite(self):
50 self._test_get_config(
51 {'9.0': ['a']},
52 self._trans_settings({'8.0': ['b'], '9.0': ['c']}),
53 {'8.0': ['b'], '9.0': ['c']},
54 )
32 55
33 def setup_extension_manager(self, extensions): 56 def setup_extension_manager(self, extensions):
34 p = mock.patch("stevedore.ExtensionManager", spec=['__call__']) 57 p = mock.patch("stevedore.ExtensionManager", spec=['__call__'])
@@ -154,8 +177,9 @@ class TestTransformations(nailgun_test_base.BaseUnitTest):
154 ), 177 ),
155 ]) 178 ])
156 179
180 @mock.patch.object(transformations.Manager, 'get_config')
157 @mock.patch.object(transformations.Manager, 'load_transformers') 181 @mock.patch.object(transformations.Manager, 'load_transformers')
158 def test_apply(self, mock_load): 182 def test_apply(self, mock_load, mock_config):
159 mock_trans = mock.Mock() 183 mock_trans = mock.Mock()
160 mock_load.return_value = [ 184 mock_load.return_value = [
161 (version.StrictVersion('7.0'), [mock_trans.a, mock_trans.b]), 185 (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):