Exemplo n.º 1
0
 def condition():
     try:
         m.init_connection(timeout=1)
         return True
     except:
         log_exc_traceback()
         return False
Exemplo n.º 2
0
    def _run(self):
        os.setpgrp()
        signal.signal(signal.SIGHUP, self._sig_ign)
        signal.signal(signal.SIGINT, self._sig_ign)
        signal.signal(signal.SIGTERM, self._sig_ign)

        self._connection_pipe = self._write_pipe

        self._log_ctl.disable_logging()
        self._log_ctl.set_connection(self._connection_pipe)

        result = {}
        try:
            self._cmd_cls.run()
        except (KeyboardInterrupt, SystemExit):
            pass
        except:
            log_exc_traceback()
            type, value, tb = sys.exc_info()
            data = {"Exception": "%s" % value}
            self._cmd_cls.set_fail(data)
        finally:
            res_data = self._cmd_cls.get_result()
            result["type"] = "result"
            result["cmd_id"] = self._id
            result["result"] = res_data

        send_data(self._write_pipe, result)
        self._write_pipe.close()
Exemplo n.º 3
0
Arquivo: Job.py Projeto: omaciel/lnst
    def _run(self):
        self._parent_pipe.close()

        os.setpgrp()
        signal.signal(signal.SIGHUP, signal.SIG_DFL)
        signal.signal(signal.SIGINT, signal.SIG_DFL)
        signal.signal(signal.SIGTERM, signal.SIG_DFL)

        self._log_ctl.disable_logging()
        self._log_ctl.set_connection(self._child_pipe)

        result = {}
        try:
            self._job_cls.run()
            job_result = self._job_cls.get_result()
        except Exception as e:
            log_exc_traceback()
            job_result = {}
            job_result["passed"] = False
            job_result["type"] = "exception"
            job_result["res_data"] = self._job_cls.get_result()
            job_result["res_data"]["exception"] = e
        finally:
            result["type"] = "job_finished"
            result["job_id"] = self._id
            result["result"] = job_result

        send_data(self._child_pipe, result)
        self._child_pipe.close()
Exemplo n.º 4
0
    def _run(self):
        os.setpgrp()
        signal.signal(signal.SIGHUP, self._sig_ign)
        signal.signal(signal.SIGINT, self._sig_ign)
        signal.signal(signal.SIGTERM, self._sig_ign)

        self._connection_pipe = self._write_pipe

        self._log_ctl.disable_logging()
        self._log_ctl.set_connection(self._connection_pipe)

        result = {}
        try:
            self._cmd_cls.run()
        except (KeyboardInterrupt, SystemExit):
            pass
        except:
            log_exc_traceback()
            type, value, tb = sys.exc_info()
            data = {"Exception": "%s" % value}
            self._cmd_cls.set_fail(data)
        finally:
            res_data = self._cmd_cls.get_result()
            result["type"] = "result"
            result["cmd_id"] = self._id
            result["result"] = res_data

        send_data(self._write_pipe, result)
        self._write_pipe.close()
Exemplo n.º 5
0
    def _cleanup_slaves(self):
        if self._machines == None:
            return

        for m_id, machine in list(self._machines.items()):
            try:
                machine.cleanup()
            except:
                #TODO report errors during deconfiguration as FAIL!!
                log_exc_traceback()
            finally:
                machine.stop_recipe()
                for dev in list(machine._device_database.values()):
                    if isinstance(dev, VirtualDevice):
                        dev._destroy()

                #clean-up slave logger
                self._log_ctl.remove_slave(m_id)
                machine.set_mapped(False)

        self._machines.clear()

        # remove dynamically created bridges
        for bridge in list(self._network_bridges.values()):
            bridge.cleanup()
        self._network_bridges = {}
