Browse Source

Merge "Ansible module: fix deployment for private and/or shared images" into stable/rocky

changes/17/676517/1
Zuul 1 month ago
parent
commit
c4658ab1c1

+ 15
- 1
ironic/drivers/modules/ansible/deploy.py View File

@@ -266,7 +266,6 @@ def _prepare_variables(task):
266 266
     for i_key, i_value in i_info.items():
267 267
         if i_key.startswith('image_'):
268 268
             image[i_key[6:]] = i_value
269
-    image['mem_req'] = _calculate_memory_req(task)
270 269
 
271 270
     checksum = image.get('checksum')
272 271
     if checksum:
@@ -432,9 +431,24 @@ class AnsibleDeploy(agent_base.HeartbeatMixin, base.DeployInterface):
432 431
     @task_manager.require_exclusive_lock
433 432
     def deploy(self, task):
434 433
         """Perform a deployment to a node."""
434
+        self._required_image_info(task)
435 435
         manager_utils.node_power_action(task, states.REBOOT)
436 436
         return states.DEPLOYWAIT
437 437
 
438
+    @staticmethod
439
+    def _required_image_info(task):
440
+        """Gather and save needed image info while the context is good.
441
+
442
+        Gather image info that will be needed later, during the
443
+        continue_deploy execution, where the context won't be the same
444
+        anymore, since coming from the server's heartbeat.
445
+        """
446
+        node = task.node
447
+        i_info = node.instance_info
448
+        i_info['image_mem_req'] = _calculate_memory_req(task)
449
+        node.instance_info = i_info
450
+        node.save()
451
+
438 452
     @METRICS.timer('AnsibleDeploy.tear_down')
439 453
     @task_manager.require_exclusive_lock
440 454
     def tear_down(self, task):

+ 20
- 22
ironic/tests/unit/drivers/modules/ansible/test_deploy.py View File

@@ -307,22 +307,25 @@ class TestAnsibleMethods(AnsibleDeployTestCaseBase):
307 307
                 self.assertIn(six.text_type(key), six.text_type(exc))
308 308
                 self.assertIn(six.text_type(value), six.text_type(exc))
309 309
 
310
-    @mock.patch.object(ansible_deploy, '_calculate_memory_req', autospec=True,
311
-                       return_value=2000)
312
-    def test__prepare_variables(self, mem_req_mock):
310
+    def test__prepare_variables(self):
311
+        i_info = self.node.instance_info
312
+        i_info['image_mem_req'] = 3000
313
+        i_info['image_whatever'] = 'hello'
314
+        self.node.instance_info = i_info
315
+        self.node.save()
316
+
313 317
         expected = {"image": {"url": "http://image",
314 318
                               "validate_certs": "yes",
315 319
                               "source": "fake-image",
316
-                              "mem_req": 2000,
320
+                              "mem_req": 3000,
317 321
                               "disk_format": "qcow2",
318
-                              "checksum": "md5:checksum"}}
322
+                              "checksum": "md5:checksum",
323
+                              "whatever": "hello"}}
319 324
         with task_manager.acquire(self.context, self.node.uuid) as task:
320 325
             self.assertEqual(expected,
321 326
                              ansible_deploy._prepare_variables(task))
322 327
 
323
-    @mock.patch.object(ansible_deploy, '_calculate_memory_req', autospec=True,
324
-                       return_value=2000)
325
-    def test__prepare_variables_root_device_hints(self, mem_req_mock):
328
+    def test__prepare_variables_root_device_hints(self):
326 329
         props = self.node.properties
327 330
         props['root_device'] = {"wwn": "fake-wwn"}
328 331
         self.node.properties = props
@@ -330,7 +333,6 @@ class TestAnsibleMethods(AnsibleDeployTestCaseBase):
330 333
         expected = {"image": {"url": "http://image",
331 334
                               "validate_certs": "yes",
332 335
                               "source": "fake-image",
333
-                              "mem_req": 2000,
334 336
                               "disk_format": "qcow2",
335 337
                               "checksum": "md5:checksum"},
336 338
                     "root_device_hints": {"wwn": "fake-wwn"}}
@@ -338,9 +340,7 @@ class TestAnsibleMethods(AnsibleDeployTestCaseBase):
338 340
             self.assertEqual(expected,
339 341
                              ansible_deploy._prepare_variables(task))
340 342
 
