Ejemplo n.º 1
0
    def start(self, pull: bool, recreate: bool):
        """If not started, start the containers defined in config"""

        verb = self.context['VERBOSE']
        debug = self.context['DEBUG']

        try:
            docker_actions.check_cts_are_running(self.project_name)
            puts(colored.yellow('[INFO]') + ' stakkr is already started ...')
            sys.exit(0)
        except SystemError:
            pass

        if pull is True:
            command.launch_cmd_displays_output(
                self.compose_base_cmd + ['pull'], verb, debug, True)

        recreate_param = '--force-recreate' if recreate is True else '--no-recreate'
        cmd = self.compose_base_cmd + [
            'up', '-d', recreate_param, '--remove-orphans'
        ]
        command.verbose(self.context['VERBOSE'], 'Command: ' + ' '.join(cmd))
        command.launch_cmd_displays_output(cmd, verb, debug, True)

        self.running_cts, self.cts = docker_actions.get_running_containers(
            self.project_name)
        if self.running_cts is 0:
            raise SystemError(
                "Couldn't start the containers, run the start with '-v' and '-d'"
            )

        os_patch.start(self.project_name)
        self._run_iptables_rules()
        self._run_services_post_scripts()
Ejemplo n.º 2
0
    def start(self, container: str, pull: bool, recreate: bool, proxy: bool):
        """If not started, start the containers defined in config."""
        self.init_project()
        verb = self.context['VERBOSE']
        debug = self.context['DEBUG']

        self._is_up(container)

        if pull is True:
            command.launch_cmd_displays_output(
                self._get_compose_base_cmd() + ['pull'], verb, debug, True)

        recreate_param = '--force-recreate' if recreate is True else '--no-recreate'
        cmd = self._get_compose_base_cmd() + [
            'up', '-d', recreate_param, '--remove-orphans'
        ]
        cmd += _get_single_container_option(container)

        command.verbose(self.context['VERBOSE'], 'Command: ' + ' '.join(cmd))
        command.launch_cmd_displays_output(cmd, verb, debug, True)

        running_cts, cts = docker.get_running_containers(self.project_name)
        if not running_cts:
            raise SystemError(
                "Couldn't start the containers, run the start with '-v' and '-d'"
            )

        self._run_iptables_rules(cts)
        if proxy is True:
            conf = self.config['proxy']
            Proxy(conf.get('http_port'), conf.get('https_port')).start(
                docker.get_network_name(self.project_name))
Ejemplo n.º 3
0
    def start(self, pull: bool, recreate: bool):
        """If not started, start the containers defined in config"""

        verb = self.context['VERBOSE']
        debug = self.context['DEBUG']

        try:
            docker_actions.check_cts_are_running(self.project_name)
            puts(colored.yellow('[INFO]') + ' stakkr is already started ...')
            sys.exit(0)
        except SystemError:
            pass

        if pull is True:
            command.launch_cmd_displays_output(self.compose_base_cmd + ['pull'], verb, debug, True)

        recreate_param = '--force-recreate' if recreate is True else '--no-recreate'
        cmd = self.compose_base_cmd + ['up', '-d', recreate_param, '--remove-orphans']
        command.verbose(self.context['VERBOSE'], 'Command: ' + ' '.join(cmd))
        command.launch_cmd_displays_output(cmd, verb, debug, True)

        self.running_cts, self.cts = docker_actions.get_running_containers(self.project_name)
        if self.running_cts is 0:
            raise SystemError("Couldn't start the containers, run the start with '-v' and '-d'")

        os_patch.start(self.project_name)
        self._run_iptables_rules()
        self._run_services_post_scripts()
Ejemplo n.º 4
0
    def start(self, container: str, pull: bool, recreate: bool, proxy: bool):
        """If not started, start the containers defined in config."""
        self.init_project()
        verb = self.context['VERBOSE']
        debug = self.context['DEBUG']

        self._is_up(container)

        if pull is True:
            command.launch_cmd_displays_output(self._get_compose_base_cmd() + ['pull'], verb, debug, True)

        recreate_param = '--force-recreate' if recreate is True else '--no-recreate'
        cmd = self._get_compose_base_cmd() + ['up', '-d', recreate_param, '--remove-orphans']
        cmd += _get_single_container_option(container)

        command.verbose(self.context['VERBOSE'], 'Command: ' + ' '.join(cmd))
        command.launch_cmd_displays_output(cmd, verb, debug, True)

        running_cts, cts = docker.get_running_containers(self.project_name)
        if not running_cts:
            raise SystemError("Couldn't start the containers, run the start with '-v' and '-d'")

        self._run_iptables_rules(cts)
        if proxy is True:
            conf = self.config['proxy']
            Proxy(conf.get('http_port'), conf.get('https_port')).start(
                docker.get_network_name(self.project_name))
