From 2fdfb38c1379919360d417a34f7e43058c795183 Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Tue, 29 Apr 2025 14:54:23 +0200 Subject: [PATCH] Feature 11071: Modular OSM installation. Move install_to_openstack to separate script Change-Id: Ia49620e2f3f7de6df28ca99540ee5305e88a7d22 Signed-off-by: garciadeblas --- installers/full_install_osm.sh | 136 ++----------------- installers/install_osm.sh | 5 - installers/openstack/install_to_openstack.sh | 92 +++++++++++++ 3 files changed, 105 insertions(+), 128 deletions(-) create mode 100755 installers/openstack/install_to_openstack.sh diff --git a/installers/full_install_osm.sh b/installers/full_install_osm.sh index a35396f4..b465ff45 100755 --- a/installers/full_install_osm.sh +++ b/installers/full_install_osm.sh @@ -38,10 +38,6 @@ function usage(){ echo -e " -P use VCA/juju public key file" echo -e " -A use VCA/juju API proxy" echo -e " -o : ONLY installs the specified component (k8s_monitor, ng-sa, k8scluster, docker, deploy-osm)" - echo -e " -O : install OSM to an OpenStack infrastructure. is required. If a is used, the clouds.yaml file should be under ~/.config/openstack/ or /etc/openstack/" - echo -e " -N : public network name required to setup OSM to OpenStack" - echo -e " -f : public SSH key to use to deploy OSM to OpenStack" - echo -e " -F : cloud-init userdata file to deploy OSM to OpenStack" echo -e " -w : Location to store runtime installation" echo -e " -l: LXD cloud yaml file" echo -e " -L: LXD credentials yaml file" @@ -59,7 +55,6 @@ function usage(){ echo -e " --nohostclient: do not install the osmclient" echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules" echo -e " --k8s_monitor: install the OSM kubernetes monitoring with prometheus and grafana" - echo -e " --volume: create a VM volume when installing to OpenStack" echo -e " --showopts: print chosen options and exit (only for debugging)" echo -e " --charmed: Deploy and operate OSM with Charms on k8s" echo -e " [--bundle ]: Specify with which bundle to deploy OSM with charms (--charmed option)" @@ -575,60 +570,6 @@ function install_osm() { return 0 } -function install_to_openstack() { - [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function - - if [ -z "$2" ]; then - FATAL "OpenStack installer requires a valid external network name" - fi - - # Install Pip for Python3 - sudo apt install -y python3-pip python3-venv - sudo -H LC_ALL=C python3 -m pip install -U pip - - # Create a venv to avoid conflicts with the host installation - python3 -m venv $OPENSTACK_PYTHON_VENV - - source $OPENSTACK_PYTHON_VENV/bin/activate - - # Install Ansible, OpenStack client and SDK, latest openstack version supported is Train - python -m pip install -U wheel - python -m pip install -U "python-openstackclient<=4.0.2" "openstacksdk>=0.12.0,<=0.36.2" "ansible>=2.10,<2.11" - - # Install the Openstack cloud module (ansible>=2.10) - ansible-galaxy collection install openstack.cloud - - export ANSIBLE_CONFIG="$OSM_DEVOPS/installers/openstack/ansible.cfg" - - OSM_INSTALLER_ARGS="${REPO_ARGS[@]}" - - ANSIBLE_VARS="external_network_name=$2 setup_volume=$3 server_name=$OPENSTACK_VM_NAME" - - if [ -n "$OPENSTACK_SSH_KEY_FILE" ]; then - ANSIBLE_VARS+=" key_file=$OPENSTACK_SSH_KEY_FILE" - fi - - if [ -n "$OPENSTACK_USERDATA_FILE" ]; then - ANSIBLE_VARS+=" userdata_file=$OPENSTACK_USERDATA_FILE" - fi - - # Execute the Ansible playbook based on openrc or clouds.yaml - if [ -e "$1" ]; then - . $1 - ansible-playbook -e installer_args="\"$OSM_INSTALLER_ARGS\"" -e "$ANSIBLE_VARS" \ - $OSM_DEVOPS/installers/openstack/site.yml - else - ansible-playbook -e installer_args="\"$OSM_INSTALLER_ARGS\"" -e "$ANSIBLE_VARS" \ - -e cloud_name=$1 $OSM_DEVOPS/installers/openstack/site.yml - fi - - # Exit from venv - deactivate - - [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function - return 0 -} - function arrange_docker_default_network_policy() { echo -e "Fixing firewall so docker and LXD can share the same host without affecting each other." sudo iptables -I DOCKER-USER -j ACCEPT @@ -660,14 +601,6 @@ function dump_vars(){ echo "INSTALL_ONLY_DEPLOY_OSM=$INSTALL_ONLY_DEPLOY_OSM" echo "INSTALL_ONLY_DOCKER_CE=$INSTALL_ONLY_DOCKER_CE" echo "INSTALL_ONLY_K8S_CLUSTER=$INSTALL_ONLY_K8S_CLUSTER" - echo "INSTALL_TO_OPENSTACK=$INSTALL_TO_OPENSTACK" - echo "INSTALL_VIMEMU=$INSTALL_VIMEMU" - echo "OPENSTACK_PUBLIC_NET_NAME=$OPENSTACK_PUBLIC_NET_NAME" - echo "OPENSTACK_OPENRC_FILE_OR_CLOUD=$OPENSTACK_OPENRC_FILE_OR_CLOUD" - echo "OPENSTACK_ATTACH_VOLUME=$OPENSTACK_ATTACH_VOLUME" - echo "OPENSTACK_SSH_KEY_FILE"="$OPENSTACK_SSH_KEY_FILE" - echo "OPENSTACK_USERDATA_FILE"="$OPENSTACK_USERDATA_FILE" - echo "OPENSTACK_VM_NAME"="$OPENSTACK_VM_NAME" echo "OSM_DEVOPS=$OSM_DEVOPS" echo "OSM_DOCKER_TAG=$OSM_DOCKER_TAG" echo "OSM_K8S_EXTERNAL_IP=$OSM_K8S_EXTERNAL_IP" @@ -718,17 +651,8 @@ DEBUG_INSTALL="" RELEASE="testing-daily" REPOSITORY="testing" INSTALL_K8S_MONITOR="" -INSTALL_VIMEMU="" LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd" LXD_REPOSITORY_PATH="" -INSTALL_TO_OPENSTACK="" -OPENSTACK_OPENRC_FILE_OR_CLOUD="" -OPENSTACK_PUBLIC_NET_NAME="" -OPENSTACK_ATTACH_VOLUME="false" -OPENSTACK_SSH_KEY_FILE="" -OPENSTACK_USERDATA_FILE="" -OPENSTACK_VM_NAME="server-osm" -OPENSTACK_PYTHON_VENV="$HOME/.virtual-envs/osm" INSTALL_ONLY="" INSTALL_ONLY_DEPLOY_OSM="" INSTALL_ONLY_DOCKER_CE="" @@ -814,24 +738,6 @@ while getopts ":a:c:e:r:n:k:u:R:D:o:O:N:H:S:s:t:U:P:A:l:L:K:d:p:T:f:F:G:M:-: hy" [ "${OPTARG}" == "k8scluster" ] && INSTALL_ONLY_K8S_CLUSTER="y" && continue [ "${OPTARG}" == "deploy-osm" ] && INSTALL_ONLY_DEPLOY_OSM="y" && continue ;; - O) - INSTALL_TO_OPENSTACK="y" - if [ -n "${OPTARG}" ]; then - OPENSTACK_OPENRC_FILE_OR_CLOUD="${OPTARG}" - else - echo -e "Invalid argument for -O : ' $OPTARG'\n" >&2 - usage && exit 1 - fi - ;; - f) - OPENSTACK_SSH_KEY_FILE="${OPTARG}" - ;; - F) - OPENSTACK_USERDATA_FILE="${OPTARG}" - ;; - N) - OPENSTACK_PUBLIC_NET_NAME="${OPTARG}" - ;; H) OSM_VCA_HOST="${OPTARG}" ;; @@ -909,7 +815,6 @@ while getopts ":a:c:e:r:n:k:u:R:D:o:O:N:H:S:s:t:U:P:A:l:L:K:d:p:T:f:F:G:M:-: hy" [ "${OPTARG}" == "ha" ] && continue [ "${OPTARG}" == "tag" ] && continue [ "${OPTARG}" == "registry" ] && continue - [ "${OPTARG}" == "volume" ] && OPENSTACK_ATTACH_VOLUME="true" && continue [ "${OPTARG}" == "nocachelxdimages" ] && continue [ "${OPTARG}" == "cachelxdimages" ] && INSTALL_CACHELXDIMAGES="--cachelxdimages" && continue echo -e "Invalid option: '--$OPTARG'\n" >&2 @@ -967,32 +872,17 @@ echo $os_release os_info="${os_distro}_${os_release}" os_info="${os_info// /_}" -if [ -n "$CHARMED" ]; then - # Charmed installation - sudo snap install jq || FATAL "Could not install jq (snap package). Make sure that snap works" - ${OSM_DEVOPS}/installers/charmed_install.sh --tag $OSM_DOCKER_TAG "$@" || \ - FATAL_TRACK charmed_install "charmed_install.sh failed" - wget -q -O- https://osm-download.etsi.org/ftp/osm-16.0-sixteen/README2.txt &> /dev/null - echo -e "\nDONE" - exit 0 -elif [ -n "$INSTALL_TO_OPENSTACK" ]; then - # Installation to Openstack - install_to_openstack $OPENSTACK_OPENRC_FILE_OR_CLOUD $OPENSTACK_PUBLIC_NET_NAME $OPENSTACK_ATTACH_VOLUME - echo -e "\nDONE" - exit 0 -else - # Community_installer - # Special cases go first - if [ -n "$INSTALL_ONLY" ]; then - setup_external_ip - [ -n "$INSTALL_ONLY_DOCKER_CE" ] && install_docker_ce - [ -n "$INSTALL_ONLY_K8S_CLUSTER" ] && install_k8s_cluster - [ -n "$INSTALL_K8S_MONITOR" ] && install_k8s_monitoring - [ -n "$INSTALL_ONLY_DEPLOY_OSM" ] && deploy_osm - echo -e "\nDONE" && exit 0 - fi - # This is where installation starts - install_osm - echo -e "\nDONE" - exit 0 +# Community_installer +# Special cases go first +if [ -n "$INSTALL_ONLY" ]; then + setup_external_ip + [ -n "$INSTALL_ONLY_DOCKER_CE" ] && install_docker_ce + [ -n "$INSTALL_ONLY_K8S_CLUSTER" ] && install_k8s_cluster + [ -n "$INSTALL_K8S_MONITOR" ] && install_k8s_monitoring + [ -n "$INSTALL_ONLY_DEPLOY_OSM" ] && deploy_osm + echo -e "\nDONE" && exit 0 fi +# This is where installation starts +install_osm +echo -e "\nDONE" +exit 0 diff --git a/installers/install_osm.sh b/installers/install_osm.sh index fa200f09..efc3f612 100755 --- a/installers/install_osm.sh +++ b/installers/install_osm.sh @@ -42,10 +42,6 @@ function usage(){ echo -e " -P use VCA/juju public key file" echo -e " -A use VCA/juju API proxy" echo -e " -o : ONLY installs the specified component (k8s_monitor, ng-sa, k8scluster, docker, deploy-osm)" - echo -e " -O : install OSM to an OpenStack infrastructure. is required. If a is used, the clouds.yaml file should be under ~/.config/openstack/ or /etc/openstack/" - echo -e " -N : public network name required to setup OSM to OpenStack" - echo -e " -f : public SSH key to use to deploy OSM to OpenStack" - echo -e " -F : cloud-init userdata file to deploy OSM to OpenStack" echo -e " -w : Location to store runtime installation" echo -e " -l: LXD cloud yaml file" echo -e " -L: LXD credentials yaml file" @@ -63,7 +59,6 @@ function usage(){ echo -e " --nohostclient: do not install the osmclient" echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules" echo -e " --k8s_monitor: install the OSM kubernetes monitoring with prometheus and grafana" - echo -e " --volume: create a VM volume when installing to OpenStack" echo -e " --showopts: print chosen options and exit (only for debugging)" echo -e " --charmed: Deploy and operate OSM with Charms on k8s" echo -e " [--bundle ]: Specify with which bundle to deploy OSM with charms (--charmed option)" diff --git a/installers/openstack/install_to_openstack.sh b/installers/openstack/install_to_openstack.sh new file mode 100755 index 00000000..30ad10d6 --- /dev/null +++ b/installers/openstack/install_to_openstack.sh @@ -0,0 +1,92 @@ +#!/bin/bash +# +# 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. +# + +set -x + +DEBUG_INSTALL=${DEBUG_INSTALL:-} +OSM_DEVOPS=${OSM_DEVOPS:-"/usr/share/osm-devops"} +OPENSTACK_OPENRC_FILE_OR_CLOUD=${OPENSTACK_OPENRC_FILE_OR_CLOUD:-""} +OPENSTACK_PUBLIC_NET_NAME=${OPENSTACK_PUBLIC_NET_NAME:-""} +OPENSTACK_ATTACH_VOLUME=${OPENSTACK_ATTACH_VOLUME:-"false"} +OPENSTACK_SSH_KEY_FILE=${OPENSTACK_SSH_KEY_FILE:-""} +OPENSTACK_USERDATA_FILE=${OPENSTACK_USERDATA_FILE:-""} +OPENSTACK_VM_NAME=${OPENSTACK_VM_NAME:-"server-osm"} +OPENSTACK_PYTHON_VENV=${OPENSTACK_PYTHON_VENV:-"$HOME/.virtual-envs/osm"} +echo "DEBUG_INSTALL=$DEBUG_INSTALL" +echo "OSM_DEVOPS=$OSM_DEVOPS" +echo "OPENSTACK_OPENRC_FILE_OR_CLOUD=$OPENSTACK_OPENRC_FILE_OR_CLOUD" +echo "OPENSTACK_PUBLIC_NET_NAME=$OPENSTACK_PUBLIC_NET_NAME" +echo "OPENSTACK_ATTACH_VOLUME=$OPENSTACK_ATTACH_VOLUME" +echo "OPENSTACK_SSH_KEY_FILE"="$OPENSTACK_SSH_KEY_FILE" +echo "OPENSTACK_USERDATA_FILE"="$OPENSTACK_USERDATA_FILE" +echo "OPENSTACK_VM_NAME"="$OPENSTACK_VM_NAME" +echo "OPENSTACK_PYTHON_VENV"="$OPENSTACK_PYTHON_VENV" + +source $OSM_DEVOPS/common/logging +source $OSM_DEVOPS/common/track + +install_to_openstack $OPENSTACK_OPENRC_FILE_OR_CLOUD $OPENSTACK_PUBLIC_NET_NAME $OPENSTACK_ATTACH_VOLUME + +[ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function + +if [ -z "${OPENSTACK_PUBLIC_NET_NAME}" ]; then + FATAL "OpenStack installer requires a valid external network name" +fi + +# Install Pip for Python3 +sudo apt install -y python3-pip python3-venv +sudo -H LC_ALL=C python3 -m pip install -U pip + +# Create a venv to avoid conflicts with the host installation +python3 -m venv $OPENSTACK_PYTHON_VENV + +source $OPENSTACK_PYTHON_VENV/bin/activate + +# Install Ansible, OpenStack client and SDK, latest openstack version supported is Train +python -m pip install -U wheel +python -m pip install -U "python-openstackclient<=4.0.2" "openstacksdk>=0.12.0,<=0.36.2" "ansible>=2.10,<2.11" + +# Install the Openstack cloud module (ansible>=2.10) +ansible-galaxy collection install openstack.cloud + +export ANSIBLE_CONFIG="$OSM_DEVOPS/installers/openstack/ansible.cfg" + +OSM_INSTALLER_ARGS="${REPO_ARGS[@]}" + +ANSIBLE_VARS="external_network_name=$OPENSTACK_PUBLIC_NET_NAME setup_volume=$OPENSTACK_ATTACH_VOLUME server_name=$OPENSTACK_VM_NAME" + +if [ -n "$OPENSTACK_SSH_KEY_FILE" ]; then + ANSIBLE_VARS+=" key_file=$OPENSTACK_SSH_KEY_FILE" +fi + +if [ -n "$OPENSTACK_USERDATA_FILE" ]; then + ANSIBLE_VARS+=" userdata_file=$OPENSTACK_USERDATA_FILE" +fi + +# Execute the Ansible playbook based on openrc or clouds.yaml +if [ -e "$OPENSTACK_OPENRC_FILE_OR_CLOUD" ]; then + . $OPENSTACK_OPENRC_FILE_OR_CLOUD + ansible-playbook -e installer_args="\"$OSM_INSTALLER_ARGS\"" -e "$ANSIBLE_VARS" \ + $OSM_DEVOPS/installers/openstack/site.yml +else + ansible-playbook -e installer_args="\"$OSM_INSTALLER_ARGS\"" -e "$ANSIBLE_VARS" \ + -e cloud_name=$OPENSTACK_OPENRC_FILE_OR_CLOUD $OSM_DEVOPS/installers/openstack/site.yml +fi + +# Exit from venv +deactivate + +[ -z "${DEBUG_INSTALL}" ] || DEBUG end of function +exit 0 -- 2.25.1