Fix environment sanitization for TestServiceUtils
I'm not sure how test_process_options_defaults ever passed for anyone that had all the ST_(AUTH|USER|KEY) set in their environment when they ran it. Despite our efforts to patch os.environ swiftclient.servce was acctually importing environ from os and then sticking the results into some global state. The tests seemed to work fine on infra, but for me locally until I `unset ST_AUTH` the test would always fail. Seems to work now and looks fairly reasonable on the surface. Change-Id: Id68590d6af16040a2877e719bc38d1e126603e42
This commit is contained in:
parent
7709fea51e
commit
eef91b3513
@ -109,41 +109,45 @@ def process_options(options):
|
||||
'region_name': options['os_region_name'],
|
||||
}
|
||||
|
||||
_default_global_options = {
|
||||
"snet": False,
|
||||
"verbose": 1,
|
||||
"debug": False,
|
||||
"info": False,
|
||||
"auth": environ.get('ST_AUTH'),
|
||||
"auth_version": environ.get('ST_AUTH_VERSION', '1.0'),
|
||||
"user": environ.get('ST_USER'),
|
||||
"key": environ.get('ST_KEY'),
|
||||
"retries": 5,
|
||||
"os_username": environ.get('OS_USERNAME'),
|
||||
"os_user_id": environ.get('OS_USER_ID'),
|
||||
"os_user_domain_name": environ.get('OS_USER_DOMAIN_NAME'),
|
||||
"os_user_domain_id": environ.get('OS_USER_DOMAIN_ID'),
|
||||
"os_password": environ.get('OS_PASSWORD'),
|
||||
"os_tenant_id": environ.get('OS_TENANT_ID'),
|
||||
"os_tenant_name": environ.get('OS_TENANT_NAME'),
|
||||
"os_project_name": environ.get('OS_PROJECT_NAME'),
|
||||
"os_project_id": environ.get('OS_PROJECT_ID'),
|
||||
"os_project_domain_name": environ.get('OS_PROJECT_DOMAIN_NAME'),
|
||||
"os_project_domain_id": environ.get('OS_PROJECT_DOMAIN_ID'),
|
||||
"os_auth_url": environ.get('OS_AUTH_URL'),
|
||||
"os_auth_token": environ.get('OS_AUTH_TOKEN'),
|
||||
"os_storage_url": environ.get('OS_STORAGE_URL'),
|
||||
"os_region_name": environ.get('OS_REGION_NAME'),
|
||||
"os_service_type": environ.get('OS_SERVICE_TYPE'),
|
||||
"os_endpoint_type": environ.get('OS_ENDPOINT_TYPE'),
|
||||
"os_cacert": environ.get('OS_CACERT'),
|
||||
"insecure": config_true_value(environ.get('SWIFTCLIENT_INSECURE')),
|
||||
"ssl_compression": False,
|
||||
'segment_threads': 10,
|
||||
'object_dd_threads': 10,
|
||||
'object_uu_threads': 10,
|
||||
'container_threads': 10
|
||||
}
|
||||
|
||||
def _build_default_global_options():
|
||||
return {
|
||||
"snet": False,
|
||||
"verbose": 1,
|
||||
"debug": False,
|
||||
"info": False,
|
||||
"auth": environ.get('ST_AUTH'),
|
||||
"auth_version": environ.get('ST_AUTH_VERSION', '1.0'),
|
||||
"user": environ.get('ST_USER'),
|
||||
"key": environ.get('ST_KEY'),
|
||||
"retries": 5,
|
||||
"os_username": environ.get('OS_USERNAME'),
|
||||
"os_user_id": environ.get('OS_USER_ID'),
|
||||
"os_user_domain_name": environ.get('OS_USER_DOMAIN_NAME'),
|
||||
"os_user_domain_id": environ.get('OS_USER_DOMAIN_ID'),
|
||||
"os_password": environ.get('OS_PASSWORD'),
|
||||
"os_tenant_id": environ.get('OS_TENANT_ID'),
|
||||
"os_tenant_name": environ.get('OS_TENANT_NAME'),
|
||||
"os_project_name": environ.get('OS_PROJECT_NAME'),
|
||||
"os_project_id": environ.get('OS_PROJECT_ID'),
|
||||
"os_project_domain_name": environ.get('OS_PROJECT_DOMAIN_NAME'),
|
||||
"os_project_domain_id": environ.get('OS_PROJECT_DOMAIN_ID'),
|
||||
"os_auth_url": environ.get('OS_AUTH_URL'),
|
||||
"os_auth_token": environ.get('OS_AUTH_TOKEN'),
|
||||
"os_storage_url": environ.get('OS_STORAGE_URL'),
|
||||
"os_region_name": environ.get('OS_REGION_NAME'),
|
||||
"os_service_type": environ.get('OS_SERVICE_TYPE'),
|
||||
"os_endpoint_type": environ.get('OS_ENDPOINT_TYPE'),
|
||||
"os_cacert": environ.get('OS_CACERT'),
|
||||
"insecure": config_true_value(environ.get('SWIFTCLIENT_INSECURE')),
|
||||
"ssl_compression": False,
|
||||
'segment_threads': 10,
|
||||
'object_dd_threads': 10,
|
||||
'object_uu_threads': 10,
|
||||
'container_threads': 10
|
||||
}
|
||||
|
||||
_default_global_options = _build_default_global_options()
|
||||
|
||||
_default_local_options = {
|
||||
'sync_to': None,
|
||||
|
@ -390,11 +390,13 @@ class TestSwiftError(testtools.TestCase):
|
||||
self.assertEqual(str(se), '5 container:con object:obj segment:seg')
|
||||
|
||||
|
||||
@mock.patch.dict(os.environ, clean_os_environ)
|
||||
class TestServiceUtils(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestServiceUtils, self).setUp()
|
||||
with mock.patch.dict(swiftclient.service.environ, clean_os_environ):
|
||||
swiftclient.service._default_global_options = \
|
||||
swiftclient.service._build_default_global_options()
|
||||
self.opts = swiftclient.service._default_global_options.copy()
|
||||
|
||||
def test_process_options_defaults(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user