CSIT-441 vhost - Parametrized qemu install
[csit.git] / resources / libraries / robot / qemu.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.QemuUtils
15 | Library | resources.libraries.python.ssh.SSH
16
17 *** Keywords ***
18
19 | Exist QEMU Build List
20 | | [Documentation] | Return TRUE if variable QEMU_BUILD exist, otherwise FALSE
21 | | ${ret} | ${tmp}=  | Run Keyword And Ignore Error
22 | | ... | Variable Should Exist | @{QEMU_BUILD}
23 | | Return From Keyword If | "${ret}" == "PASS" | ${TRUE}
24 | | Return From Keyword | ${FALSE}
25
26 | Is QEMU Ready on Node
27 | | [Documentation] | Check if QEMU was built on the node before
28 | | [Arguments] | ${node}
29 | | ${ret}= | Exist QEMU Build List
30 | | Return From Keyword If | ${ret} == ${FALSE} | ${FALSE}
31 | | ${ret} | ${tmp}=  | Run Keyword And Ignore Error
32 | | ... | Should Contain | ${QEMU_BUILD} | ${node['host']}
33 | | Return From Keyword If | "${ret}" == "PASS" | ${TRUE}
34 | | Return From Keyword | ${FALSE}
35
36 | Add Node to QEMU Build List
37 | | [Documentation] | Add node to the list of nodes with builded QEMU (global
38 | | ...             | variable QEMU_BUILD)
39 | | [Arguments] | ${node}
40 | | ${ret}= | Exist QEMU Build List
41 | | Run Keyword If | ${ret} == ${TRUE}
42 | | ... | Append To List | ${QEMU_BUILD} | ${node['host']}
43 | | ... | ELSE | Set Global Variable | @{QEMU_BUILD} | ${node['host']}
44
45 | Build QEMU on Node
46 | | [Documentation] | Build QEMU from sources on the Node. Nodes with successful
47 | | ...             | QEMU build are stored in global variable list QEMU_BUILD
48 | | ...
49 | | ... | *Arguments:*
50 | | ... | - node - Node on which to build qemu. Type: dictionary
51 | | ... | - force_install - If True, then remove previous build. Type: bool
52 | | ... | - apply_patch - If True, then apply patches from qemu_patches dir.
53 | | ... | Type: bool
54 | | ...
55 | | ... | *Example:*
56 | | ...
57 | | ... | \| Build QEMU on Node \| ${node['DUT1']} \| False \| False \|
58 | | ...
59 | | [Arguments] | ${node} | ${force_install}=${False} | ${apply_patch}=${False}
60 | | ${ready}= | Is QEMU Ready on Node | ${node}
61 | | Return From Keyword If | ${ready} == ${TRUE}
62 | | Build QEMU | ${node}
63 | | Add Node to QEMU Build List | ${node}
64
65 | Build QEMU on all DUTs
66 | | [Documentation] | Build QEMU from sources on all DUTs. Nodes with successful
67 | | ...             | QEMU build are stored in global variable list QEMU_BUILD
68 | | ...
69 | | ... | *Arguments:*
70 | | ... | - force_install - If True, then remove previous build. Type: bool
71 | | ... | - apply_patch - If True, then apply patches from qemu_patches dir.
72 | | ... | Type: bool
73 | | ...
74 | | ... | *Example:*
75 | | ...
76 | | ... | \| Build QEMU on all DUTs \| False \| False \|
77 | | ...
78 | | [Arguments] | ${force_install}=${False} | ${apply_patch}=${False}
79 | | ${duts}= | Get Matches | ${nodes} | DUT*
80 | | :FOR | ${dut} | IN | @{duts}
81 | | | Build QEMU on Node | ${nodes['${dut}']} | ${force_install} |
82 | | | ... | ${apply_patch}
83
84 | Stop and Clear QEMU
85 | | [Documentation] | Stop QEMU, clear used sockets and close SSH connection
86 | | ...             | running on ${dut}, ${vm} is VM node info dictionary
87 | | ...             | returned by qemu_start or None.
88 | | [Arguments] | ${dut} | ${vm}
89 | | Qemu Set Node | ${dut}
90 | | Qemu Kill
91 | | Qemu Clear Socks
92 | | Run Keyword If | ${vm} is not None | Disconnect | ${vm}
93
94 | Kill Qemu on all DUTs
95 | | [Documentation] | Kill QEMU processes on all DUTs.
96 | | ${duts}= | Get Matches | ${nodes} | DUT*
97 | | :FOR | ${dut} | IN | @{duts}
98 | | | Qemu Set Node | ${nodes['${dut}']}
99 | | | Qemu Kill