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