Example #1
0
    def _remove_cleanup_app(self, path):
        """Stop and remove a cleanup app.
        """
        name = os.path.basename(path)

        if name.startswith('.'):
            _LOGGER.warning('Ignore %s', name)
            return

        cleaning_link = os.path.join(self.tm_env.cleaning_dir, name)
        app_path = os.path.join(self.tm_env.cleanup_apps_dir, name)

        _LOGGER.info('Removing cleanup app %s -> %s', cleaning_link, app_path)

        if os.path.exists(cleaning_link):
            _LOGGER.debug('Removing cleanup link %s', cleaning_link)
            fs.rm_safe(cleaning_link)
            self._refresh_supervisor()
            _LOGGER.debug('Waiting on %s not being supervised', app_path)
            supervisor.ensure_not_supervised(app_path)
        else:
            _LOGGER.debug('Cleanup link %s does not exist', cleaning_link)

        _LOGGER.debug('Removing app directory %s', app_path)
        fs.rmtree_safe(app_path)
Example #2
0
    def test_ensure_not_supervised_not_running(self):  # pylint: disable=C0103
        """Tests ensuring a service and its logs are down when they already
        are not supervised.
        """
        treadmill.supervisor.is_supervised.return_value = False

        supervisor.ensure_not_supervised(self.root)

        treadmill.supervisor.is_supervised.assert_called_once_with(
            self.root
        )

        self.assertEqual(1, treadmill.supervisor.is_supervised.call_count)

        treadmill.supervisor.is_supervised.reset_mock()

        log_dir = os.path.join(self.root, 'log')
        os.mkdir(log_dir)

        supervisor.ensure_not_supervised(self.root)

        treadmill.supervisor.is_supervised.assert_has_calls([
            mock.call(self.root), mock.call(log_dir)
        ])

        self.assertEqual(2, treadmill.supervisor.is_supervised.call_count)
Example #3
0
    def test_ensure_not_supervised_failed(self):  # pylint: disable=C0103
        """Tests when a service fails to be brought down.
        """
        treadmill.supervisor.is_supervised.return_value = True
        treadmill.supervisor.control_service.side_effect = \
            subproc.CalledProcessError(1, '')

        with self.assertRaises(Exception):
            supervisor.ensure_not_supervised(self.root)
Example #4
0
    def finish(self):
        """Frees allocated resources and mark then as available."""
        # Required because on windows log files are archived and deleted
        # which cannot happen when the supervisor/log is still running.
        supervisor.ensure_not_supervised(self._service.directory)

        self._finish()

        shutil.rmtree(self._service.directory)
        _LOGGER.info('Finished cleanup: %s', self._service.directory)
Example #5
0
    def test_ensure_not_supervised_exit(self):
        """Tests a supervisor was up and waiting to exit.
        """
        treadmill.supervisor.is_supervised.side_effect = (True, False)
        treadmill.supervisor.is_supervised.control_service.return_value = True

        supervisor.ensure_not_supervised(self.root)

        treadmill.supervisor.control_service.assert_called_with(
            self.root,
            supervisor.ServiceControlAction.exit,
            supervisor.ServiceWaitAction.really_down,
            timeout=1000)

        self.assertEqual(2, treadmill.supervisor.is_supervised.call_count)