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('<requests.packages.urllib3. \
  connection.HTTPConnection object at 0x7f04c4394290>: 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
This commit is contained in:
Thomas Bechtold 2017-05-30 17:01:30 +02:00
parent 4f13909239
commit 5c5adc81e7
1 changed files with 8 additions and 5 deletions

View File

@ -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)