Fixup patch for stable-compute-uuid series

Minor cleanups from feedback on earlier patches.

Related to blueprint stable-compute-uuid

Change-Id: I00505f1df47b46ed36645c781354258e255f0dcc
This commit is contained in:
Dan Smith 2023-01-26 11:46:43 -08:00
parent 23c5f3d585
commit f41ee33e01
5 changed files with 6 additions and 8 deletions

View File

@ -66,7 +66,6 @@ from nova.tests import fixtures as nova_fixtures
from nova.tests.unit import matchers
from nova import utils
from nova.virt import images
from nova.virt import node
CONF = cfg.CONF
@ -302,7 +301,6 @@ class TestCase(base.BaseTestCase):
# Reset our local node uuid cache (and avoid writing to the
# local filesystem when we generate a new one).
node.LOCAL_NODE_UUID = None
self.useFixture(nova_fixtures.ComputeNodeIdFixture())
def _setup_cells(self):

View File

@ -65,6 +65,7 @@ from nova.scheduler import weights
from nova import service
from nova.tests.functional.api import client
from nova import utils
from nova.virt import node
CONF = cfg.CONF
LOG = logging.getLogger(__name__)
@ -1855,6 +1856,7 @@ class ComputeNodeIdFixture(fixtures.Fixture):
def setUp(self):
super().setUp()
node.LOCAL_NODE_UUID = None
self.useFixture(fixtures.MockPatch(
'nova.virt.node.read_local_node_uuid',
lambda: None))

View File

@ -1230,8 +1230,6 @@ class _IntegratedTestBase(test.TestCase, PlacementInstanceHelperMixin):
self.glance = self.useFixture(nova_fixtures.GlanceFixture(self))
self.policy = self.useFixture(nova_fixtures.RealPolicyFixture())
self.useFixture(nova_fixtures.ComputeNodeIdFixture())
self.notifier = self.useFixture(
nova_fixtures.NotificationFixture(self))
@ -1303,8 +1301,6 @@ class ProviderUsageBaseTestCase(test.TestCase, PlacementInstanceHelperMixin):
self.placement = self.useFixture(func_fixtures.PlacementFixture()).api
self.useFixture(nova_fixtures.AllServicesCurrent())
self.useFixture(nova_fixtures.ComputeNodeIdFixture())
self.notifier = self.useFixture(
nova_fixtures.NotificationFixture(self))

View File

@ -72,7 +72,8 @@ class TestNodeIdentity(testtools.TestCase):
def test_generate_local_node_uuid_unexpected_write_fail(self):
with mock.patch('builtins.open') as mock_open:
mock_open.return_value.write.side_effect = IndexError()
mock_write = mock_open.return_value.__enter__.return_value.write
mock_write.side_effect = IndexError()
e = self.assertRaises(exception.InvalidNodeConfiguration,
node.write_local_node_uuid, 'foo')
self.assertIn('Unable to write uuid to %s' % (

View File

@ -35,7 +35,8 @@ def write_local_node_uuid(node_uuid):
# Try to create the identity file and write our uuid into it. Fail
# if the file exists (since it shouldn't if we made it here).
try:
open(fn, 'x').write(node_uuid)
with open(fn, 'x') as f:
f.write(node_uuid)
except FileExistsError:
# If the file exists, we must either fail or re-survey all the
# potential files. If we just read and return it, it could be