Add: Use containers for shared TG
[csit.git] / resources / tools / testbed-setup / ansible / roles / tg / files / csit-initialize-docker-tg.sh
1 #!/usr/bin/env bash
2
3 # Copyright (c) 2019 Cisco and/or its affiliates.
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 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # CSIT SRIOV VF initialization and isolation.
17
18 set -euo pipefail
19
20 case "${1:-start}" in
21     "start" )
22         # Run TG
23         for cnt in $(seq 1 ${2:-1}); do
24             # If the IMAGE is not already loaded then docker run will pull the
25             # IMAGE, and all image dependencies, before it starts the container.
26             dcr_image="snergster/csit-sut:latest"
27             # Run the container in the background and print the new container
28             # ID.
29             dcr_stc_params="--detach=true "
30             # Give extended privileges to this container. A "privileged"
31             # container is given access to all devices and able to run nested
32             # containers.
33             dcr_stc_params+="--privileged "
34             # Publish all exposed ports to random ports on the host interfaces.
35             dcr_stc_params+="--publish 600${cnt}:22 "
36             # Automatically remove the container when it exits.
37             dcr_stc_params+="--rm "
38             # Size of /dev/shm.
39             dcr_stc_params+="--shm-size 4G "
40             # Mount vfio to be able to bind to see binded interfaces. We cannot
41             # use --device=/dev/vfio as this does not see newly binded
42             # interfaces.
43             dcr_stc_params+="--volume /dev:/dev "
44             # Mount /opt/boot/ where VM kernel and initrd are located.
45             dcr_stc_params+="--volume /opt:/opt "
46             # Mount host hugepages for VMs.
47             dcr_stc_params+="--volume /dev/hugepages:/dev/hugepages "
48
49             params=(${dcr_stc_params} --name csit-tg-"${cnt}" "${dcr_image}")
50             docker run "${params[@]}"
51         done
52         ;;
53     "stop" )
54         docker rm --force $(docker ps --all --quiet --filter name=csit-tg)
55         ;;
56 esac