def test_destroy_keep_alive(self): ContainerManager.set_container_keep_alive(self.node, "c1") with self.subTest("Try to destroy container with keep-alive tag"): self.assertFalse(ContainerManager.destroy_container(self.node, "c1")) self.assertEqual(ContainerManager.get_container(self.node, "c1"), self.container) with self.subTest("Ignore keep-alive tag"): self.assertTrue(ContainerManager.destroy_container(self.node, "c1", ignore_keepalive=True)) self.assertRaises(NotFound, ContainerManager.get_container, self.node, "c1")
def test_set_container_keep_alive(self): with self.subTest("Set keep alive to non-existent container"): self.assertRaises(NotFound, ContainerManager.set_container_keep_alive, self.node, "c2") with self.subTest("Set keep alive"): ContainerManager.set_container_keep_alive(self.node, "c1") self.assertEqual(self.container.name, "dummy---KEEPALIVE") with self.subTest("Set keep alive again"): ContainerManager.set_container_keep_alive(self.node, "c1") self.assertEqual(self.container.name, "dummy---KEEPALIVE")
def test_destroy_all(self): ContainerManager.run_container(self.node, "c2") ContainerManager.set_container_keep_alive(self.node, "c1") with self.subTest("Destroy all containers without keep-alive tag"): ContainerManager.destroy_all_containers(self.node) self.assertRaises(NotFound, ContainerManager.get_container, self.node, "c2") self.assertEqual(ContainerManager.get_container(self.node, "c1"), self.container) with self.subTest("Ignore keep-alive tag"): ContainerManager.destroy_all_containers(self.node, ignore_keepalive=True) self.assertRaises(NotFound, ContainerManager.get_container, self.node, "c1")
def test_destroy_logfile_callable(self): members = [] def logfile(member=None): members.append(member) return member self.node.c1_container_logfile = logfile c1another = ContainerManager.run_container(self.node, "c1:another") ContainerManager.set_container_keep_alive(self.node, "c1:another") with patch("builtins.open", mock_open()) as mock_file: self.assertTrue(ContainerManager.destroy_container(self.node, "c1")) self.assertFalse(ContainerManager.destroy_container(self.node, "c1:another")) mock_file.assert_called_once_with("another", "ab") mock_file().write.assert_called_once_with("container logs") self.assertEqual(members, [None, "another", ]) self.assertEqual(ContainerManager.get_container(self.node, "c1:another"), c1another) self.assertRaises(NotFound, ContainerManager.get_container, self.node, "c1") self.assertRaises(NotFound, ContainerManager.destroy_container, self.node, "c1")
def run_jepsen_web_server(self, detach: bool = False) -> None: if detach: ContainerManager.set_container_keep_alive(self, "jepsen") self.runcmd(command="cd jepsen-scylla && lein run serve", detach=detach)