On 03/21/2012 08:46 PM, Peter Krempa wrote:
For some tests it's not needed to ping the guest in the startup process.
This patch adds a flag to the start and destroy test to skip such
attempts (that consume a lot of time)
---
repos/domain/destroy.py | 54 ++
repos/domain/start.py | 50 --
2 files changed, 54 insertions(+), 50 deletions(-)
diff --git a/repos/domain/destroy.py b/repos/domain/destroy.py
index f98b602..12399d6 100644
--- a/repos/domain/destroy.py
+++ b/repos/domain/destroy.py
@@ -50,7 +50,10 @@ def destroy(params):
{'guestname': guestname}
logger -- an object of utils/Python/log.py
- guestname -- same as the domain name
+ guestname -- the domain name
+ flags -- optional arguments:
+ noping: Don't do the ping test
+
Return 0 on SUCCESS or 1 on FAILURE
@@ -62,6 +65,7 @@ def destroy(params):
if params_check_result:
return 1
guestname = params['guestname']
+flags = params['flags']
The 'flags' is optional, then we have to check if the
dictionary of params has key or not
if params.has_key('flags'):
...
otherwise, it will report KeyError:
If 'flags' is mandatory, it'd better to to check it in
check_params function.
# Connect to local hypervisor connection URI
util = utils.Utils()
@@ -73,18 +77,19 @@ def destroy(params):
dom_obj = domainAPI.DomainAPI(virconn)
dom_name_list = dom_obj.get_list()
if guestname not in dom_name_list:
-logger.error(guest %s doesn't exist or not be running. % guestname)
+logger.error(guest %s doesn't exist or isn't running. % guestname)
Thanks
conn.close()
logger.info(closed hypervisor connection)
return 1
timeout = 60
logger.info('destroy domain')
-# Get domain ip
-mac = util.get_dom_mac_addr(guestname)
-logger.info(get ip by mac address)
-ip = util.mac_to_ip(mac, 180)
-logger.info(the ip address of guest is %s % ip)
+if not(noping in flags):
+# Get domain ip
+mac = util.get_dom_mac_addr(guestname)
+logger.info(get ip by mac address)
+ip = util.mac_to_ip(mac, 180)
+logger.info(the ip address of guest is %s % ip)
# Destroy domain
try:
@@ -93,30 +98,31 @@ def destroy(params):
except LibvirtAPI, e:
logger.error(API error message: %s, error code is %s % \
(e.response()['message'], e.response()['code']))
-logger.error(fail to destroy domain)
+logger.error(failed to destroy domain)
thanks to correct it.
return 1
finally:
conn.close()
logger.info(closed hypervisor connection)
# Check domain status by ping ip
-while timeout:
-time.sleep(10)
-timeout -= 10
-logger.info(str(timeout) + s left)
-
-logger.info('ping guest')
-
-if util.do_ping(ip, 30):
-logger.error('The guest is still active, IP: ' + str(ip))
+if not noping in flags:
+while timeout:
+time.sleep(10)
+timeout -= 10
+logger.info(str(timeout) + s left)
+
+logger.info('ping guest')
+
+if util.do_ping(ip, 30):
+logger.error('The guest is still active, IP: ' + str(ip))
+return 1
+else:
+logger.info(domain %s was destroyed successfully % guestname)
+break
+
+if timeout= 0:
+logger.error(the domain couldn't be destroyed within 60 seconds.)
return 1
-else:
-logger.info(domain %s is destroied successfully % guestname)
-break
-
-if timeout= 0:
-logger.error(the domain couldn't be destroied within 60 secs.)
-return 1
return 0
diff --git a/repos/domain/start.py b/repos/domain/start.py
index 39ac47f..483ea7a 100644
--- a/repos/domain/start.py
+++ b/repos/domain/start.py
@@ -66,7 +66,7 @@ def start(params):
logger -- an object of utils/Python/log.py
mandatory arguments : guestname -- same as the domain name
- optional arguments : flags -- domain create flagsnone|start_paused
+ optional arguments : flags -- domain create
flagsnone|start_paused|noping
Return 0 on SUCCESS or 1 on FAILURE
@@ -75,13 +75,11 @@ def start(params):
check_params(params)
domname = params['guestname']
logger = params['logger']
+flags = params['flags']
Yes, please notice this like above.
It seems that you want flags to be mandatory in the
following code.
Add checking for it in check_params()
Guannan Ren
--
libvir-list mailing list
libvir-list@redhat.com