[libvirt] [test-API][PATCH 1/2] Reconnct libvirt after libvirtd restart

In domain_nfs_start case, libvirtd will be restarted during test, which broke existing connection. User need re-init connection in test case, for this: * Using sharedmod data dictionary to store Envparser class in generator. * Do not clear data dictionary in env_inspect, user can update it or framework release it at last. * Using sharemod_init in env_inspect to re-init conn in domain_nfs_start. Signed-off-by: Wayne Sun <gsun@redhat.com> --- repos/sVirt/domain_nfs_start.py | 11 +++++++++-- src/env_inspect.py | 1 - src/generator.py | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/repos/sVirt/domain_nfs_start.py b/repos/sVirt/domain_nfs_start.py index 88d349c..4d48d97 100644 --- a/repos/sVirt/domain_nfs_start.py +++ b/repos/sVirt/domain_nfs_start.py @@ -12,7 +12,7 @@ import sys import libvirt from libvirt import libvirtError - +from src import env_inspect from src import sharedmod from utils import utils from shutil import copy @@ -163,6 +163,8 @@ def domain_nfs_start(params): logger.error("Error: fail to get domain %s xml" % guestname) return 1 + conn.close() + # set env logger.info("prepare the environment") ret = prepare_env(dynamic_ownership, virt_use_nfs, guestname, \ @@ -171,6 +173,11 @@ def domain_nfs_start(params): logger.error("failed to prepare the environment") return 1 + # reconnect libvirt + env = sharedmod.data['env'] + env_inspect.sharemod_init(env, logger) + conn = sharedmod.libvirtobj['conn'] + domobj = conn.lookupByName(guestname) logger.info("begin to test start domain from nfs storage") @@ -283,7 +290,7 @@ def domain_nfs_start(params): logger.error("Error: fail to get domain %s state" % guestname) return 1 - if state != "shutoff": + if state != libvirt.VIR_DOMAIN_SHUTOFF: logger.info("shut down the domain %s" % guestname) try: domobj.destroy() diff --git a/src/env_inspect.py b/src/env_inspect.py index b260ff8..a6dc4b1 100644 --- a/src/env_inspect.py +++ b/src/env_inspect.py @@ -98,7 +98,6 @@ def sharemod_init(env_parser, logger): # initialize conn object in sharedmod sharedmod.libvirtobj.clear() - sharedmod.data.clear() sharedmod.libvirtobj['conn'] = conn return 0 diff --git a/src/generator.py b/src/generator.py index 0cdc9de..f01f2fb 100644 --- a/src/generator.py +++ b/src/generator.py @@ -30,6 +30,7 @@ from testcasexml import xml_file_to_str import env_parser import env_inspect import format +import sharedmod class FuncGen(object): """ To generate a callable testcase""" @@ -56,6 +57,7 @@ class FuncGen(object): self.__case_info_save(activity, testrunid) self.env = env_parser.Envparser("global.cfg") + sharedmod.data['env'] = self.env mapper_obj = mapper.Mapper(activity) case_list = mapper_obj.module_casename_func_map() -- 1.7.1

