Beispiel #1
0
 def power_off_do(self, target):
     _pid = target.fsdb.get('daemon_pid')
     if _pid:
         pid = int(_pid)
         commonl.process_terminate(pid)
         # ttbl.daemon_pid_rm() happens in the process that gets the SIGCHLD
         target.fsdb.set('daemon_pid', None)
Beispiel #2
0
    def off(self, target, component):
        # Kill tcpdump, if it was started
        pidfile = os.path.join(target.state_dir, "tcpdump.pid")
        commonl.process_terminate(pidfile,
                                  tag="tcpdump",
                                  path="/usr/sbin/tcpdump")
        # remove the top level device
        mode = self._get_mode(target)
        if mode == 'physical':
            # bring down the lower device
            ifname = commonl.if_find_by_mac(target.tags['mac_addr'])
            subprocess.check_call(
                # flush the IP addresses, bring it down
                "/usr/sbin/ip add flush dev %s; "
                "/usr/sbin/ip link set dev %s down promisc off" %
                (ifname, ifname),
                shell=True)
        elif mode == 'vlan':
            commonl.if_remove_maybe("b%(id)s" % target.kws)
            # nothing; we killed the upper and on the lwoer, a
            # physical device we do nothing, as others might be using it
            pass
        elif mode == 'virtual':
            commonl.if_remove_maybe("b%(id)s" % target.kws)
            # remove the lower we created
            commonl.if_remove_maybe("_b%(id)s" % target.kws)
        else:
            raise AssertionError("Unknown mode %s" % mode)

        target.fsdb.set('power_state', 'off')
Beispiel #3
0
    def power_off_do(self, target):
        _pid = target.fsdb.get('daemon_pid')
        if _pid:
            pid = int(_pid)
            commonl.process_terminate(pid)
	    # ttbl.daemon_pid_rm() happens in the process that gets the SIGCHLD
            target.fsdb.set('daemon_pid', None)
Beispiel #4
0
Datei: dhcp.py Projekt: intel/tcf
 def power_off_do(self, target):
     if self.target == None:
         self.target = target
     else:
         assert self.target == target
     self._init_for_process(target)
     commonl.process_terminate(self.dhcpd_pidfile,
                               path = self.dhcpd_path, tag = "dhcpd")
Beispiel #5
0
 def power_off_do(self, target):
     self._init_for_process(target)
     commonl.process_terminate(self.dhcpd_pidfile,
                               path=self.dhcpd_path,
                               tag="dhcpd")
     commonl.process_terminate(self.dhcpd_pidfile,
                               path=self.tftpd_path,
                               tag="tftpd")
Beispiel #6
0
 def stop(self, target, capturer, path):
     pidfile = "%s/capture-%s.pid" % (target.state_dir, capturer)
     target.log.info("%s: stopping generic streaming", capturer)
     commonl.process_terminate(pidfile,
                               tag="capture:" + capturer,
                               wait_to_kill=self.wait_to_kill,
                               use_signal=self.use_signal)
     target.log.info("%s: generic streaming stopped", capturer)
Beispiel #7
0
Datei: adb.py Projekt: intel/tcf
 def power_off_do(self, target):
     target.property_set("adb.port", None)
     pidfile = os.path.join(target.state_dir, "adb-" + self._id + ".pid")
     try:
         commonl.process_terminate(pidfile, path = self.path, tag = "adb")
     except OSError as e:
         # adb might have died already
         if e != errno.ESRCH:
             raise
Beispiel #8
0
 def power_off_do(self, target):
     target.property_set("adb.port", None)
     pidfile = os.path.join(target.state_dir, "adb-" + self._id + ".pid")
     try:
         commonl.process_terminate(pidfile, path=self.path, tag="adb")
     except OSError as e:
         # adb might have died already
         if e != errno.ESRCH:
             raise
Beispiel #9
0
 def power_off_do(self, target):
     if self.target == None:
         self.target = target
     else:
         assert self.target == target
     self._init_for_process(target)
     commonl.process_terminate(self.dhcpd_pidfile,
                               path=self.dhcpd_path,
                               tag="dhcpd")
Beispiel #10
0
    def _power_off_do(self):
        # Make sure the pidfile is removed, somehow it fails to do so
        pid = self._power_get()
        if pid != None:
            commonl.process_terminate(pid, pidfile=self.pidfile, tag="QEMU: ")

        self.fsdb.set("qemu-cmdline", None)
        commonl.rm_f(self.pidfile + ".qmp")
        console_out_fname = os.path.join(self.state_dir, "console-1.log")
        commonl.rm_f(console_out_fname)
Beispiel #11
0
 def _delete_tunnel(target, tunnel_id):
     # tunnel_id is the name of the property that holds the tunnel name
     port_pid = target.fsdb.get(tunnel_id)
     if port_pid != None:
         _, pids = port_pid.split(" ", 2)
         pid = int(pids)
         if commonl.process_alive(pid, "/usr/bin/socat"):
             commonl.process_terminate(pid,
                                       tag="socat's tunnel [%s]: " %
                                       tunnel_id)
         target.fsdb.set(tunnel_id, None)
