Tests fail if keystone is running on local host

Bug #1423170 reported by Stuart McLaren
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance Client
Fix Released
Medium
Louis Taylor

Bug Description

If keystone is running on the local machine some tests fail, eg:

======================================================================
FAIL: tests.test_shell.ShellTest.test_password_prompted_with_v2
tags: worker-2
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/mnt/ubuntu/git/python-glanceclient/.tox/py27/local/lib/python2.7/site-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "tests/test_shell.py", line 262, in test_password_prompted_with_v2
    glance_shell.main, ['image-list'])
  File "/mnt/ubuntu/git/python-glanceclient/.tox/py27/local/lib/python2.7/site-packages/testtools/testcase.py", line 420, in assertRaises
    self.assertThat(our_callable, matcher)
  File "/mnt/ubuntu/git/python-glanceclient/.tox/py27/local/lib/python2.7/site-packages/testtools/testcase.py", line 431, in assertThat
    mismatch_error = self._matchHelper(matchee, matcher, message, verbose)
  File "/mnt/ubuntu/git/python-glanceclient/.tox/py27/local/lib/python2.7/site-packages/testtools/testcase.py", line 481, in _matchHelper
    mismatch = matcher.match(matchee)
  File "/mnt/ubuntu/git/python-glanceclient/.tox/py27/local/lib/python2.7/site-packages/testtools/matchers/_exception.py", line 108, in match
    mismatch = self.exception_matcher.match(exc_info)
  File "/mnt/ubuntu/git/python-glanceclient/.tox/py27/local/lib/python2.7/site-packages/testtools/matchers/_higherorder.py", line 62, in match
    mismatch = matcher.match(matchee)
  File "/mnt/ubuntu/git/python-glanceclient/.tox/py27/local/lib/python2.7/site-packages/testtools/testcase.py", line 412, in match
    reraise(*matchee)
  File "/mnt/ubuntu/git/python-glanceclient/.tox/py27/local/lib/python2.7/site-packages/testtools/matchers/_exception.py", line 101, in match
    result = matchee()
  File "/mnt/ubuntu/git/python-glanceclient/.tox/py27/local/lib/python2.7/site-packages/testtools/testcase.py", line 965, in __call__
    return self._callable_object(*self._args, **self._kwargs)
  File "glanceclient/shell.py", line 638, in main
    force_auth=False)
  File "glanceclient/shell.py", line 539, in _get_versioned_client
    force_auth=force_auth)
  File "glanceclient/shell.py", line 526, in _get_endpoint_and_token
    token = args.os_auth_token or ks_session.get_token()
  File "/mnt/ubuntu/git/python-glanceclient/.tox/py27/local/lib/python2.7/site-packages/keystoneclient/session.py", line 605, in get_token
    return (self.get_auth_headers(auth) or {}).get('X-Auth-Token')
  File "/mnt/ubuntu/git/python-glanceclient/.tox/py27/local/lib/python2.7/site-packages/keystoneclient/session.py", line 584, in get_auth_headers
    return auth.get_headers(self, **kwargs)
  File "/mnt/ubuntu/git/python-glanceclient/.tox/py27/local/lib/python2.7/site-packages/keystoneclient/auth/base.py", line 113, in get_headers
    token = self.get_token(session)
  File "/mnt/ubuntu/git/python-glanceclient/.tox/py27/local/lib/python2.7/site-packages/keystoneclient/auth/identity/base.py", line 104, in get_token
    return self.get_access(session).auth_token
  File "/mnt/ubuntu/git/python-glanceclient/.tox/py27/local/lib/python2.7/site-packages/keystoneclient/auth/identity/base.py", line 144, in get_access
    self.auth_ref = self.get_auth_ref(session)
  File "/mnt/ubuntu/git/python-glanceclient/.tox/py27/local/lib/python2.7/site-packages/keystoneclient/auth/identity/v2.py", line 78, in get_auth_ref
    authenticated=False, log=False)
  File "/mnt/ubuntu/git/python-glanceclient/.tox/py27/local/lib/python2.7/site-packages/keystoneclient/session.py", line 483, in post
    return self.request(url, 'POST', **kwargs)
  File "/mnt/ubuntu/git/python-glanceclient/.tox/py27/local/lib/python2.7/site-packages/keystoneclient/utils.py", line 318, in inner
    return func(*args, **kwargs)
  File "/mnt/ubuntu/git/python-glanceclient/.tox/py27/local/lib/python2.7/site-packages/keystoneclient/session.py", line 384, in request
    raise exceptions.from_response(resp, method, url)