341
-    @mock.patch.object(ansible_deploy, '_calculate_memory_req', autospec=True,
342
-                       return_value=2000)
343
-    def test__prepare_variables_noglance(self, mem_req_mock):
343
+    def test__prepare_variables_insecure_activated(self):
344 344
         self.config(image_store_insecure=True, group='ansible')
345 345
         i_info = self.node.instance_info
346 346
         i_info['image_checksum'] = 'sha256:checksum'
@@ -349,16 +349,13 @@ class TestAnsibleMethods(AnsibleDeployTestCaseBase):
349 349
         expected = {"image": {"url": "http://image",
350 350
                               "validate_certs": "no",
351 351
                               "source": "fake-image",
352
-                              "mem_req": 2000,
353 352
                               "disk_format": "qcow2",
354 353
                               "checksum": "sha256:checksum"}}
355 354
         with task_manager.acquire(self.context, self.node.uuid) as task:
356 355
             self.assertEqual(expected,
357 356
                              ansible_deploy._prepare_variables(task))
358 357
 
359
-    @mock.patch.object(ansible_deploy, '_calculate_memory_req', autospec=True,
360
-                       return_value=2000)
361
-    def test__prepare_variables_configdrive_url(self, mem_req_mock):
358
+    def test__prepare_variables_configdrive_url(self):
362 359
         i_info = self.node.instance_info
363 360
         i_info['configdrive'] = 'http://configdrive_url'
364 361
         self.node.instance_info = i_info
@@ -366,7 +363,6 @@ class TestAnsibleMethods(AnsibleDeployTestCaseBase):
366 363
         expected = {"image": {"url": "http://image",
367 364
                               "validate_certs": "yes",
368 365
                               "source": "fake-image",
369
-                              "mem_req": 2000,
370 366
                               "disk_format": "qcow2",
371 367
                               "checksum": "md5:checksum"},
372 368
                     'configdrive': {'type': 'url',
@@ -375,9 +371,7 @@ class TestAnsibleMethods(AnsibleDeployTestCaseBase):
375 371
             self.assertEqual(expected,
376 372
                              ansible_deploy._prepare_variables(task))
377 373
 
378
-    @mock.patch.object(ansible_deploy, '_calculate_memory_req', autospec=True,
379
-                       return_value=2000)
380
-    def test__prepare_variables_configdrive_file(self, mem_req_mock):
374
+    def test__prepare_variables_configdrive_file(self):
381 375
         i_info = self.node.instance_info
382 376
         i_info['configdrive'] = 'fake-content'
383 377
         self.node.instance_info = i_info
@@ -388,7 +382,6 @@ class TestAnsibleMethods(AnsibleDeployTestCaseBase):
388 382
         expected = {"image": {"url": "http://image",
389 383
                               "validate_certs": "yes",
390 384
                               "source": "fake-image",
391
-                              "mem_req": 2000,
392 385
                               "disk_format": "qcow2",
393 386
                               "checksum": "md5:checksum"},
394 387
                     'configdrive': {'type': 'file',
@@ -519,13 +512,18 @@ class TestAnsibleDeploy(AnsibleDeployTestCaseBase):
519 512
                 task.driver.boot, task)
520 513
             get_boot_mock.assert_called_once_with(task.node)
521 514
 
515
+    @mock.patch.object(ansible_deploy, '_calculate_memory_req', autospec=True,
516
+                       return_value=2000)
522 517
     @mock.patch.object(utils, 'node_power_action', autospec=True)
523
-    def test_deploy(self, power_mock):
518
+    def test_deploy(self, power_mock, mem_req_mock):
524 519
         with task_manager.acquire(
525 520
                 self.context, self.node['uuid'], shared=False) as task:
526 521
             driver_return = self.driver.deploy(task)
527 522
             self.assertEqual(driver_return, states.DEPLOYWAIT)
528 523
             power_mock.assert_called_once_with(task, states.REBOOT)
524
+            mem_req_mock.assert_called_once_with(task)
525
+            i_info = task.node.instance_info
526
+            self.assertEqual(i_info['image_mem_req'], 2000)
529 527
 
530 528
     @mock.patch.object(utils, 'node_power_action', autospec=True)
531 529
     def test_tear_down(self, power_mock):

+ 7
- 0
releasenotes/notes/bug-35702-25da234580ca0c31.yaml View File

@@ -0,0 +1,7 @@
1
+---
2
+fixes:
3
+      - |
4
+          Fixes an issue regarding the ``ansible`` deploy interface. Node
5
+          deployment was broken for any image that was not public because
6
+          the original request context was not available anymore at the time
7
+          some image information was fetched.

Loading…
Cancel
Save