On 09/28/2015 05:45 PM, Shanzhi Yu wrote:
Signed-off-by: Shanzhi Yu <shyu(a)redhat.com>
---
cases/linux_domain.conf | 12 +++++++
global.cfg | 8 +++--
repos/domain/get_guest_network_info.py | 66 ++++++++++++++++++++++++++++++++++
3 files changed, 84 insertions(+), 2 deletions(-)
create mode 100644 repos/domain/get_guest_network_info.py
diff --git a/cases/linux_domain.conf b/cases/linux_domain.conf
index 8440c61..5b216f9 100644
--- a/cases/linux_domain.conf
+++ b/cases/linux_domain.conf
@@ -66,6 +66,18 @@ domain:set_guest_time
flags
sync
+domain:get_guest_network_info
+ guestname
+ $defaultname
+ flags
+ lease
+
+domain:get_guest_network_info
+ guestname
+ $defaultname
+ flags
+ agent
+
virconn:connection_getAllDomainStats
stats
state|cpu|balloon|vcpu|interface|block
diff --git a/global.cfg b/global.cfg
index 56677a5..1b72119 100644
--- a/global.cfg
+++ b/global.cfg
@@ -44,6 +44,8 @@ rhel6u1_i386 = http://
rhel6u1_x86_64 = http://
rhel6u2_i386 = http://
rhel6u2_x86_64 = http://
+rhel7u1_x86_64 = http://
+rhel7u2_x86_64 = http://
fedora12_i386 = http://
fedora12_x86_64 = http://
win2008_i386 = http://
@@ -70,6 +72,8 @@ rhel6_i386_http_ks = http://
rhel6_x86_64_http_ks = http://
rhel6u2_i386_http_ks = http://
rhel6u2_x86_64_http_ks = kickstart.cfg
+rhel7u1_x86_64_http_ks = http://
+rhel7u2_x86_64_http_ks = http://
fedora12_i386_http_ks = http://
fedora12_x86_64_http_ks = http://
@@ -97,7 +101,7 @@ sourcepath = /media/share
# also exercise DNS resolution
#
[other]
-wget_url = http://
+wget_url =
http://libvirt.org/index.html
#
# The variables section is a set of variables used by the
@@ -127,7 +131,7 @@ defaulthv = kvm
defaultname = libvirt_test_api
# default os version to use for installing a new guest
# the value of it is the first part of 'rhel6u2_x86_64' in [guest] section
above
-defaultos = rhel6u2
+defaultos = rhel7u2
# default architecture to use for installing a new guest
defaultarch = x86_64
# default the number of vcpu to use for defining or installing a guest
diff --git a/repos/domain/get_guest_network_info.py
b/repos/domain/get_guest_network_info.py
new file mode 100644
index 0000000..35bba3b
--- /dev/null
+++ b/repos/domain/get_guest_network_info.py
@@ -0,0 +1,66 @@
+#!/usr/bin/python
+
+import libvirt
+from libvirt import libvirtError
+from src import sharedmod
+
+required_params = ('guestname', 'flags',)
+optional_params = {}
+
+def check_guest_status(domobj):
+ """check guest current status
+ """
+ state = domobj.info()[0]
+ if state == libvirt.VIR_DOMAIN_SHUTOFF or \
+ state == libvirt.VIR_DOMAIN_SHUTDOWN:
+ return False
+ else:
+ return True
+
+def get_guest_network_info(params):
+ """get guest network interface info
+ """
+
+ logger = params['logger']
+ guestname = params['guestname']
+ flags = params['flags']
+
+ conn = sharedmod.libvirtobj['conn']
+
+ domobj = conn.lookupByName(guestname)
+
+ flags = params['flags']
+ logger.info("The flags are %s" % flags)
+ flags_string = flags.split("|")
+ flags = 0
+
+ for flag in flags_string:
+ if flag == 'lease':
+ flags |= libvirt.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE
+ elif flag == 'agent':
+ flags |= libvirt.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT
+ else:
+ logger.error("unknow flags")
+ return 1
+
+ logger.info("the given flags is %d" % flags)
+
+ # Check domain status
+ if check_guest_status(domobj):
+ logger.info("Guest is running")
+ else:
+ logger.error("Guest is shut off status")
+ return 1
+
+ try:
+ info = domobj.interfaceAddresses(flags)
+ logger.info("get guest interface info")
+
Hi shyu
There should be two different method of checking flags "lease" and
"agent"
It is invalid if only check the domain status
Expect your V2 patch cover it
Thanks
Hongming
+ except libvirtError, e:
+ logger.error("API error message: %s, error code is %s" \
+ % (e.message, e.get_error_code()))
+ return 1
+
+ return 0
+
+