def __setstate__(self, state): """Actualize instance from state""" # virsh is it's own dict of init params self.virsh = virsh.Virsh(**state['virsh']) # already used it's own get/sets state methods when unpickling state self.command = state['command'] # Recreate SpecificServiceManager from the init args self._run = state['run'] self.service = SpecificServiceManager(self.service_name, run=self._run) self._bind_service_commands()
def __init__(self, params, service_name, uri='lxc:///'): """Initialize connection to sandbox service with name and parameters""" # Intended workflow is: # Use virt-sandbox-service for create/destroy # Use service/systemd for runtime management # Use virsh for list/edit/modify manipulation self.virsh = virsh.Virsh(uri=uri, ignore_status=True) self.command = lvsb_base.SandboxCommandBase(params, service_name) self.command.BINARY_PATH_PARAM = 'virt_sandbox_service_binary' self.command.add_optarg('--connect', uri) # SpecificServiceManager is not pickleable, save init args self._run = utils.run self.service = SpecificServiceManager(self.service_name, run=self._run) # make self.start() --> self.service.start() self._bind_service_commands()
def run(test, params, env): """ Logs guest's hostname. 1) Decide whether use host/guest 2) Check current service status 3) Start (Stop) $service 4) Check status of $service 5) Stop (Start) $service 6) Check service status :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ if params.get('test_on_guest') == "yes": # error.context() is common method to log test steps used to verify # what exactly was tested. error.context("Using guest.", logging.info) vm = env.get_vm(params["main_vm"]) session = vm.wait_for_login() # RemoteRunner is object, which simulates the utils.run() behavior # on remote consoles runner = remote.RemoteRunner(session=session).run else: error.context("Using host", logging.info) runner = utils.run error.context("Initialize service manager", logging.info) service = SpecificServiceManager(params["test_service"], runner) error.context("Testing service %s" % params["test_service"], logging.info) original_status = service.status() logging.info("Original status=%s", original_status) if original_status is True: service.stop() time.sleep(5) if service.status() is not False: logging.error("Fail to stop service") service.start() raise error.TestFail("Fail to stop service") service.start() else: service.start() time.sleep(5) if service.status() is not True: logging.error("Fail to start service") service.stop() raise error.TestFail("Fail to start service") service.start() time.sleep(5) if not service.status() is original_status: raise error.TestFail("Fail to restore original status of the %s " "service" % params["test_service"])