Example #1
0
    def test_subnet_update_set_alloc_pool_cache_concurrency(self):
        subnet = {"cidr": "192.168.10.0/24"}
        subnet_db = db_api.subnet_create(self.context, **subnet)
        self.context.session.flush()

        # establish second session
        old_session = self.context.session
        self.context._session = None

        subnet_to_delete = db_api.subnet_find(
            self.context, id=subnet_db.id, scope=db_api.ONE)
        db_api.subnet_delete(self.context, subnet_to_delete)
        self.context.session.flush()

        # restore first session
        self.context._session = old_session

        try:
            db_api.subnet_update_set_alloc_pool_cache(
                self.context, subnet_db, {"foo": "bar"})
            self.context.session.flush()
        except exc.StaleDataError as e:
            self.fail("Did not expect StaleDataError exception: {0}".format(e))
        self.assertEqual(subnet_db["_allocation_pool_cache"],
                         "{\"foo\": \"bar\"}")
Example #2
0
 def _stubs(self, network, subnet):
     self.ipam = quark.ipam.QuarkIpamANY()
     with self.context.session.begin():
         net_mod = db_api.network_create(self.context, **network)
         subnet["network"] = net_mod
         sub_mod = db_api.subnet_create(self.context, **subnet)
     yield net_mod
     with self.context.session.begin():
         db_api.subnet_delete(self.context, sub_mod)
         db_api.network_delete(self.context, net_mod)
Example #3
0
 def _stubs(self, network, subnet):
     self.ipam = quark.ipam.QuarkIpamANY()
     with self.context.session.begin():
         next_ip = subnet.pop("next_auto_assign_ip", 0)
         net_mod = db_api.network_create(self.context, **network)
         subnet["network"] = net_mod
         sub_mod = db_api.subnet_create(self.context, **subnet)
         # NOTE(asadoughi): update after cidr constructor has been invoked
         db_api.subnet_update(self.context,
                              sub_mod,
                              next_auto_assign_ip=next_ip)
     yield net_mod
     with self.context.session.begin():
         db_api.subnet_delete(self.context, sub_mod)
         db_api.network_delete(self.context, net_mod)
Example #4
0
 def _stubs(self, network, subnet):
     self.ipam = quark.ipam.QuarkIpamANY()
     with self.context.session.begin():
         next_ip = subnet.pop("next_auto_assign_ip", 0)
         net_mod = db_api.network_create(self.context, **network)
         subnet["network"] = net_mod
         sub_mod = db_api.subnet_create(self.context, **subnet)
         # NOTE(asadoughi): update after cidr constructor has been invoked
         db_api.subnet_update(self.context,
                              sub_mod,
                              next_auto_assign_ip=next_ip)
     yield net_mod
     with self.context.session.begin():
         db_api.subnet_delete(self.context, sub_mod)
         db_api.network_delete(self.context, net_mod)
Example #5
0
 def _stubs(self, network, subnets, ipam_strategy):
     self.ipam = ipam_strategy
     with self.context.session.begin():
         net_mod = db_api.network_create(self.context, **network)
         next_ip = []
         sub_mod = []
         for sub in subnets:
             next_ip.append(sub.pop("next_auto_assign_ip", 0))
             sub["network"] = net_mod
             sub_mod.append(db_api.subnet_create(self.context, **sub))
         for sub, ip_next in zip(sub_mod, next_ip):
             # NOTE(asadoughi): update after cidr constructor has been
             # invoked
             db_api.subnet_update(self.context,
                                  sub,
                                  next_auto_assign_ip=ip_next)
     yield net_mod, sub_mod
     with self.context.session.begin():
         for sub in sub_mod:
             db_api.subnet_delete(self.context, sub)
         db_api.network_delete(self.context, net_mod)
Example #6
0
 def _stubs(self, network, subnets, ipam_strategy):
     self.ipam = ipam_strategy
     with self.context.session.begin():
         net_mod = db_api.network_create(self.context, **network)
         next_ip = []
         sub_mod = []
         for sub in subnets:
             next_ip.append(sub.pop("next_auto_assign_ip", 0))
             sub["network"] = net_mod
             sub_mod.append(db_api.subnet_create(self.context, **sub))
         for sub, ip_next in zip(sub_mod, next_ip):
             # NOTE(asadoughi): update after cidr constructor has been
             # invoked
             db_api.subnet_update(self.context,
                                  sub,
                                  next_auto_assign_ip=ip_next)
     yield net_mod, sub_mod
     with self.context.session.begin():
         for sub in sub_mod:
             db_api.subnet_delete(self.context, sub)
         db_api.network_delete(self.context, net_mod)
Example #7
0
 def _stubs(self, network, subnet, ip_address1, ip_address2, ip_address3):
     with self.context.session.begin():
         net_mod = db_api.network_create(self.context, **network)
         subnet["network"] = net_mod
         sub_mod = db_api.subnet_create(self.context, **subnet)
         # set tenant id to "123"
         ip_address1['network_id'] = net_mod.id
         ip_address1['subnet_id'] = sub_mod.id
         self.context.tenant_id = 123
         ip_address1 = db_api.ip_address_create(self.context, **ip_address1)
         # set tenant_id=456
         ip_address2['network_id'] = net_mod.id
         ip_address2['subnet_id'] = sub_mod.id
         self.context.tenant_id = 456
         ip_address2 = db_api.ip_address_create(self.context, **ip_address2)
         # set tenant id = "123" to test the list of IPs
         ip_address3['network_id'] = net_mod.id
         ip_address3['subnet_id'] = sub_mod.id
         self.context.tenant_id = 123
         ip_address3 = db_api.ip_address_create(self.context, **ip_address3)
     yield net_mod
     with self.context.session.begin():
         db_api.subnet_delete(self.context, sub_mod)
         db_api.network_delete(self.context, net_mod)
Example #8
0
 def _stubs(self, network, subnet, ip_address1, ip_address2, ip_address3):
     with self.context.session.begin():
         net_mod = db_api.network_create(self.context, **network)
         subnet["network"] = net_mod
         sub_mod = db_api.subnet_create(self.context, **subnet)
         # set tenant id to "123"
         ip_address1['network_id'] = net_mod.id
         ip_address1['subnet_id'] = sub_mod.id
         self.context.tenant_id = 123
         ip_address1 = db_api.ip_address_create(self.context, **ip_address1)
         # set tenant_id=456
         ip_address2['network_id'] = net_mod.id
         ip_address2['subnet_id'] = sub_mod.id
         self.context.tenant_id = 456
         ip_address2 = db_api.ip_address_create(self.context, **ip_address2)
         # set tenant id = "123" to test the list of IPs
         ip_address3['network_id'] = net_mod.id
         ip_address3['subnet_id'] = sub_mod.id
         self.context.tenant_id = 123
         ip_address3 = db_api.ip_address_create(self.context, **ip_address3)
     yield net_mod
     with self.context.session.begin():
         db_api.subnet_delete(self.context, sub_mod)
         db_api.network_delete(self.context, net_mod)
Example #9
0
def _delete_subnet(context, subnet):
    if subnet.allocated_ips:
        raise exceptions.SubnetInUse(subnet_id=subnet["id"])
    db_api.subnet_delete(context, subnet)
Example #10
0
def _delete_subnet(context, subnet):
    if subnet.allocated_ips:
        raise exceptions.SubnetInUse(subnet_id=subnet["id"])
    db_api.subnet_delete(context, subnet)