@@ -1583,7 +1583,11 @@ def test_set_host_enabled_with_disable(self, mock_svc, mock_save):
1583
1583
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
1584
1584
svc = self._create_service(host='fake-mini')
1585
1585
mock_svc.return_value = svc
1586
- drvr._set_host_enabled(False)
1586
+ with mock.patch.object(
1587
+ drvr, '_update_compute_provider_status') as ucps:
1588
+ drvr._set_host_enabled(False)
1589
+ ucps.assert_called_once_with(
1590
+ test.MatchType(context.RequestContext), svc)
1587
1591
self.assertTrue(svc.disabled)
1588
1592
mock_save.assert_called_once_with()
1589
1593
@@ -1594,7 +1598,10 @@ def test_set_host_enabled_with_enable(self, mock_svc, mock_save):
1594
1598
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
1595
1599
svc = self._create_service(disabled=True, host='fake-mini')
1596
1600
mock_svc.return_value = svc
1597
- drvr._set_host_enabled(True)
1601
+ with mock.patch.object(
1602
+ drvr, '_update_compute_provider_status') as ucps:
1603
+ drvr._set_host_enabled(True)
1604
+ ucps.assert_not_called()
1598
1605
# since disabled_reason is not set and not prefixed with "AUTO:",
1599
1606
# service should not be enabled.
1600
1607
mock_save.assert_not_called()
@@ -1608,7 +1615,10 @@ def test_set_host_enabled_with_enable_state_enabled(self, mock_svc,
1608
1615
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
1609
1616
svc = self._create_service(disabled=False, host='fake-mini')
1610
1617
mock_svc.return_value = svc
1611
- drvr._set_host_enabled(True)
1618
+ with mock.patch.object(
1619
+ drvr, '_update_compute_provider_status') as ucps:
1620
+ drvr._set_host_enabled(True)
1621
+ ucps.assert_not_called()
1612
1622
self.assertFalse(svc.disabled)
1613
1623
mock_save.assert_not_called()
1614
1624
@@ -1620,7 +1630,10 @@ def test_set_host_enabled_with_disable_state_disabled(self, mock_svc,
1620
1630
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
1621
1631
svc = self._create_service(disabled=True, host='fake-mini')
1622
1632
mock_svc.return_value = svc
1623
- drvr._set_host_enabled(False)
1633
+ with mock.patch.object(
1634
+ drvr, '_update_compute_provider_status') as ucps:
1635
+ drvr._set_host_enabled(False)
1636
+ ucps.assert_not_called()
1624
1637
mock_save.assert_not_called()
1625
1638
self.assertTrue(svc.disabled)
1626
1639
@@ -1635,6 +1648,47 @@ def test_set_host_enabled_swallows_exceptions(self):
1635
1648
db_mock.side_effect = exception.NovaException
1636
1649
drvr._set_host_enabled(False)
1637
1650
1651
+ def test_update_compute_provider_status(self):
1652
+ """Tests happy path of calling _update_compute_provider_status"""
1653
+ virtapi = mock.Mock()
1654
+ drvr = libvirt_driver.LibvirtDriver(virtapi, read_only=True)
1655
+ ctxt = context.get_admin_context()
1656
+ service = self._create_service()
1657
+ service.compute_node = objects.ComputeNode(uuid=uuids.rp_uuid)
1658
+ drvr._update_compute_provider_status(ctxt, service)
1659
+ virtapi.update_compute_provider_status.assert_called_once_with(
1660
+ ctxt, uuids.rp_uuid, enabled=not service.disabled)
1661
+
1662
+ def test_update_compute_provider_status_swallows_exceptions(self):
1663
+ """Tests error path handling in _update_compute_provider_status"""
1664
+ # First we'll make Service.compute_node loading raise an exception
1665
+ # by not setting the field and we cannot lazy-load it from an orphaned
1666
+ # Service object.
1667
+ virtapi = mock.Mock()
1668
+ drvr = libvirt_driver.LibvirtDriver(virtapi, read_only=True)
1669
+ ctxt = context.get_admin_context()
1670
+ service = self._create_service(host='fake-host', disabled=True)
1671
+ drvr._update_compute_provider_status(ctxt, service)
1672
+ virtapi.update_compute_provider_status.assert_not_called()
1673
+ self.assertIn('An error occurred while updating compute node resource '
1674
+ 'provider status to "disabled" for provider: fake-host',
1675
+ self.stdlog.logger.output)
1676
+
1677
+ # Now fix Service.compute_node loading but make the VirtAPI call fail.
1678
+ service.compute_node = objects.ComputeNode(uuid=uuids.rp_uuid)
1679
+ service.disabled = False # make sure the log message logic works
1680
+ error = exception.TraitRetrievalFailed(error='oops')
1681
+ virtapi.update_compute_provider_status.side_effect = error
1682
+ drvr._update_compute_provider_status(ctxt, service)
1683
+ virtapi.update_compute_provider_status.assert_called_once_with(
1684
+ ctxt, uuids.rp_uuid, enabled=True)
1685
+ log_output = self.stdlog.logger.output
1686
+ self.assertIn('An error occurred while updating compute node resource '
1687
+ 'provider status to "enabled" for provider: %s' %
1688
+ uuids.rp_uuid, log_output)
1689
+ # The error should have been logged as well.
1690
+ self.assertIn(six.text_type(error), log_output)
1691
+
1638
1692
@mock.patch.object(fakelibvirt.virConnect, "nodeDeviceLookupByName")
1639
1693
def test_prepare_pci_device(self, mock_lookup):
1640
1694
0 commit comments