コード例 #1
0
    def test_notifies_queues(self):
        cg = self._launch_container(EXITS_WITH_TERM_1)
        job_q = queue.Queue()
        activity_q = queue.Queue()
        restart(10, cg, job_q, activity_q)

        self.assertHasMessageForCg(job_q, RestartCompleteMessage, cg.path)
        self.assertHasMessageForCg(activity_q, RestartCgroupMessage, cg.path)
        self.assertHasNoMessages(activity_q)
コード例 #2
0
    def test_restart_wipes_fs(self):
        q = queue.Queue()

        cg = self._launch_container(EXITS_IF_FILE)
        time.sleep(2)

        restart(docker_wipe_fs, 1, cg, q, q)
        time.sleep(2)

        self.assertTrue(docker_json(cg)["State"]["Running"])
コード例 #3
0
    def test_restart_kills_processes(self):
        q = queue.Queue()

        cg = self._launch_container(NEVER_EXITS)
        time.sleep(2)

        restart(null, 1, cg, q, q)
        time.sleep(2)

        self.assertFalse(docker_json(cg)["State"]["Running"])
コード例 #4
0
    def test_notifies_queues_timeout(self):
        cg = self._launch_container(NEVER_EXITS)
        job_q = queue.Queue()
        activity_q = queue.Queue()
        restart(3, cg, job_q, activity_q)

        self.assertHasMessageForCg(job_q, RestartCompleteMessage, cg.path)
        self.assertHasMessageForCg(activity_q, RestartCgroupMessage, cg.path)
        self.assertHasMessageForCg(activity_q, RestartTimeoutMessage, cg.path,
                                   grace_period=3)
コード例 #5
0
    def test_restarts_with_ports(self):
        host_port = random_free_port()

        options = ["-p", "{0}:80".format(host_port)] + WELL_BEHAVED
        cg = self._launch_container(options)
        restart(queue.Queue(), 10, cg)

        binding = docker_json(cg)["NetworkSettings"]["Ports"]["80/tcp"][0]
        port = int(binding["HostPort"])

        self.assertEqual(host_port, port)
コード例 #6
0
    def test_notifies_queues(self):
        cg = self._launch_container(EXITS_WITH_TERM_1)
        self._wait_pids(cg, 2)

        job_q = queue.Queue()
        activity_q = queue.Queue()
        restart(docker, 10, cg, job_q, activity_q)

        self.assertHasMessageForCg(job_q, RestartCompleteMessage, cg.path)
        self.assertHasMessageForCg(activity_q, RestartCgroupMessage, cg.path)
        self.assertHasNoMessages(activity_q)
コード例 #7
0
    def test_restarts_with_ports(self):
        host_port = random_free_port()

        options = ["-p", "{0}:80".format(host_port)] + EXITS_WITH_TERM_1
        cg = self._launch_container(options)
        q = queue.Queue()
        restart(docker, 10, cg, q, q)

        binding = docker_json(cg)["NetworkSettings"]["Ports"]["80/tcp"][0]
        port = int(binding["HostPort"])

        self.assertEqual(host_port, port)
コード例 #8
0
    def test_notifies_queues_timeout(self):
        cg = self._launch_container(NEVER_EXITS)
        self._wait_pids(cg, 1)

        job_q = queue.Queue()
        activity_q = queue.Queue()
        restart(docker, 3, cg, job_q, activity_q)

        self.assertHasMessageForCg(job_q, RestartCompleteMessage, cg.path)
        self.assertHasMessageForCg(activity_q, RestartCgroupMessage, cg.path)
        self.assertHasMessageForCg(activity_q, RestartTimeoutMessage, cg.path,
                                   grace_period=3)
コード例 #9
0
    def test_restarts_misbehaved_container(self):
        cg = self._launch_container(MIS_BEHAVED)

        pid_before = docker_json(cg)["State"]["Pid"]
        time_before = time.time()

        restart(queue.Queue(), 3, cg)

        time_after = time.time()
        pid_after = docker_json(cg)["State"]["Pid"]

        self.assertNotEqual(pid_before, pid_after)
        self.assertGreater(time_after - time_before, 2)
