Refactor getting telemetry
[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 | | ${duts}= | Get Matches | ${nodes} | DUT*
46 | | :FOR | ${dut} | IN | @{duts}
47 | | | Run Keyword | Construct container on DUT | ${dut}
48 | | | ... | ${nf_chains} | ${nf_nodes} | ${nf_chain}
49 | | | ... | ${nf_node} | ${auto_scale} | ${pinning}
50
51 | Construct container on DUT
52 | | [Documentation] | Construct 1 CNF of specific technology on specific DUT.
53 | | ...
54 | | ... | *Arguments:*
55 | | ... | - dut: DUT node to construct the CNF on. Type: string
56 | | ... | - nf_chains: Total number of chains (Optional). Type: integer, default
57 | | ... | value: ${1}
58 | | ... | - nf_nodes: Total number of nodes per chain (Optional). Type: integer,
59 | | ... | default value: ${1}
60 | | ... | - nf_chain: Chain ID (Optional). Type: integer, default value: ${1}
61 | | ... | - nf_node: Node ID (Optional). Type: integer, default value: ${1}
62 | | ... | - auto_scale - If True, use same amount of Dataplane threads for
63 | | ... |   network function as DUT, otherwise use single physical core for
64 | | ... |   every network function. Type: boolean
65 | | ... | - pinning: Set True if CPU pinning should be done on starting
66 | | ... |   containers. Type: boolean, default value: ${False}
67 | | ...
68 | | ... | *Example:*
69 | | ...
70 | | ... | \| Construct container on DUT \| DUT1 \| 1 \| 1 \| 1 \| 1 \|
71 | | ... | \| ${True} \|
72 | | ...
73 | | [Arguments] | ${dut}
74 | | ... | ${nf_chains}=${1} | ${nf_nodes}=${1} | ${nf_chain}=${1}
75 | | ... | ${nf_node}=${1} | ${auto_scale}=${True} | ${pinning}=${True}
76 | | ...
77 | | ${nf_dtcr_status} | ${value}= | Run Keyword And Ignore Error
78 | | ... | Variable Should Exist | ${nf_dtcr}
79 | | ${nf_dtcr}= | Run Keyword If | '${nf_dtcr_status}' == 'PASS'
80 | | ... | Set Variable | ${nf_dtcr} | ELSE | Set Variable | ${1}
81 | | ${nf_dtc}= | Run Keyword If | ${pinning}
82 | | ... | Set Variable If | ${auto_scale} | ${cpu_count_int}
83 | | ... | ${nf_dtc}
84 | | ${nf_id}= | Evaluate | (${nf_chain} - ${1}) * ${nf_nodes} + ${nf_node}
85 | | ${env}= | Create List | DEBIAN_FRONTEND=noninteractive
86 | | ${dut1_uuid_length} = | Get Length | ${DUT1_UUID}
87 | | ${root}= | Run Keyword If | ${dut1_uuid_length}
88 | | ... | Get Docker Mergeddir | ${nodes['DUT1']} | ${DUT1_UUID}
89 | | ... | ELSE | Set Variable | ${EMPTY}
90 | | ${node_arch}= | Get Node Arch | ${nodes['${dut}']}
91 | | ${name}= | Set Variable | ${dut}_${container_group}${nf_id}${DUT1_UUID}
92 | | ${mnt}= | Create List
93 | | ... | ${root}/tmp/:/mnt/host/
94 | | ... | ${root}/tmp/vpp_sockets/${name}/:/run/vpp/
95 | | ... | ${root}/dev/vfio/:/dev/vfio/
96 | | ... | ${root}/usr/bin/vpp:/usr/bin/vpp
97 | | ... | ${root}/usr/bin/vppctl:/usr/bin/vppctl
98 | | ... | ${root}/usr/lib/${node_arch}-linux-gnu/:/usr/lib/${node_arch}-linux-gnu/
99 | | ... | ${root}/usr/share/vpp/:/usr/share/vpp/
100 | | ${nf_cpus}= | Set Variable | ${None}
101 | | ${nf_cpus}= | Run Keyword If | ${pinning}
102 | | ... | Get Affinity NF | ${nodes} | ${dut}
103 | | ... | nf_chains=${nf_chains} | nf_nodes=${nf_nodes}
104 | | ... | nf_chain=${nf_chain} | nf_node=${nf_node}
105 | | ... | vs_dtc=${cpu_count_int} | nf_dtc=${nf_dtc} | nf_dtcr=${nf_dtcr}
106 | | &{cont_args}= | Create Dictionary
107 | | ... | name=${name} | node=${nodes['${dut}']} | mnt=${mnt} | env=${env}
108 | | ... | root=${root}
109 | | Run Keyword If | ${pinning}
110 | | ... | Set To Dictionary | ${cont_args} | cpuset_cpus=${nf_cpus}
111 | | Run Keyword | ${container_group}.Construct container | &{cont_args}
112
113 | Construct chain of containers
114 | | [Documentation] | Construct 1 chain of 1..N CNFs on selected/all DUT nodes.
115 | | ...
116 | | ... | *Arguments:*
117 | | ... | - dut: DUT node to start the containers on. Run on all nodes if None.
118 | | ... |   Type: string or None
119 | | ... | - nf_chains: Total number of chains. Type: integer
120 | | ... | - nf_nodes: Total number of nodes per chain. Type: integer
121 | | ... | - nf_chain: Chain ID. Type: integer
122 | | ... | - auto_scale - If True, use same amount of Dataplane threads for
123 | | ... |   network function as DUT, otherwise use single physical core for
124 | | ... |   every network function. Type: boolean
125 | | ... | - pinning: Set True if CPU pinning should be done on starting
126 | | ... |   containers. Type: boolean, default value: ${False}
127 | | ...
128 | | ... | *Example:*
129 | | ...
130 | | ... | \| Construct chain of containers \| 1 \| 1 \| 1 \| ${True} \|
131 | | ...
132 | | [Arguments] | ${dut}=${None} | ${nf_chains}=${1} | ${nf_nodes}=${1}
133 | | ... | ${nf_chain}=${1} | ${auto_scale}=${True} | ${pinning}=${True}
134 | | ...
135 | | :FOR | ${nf_node} | IN RANGE | 1 | ${nf_nodes}+1
136 | | | Run Keyword If | '${dut}' == '${None}'
137 | | | ... | Construct container on all DUTs
138 | | | ... | nf_chains=${nf_chains} | nf_nodes=${nf_nodes} | nf_chain=${nf_chain}
139 | | | ... | nf_node=${nf_node} | auto_scale=${auto_scale} | pinning=${pinning}
140 | | | ... | ELSE
141 | | | ... | Construct container on DUT | ${dut}
142 | | | ... | nf_chains=${nf_chains} | nf_nodes=${nf_nodes} | nf_chain=${nf_chain}
143 | | | ... | nf_node=${nf_node} | auto_scale=${auto_scale} | pinning=${pinning}
144
145 | Construct chains of containers
146 | | [Documentation] | Construct 1..N chains of 1..N CNFs on selected/all DUT
147 | | ... | nodes.
148 | | ...
149 | | ... | *Arguments:*
150 | | ... | - dut: DUT node to start the containers on. Run on all nodes if None.
151 | | ... |   Type: string or None
152 | | ... | - nf_chains: Total number of chains (Optional). Type: integer, default
153 | | ... |   value: ${1}
154 | | ... | - nf_nodes: Total number of nodes per chain (Optional). Type: integer,
155 | | ... |   default value: ${1}
156 | | ... | - auto_scale - If True, use same amount of Dataplane threads for
157 | | ... |   network function as DUT, otherwise use single physical core for
158 | | ... |   every network function. Type: boolean
159 | | ... | - pinning: Set True if CPU pinning should be done on starting
160 | | ... |   containers. Type: boolean, default value: ${True}
161 | | ...
162 | | ... | *Example:*
163 | | ...
164 | | ... | \| Construct chains of containers \| 1 \| 1 \|
165 | | ...
166 | | [Arguments] | ${dut}=${None} | ${nf_chains}=${1} | ${nf_nodes}=${1}
167 | | ... | ${auto_scale}=${True} | ${pinning}=${True}
168 | | ...
169 | | :FOR | ${nf_chain} | IN RANGE | 1 | ${nf_chains}+1
170 | | | Construct chain of containers
171 | | | ... | dut=${dut} | nf_chains=${nf_chains} | nf_nodes=${nf_nodes}
172 | | | ... | nf_chain=${nf_chain} | auto_scale=${auto_scale} | pinning=${pinning}
173
174 | Acquire all '${group}' containers
175 | | [Documentation] | Acquire all container(s) in specific container group on
176 | | ... | all DUT nodes.
177 | | ...
178 | | Run Keyword | ${group}.Acquire all containers
179
180 | Create all '${group}' containers
181 | | [Documentation] | Create/deploy all container(s) in specific container group
182 | | ... | on all DUT nodes.
183 | | ...
184 | | Run Keyword | ${group}.Create all containers
185
186 | Start VPP in all '${group}' containers
187 | | [Documentation] | Start VPP on all container(s) in specific container
188 | | ... | group on all DUT nodes.
189 | | ...
190 | | Run Keyword | ${group}.Start VPP In All Containers
191
192 | Restart VPP in all '${group}' containers
193 | | [Documentation] | Restart VPP on all container(s) in specific container
194 | | ... | group on all DUT nodes.
195 | | ...
196 | | Run Keyword | ${group}.Restart VPP In All Containers
197
198 | Configure VPP in all '${group}' containers
199 | | [Documentation] | Configure VPP on all container(s) in specific container
200 | | ... | group on all DUT nodes.
201 | | ...
202 | | ... | *Test (or broader scope) variables read:*
203 | | ... |   - container_chain_topology - Topology type used for configuring CNF
204 | | ... |     (VPP) in container. Type: string
205 | | ...
206 | | ${dut1_if2} = | Get Variable Value | \${dut1_if2} | ${None}
207 | | ${dut2_if2} = | Get Variable Value | \${dut2_if2} | ${None}
208 | | Run Keyword If | '${container_chain_topology}' == 'chain_ip4'
209 | | ... | ${group}.Configure VPP In All Containers | ${container_chain_topology}
210 | | ... | tg_if1_mac=${tg_if1_mac} | tg_if2_mac=${tg_if2_mac}
211 | | ... | nodes=${nf_nodes}
212 | | ... | ELSE IF | '${container_chain_topology}' == 'chain_ipsec'
213 | | ... | ${group}.Configure VPP In All Containers | ${container_chain_topology}
214 | | ... | tg_if2_ip4=${tg_if2_ip4} | tg_if2_mac=${tg_if2_mac}
215 | | ... | dut2_if1_ip4=${dut2_if1_ip4} | dut2_if2_ip4=${dut2_if2_ip4}
216 | | ... | raddr_ip4=${raddr_ip4} | nodes=${nodes} | nf_nodes=${nf_nodes}
217 | | ... | ELSE IF | '${container_chain_topology}' == 'pipeline_ip4'
218 | | ... | ${group}.Configure VPP In All Containers | ${container_chain_topology}
219 | | ... | tg_if1_mac=${tg_if1_mac} | tg_if2_mac=${tg_if2_mac}
220 | | ... | nodes=${nf_nodes}
221 | | ... | ELSE IF | '${container_chain_topology}' == 'cross_horiz'
222 | | ... | ${group}.Configure VPP In All Containers | ${container_chain_topology}
223 | | ... | dut1_if=${dut1_if2} | dut2_if=${dut2_if2}
224 | | ... | ELSE
225 | | ... | ${group}.Configure VPP In All Containers | ${container_chain_topology}
226
227 | Stop all '${group}' containers
228 | | [Documentation] | Stop all container(s) in specific container group on all
229 | | ... | DUT nodes.
230 | | ...
231 | | Run Keyword | ${group}.Stop all containers
232
233 | Destroy all '${group}' containers
234 | | [Documentation] | Destroy all container(s) in specific container group on
235 | | ... | all DUT nodes.
236 | | ...
237 | | Run Keyword | ${group}.Destroy all containers
238
239 | Start containers for test
240 | | [Documentation]
241 | | ... | Start containers for test.
242 | | ...
243 | | ... | *Arguments:*
244 | | ... | - dut: DUT node to start the containers on. Run on all nodes if None.
245 | | ... |   Type: string or None
246 | | ... | - nf_chains: Total number of chains. Type: integer
247 | | ... | - nf_nodes: Total number of nodes per chain. Type: integer
248 | | ... | - auto_scale - If True, use same amount of Dataplane threads for
249 | | ... |   network function as DUT, otherwise use single physical core for
250 | | ... |   every network function. Type: boolean
251 | | ... | - pinning: Set True if CPU pinning should be done on starting
252 | | ... |   containers. Type: boolean, default value: ${False}
253 | | ...
254 | | ... | *Example:*
255 | | ...
256 | | ... | \| Start containers for test \| 1 \| 1 \|
257 | | ...
258 | | [Arguments] | ${dut}=${None} | ${nf_chains}=${1} | ${nf_nodes}=${1}
259 | | ... | ${auto_scale}=${True} | ${pinning}=${True}
260 | | ...
261 | | Set Test Variable | @{container_groups} | @{EMPTY}
262 | | Set Test Variable | ${container_group} | CNF
263 | | Set Test Variable | ${nf_nodes}
264 | | Import Library | resources.libraries.python.ContainerUtils.ContainerManager
265 | | ... | engine=${container_engine} | WITH NAME | ${container_group}
266 | | Construct chains of containers
267 | | ... | dut=${dut} | nf_chains=${nf_chains} | nf_nodes=${nf_nodes}
268 | | ... | auto_scale=${auto_scale} | pinning=${pinning}
269 | | Acquire all '${container_group}' containers
270 | | Create all '${container_group}' containers
271 | | Configure VPP in all '${container_group}' containers
272 | | Start VPP in all '${container_group}' containers
273 | | Append To List | ${container_groups} | ${container_group}
274 | | Save VPP PIDs