Use interface key instead of interface name.
[csit.git] / resources / libraries / robot / double_qemu_setup.robot
1 # Copyright (c) 2016 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 *** Keywords ***
15 | Setup QEMU Vhost and Run
16 | | [Documentation] | Setup Qemu with 4 vhost-user interfaces and 4 namespaces.
17 | | ...             | Each call will be different object instance.
18 | | ...
19 | | ... | *Arguments:*
20 | | ... | - dut_node - Node where to setup qemu. Type: dict
21 | | ... | - sock1 - Socket path for first Vhost-User interface. Type: string
22 | | ... | - sock2 - Socket path for second Vhost-User interface. Type: string
23 | | ... | - sock3 - Socket path for third Vhost-User interface. Type: string
24 | | ... | - sock4 - Socket path for forth Vhost-User interface. Type: string
25 | | ... | - ip1 - IP address for namespace 1. Type: string
26 | | ... | - ip2 - IP address for namespace 2. Type: string
27 | | ... | - ip3 - IP address for namespace 3. Type: string
28 | | ... | - ip4 - IP address for namespace 4. Type: string
29 | | ... | - prefix_length - IP prefix length. Type: int
30 | | ... | - qemu_name - Qemu instance name by which the object will be accessed.
31 | | ... |               Type: string
32 | | ... | - mac_ID - MAC address ID used to differentiate qemu instances and
33 | | ... | namespaces assigned to them. Type: string
34 | | ...
35 | | ... | *Example:*
36 | | ...
37 | | ... | \| Setup QEMU Vhost And Run\| {nodes['DUT1']} \| /tmp/sock1 \
38 | | ... | \| /tmp/sock2 \| /tmp/sock3 \| /tmp/sock4 \| 16.0.0.1 \| 16.0.0.2 \
39 | | ... | \| 16.0.0.3 \| 16.0.0.4 \| 24 \| qemu_instance_1 \| 06 \|
40 | | ...
41 | | [Arguments] | ${dut_node} | ${sock1} | ${sock2} | ${sock3} | ${sock4}
42 | | ... | ${ip1} | ${ip2} | ${ip3} | ${ip4} | ${prefix_length}
43 | | ... | ${qemu_name} | ${mac_ID}
44 | | Import Library | resources.libraries.python.QemuUtils \
45 | | ... | WITH NAME | ${qemu_name}
46 | | ${qemu_add_vhost}= | Replace Variables | ${qemu_name}.Qemu Add Vhost User If
47 | | ${qemu_set_node}= | Replace Variables | ${qemu_name}.Qemu Set Node
48 | | ${qemu_start}= | Replace Variables | ${qemu_name}.Qemu Start
49 | | Run keyword | ${qemu_add_vhost} | ${sock1} | mac=52:54:00:00:${mac_ID}:01
50 | | Run keyword | ${qemu_add_vhost} | ${sock2} | mac=52:54:00:00:${mac_ID}:02
51 | | Run keyword | ${qemu_add_vhost} | ${sock3} | mac=52:54:00:00:${mac_ID}:03
52 | | Run keyword | ${qemu_add_vhost} | ${sock4} | mac=52:54:00:00:${mac_ID}:04
53 | | Run keyword | ${qemu_set_node} | ${dut_node}
54 | | ${vm}= | Run keyword | ${qemu_start}
55 | | ${vhost1}= | Get Vhost User If Name By Sock | ${vm} | ${sock1}
56 | | ${vhost2}= | Get Vhost User If Name By Sock | ${vm} | ${sock2}
57 | | ${vhost3}= | Get Vhost User If Name By Sock | ${vm} | ${sock3}
58 | | ${vhost4}= | Get Vhost User If Name By Sock | ${vm} | ${sock4}
59 | | Set Interface State | ${vm} | ${vhost1} | up | if_type=name
60 | | Set Interface State | ${vm} | ${vhost2} | up | if_type=name
61 | | Set Interface State | ${vm} | ${vhost3} | up | if_type=name
62 | | Set Interface State | ${vm} | ${vhost4} | up | if_type=name
63 | | Setup Network Namespace
64 | | ... | ${vm} | nmspace1 | ${vhost1} | ${ip1} | ${prefix_length}
65 | | Setup Network Namespace
66 | | ... | ${vm} | nmspace2 | ${vhost2} | ${ip2} | ${prefix_length}
67 | | Setup Network Namespace
68 | | ... | ${vm} | nmspace3 | ${vhost3} | ${ip3} | ${prefix_length}
69 | | Setup Network Namespace
70 | | ... | ${vm} | nmspace4 | ${vhost4} | ${ip4} | ${prefix_length}
71 | | Set Test Variable | ${${qemu_name}} | ${vm}
72
73 | Qemu Teardown
74 | | [Documentation] | Stop specific qemu instance
75 | | ...             | running on ${dut_node}, ${vm} is VM node info dictionary
76 | | ...             | returned by qemu_start or None.
77 | | ... | *Arguments:*
78 | | ... | - dut_node - Node where to clean qemu. Type: dict
79 | | ... | - vm - VM node info dictionary. Type: string
80 | | ... | - qemu_name - Qemu instance by name. Type: string
81 | | ...
82 | | ... | *Example:*
83 | | ...
84 | | ... | \| Qemu Teardown \| ${node['DUT1']} \| ${vm} \| qemu_node_1 \|
85 | | ...
86 | | [Arguments] | ${dut_node} | ${vm} | ${qemu_name}
87 | | ${set_node}= | Replace Variables | ${qemu_name}.Qemu Set Node
88 | | ${sys_status}= | Replace Variables | ${qemu_name}.Qemu System Status
89 | | ${kill}= | Replace Variables | ${qemu_name}.Qemu Kill
90 | | ${sys_pd}= | Replace Variables | ${qemu_name}.Qemu System Powerdown
91 | | ${quit}= | Replace Variables | ${qemu_name}.Qemu Quit
92 | | ${clear_socks}= | Replace Variables | ${qemu_name}.Qemu Clear Socks
93 | | Run Keyword | ${set_node} | ${dut_node}
94 | | ${status} | ${value}= | Run Keyword And Ignore Error | ${sys_status}
95 | | Run Keyword If | "${status}" == "FAIL" | ${kill}
96 | | ... | ELSE IF | "${value}" == "running" | ${sys_pd}
97 | | ... | ELSE | ${quit}
98 | | Run Keyword | ${clear_socks}
99 | | Run Keyword If | ${vm} is not None | Disconnect | ${vm}