diff --git a/nova/privsep/utils.py b/nova/privsep/utils.py index 6ba9c4c89773..2b9d9703acdd 100644 --- a/nova/privsep/utils.py +++ b/nova/privsep/utils.py @@ -27,6 +27,7 @@ import os from oslo_log import log as logging from oslo_utils import excutils +from nova import utils as nova_utils LOG = logging.getLogger(__name__) @@ -37,7 +38,9 @@ def supports_direct_io(dirpath): LOG.debug("This python runtime does not support direct I/O") return False - testfile = os.path.join(dirpath, ".directio.test") + file_name = "%s.%s" % (".directio.test", + nova_utils.generate_random_string()) + testfile = os.path.join(dirpath, file_name) hasDirectIO = True fd = None diff --git a/nova/tests/functional/test_servers.py b/nova/tests/functional/test_servers.py index 3f962722673e..d1af06c171c1 100644 --- a/nova/tests/functional/test_servers.py +++ b/nova/tests/functional/test_servers.py @@ -632,6 +632,8 @@ class ServersTest(ServersTestBase): self.assertIn('reservation_id', response) reservation_id = response['reservation_id'] self.assertNotIn(reservation_id, ['', None]) + # Assert that the reservation_id itself has the expected format + self.assertRegex(reservation_id, 'r-[0-9a-zA-Z]{8}') # Create 1 more server, which should not return a reservation_id server = self._build_minimal_create_server_request() diff --git a/nova/tests/unit/privsep/test_utils.py b/nova/tests/unit/privsep/test_utils.py index 6d87a643641c..cdb64331fa31 100644 --- a/nova/tests/unit/privsep/test_utils.py +++ b/nova/tests/unit/privsep/test_utils.py @@ -36,21 +36,25 @@ class SupportDirectIOTestCase(test.NoDBTestCase): self.einval.errno = errno.EINVAL self.enoent = OSError() self.enoent.errno = errno.ENOENT - self.test_path = os.path.join('.', '.directio.test') + self.test_path = os.path.join('.', '.directio.test.abc123') self.io_flags = os.O_CREAT | os.O_WRONLY | os.O_DIRECT open_patcher = mock.patch('os.open') write_patcher = mock.patch('os.write') close_patcher = mock.patch('os.close') unlink_patcher = mock.patch('os.unlink') + random_string_patcher = mock.patch('nova.utils.generate_random_string', + return_value='abc123') self.addCleanup(open_patcher.stop) self.addCleanup(write_patcher.stop) self.addCleanup(close_patcher.stop) self.addCleanup(unlink_patcher.stop) + self.addCleanup(random_string_patcher.stop) self.mock_open = open_patcher.start() self.mock_write = write_patcher.start() self.mock_close = close_patcher.start() self.mock_unlink = unlink_patcher.start() + random_string_patcher.start() def test_supports_direct_io(self): self.mock_open.return_value = 3 diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index f9a1ac31731a..6c1bae617830 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -2435,6 +2435,8 @@ class LibvirtConnTestCase(test.NoDBTestCase, self.assertEqual(0, len(cfg.cputune.vcpupin)) self.assertIsNone(cfg.cpu.numa) + @mock.patch('nova.privsep.utils.supports_direct_io', + new=mock.Mock(return_value=True)) @mock.patch.object( host.Host, "is_cpu_control_policy_capable", return_value=True) def test_get_guest_config_numa_host_instance_no_fit(self, is_able): @@ -2686,6 +2688,8 @@ class LibvirtConnTestCase(test.NoDBTestCase, self.assertEqual(0, len(cfg.cputune.vcpupin)) self.assertIsNone(cfg.cpu.numa) + @mock.patch('nova.privsep.utils.supports_direct_io', + new=mock.Mock(return_value=True)) @mock.patch.object( host.Host, "is_cpu_control_policy_capable", return_value=True) def test_get_guest_config_numa_host_instance_2pci_no_fit(self, is_able): diff --git a/nova/utils.py b/nova/utils.py index a890d3ea67a4..a9d29a4f36ee 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -244,9 +244,13 @@ def ssh_execute(dest, *cmd, **kwargs): def generate_uid(topic, size=8): + random_string = generate_random_string(size) + return '%s-%s' % (topic, random_string) + + +def generate_random_string(size=8): characters = '01234567890abcdefghijklmnopqrstuvwxyz' - choices = [random.choice(characters) for _x in range(size)] - return '%s-%s' % (topic, ''.join(choices)) + return ''.join([random.choice(characters) for _x in range(size)]) # Default symbols to use for passwords. Avoids visually confusing characters.