From dd16ce95177e656903ee14cfc624e059a6621e98 Mon Sep 17 00:00:00 2001 From: beierlm Date: Thu, 8 Apr 2021 15:09:40 +0200 Subject: [PATCH 1/2] Local Build Procedure Chapter 6: how to build locally, as if you were Jenkins. --- 06-building-locally.md | 293 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 293 insertions(+) create mode 100644 06-building-locally.md diff --git a/06-building-locally.md b/06-building-locally.md new file mode 100644 index 0000000..8807306 --- /dev/null +++ b/06-building-locally.md @@ -0,0 +1,293 @@ +# Building OSM locally, the same as Jenkins + +## Introduction + +This section covers how to perform an end to end build of OSM, including being able +to install it the way Jenkins does. + +### Step 1 - Prepare the environment + +Note: you must have all OSM modules checked out into a single root directory for this +procedure. The following is an example of how to clone all the modules, replacing +`YOURUSERID` with your ETSI OnLine (EOL) account for Gerrit. + +```bash +for MODULE in common devops IM LCM MON NBI NG-UI osmclient PLA POL RO tests ; do + git clone ssh://@osm.etsi.org:29418/osm/${MODULE} +done +``` + +Install an HTTP server and have it listen on a non-standard port, as well as serve +up content from our packages directory + +```bash +sudo snap install qhttp +qhttp -p 4080 & +``` + +A web browser page with open with a simple directory listing page. + +### Step 2 - Build .deb Packages + +When a new patch is proposed, the Stage 2 job creates a series of Debian packages +for each module and uploads them to Artifactory. With a local build, we can bypass +the artifactory step by using a local HTTP server instead. + +We need to create all the Debian packages and collect them in one place. We will +create a packages folder and will later serve that up using an HTTP server. From the +same directory that you isssued the git clone, do the following: + +```bash +rm -rf ~/snap/qhttp/common/* +``` + +This next command will also clean out any .deb packages that may have been +present from older runs, but is not typically necessary to run: + +```bash +find . -name '*.deb' -exec rm -v {} \; +``` + +Run the stage 2 build of the Debian packages using Docker. + +```bash +rm -rf ~/snap/qhttp/common/* +find . -name '*.deb' -exec rm -v {} \; +for MODULE in common devops IM LCM MON N2VC NBI NG-UI osmclient PLA POL RO tests ; do + pushd . + cd ${MODULE} + docker build -t ${MODULE,,}-stage2 . + docker run -ti \ + -v `pwd`:/build \ + -w /build \ + ${MODULE,,}-stage2 \ + bash -c "groupadd -o -g $(id -g) -r $USER ; + useradd -o -u $(id -u) -d /build -r -g $USER $USER ; + runuser $USER -c devops-stages/stage-build.sh" + if [ $? -ne 0 ] ; then + echo $MODULE failed to build + break + fi + find . -name '*.deb' -exec mv -v {} ~/snap/qhttp/common \; + popd +done +``` + +### Step 3 - Build Docker Images + +In this step, we get the URL of the artifacts from the stage 2 style build we just +completed, and then launch a docker build of each container using the URLs as build +arguments. + +Gather the URLs into environment variables. Note that if your host is running +docker on a different network than the default docker0, you will need to update this +script accordingly + +```bash +export BUILD_ARGS="" +export HOSTIP=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+') +for file in ~/snap/qhttp/common/*.deb ; do + file=`basename ${file}` + name=`echo ${file} | cut -d_ -f1 | sed "s/-/_/g"`; + name=${name^^}_URL + export BUILD_ARGS="${BUILD_ARGS}--build-arg ${name}=http://$HOSTIP:4080/$file " + echo Added ${name} as http://$HOSTIP:4080/$file +done +``` + +Build all the docker images. +```bash +pushd . +cd devops/docker +for MODULE in `find . -name Dockerfile -printf '%h\n' | sed 's|\./||' | sort` ; do + pushd . + cd ${MODULE} + MODULE=${MODULE,,} + docker build -t opensourcemano/${MODULE}:devel ${BUILD_ARGS} . + if [ $? -ne 0 ] ; then + echo $MODULE failed to build + break + fi + popd +done +popd +``` + +### Step 4 - Create a Local Registry + +Install Microk8s and enable the local registry in it. +```bash +sudo snap install microk8s +microk8s status --wait-ready +microk8s.enable registry +``` + +Push all the images you just built to your local registry: +```bash +pushd . +cd devops/docker +for MODULE in `find . -name Dockerfile -printf '%h\n' | sed 's|\./||' | sort` ; do + MODULE=${MODULE,,} + docker tag opensourcemano/${MODULE}:devel localhost:32000/opensourcemano/${MODULE}:devel + docker push localhost:32000/opensourcemano/${MODULE}:devel +done +``` + +### Step 5 - Install OSM + +Using Charmed Installer: +```bash +cd devops/installers +./charmed_install.sh --registry localhost:32000 --tag devel +``` + + + +### Step 6 - Run Robot Tests (Optional) + +For this you will need an openstack available, complete with an osm-ext network and +some images pre-loaded. + +Create the robot-systest.cfg file using your openstack credentials. The following +example uses Microstack to get the environment variables. +```bash +# Source your openstack credentials file as needed +. /var/snap/microstack/common/etc/microstack.rc + +rm robot-systest.cfg +for line in `env | grep "^OS_" | sort` ; do echo $line >> robot-systest.cfg ; done +cat << EOF >> robot-systest.cfg +OS_AUTH_URL=$OS_AUTH_URL/v3 +VIM_TARGET=osm +VIM_MGMT_NET=osm-ext +ENVIRONMENTS_FOLDER=environments +PACKAGES_FOLDER=/robot-systest/osm-packages +OS_CLOUD=openstack +LC_ALL=C.UTF-8 +LANG=C.UTF-8 +EOF +``` + +Export some variables for the container to use + +```bash +export OSM_HOSTNAME=$(juju config -m osm nbi site_url | sed "s/http.*\?:\/\///"):443 +export PROMETHEUS_HOSTNAME=$(juju config -m osm prometheus site_url | sed "s/http.*\?:\/\///") +export PROMETHEUS_PORT=80 +export JUJU_PASSWORD=`juju gui 2>&1 | grep password | awk '{print $2}'` +export HOSTIP=$(echo $PROMETHEUS_HOSTNAME | sed "s/prometheus.//" | sed "s/.xip.io//") +``` + +Create a hostfile entry for the container: +```bash +cat << EOF > robot.etc.hosts +127.0.0.1 localhost +${HOSTIP} prometheus.${HOSTIP}.xip.io nbi.${HOSTIP}.xip.io +EOF +``` + +Create a clouds.yaml file for the Robot tests to use: +```bash +cat << EOF > clouds.yaml +clouds: + openstack: + auth: + auth_url: $OS_AUTH_URL/v3 + project_name: $OS_PROJECT_NAME + username: $OS_USERNAME + password: $OS_PASSWORD + user_domain_name: $OS_USER_DOMAIN_NAME + project_domain_name: $OS_PROJECT_DOMAIN_NAME +EOF +``` + +Create the VIM for the robot tests to use: +```bash +osm vim-create --name osm --user "$OS_USERNAME" --password "$OS_PASSWORD" \ + --auth_url "$OS_AUTH_URL/v3" --tenant "$OS_USERNAME" --account_type openstack \ + --config='{use_floating_ip: True, + management_network_name: osm-ext}' +``` + + +```bash +mkdir -p reports +docker run -ti --entrypoint /bin/bash \ + --env OSM_HOSTNAME=${OSM_HOSTNAME} \ + --env PROMETHEUS_HOSTNAME=${PROMETHEUS_HOSTNAME} \ + --env PROMETHEUS_PORT=${PROMETHEUS_PORT} \ + --env JUJU_PASSWORD=${JUJU_PASSWORD} \ + --env HOSTIP=${HOSTIP} \ + --env-file robot-systest.cfg \ + -v `pwd`/robot.etc.hosts:/etc/hosts \ + -v ~/.osm/microk8s-config.yaml:/root/.kube/config \ + -v `pwd`/clouds.yaml:/etc/openstack/clouds.yaml \ + -v `pwd`/reports:/robot-systest/reports \ + opensourcemano/tests:devel +``` + +This should present you with a bash command prompt. You can now create the VIM: + + +Run the sanity suite with the following command: +```bash +./run_test.sh -t sanity +``` + +# Using Microstack + +Here is a script to install microstack with the necessary configuration steps. + +```bash +sudo snap install microstack --devmode --edge +sudo snap set microstack config.network.ports.dashboard=8080 +sudo microstack.init --auto --control + +sudo snap alias microstack.openstack openstack + +for i in $(openstack security group list | awk '/default/{ print $2 }'); do + openstack security group rule create $i --protocol icmp --remote-ip 0.0.0.0/0 + openstack security group rule create $i --protocol tcp --remote-ip 0.0.0.0/0 +done + +openstack network create --enable --no-share osm-ext +openstack subnet create osm-ext-subnet --network osm-ext --dns-nameserver 8.8.8.8 \ + --subnet-range 172.30.0.0/24 +openstack router create external-router +openstack router add subnet external-router osm-ext-subnet +openstack router set --external-gateway external external-router + +wget http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img \ + | openstack image create --public --container-format=bare \ + --disk-format=qcow2 cirros-0.3.5-x86_64-disk.img +wget https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img \ + | openstack image create --public --container-format=bare \ + --disk-format=qcow2 ubuntu16.04 +wget https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img \ + | openstack image create --public --container-format=bare \ + --disk-format=qcow2 ubuntu18.04 +wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img \ + | openstack image create --public --container-format=bare \ + --disk-format=qcow2 ubuntu20.04 + +``` + +# Module Dependencies + +``` + +--------+ +----+ + | common | | IM | + +--------+ +----+ + | |------------------|--------| + |-------| | | ++------+ | | +-----------+ +| N2VC | |--------|--------|--------|--------| | | osmclient | ++------+ | | | | | | +-----------+ + | | | | | | | | + |------| | | | | | | | + | | | | | | | | | ++-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-------+ +| LCM | | MON | | RO | | PLA | | POL | | NBI | | tests | ++-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-------+ +``` + -- GitLab From e793c9e75e0c0037e0396c491cbc5c8f07a84e67 Mon Sep 17 00:00:00 2001 From: beierlm Date: Thu, 8 Apr 2021 20:57:17 +0200 Subject: [PATCH 2/2] Update 06-building-locally.md --- 06-building-locally.md | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/06-building-locally.md b/06-building-locally.md index 8807306..93e8b86 100644 --- a/06-building-locally.md +++ b/06-building-locally.md @@ -113,7 +113,7 @@ done popd ``` -### Step 4 - Create a Local Registry +### Step 4 - Publish to a Local Registry Install Microk8s and enable the local registry in it. ```bash @@ -135,14 +135,18 @@ done ### Step 5 - Install OSM +Using K8s Installer: +```bash +cd devops/installers +./full_install_osm.sh -d localhost:32000 -t devel --nohostclient +``` + Using Charmed Installer: ```bash cd devops/installers ./charmed_install.sh --registry localhost:32000 --tag devel ``` - - ### Step 6 - Run Robot Tests (Optional) For this you will need an openstack available, complete with an osm-ext network and @@ -209,7 +213,6 @@ osm vim-create --name osm --user "$OS_USERNAME" --password "$OS_PASSWORD" \ management_network_name: osm-ext}' ``` - ```bash mkdir -p reports docker run -ti --entrypoint /bin/bash \ @@ -231,12 +234,14 @@ This should present you with a bash command prompt. You can now create the VIM: Run the sanity suite with the following command: ```bash -./run_test.sh -t sanity +./run_test.sh -t daily ``` -# Using Microstack +# Local Openstack via Microstack -Here is a script to install microstack with the necessary configuration steps. +For greater end to end testing, you may want a local Openstack environment for +testing. The following command will install Microstack on your desktop, complete +with the necessary configuration for running Robot tests and Hackfest examples. ```bash sudo snap install microstack --devmode --edge @@ -275,10 +280,10 @@ wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.i # Module Dependencies ``` - +--------+ +----+ - | common | | IM | - +--------+ +----+ - | |------------------|--------| + +--------+ +----+ + | common | | IM | + +--------+ +----+ + | |--------| |-------| | | +------+ | | +-----------+ | N2VC | |--------|--------|--------|--------| | | osmclient | -- GitLab