Unauthorized: Could not find user: username (Disable debug mode to suppress these details.) (HTTP 401)
... terminating glance client
Schema is not a valid JSON object.
Schema is not a valid JSON object.
Ran 332 (+330) tests in 3.565s (+3.472s)
FAILED (id=72, failures=2)
error: testr failed (1)

The tests define a mix of urls for image and keystone (all on port 5000):

DEFAULT_IMAGE_URL = 'http://127.0.0.1:5000/'
DEFAULT_USERNAME = 'username'
DEFAULT_PASSWORD = 'password'
DEFAULT_TENANT_ID = 'tenant_id'
DEFAULT_TENANT_NAME = 'tenant_name'
DEFAULT_PROJECT_ID = '0123456789'
DEFAULT_USER_DOMAIN_NAME = 'user_domain_name'
DEFAULT_UNVERSIONED_AUTH_URL = 'http://127.0.0.1:5000/'
DEFAULT_V2_AUTH_URL = 'http://127.0.0.1:5000/v2.0/'
DEFAULT_V3_AUTH_URL = 'http://127.0.0.1:5000/v3/'
DEFAULT_AUTH_TOKEN = ' 3bcc3d3a03f44e3d8377f9247b0ad155'
TEST_SERVICE_URL = 'http://127.0.0.1:5000/'

and explicitly rely on keystone not running:

    @mock.patch('sys.stdin', side_effect=mock.MagicMock)
    @mock.patch('getpass.getpass', return_value='password')
    def test_password_prompted_with_v2(self, mock_getpass, mock_stdin):
        glance_shell = openstack_shell.OpenStackImagesShell()
        self.make_env(exclude='OS_PASSWORD')
        # We will get a Connection Refused because there is no keystone. <<<<<
        self.assertRaises(ks_exc.ConnectionRefused,
                          glance_shell.main, ['image-list'])
        # Make sure we are actually prompted.
        mock_getpass.assert_called_with('OS Password: ')

Ideally tests should be isolated from the test environment as much as possible.

Louis Taylor (kragniz)
Changed in python-glanceclient:
status: New → Confirmed
importance: Undecided → Critical
importance: Critical → Medium
Revision history for this message
Louis Taylor (kragniz) wrote :

Review, since gerritbot doesn't like me: https://review.openstack.org/#/c/160340/

Changed in python-glanceclient:
status: Confirmed → In Progress
assignee: nobody → Louis Taylor (kragniz)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-glanceclient (master)

Reviewed: https://review.openstack.org/160340
Committed: https://git.openstack.org/cgit/openstack/python-glanceclient/commit/?id=96871b975b0edbabe08e6171f8f24b789656322a
Submitter: Jenkins
Branch: master

commit 96871b975b0edbabe08e6171f8f24b789656322a
Author: Louis Taylor <email address hidden>
Date: Mon Mar 2 13:14:19 2015 +0000

    Fix tests failing if keystone is running locally

    This mocks out the call to python-keystoneclient's Session.get_token(),
    preventing any actual calls being made to a keystone service, running or
    not.

    Change-Id: I24b0874d8e67b46b7c2294d4ac54efa861561dff
    Closes-bug: 1423170

Changed in python-glanceclient:
status: In Progress → Fix Committed
Louis Taylor (kragniz)
Changed in python-glanceclient:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.