From b3c610b205f88dddb02cdac39638c52eafaaf82c Mon Sep 17 00:00:00 2001 From: Tim Rozet Date: Tue, 12 Sep 2017 17:32:56 -0400 Subject: Adds ability to deploy from upstream openstack To deploy with upstream openstack branch, use new deploy setting 'os_version'. A default scenario file for nosdn with pike has been included in this patch. If 'os_version' is a version other than the default version for this OPNFV release, then upstream is used. In order to use upstream with the current OS version use '--upstream' argument to the deploy command, to force an upstream deployment. Also include '-e upstream-environment.yaml' to use default upstream deployment settings. Supports nosdn and odl-nofeature deployments. Change-Id: Ic07e308827b449637b4e86cdd086434e4de2fb69 Signed-off-by: Tim Rozet --- apex/builders/__init__.py | 0 apex/builders/common_builder.py | 111 ++++++++++++++++++++++++++++++++++++ apex/builders/overcloud_builder.py | 45 +++++++++++++++ apex/builders/undercloud_builder.py | 38 ++++++++++++ 4 files changed, 194 insertions(+) create mode 100644 apex/builders/__init__.py create mode 100644 apex/builders/common_builder.py create mode 100644 apex/builders/overcloud_builder.py create mode 100644 apex/builders/undercloud_builder.py (limited to 'apex/builders') diff --git a/apex/builders/__init__.py b/apex/builders/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/apex/builders/common_builder.py b/apex/builders/common_builder.py new file mode 100644 index 00000000..101860cd --- /dev/null +++ b/apex/builders/common_builder.py @@ -0,0 +1,111 @@ +############################################################################## +# Copyright (c) 2017 Tim Rozet (trozet@redhat.com) and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +# Common building utilities for undercloud and overcloud + +import git +import logging +import os + +from apex import build_utils +from apex.common import constants as con +from apex.virtual import utils as virt_utils + + +def project_to_path(project): + """ + Translates project to absolute file path + :param project: name of project + :return: File path + """ + if project.startswith('openstack/'): + project = os.path.basename(project) + if 'puppet' in project: + return "/etc/puppet/modules/{}".format(project.replace('puppet-', '')) + elif 'tripleo-heat-templates' in project: + return "/usr/share/openstack-tripleo-heat-templates" + else: + # assume python + return "/usr/lib/python2.7/site-packages/{}".format(project) + + +def add_upstream_patches(patches, image, tmp_dir, + default_branch=os.path.join('stable', + con.DEFAULT_OS_VERSION)): + """ + Adds patches from upstream OpenStack gerrit to Undercloud for deployment + :param patches: list of patches + :param image: undercloud image + :param tmp_dir: to store temporary patch files + :param default_branch: default branch to fetch commit (if not specified + in patch) + :return: None + """ + virt_ops = list() + logging.debug("Evaluating upstream patches:\n{}".format(patches)) + for patch in patches: + assert isinstance(patch, dict) + assert all(i in patch.keys() for i in ['project', 'change-id']) + if 'branch' in patch.keys(): + branch = patch['branch'] + else: + branch = default_branch + patch_diff = build_utils.get_patch(patch['change-id'], + patch['project'], branch) + if patch_diff: + patch_file = "{}.patch".format(patch['change-id']) + patch_file_path = os.path.join(tmp_dir, patch_file) + with open(patch_file_path, 'w') as fh: + fh.write(patch_diff) + project_path = project_to_path(patch['project']) + virt_ops.extend([ + {con.VIRT_UPLOAD: "{}:{}".format(patch_file_path, + project_path)}, + {con.VIRT_RUN_CMD: "cd {} && patch -p1 < {}".format( + project_path, patch_file)}]) + logging.info("Adding patch {} to {}".format(patch_file, + image)) + else: + logging.info("Ignoring patch:\n{}".format(patch)) + if virt_ops: + virt_utils.virt_customize(virt_ops, image) + + +def add_repo(repo_url, repo_name, image, tmp_dir): + assert repo_name is not None + assert repo_url is not None + repo_file = "{}.repo".format(repo_name) + repo_file_path = os.path.join(tmp_dir, repo_file) + content = [ + "[{}]".format(repo_name), + "name={}".format(repo_name), + "baseurl={}".format(repo_url), + "gpgcheck=0" + ] + logging.debug("Creating repo file {}".format(repo_name)) + with open(repo_file_path, 'w') as fh: + fh.writelines("{}\n".format(line) for line in content) + logging.debug("Adding repo {} to {}".format(repo_file, image)) + virt_utils.virt_customize([ + {con.VIRT_UPLOAD: "{}:/etc/yum.repos.d/".format(repo_file_path)}], + image + ) + + +def create_git_archive(repo_url, repo_name, tmp_dir, + branch='master', prefix=''): + repo = git.Repo.clone_from(repo_url, os.path.join(tmp_dir, repo_name)) + repo_git = repo.git + if branch != str(repo.active_branch): + repo_git.checkout("origin/{}".format(branch)) + archive_path = os.path.join(tmp_dir, "{}.tar".format(repo_name)) + with open(archive_path, 'wb') as fh: + repo.archive(fh, prefix=prefix) + logging.debug("Wrote archive file: {}".format(archive_path)) + return archive_path diff --git a/apex/builders/overcloud_builder.py b/apex/builders/overcloud_builder.py new file mode 100644 index 00000000..e7b07963 --- /dev/null +++ b/apex/builders/overcloud_builder.py @@ -0,0 +1,45 @@ +############################################################################## +# Copyright (c) 2017 Tim Rozet (trozet@redhat.com) and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +# Used to modify overcloud qcow2 image + +import logging + +from apex.builders import common_builder as c_builder +from apex.common import constants as con +from apex.virtual import utils as virt_utils + + +def inject_opendaylight(odl_version, image, tmp_dir): + assert odl_version in con.VALID_ODL_VERSIONS + # add repo + if odl_version == 'master': + odl_pkg_version = con.VALID_ODL_VERSIONS[-2] + branch = odl_version + else: + odl_pkg_version = odl_version + branch = "stable/{}".format(odl_version) + odl_url = "https://nexus.opendaylight.org/content/repositories" \ + "/opendaylight-{}-epel-7-x86_64-devel/".format(odl_pkg_version) + repo_name = "opendaylight-{}".format(odl_pkg_version) + c_builder.add_repo(odl_url, repo_name, image, tmp_dir) + # download puppet-opendaylight + archive = c_builder.create_git_archive( + repo_url=con.PUPPET_ODL_URL, repo_name='puppet-opendaylight', + tmp_dir=tmp_dir, branch=branch, prefix='opendaylight/') + # install ODL, puppet-odl + virt_ops = [ + {con.VIRT_INSTALL: 'opendaylight'}, + {con.VIRT_UPLOAD: "{}:/etc/puppet/modules/".format(archive)}, + {con.VIRT_RUN_CMD: 'rm -rf /etc/puppet/modules/opendaylight'}, + {con.VIRT_RUN_CMD: "cd /etc/puppet/modules/ && tar xvf " + "puppet-opendaylight.tar"} + ] + virt_utils.virt_customize(virt_ops, image) + logging.info("OpenDaylight injected into {}".format(image)) diff --git a/apex/builders/undercloud_builder.py b/apex/builders/undercloud_builder.py new file mode 100644 index 00000000..baba8a55 --- /dev/null +++ b/apex/builders/undercloud_builder.py @@ -0,0 +1,38 @@ +############################################################################## +# Copyright (c) 2017 Tim Rozet (trozet@redhat.com) and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +# Used to modify undercloud qcow2 image + +from apex.common import constants as con +from apex.virtual import utils as virt_utils + + +def add_upstream_packages(image): + """ + Adds required base upstream packages to Undercloud for deployment + :param image: + :return: None + """ + virt_ops = list() + pkgs = [ + 'openstack-utils', + 'ceph-common', + 'python2-networking-sfc', + 'openstack-ironic-inspector', + 'subunit-filters', + 'docker-distribution', + 'openstack-tripleo-validations', + 'libguestfs-tools', + ] + + for pkg in pkgs: + virt_ops.append({con.VIRT_INSTALL: pkg}) + virt_utils.virt_customize(virt_ops, image) + +# TODO(trozet): add rest of build for undercloud here as well -- cgit 1.2.3-korg