From patchwork Mon Sep 27 22:43:50 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 213622 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o8RMforO032214 for ; Mon, 27 Sep 2010 22:41:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932638Ab0I0Wl2 (ORCPT ); Mon, 27 Sep 2010 18:41:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:9268 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760344Ab0I0WlU (ORCPT ); Mon, 27 Sep 2010 18:41:20 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o8RMf9d8018164 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 27 Sep 2010 18:41:09 -0400 Received: from virtlab105.virt.bos.redhat.com (virtlab105.virt.bos.redhat.com [10.16.72.124]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o8RMf33r003834; Mon, 27 Sep 2010 18:41:08 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, mst@redhat.com, akong@redhat.com, jasowang@redhat.com, psuriset@linux.vnet.ibm.com, mgoldish@redhat.com, Lucas Meneghel Rodrigues Subject: [PATCH 04/18] KVM test: Add a get_ifname function Date: Mon, 27 Sep 2010 18:43:50 -0400 Message-Id: <1285627444-2732-5-git-send-email-lmr@redhat.com> In-Reply-To: <1285627444-2732-1-git-send-email-lmr@redhat.com> References: <1285627444-2732-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Mon, 27 Sep 2010 22:41:54 +0000 (UTC) diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py index 13eaac1..a473bb4 100755 --- a/client/tests/kvm/kvm_vm.py +++ b/client/tests/kvm/kvm_vm.py @@ -426,7 +426,7 @@ class VM: if tftp: tftp = kvm_utils.get_path(root_dir, tftp) qemu_cmd += add_net(help, vlan, nic_params.get("nic_mode", "user"), - nic_params.get("nic_ifname"), + self.get_ifname(vlan), script, downscript, tftp, nic_params.get("bootp"), redirs, self.netdev_id[vlan]) @@ -959,6 +959,25 @@ class VM: return self.redirs.get(port) + def get_ifname(self, nic_index=0): + """ + Return the ifname of tap device for the guest nic. + + The vnc_port is unique for each VM, nic_index is unique for each nic + of one VM, it can avoid repeated ifname. + + @param nic_index: Index of the NIC + """ + nics = kvm_utils.get_sub_dict_names(self.params, "nics") + nic_name = nics[nic_index] + nic_params = kvm_utils.get_sub_dict(self.params, nic_name) + if nic_params.get("nic_ifname"): + return nic_params.get("nic_ifname") + else: + return "%s_%s_%s" % (nic_params.get("nic_model"), + nic_index, self.vnc_port) + + def get_mac_address(self, nic_index=0): """ Return the macaddr of guest nic.