| ramonsalguer | 38bd734 | 2020-04-08 19:44:07 +0200 | [diff] [blame^] | 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 | # (OPTIONAL) Devops patch configuration |
| 57 | if [ -f ${BASE_CONFIG_FOLDER}/patchconfig.rc ] |
| 58 | then |
| 59 | cat ${BASE_CONFIG_FOLDER}/patchconfig.rc >> defaultenv.rc |
| 60 | source ${BASE_CONFIG_FOLDER}/patchconfig.rc |
| 61 | fi |
| 62 | |
| 63 | # (OPTIONAL) Local environment provisioning (e.g. cloning of local repos) |
| 64 | if [ -f ${LOCAL_CONFIG_FOLDER}/envprovisioning.sh ] |
| 65 | then |
| 66 | source ${LOCAL_CONFIG_FOLDER}/envprovisioning.sh |
| 67 | fi |
| 68 | |
| 69 | # Local environment configuration: VIM(s), OSM(s), credentials, etc. |
| 70 | if [ -f ${LOCAL_CONFIG_FOLDER}/envconfig.rc ] |
| 71 | then |
| 72 | cat ${LOCAL_CONFIG_FOLDER}/envconfig.rc >> defaultenv.rc |
| 73 | source ${LOCAL_CONFIG_FOLDER}/envconfig.rc |
| 74 | else |
| 75 | >&2 echo ################################################################################ |
| 76 | >&2 echo WARNING: Local configuration file ${BASE_CONFIG_FOLDER}/envconfig.rc is missing. |
| 77 | >&2 echo Please check README.md for details. |
| 78 | >&2 echo If it is an error, once fixed, rebuild your environment. E.g. for Vagrant: |
| 79 | >&2 echo vagrant destroy && vagrant up |
| 80 | >&2 echo Otherwise, you should add manually the appropriate environment variables later. |
| 81 | >&2 echo ################################################################################ |
| 82 | fi |
| 83 | |
| 84 | #------------------------------------------------------------------------------------------------------ |
| 85 | |
| 86 | # Installs OSM client |
| 87 | sudo sed -i "/osm-download.etsi.org/d" /etc/apt/sources.list |
| 88 | wget -qO - https://osm-download.etsi.org/repository/osm/debian/ReleaseSEVEN/OSM%20ETSI%20Release%20Key.gpg | sudo apt-key add - |
| 89 | sudo add-apt-repository -y "deb [arch=amd64] https://osm-download.etsi.org/repository/osm/debian/ReleaseSEVEN stable devops IM osmclient" |
| 90 | sudo apt-get update |
| 91 | sudo apt-get install -y python3-pip |
| 92 | sudo -H python3 -m pip install python-magic pyangbind verboselogs |
| 93 | sudo apt-get install -y python3-osmclient |
| 94 | |
| 95 | # Installs OpenStack client |
| 96 | ##For Train version, uncomment the following two lines: |
| 97 | ##sudo add-apt-repository -y cloud-archive:train |
| 98 | ##sudo apt-get update |
| 99 | sudo apt-get install -y python3-openstackclient # Installs Queens by default |
| 100 | |
| 101 | # Installs Robot and all dependencies required for the tests |
| 102 | |
| 103 | sudo -H python3 -m pip install --ignore-installed haikunator requests pyvcloud progressbar pathlib robotframework robotframework-seleniumlibrary robotframework-requests robotframework-SSHLibrary |
| 104 | curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - |
| 105 | sudo add-apt-repository -y "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" |
| 106 | sudo apt-get install -y google-chrome-stable chromium-chromedriver |
| 107 | ln -s ${ROBOT_DEVOPS_FOLDER} robot |
| 108 | |
| 109 | # Clones Devops repo to retrieve all Robot tests from OSM community |
| 110 | ssh-keyscan -p 29418 osm.etsi.org >> ~/.ssh/known_hosts |
| 111 | if [ -n "${ETSIUSERNAME}" ] # If possible, uses ETSI's user name to make further contributions easier |
| 112 | then |
| 113 | git clone "ssh://${ETSIUSERNAME}@osm.etsi.org:29418/osm/devops" && \ |
| 114 | (cd "devops" && curl https://osm.etsi.org/gerrit/tools/hooks/commit-msg > .git/hooks/commit-msg ; chmod +x .git/hooks/commit-msg) |
| 115 | else |
| 116 | git clone "https://osm.etsi.org/gerrit/osm/devops" |
| 117 | fi |
| 118 | |
| 119 | # if applicable, adds additional patches to devops repo (refer to `patchconfig.rc`) |
| 120 | [ -n "${DEVOPS_PATCH}" ] && git -C devops pull https://osm.etsi.org/gerrit/osm/devops ${DEVOPS_PATCH} |
| 121 | |
| 122 | # Installs some additional packages to ease interactive troubleshooting |
| 123 | sudo apt-get install -y osm-devops |
| 124 | sudo snap install charm --classic |
| 125 | sudo snap install yq |
| 126 | |
| 127 | # Copies VIM credentials in `clouds.yaml` (if applicable) to a proper location |
| 128 | if [ -f ${CLOUDS_PATH}/clouds.yaml ]; then |
| 129 | sudo mkdir -p /etc/openstack |
| 130 | sudo cp ${CLOUDS_PATH}/clouds.yaml /etc/openstack/ |
| 131 | rm ${CLOUDS_PATH}/clouds.yaml |
| 132 | fi |
| 133 | |
| 134 | # Sets default environment to load automatically in `.bashrc` |
| 135 | cat defaultenv.rc >> ~/.bashrc |