From 5c5adc81e73563288d23b86241149ede019339ad Mon Sep 17 00:00:00 2001 From: Thomas Bechtold Date: Tue, 30 May 2017 17:01:30 +0200 Subject: [PATCH] Do not require network for test_noauth_plugin() While running the unittests, test_noauth_plugin() needs network access and fails in build environments where no network is available: keystoneauth1.exceptions.connection.ConnectFailure: Unable to establish \ connection to http://example.com/v2/admin/volumes/detail: HTTPConnectionPool \ (host='example.com', port=80): Max retries exceeded with url: /v2/admin/ \ volumes/detail (Caused by NewConnectionError(': Failed to establish a \ new connection: [Errno -3] Temporary failure in name resolution',)) Prevent the need of network access to be able to run the unittest in such build envs. Closes-Bug: #1695009 Change-Id: I123919f29de7cb72a780b5f134a5bfaa404f5b53 --- cinderclient/tests/unit/test_shell.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cinderclient/tests/unit/test_shell.py b/cinderclient/tests/unit/test_shell.py index c6557e1ba..728dfd42d 100644 --- a/cinderclient/tests/unit/test_shell.py +++ b/cinderclient/tests/unit/test_shell.py @@ -169,14 +169,17 @@ class ShellTest(utils.TestCase): tenant_name=self.FAKE_ENV['OS_TENANT_NAME'], username=self.FAKE_ENV['OS_USERNAME']) - def test_noauth_plugin(self): + @requests_mock.Mocker() + def test_noauth_plugin(self, mocker): + os_auth_url = "http://example.com/v2" + mocker.register_uri('GET', + "%s/admin/volumes/detail" + % os_auth_url, text='{"volumes": []}') _shell = shell.OpenStackCinderShell() - args = ['--os-endpoint', 'http://example.com/v2', + args = ['--os-endpoint', os_auth_url, '--os-auth-type', 'noauth', '--os-user-id', 'admin', '--os-project-id', 'admin', 'list'] - - # This "fails" but instantiates the client with session - self.assertRaises(exceptions.NotFound, _shell.main, args) + _shell.main(args) self.assertIsInstance(_shell.cs.client.session.auth, noauth.CinderNoAuthPlugin)