Beispiel #1
0
 def _create_subnet(self, network, namestart='subnet-smoke-'):
     """
     Create a subnet for the given network within the cidr block
     configured for tenant networks.
     """
     cfg = self.config.network
     tenant_cidr = netaddr.IPNetwork(cfg.tenant_network_cidr)
     result = None
     # Repeatedly attempt subnet creation with sequential cidr
     # blocks until an unallocated block is found.
     for subnet_cidr in tenant_cidr.subnet(cfg.tenant_network_mask_bits):
         body = dict(subnet=dict(
             ip_version=4,
             network_id=network.id,
             tenant_id=network.tenant_id,
             cidr=str(subnet_cidr),
         ), )
         try:
             result = self.network_client.create_subnet(body=body)
             break
         except exc.NeutronClientException as e:
             is_overlapping_cidr = 'overlaps with another subnet' in str(e)
             if not is_overlapping_cidr:
                 raise
     self.assertIsNotNone(result, 'Unable to allocate tenant network')
     subnet = net_common.DeletableSubnet(client=self.network_client,
                                         **result['subnet'])
     self.assertEqual(subnet.cidr, str(subnet_cidr))
     self.set_resource(rand_name(namestart), subnet)
     return subnet
Beispiel #2
0
 def _create_pool(self):
     """Create a pool with ROUND_ROBIN algorithm."""
     # get tenant subnet and verify there's only one
     subnet = self._list_subnets(tenant_id=self.tenant_id)[0]
     self.subnet = net_common.DeletableSubnet(client=self.network_client,
                                              **subnet['subnet'])
     self.pool = super(TestLoadBalancerBasic,
                       self)._create_pool('ROUND_ROBIN', 'HTTP',
                                          self.subnet.id)
     self.assertTrue(self.pool)
 def _create_pool(self):
     """Create a pool with ROUND_ROBIN algorithm."""
     # get tenant subnet and verify there's only one
     subnet = self._list_subnets(tenant_id=self.tenant_id)[0]
     self.subnet = net_common.DeletableSubnet(client=self.network_client,
                                              **subnet)
     self.pool = super(TestLoadBalancerBasic,
                       self)._create_pool(lb_method='ROUND_ROBIN',
                                          protocol='HTTP',
                                          subnet_id=self.subnet.id)
     self.addCleanup(self.cleanup_wrapper, self.pool)
     self.assertTrue(self.pool)
Beispiel #4
0
    def _create_subnet(self, network, namestart='subnet-smoke-', **kwargs):
        """
        Create a subnet for the given network within the cidr block
        configured for tenant networks.
        """

        def cidr_in_use(cidr, tenant_id):
            """
            :return True if subnet with cidr already exist in tenant
                False else
            """
            cidr_in_use = self._list_subnets(tenant_id=tenant_id, cidr=cidr)
            return len(cidr_in_use) != 0

        tenant_cidr = netaddr.IPNetwork(CONF.network.tenant_network_cidr)
        result = None
        # Repeatedly attempt subnet creation with sequential cidr
        # blocks until an unallocated block is found.
        for subnet_cidr in tenant_cidr.subnet(
            CONF.network.tenant_network_mask_bits):
            str_cidr = str(subnet_cidr)
            if cidr_in_use(str_cidr, tenant_id=network.tenant_id):
                continue

            body = dict(
                subnet=dict(
                    name=data_utils.rand_name(namestart),
                    ip_version=4,
                    network_id=network.id,
                    tenant_id=network.tenant_id,
                    cidr=str_cidr,
                ),
            )
            body['subnet'].update(kwargs)
            try:
                result = self.network_client.create_subnet(body=body)
                break
            except exc.NeutronClientException as e:
                is_overlapping_cidr = 'overlaps with another subnet' in str(e)
                if not is_overlapping_cidr:
                    raise
        self.assertIsNotNone(result, 'Unable to allocate tenant network')
        subnet = net_common.DeletableSubnet(client=self.network_client,
                                            **result['subnet'])
        self.assertEqual(subnet.cidr, str_cidr)
        self.set_resource(data_utils.rand_name(namestart), subnet)
        return subnet