From e4264635dcbb7467c64d532c547f4c95370bace9 Mon Sep 17 00:00:00 2001 From: Sundar Nadathur Date: Sun, 18 Nov 2018 21:30:30 -0800 Subject: [PATCH] Devstack enablement for OPAE FPGA driver. This is partial refactor of https://review.openstack.org/#/c/584170 based on review comments. Change-Id: Ia25df018ceae84c613f2f5dea1a6c3d175b4a551 Storyboard: https://storyboard.openstack.org/#!/story/2004250 --- devstack/lib/opae | 61 ++++++++++++++++++++++++++++++++++++++++++++++ devstack/plugin.sh | 21 +++++++++------- devstack/settings | 10 ++++++++ 3 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 devstack/lib/opae diff --git a/devstack/lib/opae b/devstack/lib/opae new file mode 100644 index 00000000..f590dca5 --- /dev/null +++ b/devstack/lib/opae @@ -0,0 +1,61 @@ +#!/bin/bash +# +# lib/opae +# Functions to download, install, or remove OPAE packages + +# Dependencies: +# + +# ensure we don't re-source this in the same environment +[[ -z "$_OPAE_PKG_FNS" ]] || return 0 +declare -r -g _OPAE_PKG_FNS=1 + +function setup_distro_vars { + PKG_EXT="" + if is_fedora; then + PKG_EXT="rpm" + elif is_ubuntu ; then + # NOTE(Sundar): OPAE packages depend on libjson0, which is + # not available after Ubuntu 16.04. After OPAE packages are + # updated, this check can be removed. + [[ $os_RELEASE == "16.04" ]] && PKG_EXT="deb" + fi +} +setup_distro_vars + +function install_opae_pkg { + local pkg=$1 + local url=$2 + local CURL="curl -sSfL --retry 2" + local tmpfile="/tmp/$pkg.$PKG_EXT" + local retval=0 + + # NOTE(Sundar): After OPAE libraries become part of the distro + # repos, we can skip the download with curl. + if ! is_package_installed $pkg; then + $CURL -o $tmpfile $url; retval=$? + if [[ $? -eq 0 ]]; then + install_package $tmpfile; retval=$? + [[ $? -ne 0 ]] && echo "WARNING: Could not install $pkg" + else + echo "WARNING: Could not download $url" + fi + /bin/rm -f $tmpfile + fi + return $retval +} + +function install_opae_packages { + local libs_url="$OPAE_GITHUB/$OPAE_LIBS.$PKG_EXT" + local devel_url="$OPAE_GITHUB/$OPAE_DEVEL.$PKG_EXT" + + [[ "$PKG_EXT" == "" ]] && return 1 + install_opae_pkg "$OPAE_LIBS_PKG" $libs_url && \ + install_opae_pkg "$OPAE_DEVEL_PKG" $devel_url + # return value is the exit code of last command +} + +function uninstall_opae_packages { + uninstall_package "$OPAE_DEVEL_PKG" + uninstall_package "$OPAE_LIBS_PKG" +} diff --git a/devstack/plugin.sh b/devstack/plugin.sh index f29a39be..1e9fff01 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -6,46 +6,49 @@ echo_summary "cyborg devstack plugin.sh called: $1/$2" source $DEST/cyborg/devstack/lib/cyborg +source $DEST/cyborg/devstack/lib/opae if is_service_enabled cyborg-api cyborg-cond; then if [[ "$1" == "stack" ]]; then - if [[ "$2" == "install" ]]; then + if [[ "$2" == "pre-install" ]]; then + # stack/pre-install - Called after (OS) setup is complete and before + # project source is installed + echo_summary "Installing additional Cyborg packages" + if install_opae_packages; then + echo_summary "INFO: Additional Cyborg packages installed" + else + echo "WARNING: Failed to install additional Cyborg packages" + fi + elif [[ "$2" == "install" ]]; then # stack/install - Called after the layer 1 and 2 projects source and # their dependencies have been installed - echo_summary "Installing Cyborg" if ! is_service_enabled nova; then source $RC_DIR/lib/nova_plugins/functions-libvirt install_libvirt fi install_cyborg - elif [[ "$2" == "post-config" ]]; then # stack/post-config - Called after the layer 1 and 2 services have been # configured. All configuration files for enabled services should exist # at this point. - echo_summary "Configuring Cyborg" configure_cyborg create_cyborg_accounts - elif [[ "$2" == "extra" ]]; then # stack/extra - Called near the end after layer 1 and 2 services have # been started. - # Initialize cyborg init_cyborg # Start the cyborg API and cyborg taskmgr components echo_summary "Starting Cyborg" start_cyborg - fi fi if [[ "$1" == "unstack" ]]; then # unstack - Called by unstack.sh before other services are shut down. - stop_cyborg fi @@ -53,6 +56,6 @@ if is_service_enabled cyborg-api cyborg-cond; then # clean - Called by clean.sh before other services are cleaned, but after # unstack.sh has been called. cleanup_cyborg + uninstall_opae_packages fi fi - diff --git a/devstack/settings b/devstack/settings index e9a16e63..df264a4b 100644 --- a/devstack/settings +++ b/devstack/settings @@ -1 +1,11 @@ enable_service cyborg cyborg-api cyborg-cond cyborg-agent + +# OPAE settings +# OPAE packages are not yet upstreamed into OS repos +# We need to download them from OPAE releases page on GitHub +OPAE_VERSION=${OPAE_VERSION:-"1.1.0-2"} +OPAE_GITHUB=${OPAE_GITHUB:-"https://github.com/OPAE/opae-sdk/releases/download/$OPAE_VERSION"} +OPAE_DEVEL_PKG=${OPAE_DEVEL_PKG:-"opae-devel"} +OPAE_DEVEL=${OPAE_DEVEL:-"${OPAE_DEVEL_PKG}-$OPAE_VERSION.x86_64"} +OPAE_LIBS_PKG=${OPAE_LIBS_PKG:-"opae-libs"} +OPAE_LIBS=${OPAE_LIBS:-"${OPAE_LIBS_PKG}-$OPAE_VERSION.x86_64"}