Raise ClientException for invalid auth version.

- Fixes LP Bug #1008667.
- Fix a pep8 error along the way to pass jenkins.
- Update openstack.swift.common to get jenkins passing for 1.2 pep8
  error.

Change-Id: I4ce86a94e1c799807a2ad8e7e1c502b1eb8a51c7
This commit is contained in:
Dan Prince 2012-06-06 18:38:08 +02:00 committed by Chmouel Boudjnah
parent 7bbb5c72ca
commit b13823ef18
3 changed files with 31 additions and 5 deletions

View File

@ -245,7 +245,7 @@ def _get_auth_v2_0(url, user, tenant_name, key, snet):
url = service['endpoints'][0]['publicURL']
token_id = body['access']['token']['id']
if not url:
raise ClientException("There is no object-store endpoint " \
raise ClientException("There is no object-store endpoint "
"on this auth server.")
except(KeyError, IndexError):
raise ClientException("Error while getting answers from auth server")
@ -285,6 +285,9 @@ def get_auth(url, user, key, snet=False, tenant_name=None, auth_version="1.0"):
if not tenant_name:
raise ClientException('No tenant specified')
return _get_auth_v2_0(url, user, tenant_name, key, snet)
else:
raise ClientException('Unknown auth_version %s specified.' %
auth_version)
def get_account(url, token, marker=None, limit=None, prefix=None,

View File

@ -33,8 +33,8 @@ def parse_mailmap(mailmap='.mailmap'):
for l in fp:
l = l.strip()
if not l.startswith('#') and ' ' in l:
canonical_email, alias = [x for x in l.split(' ') \
if x.startswith('<')]
canonical_email, alias = [x for x in l.split(' ')
if x.startswith('<')]
mapping[alias] = canonical_email
return mapping
@ -61,9 +61,19 @@ def parse_requirements(requirements_files=['requirements.txt',
'tools/pip-requires']):
requirements = []
for line in get_reqs_from_files(requirements_files):
# For the requirements list, we need to inject only the portion
# after egg= so that distutils knows the package it's looking for
# such as:
# -e git://github.com/openstack/nova/master#egg=nova
if re.match(r'\s*-e\s+', line):
requirements.append(re.sub(r'\s*-e\s+.*#egg=(.*)$', r'\1',
line))
# such as:
# http://github.com/openstack/nova/zipball/master#egg=nova
elif re.match(r'\s*https?:', line):
requirements.append(re.sub(r'\s*https?:.*#egg=(.*)$', r'\1',
line))
# -f lines are for index locations, and don't get used here
elif re.match(r'\s*-f\s+', line):
pass
else:
@ -75,11 +85,18 @@ def parse_requirements(requirements_files=['requirements.txt',
def parse_dependency_links(requirements_files=['requirements.txt',
'tools/pip-requires']):
dependency_links = []
# dependency_links inject alternate locations to find packages listed
# in requirements
for line in get_reqs_from_files(requirements_files):
# skip comments and blank lines
if re.match(r'(\s*#)|(\s*$)', line):
continue
# lines with -e or -f need the whole line, minus the flag
if re.match(r'\s*-[ef]\s+', line):
dependency_links.append(re.sub(r'\s*-[ef]\s+', '', line))
# lines that are only urls can go in unmolested
elif re.match(r'\s*https?:', line):
dependency_links.append(line)
return dependency_links
@ -137,8 +154,8 @@ def generate_authors():
new_authors = 'AUTHORS'
if os.path.isdir('.git'):
# don't include jenkins email address in AUTHORS file
git_log_cmd = "git log --format='%aN <%aE>' | sort -u | " \
"grep -v " + jenkins_email
git_log_cmd = ("git log --format='%aN <%aE>' | sort -u | "
"grep -v " + jenkins_email)
changelog = _run_shell_command(git_log_cmd)
mailmap = parse_mailmap()
with open(new_authors, 'w') as new_authors_fh:

View File

@ -161,6 +161,12 @@ class TestGetAuth(MockHttpTest):
self.assertEquals(url, None)
self.assertEquals(token, None)
def test_invalid_auth(self):
c.http_connection = self.fake_http_connection(200)
self.assertRaises(c.ClientException, c.get_auth,
'http://www.tests.com', 'asdf', 'asdf',
auth_version="foo")
def test_auth_v1(self):
c.http_connection = self.fake_http_connection(200)
url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',