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