Beispiel #12
0
    def _power_off_do(self):
        # Make sure the pidfile is removed, somehow it fails to do so
        pid = self._power_get()
        if pid != None:
            commonl.process_terminate(pid, pidfile = self.pidfile,
                                      tag = "QEMU: ")

        self.fsdb.set("qemu-cmdline", None)
        commonl.rm_f(self.pidfile + ".qmp")
        console_out_fname = os.path.join(self.state_dir, "console-1.log")
        commonl.rm_f(console_out_fname)
Beispiel #13
0
    def _power_off_do_bsp(self, bsp):
        # Make sure the pidfile is removed, somehow it fails to do so
        pid = self._power_get_bsp(bsp)
        if pid != None:
            commonl.process_terminate(pid, pidfile = self.pidfile[bsp],
                                      tag = "QEMU[%s]: " % bsp)

        self.fsdb.set("qemu-cmdline-%s" % bsp, None)
        commonl.rm_f(self.pidfile[bsp] + ".qmp")
        console_out_fname = os.path.join(
            self.state_dir, "console-%s.log" % bsp)
        commonl.rm_f(console_out_fname)
Beispiel #14
0
 def off(self, target, component):
     kws = dict(target.kws)
     kws.update(self.kws)
     kws['component'] = component
     pidfile = self.pidfile % kws
     try:
         commonl.process_terminate(pidfile,
                                   path=self.path,
                                   tag=component + "-" + self.name)
     except OSError as e:
         if e != errno.ESRCH:
             raise
Beispiel #15
0
    def _power_off_do_bsp(self, bsp):
        # Make sure the pidfile is removed, somehow it fails to do so
        pid = self._power_get_bsp(bsp)
        if pid != None:
            commonl.process_terminate(pid,
                                      pidfile=self.pidfile[bsp],
                                      tag="QEMU[%s]: " % bsp)

        self.fsdb.set("qemu-cmdline-%s" % bsp, None)
        commonl.rm_f(self.pidfile[bsp] + ".qmp")
        console_out_fname = os.path.join(self.state_dir,
                                         "console-%s.log" % bsp)
        commonl.rm_f(console_out_fname)
Beispiel #16
0
 def off(self, target, component):
     kws = dict(target.kws)
     kws.update(self.kws)
     # bring in runtime properties (override the rest)
     kws.update(target.fsdb.get_as_dict())
     kws['component'] = component
     pidfile = self.pidfile % kws
     try:
         commonl.process_terminate(pidfile, path = self.path,
                                   tag = component + "-" + self.name)
     except OSError as e:
         if e != errno.ESRCH:
             raise
Beispiel #17
0
 def stop_and_get(self, target, capturer):
     impl_c.stop_and_get(self, target, capturer)
     pidfile = os.path.join(target.state_dir,
                            "capturer-" + capturer + ".pid")
     file_name = target.property_get("capturer-%s-output" % capturer)
     kws = dict(output_file_name=file_name)
     kws.update(target.kws)
     try:
         target.property_set("capturer-%s-output" % capturer, None)
         commonl.process_terminate(pidfile,
                                   tag="capture:" + self.name % kws,
                                   wait_to_kill=self.wait_to_kill)
         return dict(stream_file=file_name)
     except OSError as e:
         # adb might have died already
         if e != errno.ESRCH:
             raise
Beispiel #18
0
 def _delete_tunnel(target, local_port, pid=None):
     if pid == None:
         pid = target.fsdb.get("interfaces.tunnel.%s.__id" % local_port)
     try:
         if isinstance(pid, int):
             if commonl.process_alive(pid, "/usr/bin/socat"):
                 commonl.process_terminate(pid,
                                           tag="socat's tunnel [%s]: " %
                                           local_port)
     finally:
         # whatever happens, just wipe all info about it because
         # this might be a corrupted entry
         prefix = "interfaces.tunnel.%s" % local_port
         target.fsdb.set(prefix + ".__id", None)
         target.fsdb.set(prefix + ".ip_addr", None)
         target.fsdb.set(prefix + ".protocol", None)
         target.fsdb.set(prefix + ".port", None)
Beispiel #19
0
 def power_get_do(self, target):
     self._init_for_process(target)
     dhcpd_pid = commonl.process_alive(self.dhcpd_pidfile, self.dhcpd_path)
     tftpd_pid = commonl.process_alive(self.tftpd_pidfile, self.tftpd_path)
     if dhcpd_pid != None and tftpd_pid != None:
         return True
     elif dhcpd_pid == None and tftpd_pid == None:
         return False
     else:
         self.log.warning("Inconstent PIDs DHCPD %s TFTP %s: stopping\n",
                          dhcpd_pid, tftpd_pid)
         if dhcpd_pid:
             commonl.process_terminate(dhcpd_pid, self.dhcpd_pidfile,
                                       "dhcpd[%d]" % dhcpd_pid)
         if tftpd_pid:
             commonl.process_terminate(tftpd_pid, self.tftpd_pidfile,
                                       "tftpd[%d]" % tftpd_pid)
         return False
