diff --git a/broker/binds/containers.py b/broker/binds/containers.py index 19bb285..a574d9d 100644 --- a/broker/binds/containers.py +++ b/broker/binds/containers.py @@ -100,11 +100,12 @@ def image_info(self, name): def create_container(self, image, command=None, **kwargs): """Create and return running container instance.""" if net_name := settings.container.network: - if not self.get_network_by_attrs({"name": net_name}): - raise UserError( - f"Network '{settings.container.network}' not found on container host." - ) - kwargs["networks"] = {net_name: {"NetworkId": net_name}} + net_dict = {} + for name in net_name.split(","): + if not self.get_network_by_attrs({"name": name}): + raise UserError(f"Network '{name}' not found on container host.") + net_dict[name] = {"NetworkId": name} + kwargs["networks"] = net_dict kwargs = self._sanitize_create_args(kwargs) return self.client.containers.create(image, command, **kwargs) diff --git a/tests/providers/test_container.py b/tests/providers/test_container.py index 031da14..34746be 100644 --- a/tests/providers/test_container.py +++ b/tests/providers/test_container.py @@ -58,9 +58,14 @@ def pull_image(tag_name): def create_container(self, container_host, **kwargs): if net_name := settings.container.network: - if not self.get_network_by_attrs({"name": net_name}): - raise Exception(f"Network '{settings.container.network}' not found on container host.") - kwargs["networks"] = {net_name: {"NetworkId": net_name}} + net_dict = {} + for name in net_name.split(","): + if not self.get_network_by_attrs({"name": name}): + raise Exception( + f"Network '{name}' not found on container host." + ) + net_dict[name] = {"NetworkId": name} + kwargs["networks"] = net_dict with open("tests/data/container/fake_containers.json") as container_file: container_data = json.load(container_file) image_data = self.pull_image(container_host) @@ -93,12 +98,18 @@ def test_host_creation(container_stub): assert host.hostname == "f37d3058317f" -def test_ipv6_host_creation(container_stub): +def test_single_network(container_stub): settings.container.network = "podman2" cont = container_stub.run_container(container_host="ch-d:ubi8") assert cont.kwargs["networks"] == {'podman2': {'NetworkId': 'podman2'}} +def test_multiple_networks(container_stub): + settings.container.network = "podman1,podman2" + cont = container_stub.run_container(container_host="ch-d:ubi8") + assert cont.kwargs["networks"] == {'podman1': {'NetworkId': 'podman1'}, 'podman2': {'NetworkId': 'podman2'}} + + def test_image_lookup_failure(container_stub): with pytest.raises(Broker.ProviderError) as err: container_stub.run_container(container_host="this-does-not-exist") diff --git a/tests/test_broker.py b/tests/test_broker.py index a15427c..ab2e109 100644 --- a/tests/test_broker.py +++ b/tests/test_broker.py @@ -38,6 +38,13 @@ def test_full_init(): assert broker_inst._kwargs["test_action"] == "blank" +def test_specified_instance(): + """Make sure that a specified instance is used""" + broker_inst = Broker(nick="test_nick", TestProvider="test2") + host_checkout = broker_inst.checkout() + assert host_checkout._broker_provider_instance == "test2" + + def test_broker_e2e(): """Run through the base functionality of broker""" broker_inst = Broker(nick="test_nick")