From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lucas Meneghel Rodrigues Subject: [PATCH 04/18] KVM test: Add a get_ifname function Date: Tue, 14 Sep 2010 19:25:29 -0300 Message-ID: <1284503143-5993-5-git-send-email-lmr@redhat.com> References: <1284503143-5993-1-git-send-email-lmr@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: autotest@test.kernel.org Return-path: In-Reply-To: <1284503143-5993-1-git-send-email-lmr@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: autotest-bounces@test.kernel.org Errors-To: autotest-bounces@test.kernel.org List-Id: kvm.vger.kernel.org It's clearer to use 'nic_mode + nic_index + vnc_port' than 'tap0', It's also unique for one guest. Signed-off-by: Amos Kong --- client/tests/kvm/kvm_vm.py | 21 ++++++++++++++++++++- 1 files changed, 20 insertions(+), 1 deletions(-) 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. -- 1.7.2.2