Esempio n. 1
0
 def test_cleanup(self, mock_wrap, mock_clients):
     net_context = network_context.Network(self.get_context())
     net_context.cleanup()
     mock_wrap().delete_network.assert_has_calls(
         [mock.call({"id": "foo_net"}),
          mock.call({"id": "bar_net"})],
         any_order=True)
Esempio n. 2
0
 def test__init__explicit(self, mock_wrap, mock_clients):
     context = network_context.Network(
         self.get_context(start_cidr="foo_cidr",
                          networks_per_tenant=42,
                          network_create_args={"fakearg": "fake"},
                          dns_nameservers=["1.2.3.4", "5.6.7.8"]))
     self.assertEqual(42, context.config["networks_per_tenant"])
     self.assertEqual("foo_cidr", context.config["start_cidr"])
     self.assertEqual({"fakearg": "fake"},
                      context.config["network_create_args"])
     self.assertEqual(("1.2.3.4", "5.6.7.8"),
                      context.config["dns_nameservers"])
Esempio n. 3
0
    def test_setup(self, mock_clients, mock_utils, mock_wrap, **dns_kwargs):
        mock_utils.iterate_per_tenants.return_value = [
            ("foo_user", "foo_tenant"), ("bar_user", "bar_tenant")
        ]
        mock_create = mock.Mock(side_effect=lambda t, **kw: t + "-net")
        mock_utils.generate_random_name = mock.Mock()
        mock_wrap.return_value = mock.Mock(create_network=mock_create)
        nets_per_tenant = 2
        net_context = network_context.Network(
            self.get_context(networks_per_tenant=nets_per_tenant,
                             network_create_args={"fakearg": "fake"},
                             **dns_kwargs))

        net_context.setup()

        if "dns_nameservers" in dns_kwargs:
            dns_kwargs["dns_nameservers"] = tuple(
                dns_kwargs["dns_nameservers"])
        create_calls = [
            mock.call(tenant,
                      dualstack=False,
                      subnets_num=1,
                      network_create_args={"fakearg": "fake"},
                      router_create_args={"external": True},
                      **dns_kwargs)
            for user, tenant in mock_utils.iterate_per_tenants.return_value
        ]
        mock_create.assert_has_calls(create_calls)

        mock_utils.iterate_per_tenants.assert_called_once_with(
            net_context.context["users"])
        expected_networks = ["bar_tenant-net", "foo_tenant-net"
                             ] * nets_per_tenant
        actual_networks = []
        for tenant_id, tenant_ctx in net_context.context["tenants"].items():
            actual_networks.extend(tenant_ctx["networks"])
        self.assertSequenceEqual(sorted(expected_networks),
                                 sorted(actual_networks))
Esempio n. 4
0
 def test__init__default(self, mock_wrap, mock_clients):
     context = network_context.Network(self.get_context())
     self.assertEqual(1, context.config["networks_per_tenant"])
     self.assertEqual(network_context.Network.DEFAULT_CONFIG["start_cidr"],
                      context.config["start_cidr"])
     self.assertIsNone(context.config["dns_nameservers"])