Exemplo n.º 6
0
Arquivo: Job.py Projeto: jbenc/lnst
    def _run(self):
        os.setpgrp()
        signal.signal(signal.SIGHUP, signal.SIG_DFL)
        signal.signal(signal.SIGINT, signal.SIG_DFL)
        signal.signal(signal.SIGTERM, signal.SIG_DFL)

        self._log_ctl.disable_logging()
        self._log_ctl.set_connection(self._child_pipe)

        result = {}
        try:
            self._job_cls.run()
        except:
            log_exc_traceback()
            type, value, tb = sys.exc_info()
            data = {"Exception": "%s" % value}
            # self._job_cls.set_fail(data)
        finally:
            res_data = self._job_cls.get_result()
            result["type"] = "job_finished"
            result["job_id"] = self._id
            result["result"] = res_data

        send_data(self._child_pipe, result)
        self._child_pipe.close()
Exemplo n.º 7
0
    def _process_msg(self, msg):
        if msg["type"] == "command":
            method = getattr(self._methods, msg["method_name"], None)
            if method != None:
                try:
                    result = method(*msg["args"])
                except:
                    log_exc_traceback()
                    type, value, tb = sys.exc_info()
                    exc_trace = ''.join(traceback.format_exception(type,
                                                                   value, tb))
                    response = {"type": "exception", "Exception": exc_trace}

                    self._server_handler.send_data_to_ctl(response)
                    return

                if result != None:
                    response = {"type": "result", "result": result}
                    self._server_handler.send_data_to_ctl(response)
            else:
                err = "Method '%s' not supported." % msg["method_name"]
                response = {"type": "error", "err": err}
                self._server_handler.send_data_to_ctl(response)
        elif msg["type"] == "log":
            logger = logging.getLogger()
            record = logging.makeLogRecord(msg["record"])
            logger.handle(record)
        elif msg["type"] == "exception":
            if msg["cmd_id"] != None:
                logging.debug("Recieved an exception from command with id: %s"
                                % msg["cmd_id"])
            else:
                logging.debug("Recieved an exception from foreground command")
            logging.error(msg["Exception"])
            cmd = self._cmd_context.get_cmd(msg["cmd_id"])
            cmd.join()
            self._cmd_context.del_cmd(cmd)
            self._server_handler.send_data_to_ctl(msg)
        elif msg["type"] == "result":
            if msg["cmd_id"] == None:
                del msg["cmd_id"]
                self._server_handler.send_data_to_ctl(msg)
                cmd = self._cmd_context.get_cmd(None)
                cmd.join()
                self._cmd_context.del_cmd(cmd)
            else:
                cmd = self._cmd_context.get_cmd(msg["cmd_id"])
                cmd.join()
                del msg["cmd_id"]

                if cmd.finished():
                    self._server_handler.send_data_to_ctl(msg)
                    self._cmd_context.del_cmd(cmd)
                else:
                    cmd.set_result(msg["result"])
        else:
            raise Exception("Recieved unknown command")

        pipes = self._cmd_context.get_read_pipes()
        self._server_handler.update_connections(pipes)
Exemplo n.º 8
0
 def _create(self):
     self._update_attr(self._link_type, "IFLA_LINKINFO", "IFLA_INFO_KIND")
     try:
         self._nl_link_sync("add", bulk=True)
     except Exception as e:
         log_exc_traceback()
         raise DeviceConfigError("Creating link {} failed: {}".format(
             self.name, str(e)))
Exemplo n.º 9
0
 def obj_setattr(self, obj_ref, name, value):
     try:
         obj = self._dynamic_objects[obj_ref]
         return setattr(obj, name, value)
     except LnstError:
         raise
     except Exception as exc:
         log_exc_traceback()
         raise LnstError(exc)
Exemplo n.º 10
0
Arquivo: Job.py Projeto: omaciel/lnst
 def run(self):
     try:
         self._result["passed"] = self._what["module"].run()
         self._result["res_data"] = self._what["module"]._get_res_data()
     except Exception as e:
         log_exc_traceback()
         self._result["passed"] = False
         self._result["type"] = "module_exception"
         self._result["res_data"] = {"exception": e}
Exemplo n.º 11
0
 def obj_method(self, obj_ref, name, args, kwargs):
     try:
         obj = self._dynamic_objects[obj_ref]
         method = getattr(obj, name)
         return method(*args, **kwargs)
     except LnstError:
         raise
     except Exception as exc:
         log_exc_traceback()
         raise LnstError(exc)
