Read environment variables in Constants.py
[csit.git] / resources / libraries / robot / shared / container.robot
1 # Copyright (c) 2019 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
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 *** Settings ***
15 | Documentation | Keywords related to linux containers
16 | ...
17 | Library | resources.libraries.python.CpuUtils
18 | Library | resources.libraries.python.topology.Topology
19 | Variables | resources/libraries/python/Constants.py
20
21 *** Keywords ***
22 | Construct container on all DUTs
23 | | [Documentation] | Construct 1 CNF of specific technology on all DUT nodes.
24 | | ...
25 | | ... | *Arguments:*
26 | | ... | - nf_chains: Total number of chains (Optional). Type: integer, default
27 | | ... | value: ${1}
28 | | ... | - nf_nodes: Total number of nodes per chain (Optional). Type: integer,
29 | | ... | default value: ${1}
30 | | ... | - nf_chain: Chain ID (Optional). Type: integer, default value: ${1}
31 | | ... | - nf_node: Node ID (Optional). Type: integer, default value: ${1}
32 | | ... | - auto_scale - If True, use same amount of Dataplane threads for
33 | | ... |   network function as DUT, otherwise use single physical core for
34 | | ... |   every network function. Type: boolean
35 | | ... | - pinning: Set True if CPU pinning should be done on starting
36 | | ... |   containers. Type: boolean, default value: ${False}
37 | | ...
38 | | ... | *Example:*
39 | | ...
40 | | ... | \| Construct container on all DUTs \| 1 \| 1 \| 1 \| 1 \| ${True} \|
41 | | ...
42 | | [Arguments] | ${nf_chains}=${1} | ${nf_nodes}=${1} | ${nf_chain}=${1}
43 | | ... | ${nf_node}=${1} | ${auto_scale}=${True} | ${pinning}=${True}
44 | | ...
45 | | ${nf_dtcr_status} | ${value}= | Run Keyword And Ignore Error
46 | | ... | Variable Should Exist | ${nf_dtcr}
47 | | ${nf_dtcr}= | Run Keyword If | '${nf_dtcr_status}' == 'PASS'
48 | | ... | Set Variable | ${nf_dtcr} | ELSE | Set Variable | ${1}
49 | | ${nf_dtc}= | Run Keyword If | ${pinning}
50 | | ... | Set Variable If | ${auto_scale} | ${cpu_count_int}
51 | | ... | ${nf_dtc}
52 | | ${duts}= | Get Matches | ${nodes} | DUT*
53 | | :FOR | ${dut} | IN | @{duts}
54 | | | ${nf_id}= | Evaluate | (${nf_chain} - ${1}) * ${nf_nodes} + ${nf_node}
55 | | | ${env}= | Create List | DEBIAN_FRONTEND=noninteractive
56 | | | ${dut1_uuid_length} = | Get Length | ${DUT1_UUID}
57 | | | ${root}= | Run Keyword If | ${dut1_uuid_length}
58 | | | ... | Get Docker Mergeddir | ${nodes['DUT1']} | ${DUT1_UUID}
59 | | | ... | ELSE | Set Variable | ${EMPTY}
60 | | | ${node_arch}= | Get Node Arch | ${nodes['${dut}']}
61 | | | ${mnt}= | Create List
62 | | | ... | ${root}/tmp/:/mnt/host/
63 | | | ... | ${root}/dev/vfio/:/dev/vfio/
64 | | | ... | ${root}/usr/bin/vpp:/usr/bin/vpp
65 | | | ... | ${root}/usr/bin/vppctl:/usr/bin/vppctl
66 | | | ... | ${root}/usr/lib/${node_arch}-linux-gnu/:/usr/lib/${node_arch}-linux-gnu/
67 | | | ... | ${root}/usr/share/vpp/:/usr/share/vpp/
68 | | | ${nf_cpus}= | Set Variable | ${None}
69 | | | ${nf_cpus}= | Run Keyword If | ${pinning}
70 | | | ... | Get Affinity NF | ${nodes} | ${dut}
71 | | | ... | nf_chains=${nf_chains} | nf_nodes=${nf_nodes}
72 | | | ... | nf_chain=${nf_chain} | nf_node=${nf_node}
73 | | | ... | vs_dtc=${cpu_count_int} | nf_dtc=${nf_dtc} | nf_dtcr=${nf_dtcr}
74 | | | &{cont_args}= | Create Dictionary
75 | | | ... | name=${dut}_${container_group}${nf_id}${DUT1_UUID}
76 | | | ... | node=${nodes['${dut}']} | mnt=${mnt} | env=${env}
77 | | | Run Keyword If | ${pinning}
78 | | | ... | Set To Dictionary | ${cont_args} | cpuset_cpus=${nf_cpus}
79 | | | Run Keyword | ${container_group}.Construct container | &{cont_args}
80
81 | Construct chain of containers on all DUTs
82 | | [Documentation] | Construct 1 chain of 1..N CNFs on all DUT nodes.
83 | | ...
84 | | ... | *Arguments:*
85 | | ... | - nf_chains: Total number of chains. Type: integer
86 | | ... | - nf_nodes: Total number of nodes per chain. Type: integer
87 | | ... | - nf_chain: Chain ID. Type: integer
88 | | ... | - auto_scale - If True, use same amount of Dataplane threads for
89 | | ... |   network function as DUT, otherwise use single physical core for
90 | | ... |   every network function. Type: boolean
91 | | ... | - pinning: Set True if CPU pinning should be done on starting
92 | | ... |   containers. Type: boolean, default value: ${False}
93 | | ...
94 | | ... | *Example:*
95 | | ...
96 | | ... | \| Construct chain of containers on all DUTs \| 1 \| 1 \| 1 \
97 | | ... | \| ${True} \|
98 | | ...
99 | | [Arguments] | ${nf_chains}=${1} | ${nf_nodes}=${1} | ${nf_chain}=${1}
100 | | ... | ${auto_scale}=${True} | ${pinning}=${True}
101 | | ...
102 | | :FOR | ${nf_node} | IN RANGE | 1 | ${nf_nodes}+1
103 | | | Construct container on all DUTs | nf_chains=${nf_chains}
104 | | | ... | nf_nodes=${nf_nodes} | nf_chain=${nf_chain} | nf_node=${nf_node}
105 | | | ... | auto_scale=${auto_scale} | pinning=${pinning}
106
107 | Construct chains of containers on all DUTs
108 | | [Documentation] | Construct 1..N chains of 1..N CNFs on all DUT nodes.
109 | | ...
110 | | ... | *Arguments:*
111 | | ... | - nf_chains: Total number of chains (Optional). Type: integer, default
112 | | ... |   value: ${1}
113 | | ... | - nf_nodes: Total number of nodes per chain (Optional). Type: integer,
114 | | ... |   default value: ${1}
115 | | ... | - auto_scale - If True, use same amount of Dataplane threads for
116 | | ... |   network function as DUT, otherwise use single physical core for
117 | | ... |   every network function. Type: boolean
118 | | ... | - pinning: Set True if CPU pinning should be done on starting
119 | | ... |   containers. Type: boolean, default value: ${True}
120 | | ...
121 | | ... | *Example:*
122 | | ...
123 | | ... | \| Construct chains of containers on all DUTs \| 1 \| 1 \|
124 | | ...
125 | | [Arguments] | ${nf_chains}=${1} | ${nf_nodes}=${1} | ${auto_scale}=${True}
126 | | ... | ${pinning}=${True}
127 | | ...
128 | | :FOR | ${nf_chain} | IN RANGE | 1 | ${nf_chains}+1
129 | | | Construct chain of containers on all DUTs | nf_chains=${nf_chains}
130 | | | ... | nf_nodes=${nf_nodes} | nf_chain=${nf_chain}
131 | | | ... | auto_scale=${auto_scale} | pinning=${pinning}
132
133 | Acquire all '${group}' containers
134 | | [Documentation] | Acquire all container(s) in specific container group on
135 | | ... | all DUT nodes.
136 | | ...
137 | | Run Keyword | ${group}.Acquire all containers
138
139 | Create all '${group}' containers
140 | | [Documentation] | Create/deploy all container(s) in specific container group
141 | | ... | on all DUT nodes.
142 | | ...
143 | | Run Keyword | ${group}.Create all containers
144
145 | Start VPP in all '${group}' containers
146 | | [Documentation] | Start VPP on all container(s) in specific container
147 | | ... | group on all DUT nodes.
148 | | ...
149 | | Run Keyword | ${group}.Start VPP In All Containers
150
151 | Restart VPP in all '${group}' containers
152 | | [Documentation] | Restart VPP on all container(s) in specific container
153 | | ... | group on all DUT nodes.
154 | | ...
155 | | Run Keyword | ${group}.Restart VPP In All Containers
156
157 | Configure VPP in all '${group}' containers
158 | | [Documentation] | Configure VPP on all container(s) in specific container
159 | | ... | group on all DUT nodes.
160 | | ...
161 | | ${dut1_if2} = | Get Variable Value | \${dut1_if2} | ${None}
162 | | ${dut2_if2} = | Get Variable Value | \${dut2_if2} | ${None}
163 | | Run Keyword If | '${container_chain_topology}' == 'chain_ip4'
164 | | ... | ${group}.Configure VPP In All Containers | ${container_chain_topology}
165 | | ... | tg_if1_mac=${tg_if1_mac} | tg_if2_mac=${tg_if2_mac}
166 | | ... | nodes=${nf_nodes}
167 | | ... | ELSE IF | '${container_chain_topology}' == 'pipeline_ip4'
168 | | ... | ${group}.Configure VPP In All Containers | ${container_chain_topology}
169 | | ... | tg_if1_mac=${tg_if1_mac} | tg_if2_mac=${tg_if2_mac}
170 | | ... | nodes=${nf_nodes}
171 | | ... | ELSE IF | '${container_chain_topology}' == 'cross_horiz'
172 | | ... | ${group}.Configure VPP In All Containers | ${container_chain_topology}
173 | | ... | dut1_if=${dut1_if2} | dut2_if=${dut2_if2}
174 | | ... | ELSE
175 | | ... | ${group}.Configure VPP In All Containers | ${container_chain_topology}
176
177 | Stop all '${group}' containers
178 | | [Documentation] | Stop all container(s) in specific container group on all
179 | | ... | DUT nodes.
180 | | ...
181 | | Run Keyword | ${group}.Stop all containers
182
183 | Destroy all '${group}' containers
184 | | [Documentation] | Destroy all container(s) in specific container group on
185 | | ... | all DUT nodes.
186 | | ...
187 | | Run Keyword | ${group}.Destroy all containers
188
189 | Start containers for test
190 | | [Documentation]
191 | | ... | Start containers for test.
192 | | ...
193 | | ... | *Arguments:*
194 | | ... | - nf_chains: Total number of chains. Type: integer
195 | | ... | - nf_nodes: Total number of nodes per chain. Type: integer
196 | | ... | - auto_scale - If True, use same amount of Dataplane threads for
197 | | ... |   network function as DUT, otherwise use single physical core for
198 | | ... |   every network function. Type: boolean
199 | | ... | - pinning: Set True if CPU pinning should be done on starting
200 | | ... |   containers. Type: boolean, default value: ${False}
201 | | ...
202 | | ... | *Example:*
203 | | ...
204 | | ... | \| Start containers for test \| 1 \| 1 \|
205 | | ...
206 | | [Arguments] | ${nf_chains}=${1} | ${nf_nodes}=${1} | ${auto_scale}=${True}
207 | | ... | ${pinning}=${True}
208 | | ...
209 | | Set Test Variable | @{container_groups} | @{EMPTY}
210 | | Set Test Variable | ${container_group} | CNF
211 | | Set Test Variable | ${nf_nodes}
212 | | Import Library | resources.libraries.python.ContainerUtils.ContainerManager
213 | | ... | engine=${container_engine} | WITH NAME | ${container_group}
214 | | Construct chains of containers on all DUTs | ${nf_chains} | ${nf_nodes}
215 | | ... | auto_scale=${auto_scale} | pinning=${pinning}
216 | | Acquire all '${container_group}' containers
217 | | Create all '${container_group}' containers
218 | | Configure VPP in all '${container_group}' containers
219 | | Start VPP in all '${container_group}' containers
220 | | Append To List | ${container_groups} | ${container_group}
221 | | Save VPP PIDs