Initial contribution: Sandbox for Robot tests
[osm/sandboxes.git] / osm-tests / README.md
1 # README: Vagrant sandbox for Robot tests
2
3 Copyright 2020 Telefónica Investigación y Desarrollo S.A.U.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7     http://www.apache.org/licenses/LICENSE-2.0
8 Unless required by applicable law or agreed to in writing, software
9 distributed under the License is distributed on an "AS IS" BASIS,
10 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 See the License for the specific language governing permissions and
12 limitations under the License.
13
14 ## HOW TO USE IT (TL;DR)
15
16 1. Prepare your local environment:
17    1. Upload all required images to your VIM (e.g. `openstack image create ...`).
18       - Hint: you can download first all relevant testing images from OSM by:
19         ```bash
20         cd images
21         ./download_images.sh
22         ```
23    2. Add the corresponding VIM target to your OSM (`osm vim-create ...`).
24    3. Copy all packages (NF, NS, NSI) required for the tests to the `packages/` folder. Hint:
25       ```bash
26       cd packages
27       ./download_packages.sh
28       ```
29 2. Provide credentials for your VIM+OSM environment:
30    - Create/Edit `localconfig/envconfig.rc` (and `localconfig/envprovisioning.sh` if needed).
31      - HINT: First time, use `localconfig/TEMPLATE-envconfig.rc` and (if needed) `localconfig/TEMPLATE-envprovisioning.sh` as templates.
32 3. (OPTIONAL) In case you needed to apply a specific Devops patch-set, define it at `baseconfig/patchconfig.rc`.
33 4. Start the sandbox for its first time provisioning with `vagrant up`.
34 5. Do `vagrant ssh` to enter in the VM.
35 6. Run your first test:
36    ```bash
37    cd robot
38    robot -d /vagrant/results testsuite/hackfest_basic.robot
39    ```
40
41 ## INTRODUCTION
42
43 This Vagrant sandbox provides a simple self-contained environment suitable for running consistently E2E tests with OSM.
44
45 Using this sandbox for local E2E testing has a number of advantages:
46
47 - It enables the end user to run and validate easily in your local environment the set of Robot tests available in ETSI OSM and enables you to contribute back more easily.
48 - It provides a well-known software environment, with all the required dependencies properly pre-validated.
49 - It guarantees that there are no hardcoded dependencies with the local tester environment or with OSM's CI/CD in terms of versions, destinations, paths, credentials, etc. All the test conditions can be completely defined using environment variables if needed.
50 - Its provisioner script (`provisioner.sh`) can be used as-is for provisioning other types of environments, such as a Docker containers.
51 - Likewise, the provisioner script can serve as documentation/validation of different installation processes maintained by OSM (client, Robot, etc.).
52
53 Here is the sandbox what Vagrant creates for you:
54
55 ![Diagram of the functionality of the Sandbox](assets/image-20200406234414818.png)
56
57 As it can be seen, the provisioning of the sandbox installs several pieces of software:
58
59 - OSM Client.
60 - Robot Framework and all library dependencies required to run the full test suite.
61 - Other complementary utilities to perform the tests or ease troubleshooting.
62
63 In addition, the provision of the sandbox requires a number of inputs:
64
65 - The collection of E2E Robot tests for OSM.
66 - Details of OSM instance(s) available for testing, part of the DUT.
67 - Details of VIM(s) available for testing, part of the DUT.
68 - Location of VNF and NS packages required to run the tests.
69 - Location of VM images required to run the tests (future use).
70
71 ## PRE-REQUIREMENTS
72
73 ### Available infrastructure (DUT)
74
75 - There is at least one VIM available and reachable.
76 - There is at least one OSM instance available and reachable.
77 - The OSM instance(s) has (have) at least one target added per VIM.
78
79 ### Software pre-requirements already covered by Vagrant
80
81 - `authorized_keys` at `~/.ssh` with proper permissions.
82 - `id_rsa`, `id_rsa.pub` at `~/.ssh` with proper permissions.
83 - A functional `.gitconfig` file at `~` with proper permissions.
84 - Base configuration files at `${BASE_CONFIG_FOLDER}` (for Vagrant, `~/baseconfig`):
85   - `seedconfig.rc`, where most basic configuration is made.
86   - `patchconfig.rc`, where a Gerrit patch-set for Devops is selected. This file is optional.
87 - Local environment configuration files at `${LOCAL_CONFIG_FOLDER}` (for Vagrant, `~/localconfig`)
88   - `envprovisioning.sh`, where local provisioning tasks are scripted. This file is optional.
89   - `envconfig.rc`, where the DUT (VIM and OSM) are defined with environment variables.
90 - All packages required for the tests are already placed at `${PACKAGES_FOLDER}`.
91   - In Vagrant, `/vagrant/packages`.
92 - All images required for the tests are already placed at `${IMAGES_FOLDER}`.
93   - In Vagrant, `/vagrant/images`.
94   - This folder is intended for future use, but not relevant for the current test suite.
95
96 ### Software pre-requirements to be fulfilled by the user
97
98 Users **should edit** the information about the DUT (local VIM and available OSM) before provisioning the sandbox.
99
100 In the case of Vagrant, the `localconfig` sub-folder of the Vagrant sandbox definition (i.e. at the host) contains the relevant files to be edited:
101
102 1. `envprovisioning.sh` is used as "provisioner" to retrieve some the local environment data, i.e. it is a script intended to retrieve information from some well-known locations, such as local Git repos, that will be referred lated by `envconfig.rc`.
103 2. `envconfig.rc` contains the minimal set of environment variables required to run successfully the suite of Robot tests.
104
105 Once the vagrant sandbox is created, these files will be automatically copied into the VM to `${LOCAL_CONFIG_FOLDER}`) so that they can complete the configuration of the test environment.
106
107 ## Configuration setup
108
109 ### Tester setup and test suite configuration
110
111 Setup of testing conditions, independent from the local environment. This configuration is defined in two configuration files, stored at `${BASE_CONFIG_FOLDER}` (for Vagrant, `~/baseconfig`).
112
113 #### Base configuration: `seedconfig.rc`
114
115 This file contains common base configuration for the test suite, independent of the environment.
116
117 This repo provides a configuration customized for Vagrant sandboxes. If that is your case, please do not edit. However, the existing file can be used as template for creating a `seedconfig.rc` for other types of environments (e.g. Docker).
118
119 Hare is the sample of `seedconfig.rc` for Vagrant with the environment variables commented:
120
121 ```bash
122 # Base folder for all operations
123 export BASE_FOLDER=/home/vagrant
124 # EOL account for SSH operations. Required for password-less operations with Git.
125 # Comment to undefine and it will use HTTP instead
126 export ETSIUSERNAME=$(git config user.name)
127 # Folder where Robot tests are stored
128 export ROBOT_DEVOPS_FOLDER="${HOME}/devops/robot-systest"
129 # Folder to save alternative DUT environments (optional)
130 export ENVIRONMENTS_FOLDER=environments
131 # Folder where all required packages are stored
132 export PACKAGES_FOLDER="/vagrant/packages"
133 # Folder where all required images are stored (intended for future use)
134 #export IMAGES_FOLDER="/vagrant/images"
135 # Folder where test results should be exported
136 export ROBOT_REPORT_FOLDER="/vagrant/results"
137 ```
138
139 #### Devops patch configuration (optional): `patchconfig.rc`
140
141 This file, when exists, defines an optional Gerrit patch-set to be applied over the current Devops master.
142
143 This configuration is optional and mostly intended for OSM developers. Do not use if you plan to run community-approved test suites.
144
145 Here is the sample of `patchconfig.rc` with the environment variable commented:
146
147 ```bash
148 # URL to be used in a subsequent `pull` command to apply the patchset
149 export DEVOPS_PATCH=refs/changes/51/8751/1
150 ```
151
152 ### DUT configuration (local environment)
153
154 Setup of the local environment for the tests. This configuration is defined in configuration files stored at `${LOCAL_CONFIG_FOLDER}` (for Vagrant, `~/localconfig`).
155
156 #### Local environment provisioning (optional): `envprovisioning.sh`
157
158 This file, which is optional, is intended to be used as a script to retrieve information about the local environment, which might include cloning repositories, downloading credential files, etc. Typically, this is used to fetch sensitive information. There are two typical cases:
159
160 - `openstack.rc`
161   - The provisioner, besides fetching it, would append the info to `${LOCAL_CONFIG_FOLDER}/envconfig.rc`.
162 - `clouds.yaml`
163   - The provisioner, besides fetching it, should copy the file to `${BASE_FOLDER}`.
164
165 Here is an example of `envprovisioning.sh` with relevant operations commented:
166
167 ```bash
168 ssh-keyscan mygit.com >> ~/.ssh/known_hosts  # Often needed for non public repos
169 git clone git@mygit.com:local-environment-data/vim-and-infra.git
170 cp vim-and-infra/openstack/clouds.yaml "${BASE_FOLDER}"/ # Copy of credentials to base folder
171 ```
172
173 #### Local environment configuration: `envconfig.rc`
174
175 This file, which is **mandatory**, is where the local DUT is completely defined with environment variables.
176
177 ```bash
178 # VIM setup
179 export OS_USERNAME=username
180 export OS_PASSWORD=password
181 export OS_TENANT_NAME=projectName
182 export OS_AUTH_URL=https://identityHost:portNumber/v2.0
183 export OS_TENANT_ID=tenantIDString
184 export OS_REGION_NAME=regionName
185 export OS_CACERT=/path/to/cacertFile
186 # OSM location
187 export OSM_HOSTNAME="192.168.1.22"
188 # Details of the VIM target for OSM
189 export VIM_TARGET="vim002-fortville-physnet"
190 export VIM_MGMT_NET="management"
191 # Optional: location of alternative `envconfig.rc`-like files
192 export ENVIRONMENTS_FOLDER=environments
193 ```
194
195 Alternatively, here is another example `envconfig.rc` where the VIM is defined with a credentials file, `clouds.yaml`:
196
197 ```bash
198 # VIM setup
199 export CLOUDS_PATH=${BASE_FOLDER} # Location of `clouds.yaml`
200 export OS_CLOUD=vim-002
201 # OSM location
202 export OSM_HOSTNAME="192.168.1.22"
203 # Details of the VIM target for OSM
204 export VIM_TARGET="vim002-fortville-physnet"
205 export VIM_MGMT_NET="management"
206 # Optional: location of alternative `envconfig.rc`-like files
207 export ENVIRONMENTS_FOLDER=environments
208 ```