Esempio n. 1
0
    def _kill_ovsdb(self):
        """Kill ``ovsdb-server`` instance.

        :returns: None
        """
        if os.path.isfile(self._ovsdb_pidfile_path):
            with open(self._ovsdb_pidfile_path, "r") as pidfile:
                ovsdb_pid = pidfile.read().strip()

            self._logger.info("Killing ovsdb with pid: %s", ovsdb_pid)

            if ovsdb_pid:
                tasks.terminate_task(ovsdb_pid, logger=self._logger)

        # restore original content of ovs_var_tmp and ovs_etc_tmp; It is
        # essential for OVS installed from binary packages.
        if self._stamp:
            for tmp_dir in ['ovs_var_tmp', 'ovs_etc_tmp']:
                orig_dir = os.path.normpath(
                    settings.getValue('TOOLS')[tmp_dir])
                if os.path.exists('{}.{}'.format(orig_dir, self._stamp)):
                    self._logger.info('Restoring backup of %s directory...',
                                      tmp_dir)
                    tasks.run_task(['sudo', 'rm', '-rf', orig_dir],
                                   self._logger)
                    tasks.run_task([
                        'sudo', 'mv', '{}.{}'.format(orig_dir, self._stamp),
                        orig_dir
                    ], self._logger)
Esempio n. 2
0
    def kill(self, signal='-15', sleep=10):
        """Kill ``ovs-vswitchd`` and ``ovs-ovsdb`` instances if they are alive.

        :returns: None
        """
        if os.path.isfile(self._vswitchd_pidfile_path):
            self._logger.info('Killing ovs-vswitchd...')
            with open(self._vswitchd_pidfile_path, "r") as pidfile:
                vswitchd_pid = pidfile.read().strip()
                tasks.terminate_task(vswitchd_pid, logger=self._logger)

        self._kill_ovsdb()  # ovsdb must be killed after vswitchd

        # just for case, that sudo envelope has not been terminated yet
        tasks.Process.kill(self, signal, sleep)
    def kill(self, signal='-15', sleep=10):
        """See IVswitch for general description

        Kills ``vpp``
        """
        # try to get VPP pid
        output = self.run_vppctl(['show', 'version', 'verbose'])
        match = re.search(r'Current PID:\s*([0-9]+)', output[0])
        if match:
            vpp_pid = match.group(1)
            tasks.terminate_task(vpp_pid, logger=self._logger)

        # in case, that pid was not detected or sudo envelope
        # has not been terminated yet
        tasks.Process.kill(self, signal, sleep)
Esempio n. 4
0
    def restart(self):
        """ Restart ``ovs-vswitchd`` instance. ``ovsdb-server`` is not restarted.

        :raises: pexpect.EOF, pexpect.TIMEOUT
        """
        self._logger.info("Restarting vswitchd...")
        if os.path.isfile(self._vswitchd_pidfile_path):
            self._logger.info('Killing ovs-vswitchd...')
            with open(self._vswitchd_pidfile_path, "r") as pidfile:
                vswitchd_pid = pidfile.read().strip()
                tasks.terminate_task(vswitchd_pid, logger=self._logger)

        try:
            tasks.Process.start(self)
            self.relinquish()
        except (pexpect.EOF, pexpect.TIMEOUT) as exc:
            self._logger.error("Exception during VSwitch start.")
            self._kill_ovsdb()
            raise exc
        self._logger.info("Vswitchd...Started.")