コード例 #10
0
    def test_restarts_well_behaved_container(self):
        cg = self._launch_container(WELL_BEHAVED)

        pid_before = docker_json(cg)["State"]["Pid"]
        time_before = time.time()

        restart(queue.Queue(), 10, cg)

        time_after = time.time()
        pid_after = docker_json(cg)["State"]["Pid"]

        self.assertNotEqual(pid_before, pid_after)
        self.assertLess(time_after - time_before, 5)
コード例 #11
0
    def test_restart_container_with_term_all(self):
        cg = self._launch_container(EXITS_WITH_TERM_ALL)

        pid_before = docker_json(cg)["State"]["Pid"]
        time_before = time.time()

        q = queue.Queue()
        restart(10, cg, q, q)

        time_after = time.time()
        pid_after = docker_json(cg)["State"]["Pid"]

        self.assertNotEqual(pid_before, pid_after)
        self.assertLess(time_after - time_before, 5)
コード例 #12
0
    def test_restarts_misbehaved_container(self):
        cg = self._launch_container(NEVER_EXITS)

        pid_before = docker_json(cg)["State"]["Pid"]
        time_before = time.time()

        q = queue.Queue()
        restart(3, cg, q, q)

        time_after = time.time()
        pid_after = docker_json(cg)["State"]["Pid"]

        self.assertNotEqual(pid_before, pid_after)
        self.assertGreater(time_after - time_before, 2)
コード例 #13
0
    def test_restarts_misbehaved_container(self):
        cg = self._launch_container(NEVER_EXITS)
        self._wait_pids(cg, 1)

        pid_before = docker_json(cg)["State"]["Pid"]
        time_before = time.time()

        q = queue.Queue()
        restart(docker, 3, cg, q, q)

        time_after = time.time()
        pid_after = docker_json(cg)["State"]["Pid"]

        self.assertNotEqual(pid_before, pid_after)
        self.assertGreater(time_after - time_before, 2)
コード例 #14
0
ファイル: cli.py プロジェクト: zharben/captain-comeback
def restart_one(root_cg, grace_period, container_id):
    q = queue.Queue()
    cg = Cgroup(os.path.join(root_cg, container_id))

    try:
        restart(grace_period, cg, q, q)
    except IOError:
        logger.error("%s: container does not exist", cg.name())
        return 1
    finally:
        while not q.empty():
            m = q.get()
            logger.debug("%s: received %s", cg.name(), m.__class__.__name__)

    return 0
コード例 #15
0
    def test_restart_container_with_term_all(self):
        cg = self._launch_container(EXITS_WITH_TERM_ALL)
        self._wait_pids(cg, 2)

        pid_before = docker_json(cg)["State"]["Pid"]
        time_before = time.time()

        q = queue.Queue()
        restart(docker, 10, cg, q, q)

        time_after = time.time()
        pid_after = docker_json(cg)["State"]["Pid"]

        self.assertNotEqual(pid_before, pid_after)
        self.assertLess(time_after - time_before, 5)
コード例 #16
0
ファイル: cli.py プロジェクト: aptible/captain-comeback
def restart_one(root_cg_path, restart_adapter, restart_grace_period,
                container_id):
    q = queue.Queue()
    cg = Cgroup(os.path.join(root_cg_path, container_id))

    try:
        restart(restart_adapter, restart_grace_period, cg, q, q)
    except IOError:
        logger.error("%s: container does not exist", cg.name())
        return 1
    finally:
        while not q.empty():
            m = q.get()
            logger.debug("%s: received %s", cg.name(), m.__class__.__name__)

    return 0
コード例 #17
0
 def test_restart_with_memory_limit(self):
     options = ["--memory", "10mb"] + WELL_BEHAVED
     cg = self._launch_container(options)
     restart(queue.Queue(), 10, cg)
コード例 #18
0
 def test_restart_with_memory_limit(self):
     options = ["--memory", "10mb"] + EXITS_WITH_TERM_1
     cg = self._launch_container(options)
     q = queue.Queue()
     restart(docker, 10, cg, q, q)