Browse Source

Merge "Set nodes' statuses to 'error' when their nodegroup is deleted"

tags/11.0.0.0rc1
Jenkins 2 years ago
parent
commit
6c29488b0c

+ 12
- 0
nailgun/nailgun/extensions/network_manager/extension.py View File

@@ -182,6 +182,18 @@ class NetworkManagerExtension(BaseExtension):
182 182
 
183 183
     @classmethod
184 184
     def on_nodegroup_delete(cls, ng):
185
+        netmanager = objects.Cluster.get_network_manager(ng.cluster)
186
+        default_admin_net = objects.NetworkGroup.get_default_admin_network()
187
+        for node in ng.nodes:
188
+            objects.Node.remove_from_cluster(node)
189
+            if not netmanager.is_same_network(node.ip, default_admin_net.cidr):
190
+                objects.Node.set_error_status_and_file_notification(
191
+                    node,
192
+                    consts.NODE_ERRORS.discover,
193
+                    "Node '{0}' nodegroup was deleted which means that it may "
194
+                    "not be able to boot correctly unless it is a member of "
195
+                    "another node group admin network".format(node.hostname)
196
+                )
185 197
         try:
186 198
             task = UpdateDnsmasqTaskManager().execute()
187 199
         except errors.TaskAlreadyRunning:

+ 2
- 2
nailgun/nailgun/test/base.py View File

@@ -1452,7 +1452,7 @@ class EnvironmentManager(object):
1452 1452
                              expect_errors)
1453 1453
 
1454 1454
     def _create_network_group(self, expect_errors=False, cluster=None,
1455
-                              **kwargs):
1455
+                              group_id=None, **kwargs):
1456 1456
         if not cluster:
1457 1457
             cluster = self.clusters[0]
1458 1458
         ng = {
@@ -1461,7 +1461,7 @@ class EnvironmentManager(object):
1461 1461
             "vlan_start": 50,
1462 1462
             "cidr": "10.3.0.0/24",
1463 1463
             "gateway": "10.3.0.1",
1464
-            "group_id": Cluster.get_default_group(cluster).id,
1464
+            "group_id": group_id or Cluster.get_default_group(cluster).id,
1465 1465
             "meta": {
1466 1466
                 "notation": consts.NETWORK_NOTATION.cidr,
1467 1467
                 "use_gateway": True,

+ 38
- 1
nailgun/nailgun/test/unit/test_node_groups.py View File

@@ -26,6 +26,7 @@ from nailgun.db import db
26 26
 from nailgun.db.sqlalchemy import models
27 27
 from nailgun import errors
28 28
 from nailgun import objects
29
+from nailgun.rpc.receiver import NailgunReceiver
29 30
 from nailgun.test.base import BaseIntegrationTest
30 31
 from nailgun.utils import reverse
31 32
 
@@ -37,7 +38,7 @@ class TestNodeGroups(BaseIntegrationTest):
37 38
     def setUp(self):
38 39
         super(TestNodeGroups, self).setUp()
39 40
         self.cluster = self.env.create(
40
-            release_kwargs={'version': '1111-8.0'},
41
+            release_kwargs={'version': '1111-9.0'},
41 42
             cluster_kwargs={
42 43
                 'api': False,
43 44
                 'net_provider': consts.CLUSTER_NET_PROVIDERS.neutron,
@@ -159,6 +160,42 @@ class TestNodeGroups(BaseIntegrationTest):
159 160
         self.assertEqual(err.exception.message,
160 161
                          'Default node group cannot be deleted.')
161 162
 
163
+    @patch('nailgun.task.task.rpc.cast')
164
+    @patch('objects.Notification.create')
165
+    def test_delete_non_default_node_group_reset_node_to_error(
166
+            self, _, notify):
167
+        node_group = self.env.create_node_group(api=False,
168
+                                                cluster_id=self.cluster.id)
169
+        self.env._create_network_group(cluster=self.cluster,
170
+                                       group_id=node_group.id)
171
+        node2 = self.env.create_node(group_id=node_group.id,
172
+                                     roles=['compute'],
173
+                                     status=consts.NODE_STATUSES.provisioned,
174
+                                     cluster_id=self.cluster.id,
175
+                                     ip='10.3.0.42')
176
+        task = self.env.launch_deployment()
177
+        NailgunReceiver.deploy_resp(
178
+            task_uuid=task.uuid,
179
+            status=consts.TASK_STATUSES.ready,
180
+            progress=100,
181
+            nodes=[{'uid': n.uid, 'status': consts.NODE_STATUSES.ready,
182
+                    'progress': 100}
183
+                   for n in self.env.nodes],
184
+        )
185
+        reset_task = self.env.reset_environment()
186
+        NailgunReceiver.reset_environment_resp(
187
+            task_uuid=reset_task.uuid,
188
+            status=consts.TASK_STATUSES.ready,
189
+            progress=100,
190
+            nodes=[{'uid': n.uid}
191
+                   for n in self.env.nodes],
192
+        )
193
+        self.env.delete_node_group(node_group.id)
194
+        self.assertEqual(node2.status, consts.NODE_STATUSES.error)
195
+        self.assertEqual(node2.error_type, consts.NODE_ERRORS.discover)
196
+        self.assertIsNone(node2.cluster)
197
+        notify.assert_called()
198
+
162 199
     def test_delete_non_default_node_group_error(self):
163 200
         node_group = self.env.create_node_group(api=False,
164 201
                                                 cluster_id=self.cluster.id)

Loading…
Cancel
Save