Browse Source

Add info about upgrade to deployment_info

This patch adds new data pipline for seed cluster that add to cluster
deployment info attributes about upgrade

Change-Id: I0630e75508552927b67065ff85cb6bac1bb88f61
Nikita Zubkov 2 years ago
parent
commit
e7b127a308

+ 19
- 1
cluster_upgrade/extension.py View File

@@ -18,7 +18,21 @@ import os
18 18
 
19 19
 from nailgun import extensions
20 20
 
21
-from . import handlers
21
+from cluster_upgrade import handlers
22
+
23
+
24
+class UpgradePipeline(extensions.BasePipeline):
25
+    @classmethod
26
+    def process_deployment_for_cluster(cls, cluster, cluster_data):
27
+        from cluster_upgrade.objects.relations import UpgradeRelationObject
28
+
29
+        relation = UpgradeRelationObject.get_cluster_relation(cluster.id)
30
+        cluster_data['upgrade'] = {
31
+            'relation_info': {
32
+                'orig_cluster_id': relation.orig_cluster_id,
33
+                'seed_cluster_id': relation.seed_cluster_id,
34
+            }
35
+        }
22 36
 
23 37
 
24 38
 class ClusterUpgradeExtension(extensions.BaseExtension):
@@ -26,6 +40,10 @@ class ClusterUpgradeExtension(extensions.BaseExtension):
26 40
     version = '0.0.1'
27 41
     description = "Cluster Upgrade Extension"
28 42
 
43
+    data_pipelines = [
44
+        UpgradePipeline,
45
+    ]
46
+
29 47
     urls = [
30 48
         {'uri': r'/clusters/(?P<cluster_id>\d+)/upgrade/clone/?$',
31 49
          'handler': handlers.ClusterUpgradeCloneHandler},

+ 2
- 0
cluster_upgrade/handlers.py View File

@@ -19,6 +19,7 @@ import six
19 19
 
20 20
 from nailgun.api.v1.handlers import base
21 21
 from nailgun import errors
22
+from nailgun.extensions.manager import update_extensions_for_object
22 23
 from nailgun import objects
23 24
 from nailgun.task import manager
24 25
 
@@ -61,6 +62,7 @@ class ClusterUpgradeCloneHandler(base.BaseHandler):
61 62
             raise errors.InvalidData("Network changes during upgrade"
62 63
                                      " is not supported.")
63 64
 
65
+        update_extensions_for_object(new_cluster.cluster, ['cluster_upgrade'])
64 66
         return new_cluster.to_dict()
65 67
 
66 68
 

+ 39
- 2
cluster_upgrade/tests/test_extension.py View File

@@ -15,10 +15,16 @@
15 15
 #    under the License.
16 16
 
17 17
 import mock
18
+from oslo_serialization import jsonutils
19
+
20
+from nailgun import objects
21
+from nailgun.orchestrator.deployment_serializers import DeploymentLCMSerializer
18 22
 from nailgun.test.base import BaseTestCase
23
+from nailgun.utils import reverse
19 24
 
20
-from .. import extension
21
-from ..objects import relations
25
+from cluster_upgrade import extension
26
+from cluster_upgrade.objects import relations
27
+from cluster_upgrade.tests import base
22 28
 
23 29
 
24 30
 class TestExtension(BaseTestCase):
@@ -27,3 +33,34 @@ class TestExtension(BaseTestCase):
27 33
         cluster = mock.Mock(id=42)
28 34
         extension.ClusterUpgradeExtension.on_cluster_delete(cluster)
29 35
         mock_on_cluster_delete.assert_called_once_with(42)
36
+
37
+
38
+class TestPipeline(base.BaseCloneClusterTest):
39
+    def setUp(self):
40
+        super(TestPipeline, self).setUp()
41
+
42
+        resp = self.app.post(
43
+            reverse("ClusterUpgradeCloneHandler",
44
+                    kwargs={"cluster_id": self.src_cluster_db.id}),
45
+            jsonutils.dumps(self.data),
46
+            headers=self.default_headers
47
+        ).json_body
48
+
49
+        self.dst_cluster_db = objects.Cluster.get_by_uid(resp['id'])
50
+
51
+    def test_upgrade_info(self):
52
+        deployment_info = DeploymentLCMSerializer().serialize(
53
+            self.dst_cluster_db, []
54
+        )
55
+
56
+        expected = {
57
+            'relation_info': {
58
+                'orig_cluster_id': self.src_cluster_db.id,
59
+                'seed_cluster_id': self.dst_cluster_db.id,
60
+            }
61
+        }
62
+
63
+        self.assertEqual(
64
+            deployment_info['common']['upgrade'],
65
+            expected,
66
+        )

Loading…
Cancel
Save