From patchwork Fri Sep 21 09:31:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiri Zupka X-Patchwork-Id: 1490791 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 6892FDF28C for ; Fri, 21 Sep 2012 09:32:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932829Ab2IUJcI (ORCPT ); Fri, 21 Sep 2012 05:32:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47549 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932817Ab2IUJcD (ORCPT ); Fri, 21 Sep 2012 05:32:03 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8L9VfCf027947 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 21 Sep 2012 05:31:41 -0400 Received: from jzupka-pc.local.com (dhcp-27-230.brq.redhat.com [10.34.27.230]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q8L9VYhs005668; Fri, 21 Sep 2012 05:31:40 -0400 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C5=BDupka?= To: autotest@test.kernel.org, kvm@vger.kernel.org, kvm-autotest@redhat.com, lmr@redhat.com, ldoktor@redhat.com, jzupka@redhat.com Subject: [Autotest][PATCH 3/5] virt: Adds functionality for vms. Date: Fri, 21 Sep 2012 11:31:26 +0200 Message-Id: <1348219888-23436-4-git-send-email-jzupka@redhat.com> In-Reply-To: <1348219888-23436-1-git-send-email-jzupka@redhat.com> References: <1348219888-23436-1-git-send-email-jzupka@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Allow creating of machine with tap devices which are not connected to bridge. Add function for fill virtnet object with address. Signed-off-by: Ji?í Župka --- client/tests/virt/virttest/kvm_vm.py | 9 +++++---- client/tests/virt/virttest/utils_misc.py | 3 ++- client/tests/virt/virttest/virt_vm.py | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/client/tests/virt/virttest/kvm_vm.py b/client/tests/virt/virttest/kvm_vm.py index 247f0eb..d3b4ede 100644 --- a/client/tests/virt/virttest/kvm_vm.py +++ b/client/tests/virt/virttest/kvm_vm.py @@ -949,7 +949,7 @@ class VM(virt_vm.BaseVM): qemu_cmd += add_name(hlp, name) # no automagic devices please defaults = params.get("defaults", "no") - if has_option(hlp,"nodefaults") and defaults != "yes": + if has_option(hlp, "nodefaults") and defaults != "yes": qemu_cmd += " -nodefaults" # Add monitors for monitor_name in params.objects("monitors"): @@ -1065,7 +1065,7 @@ class VM(virt_vm.BaseVM): for nic in vm.virtnet: # setup nic parameters as needed - nic = vm.add_nic(**dict(nic)) # add_netdev if netdev_id not set + nic = vm.add_nic(**dict(nic)) # add_netdev if netdev_id not set # gather set values or None if unset vlan = int(nic.get('vlan')) netdev_id = nic.get('netdev_id') @@ -2064,7 +2064,7 @@ class VM(virt_vm.BaseVM): nic.set_if_none('nettype', 'bridge') if nic.nettype == 'bridge': # implies tap # destination is required, hard-code reasonable default if unset - nic.set_if_none('netdst', 'virbr0') + # nic.set_if_none('netdst', 'virbr0') # tapfd allocated/set in activate because requires system resources nic.set_if_none('tapfd_id', utils_misc.generate_random_id()) elif nic.nettype == 'user': @@ -2142,7 +2142,8 @@ class VM(virt_vm.BaseVM): error.context("Raising bridge for " + msg_sfx + attach_cmd, logging.debug) # assume this will puke if netdst unset - utils_misc.add_to_bridge(nic.ifname, nic.netdst) + if not nic.netdst is None: + utils_misc.add_to_bridge(nic.ifname, nic.netdst) elif nic.nettype == 'user': attach_cmd += " user,name=%s" % nic.ifname else: # unsupported nettype diff --git a/client/tests/virt/virttest/utils_misc.py b/client/tests/virt/virttest/utils_misc.py index e416551..b4799e7 100644 --- a/client/tests/virt/virttest/utils_misc.py +++ b/client/tests/virt/virttest/utils_misc.py @@ -719,7 +719,8 @@ class VirtIface(PropCan): Networking information for single guest interface and host connection. """ - __slots__ = ['nic_name', 'mac', 'nic_model', 'ip', 'nettype', 'netdst'] + __slots__ = ['nic_name', 'g_nic_name', 'mac', 'nic_model', 'ip', + 'nettype', 'netdst'] # Make sure first byte generated is always zero and it follows # the class definition. This helps provide more predictable # addressing while avoiding clashes between multiple NICs. diff --git a/client/tests/virt/virttest/virt_vm.py b/client/tests/virt/virttest/virt_vm.py index 79dd08b..ff6a0f7 100644 --- a/client/tests/virt/virttest/virt_vm.py +++ b/client/tests/virt/virttest/virt_vm.py @@ -518,6 +518,7 @@ class BaseVM(object): # Make sure the IP address is assigned to one or more macs # for this guest macs = self.virtnet.mac_list() + if not utils_misc.verify_ip_address_ownership(arp_ip, macs): raise VMAddressVerificationError(nic.mac, arp_ip) logging.debug('Found/Verified IP %s for VM %s NIC %s' % ( @@ -525,6 +526,25 @@ class BaseVM(object): return arp_ip + def fill_addrs(self, addrs): + """ + Fill VM's nic address to the virtnet structure based on VM's address + structure addrs. + + @param addrs: Dict of interfaces and address + {"if_name":{"mac":['addrs',], + "ipv4":['addrs',], + "ipv6":['addrs',]}, + ...} + """ + for virtnet in self.virtnet: + for iface_name, iface in addrs.iteritems(): + if virtnet.mac in iface["mac"]: + virtnet.ip = {"ipv4": iface["ipv4"], + "ipv6": iface["ipv6"]} + virtnet.g_nic_name = iface_name + + def get_port(self, port, nic_index=0): """ Return the port in host space corresponding to port in guest space.