Only update the expection info when parsing. Signed-off-by: Wayne Sun <gsun@redhat.com> --- src/env_parser.py | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/env_parser.py b/src/env_parser.py index f02af57..ddda727 100644 --- a/src/env_parser.py +++ b/src/env_parser.py @@ -30,7 +30,7 @@ class Envparser(object): self.cfg.read(configfile) else: raise exception.FileDoesNotExist( - "env.conf is not a regular file or nonexist") + "global.conf is not a regular file or nonexist") def has_section(self, section): if self.cfg.has_section(section): @@ -46,7 +46,7 @@ class Envparser(object): return False else: raise exception.SectionDoesNotExist( - "In env.conf, the section %s is nonexist" % section) + "In global.conf, the section %s is nonexist" % section) def sections_list(self): return self.cfg.sections() @@ -56,7 +56,7 @@ class Envparser(object): return self.cfg.options(section) else: raise exception.SectionDoesNotExist( - "In env.conf, the section %s is nonexist" % section) + "In global.conf, the section %s is nonexist" % section) def get_value(self, section, option): if self.has_section: @@ -64,17 +64,17 @@ class Envparser(object): return self.cfg.get(section, option) else: raise exception.OptionDoesNotExist( - "In env.conf, the option %s is nonexist" % option) + "In global.conf, the option %s is nonexist" % option) else: raise exception.SectionDoesNotExist( - "In env.conf, the section %s is nonexist" % section) + "In global.conf, the section %s is nonexist" % section) def get_items(self, section): if self.has_section: return self.cfg.items(section) else: raise exception.SectionDoesNotExist( - "In env.conf, the section %s is nonexist" % section) + "In global.conf, the section %s is nonexist" % section) def add_section(self, section): if self.has_section: @@ -91,10 +91,10 @@ class Envparser(object): return True else: raise exception.OptionDoesNotExist( - "In env.conf, the option %s is nonexist" % option) + "In global.conf, the option %s is nonexist" % option) else: raise exception.SectionDoesNotExist( - "In env.conf, the section %s is nonexist" % section) + "In global.conf, the section %s is nonexist" % section) def remove_section(self, section): if self.has_section: @@ -102,7 +102,7 @@ class Envparser(object): return True else: raise exception.SectionDoesNotExist( - "In env.conf, the section %s is nonexist" % section) + "In global.conf, the section %s is nonexist" % section) def set_value(self, section, option, value): if self.has_section: @@ -111,6 +111,6 @@ class Envparser(object): return True else: raise exception.OptionDoesNotExist( - "In env.conf, the option %s is nonexist" % option) + "In global.conf, the option %s is nonexist" % option) raise exception.SectionDoesNotExist( - "In env.conf, the section %s is nonexist" % section) + "In global.conf, the section %s is nonexist" % section) -- 1.7.1

On 08/06/2012 03:46 PM, Wayne Sun wrote:
Only update the expection info when parsing.
Signed-off-by: Wayne Sun <gsun@redhat.com> --- src/env_parser.py | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/env_parser.py b/src/env_parser.py index f02af57..ddda727 100644 --- a/src/env_parser.py +++ b/src/env_parser.py @@ -30,7 +30,7 @@ class Envparser(object): self.cfg.read(configfile) else: raise exception.FileDoesNotExist( - "env.conf is not a regular file or nonexist") + "global.conf is not a regular file or nonexist")
def has_section(self, section): if self.cfg.has_section(section): @@ -46,7 +46,7 @@ class Envparser(object): return False else: raise exception.SectionDoesNotExist( - "In env.conf, the section %s is nonexist" % section) + "In global.conf, the section %s is nonexist" % section)
def sections_list(self): return self.cfg.sections() @@ -56,7 +56,7 @@ class Envparser(object): return self.cfg.options(section) else: raise exception.SectionDoesNotExist( - "In env.conf, the section %s is nonexist" % section) + "In global.conf, the section %s is nonexist" % section)
def get_value(self, section, option): if self.has_section: @@ -64,17 +64,17 @@ class Envparser(object): return self.cfg.get(section, option) else: raise exception.OptionDoesNotExist( - "In env.conf, the option %s is nonexist" % option) + "In global.conf, the option %s is nonexist" % option) else: raise exception.SectionDoesNotExist( - "In env.conf, the section %s is nonexist" % section) + "In global.conf, the section %s is nonexist" % section)
def get_items(self, section): if self.has_section: return self.cfg.items(section) else: raise exception.SectionDoesNotExist( - "In env.conf, the section %s is nonexist" % section) + "In global.conf, the section %s is nonexist" % section)
def add_section(self, section): if self.has_section: @@ -91,10 +91,10 @@ class Envparser(object): return True else: raise exception.OptionDoesNotExist( - "In env.conf, the option %s is nonexist" % option) + "In global.conf, the option %s is nonexist" % option) else: raise exception.SectionDoesNotExist( - "In env.conf, the section %s is nonexist" % section) + "In global.conf, the section %s is nonexist" % section)
def remove_section(self, section): if self.has_section: @@ -102,7 +102,7 @@ class Envparser(object): return True else: raise exception.SectionDoesNotExist( - "In env.conf, the section %s is nonexist" % section) + "In global.conf, the section %s is nonexist" % section)
def set_value(self, section, option, value): if self.has_section: @@ -111,6 +111,6 @@ class Envparser(object): return True else: raise exception.OptionDoesNotExist( - "In env.conf, the option %s is nonexist" % option) + "In global.conf, the option %s is nonexist" % option) raise exception.SectionDoesNotExist( - "In env.conf, the section %s is nonexist" % section) + "In global.conf, the section %s is nonexist" % section)
It should be global.cfg, but dont' worry let me change them. ACK and pushed. Guannan