Exemplo n.º 12
0
    def run(self, recipe, **kwargs):
        """Execute the provided Recipe

        This method takes care of both finding Agent hosts matching the Recipe
        requirements, provisioning them and calling the *test* method of the
        Recipe object with proper references to the mapped Hosts

        :param recipe:
            an instantiated Recipe object
        :type recipe: :py:class:`lnst.Controller.Recipe.BaseRecipe`

        :param kwargs:
            optional keyword arguments passed to the configured Mapper
        :type kwargs: Dict[str, Any]
        """
        if not isinstance(recipe, BaseRecipe):
            raise ControllerError(
                "recipe argument must be a BaseRecipe instance.")

        recipe_ctl = RecipeControl(self, recipe)
        recipe._set_ctl(recipe_ctl)

        req = recipe.req

        self._mapper.set_pools_manager(self._pools)
        self._mapper.set_requirements(req._to_dict())

        i = 0
        for match in self._mapper.matches(**kwargs):
            self._log_ctl.set_recipe(recipe.__class__.__name__,
                                     expand="match_%d" % i)
            i += 1

            for line in format_match_description(match).split('\n'):
                logging.info(line)
            try:
                self._map_match(match, req, recipe)
                recipe._init_run(
                    RecipeRun(recipe,
                              match,
                              log_dir=self._log_ctl.get_recipe_log_path(),
                              log_list=self._log_ctl.get_recipe_log_list()))
                recipe.test()
            except Exception as exc:
                recipe.current_run.exception = exc
                logging.error(
                    "Recipe execution terminated by unexpected exception")
                log_exc_traceback()
                raise
            finally:
                self._cleanup_agents()
Exemplo n.º 13
0
    def test_wide_deconfiguration(self, config):
        try:
            self.guest_deconfigure(config.guest)
        except:
            log_exc_traceback()

        try:
            config.dut.host.run("ovs-ofctl del-flows br0")
            for vm_port, port_id in config.dut.vm_ports:
                config.dut.host.run("ovs-vsctl del-port br0 {}".format(vm_port))
            for dpdk_port, port_id in config.dut.dpdk_ports:
                config.dut.host.run("ovs-vsctl del-port br0 {}".format(dpdk_port))
            config.dut.host.run("ovs-vsctl del-br br0")
            config.dut.host.run("service openvswitch restart")

            self.base_dpdk_deconfiguration(config.dut, ["openvswitch"])
        except:
            log_exc_traceback()

        try:
            #  returning the guest to the original running state
            self.shutdown_guest(config.guest)
            config.guest.virtctl.vm_start(config.guest.name)
        except:
            log_exc_traceback()

        try:
            for nic in config.generator.nics:
                config.generator.host.run(
                    "driverctl unset-override {}".format(nic.bus_info))

            config.generator.host.run("service irqbalance start")
        except:
            log_exc_traceback()
Exemplo n.º 14
0
    def run(self):
        while not self._finished:
            if self._server_handler.get_ctl_sock() == None:
                self._log_ctl.cancel_connection()
                try:
                    logging.info("Waiting for connection.")
                    self._server_handler.accept_connection()
                except (socket.error, SecSocketException):
                    log_exc_traceback()
                    continue
                self._log_ctl.set_connection(
                    self._server_handler.get_ctl_sock())

            msgs = self._server_handler.get_messages()

            for msg in msgs:
                self._process_msg(msg[1])

        self._methods.machine_cleanup()
Exemplo n.º 15
0
    def run(self, recipe, **kwargs):
        """Execute the provided Recipe

        This method takes care of both finding a Slave hosts matching the Recipe
        requirements, provisioning them and calling the 'test' method of the
        Recipe object with proper references to the mapped Hosts

        Args:
            recipe -- an instantiated Recipe object (isinstance BaseRecipe)
            kwargs -- optional keyword arguments passed to the configured Mapper
        """
        if not isinstance(recipe, BaseRecipe):
            raise ControllerError(
                "recipe argument must be a BaseRecipe instance.")

        req = recipe.req

        self._mapper.set_pools(self._pools.get_pools())
        self._mapper.set_requirements(req._to_dict())

        i = 0
        for match in self._mapper.matches(**kwargs):
            self._log_ctl.set_recipe(recipe.__class__.__name__,
                                     expand="match_%d" % i)
            i += 1

            self._print_match_description(match)
            self._map_match(match, req)
            try:
                recipe._set_hosts(self._hosts)
                recipe.test()
            except Exception as exc:
                logging.error(
                    "Recipe execution terminated by unexpected exception")
                log_exc_traceback()
                raise
            finally:
                recipe._set_hosts(None)
                for machine in self._machines.values():
                    machine.restore_system_config()
                self._cleanup_slaves()
