def test__init__readfile(self): with mock.patch.object(lla.LinkLocalAllocator, '_read') as read: read.return_value = ["da873ca2,169.254.31.28/31\n"] a = lla.LinkLocalAllocator('/file', self.subnet.cidr) self.assertTrue('da873ca2' in a.remembered) self.assertEqual({}, a.allocations)
def test_allocate(self): a = lla.LinkLocalAllocator('/file', self.subnet.cidr) with mock.patch.object(lla.LinkLocalAllocator, '_write') as write: subnet = a.allocate('deadbeef') self.assertTrue('deadbeef' in a.allocations) self.assertTrue(subnet not in a.pool) self._check_allocations(a.allocations) write.assert_called_once_with(['deadbeef,%s\n' % subnet.cidr])
def __init__(self, host): # dvr data self.agent_gateway_port = None self.fip_ns_subscribers = set() self.local_subnets = lla.LinkLocalAllocator( os.path.join(self.conf.state_path, 'fip-linklocal-networks'), FIP_LL_SUBNET) self.fip_priorities = set(range(FIP_PR_START, FIP_PR_END)) super(AgentMixin, self).__init__(host)
def test_release(self): with mock.patch.object(lla.LinkLocalAllocator, '_write') as write: a = lla.LinkLocalAllocator('/file', self.subnet.cidr) subnet = a.allocate('deadbeef') write.reset_mock() a.release('deadbeef') self.assertTrue('deadbeef' not in a.allocations) self.assertTrue(subnet in a.pool) self.assertEqual({}, a.allocations) write.assert_called_once_with([])
def test_allocate_from_file(self): with mock.patch.object(lla.LinkLocalAllocator, '_read') as read: read.return_value = ["deadbeef,169.254.31.88/31\n"] a = lla.LinkLocalAllocator('/file', self.subnet.cidr) with mock.patch.object(lla.LinkLocalAllocator, '_write') as write: subnet = a.allocate('deadbeef') self.assertEqual(netaddr.IPNetwork('169.254.31.88/31'), subnet) self.assertTrue(subnet not in a.pool) self._check_allocations(a.allocations) self.assertFalse(write.called)
def __init__(self, ext_net_id, agent_conf, driver, use_ipv6): self._ext_net_id = ext_net_id self.agent_conf = agent_conf self.driver = driver self.use_ipv6 = use_ipv6 self.agent_gateway_port = None self._subscribers = set() self._rule_priorities = set(range(FIP_PR_START, FIP_PR_END)) self._iptables_manager = iptables_manager.IptablesManager( namespace=self.get_name(), use_ipv6=self.use_ipv6) path = os.path.join(agent_conf.state_path, 'fip-linklocal-networks') self.local_subnets = lla.LinkLocalAllocator(path, FIP_LL_SUBNET) self.destroyed = False
def test_allocate_exhausted_pool(self): subnet = netaddr.IPNetwork('169.254.31.0/31') with mock.patch.object(lla.LinkLocalAllocator, '_read') as read: read.return_value = ["deadbeef,169.254.31.0/31\n"] a = lla.LinkLocalAllocator('/file', subnet.cidr) with mock.patch.object(lla.LinkLocalAllocator, '_write') as write: allocation = a.allocate('abcdef12') self.assertEqual(subnet, allocation) self.assertFalse('deadbeef' in a.allocations) self.assertTrue('abcdef12' in a.allocations) self.assertTrue(allocation not in a.pool) self._check_allocations(a.allocations) write.assert_called_once_with(['abcdef12,%s\n' % allocation.cidr]) self.assertRaises(RuntimeError, a.allocate, 'deadbeef')
def __init__(self, ext_net_id, agent_conf, driver, use_ipv6): name = self._get_ns_name(ext_net_id) super(FipNamespace, self).__init__(name, agent_conf, driver, use_ipv6) self._ext_net_id = ext_net_id self.agent_conf = agent_conf self.driver = driver self.use_ipv6 = use_ipv6 self.agent_gateway_port = None self._subscribers = set() path = os.path.join(agent_conf.state_path, 'fip-priorities') self._rule_priorities = frpa.FipRulePriorityAllocator( path, FIP_PR_START, FIP_PR_END) self._iptables_manager = iptables_manager.IptablesManager( namespace=self.get_name(), use_ipv6=self.use_ipv6) path = os.path.join(agent_conf.state_path, 'fip-linklocal-networks') self.local_subnets = lla.LinkLocalAllocator(path, constants.DVR_FIP_LL_CIDR) self.destroyed = False
def test__init__(self): a = lla.LinkLocalAllocator('/file', self.subnet.cidr) self.assertEqual('/file', a.state_file) self.assertEqual({}, a.allocations)