Browse Source

Add tests for assign_node_to_cluster

Change-Id: Iafa1baa6a1ca4d701ec89e49dd9d6f969804c82e
Anastasiya 2 years ago
parent
commit
b3ce0d348c
2 changed files with 53 additions and 3 deletions
  1. 11
    3
      cluster_upgrade/objects/adapters.py
  2. 42
    0
      cluster_upgrade/tests/test_upgrade.py

+ 11
- 3
cluster_upgrade/objects/adapters.py View File

@@ -58,13 +58,17 @@ class NailgunClusterAdapter(object):
58 58
     def editable_attrs(self):
59 59
         return self.cluster.attributes.editable
60 60
 
61
+    @editable_attrs.setter
62
+    def editable_attrs(self, attrs):
63
+        self.cluster.attributes.editable = attrs
64
+
61 65
     @property
62 66
     def network_template(self):
63 67
         return self.cluster.network_config.configuration_template
64 68
 
65
-    @editable_attrs.setter
66
-    def editable_attrs(self, attrs):
67
-        self.cluster.attributes.editable = attrs
69
+    @network_template.setter
70
+    def network_template(self, template):
71
+        self.cluster.network_config.configuration_template = template
68 72
 
69 73
     def get_create_data(self):
70 74
         return objects.Cluster.get_create_data(self.cluster)
@@ -177,6 +181,10 @@ class NailgunNodeAdapter(object):
177 181
     def status(self):
178 182
         return self.node.status
179 183
 
184
+    @property
185
+    def nic_interfaces(self):
186
+        return self.node.nic_interfaces
187
+
180 188
     @property
181 189
     def error_type(self):
182 190
         return self.node.error_type

+ 42
- 0
cluster_upgrade/tests/test_upgrade.py View File

@@ -20,6 +20,7 @@ import six
20 20
 from nailgun import consts
21 21
 from nailgun.extensions.network_manager.objects.serializers import \
22 22
     network_configuration
23
+from nailgun.test.base import fake_tasks
23 24
 
24 25
 from .. import upgrade
25 26
 from . import base as base_tests
@@ -239,3 +240,44 @@ class TestUpgradeHelperCloneCluster(base_tests.BaseCloneClusterTest):
239 240
         self.helper.change_env_settings(self.src_cluster, new_cluster)
240 241
         self.assertEqual('image',
241 242
                          attrs['editable']['provision']['method']['value'])
243
+
244
+    def get_assigned_nets(self, node):
245
+        assigned_nets = {}
246
+        for iface in node.nic_interfaces:
247
+            nets = [net.name for net in iface.assigned_networks_list]
248
+            assigned_nets[iface.name] = nets
249
+        return assigned_nets
250
+
251
+    @fake_tasks()
252
+    def assign_node_to_cluster(self, template=None):
253
+        new_cluster = self.helper.clone_cluster(self.src_cluster, self.data)
254
+        node = adapters.NailgunNodeAdapter(self.src_cluster.cluster.nodes[0])
255
+
256
+        orig_assigned_nets = self.get_assigned_nets(node)
257
+
258
+        if template:
259
+            net_template = self.env.read_fixtures(['network_template_80'])[0]
260
+            new_cluster.network_template = net_template
261
+            orig_assigned_nets = {
262
+                'eth0': ['fuelweb_admin'], 'eth1': ['public', 'management']
263
+            }
264
+
265
+        self.helper.assign_node_to_cluster(node, new_cluster, node.roles, [])
266
+        self.db.refresh(new_cluster.cluster)
267
+
268
+        self.assertEqual(node.cluster_id, new_cluster.id)
269
+
270
+        self.env.clusters.append(new_cluster.cluster)
271
+        task = self.env.launch_provisioning_selected(cluster_id=new_cluster.id)
272
+        self.assertEqual(task.status, consts.TASK_STATUSES.ready)
273
+        for n in new_cluster.cluster.nodes:
274
+            self.assertEqual(consts.NODE_STATUSES.provisioned, n.status)
275
+
276
+        new_assigned_nets = self.get_assigned_nets(node)
277
+        self.assertEqual(orig_assigned_nets, new_assigned_nets)
278
+
279
+    def test_assign_node_to_cluster(self):
280
+        self.assign_node_to_cluster()
281
+
282
+    def test_assign_node_to_cluster_with_template(self):
283
+        self.assign_node_to_cluster(template=True)

Loading…
Cancel
Save