diff --git a/openstack_releases/cmds/validate.py b/openstack_releases/cmds/validate.py index 7041cc2d10..b50ca26c5d 100644 --- a/openstack_releases/cmds/validate.py +++ b/openstack_releases/cmds/validate.py @@ -48,6 +48,7 @@ from openstack_releases import puppetutils from openstack_releases import pythonutils from openstack_releases import requirements from openstack_releases import versionutils +from openstack_releases import xstaticutils LOG = logging.getLogger() @@ -944,6 +945,26 @@ def validate_version_numbers(deliv, context): ) ) + # If this is an xstatic package, ensure the package version in code + # matches the tag being requested. + if release_type == 'xstatic': + LOG.debug('performing xstatic version checks') + xs_versions = xstaticutils.get_versions( + context.workdir, project.repo.name) + if not xs_versions: + context.error( + '%s should contain a PACKAGE_VERSION but none found') + for xs_version in xs_versions: + if xs_version != release.version: + context.error( + '%s xstatic.pkg has PACKAGE_VERSION "%s" but is ' + 'being tagged as "%s"' % ( + project.repo.name, + xs_version, + release.version, + ) + ) + # If we know the previous version and the # project is a python deliverable make sure # the requirements haven't changed in a way diff --git a/openstack_releases/xstaticutils.py b/openstack_releases/xstaticutils.py new file mode 100644 index 0000000000..5cc12db05c --- /dev/null +++ b/openstack_releases/xstaticutils.py @@ -0,0 +1,45 @@ +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import importlib +import os +import sys + + +def get_versions(workdir, repo): + """Get the package versions from packages.""" + versions = [] + + # Switch to the workdir + start_path = os.getcwd() + repo_dir = '%s/%s' % (workdir, repo) + os.chdir(repo_dir) + + # Add the repo to the PYTHONPATH so we can import its contents + sys.path.append(repo_dir) + + # Extract PACAKGE_VERSION from any xstatic packages found + try: + for name in os.listdir('xstatic/pkg'): + if '__' in name: + continue + if os.path.isdir('xstatic/pkg/%s' % name): + xs = importlib.import_module('xstatic.pkg.%s' % name) + versions.append(xs.PACKAGE_VERSION) + finally: + # Get back to our original state + sys.path.pop() + os.chdir(start_path) + + return versions