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

©2016 FD.io a Linux Foundation Collaborative Project. All Rights Reserved.
Linux Foundation is a registered trademark of The Linux Foundation. Linux is a registered trademark of Linus Torvalds.
Please see our privacy policy and terms of use.