Browse Source

Merge "Use fields="instance_uuid" when calling Ironic API"

changes/10/680810/1
Zuul 1 week ago
parent
commit
535af1ee12
2 changed files with 28 additions and 6 deletions
  1. 22
    4
      nova/tests/unit/virt/ironic/test_driver.py
  2. 6
    2
      nova/virt/ironic/driver.py

+ 22
- 4
nova/tests/unit/virt/ironic/test_driver.py View File

@@ -594,13 +594,22 @@ class IronicDriverTestCase(test.NoDBTestCase):
594 594
         response = self.driver.list_instances()
595 595
 
596 596
         self.mock_conn.nodes.assert_called_with(associated=True,
597
-                                                fields=['instance_id'])
597
+                                                fields=['instance_uuid'])
598 598
         expected_calls = [mock.call(mock.ANY, instances[0].uuid),
599 599
                           mock.call(mock.ANY, instances[1].uuid)]
600 600
         mock_inst_by_uuid.assert_has_calls(expected_calls)
601 601
         self.assertEqual(['instance-00000000', 'instance-00000001'],
602 602
                          sorted(response))
603 603
 
604
+    # NOTE(dustinc) This test ensures we use instance_uuid not instance_id in
605
+    # 'fields' when calling ironic.
606
+    @mock.patch.object(objects.Instance, 'get_by_uuid')
607
+    def test_list_instances_uses_instance_uuid(self, mock_inst_by_uuid):
608
+        self.driver.list_instances()
609
+
610
+        self.mock_conn.nodes.assert_called_with(associated=True,
611
+                                                fields=['instance_uuid'])
612
+
604 613
     @mock.patch.object(objects.Instance, 'get_by_uuid')
605 614
     def test_list_instances_fail(self, mock_inst_by_uuid):
606 615
         self.mock_conn.nodes.side_effect = exception.NovaException
@@ -608,7 +617,7 @@ class IronicDriverTestCase(test.NoDBTestCase):
608 617
         self.assertRaises(exception.VirtDriverNotReady,
609 618
                           self.driver.list_instances)
610 619
         self.mock_conn.nodes.assert_called_with(associated=True,
611
-                                                fields=['instance_id'])
620
+                                                fields=['instance_uuid'])
612 621
         self.assertFalse(mock_inst_by_uuid.called)
613 622
 
614 623
     def test_list_instance_uuids(self):
@@ -616,17 +625,26 @@ class IronicDriverTestCase(test.NoDBTestCase):
616 625
         nodes = []
617 626
         for n in range(num_nodes):
618 627
             nodes.append(ironic_utils.get_test_node(
619
-                                      instance_uuid=uuidutils.generate_uuid(),
628
+                                      instance_id=uuidutils.generate_uuid(),
620 629
                                       fields=['instance_id']))
621 630
         self.mock_conn.nodes.return_value = iter(nodes)
622 631
 
623 632
         uuids = self.driver.list_instance_uuids()
624 633
 
625 634
         self.mock_conn.nodes.assert_called_with(associated=True,
626
-                                                fields=['instance_id'])
635
+                                                fields=['instance_uuid'])
627 636
         expected = [n.instance_id for n in nodes]
628 637
         self.assertEqual(sorted(expected), sorted(uuids))
629 638
 
639
+    # NOTE(dustinc) This test ensures we use instance_uuid not instance_id in
640
+    # 'fields' when calling ironic.
641
+    @mock.patch.object(objects.Instance, 'get_by_uuid')
642
+    def test_list_instance_uuids_uses_instance_uuid(self, mock_inst_by_uuid):
643
+        self.driver.list_instance_uuids()
644
+
645
+        self.mock_conn.nodes.assert_called_with(associated=True,
646
+                                                fields=['instance_uuid'])
647
+
630 648
     @mock.patch.object(objects.InstanceList, 'get_uuids_by_host')
631 649
     @mock.patch.object(objects.ServiceList, 'get_all_computes_by_hv_type')
632 650
     def test_node_is_available_empty_cache_empty_list(self, mock_services,

+ 6
- 2
nova/virt/ironic/driver.py View File

@@ -688,11 +688,13 @@ class IronicDriver(virt_driver.ComputeDriver):
688 688
         :raises: VirtDriverNotReady
689 689
 
690 690
         """
691
+        # NOTE(dustinc): The SDK returns an object with instance_id,
692
+        #  but the Ironic API expects instance_uuid in query.
691 693
         context = nova_context.get_admin_context()
692 694
         return [objects.Instance.get_by_uuid(context, i.instance_id).name
693 695
                 for i in self._get_node_list(return_generator=True,
694 696
                                              associated=True,
695
-                                             fields=['instance_id'])]
697
+                                             fields=['instance_uuid'])]
696 698
 
697 699
     def list_instance_uuids(self):
698 700
         """Return the IDs of all the instances provisioned.
@@ -701,8 +703,10 @@ class IronicDriver(virt_driver.ComputeDriver):
701 703
         :raises: VirtDriverNotReady
702 704
 
703 705
         """
706
+        # NOTE(dustinc): The SDK returns an object with instance_id,
707
+        #  but the Ironic API expects instance_uuid in query.
704 708
         return [node.instance_id for node in self._get_node_list(
705
-            return_generator=True, associated=True, fields=['instance_id'])]
709
+            return_generator=True, associated=True, fields=['instance_uuid'])]
706 710
 
707 711
     def node_is_available(self, nodename):
708 712
         """Confirms a Nova hypervisor node exists in the Ironic inventory.

Loading…
Cancel
Save