Beispiel #20
0
    def on(self, target, component):
        pidfile = os.path.join(target.state_dir,
                               "socat-" + self.tunnel_id + ".pid")
        # kill anything that might be left lingering
        # FIXME: this should use daemon_c
        commonl.process_terminate(pidfile, path = self.path, tag = "socat")
        cmdline = [
            self.path,
            "-ly", "-lp", self.tunnel_id,
            "%s-LISTEN:%d,bind=%s,fork,reuseaddr" % (
                self.proto, self.local_port, self.local_addr),
            "%s:%s:%s" % (self.proto, self.remote_addr, self.remote_port)
        ]
        if self.kill_before_on:
            pids = commonl.kill_by_cmdline(" ".join(cmdline))
            if pids:
                target.log.error(
                    f"BUG? {component}/on: killed PIDs '{pids}'"
                    f" with the same command line: {cmdline}")

        try:
            p = subprocess.Popen(cmdline, shell = False,
                                 cwd = target.state_dir,
                                 close_fds = True, stderr = subprocess.STDOUT)
            with open(pidfile, "w+") as pidf:
                pidf.write("%s" % p.pid)
        except OSError as e:
            raise self.start_e("socat failed to start: %s", e)
        pid = commonl.process_started(
            pidfile, self.path,
            verification_f = commonl.tcp_port_busy,
            verification_f_args = (self.local_port,),
            tag = "socat", log = target.log)
        # systemd might complain with
        #
        # Supervising process PID which is not our child. We'll most
        # likely not notice when it exits.
        #
        # Can be ignored
        if pid == None:
            raise self.start_e("socat failed to start")
        ttbl.daemon_pid_add(pid)	# FIXME: race condition if it died?
Beispiel #21
0
    def power_on_do(self, target):
        """
        Start DHCPd and TFTPd servers on the network interface
        described by `target`
        """
        # FIXME: detect @target is an ipv4 capable network, fail otherwise
        self._init_for_process(target)
        # Create runtime directory where we place everything
        shutil.rmtree(self.state_dir, ignore_errors=True)
        os.makedirs(self.state_dir)
        os.makedirs(os.path.join(self.pxe_dir, "pxelinux.cfg"))

        # We set the parameters in a dictionary so we can use it to
        # format strings
        # FIXME: FUGLY
        self._params['if_name'] = "b" + target.id

        # FIXME: if we get the parameters from the network here, we
        # have target -- so we don't need to set them on init
        self._dhcp_conf_write()
        self._tftpd_conf_write()

        # FIXME: before start, filter out leases file, anything in the
        # leases dhcpd.leases file that has a "binding state active"
        # shall be kept ONLY if we still have that client in the
        # configuration...or sth like that.
        # FIXME: rm old leases file, overwrite with filtered one

        self._dhcpd_start()
        try:
            self._tftpd_start()
        except self.error_e:
            commonl.process_terminate(self.dhcpd_pidfile,
                                      path=self.dhcpd_path,
                                      tag="dhcpd")
            raise
Beispiel #22
0
 def power_off_do(self, target):
     pidfile = os.path.join(target.state_dir,
                            "socat-" + self.tunnel_id + ".pid")
     commonl.process_terminate(pidfile, path = self.path, tag = "socat")
Beispiel #23
0
 def power_off_do(self, target):
     pidfile = os.path.join(
         target.state_dir, "rsync-%s:%d.pid" % (self.address, self.port))
     commonl.process_terminate(pidfile, path = self.path, tag = "rsync")
Beispiel #24
0
 def power_off_do(self, target):
     pidfile = os.path.join(target.state_dir,
                            "socat-" + self.tunnel_id + ".pid")
     commonl.process_terminate(pidfile, path=self.path, tag="socat")
Beispiel #25
0
 def _power_off_do_kill(self):
     if self.pid == 0 or self.pid == None:
         self.log.error("BUG: OpenOCD pid %s found" % self.pid_s)
         return
     commonl.process_terminate(self.pid, None, "openocd[%d]" % self.pid)
Beispiel #26
0
 def stop(self, target, capturer, path):
     pidfile = "%s/capture-%s.pid" % (target.state_dir, capturer)
     commonl.process_terminate(pidfile, tag = "capture:" + capturer,
                               wait_to_kill = 2)
Beispiel #27
0
 def _power_off_do_kill(self):
     if self.pid == 0 or self.pid == None:
         self.log.error("BUG: OpenOCD pid %s found" % self.pid_s)
         return
     commonl.process_terminate(self.pid, None, "openocd[%d]" % self.pid)