On 08/06/2012 03:46 PM, Wayne Sun wrote:
In domain_nfs_start case, libvirtd will be restarted during test, which broke existing connection. User need re-init connection in test case, for this: * Using sharedmod data dictionary to store Envparser class in generator. * Do not clear data dictionary in env_inspect, user can update it or framework release it at last. * Using sharemod_init in env_inspect to re-init conn in domain_nfs_start.
For this case, it's better not to use the connection object offered by framework. The case could create its own connection through case options.
Signed-off-by: Wayne Sun <gsun@redhat.com> --- repos/sVirt/domain_nfs_start.py | 11 +++++++++-- src/env_inspect.py | 1 - src/generator.py | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/repos/sVirt/domain_nfs_start.py b/repos/sVirt/domain_nfs_start.py index 88d349c..4d48d97 100644 --- a/repos/sVirt/domain_nfs_start.py +++ b/repos/sVirt/domain_nfs_start.py @@ -12,7 +12,7 @@ import sys
import libvirt from libvirt import libvirtError - +from src import env_inspect
The env_inspect is framework module. It is not recommanded to use directly in testcase.
from src import sharedmod from utils import utils from shutil import copy @@ -163,6 +163,8 @@ def domain_nfs_start(params): logger.error("Error: fail to get domain %s xml" % guestname) return 1
+ conn.close() + # set env logger.info("prepare the environment") ret = prepare_env(dynamic_ownership, virt_use_nfs, guestname, \ @@ -171,6 +173,11 @@ def domain_nfs_start(params): logger.error("failed to prepare the environment") return 1
+ # reconnect libvirt + env = sharedmod.data['env'] + env_inspect.sharemod_init(env, logger) + conn = sharedmod.libvirtobj['conn']
you could create own connection rather than use the connection object offerred by framework.
+ domobj = conn.lookupByName(guestname)
logger.info("begin to test start domain from nfs storage") @@ -283,7 +290,7 @@ def domain_nfs_start(params): logger.error("Error: fail to get domain %s state" % guestname) return 1
- if state != "shutoff": + if state != libvirt.VIR_DOMAIN_SHUTOFF: logger.info("shut down the domain %s" % guestname) try: domobj.destroy() diff --git a/src/env_inspect.py b/src/env_inspect.py index b260ff8..a6dc4b1 100644 --- a/src/env_inspect.py +++ b/src/env_inspect.py @@ -98,7 +98,6 @@ def sharemod_init(env_parser, logger):
# initialize conn object in sharedmod sharedmod.libvirtobj.clear() - sharedmod.data.clear() sharedmod.libvirtobj['conn'] = conn return 0
diff --git a/src/generator.py b/src/generator.py index 0cdc9de..f01f2fb 100644 --- a/src/generator.py +++ b/src/generator.py @@ -30,6 +30,7 @@ from testcasexml import xml_file_to_str import env_parser import env_inspect import format +import sharedmod
class FuncGen(object): """ To generate a callable testcase""" @@ -56,6 +57,7 @@ class FuncGen(object): self.__case_info_save(activity, testrunid)
self.env = env_parser.Envparser("global.cfg") + sharedmod.data['env'] = self.env
mapper_obj = mapper.Mapper(activity) case_list = mapper_obj.module_casename_func_map()

