|
1 | 1 | import logging as log |
2 | 2 | import ipaddress |
| 3 | +import platform |
3 | 4 | import time |
4 | 5 |
|
5 | 6 | from virttest import virsh, virt_vm |
@@ -39,6 +40,8 @@ def run(test, params, env): |
39 | 40 | i) Reboot. |
40 | 41 | ii) Suspend/Resume. |
41 | 42 | iii) Start/Shutdown. |
| 43 | + d). Multiple Reboots: |
| 44 | + 1. Checking PCI Device remains persistent across multiple reboots |
42 | 45 | """ |
43 | 46 |
|
44 | 47 | def guest_lifecycle(): |
@@ -93,6 +96,8 @@ def guest_lifecycle(): |
93 | 96 | sriov = ('yes' == params.get("libvirt_pci_SRIOV", 'no')) |
94 | 97 | device_type = params.get("libvirt_pci_device_type", "NIC") |
95 | 98 | vm_vfs = int(params.get("number_vfs", 2)) |
| 99 | + number_of_reboots = int(params.get("number_of_reboots", "1")) |
| 100 | + arch = platform.machine() |
96 | 101 | pci_dev = None |
97 | 102 | pci_address = None |
98 | 103 | bus_info = [] |
@@ -174,59 +179,76 @@ def guest_lifecycle(): |
174 | 179 | pci_address = pci_xml.cap.get_address_dict() |
175 | 180 | vmxml.add_hostdev(pci_address) |
176 | 181 |
|
177 | | - try: |
178 | | - for itr in range(iteration): |
179 | | - logging.info("Currently executing iteration number: '%s'", itr) |
180 | | - vmxml.sync() |
181 | | - vm.start() |
182 | | - session = vm.wait_for_login() |
183 | | - # The Network configuration is generic irrespective of PF or SRIOV VF |
184 | | - if device_type == "NIC": |
185 | | - if sorted(vm.get_pci_devices()) != sorted(nic_list_before): |
186 | | - logging.debug("Adapter passthroughed to guest successfully") |
187 | | - else: |
188 | | - test.fail("Passthrough adapter not found in guest.") |
189 | | - net_ip = ipaddress.ip_address(net_ip) |
190 | | - nic_list_after = vm.get_pci_devices() |
191 | | - nic_list = list(set(nic_list_after).difference(set(nic_list_before))) |
192 | | - for val in range(len(nic_list)): |
193 | | - bus_info.append(str(nic_list[val]).split(' ', 1)[0]) |
194 | | - nic_list[val] = str(nic_list[val]).split(' ', 1)[0][:-2] |
195 | | - bus_info.sort() |
196 | | - if not sriov: |
197 | | - # check all functions get same iommu group |
| 182 | + def check_device_status(net_ip, server_ip, netmask): |
| 183 | + logging.info("Currently executing iteration number: '%s'", itr) |
| 184 | + vmxml.sync() |
| 185 | + vm.start() |
| 186 | + session = vm.wait_for_login() |
| 187 | + # The Network configuration is generic irrespective of PF or SRIOV VF |
| 188 | + if device_type == "NIC": |
| 189 | + if sorted(vm.get_pci_devices()) != sorted(nic_list_before): |
| 190 | + logging.debug("Adapter passthroughed to guest successfully") |
| 191 | + else: |
| 192 | + test.fail("Passthrough adapter not found in guest.") |
| 193 | + net_ip = ipaddress.ip_address(net_ip) |
| 194 | + nic_list_after = vm.get_pci_devices() |
| 195 | + nic_list = list(set(nic_list_after).difference(set(nic_list_before))) |
| 196 | + for val in range(len(nic_list)): |
| 197 | + bus_info.append(str(nic_list[val]).split(' ', 1)[0]) |
| 198 | + nic_list[val] = str(nic_list[val]).split(' ', 1)[0][:-2] |
| 199 | + bus_info.sort() |
| 200 | + if not sriov: |
| 201 | + # check all functions get same iommu group |
| 202 | + # arch ppc64 gets different iommu group when attached to VM |
| 203 | + if arch != "ppc64le": |
198 | 204 | if len(set(nic_list)) != 1: |
199 | 205 | test.fail("Multifunction Device passthroughed but " |
200 | 206 | "functions are in different iommu group") |
201 | | - # ping to server from each function |
202 | | - for val in bus_info: |
203 | | - nic_name = str(utils_misc.get_interface_from_pci_id(val, session)) |
204 | | - session.cmd("ip addr flush dev %s" % nic_name) |
205 | | - session.cmd("ip addr add %s/%s dev %s" |
206 | | - % (net_ip, netmask, nic_name)) |
207 | | - session.cmd("ip link set %s up" % nic_name) |
208 | | - # Pinging using nic_name is having issue, |
209 | | - # hence replaced with IPAddress |
210 | | - s_ping, o_ping = utils_test.ping(server_ip, count=5, |
211 | | - interface=net_ip, timeout=30, |
212 | | - session=session) |
213 | | - logging.info(o_ping) |
214 | | - if s_ping != 0: |
215 | | - err_msg = "Ping test fails, error info: '%s'" |
216 | | - test.fail(err_msg % o_ping) |
217 | | - # Each interface should have unique IP |
| 207 | + # ping to server from each function |
| 208 | + for val in bus_info: |
| 209 | + nic_name = str(utils_misc.get_interface_from_pci_id(val, session)) |
| 210 | + session.cmd("ip addr flush dev %s" % nic_name) |
| 211 | + session.cmd("ip addr add %s/%s dev %s" |
| 212 | + % (net_ip, netmask, nic_name)) |
| 213 | + session.cmd("ip link set %s up" % nic_name) |
| 214 | + # Pinging using nic_name is having issue, |
| 215 | + # hence replaced with IPAddress |
| 216 | + s_ping, o_ping = utils_test.ping(server_ip, count=5, |
| 217 | + interface=net_ip, timeout=30, |
| 218 | + session=session) |
| 219 | + logging.info(o_ping) |
| 220 | + if s_ping != 0: |
| 221 | + err_msg = "Ping test fails, error info: '%s'" |
| 222 | + test.fail(err_msg % o_ping) |
| 223 | + # Each interface should have unique IP |
| 224 | + # For ppc64 arch let's test using one ip only |
| 225 | + if arch != "ppc64le": |
218 | 226 | net_ip = net_ip + 1 |
219 | 227 |
|
220 | | - elif device_type == "STORAGE": |
221 | | - # Get the result of "fdisk -l" in guest, and |
222 | | - # compare the result with fdisk_list_before. |
223 | | - output = session.cmd_output("fdisk -l|grep \"Disk identifier:\"") |
224 | | - fdisk_list_after = output.splitlines() |
225 | | - if fdisk_list_after == fdisk_list_before: |
226 | | - test.fail("Didn't find the disk attached to guest.") |
| 228 | + elif device_type == "STORAGE": |
| 229 | + # Get the result of "fdisk -l" in guest, and |
| 230 | + # compare the result with fdisk_list_before. |
| 231 | + output = session.cmd_output("fdisk -l|grep \"Disk identifier:\"") |
| 232 | + fdisk_list_after = output.splitlines() |
| 233 | + if fdisk_list_after == fdisk_list_before: |
| 234 | + test.fail("Didn't find the disk attached to guest.") |
227 | 235 |
|
228 | | - # Execute VM Life-cycle Operation with device pass-through |
| 236 | + def multiple_reboot(number_of_reboots): |
| 237 | + for reboot_count in range(number_of_reboots): |
| 238 | + logging.info("Performing VM Reboot with device pass-through for reboot count : %s", reboot_count) |
229 | 239 | guest_lifecycle() |
| 240 | + logging.info("Check device avialablity after VM Reboot for reboot count : %s", reboot_count) |
| 241 | + check_device_status(net_ip, server_ip, netmask) |
| 242 | + |
| 243 | + try: |
| 244 | + for itr in range(iteration): |
| 245 | + check_device_status(net_ip, server_ip, netmask) |
| 246 | + |
| 247 | + # Execute VM Life-cycle Operation with device pass-through |
| 248 | + guest_lifecycle() |
| 249 | + |
| 250 | + # Execute Multiple reboots on VM and check the device persistency |
| 251 | + multiple_reboot(number_of_reboots) |
230 | 252 |
|
231 | 253 | finally: |
232 | 254 | backup_xml.sync() |
|
0 commit comments