CSIT-1386 KernelVM - Part I
[csit.git] / resources / libraries / robot / vm / qemu.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 *** Settings ***
14 | Library | resources.libraries.python.IPUtil
15 | Library | resources.libraries.python.QemuUtils
16
17 *** Keywords ***
18 | Configure QEMU vhost and run it
19 | | [Documentation]
20 | | ... | Setup Qemu with 4 vhost-user interfaces and 4 namespaces.
21 | | ... | Each call will be different object instance.
22 | | ...
23 | | ... | *Arguments:*
24 | | ... | - dut_node - Node where to setup qemu. Type: dict
25 | | ... | - sock1 - Socket path for first Vhost-User interface. Type: string
26 | | ... | - sock2 - Socket path for second Vhost-User interface. Type: string
27 | | ... | - sock3 - Socket path for third Vhost-User interface. Type: string
28 | | ... | - sock4 - Socket path for forth Vhost-User interface. Type: string
29 | | ... | - ip1 - IP address for namespace 1. Type: string
30 | | ... | - ip2 - IP address for namespace 2. Type: string
31 | | ... | - ip3 - IP address for namespace 3. Type: string
32 | | ... | - ip4 - IP address for namespace 4. Type: string
33 | | ... | - prefix_length - IP prefix length. Type: int
34 | | ... | - qemu_name - Qemu instance name by which the object will be accessed.
35 | | ... |               Type: string
36 | | ... | - mac_ID - MAC address ID used to differentiate qemu instances and
37 | | ... | namespaces assigned to them. Type: string
38 | | ...
39 | | ... | *Example:*
40 | | ...
41 | | ... | \| Setup QEMU Vhost And Run\| {nodes['DUT1']} \| /tmp/sock1 \
42 | | ... | \| /tmp/sock2 \| /tmp/sock3 \| /tmp/sock4 \| 16.0.0.1 \| 16.0.0.2 \
43 | | ... | \| 16.0.0.3 \| 16.0.0.4 \| 24 \| qemu_instance_1 \| 06 \|
44 | | ...
45 | | [Arguments] | ${dut_node} | ${sock1} | ${sock2} | ${sock3} | ${sock4}
46 | | ... | ${ip1} | ${ip2} | ${ip3} | ${ip4} | ${prefix_length}
47 | | ... | ${qemu_name} | ${mac_ID}=${None}
48 | | ...
49 | | Import Library | resources.libraries.python.QemuUtils \
50 | | ... | node=${dut_node} | WITH NAME | ${qemu_name}
51 | | Run keyword | ${qemu_name}.Qemu Add Vhost User If | ${sock1}
52 | | Run keyword | ${qemu_name}.Qemu Add Vhost User If | ${sock2}
53 | | Run keyword | ${qemu_name}.Qemu Add Vhost User If | ${sock3}
54 | | Run keyword | ${qemu_name}.Qemu Add Vhost User If | ${sock4}
55 | | ${vm}= | Run keyword | ${qemu_name}.Qemu Start
56 | | ${vhost1}= | Get Vhost User If Name By Sock | ${vm} | ${sock1}
57 | | ${vhost2}= | Get Vhost User If Name By Sock | ${vm} | ${sock2}
58 | | ${vhost3}= | Get Vhost User If Name By Sock | ${vm} | ${sock3}
59 | | ${vhost4}= | Get Vhost User If Name By Sock | ${vm} | ${sock4}
60 | | Set Interface State | ${vm} | ${vhost1} | up | if_type=name
61 | | Set Interface State | ${vm} | ${vhost2} | up | if_type=name
62 | | Set Interface State | ${vm} | ${vhost3} | up | if_type=name
63 | | Set Interface State | ${vm} | ${vhost4} | up | if_type=name
64 | | Setup Network Namespace
65 | | ... | ${vm} | nmspace1 | ${vhost1} | ${ip1} | ${prefix_length}
66 | | Setup Network Namespace
67 | | ... | ${vm} | nmspace2 | ${vhost2} | ${ip2} | ${prefix_length}
68 | | Setup Network Namespace
69 | | ... | ${vm} | nmspace3 | ${vhost3} | ${ip3} | ${prefix_length}
70 | | Setup Network Namespace
71 | | ... | ${vm} | nmspace4 | ${vhost4} | ${ip4} | ${prefix_length}
72 | | Set Test Variable | ${${qemu_name}} | ${vm}
73
74 | Tear down QEMU
75 | | [Documentation]
76 | | ... | Stop specific qemu instance running on ${dut_node}.
77 | | ...
78 | | ... | *Arguments:*
79 | | ... | - dut_node - Node where to clean qemu. Type: dict
80 | | ... | - qemu_name - Qemu instance by name. Type: string
81 | | ...
82 | | ... | *Example:*
83 | | ...
84 | | ... | \| Tear down QEMU \| ${node['DUT1']} \| qemu_node_1 \|
85 | | ...
86 | | [Arguments] | ${dut_node} | ${qemu_name}
87 | | ...
88 | | Run Keyword | ${qemu_name}.Qemu Set Node | ${dut_node}
89 | | Run Keyword | ${qemu_name}.Qemu Kill
90
91 | Stop and clear QEMU
92 | | [Documentation]
93 | | ... | Stop QEMU, clear used sockets running on ${dut}.
94 | | ...
95 | | ... | *Arguments:*
96 | | ... | - dut_node - Node where to clean qemu. Type: dict
97 | | ...
98 | | ... | *Example:*
99 | | ...
100 | | ... | \| Tear down QEMU \| ${node['DUT1']} \|
101 | | ...
102 | | [Arguments] | ${dut}
103 | | ...
104 | | Qemu Set Node | ${dut}
105 | | Qemu Kill