def test_port_list_device_owner_found_returns_only_those(self): # create a network network = dict(name="public", tenant_id="fake", network_plugin="BASE") net_mod = db_api.network_create(self.context, **network) # create ports port1 = dict(network_id=net_mod["id"], backend_key="1", device_id="1", device_owner="Doge") port2 = dict(network_id=net_mod["id"], backend_key="1", device_id="1", device_owner=port1["device_owner"]) port3 = dict(network_id=net_mod["id"], backend_key="1", device_id="1", device_owner="network:dhcp") port_mod1 = db_api.port_create(self.context, **port1) port_mod2 = db_api.port_create(self.context, **port2) port_mod3 = db_api.port_create(self.context, **port3) res = db_api.port_find(self.context, scope=db_api.ALL, device_owner=port3["device_owner"]) self.assertTrue(len(res) == 1) self.assertTrue(res[0]["device_owner"] == port3["device_owner"]) res = db_api.port_find(self.context, scope=db_api.ALL, device_owner=port1["device_owner"]) self.assertTrue(len(res) == 2) self.assertTrue(res[0]["device_owner"] == res[1]["device_owner"] == port1["device_owner"]) db_api.network_delete(self.context, net_mod) db_api.port_delete(self.context, port_mod1) db_api.port_delete(self.context, port_mod2) db_api.port_delete(self.context, port_mod3)
def test_ports_sorted_by_created_at(self): # create a network network = dict(name="public", tenant_id="fake", network_plugin="BASE") net_mod = db_api.network_create(self.context, **network) # create ports port1 = dict(network_id=net_mod["id"], backend_key="1", device_id="1") port2 = dict(network_id=net_mod["id"], backend_key="1", device_id="1") port3 = dict(network_id=net_mod["id"], backend_key="1", device_id="1") port_mod1 = db_api.port_create(self.context, **port1) port_mod2 = db_api.port_create(self.context, **port2) port_mod3 = db_api.port_create(self.context, **port3) res = db_api.port_find(context=self.context, limit=None, sorts=['created_at'], marker_obj=None, fields=None, scope=db_api.ALL) self.assertTrue( res[0]["created_at"] < res[1]["created_at"] < res[2]['created_at']) self.assertTrue(res[0]['id'] == port_mod1['id']) self.assertTrue(res[1]['id'] == port_mod2['id']) self.assertTrue(res[2]['id'] == port_mod3['id']) db_api.network_delete(self.context, net_mod) db_api.port_delete(self.context, port_mod1) db_api.port_delete(self.context, port_mod2) db_api.port_delete(self.context, port_mod3)
def delete_network(context, id): """Delete a network. : param context: neutron api request context : param id: UUID representing the network to delete. """ LOG.info("delete_network %s for tenant %s" % (id, context.tenant_id)) with context.session.begin(): net = db_api.network_find(context=context, limit=None, sorts=['id'], marker=None, page_reverse=False, id=id, scope=db_api.ONE) if not net: raise n_exc.NetworkNotFound(net_id=id) if not context.is_admin: if STRATEGY.is_provider_network(net.id): raise n_exc.NotAuthorized(net_id=id) if net.ports: raise n_exc.NetworkInUse(net_id=id) net_driver = registry.DRIVER_REGISTRY.get_driver(net["network_plugin"]) net_driver.delete_network(context, id) for subnet in net["subnets"]: subnets._delete_subnet(context, subnet) db_api.network_delete(context, net)
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)
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)
def delete_network(context, id): """Delete a network. : param context: neutron api request context : param id: UUID representing the network to delete. """ LOG.info("delete_network %s for tenant %s" % (id, context.tenant_id)) net = db_api.network_find(context, id=id, scope=db_api.ONE) if not net: raise exceptions.NetworkNotFound(net_id=id) if net.ports: raise exceptions.NetworkInUse(net_id=id) net_driver.delete_network(context, id) for subnet in net["subnets"]: subnets._delete_subnet(context, subnet) db_api.network_delete(context, net)
def test_ports_sorted_by_created_at(self): # create a network network = dict(name="public", tenant_id="fake", network_plugin="BASE") net_mod = db_api.network_create(self.context, **network) # create ports port1 = dict(network_id=net_mod["id"], backend_key="1", device_id="1") port2 = dict(network_id=net_mod["id"], backend_key="1", device_id="1") port3 = dict(network_id=net_mod["id"], backend_key="1", device_id="1") port_mod1 = db_api.port_create(self.context, **port1) port_mod2 = db_api.port_create(self.context, **port2) port_mod3 = db_api.port_create(self.context, **port3) res = db_api.port_find(self.context, scope=db_api.ALL) self.assertTrue(res[0]["created_at"] < res[1]["created_at"] < res[2]["created_at"]) db_api.network_delete(self.context, net_mod) db_api.port_delete(self.context, port_mod1) db_api.port_delete(self.context, port_mod2) db_api.port_delete(self.context, port_mod3)
def delete_network(context, id): """Delete a network. : param context: neutron api request context : param id: UUID representing the network to delete. """ LOG.info("delete_network %s for tenant %s" % (id, context.tenant_id)) with context.session.begin(): net = db_api.network_find(context, None, None, None, False, id=id, scope=db_api.ONE) if not net: raise exceptions.NetworkNotFound(net_id=id) if net.ports: raise exceptions.NetworkInUse(net_id=id) net_driver = registry.DRIVER_REGISTRY.get_driver(net["network_plugin"]) net_driver.delete_network(context, id) for subnet in net["subnets"]: subnets._delete_subnet(context, subnet) db_api.network_delete(context, net)
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)
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)