fix(docs): File placements
[csit.git] / docs / toi / vagrant.md
1 # FD.io CSIT Development Environment
2
3 The intent of this document is to give you a quick start guide for setting up a CSIT development and testing environment inside a Vagrant VM.
4
5 ## Pulling CSIT code
6
7 The first step is to pull the FD.io CSIT code. Eventhough the fastest way is to pull the code anonymously using https by typing the below command, the recommended way is to pull code via ssh if you intend to develop and commit changes upstream.
8 ```
9 git clone https://gerrit.fd.io/r/csit
10 ```
11 To pull the code via ssh, you'll first need to setup a Linux Foundation (LF) account as fd.io uses the Linux Foundations identity system. If you do not have an LF account, proceed to [Linux_Foundations_Identity_Setup](https://identity.linuxfoundation.org) to setup one. Once you have setup your Linux Foundation username and password, you can use if for all fd.io logins.
12
13 After you've setup your account, make sure you have registered your [ssh key with
14 gerrit](https://wiki.fd.io/view/DEV/Setting_up_Gerrit). Then pull the code by typing the below command. Replace USERNAME with your Linux Foundation username.
15
16 ```
17 git clone ssh://USERNAME@gerrit.fd.io:29418/csit.git
18 ```
19
20 ## Standing up Linux VM
21
22 To setup your dev environment, you'll want to stand up a Linux VM. The CSIT repo provides a
23 Vagrantfile to help you quickly setup an Ubuntu Jammy VM. This file is located in the csit.infra.vagrant folder.
24
25 If you haven't already installed Vagrant, install it by following the instructions [here](https://developer.hashicorp.com/vagrant/docs/installation).
26
27 Vagrant works well with the VirtualBox provider. We have only tested Vagrant with the VirtualBox provider for setting up a CSIT dev/test environment. Install the VirtualBox hypervisor on your
28 host machine by following the instructions for [Installing VirtualBox](https://www.virtualbox.org/wiki/Downloads).
29
30 If you've more than one hypervisor in use on the host machine, you'll most likely encounter an error when bringing up the VM. You must ensure that other hyperviors such as Hyper-V or KVM are disabled.
31
32 ### Ensure KVM and Hyper-V are disabled on the host
33
34 If you have a Linux machine, ensure KVM is disabled:
35 ```
36 lsmod | grep kvm
37 ```
38 If you see kvm or kvm_intel in the output, you'll need to use the blacklist command to add it to the deny list.
39 ```
40 echo 'blacklist kvm-intel' | sudo tee -a /etc/modprobe.d/blacklist.conf
41 ```
42
43 If you have a Windows machine, ensure Hyper-V is disabled in system settings.
44
45  - Right click on the Windows button and select 'Apps and Features'.
46  - Select Turn Windows Features on or off.
47  - Unselect Hyper-V and click OK.
48
49  Reboot your host machine for the changes to take effect.
50
51 ### Starting the Vagrant VM
52
53 The CSIT Vagrantfile: csit/csit.infra.vagrant/Vagrantfile is used to start up the Ubuntu
54 jammy VM with 8GB of RAM and 4 VCPUs. Vagrant boots up the VM and provisions software in it
55 using ansible local. Ansible installation is not required on the host.
56
57 The inventory path for ansible provisioning on the vagrant VM is located at:
58 csit/fdio.infra.ansible/inventories/vagrant_inventory/hosts.
59
60 The ansible playbook used for the vagrant host is located at:
61 /home/vagrant/csit/fdio.infra.ansible/vagrant.yaml
62
63 If your host OS is Linux, you may have to increase the maximum map count to a high value to
64 ensure that the Linux Kernel allows the VirtualBox hypervisor to allocate the required memory
65 maps. You can do this by typing the below command:
66 ```
67 sudo sysctl -w vm.max_map_count=262144
68 ```
69
70 If you're using a proxy, you'll need to export your proxy settings to facilitate software provisioning within the Vagrant VM.
71 ```
72 export VAGRANT_APT_HTTP_PROXY=http://{Your_Proxy_URL}:{Proxy_Port}
73 export VAGRANT_APT_HTTPS_PROXY=http://{Your_Proxy_URL}:{Proxy_Port}
74 export VAGRANT_HTTPS_PROXY=http://{Your_Proxy_URL}:{Proxy_Port}
75 export VAGRANT_HTTP_PROXY=http://{Your_Proxy_URL}:{Proxy_Port}
76 ```
77
78 Ansible downloads stable VPP packages from Packagecloud. The VPP version used for testing
79 can be set by updating the file: csit/VPP_STABLE_VER_UBUNTU_JAMMY.
80
81 To bring up the Ubuntu jammy VM with virtualbox provider and provision software, type the command
82 ```
83 vagrant up
84 ```
85
86 If everything goes well, vagrant will boot up the VM, mount shared folders and provision all the required software for running CSIT tests. The csit repository on the host will be mounted at /home/vagrant/csit on the VM.
87
88 ### Running Device Tests
89
90 After your VM is provisioned, start by running VPP device tests. To do this type the
91 following commands:
92 ```
93 vagrant ssh   # login to the VM
94 cd /home/vagrant/csit/resources/libraries/bash/entry
95 ./bootstrap_vpp_device.sh csit-vpp-device-master-ubuntu2004-1n-vbox
96 ```
97
98 The script will pack and copy the test framework into the docker containers named csit-tg-* and csit-dut1-* via ssh. The copied tarball will be extracted in the docker container.
99 Once the nodes are ready, you'll see device tests being executed in the docker container and the test results.
100
101 ### Your questions answered
102
103 1) Where are the tests located and how are they written?
104
105     CSIT tests are written using an open source automation framework called the [Robot Framework](https://robotframework.org/). The tests are present in the /tests folder. Infact these tests are used as templates to generate new robot tests for testing various interface types. The new interface tests are generated at runtime and stored in the /generated/tests folder. For VM based testing of interfaces, you should see robot tests generated for 1GE interfaces in this folder.
106
107 2) I am getting a robot error, [ ERROR ] Suite 'Tests' contains no tests matching tag '2 node single link topo', not matching tags 'avf', 'vhost', 'flow', 'NIC "HW 4xxx"', 'NIC "HW C4xxx"', 'NIC Amazon-Nitro-100G', 'NIC Amazon-Nitro-200G', 'NIC Amazon-Nitro-50G', 'NIC Intel-DSA', 'NIC Intel-E810CQ', 'NIC Intel-E810XXV', 'NIC Intel-E822CQ', 'NIC Intel-X520-DA2', 'NIC Intel-X553', 'NIC Intel-X710', 'NIC Intel-XL710', 'NIC Intel-XXV710', 'NIC Mellanox-CX556A', 'NIC Mellanox-CX6DX', 'NIC Mellanox-CX7VEAT' or 'NIC azure-mlx-40g' and matching name 'devicetest' in suite 'tests.vpp.device'. How do I resolve this?
108
109     This error means that the robot framework is missing the virtual interface specification in its configuration. To resolve this issue, update the file: resources/library/python/Constants.py by adding a mapping for the nic named virtual. For instance, create two mappings such as:
110     ```
111     "virtual": "1ge1p82540em"
112     "virtual": ["vfio-pci"]
113     ```
114     Add the appropriate mapping into,
115      -  NIC_NAME_TO_CODE
116      -  NIC_CODE_TO_SHORT_NAME
117      -  NIC_NAME_TO_DRIVER
118      -  NIC_DRIVER_TO_PLUGINS
119      -  NIC_DRIVER_TO_TAG
120      -  NIC_DRIVER_TO_SUITE_PREFIX
121      -  NIC_DRIVER_TO_VFS
122      -  DPDK_NIC_NAME_TO_DRIVER
123
124     After this, delete the /generated/tests folder. We are using job_spec files for test definition. See /resources/job_specs/vpp_device. If a job spec is missing for vbox, create a new job spec by just copying and pasting the existing vpp-1n-spr.md to vpp-1n-vbox.md. However, change the NIC to virtual!
125
126     Next, in the file: resources/libraries/bash/function/common.sh add the below line to create a substitution for the virtual NIC,
127     ```
128     awk_nics_sub_cmd+='gsub("virtual","1ge1p82540em");'
129     ```
130     Also, keep the “virtual” in vpp-1n-vbox.md (column 4).
131     Now re-run the tests and in robot command line (log) you should start seeing --test <name> --test <name> etc.
132
133 3) Where can I find test run logs?
134
135     Test run logs are present in the /archives folder. You should find a file named log.hml in this folder.
136
137 4) I am seeing a Docker image not found error when running tests.
138    How do I build the required docker images?
139
140     You should have two docker images inside the VM named,
141     - base-ubuntu2204:local
142     - csit_sut-ubuntu2204:local.
143
144     If these images are missing, you can create them by typing the below commands:
145     ```
146     cd /opt/csit-docker-images/base
147     docker build -t base-ubuntu2204:local .
148
149     cd /opt/csit-docker-images/csit-sut
150     docker build -t csit_sut-ubuntu2204:local .
151     ```
152
153 5) VPP is failing to start inside the docker container. How do I fix this?
154
155     First start by looking at the log.html file. You should find the startup configuration used to start VPP. For instance, your startup.conf file could look like the below,
156     ```
157     {
158         log /var/log/vpp/vpp.log
159         cli-listen /run/vpp/cli.sock
160         cli-no-pager
161         gid vpp
162         full-coredump
163     }
164     socksvr
165     {
166         socket-name /run/vpp/api.sock
167     }
168     memory
169     {
170         main-heap-size 2G
171         main-heap-page-size 2M
172         default-hugepage-size 2M
173     }
174     statseg
175     {
176         size 2G
177         page-size 2M
178         per-node-counters on
179     }
180     plugins
181     {
182         plugin default
183         {
184             disable
185         }
186         plugin dpdk_plugin.so
187         {
188             enable
189         }
190     }
191     dpdk
192     {
193         dev 0000:00:10.0
194         dev 0000:00:11.0
195     }
196     ip6
197     {
198         hash-buckets 2000000
199         heap-size 4G
200     }
201     ```
202     One common reason for VPP not starting up is not allocating enough hugepages for VPP inside the VM. Increase the number of hugepages to 2560 by typing the below command and try running the tests again.
203
204     ```
205     sudo sysctl -w vm.nr_hugepages=2650
206     ```
207
208 6) How do I check if the robot test cases for virtual interfaces have been successfully generated?
209
210     Check the /generated/tests folder for all the generated tests. If you're running VPP device tests, generated tests will be found in the sub-folder named vpp/device. If you've named your virtual interface  "1ge1p82540em", you will find robot test files with names 2n1l-1ge1p82540em-*
211
212 7) For debugging, how do I prevent the test environment from being torn down after a test run?
213
214     You can disable the CSIT framework from cleaning up the test environment by setting the environment variable CSIT_NO_CLEANUP=1.
215
216     To reset the environment back for regular test runs, reboot the VM by typing the command,
217
218     ```
219     vagrant reload
220     ```
221
222     This will terminate all docker containers and free up all pci interfaces grabbed by dpdk.
223
224     ```
225     cd /home/vagrant/csit/resources/libraries/bash/entry
226     CSIT_NO_CLEANUP=1 ./bootstrap_vpp_device.sh csit-vpp-device-master-ubuntu2004-1n-vbox
227     ```
228
229 8) How do I ssh into the docker container for further troubleshooting?
230
231     First disable test environment cleanups by following the instructions above. This will leave the TG and DUT1 docker containers running. You can now ssh into the csit-dut1-* docker container for further troubleshooting, such as running VPP or robot tests by hand. To do so, find the port published by the DUT1 docker container by typing the below command and then ssh into the container as root. The default root password is Csit1234.
232     ```
233     docker ps  # list all running containers and get the csit-dut1-* container ID
234     docker port ${DUT1_CONTAINER_ID}   # get the published docker container port
235     ssh root@{HOST_IP_ADDRESS} -p {DOCKER_PORT}  # ssh into the container
236     ```
237
238 9) What's the CSIT test topology used for VM tests and where's the topology file?
239
240     CSIT generates a 2 node topology with a TG docker node connected to a DUT1 docker node.
241     The topology file is located at topologies/available/vpp_device.yaml
242     For instance, here's a sample topology file generated by CSIT -
243     ```
244     metadata:
245     version: 0.1
246     schema:
247         - resources/topology_schemas/2_node_topology.sch.yaml
248         - resources/topology_schemas/topology.sch.yaml
249     tags: [dcr, 2-node]
250
251     nodes:
252     TG:
253         type: "TG"
254         host: "10.0.2.15"
255         arch: "x86_64"
256         port: 32768
257         username: "root"
258         interfaces:
259             port0:
260                 mac_address: "08:00:27:0f:e0:4d"
261                 pci_address: "0000:00:08.0"
262                 link: "link0"
263                 model: virtual
264                 driver: "e1000"
265                 vlan: 0
266             port1:
267                 mac_address: "08:00:27:61:f7:ad"
268                 pci_address: "0000:00:09.0"
269                 link: "link1"
270                 model: virtual
271                 driver: "e1000"
272                 vlan: 0
273
274     DUT1:
275         type: "DUT"
276         host: "10.0.2.15"
277         arch: "x86_64"
278         port: 32769
279         username: "root"
280         interfaces:
281             port0:
282                 mac_address: "08:00:27:38:5e:58"
283                 pci_address: "0000:00:10.0"
284                 link: "link0"
285                 model: virtual
286                 driver: "e1000"
287                 vlan: 0
288             port1:
289                 mac_address: "08:00:27:e3:f5:42"
290                 pci_address: "0000:00:11.0"
291                 link: "link1"
292                 model: virtual
293                 driver: "e1000"
294                 vlan: 0
295     ```
296
297 10) How do I run an ansible task after the VM is provisioned?
298
299     You can run a specific ansible task after the VM has been provisioned using ansible tags.
300     For instance, you can run the tasks that has been tagged docker_images, by typing the below ansible command,
301
302     ```
303     cd ~/csit/fdio.infra.ansible
304     ansible-playbook vagrant.yaml --tags "docker_images" -i inventories/vagrant_inventory/hosts
305     ```
306
307 11) Docker image build is failing due to a network error. Where do I set proxy settings for Docker?
308
309     You can set proxy settings for Docker in the file ~/.docker/config.json. Update this file with your environment's proxy info -
310     ```
311     {
312         "proxies":
313         {
314             "default":
315             {
316             "httpProxy": "http://{Proxy_IP_Address}:{Proxy_Port}",
317             "httpsProxy": "http://{Proxy_IP_Address}:{Proxy_Port}",
318             "noProxy": "localhost,127.0.0.1"
319             }
320         }
321     }
322     ```
323
324 12) Where should I set the proxy vars for Ansible?
325
326     Set Ansible proxy variables in the file - fdio.infra.ansible/roles/common/defaults/main.yaml. Uncomment the proxy_env: section and fill the correct proxy values for your dev/test environment.