def _stubs(self, nets=None, subnets=None): net_mods = [] if isinstance(nets, list): for net in nets: subnet_mods = [] subnets = net.pop('subnets', []) for subnet in subnets: subnet_mod = models.Subnet() subnet_mod.update(subnet) subnet_mods.append(subnet_mod) net_mod = models.Network() net_mod.update(net) net_mod["subnets"] = subnet_mods net_mods.append(net_mod) else: if nets: net_mods = nets.copy() else: net_mods = nets db_mod = "quark.db.api" db_api.STRATEGY = network_strategy.JSONStrategy(self.strategy_json) network_strategy.STRATEGY = network_strategy.JSONStrategy( self.strategy_json) with mock.patch("%s._network_find" % db_mod) as net_find: net_find.return_value = net_mods yield net_find
def test_get_provider_subnets(self): json_strategy = network_strategy.JSONStrategy() expected = ["public_v4", "public_v6"] subs = json_strategy.get_provider_subnets() for sub in expected: self.assertTrue(sub in subs) self.assertEqual(2, len(subs))
def setUp(self): super(TestIronicDriverBase, self).setUp() net_strategy = { "1": { "bridge": "publicnet", "subnets": { "4": "1", "6": "2" } }, "2": { "bridge": "publicnet", "subnets": { "3": "1", "6": "4" } } } strategy = json.dumps(net_strategy) quark.drivers.ironic_driver.STRATEGY = network_strategy.JSONStrategy( strategy) cfg.CONF.set_override("default_net_strategy", strategy, "QUARK") cfg.CONF.set_override("operation_delay", 0, "IRONIC") cfg.CONF.set_override("operation_backoff", 0, "IRONIC")
def test_subnet_ids_for_network(self): json_strategy = network_strategy.JSONStrategy() expected = ["public_v4", "public_v6"] subs = json_strategy.subnet_ids_for_network("public_network") for sub in expected: self.assertTrue(sub in subs) self.assertEqual(2, len(subs))
def setUp(self): super(TestUnmanagedDriver, self).setUp() self.strategy = {"public_network": {"bridge": "xenbr0", "subnets": {"4": "public"}}} strategy_json = json.dumps(self.strategy) self.driver = unmanaged.UnmanagedDriver() unmanaged.STRATEGY = network_strategy.JSONStrategy(strategy_json)
def test_split_network_ids(self): json_strategy = network_strategy.JSONStrategy() net_ids = ["foo_net", "public_network"] tenant, assignable = json_strategy.split_network_ids(net_ids) self.assertTrue("foo_net" in tenant) self.assertTrue("foo_net" not in assignable) self.assertTrue("public_network" not in tenant) self.assertTrue("public_network" in assignable)
def test_split_subnet_ids(self): json_strategy = network_strategy.JSONStrategy() subnet_ids = ["tenant_subnet", "public_v6"] tenant, assignable = json_strategy.split_subnet_ids(subnet_ids) self.assertTrue("tenant_subnet" in tenant) self.assertTrue("tenant_subnet" not in assignable) self.assertTrue("public_v6" not in tenant) self.assertTrue("public_v6" in assignable)
def setUp(self): super(BaseFloatingIPTest, self).setUp() self.public_net_id = "00000000-0000-0000-0000-000000000000" net_stat = '{"%s": {}}' % self.public_net_id cfg.CONF.set_override('default_net_strategy', net_stat, group='QUARK') old_strat = db_api.STRATEGY def reset_strategy(): db_api.STRATEGY = old_strat db_api.STRATEGY = network_strategy.JSONStrategy() self.addCleanup(reset_strategy) admin_ctx = context.get_admin_context() self._setup_mock_requests() self.plugin = quark.plugin.Plugin() mac = {'mac_address_range': dict(cidr="AA:BB:CC")} macrng_api.create_mac_address_range(admin_ctx, mac) with admin_ctx.session.begin(): tenant = 'rackspace' floating_net = dict(name='publicnet', tenant_id=tenant, id=self.public_net_id) self.floating_network = db_api.network_create( self.context, **floating_net) self.pub_net_cidr = "10.1.1.0/24" floating_subnet = dict(id=self.public_net_id, cidr=self.pub_net_cidr, ip_policy=None, tenant_id=tenant, segment_id='floating_ip', network_id=self.floating_network.id) self.floating_subnet = db_api.subnet_create( self.context, **floating_subnet) user_net = dict(name='user_network', tenant_id='fake') self.user_network = self.plugin.create_network( self.context, {'network': user_net}) user_subnet = dict(cidr="192.168.1.0/24", ip_policy=None, tenant_id="fake", network_id=self.user_network['id']) self.user_subnet = self.plugin.create_subnet( self.context, {'subnet': user_subnet}) user_port1 = dict(name='user_port1', network_id=self.user_network['id']) self.user_port1 = self.plugin.create_port( self.context, {'port': user_port1}) user_port2 = dict(name='user_port2', network_id=self.user_network['id']) self.user_port2 = self.plugin.create_port( self.context, {'port': user_port2})
def setUp(self): super(TestQuarkGetNetworksShared, self).setUp() self.strategy = { "public_network": { "bridge": "xenbr0", "subnets": { "4": "public_v4", "6": "public_v6" } } } self.strategy_json = json.dumps(self.strategy) self.old = plugin_views.STRATEGY plugin_views.STRATEGY = network_strategy.JSONStrategy( self.strategy_json) cfg.CONF.set_override("default_net_strategy", self.strategy_json, "QUARK")
def setUp(self): super(TestQuarkGetNetworksShared, self).setUp() self.strategy = { "public_network": { "required": True, "bridge": "xenbr0", "children": { "nova": "child_net" } } } self.strategy_json = json.dumps(self.strategy) self.old = plugin_views.STRATEGY plugin_views.STRATEGY = network_strategy.JSONStrategy( self.strategy_json) cfg.CONF.set_override("default_net_strategy", self.strategy_json, "QUARK")
def test_get_network_for_subnet_matches_none(self): json_strategy = network_strategy.JSONStrategy() net = json_strategy.get_network_for_subnet("tenant_v4") self.assertIsNone(net)
def test_get_network_for_subnet(self): json_strategy = network_strategy.JSONStrategy() net = json_strategy.get_network_for_subnet("public_v4") self.assertEqual("public_network", net)
def test_get_parent_network_no_parent(self): json_strategy = network_strategy.JSONStrategy(None) parent_net = json_strategy.get_parent_network("bar_network") self.assertEqual(parent_net, "bar_network")
def test_get_provider_networks(self): json_strategy = network_strategy.JSONStrategy() expected = "public_network" nets = json_strategy.get_provider_networks() self.assertTrue(expected in nets) self.assertEqual(1, len(nets))
def test_best_match_network_no_valid_child(self): json_strategy = network_strategy.JSONStrategy(None) with self.assertRaises(exceptions.NetworkNotFound): json_strategy.best_match_network_id(self.context, "public_network", "derpa")
def test_get_assignable_networks_custom_strategy(self): custom = {"private_network": self.strategy["public_network"]} json_strategy = network_strategy.JSONStrategy(json.dumps(custom)) net_ids = json_strategy.get_assignable_networks(self.context) self.assertEqual("private_network", net_ids[0])
def test_get_assignable_networks_default_strategy(self): json_strategy = network_strategy.JSONStrategy() net_ids = json_strategy.get_assignable_networks(self.context) self.assertEqual("public_network", net_ids[0])
def test_get_network(self): json_strategy = network_strategy.JSONStrategy() net = json_strategy.get_network("public_network") self.assertEqual(net["bridge"], "xenbr0")
def test_get_provider_subnet_id_matches_none(self): json_strategy = network_strategy.JSONStrategy() net_id = "tenant_network" ip_version = 4 sub = json_strategy.get_provider_subnet_id(net_id, ip_version) self.assertIsNone(sub)
def test_get_provider_subnet_id(self): json_strategy = network_strategy.JSONStrategy() net_id = "public_network" ip_version = 4 sub = json_strategy.get_provider_subnet_id(net_id, ip_version) self.assertEqual(sub, "public_v4")
def test_subnet_ids_for_network_matches_none(self): json_strategy = network_strategy.JSONStrategy() subs = json_strategy.subnet_ids_for_network("tenant_network") self.assertIsNone(subs)
def test_best_match_network_id(self): json_strategy = network_strategy.JSONStrategy(None) net = json_strategy.best_match_network_id(self.context, "public_network", "nova") self.assertEqual(net, "child_net")
def test_get_parent_network(self): json_strategy = network_strategy.JSONStrategy(None) parent_net = json_strategy.get_parent_network("child_net") self.assertEqual(parent_net, "public_network")
def test_is_provider_subnet(self): json_strategy = network_strategy.JSONStrategy() self.assertTrue(json_strategy.is_provider_subnet("public_v4"))
def test_is_not_provider_subnet(self): json_strategy = network_strategy.JSONStrategy() self.assertFalse(json_strategy.is_provider_network("tenant_v4"))
def test_best_match_network_net_not_in_strategy(self): json_strategy = network_strategy.JSONStrategy(None) net = json_strategy.best_match_network_id(self.context, "foo_net", "nova") self.assertEqual(net, "foo_net")