Browse Source

Merge "Add tests for assign_node_to_cluster"

Jenkins 2 years ago
parent
commit
72df55c185
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)
@@ -181,6 +185,10 @@ class NailgunNodeAdapter(object):
181 185
     def status(self):
182 186
         return self.node.status
183 187
 
188
+    @property
189
+    def nic_interfaces(self):
190
+        return self.node.nic_interfaces
191
+
184 192
     @property
185 193
     def error_type(self):
186 194
         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
@@ -236,3 +237,44 @@ class TestUpgradeHelperCloneCluster(base_tests.BaseCloneClusterTest):
236 237
         self.helper.change_env_settings(self.src_cluster, new_cluster)
237 238
         self.assertEqual('image',
238 239
                          attrs['editable']['provision']['method']['value'])
240
+
241
+    def get_assigned_nets(self, node):
242
+        assigned_nets = {}
243
+        for iface in node.nic_interfaces:
244
+            nets = [net.name for net in iface.assigned_networks_list]
245
+            assigned_nets[iface.name] = nets
246
+        return assigned_nets
247
+
248
+    @fake_tasks()
249
+    def assign_node_to_cluster(self, template=None):
250
+        new_cluster = self.helper.clone_cluster(self.src_cluster, self.data)
251
+        node = adapters.NailgunNodeAdapter(self.src_cluster.cluster.nodes[0])
252
+
253
+        orig_assigned_nets = self.get_assigned_nets(node)
254
+
255
+        if template:
256
+            net_template = self.env.read_fixtures(['network_template_80'])[0]
257
+            new_cluster.network_template = net_template
258
+            orig_assigned_nets = {
259
+                'eth0': ['fuelweb_admin'], 'eth1': ['public', 'management']
260
+            }
261
+
262
+        self.helper.assign_node_to_cluster(node, new_cluster, node.roles, [])
263
+        self.db.refresh(new_cluster.cluster)
264
+
265
+        self.assertEqual(node.cluster_id, new_cluster.id)
266
+
267
+        self.env.clusters.append(new_cluster.cluster)
268
+        task = self.env.launch_provisioning_selected(cluster_id=new_cluster.id)
269
+        self.assertEqual(task.status, consts.TASK_STATUSES.ready)
270
+        for n in new_cluster.cluster.nodes:
271
+            self.assertEqual(consts.NODE_STATUSES.provisioned, n.status)
272
+
273
+        new_assigned_nets = self.get_assigned_nets(node)
274
+        self.assertEqual(orig_assigned_nets, new_assigned_nets)
275
+
276
+    def test_assign_node_to_cluster(self):
277
+        self.assign_node_to_cluster()
278
+
279
+    def test_assign_node_to_cluster_with_template(self):
280
+        self.assign_node_to_cluster(template=True)

Loading…
Cancel
Save