blob: 8167982684c2fd45a5936d08a1dc0ed5dfd0bcfa [file] [log] [blame]
ramonsalguer38bd7342020-04-08 19:44:07 +02001#!/usr/bin/env bash
2
3# Copyright 2020 Telefónica Investigación y Desarrollo S.A.U.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17#######################################################################################################
18# PRE-REQUIREMENTS FOR THE ENVIRONMENT:
19#######################################################################################################
20# - There is at least one VIM available and reachable.
21# - There is at least one OSM instance available and reachable.
22# - The OSM instance(s) has (have) already at least one target added per VIM.
23
24#######################################################################################################
25# SOFTWARE PRE-REQUIREMENTS: (already covered for Vagrant)
26#######################################################################################################
27# - `authorized_keys` at `~/.ssh` with proper permissions
28# - `id_rsa`, `id_rsa.pub` at `~/.ssh` with proper permissions
29# - A functional `.gitconfig` file at `~` with proper permissions
30# - `seedconfig.rc` and `patchconfig.rc` copied to `~/baseconfig`
31# - `envprovisioning.sh` and `envconfig.rc` copied to `~/localconfig`
32
33#######################################################################################################
34# CONFIGURATION SEEDING
35#######################################################################################################
36
37# Folders where configuration is stored
38BASE_CONFIG_FOLDER=baseconfig
39LOCAL_CONFIG_FOLDER=localconfig # Default path. It can be reset dinamically by `seedconfig.rc` or `envprovisioning.sh` if needed
40
41# Base configuration
42if [ -f ${BASE_CONFIG_FOLDER}/seedconfig.rc ]
43then
44 cat ${BASE_CONFIG_FOLDER}/seedconfig.rc >> defaultenv.rc
45 source ${BASE_CONFIG_FOLDER}/seedconfig.rc
46else
47 >&2 echo ################################################################################
48 >&2 echo ERROR: Base configuration file ${BASE_CONFIG_FOLDER}/seedconfig.rc is missing.
49 >&2 echo Please check README.md for details.
50 >&2 echo Once fixed, rebuild your environment. E.g. for Vagrant:
51 >&2 echo vagrant destroy && vagrant up
52 >&2 echo ################################################################################
53 exit 1
54fi
55
ramonsalguer697e4c02020-06-14 23:24:06 +020056mkdir -p ${BASE_PACKAGES_FOLDER} # Folder to store collections of packages, based on env varibles
57
ramonsalguer38bd7342020-04-08 19:44:07 +020058# (OPTIONAL) Devops patch configuration
59if [ -f ${BASE_CONFIG_FOLDER}/patchconfig.rc ]
60then
61 cat ${BASE_CONFIG_FOLDER}/patchconfig.rc >> defaultenv.rc
62 source ${BASE_CONFIG_FOLDER}/patchconfig.rc
63fi
64
65# (OPTIONAL) Local environment provisioning (e.g. cloning of local repos)
66if [ -f ${LOCAL_CONFIG_FOLDER}/envprovisioning.sh ]
67then
68 source ${LOCAL_CONFIG_FOLDER}/envprovisioning.sh
69fi
70
71# Local environment configuration: VIM(s), OSM(s), credentials, etc.
72if [ -f ${LOCAL_CONFIG_FOLDER}/envconfig.rc ]
73then
74 cat ${LOCAL_CONFIG_FOLDER}/envconfig.rc >> defaultenv.rc
75 source ${LOCAL_CONFIG_FOLDER}/envconfig.rc
76else
77 >&2 echo ################################################################################
78 >&2 echo WARNING: Local configuration file ${BASE_CONFIG_FOLDER}/envconfig.rc is missing.
79 >&2 echo Please check README.md for details.
80 >&2 echo If it is an error, once fixed, rebuild your environment. E.g. for Vagrant:
81 >&2 echo vagrant destroy && vagrant up
82 >&2 echo Otherwise, you should add manually the appropriate environment variables later.
83 >&2 echo ################################################################################
84fi
85
86#------------------------------------------------------------------------------------------------------
87
88# Installs OSM client
ramonsalguer697e4c02020-06-14 23:24:06 +020089if [ -n "${1}" ]; then # If there is a first argument, it must be the version
90 OSM_VERSION=$1
91fi
92
ramonsalguer38bd7342020-04-08 19:44:07 +020093sudo sed -i "/osm-download.etsi.org/d" /etc/apt/sources.list
94wget -qO - https://osm-download.etsi.org/repository/osm/debian/ReleaseSEVEN/OSM%20ETSI%20Release%20Key.gpg | sudo apt-key add -
95sudo add-apt-repository -y "deb [arch=amd64] https://osm-download.etsi.org/repository/osm/debian/ReleaseSEVEN stable devops IM osmclient"
96sudo apt-get update
97sudo apt-get install -y python3-pip
98sudo -H python3 -m pip install python-magic pyangbind verboselogs
99sudo apt-get install -y python3-osmclient
100
ramonsalguer697e4c02020-06-14 23:24:06 +0200101# Checks if there is is a version indication and if it is for "master"
102if [[ -n "${OSM_VERSION}" && "${OSM_VERSION}" = "master" ]]
103then
104 sudo apt-get remove -y python3-osmclient
105 sudo apt-get install python3-pip libcurl4-openssl-dev libssl-dev
106
107 # Upgrade pip and install dependencies (python-magic, osm-im)
108 # Next instructions install the dependencies at system level with sudo -H
109 sudo -H python3 -m pip install -U pip
110 sudo -H python3 -m pip install python-magic
111 sudo -H python3 -m pip install git+https://osm.etsi.org/gerrit/osm/IM --upgrade
112
113 # Clone the osmclient repo and install OSM client from the git repo.
114 git clone https://osm.etsi.org/gerrit/osm/osmclient
115 curl -Lo osmclient/.git/hooks/commit-msg http://osm.etsi.org/gerrit/tools/hooks/commit-msg
116 chmod u+x osmclient/.git/hooks/commit-msg
117 # Install osmclient using pip3 with the --user and -e options
118 python3 -m pip install --user -e osmclient
119fi
120
ramonsalguer38bd7342020-04-08 19:44:07 +0200121# Installs OpenStack client
122##For Train version, uncomment the following two lines:
123##sudo add-apt-repository -y cloud-archive:train
124##sudo apt-get update
125sudo apt-get install -y python3-openstackclient # Installs Queens by default
126
ramonsalguer697e4c02020-06-14 23:24:06 +0200127# Downloads community test plan
128ssh-keyscan -p 29419 osm.etsi.org >> ~/.ssh/known_hosts
129git clone ssh://git@osm.etsi.org:29419/osm-doc/osm-tester-guide.git
ramonsalguer38bd7342020-04-08 19:44:07 +0200130
ramonsalguer697e4c02020-06-14 23:24:06 +0200131# Downloads community packages and puts them in the location determined by the corresponding env variable for Robot
132git clone ssh://git@osm.etsi.org:29419/vnf-onboarding/osm-packages.git ${PACKAGES_FOLDER}
133
134# Installs Robot and all dependencies required for the tests
ramonsalguer38bd7342020-04-08 19:44:07 +0200135sudo -H python3 -m pip install --ignore-installed haikunator requests pyvcloud progressbar pathlib robotframework robotframework-seleniumlibrary robotframework-requests robotframework-SSHLibrary
136curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
137sudo add-apt-repository -y "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main"
138sudo apt-get install -y google-chrome-stable chromium-chromedriver
139ln -s ${ROBOT_DEVOPS_FOLDER} robot
140
141# Clones Devops repo to retrieve all Robot tests from OSM community
142ssh-keyscan -p 29418 osm.etsi.org >> ~/.ssh/known_hosts
143if [ -n "${ETSIUSERNAME}" ] # If possible, uses ETSI's user name to make further contributions easier
144then
145 git clone "ssh://${ETSIUSERNAME}@osm.etsi.org:29418/osm/devops" && \
146 (cd "devops" && curl https://osm.etsi.org/gerrit/tools/hooks/commit-msg > .git/hooks/commit-msg ; chmod +x .git/hooks/commit-msg)
147else
148 git clone "https://osm.etsi.org/gerrit/osm/devops"
149fi
150
151# if applicable, adds additional patches to devops repo (refer to `patchconfig.rc`)
152[ -n "${DEVOPS_PATCH}" ] && git -C devops pull https://osm.etsi.org/gerrit/osm/devops ${DEVOPS_PATCH}
153
154# Installs some additional packages to ease interactive troubleshooting
155sudo apt-get install -y osm-devops
156sudo snap install charm --classic
ramonsalguer697e4c02020-06-14 23:24:06 +0200157sudo apt-get install -y jq
ramonsalguer38bd7342020-04-08 19:44:07 +0200158sudo snap install yq
159
160# Copies VIM credentials in `clouds.yaml` (if applicable) to a proper location
161if [ -f ${CLOUDS_PATH}/clouds.yaml ]; then
162 sudo mkdir -p /etc/openstack
163 sudo cp ${CLOUDS_PATH}/clouds.yaml /etc/openstack/
164 rm ${CLOUDS_PATH}/clouds.yaml
165fi
166
167# Sets default environment to load automatically in `.bashrc`
168cat defaultenv.rc >> ~/.bashrc