Fix using ODL versions other than oxygen
[apex.git] / apex / builders / overcloud_builder.py
index d6f03eb..eab8fb6 100644 (file)
@@ -15,6 +15,7 @@ import tarfile
 
 import apex.builders.common_builder
 from apex.common import constants as con
+from apex.common import utils as utils
 from apex.common.exceptions import ApexBuildException
 from apex.virtual import utils as virt_utils
 
@@ -24,7 +25,12 @@ def inject_opendaylight(odl_version, image, tmp_dir, uc_ip,
     assert odl_version in con.VALID_ODL_VERSIONS
     # add repo
     if odl_version == 'master':
+        # last version in the constants is "master" so select 2nd to last
+        # odl package version has no "master" version
         odl_pkg_version = con.VALID_ODL_VERSIONS[-2]
+        # branch will be used to pull puppet-opendaylight. Since puppet-odl
+        # does not pull branch until later, we need to use master version of
+        # that if master ODL version is specified
         branch = odl_version
     else:
         odl_pkg_version = odl_version
@@ -64,6 +70,65 @@ def inject_opendaylight(odl_version, image, tmp_dir, uc_ip,
     logging.info("OpenDaylight injected into {}".format(image))
 
 
+def inject_quagga(image, tmp_dir):
+    """
+    Downloads quagga tarball from artifacts.opnfv.org
+    and install it on the overcloud image on the fly.
+    :param image:
+    :param tmp_dir:
+    :return:
+    """
+    utils.fetch_upstream_and_unpack(tmp_dir,
+                                    os.path.split(con.QUAGGA_URL)[0] + "/",
+                                    [os.path.basename(con.QUAGGA_URL)])
+
+    virt_ops = [
+        {con.VIRT_UPLOAD: "{}/quagga-4.tar.gz:/root/".format(tmp_dir)},
+        {con.VIRT_RUN_CMD: "cd /root/ && tar xzf quagga-4.tar.gz"},
+        {con.VIRT_RUN_CMD: "cd /root/quagga;packages=$(ls |grep -vE 'debug"
+         "info|devel|contrib');yum -y install $packages"}
+    ]
+    virt_utils.virt_customize(virt_ops, image)
+    logging.info("Quagga injected into {}".format(image))
+
+
+def inject_ovs_nsh(image, tmp_dir):
+    """
+    Downloads OpenVswitch, compiles it and installs it on the
+    overcloud image on the fly.
+    :param image:
+    :param tmp_dir:
+    :return:
+    """
+    ovs_filename = os.path.basename(con.OVS_URL)
+    ovs_folder = ovs_filename.replace(".tar.gz", "")
+    utils.fetch_upstream_and_unpack(tmp_dir,
+                                    os.path.split(con.OVS_URL)[0] + "/",
+                                    [ovs_filename])
+    (ovs_dist_name, ovs_version) = ovs_folder.split("-")
+
+    virt_ops = [
+        {con.VIRT_UPLOAD: "{}:/root/".format(tmp_dir + "/" + ovs_filename)},
+        {con.VIRT_INSTALL: "rpm-build,autoconf,automake,libtool,openssl,"
+         "openssl-devel,python,python-twisted-core,python-six,groff,graphviz,"
+         "python-zope-interface,desktop-file-utils,procps-ng,PyQt4,"
+         "libcap-ng,libcap-ng-devel,selinux-policy-devel,kernel-devel,"
+         "kernel-headers,kernel-tools,rpmdevtools,systemd-units,python-devel,"
+         "python-sphinx"},
+        {con.VIRT_RUN_CMD: "cd /root/ && tar xzf {}".format(ovs_filename)},
+        {con.VIRT_UPLOAD:
+         "{}/build_ovs_nsh.sh:/root/{}".format(tmp_dir, ovs_folder)},
+        {con.VIRT_RUN_CMD:
+         "cd /root/{0} && chmod -R 777 * && chown -R root:root * && "
+         "./build_ovs_nsh.sh && rpm -Uhv --force rpm/rpmbuild/RPMS/x86_64/{0}"
+         "-1.el7.x86_64.rpm && rpm -Uhv --force rpm/rpmbuild/RPMS/x86_64"
+         "/openvswitch-kmod-{1}-1.el7.x86_64.rpm".format(ovs_folder,
+                                                         ovs_version)}
+    ]
+    virt_utils.virt_customize(virt_ops, image)
+    logging.info("OVS injected into {}".format(image))
+
+
 def build_dockerfile(service, tmp_dir, docker_cmds, src_image_uri):
     """
     Builds docker file per service and stores it in a