| Index: client/tests/kvm/kvm_vm.py
|
| diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
|
| index 969558b92b8f52ecba07db4e6faf4adb59904ecf..41f7491f90a0ae20098517c1a228b419025e52b1 100755
|
| --- a/client/tests/kvm/kvm_vm.py
|
| +++ b/client/tests/kvm/kvm_vm.py
|
| @@ -325,6 +325,7 @@ class VM:
|
| self.monitors = []
|
| self.pci_assignable = None
|
| self.netdev_id = []
|
| + self.device_id = []
|
| self.uuid = None
|
|
|
| # Find a unique identifier for this VM
|
| @@ -461,7 +462,7 @@ class VM:
|
| cmd += ",boot=on"
|
| return cmd
|
|
|
| - def add_nic(help, vlan, model=None, mac=None, netdev_id=None,
|
| + def add_nic(help, vlan, model=None, mac=None, device_id=None, netdev_id=None,
|
| nic_extra_params=None):
|
| if has_option(help, "netdev"):
|
| netdev_vlan_str = ",netdev=%s" % netdev_id
|
| @@ -483,6 +484,8 @@ class VM:
|
| cmd += ",model=%s" % model
|
| if mac:
|
| cmd += ",macaddr='%s'" % mac
|
| + if device_id:
|
| + cmd += ",id='%s'" % device_id
|
| return cmd
|
|
|
| def add_net(help, vlan, mode, ifname=None, script=None,
|
| @@ -635,13 +638,17 @@ class VM:
|
| nic_params = params.object_params(nic_name)
|
| try:
|
| netdev_id = vm.netdev_id[vlan]
|
| + device_id = vm.device_id[vlan]
|
| except IndexError:
|
| netdev_id = None
|
| # Handle the '-net nic' part
|
| - mac = vm.get_mac_address(vlan)
|
| + try:
|
| + mac = vm.get_mac_address(vlan)
|
| + except VMAddressError:
|
| + mac = None
|
| qemu_cmd += add_nic(help, vlan, nic_params.get("nic_model"), mac,
|
| - netdev_id, nic_params.get("nic_extra_params"))
|
| - # Handle the '-net tap' or '-net user' part
|
| + device_id, netdev_id, nic_params.get("nic_extra_params"))
|
| + # Handle the '-net tap' or '-net user' or '-netdev' part
|
| script = nic_params.get("nic_script")
|
| downscript = nic_params.get("nic_downscript")
|
| tftp = nic_params.get("tftp")
|
| @@ -827,10 +834,12 @@ class VM:
|
| guest_port = int(redir_params.get("guest_port"))
|
| self.redirs[guest_port] = host_ports[i]
|
|
|
| - # Generate netdev IDs for all NICs
|
| + # Generate netdev/device IDs for all NICs
|
| self.netdev_id = []
|
| + self.device_id = []
|
| for nic in params.objects("nics"):
|
| self.netdev_id.append(kvm_utils.generate_random_id())
|
| + self.device_id.append(kvm_utils.generate_random_id())
|
|
|
| # Find available VNC port, if needed
|
| if params.get("display") == "vnc":
|
| @@ -847,15 +856,12 @@ class VM:
|
| for vlan in range(num_nics):
|
| nic_name = params.objects("nics")[vlan]
|
| nic_params = params.object_params(nic_name)
|
| - if nic_params.get("nic_mac", None):
|
| - mac = nic_params.get("nic_mac")
|
| + mac = (nic_params.get("nic_mac") or
|
| + mac_source and mac_source.get_mac_address(vlan))
|
| + if mac:
|
| kvm_utils.set_mac_address(self.instance, vlan, mac)
|
| else:
|
| - mac = mac_source and mac_source.get_mac_address(vlan)
|
| - if mac:
|
| - kvm_utils.set_mac_address(self.instance, vlan, mac)
|
| - else:
|
| - kvm_utils.generate_mac_address(self.instance, vlan)
|
| + kvm_utils.generate_mac_address(self.instance, vlan)
|
|
|
| # Assign a PCI assignable device
|
| self.pci_assignable = None
|
| @@ -1207,6 +1213,20 @@ class VM:
|
| raise VMPortNotRedirectedError(port)
|
|
|
|
|
| + def get_peer(self, netid):
|
| + """
|
| + Return the peer of netdev or network deivce.
|
| +
|
| + @param netid: id of netdev or device
|
| + @return: id of the peer device otherwise None
|
| + """
|
| + network_info = self.monitor.info("network")
|
| + try:
|
| + return re.findall("%s:.*peer=(.*)" % netid, network_info)[0]
|
| + except IndexError:
|
| + return None
|
| +
|
| +
|
| def get_ifname(self, nic_index=0):
|
| """
|
| Return the ifname of a tap device associated with a NIC.
|
| @@ -1230,7 +1250,10 @@ class VM:
|
| @raise VMMACAddressMissingError: If no MAC address is defined for the
|
| requested NIC
|
| """
|
| - mac = kvm_utils.get_mac_address(self.instance, nic_index)
|
| + nic_name = self.params.objects("nics")[nic_index]
|
| + nic_params = self.params.object_params(nic_name)
|
| + mac = (nic_params.get("nic_mac") or
|
| + kvm_utils.get_mac_address(self.instance, nic_index))
|
| if not mac:
|
| raise VMMACAddressMissingError(nic_index)
|
| return mac
|
|
|