Return default value for pkg_version if missing
Particularly when writing test code the project as defined by your oslo.config may not exist. In which case we should just use some default value (in this case "unknown") for the version string rather than fail to load. Change-Id: I176fced85468683268e35ce81e63baa17f0e6b84 Closes-Bug: #1494138
This commit is contained in:
parent
adcdd17c02
commit
3d40f1b10e
@ -427,7 +427,10 @@ def _conf_values_type_convert(conf):
|
||||
|
||||
|
||||
def _get_project_version(project):
|
||||
return pkg_resources.get_distribution(project).version
|
||||
try:
|
||||
return pkg_resources.get_distribution(project).version
|
||||
except pkg_resources.DistributionNotFound:
|
||||
return "unknown"
|
||||
|
||||
|
||||
def _uncompress_pkiz(token):
|
||||
|
@ -15,6 +15,7 @@
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
import pkg_resources
|
||||
import shutil
|
||||
import stat
|
||||
import tempfile
|
||||
@ -2474,6 +2475,19 @@ class TestAuthPluginUserAgentGeneration(BaseAuthTokenMiddlewareTest):
|
||||
project_with_version = '{0}/{1} '.format(project, project_version)
|
||||
self._assert_user_agent(app, project_with_version, project_version)
|
||||
|
||||
def test_project_not_installed_results_in_unknown_version(self):
|
||||
project = uuid.uuid4().hex
|
||||
|
||||
conf = {'username': self.username,
|
||||
'auth_url': self.auth_url,
|
||||
'project': project}
|
||||
|
||||
v = pkg_resources.get_distribution('keystonemiddleware').version
|
||||
|
||||
app = self.create_simple_middleware(conf=conf, use_global_conf=True)
|
||||
project_with_version = '{0}/{1} '.format(project, 'unknown')
|
||||
self._assert_user_agent(app, project_with_version, v)
|
||||
|
||||
def test_project_in_oslo_configuration(self):
|
||||
project = uuid.uuid4().hex
|
||||
project_version = uuid.uuid4().hex
|
||||
|
Loading…
x
Reference in New Issue
Block a user