Stop leaving temp files after unit test runs
test_shell.CLOUD_2 is using an absolute path for a temp file, so leaves /tmp/test_log_file around after the unit tests are run. Use a fixture instead so it's cleaned automatically, which also removes the possibility of two tests using the same file and interfering with each other. Change-Id: If722b860be4010b91635c6d46f634da980e17152
This commit is contained in:
parent
1bc44fcdc6
commit
4b91cd4965
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
|
import fixtures
|
||||||
import mock
|
import mock
|
||||||
from osc_lib.tests import utils as osc_lib_utils
|
from osc_lib.tests import utils as osc_lib_utils
|
||||||
|
|
||||||
@ -399,6 +400,16 @@ class TestIntegShellCliPrecedenceOCC(test_base.TestInteg):
|
|||||||
test_shell.PUBLIC_1['public-clouds']['megadodo']['auth']['auth_url'] \
|
test_shell.PUBLIC_1['public-clouds']['megadodo']['auth']['auth_url'] \
|
||||||
= test_base.V3_AUTH_URL
|
= test_base.V3_AUTH_URL
|
||||||
|
|
||||||
|
def get_temp_file_path(self, filename):
|
||||||
|
"""Returns an absolute path for a temporary file.
|
||||||
|
|
||||||
|
:param filename: filename
|
||||||
|
:type filename: string
|
||||||
|
:returns: absolute file path string
|
||||||
|
"""
|
||||||
|
temp_dir = self.useFixture(fixtures.TempDir())
|
||||||
|
return temp_dir.join(filename)
|
||||||
|
|
||||||
@mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_vendor_file")
|
@mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_vendor_file")
|
||||||
@mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_config_file")
|
@mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_config_file")
|
||||||
def test_shell_args_precedence_1(self, config_mock, vendor_mock):
|
def test_shell_args_precedence_1(self, config_mock, vendor_mock):
|
||||||
@ -408,7 +419,9 @@ class TestIntegShellCliPrecedenceOCC(test_base.TestInteg):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def config_mock_return():
|
def config_mock_return():
|
||||||
return ('file.yaml', copy.deepcopy(test_shell.CLOUD_2))
|
log_file = self.get_temp_file_path('test_log_file')
|
||||||
|
cloud2 = test_shell.get_cloud(log_file)
|
||||||
|
return ('file.yaml', cloud2)
|
||||||
config_mock.side_effect = config_mock_return
|
config_mock.side_effect = config_mock_return
|
||||||
|
|
||||||
def vendor_mock_return():
|
def vendor_mock_return():
|
||||||
@ -478,7 +491,9 @@ class TestIntegShellCliPrecedenceOCC(test_base.TestInteg):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def config_mock_return():
|
def config_mock_return():
|
||||||
return ('file.yaml', copy.deepcopy(test_shell.CLOUD_2))
|
log_file = self.get_temp_file_path('test_log_file')
|
||||||
|
cloud2 = test_shell.get_cloud(log_file)
|
||||||
|
return ('file.yaml', cloud2)
|
||||||
config_mock.side_effect = config_mock_return
|
config_mock.side_effect = config_mock_return
|
||||||
|
|
||||||
def vendor_mock_return():
|
def vendor_mock_return():
|
||||||
|
@ -70,23 +70,6 @@ CLOUD_1 = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CLOUD_2 = {
|
|
||||||
'clouds': {
|
|
||||||
'megacloud': {
|
|
||||||
'cloud': 'megadodo',
|
|
||||||
'auth': {
|
|
||||||
'project_name': 'heart-o-gold',
|
|
||||||
'username': 'zaphod',
|
|
||||||
},
|
|
||||||
'region_name': 'occ-cloud,krikkit,occ-env',
|
|
||||||
'log_file': '/tmp/test_log_file',
|
|
||||||
'log_level': 'debug',
|
|
||||||
'cert': 'mycert',
|
|
||||||
'key': 'mickey',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PUBLIC_1 = {
|
PUBLIC_1 = {
|
||||||
'public-clouds': {
|
'public-clouds': {
|
||||||
'megadodo': {
|
'megadodo': {
|
||||||
@ -118,6 +101,26 @@ global_options = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_cloud(log_file):
|
||||||
|
CLOUD = {
|
||||||
|
'clouds': {
|
||||||
|
'megacloud': {
|
||||||
|
'cloud': 'megadodo',
|
||||||
|
'auth': {
|
||||||
|
'project_name': 'heart-o-gold',
|
||||||
|
'username': 'zaphod',
|
||||||
|
},
|
||||||
|
'region_name': 'occ-cloud,krikkit,occ-env',
|
||||||
|
'log_file': log_file,
|
||||||
|
'log_level': 'debug',
|
||||||
|
'cert': 'mycert',
|
||||||
|
'key': 'mickey',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CLOUD
|
||||||
|
|
||||||
|
|
||||||
# Wrap the osc_lib make_shell() function to set the shell class since
|
# Wrap the osc_lib make_shell() function to set the shell class since
|
||||||
# osc-lib's TestShell class doesn't allow us to specify it yet.
|
# osc-lib's TestShell class doesn't allow us to specify it yet.
|
||||||
# TODO(dtroyer): remove this once the shell_class_patch patch is released
|
# TODO(dtroyer): remove this once the shell_class_patch patch is released
|
||||||
|
Loading…
x
Reference in New Issue
Block a user