Exemplo n.º 16
0
    def _ipr_wrapper(self, obj_name, op_name, *args, **kwargs):
        pretty_attrs = pprint.pformat({"args": args, "kwargs": kwargs})
        logging.debug(
            "Performing pyroute.IPRoute().{}({}, *args, **kwargs)".format(
                obj_name, op_name))
        logging.debug("{}".format(pretty_attrs))

        ret_val = None
        with pyroute2.IPRoute() as ipr:
            try:
                obj = getattr(ipr, obj_name)
                if op_name is not None:
                    ret_val = obj(op_name, *args, **kwargs)
                else:
                    ret_val = obj(*args, **kwargs)
                self._if_manager.rescan_devices()
            except Exception as e:
                log_exc_traceback()
                raise DeviceConfigError(
                    "Object {} operation {} on link {} failed: {}".format(
                        obj_name, op_name, self.name, str(e)))
        return ret_val
Exemplo n.º 17
0
    def test_wide_deconfiguration(self, config):
        try:
            self.guest_deconfigure(config.guest)
        except:
            log_exc_traceback()

        try:
            self.host_forwarding_vm_deconfiguration(config.dut, config.guest)
        except:
            log_exc_traceback()

        try:
            self.host_forwarding_deconfiguration(config.dut)
        except:
            log_exc_traceback()

        try:
            self.base_dpdk_deconfiguration(config.generator)
        except:
            log_exc_traceback()

        try:
            #returning the guest to the original running state
            self.shutdown_guest(config.guest)
            if config.guest.virtctl:
                config.guest.virtctl.vm_start(config.guest.name)
        except:
            log_exc_traceback()

        try:
            config.generator.host.run("service irqbalance start")
        except:
            log_exc_traceback()
Exemplo n.º 18
0
 def bus_info(self):
     try:
         return ethtool.get_businfo(self.name)
     except IOError as e:
         log_exc_traceback()
         return ""
Exemplo n.º 19
0
 def createXML(self, xml, flags=0):
     try:
         self._libvirt_conn.createXML(xml, flags)
     except:
         log_exc_traceback()
Exemplo n.º 20
0
 def vm_shutdown(self, name):
     vm = self._libvirt_conn.lookupByName(name)
     try:
         vm.shutdown()
     except:
         log_exc_traceback()
Exemplo n.º 21
0
 def vm_destroy(self, name):
     vm = self._libvirt_conn.lookupByName(name)
     try:
         vm.destroy()
     except:
         log_exc_traceback()
Exemplo n.º 22
0
 def _dispatch(self, method, params):
     try:
         return SimpleXMLRPCServer._dispatch(self, method, params)
     except Exception as err:
         log_exc_traceback()
         raise xmlrpclib.Fault(1, str(err))
