Browse Source

Move partition info transformation to extension

octane have some dirty hacks to change volumes attributes using nailgun
as a library, such modifications should be done in a extension

Change-Id: I422bb368916f3a319e286edcc6103a2834097a87
Nikita Zubkov 2 years ago
parent
commit
b54f9d4c29

+ 9
- 0
cluster_upgrade/objects/adapters.py View File

@@ -14,6 +14,7 @@
14 14
 #    License for the specific language governing permissions and limitations
15 15
 #    under the License.
16 16
 
17
+from nailgun.extensions.volume_manager import extension as volume_ext
17 18
 from nailgun import objects
18 19
 
19 20
 
@@ -200,6 +201,14 @@ class NailgunNodeAdapter(object):
200 201
     def add_pending_change(self, change):
201 202
         objects.Node.add_pending_change(self.node, change)
202 203
 
204
+    def get_volumes(self):
205
+        return volume_ext.VolumeManagerExtension.get_node_volumes(self.node)
206
+
207
+    def set_volumes(self, volumes):
208
+        return volume_ext.VolumeManagerExtension.set_node_volumes(
209
+            self.node, volumes
210
+        )
211
+
203 212
 
204 213
 class NailgunNetworkGroupAdapter(object):
205 214
 

+ 2
- 2
cluster_upgrade/transformations/__init__.py View File

@@ -64,8 +64,8 @@ class Manager(object):
64 64
     def apply(self, from_version, to_version, data):
65 65
         strict_from = distutils.version.StrictVersion(from_version)
66 66
         strict_to = distutils.version.StrictVersion(to_version)
67
-        assert strict_from < strict_to, \
68
-            "from_version must be smaller than to_version"
67
+        assert strict_from <= strict_to, \
68
+            "from_version must not be greater than to_version"
69 69
         data = copy.deepcopy(data)
70 70
         for version, transformers in self.transformers:
71 71
             if version <= strict_from:

+ 53
- 0
cluster_upgrade/transformations/volumes.py View File

@@ -0,0 +1,53 @@
1
+# coding: utf-8
2
+
3
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+#    not use this file except in compliance with the License. You may obtain
5
+#    a copy of the License at
6
+#
7
+#         http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+#    Unless required by applicable law or agreed to in writing, software
10
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+#    License for the specific language governing permissions and limitations
13
+#    under the License.
14
+
15
+from cluster_upgrade import transformations
16
+
17
+
18
+def transform_node_volumes(volumes):
19
+    try:
20
+        os_vg = next(vol for vol in volumes
21
+                     if 'id' in vol and vol['id'] == 'os')
22
+    except StopIteration:
23
+        return volumes
24
+
25
+    other_volumes = [vol for vol in volumes
26
+                     if 'id' not in vol or vol['id'] != 'os']
27
+
28
+    for disk in other_volumes:
29
+        disk_volumes = disk['volumes']
30
+        disk['volumes'] = []
31
+
32
+        for v in disk_volumes:
33
+            if v['type'] == 'pv' and v['vg'] == 'os' and v['size'] > 0:
34
+                for vv in os_vg['volumes']:
35
+                    partition = {'name': vv['name'],
36
+                                 'size': vv['size'],
37
+                                 'type': 'partition',
38
+                                 'mount': vv['mount'],
39
+                                 'file_system': vv['file_system']}
40
+                    disk['volumes'].append(partition)
41
+            else:
42
+                if v['type'] == 'lvm_meta_pool' or v['type'] == 'boot':
43
+                    v['size'] = 0
44
+                disk['volumes'].append(v)
45
+
46
+    return volumes
47
+
48
+
49
+class Manager(transformations.Manager):
50
+    default_config = {
51
+        '6.1': ['node_volumes']
52
+    }
53
+    name = 'volumes'

+ 9
- 0
cluster_upgrade/upgrade.py View File

@@ -28,6 +28,7 @@ from nailgun import utils
28 28
 from . import transformations  # That's weird, but that's how hacking likes
29 29
 from .objects import adapters
30 30
 from .transformations import cluster as cluster_trs
31
+from .transformations import volumes as volumes_trs
31 32
 
32 33
 
33 34
 def merge_attributes(a, b):
@@ -75,6 +76,7 @@ class UpgradeHelper(object):
75 76
         network_configuration.NovaNetworkConfigurationSerializer,
76 77
     }
77 78
     cluster_transformations = transformations.Lazy(cluster_trs.Manager)
79
+    volumes_transformations = transformations.Lazy(volumes_trs.Manager)
78 80
 
79 81
     @classmethod
80 82
     def clone_cluster(cls, orig_cluster, data):
@@ -215,6 +217,13 @@ class UpgradeHelper(object):
215 217
         orig_cluster = adapters.NailgunClusterAdapter.get_by_uid(
216 218
             node.cluster_id)
217 219
 
220
+        volumes = cls.volumes_transformations.apply(
221
+            orig_cluster.release.environment_version,
222
+            seed_cluster.release.environment_version,
223
+            node.get_volumes(),
224
+        )
225
+        node.set_volumes(volumes)
226
+
218 227
         orig_manager = orig_cluster.get_network_manager()
219 228
 
220 229
         netgroups_id_mapping = cls.get_netgroups_id_mapping(

+ 2
- 0
setup.cfg View File

@@ -25,6 +25,8 @@ packages =
25 25
 [entry_points]
26 26
 nailgun.extensions =
27 27
     cluster_upgrade = cluster_upgrade.extension:ClusterUpgradeExtension
28
+nailgun.cluster_upgrade.transformations.volumes.6.1 =
29
+    node_volumes = cluster_upgrade.transformations.volumes:transform_node_volumes
28 30
 nailgun.cluster_upgrade.transformations.cluster.9.0 =
29 31
     dns_list = cluster_upgrade.transformations.cluster:transform_dns_list
30 32
     ntp_list = cluster_upgrade.transformations.cluster:transform_ntp_list

Loading…
Cancel
Save