diff options
author | Cédric Ollivier <cedric.ollivier@orange.com> | 2017-02-08 17:48:47 +0100 |
---|---|---|
committer | Cédric Ollivier <cedric.ollivier@orange.com> | 2017-02-09 21:36:49 +0100 |
commit | eb0151059dcc1efff797eeeb9f0e77e344426ef6 (patch) | |
tree | 4e5e0032ded12c2817bc5ec587f187db9e7e7272 /functest/tests/unit | |
parent | a34f23295ba75694d2837687df3ada5541489a25 (diff) |
Fix source_credentials in openstack_utils
It fixes issues raised when an env var contains '=' (e.g. LS_COLORS).
It now exports the vars listed in rc_file without creating a new
process.
Change-Id: I6e6a4e3ab9c45afe4d40015831acb283acbe564c
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest/tests/unit')
-rw-r--r-- | functest/tests/unit/utils/test_openstack_utils.py | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/functest/tests/unit/utils/test_openstack_utils.py b/functest/tests/unit/utils/test_openstack_utils.py index 0f510414..0971b4e8 100644 --- a/functest/tests/unit/utils/test_openstack_utils.py +++ b/functest/tests/unit/utils/test_openstack_utils.py @@ -7,6 +7,7 @@ import copy import logging +import os import unittest import mock @@ -353,18 +354,31 @@ class OSUtilsTesting(unittest.TestCase): def test_get_credentials_missing_endpoint_type(self): self._get_credentials_missing_env('OS_ENDPOINT_TYPE') + def _test_source_credentials(self, msg, key='OS_TENANT_NAME', + value='admin'): + try: + del os.environ[key] + except: + pass + f = 'rc_file' + with mock.patch('__builtin__.open', mock.mock_open(read_data=msg), + create=True) as m: + m.return_value.__iter__ = lambda self: iter(self.readline, '') + openstack_utils.source_credentials(f) + m.assert_called_once_with(f, 'r') + self.assertEqual(os.environ[key], value) + def test_source_credentials(self): - with mock.patch('functest.utils.openstack_utils.subprocess.Popen') \ - as mock_subproc_popen, \ - mock.patch('functest.utils.openstack_utils.os.environ'): - process_mock = mock.Mock() - attrs = {'communicate.return_value': ('OS_USER_NAME=test_name', - 'success')} - process_mock.configure_mock(**attrs) - mock_subproc_popen.return_value = process_mock - - self.assertDictEqual(openstack_utils.source_credentials('rc_file'), - {'OS_USER_NAME': 'test_name'}) + self._test_source_credentials('OS_TENANT_NAME=admin') + self._test_source_credentials('OS_TENANT_NAME= admin') + self._test_source_credentials('OS_TENANT_NAME = admin') + self._test_source_credentials('OS_TENANT_NAME = "admin"') + self._test_source_credentials('export OS_TENANT_NAME=admin') + self._test_source_credentials('export OS_TENANT_NAME =admin') + self._test_source_credentials('export OS_TENANT_NAME = admin') + self._test_source_credentials('export OS_TENANT_NAME = "admin"') + self._test_source_credentials('OS_TENANT_NAME', value='') + self._test_source_credentials('export OS_TENANT_NAME', value='') @mock.patch('functest.utils.openstack_utils.os.getenv', return_value=None) |