Create tmd dir with specific prefix in check-uuid unit tests

test_fix_argument_yes for check-uuid tool try to
import the created tmp directory and work on that
which is failing with the below error:
ModuleNotFoundError: No module named 'tmpf61iim1k'

- https://88e1de9a81e55d590d5b-26f184bb59af339cfe698349cbda4177.ssl.cf5.rackcdn.com/770520/8/check/openstack-tox-cover/e3518e8/testr_results.html

It is happening more frequently nowadays: 40 occurrences in 7 days

http://logstash.openstack.org/#/dashboard/file/logstash.json

There is some race happening to delete the created tmp dir
which is then used to import the test file in check-uuid run
and raise error.

This commit try to create the tmp dir with specific prefix so that
any other tests cleanup deleting the *tmp* dir on root path then
it can avoid this failure.

Related-Bug: #1918316
Change-Id: Ibab610d3e59ec22bb8c37d66f262ed1d2648bbf8
This commit is contained in:
Ghanshyam Mann 2021-03-09 12:30:47 -06:00
parent 218c2f258f
commit 238be50423
1 changed files with 9 additions and 10 deletions

View File

@ -13,12 +13,11 @@
import ast
import importlib
import os
import shutil
import sys
import tempfile
from unittest import mock
import fixtures
from tempest.lib.cmd import check_uuid
from tempest.tests import base
@ -40,23 +39,23 @@ class TestCLInterface(base.TestCase):
return tests_file
def test_fix_argument_no(self):
temp_dir = self.useFixture(fixtures.TempDir(rootdir="."))
tests_file = self.create_tests_file(temp_dir.path)
temp_dir = tempfile.mkdtemp(prefix='check-uuid-no', dir=".")
self.addCleanup(shutil.rmtree, temp_dir, ignore_errors=True)
tests_file = self.create_tests_file(temp_dir)
sys.argv = [sys.argv[0]] + ["--package",
os.path.relpath(temp_dir.path)]
os.path.relpath(temp_dir)]
self.assertRaises(SystemExit, check_uuid.run)
with open(tests_file, "r") as f:
self.assertTrue(TestCLInterface.CODE == f.read())
def test_fix_argument_yes(self):
temp_dir = self.useFixture(fixtures.TempDir(rootdir="."))
tests_file = self.create_tests_file(temp_dir.path)
temp_dir = tempfile.mkdtemp(prefix='check-uuid-yes', dir=".")
self.addCleanup(shutil.rmtree, temp_dir, ignore_errors=True)
tests_file = self.create_tests_file(temp_dir)
sys.argv = [sys.argv[0]] + ["--fix", "--package",
os.path.relpath(temp_dir.path)]
os.path.relpath(temp_dir)]
check_uuid.run()
with open(tests_file, "r") as f:
self.assertTrue(TestCLInterface.CODE != f.read())