Skip to content

Commit 3cba09e

Browse files
amotokikiwik
andcommitted
Fix unit test failures related to new os-client-config and osc-lib
[breakage related to os-client-config 1.28.0] os-client-config 1.28.0 add a check if filebased and envvars are both used. This check causes OSC unit test failure. OSC now instantiates OpenStackConfig twice as a workaround. The unit test mocks _load_config_file() and it returns a config dict, but os-client-config OpenStackConfig.__init__ updates the dict returned. As a result, when OpenStackConfig is instantiated second time, the mock of _load_config_file returns a modified version of the config dict. This hits the new check in os-client-config 1.28.0. This commit changes the mock to use side_effect rather than return_value to ensure the original dict is used. [breakage related to osc-lib 1.7.0] The change in osc-lib 1.7.0 added "if" logic to avoid calling get() twice. In tests.unit.volume.test_find_resource, kwargs is empty dict in find_resource(), so the second call to get() is NOT called now. Removing the second elements of side_effect addresses the unit failure. Co-Authored-By: Rui Chen <chenrui.momo@gmail.com> Change-Id: Ib9d14661b2755bbd6619e15c0d9023fbc9d27d70 Closes-Bug: #1703782 Closes-Bug: #1703783
1 parent faf6e16 commit 3cba09e

2 files changed

Lines changed: 16 additions & 18 deletions

File tree

openstackclient/tests/unit/integ/cli/test_shell.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -397,14 +397,14 @@ def test_shell_args_precedence_1(self, config_mock, vendor_mock):
397397
Run 1 has --os-password on CLI
398398
"""
399399

400-
config_mock.return_value = (
401-
'file.yaml',
402-
copy.deepcopy(test_shell.CLOUD_2),
403-
)
404-
vendor_mock.return_value = (
405-
'file.yaml',
406-
copy.deepcopy(test_shell.PUBLIC_1),
407-
)
400+
def config_mock_return():
401+
return ('file.yaml', copy.deepcopy(test_shell.CLOUD_2))
402+
config_mock.side_effect = config_mock_return
403+
404+
def vendor_mock_return():
405+
return ('file.yaml', copy.deepcopy(test_shell.PUBLIC_1))
406+
vendor_mock.side_effect = vendor_mock_return
407+
408408
_shell = shell.OpenStackShell()
409409
_shell.run(
410410
"--os-password qaz configuration show".split(),
@@ -466,14 +466,14 @@ def test_shell_args_precedence_2(self, config_mock, vendor_mock):
466466
Run 2 has --os-username, --os-password, --os-project-domain-id on CLI
467467
"""
468468

469-
config_mock.return_value = (
470-
'file.yaml',
471-
copy.deepcopy(test_shell.CLOUD_2),
472-
)
473-
vendor_mock.return_value = (
474-
'file.yaml',
475-
copy.deepcopy(test_shell.PUBLIC_1),
476-
)
469+
def config_mock_return():
470+
return ('file.yaml', copy.deepcopy(test_shell.CLOUD_2))
471+
config_mock.side_effect = config_mock_return
472+
473+
def vendor_mock_return():
474+
return ('file.yaml', copy.deepcopy(test_shell.PUBLIC_1))
475+
vendor_mock.side_effect = vendor_mock_return
476+
477477
_shell = shell.OpenStackShell()
478478
_shell.run(
479479
"--os-username zarquon --os-password qaz "

openstackclient/tests/unit/volume/test_find_resource.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def setUp(self):
4545
resp = mock.Mock()
4646
body = {"volumes": [{"id": ID, 'display_name': NAME}]}
4747
api.client.get.side_effect = [Exception("Not found"),
48-
Exception("Not found"),
4948
(resp, body)]
5049
self.manager = volumes.VolumeManager(api)
5150

@@ -69,7 +68,6 @@ def setUp(self):
6968
resp = mock.Mock()
7069
body = {"snapshots": [{"id": ID, 'display_name': NAME}]}
7170
api.client.get.side_effect = [Exception("Not found"),
72-
Exception("Not found"),
7371
(resp, body)]
7472
self.manager = volume_snapshots.SnapshotManager(api)
7573

0 commit comments

Comments
 (0)