Browse Source

Move change_env_settings function from octane to cluster upgrade extension

* change_env_settings function was moved to cluster upgrade extention
* merge generated attributes code was written

Change-Id: I6d1e27b8b0c01f3251067bc88931cd2354feb5ce
Partial-Bug: #1602587
(cherry picked from commit dc2e3f9309)
Anastasiya 2 years ago
parent
commit
a78f4348f8
2 changed files with 43 additions and 3 deletions
  1. 29
    2
      cluster_upgrade/tests/test_upgrade.py
  2. 14
    1
      cluster_upgrade/upgrade.py

+ 29
- 2
cluster_upgrade/tests/test_upgrade.py View File

@@ -97,8 +97,16 @@ class TestUpgradeHelperCloneCluster(base_tests.BaseCloneClusterTest):
97 97
 
98 98
         self.helper.copy_attributes(self.src_cluster, new_cluster)
99 99
 
100
-        self.assertEqual(self.src_cluster.generated_attrs,
101
-                         new_cluster.generated_attrs)
100
+        self.assertNotEqual(new_cluster.generated_attrs.get('provision'),
101
+                            self.src_cluster.generated_attrs.get('provision'))
102
+
103
+        # We make image_data in src_cluster and in new_cluster the same
104
+        # to validate that all other generated attributes are equal
105
+        generated_attrs = copy.deepcopy(self.src_cluster.generated_attrs)
106
+        generated_attrs['provision']['image_data'] = \
107
+            new_cluster.generated_attrs['provision']['image_data']
108
+
109
+        self.assertEqual(generated_attrs, new_cluster.generated_attrs)
102 110
         editable_attrs = self.src_cluster.editable_attrs
103 111
         for section, params in six.iteritems(new_cluster.editable_attrs):
104 112
             if section == "repo_setup":
@@ -211,3 +219,22 @@ class TestUpgradeHelperCloneCluster(base_tests.BaseCloneClusterTest):
211 219
         self.helper.copy_attributes(self.src_cluster, new_cluster)
212 220
         self._check_dns_and_ntp_list_values(
213 221
             new_cluster, ["4", "5", "6"], ["1", "2", "3"])
222
+
223
+    def test_change_env_settings(self):
224
+        new_cluster = self.helper.create_cluster_clone(self.src_cluster,
225
+                                                       self.data)
226
+        self.helper.copy_attributes(self.src_cluster, new_cluster)
227
+        attrs = new_cluster.attributes
228
+        self.helper.change_env_settings(self.src_cluster, new_cluster)
229
+        self.assertEqual('image',
230
+                         attrs['editable']['provision']['method']['value'])
231
+
232
+    def test_change_env_settings_no_editable_provision(self):
233
+        new_cluster = self.helper.create_cluster_clone(self.src_cluster,
234
+                                                       self.data)
235
+        self.helper.copy_attributes(self.src_cluster, new_cluster)
236
+        attrs = new_cluster.attributes
237
+        attrs['editable']['provision']['method']['value'] = 'cobbler'
238
+        self.helper.change_env_settings(self.src_cluster, new_cluster)
239
+        self.assertEqual('image',
240
+                         attrs['editable']['provision']['method']['value'])

+ 14
- 1
cluster_upgrade/upgrade.py View File

@@ -53,6 +53,13 @@ def merge_attributes(a, b):
53 53
     return attrs
54 54
 
55 55
 
56
+def merge_generated_attrs(new_attrs, orig_attrs):
57
+    # skip attributes that should be generated for new cluster
58
+    attrs = copy.deepcopy(orig_attrs)
59
+    attrs.pop('provision', None)
60
+    return utils.dict_merge(new_attrs, attrs)
61
+
62
+
56 63
 def merge_nets(a, b):
57 64
     new_settings = copy.deepcopy(b)
58 65
     source_networks = dict((n["name"], n) for n in a["networks"])
@@ -90,6 +97,7 @@ class UpgradeHelper(object):
90 97
         cls.copy_network_config(orig_cluster, new_cluster)
91 98
         relations.UpgradeRelationObject.create_relation(orig_cluster.id,
92 99
                                                         new_cluster.id)
100
+        cls.change_env_settings(orig_cluster, new_cluster)
93 101
         return new_cluster
94 102
 
95 103
     @classmethod
@@ -110,13 +118,18 @@ class UpgradeHelper(object):
110 118
         #                version to another. A set of this kind of steps
111 119
         #                should define an upgrade path of a particular
112 120
         #                cluster.
113
-        new_cluster.generated_attrs = utils.dict_merge(
121
+        new_cluster.generated_attrs = merge_generated_attrs(
114 122
             new_cluster.generated_attrs,
115 123
             orig_cluster.generated_attrs)
116 124
         new_cluster.editable_attrs = merge_attributes(
117 125
             orig_cluster.editable_attrs,
118 126
             new_cluster.editable_attrs)
119 127
 
128
+    @classmethod
129
+    def change_env_settings(cls, orig_cluster, new_cluster):
130
+        attrs = new_cluster.attributes
131
+        attrs['editable']['provision']['method']['value'] = 'image'
132
+
120 133
     @classmethod
121 134
     def transform_vips_for_net_groups_70(cls, vips):
122 135
         """Rename or remove types of VIPs for 7.0 network groups.

Loading…
Cancel
Save