Exemplo n.º 23
0
    def _process_msg(self, msg):
        if msg["type"] == "command":
            method = getattr(self._methods, msg["method_name"], None)
            if method != None:
                if_manager = self._methods._if_manager
                if if_manager is not None:
                    args = deviceref_to_device(if_manager, msg["args"])
                    kwargs = deviceref_to_device(if_manager, msg["kwargs"])
                else:
                    args = msg["args"]
                    kwargs = msg["kwargs"]

                try:
                    result = method(*args, **kwargs)
                except LnstError as e:
                    log_exc_traceback()
                    response = {"type": "exception", "Exception": e}

                    self._server_handler.send_data_to_ctl(response)
                    return

                response = {"type": "result", "result": result}
                response = device_to_deviceref(response)
                self._server_handler.send_data_to_ctl(response)
            else:
                err = LnstError("Method '%s' not supported." % msg["method_name"])
                response = {"type": "exception", "Exception": err}
                self._server_handler.send_data_to_ctl(response)
        elif msg["type"] == "log":
            logger = logging.getLogger()
            record = logging.makeLogRecord(msg["record"])
            logger.handle(record)
        elif msg["type"] == "exception":
            if msg["cmd_id"] != None:
                logging.debug("Recieved an exception from command with id: %s"
                                % msg["cmd_id"])
            else:
                logging.debug("Recieved an exception from foreground command")
            logging.debug(msg["Exception"])
            job = self._job_context.get_cmd(msg["job_id"])
            job.join()
            self._job_context.del_cmd(job)
            self._server_handler.send_data_to_ctl(msg)
        elif msg["type"] == "job_finished":
            job = self._job_context.get_job(msg["job_id"])
            job.join()

            job.set_finished(msg["result"])
            self._server_handler.send_data_to_ctl(msg)

            self._job_context.del_job(job)

        elif msg["type"] == "from_netns":
            self._server_handler.send_data_to_ctl(msg["data"])
        elif msg["type"] == "to_netns":
            netns = msg["netns"]
            try:
                self._server_handler.send_data_to_netns(netns, msg["data"])
            except LnstError as e:
                log_exc_traceback()
                response = {"type": "exception", "Exception": e}

                self._server_handler.send_data_to_ctl(response)
                return
        else:
            raise Exception("Recieved unknown command")

        pipes = self._job_context.get_parent_pipes()
        self._server_handler.update_connections(pipes)
Exemplo n.º 24
0
    def _process_msg(self, msg):
        if msg["type"] == "command":
            method = getattr(self._methods, msg["method_name"], None)
            if method != None:
                try:
                    result = method(*msg["args"])
                except:
                    log_exc_traceback()
                    type, value, tb = sys.exc_info()
                    exc_trace = ''.join(
                        traceback.format_exception(type, value, tb))
                    response = {"type": "exception", "Exception": exc_trace}

                    self._server_handler.send_data_to_ctl(response)
                    return

                if result != None:
                    response = {"type": "result", "result": result}
                    self._server_handler.send_data_to_ctl(response)
            else:
                err = "Method '%s' not supported." % msg["method_name"]
                response = {"type": "error", "err": err}
                self._server_handler.send_data_to_ctl(response)
        elif msg["type"] == "log":
            logger = logging.getLogger()
            record = logging.makeLogRecord(msg["record"])
            logger.handle(record)
        elif msg["type"] == "exception":
            if msg["cmd_id"] != None:
                logging.debug(
                    "Recieved an exception from command with id: %s" %
                    msg["cmd_id"])
            else:
                logging.debug("Recieved an exception from foreground command")
            logging.error(msg["Exception"])
            cmd = self._cmd_context.get_cmd(msg["cmd_id"])
            cmd.join()
            self._cmd_context.del_cmd(cmd)
            self._server_handler.send_data_to_ctl(msg)
        elif msg["type"] == "result":
            if msg["cmd_id"] == None:
                del msg["cmd_id"]
                self._server_handler.send_data_to_ctl(msg)
                cmd = self._cmd_context.get_cmd(None)
                cmd.join()
                self._cmd_context.del_cmd(cmd)
            else:
                cmd = self._cmd_context.get_cmd(msg["cmd_id"])
                cmd.join()
                del msg["cmd_id"]

                if cmd.finished():
                    self._server_handler.send_data_to_ctl(msg)
                    self._cmd_context.del_cmd(cmd)
                else:
                    cmd.set_result(msg["result"])
        else:
            raise Exception("Recieved unknown command")

        pipes = self._cmd_context.get_read_pipes()
        self._server_handler.update_connections(pipes)
Exemplo n.º 25
0
 def _dispatch(self, method, params):
     try:
         return SimpleXMLRPCServer._dispatch(self, method, params)
     except Exception as err:
         log_exc_traceback()
         raise xmlrpclib.Fault(1, str(err))