Exemple #1
0
 def test_subnet_request(self):
     request = ipam.AnySubnetRequest(self.tenant_id,
                                     self.subnet_id,
                                     constants.IPv4,
                                     24,
                                     gateway_ip='0.0.0.1')
     self.assertEqual(24, request.prefixlen)
 def test_insufficient_prefix_space_for_any_allocation(self):
     sp = self._create_subnet_pool(self.plugin, self.ctx, 'test-sp',
                                   ['10.1.1.0/24', '192.168.1.0/24'], 21, 4)
     sp = self.plugin._get_subnetpool(self.ctx, sp['id'])
     sa = subnet_alloc.SubnetAllocator(sp)
     req = ipam.AnySubnetRequest(self._tenant_id, uuidutils.generate_uuid(),
                                 constants.IPv4, 21)
     self.assertRaises(n_exc.SubnetAllocationError, sa.allocate_subnet,
                       self.ctx.session, req)
 def test_allocate_any_subnet_gateway(self):
     sp = self._create_subnet_pool(self.plugin, self.ctx, 'test-sp',
                                   ['10.1.0.0/16', '192.168.1.0/24'], 21, 4)
     sp = self.plugin._get_subnetpool(self.ctx, sp['id'])
     with self.ctx.session.begin(subtransactions=True):
         sa = subnet_alloc.SubnetAllocator(sp)
         req = ipam.AnySubnetRequest(self._tenant_id,
                                     uuidutils.generate_uuid(),
                                     constants.IPv4, 21)
         res = sa.allocate_subnet(self.ctx.session, req)
         detail = res.get_details()
         self.assertEqual(detail.gateway_ip, detail.subnet.network + 1)
Exemple #4
0
    def _make_subnet_request(self, tenant_id, subnet, subnetpool):
        cidr = subnet.get('cidr')
        subnet_id = subnet.get('id', uuidutils.generate_uuid())
        is_any_subnetpool_request = not attributes.is_attr_set(cidr)

        if is_any_subnetpool_request:
            prefixlen = subnet['prefixlen']
            if not attributes.is_attr_set(prefixlen):
                prefixlen = int(subnetpool['default_prefixlen'])

            return ipam.AnySubnetRequest(
                tenant_id, subnet_id,
                utils.ip_version_from_int(subnetpool['ip_version']), prefixlen)
        else:
            return ipam.SpecificSubnetRequest(tenant_id, subnet_id, cidr)
Exemple #5
0
 def test_allocate_any_subnet(self):
     prefix_list = ['10.1.0.0/16', '192.168.1.0/24']
     sp = self._create_subnet_pool(self.plugin, self.ctx, 'test-sp',
                                   prefix_list, 21, 4)
     sp = self.plugin._get_subnetpool(self.ctx, sp['id'])
     with self.ctx.session.begin(subtransactions=True):
         sa = subnet_alloc.SubnetAllocator(sp, self.ctx)
         req = ipam.AnySubnetRequest(self._tenant_id,
                                     uuidutils.generate_uuid(),
                                     constants.IPv4, 21)
         res = sa.allocate_subnet(req)
         detail = res.get_details()
         prefix_set = netaddr.IPSet(iterable=prefix_list)
         allocated_set = netaddr.IPSet(iterable=[detail.subnet_cidr])
         self.assertTrue(allocated_set.issubset(prefix_set))
         self.assertEqual(detail.prefixlen, 21)
Exemple #6
0
 def test_allocate_any_subnet_fails(self):
     self.assertRaises(
         ipam_exc.InvalidSubnetRequestType,
         self.ipam_pool.allocate_subnet,
         ipam.AnySubnetRequest(self._tenant_id, 'meh', constants.IPv4, 24))