Exemple #1
0
    def test_allocate_v6_with_mac_fails_policy_raises(self):
        cidr = netaddr.IPNetwork("fe80::dead:beef/64")
        allocation_pool = [{"start": cidr[-4], "end": cidr[-2]}]
        subnet = dict(allocation_pools=allocation_pool,
                      cidr="fe80::dead:beef/64",
                      ip_version=6,
                      next_auto_assign_ip=0,
                      tenant_id="fake")
        subnet = {"subnet": subnet}

        network = dict(name="public", tenant_id="fake", network_plugin="BASE")
        network = {"network": network}

        ip_policy = {"exclude": ["fe80::dead:beef/64"]}
        ip_policy = {"ip_policy": ip_policy}

        mac = models.MacAddress()
        mac["address"] = netaddr.EUI("AA:BB:CC:DD:EE:FF")

        old_override = cfg.CONF.QUARK.v6_allocation_attempts
        cfg.CONF.set_override('v6_allocation_attempts', 1, 'QUARK')

        with self._stubs(network, subnet, ip_policy) as (net, sub, ipp):
            with self.assertRaises(n_exc.IpAddressGenerationFailure):
                self.ipam.allocate_ip_address(self.context, [],
                                              net["id"],
                                              0,
                                              0,
                                              subnets=[sub["id"]])
        cfg.CONF.set_override('v6_allocation_attempts', old_override, 'QUARK')
Exemple #2
0
def mac_address_create(context, **mac_dict):
    mac_address = models.MacAddress()
    mac_address.update(mac_dict)
    mac_address["tenant_id"] = context.tenant_id
    mac_address["deallocated"] = False
    mac_address["deallocated_at"] = None
    context.session.add(mac_address)
    return mac_address
Exemple #3
0
 def migrate_macs(self):
     """2. Migrate the m.mac_address -> q.quark_mac_addresses
     This is the next simplest but the relationship between quark_networks
     and quark_mac_addresses may be complicated to set up (if it exists)
     """
     """Only migrating the first mac_address_range from melange."""
     import netaddr
     mac_range = self.melange_session.query(
         melange.MacAddressRanges).first()
     cidr = mac_range.cidr
     init_id(self.json_data, 'mac_ranges', mac_range.id)
     try:
         cidr, first_address, last_address = to_mac_range(cidr)
     except ValueError as e:
         set_reason(self.json_data, mac_range.id, "mac_ranges", e.message)
         self.log.critical(e.message)
         return None
     except netaddr.AddrFormatError as afe:
         set_reason(self.json_data, mac_range.id, "mac_ranges", afe.message)
         self.log.critical(afe.message)
         return None
     q_range = quarkmodels.MacAddressRange(
         id=mac_range.id,
         cidr=cidr,
         created_at=mac_range.created_at,
         first_address=first_address,
         next_auto_assign_mac=first_address,
         last_address=last_address)
     self.add_to_session(q_range, 'mac_ranges', q_range.id)
     res = self.melange_session.query(melange.MacAddresses).all()
     no_network_count = 0
     for mac in res:
         init_id(self.json_data, 'macs', mac.address)
         if mac.interface_id not in self.interface_network:
             no_network_count += 1
             r = "mac.interface_id {0} not in self.interface_network"\
                 .format(mac.interface_id)
             set_reason(self.json_data, 'macs', mac.address, r)
             continue
         tenant_id = self.interface_tenant[mac.interface_id]
         q_mac = quarkmodels.MacAddress(tenant_id=tenant_id,
                                        created_at=mac.created_at,
                                        mac_address_range_id=mac_range.id,
                                        address=mac.address)
         q_port = self.port_cache[mac.interface_id]
         q_port.mac_address = q_mac.address
         self.add_to_session(q_mac, 'macs', q_mac.address)
     self.log.info("skipped {0} mac addresses".format(
         str(no_network_count)))  # noqa