Sandbox clones & uses community packages from Git:
[osm/sandboxes.git] / osm-tests / provisioner.sh
1 #!/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
38 BASE_CONFIG_FOLDER=baseconfig
39 LOCAL_CONFIG_FOLDER=localconfig # Default path. It can be reset dinamically by `seedconfig.rc` or `envprovisioning.sh` if needed
40
41 # Base configuration
42 if [ -f ${BASE_CONFIG_FOLDER}/seedconfig.rc ]
43 then
44 cat ${BASE_CONFIG_FOLDER}/seedconfig.rc >> defaultenv.rc
45 source ${BASE_CONFIG_FOLDER}/seedconfig.rc
46 else
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
54 fi
55
56 mkdir -p ${BASE_PACKAGES_FOLDER} # Folder to store collections of packages, based on env varibles
57
58 # (OPTIONAL) Devops patch configuration
59 if [ -f ${BASE_CONFIG_FOLDER}/patchconfig.rc ]
60 then
61 cat ${BASE_CONFIG_FOLDER}/patchconfig.rc >> defaultenv.rc
62 source ${BASE_CONFIG_FOLDER}/patchconfig.rc
63 fi
64
65 # (OPTIONAL) Local environment provisioning (e.g. cloning of local repos)
66 if [ -f ${LOCAL_CONFIG_FOLDER}/envprovisioning.sh ]
67 then
68 source ${LOCAL_CONFIG_FOLDER}/envprovisioning.sh
69 fi
70
71 # Local environment configuration: VIM(s), OSM(s), credentials, etc.
72 if [ -f ${LOCAL_CONFIG_FOLDER}/envconfig.rc ]
73 then
74 cat ${LOCAL_CONFIG_FOLDER}/envconfig.rc >> defaultenv.rc
75 source ${LOCAL_CONFIG_FOLDER}/envconfig.rc
76 else
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 ################################################################################
84 fi
85
86 #------------------------------------------------------------------------------------------------------
87
88 # Installs OSM client
89 if [ -n "${1}" ]; then # If there is a first argument, it must be the version
90 OSM_VERSION=$1
91 fi
92
93 sudo sed -i "/osm-download.etsi.org/d" /etc/apt/sources.list
94 wget -qO - https://osm-download.etsi.org/repository/osm/debian/ReleaseSEVEN/OSM%20ETSI%20Release%20Key.gpg | sudo apt-key add -
95 sudo add-apt-repository -y "deb [arch=amd64] https://osm-download.etsi.org/repository/osm/debian/ReleaseSEVEN stable devops IM osmclient"
96 sudo apt-get update
97 sudo apt-get install -y python3-pip
98 sudo -H python3 -m pip install python-magic pyangbind verboselogs
99 sudo apt-get install -y python3-osmclient
100
101 # Checks if there is is a version indication and if it is for "master"
102 if [[ -n "${OSM_VERSION}" && "${OSM_VERSION}" = "master" ]]
103 then
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
119 fi
120
121 # 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
125 sudo apt-get install -y python3-openstackclient # Installs Queens by default
126
127 # Downloads community test plan
128 ssh-keyscan -p 29419 osm.etsi.org >> ~/.ssh/known_hosts
129 git clone ssh://git@osm.etsi.org:29419/osm-doc/osm-tester-guide.git
130
131 # Downloads community packages and puts them in the location determined by the corresponding env variable for Robot
132 git 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
135 sudo -H python3 -m pip install --ignore-installed haikunator requests pyvcloud progressbar pathlib robotframework robotframework-seleniumlibrary robotframework-requests robotframework-SSHLibrary
136 curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
137 sudo add-apt-repository -y "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main"
138 sudo apt-get install -y google-chrome-stable chromium-chromedriver
139 ln -s ${ROBOT_DEVOPS_FOLDER} robot
140
141 # Clones Devops repo to retrieve all Robot tests from OSM community
142 ssh-keyscan -p 29418 osm.etsi.org >> ~/.ssh/known_hosts
143 if [ -n "${ETSIUSERNAME}" ] # If possible, uses ETSI's user name to make further contributions easier
144 then
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)
147 else
148 git clone "https://osm.etsi.org/gerrit/osm/devops"
149 fi
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
155 sudo apt-get install -y osm-devops
156 sudo snap install charm --classic
157 sudo apt-get install -y jq
158 sudo snap install yq
159
160 # Copies VIM credentials in `clouds.yaml` (if applicable) to a proper location
161 if [ -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
165 fi
166
167 # Sets default environment to load automatically in `.bashrc`
168 cat defaultenv.rc >> ~/.bashrc