Ejemplo n.º 5
0
    def stop(self):
        """If started, stop the containers defined in config. Else throw an error"""

        verb = self.context['VERBOSE']
        debug = self.context['DEBUG']

        docker_actions.check_cts_are_running(self.project_name)
        command.launch_cmd_displays_output(self.compose_base_cmd + ['stop'], verb, debug, True)
        os_patch.stop(self.project_name)

        self.running_cts, self.cts = docker_actions.get_running_containers(self.project_name)
        if self.running_cts is not 0:
            raise SystemError("Couldn't stop services ...")
Ejemplo n.º 6
0
    def stop(self, container: str):
        """If started, stop the containers defined in config. Else throw an error"""

        verb = self.context['VERBOSE']
        debug = self.context['DEBUG']

        docker_actions.check_cts_are_running(self.project_name)

        cmd = self.compose_base_cmd + ['stop'] + self._get_single_container_option(container)
        command.launch_cmd_displays_output(cmd, verb, debug, True)

        self.running_cts, self.cts = docker_actions.get_running_containers(self.project_name)
        if self.running_cts is not 0 and container is None:
            raise SystemError("Couldn't stop services ...")
Ejemplo n.º 7
0
    def stop(self, container: str, proxy: bool):
        """If started, stop the containers defined in config. Else throw an error."""
        self.init_project()
        verb = self.context['VERBOSE']
        debug = self.context['DEBUG']

        docker.check_cts_are_running(self.project_name)

        cmd = self._get_compose_base_cmd() + ['stop'] + _get_single_container_option(container)
        command.launch_cmd_displays_output(cmd, verb, debug, True)

        running_cts, _ = docker.get_running_containers(self.project_name)
        if running_cts and container is None:
            raise SystemError("Couldn't stop services ...")

        if proxy is True:
            Proxy().stop()
Ejemplo n.º 8
0
    def stop(self, container: str, proxy: bool):
        """If started, stop the containers defined in config. Else throw an error."""
        self.init_project()
        verb = self.context['VERBOSE']
        debug = self.context['DEBUG']

        docker.check_cts_are_running(self.project_name)

        cmd = self._get_compose_base_cmd() + [
            'stop'
        ] + _get_single_container_option(container)
        command.launch_cmd_displays_output(cmd, verb, debug, True)

        running_cts, _ = docker.get_running_containers(self.project_name)
        if running_cts and container is None:
            raise SystemError("Couldn't stop services ...")

        if proxy is True:
            Proxy().stop()
Ejemplo n.º 9
0
    def test_command_without_stderr_and_stdout_err(self):
        # TODO make it work under windows
        if os.name == 'nt':
            return

        f = io.StringIO()
        with redirect_stdout(f):
            launch_cmd_displays_output(self.cmd_nook, False, False)
        res = f.getvalue()
        self.assertEqual('\n', res)

        try:
            from contextlib import redirect_stderr
        except Exception:
            return

        f = io.StringIO()
        with redirect_stderr(f):
            launch_cmd_displays_output(self.cmd_nook, False, False)
        res = f.getvalue()
        self.assertEqual('', res)
Ejemplo n.º 10
0
    def test_command_without_stderr_and_stdout_err(self):
        # TODO make it work under windows
        if os.name == 'nt':
            return

        f = io.StringIO()
        with redirect_stdout(f):
            launch_cmd_displays_output(self.cmd_nook, False, False)
        res = f.getvalue()
        self.assertEqual('\n', res)

        try:
            from contextlib import redirect_stderr
        except Exception:
            return

        f = io.StringIO()
        with redirect_stderr(f):
            launch_cmd_displays_output(self.cmd_nook, False, False)
        res = f.getvalue()
        self.assertEqual('', res)
