summaryrefslogtreecommitdiff
path: root/nova
diff options
context:
space:
mode:
authorDan Smith <dansmith@redhat.com>2023-01-26 11:46:43 -0800
committerDan Smith <dansmith@redhat.com>2023-01-30 12:44:57 -0800
commitf41ee33e0113a569f03941e95f8effc6a784b49a (patch)
tree83211cc8e85d57c86f96a40a1c06aa8a5eb0d824 /nova
parent23c5f3d585ff44b106a27fd54db5e012002611d3 (diff)
downloadnova-f41ee33e0113a569f03941e95f8effc6a784b49a.tar.gz
Fixup patch for stable-compute-uuid series
Minor cleanups from feedback on earlier patches. Related to blueprint stable-compute-uuid Change-Id: I00505f1df47b46ed36645c781354258e255f0dcc
Diffstat (limited to 'nova')
-rw-r--r--nova/test.py2
-rw-r--r--nova/tests/fixtures/nova.py2
-rw-r--r--nova/tests/functional/integrated_helpers.py4
-rw-r--r--nova/tests/unit/virt/test_node.py3
-rw-r--r--nova/virt/node.py3
5 files changed, 6 insertions, 8 deletions
diff --git a/nova/test.py b/nova/test.py
index 4f3554d682..562bd2516e 100644
--- a/nova/test.py
+++ b/nova/test.py
@@ -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):
diff --git a/nova/tests/fixtures/nova.py b/nova/tests/fixtures/nova.py
index 54ef4d2b8d..76dc63755d 100644
--- a/nova/tests/fixtures/nova.py
+++ b/nova/tests/fixtures/nova.py
@@ -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))
diff --git a/nova/tests/functional/integrated_helpers.py b/nova/tests/functional/integrated_helpers.py
index 2dd840259f..ca6fd48e8c 100644
--- a/nova/tests/functional/integrated_helpers.py
+++ b/nova/tests/functional/integrated_helpers.py
@@ -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))
diff --git a/nova/tests/unit/virt/test_node.py b/nova/tests/unit/virt/test_node.py
index cc99268eb4..668b762520 100644
--- a/nova/tests/unit/virt/test_node.py
+++ b/nova/tests/unit/virt/test_node.py
@@ -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' % (
diff --git a/nova/virt/node.py b/nova/virt/node.py
index e567ad28e2..4cb3d0a573 100644
--- a/nova/virt/node.py
+++ b/nova/virt/node.py
@@ -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