def test_create(self): containers = { 'c1': BlockadeContainerConfig("c1", "image"), 'c2': BlockadeContainerConfig("c2", "image"), 'c3': BlockadeContainerConfig("c3", "image") } config = BlockadeConfig(containers) self.network.get_container_device.side_effect = lambda dc, y: "veth" + y self.state.exists.side_effect = lambda: False self.state.blockade_id = self.blockade_id self.docker_client.create_container.side_effect = [{ "Id": "container1" }, { "Id": "container2" }, { "Id": "container3" }] b = Blockade(config, state=self.state, network=self.network, docker_client=self.docker_client) b.create() self.assertEqual(self.state.initialize.call_count, 1) self.assertEqual(self.docker_client.create_container.call_count, 3)
def test_create(self): containers = { 'c1': BlockadeContainerConfig("c1", "image"), 'c2': BlockadeContainerConfig("c2", "image"), 'c3': BlockadeContainerConfig("c3", "image") } config = BlockadeConfig(containers) self.network.get_container_device.side_effect = lambda dc, y: "veth" + y initialize = lambda x, y: BlockadeState("ourblockadeid", x) self.state_factory.initialize.side_effect = initialize self.state_factory.exists.side_effect = lambda: False self.state_factory.get_blockade_id = mock.MagicMock( return_value="ourblockadeid") self.docker_client.create_container.side_effect = [{ "Id": "container1" }, { "Id": "container2" }, { "Id": "container3" }] b = Blockade(config, self.state_factory, self.network, self.docker_client) b.create() self.assertEqual(self.state_factory.initialize.call_count, 1) self.assertEqual(self.docker_client.create_container.call_count, 3)
def test_link_ordering_unknown_2(self): containers = [ BlockadeContainerConfig("c1", "image"), BlockadeContainerConfig("c2", "image", links=["c6", "c7"]), BlockadeContainerConfig("c3", "image", links=["c1"]) ] with self.assertRaisesRegexp(BlockadeConfigError, "unknown"): dependency_sorted(containers)
def test_link_ordering_circular_1(self): containers = [ BlockadeContainerConfig("c1", "image"), BlockadeContainerConfig("c2", "image", links=["c1"]), BlockadeContainerConfig("c3", "image", links=["c3"]) ] with self.assertRaisesRegexp(BlockadeConfigError, "circular"): dependency_sorted(containers)
def test_link_ordering_3(self): containers = [ BlockadeContainerConfig("c1", "image"), BlockadeContainerConfig("c2", "image", links={"c1": "c1"}), BlockadeContainerConfig("c3", "image", links={"c1": "c1"}) ] ordered = dependency_sorted(containers) ordered_names = [c.name for c in ordered] self.assertDependencyLevels(ordered_names, ["c1"], ["c2", "c3"])
def test_create(self): containers = [BlockadeContainerConfig("c1", "image"), BlockadeContainerConfig("c2", "image"), BlockadeContainerConfig("c3", "image")] config = BlockadeConfig(containers) self.network.new_veth_device_name.side_effect = ["veth1", "veth2", "veth3"] initialize = lambda x: BlockadeState("ourblockadeid", x) self.state_factory.initialize.side_effect = initialize self.docker_client.create_container.side_effect = [ {"Id": "container1"}, {"Id": "container2"}, {"Id": "container3"}] b = Blockade(config, self.state_factory, self.network, self.docker_client) b.create() self.assertEqual(self.state_factory.initialize.call_count, 1) self.assertEqual(self.docker_client.create_container.call_count, 3)
def test_publish_without_expose_1(self): cont = BlockadeContainerConfig("c1", "image", expose_ports=[], publish_ports={8080: 80}) self.assertEqual(cont.expose_ports, [80])