Ejemplo n.º 11
0
    def test_command_with_stderr_no_stdout_err(self):
        # TODO make it work under windows
        if os.name == 'nt':
            return

        f = io.StringIO()
        with redirect_stdout(f):
            launch_cmd_displays_output(self.cmd_nook, False, True)
        res = f.getvalue()
        expected = re.compile('.*No such file or directory.*', re.MULTILINE)
        self.assertRegex(res, expected)

        try:
            from contextlib import redirect_stderr
        except Exception:
            return

        f = io.StringIO()
        with redirect_stderr(f):
            launch_cmd_displays_output(self.cmd_nook, False, True)
        res = f.getvalue()
        self.assertEqual('', res)
Ejemplo n.º 12
0
    def test_command_with_stderr_no_stdout_err(self):
        # TODO make it work under windows
        if os.name == 'nt':
            return

        f = io.StringIO()
        with redirect_stdout(f):
            launch_cmd_displays_output(self.cmd_nook, False, True)
        res = f.getvalue()
        expected = re.compile('.*No such file or directory.*', re.MULTILINE)
        self.assertRegex(res, expected)

        try:
            from contextlib import redirect_stderr
        except Exception:
            return

        f = io.StringIO()
        with redirect_stderr(f):
            launch_cmd_displays_output(self.cmd_nook, False, True)
        res = f.getvalue()
        self.assertEqual('', res)
Ejemplo n.º 13
0
    def test_command_with_stderr_no_stdout_err_loop(self):
        # TODO make it work under windows
        if os.name == 'nt':
            return

        f = io.StringIO()
        with redirect_stdout(f):
            launch_cmd_displays_output(['wget', '--debug', '--tries', '3', 'http://doesnotexist'], False, True)
        res = f.getvalue()
        expected = re.compile('.*\.\.\. and more.*', re.MULTILINE)
        self.assertRegex(res, expected)

        try:
            from contextlib import redirect_stderr
        except Exception:
            return

        f = io.StringIO()
        with redirect_stderr(f):
            launch_cmd_displays_output(self.cmd_nook, False, True)
        res = f.getvalue()
        self.assertEqual('', res)
Ejemplo n.º 14
0
    def test_command_with_stderr_no_stdout_err_loop(self):
        # TODO make it work under windows
        if os.name == 'nt':
            return

        f = io.StringIO()
        with redirect_stdout(f):
            cmd = ['cat', 'w', 'r', 'o', 'n', 'g', 'f', 'i', 'l', 'e']
            launch_cmd_displays_output(cmd, False, True)
        res = f.getvalue()
        expected = re.compile('.*\.\.\. and more.*', re.MULTILINE)
        self.assertRegex(res, expected)

        try:
            from contextlib import redirect_stderr
        except Exception:
            return

        f = io.StringIO()
        with redirect_stderr(f):
            launch_cmd_displays_output(self.cmd_nook, False, True)
        res = f.getvalue()
        self.assertEqual('', res)
Ejemplo n.º 15
0
    def start(self, container: str, pull: bool, recreate: bool):
        """If not started, start the containers defined in config"""

        verb = self.context['VERBOSE']
        debug = self.context['DEBUG']

        self._is_containers_running(container)

        if pull is True:
            command.launch_cmd_displays_output(self.compose_base_cmd + ['pull'], verb, debug, True)

        recreate_param = '--force-recreate' if recreate is True else '--no-recreate'
        cmd = self.compose_base_cmd + ['up', '-d', recreate_param, '--remove-orphans']
        cmd += self._get_single_container_option(container)

        command.verbose(self.context['VERBOSE'], 'Command: ' + ' '.join(cmd))
        command.launch_cmd_displays_output(cmd, verb, debug, True)

        self.running_cts, self.cts = docker_actions.get_running_containers(self.project_name)
        if self.running_cts is 0:
            raise SystemError("Couldn't start the containers, run the start with '-v' and '-d'")

        self._run_iptables_rules()
        self._run_services_post_scripts()
Ejemplo n.º 16
0
 def test_command_exception(self):
     with self.assertRaisesRegex(SystemError,
                                 "Cannot run the command: \[.*Err.*2\]"):
         launch_cmd_displays_output(self.cmd_err, True, True)
Ejemplo n.º 17
0
 def test_command_exception(self):
     with self.assertRaisesRegex(SystemError, "Cannot run the command: \[.*Err.*2\]"):
         launch_cmd_displays_output(self.cmd_err, True, True)