On 08/07/2012 09:15 PM, Guannan Ren wrote:
On 08/06/2012 03:46 PM, Wayne Sun wrote:
In domain_nfs_start case, libvirtd will be restarted during test, which broke existing connection. User need re-init connection in test case, for this: * Using sharedmod data dictionary to store Envparser class in generator. * Do not clear data dictionary in env_inspect, user can update it or framework release it at last. * Using sharemod_init in env_inspect to re-init conn in domain_nfs_start.
For this case, it's better not to use the connection object offered by framework. The case could create its own connection through case options. Yes, the first thought is to create the connection in the case, but since multiple cases have this problem and the get connection code is reusable, so i directly using the sharemod_init function in env_inspect. This is not right, it's better create a shared get_conn function in utils for both framework and testcase. Then, env_inspect could use it and also testcases have the reconnect problem. I'll send v2 for this, thx!
Wayne Sun 2012-08-08
Signed-off-by: Wayne Sun <gsun@redhat.com> --- repos/sVirt/domain_nfs_start.py | 11 +++++++++-- src/env_inspect.py | 1 - src/generator.py | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/repos/sVirt/domain_nfs_start.py b/repos/sVirt/domain_nfs_start.py index 88d349c..4d48d97 100644 --- a/repos/sVirt/domain_nfs_start.py +++ b/repos/sVirt/domain_nfs_start.py @@ -12,7 +12,7 @@ import sys import libvirt from libvirt import libvirtError - +from src import env_inspect
The env_inspect is framework module. It is not recommanded to use directly in testcase.
from src import sharedmod from utils import utils from shutil import copy @@ -163,6 +163,8 @@ def domain_nfs_start(params): logger.error("Error: fail to get domain %s xml" % guestname) return 1 + conn.close() + # set env logger.info("prepare the environment") ret = prepare_env(dynamic_ownership, virt_use_nfs, guestname, \ @@ -171,6 +173,11 @@ def domain_nfs_start(params): logger.error("failed to prepare the environment") return 1 + # reconnect libvirt + env = sharedmod.data['env'] + env_inspect.sharemod_init(env, logger) + conn = sharedmod.libvirtobj['conn']
you could create own connection rather than use the connection object offerred by framework.
+ domobj = conn.lookupByName(guestname) logger.info("begin to test start domain from nfs storage") @@ -283,7 +290,7 @@ def domain_nfs_start(params): logger.error("Error: fail to get domain %s state" % guestname) return 1 - if state != "shutoff": + if state != libvirt.VIR_DOMAIN_SHUTOFF: logger.info("shut down the domain %s" % guestname) try: domobj.destroy() diff --git a/src/env_inspect.py b/src/env_inspect.py index b260ff8..a6dc4b1 100644 --- a/src/env_inspect.py +++ b/src/env_inspect.py @@ -98,7 +98,6 @@ def sharemod_init(env_parser, logger): # initialize conn object in sharedmod sharedmod.libvirtobj.clear() - sharedmod.data.clear() sharedmod.libvirtobj['conn'] = conn return 0 diff --git a/src/generator.py b/src/generator.py index 0cdc9de..f01f2fb 100644 --- a/src/generator.py +++ b/src/generator.py @@ -30,6 +30,7 @@ from testcasexml import xml_file_to_str import env_parser import env_inspect import format +import sharedmod class FuncGen(object): """ To generate a callable testcase""" @@ -56,6 +57,7 @@ class FuncGen(object): self.__case_info_save(activity, testrunid) self.env = env_parser.Envparser("global.cfg") + sharedmod.data['env'] = self.env mapper_obj = mapper.Mapper(activity) case_list = mapper_obj.module_casename_func_map()
participants (2)
-
Guannan Ren
-
Wayne Sun