def test_get_ports_filter_with_ip_and_device(self): with self._stubs(self.network, self.subnet, self.ports_info4) as ( net, sub, ports): network = dict(name="xx", tenant_id="fake", network_plugin="BASE") xx_network = {"network": network} xx_net = network_api.create_network(self.context, xx_network) subnet = dict(id=2, ip_version=4, next_auto_assign_ip=2, cidr=self.cidr, first_ip=self.ip_network.first, last_ip=self.ip_network.last, ip_policy=None, tenant_id="fake") xx_subnet = {"subnet": subnet} xx_subnet['subnet']['network_id'] = xx_net['id'] subnet_api.create_subnet(self.context, xx_subnet) port_info = {'port': dict(device_id='a')} port_info['port']['network_id'] = xx_net['id'] port_api.create_port(self.context, port_info) port_ids1 = [ports[0]['id'], ports[1]['id']] shared_ip1 = {'ip_address': dict(port_ids=port_ids1, network_id=net['id'], version=4)} ip1 = ip_api.create_ip_address(self.context, shared_ip1) filters = dict(device_id='a') ports = ip_api.get_ports_for_ip_address(self.context, ip1['id'], filters=filters) self.assertEqual(1, len(ports)) filters = dict(device_id='a') ports = port_api.get_ports(self.context, filters=filters) self.assertEqual(2, len(ports))
def _stubs(self, network, subnet): self.ipam = quark.ipam.QuarkIpamANY() with contextlib.nested(mock.patch("neutron.common.rpc.get_notifier")): net = network_api.create_network(self.context, network) subnet['subnet']['network_id'] = net['id'] sub1 = subnet_api.create_subnet(self.context, subnet) yield net, sub1
def _stubs(self, network_info, subnet_v4_info, subnet_v6_info=None): with contextlib.nested(mock.patch("neutron.common.rpc.get_notifier"), mock.patch("neutron.quota.QUOTAS.limit_check")): self.context.is_admin = True net = network_api.create_network(self.context, network_info) mac = {'mac_address_range': dict(cidr="AA:BB:CC")} macrng_api.create_mac_address_range(self.context, mac) self.context.is_admin = False subnet_v4_info['subnet']['network_id'] = net['id'] sub_v4 = subnet_api.create_subnet(self.context, subnet_v4_info) sub_v6 = None if subnet_v6_info: subnet_v6_info['subnet']['network_id'] = net['id'] sub_v6 = subnet_api.create_subnet(self.context, subnet_v6_info) yield net, sub_v4, sub_v6
def _stubs(self, network_info, subnet_v4_info, subnet_v6_info=None): with mock.patch("neutron.common.rpc.get_notifier"), \ mock.patch("neutron.quota.QUOTAS.limit_check"): self.context.is_admin = True net = network_api.create_network(self.context, network_info) mac = {'mac_address_range': dict(cidr="AA:BB:CC")} macrng_api.create_mac_address_range(self.context, mac) self.context.is_admin = False subnet_v4_info['subnet']['network_id'] = net['id'] sub_v4 = subnet_api.create_subnet(self.context, subnet_v4_info) sub_v6 = None if subnet_v6_info: subnet_v6_info['subnet']['network_id'] = net['id'] sub_v6 = subnet_api.create_subnet(self.context, subnet_v6_info) yield net, sub_v4, sub_v6
def _stubs(self, network, subnet, ip_policy): self.ipam = quark.ipam.QuarkIpamANY() with mock.patch("neutron.common.rpc.get_notifier"): net = network_api.create_network(self.context, network) subnet['subnet']['network_id'] = net['id'] sub1 = subnet_api.create_subnet(self.context, subnet) ipp = policy_api.update_ip_policy(self.context, sub1["ip_policy_id"], ip_policy) yield net, sub1, ipp
def _stubs(self, network_info, subnet_v4_infos, subnet_v6_info=None): with mock.patch("neutron.common.rpc.get_notifier"), \ mock.patch("neutron.quota.QUOTAS.limit_check"): self.context.is_admin = True net = network_api.create_network(self.context, network_info) mac = {'mac_address_range': dict(cidr="AA:BB:CC", do_not_use=True)} macrng_api.create_mac_address_range(self.context, mac) self.context.is_admin = False sub_v4s = [] for sub_info in subnet_v4_infos: sub_info['subnet']['network_id'] = net['id'] sub_v4s.append(subnet_api.create_subnet( self.context, sub_info)) sub_v6 = None if subnet_v6_info: subnet_v6_info['subnet']['network_id'] = net['id'] sub_v6 = subnet_api.create_subnet(self.context, subnet_v6_info) yield net, sub_v4s, sub_v6
def _stubs(self, network_info, subnet_v4_infos, subnet_v6_info=None): with contextlib.nested( mock.patch("neutron.common.rpc.get_notifier"), mock.patch("neutron.quota.QUOTAS.limit_check")): self.context.is_admin = True net = network_api.create_network(self.context, network_info) mac = {'mac_address_range': dict(cidr="AA:BB:CC", do_not_use=True)} macrng_api.create_mac_address_range(self.context, mac) self.context.is_admin = False sub_v4s = [] for sub_info in subnet_v4_infos: sub_info['subnet']['network_id'] = net['id'] sub_v4s.append(subnet_api.create_subnet(self.context, sub_info)) sub_v6 = None if subnet_v6_info: subnet_v6_info['subnet']['network_id'] = net['id'] sub_v6 = subnet_api.create_subnet(self.context, subnet_v6_info) yield net, sub_v4s, sub_v6
def _stubs(self, network_info, subnet_info): with mock.patch("neutron.common.rpc.get_notifier"), \ mock.patch("neutron.quota.QUOTAS.limit_check"): mac = {'mac_address_range': dict(cidr="AA:BB:CC")} self.context.is_admin = True macrng_api.create_mac_address_range(self.context, mac) self.context.is_admin = False network = network_api.create_network(self.context, network_info) subnet_info['subnet']['network_id'] = network['id'] subnet = subnet_api.create_subnet(self.context, subnet_info) yield network, subnet
def _stubs(self, network_info, subnet_info): with contextlib.nested( mock.patch("neutron.common.rpc.get_notifier"), mock.patch("neutron.quota.QUOTAS.limit_check")): mac = {'mac_address_range': dict(cidr="AA:BB:CC")} self.context.is_admin = True macrng_api.create_mac_address_range(self.context, mac) self.context.is_admin = False network = network_api.create_network(self.context, network_info) subnet_info['subnet']['network_id'] = network['id'] subnet = subnet_api.create_subnet(self.context, subnet_info) yield network, subnet
def _stubs(self, network_info, subnet_info, ports_info): self.ipam = quark.ipam.QuarkIpamANY() with mock.patch("neutron.common.rpc.get_notifier"), mock.patch("neutron.quota.QUOTAS.limit_check"): net = network_api.create_network(self.admin_context, network_info) mac = {"mac_address_range": dict(cidr="AA:BB:CC")} macrng_api.create_mac_address_range(self.admin_context, mac) subnet_info["subnet"]["network_id"] = net["id"] sub = subnet_api.create_subnet(self.context, subnet_info) ports = [] for port_info in ports_info: port_info["port"]["network_id"] = net["id"] ports.append(port_api.create_port(self.context, port_info)) yield net, sub, ports
def _stubs(self, network_info, subnet_info, port_info): self.ipam = quark.ipam.QuarkIpamANY() with contextlib.nested(mock.patch("neutron.common.rpc.get_notifier"), mock.patch("neutron.quota.QUOTAS.limit_check")): net = network_api.create_network(self.context, network_info) mac = {'mac_address_range': dict(cidr="AA:BB:CC")} self.context.is_admin = True macrng_api.create_mac_address_range(self.context, mac) self.context.is_admin = False subnet_info['subnet']['network_id'] = net['id'] port_info['port']['network_id'] = net['id'] sub = subnet_api.create_subnet(self.context, subnet_info) port = port_api.create_port(self.context, port_info) yield net, sub, port
def _stubs(self, network_info, subnet_info, ports_info): self.ipam = quark.ipam.QuarkIpamANY() with mock.patch("neutron.common.rpc.get_notifier"), \ mock.patch("neutron.quota.QUOTAS.limit_check"): net = network_api.create_network(self.admin_context, network_info) mac = {'mac_address_range': dict(cidr="AA:BB:CC")} macrng_api.create_mac_address_range(self.admin_context, mac) subnet_info['subnet']['network_id'] = net['id'] sub = subnet_api.create_subnet(self.context, subnet_info) ports = [] for port_info in ports_info: port_info['port']['network_id'] = net['id'] ports.append(port_api.create_port(self.context, port_info)) yield net, sub, ports
def _stubs(self, network_info, subnet_info, ports_info): self.ipam = quark.ipam.QuarkIpamANY() with contextlib.nested(mock.patch("neutron.common.rpc.get_notifier")): self.context.is_admin = True net = network_api.create_network(self.context, network_info) mac = {'mac_address_range': dict(cidr="AA:BB:CC")} macrng_api.create_mac_address_range(self.context, mac) self.context.is_admin = False subnet_info['subnet']['network_id'] = net['id'] sub = subnet_api.create_subnet(self.context, subnet_info) ports = [] for port_info in ports_info: port_info['port']['network_id'] = net['id'] ports.append(port_api.create_port(self.context, port_info)) yield net, sub, ports
def _stubs(self, network_info, subnet_info, port_info): self.ipam = quark.ipam.QuarkIpamANY() with contextlib.nested( mock.patch("neutron.common.rpc.get_notifier"), mock.patch("neutron.quota.QUOTAS.limit_check")): net = network_api.create_network(self.context, network_info) mac = {'mac_address_range': dict(cidr="AA:BB:CC")} self.context.is_admin = True macrng_api.create_mac_address_range(self.context, mac) self.context.is_admin = False subnet_info['subnet']['network_id'] = net['id'] port_info['port']['network_id'] = net['id'] sub = subnet_api.create_subnet(self.context, subnet_info) port = port_api.create_port(self.context, port_info) yield net, sub, port
def _stubs(self, network_info, subnet_info, ports_info): self.ipam = quark.ipam.QuarkIpamANY() with contextlib.nested( mock.patch("neutron.common.rpc.get_notifier")): self.context.is_admin = True net = network_api.create_network(self.context, network_info) mac = {'mac_address_range': dict(cidr="AA:BB:CC")} macrng_api.create_mac_address_range(self.context, mac) self.context.is_admin = False subnet_info['subnet']['network_id'] = net['id'] sub = subnet_api.create_subnet(self.context, subnet_info) ports = [] for port_info in ports_info: port_info['port']['network_id'] = net['id'] ports.append(port_api.create_port(self.context, port_info)) yield net, sub, ports
def _stubs(self, network_info, subnet_info): with mock.patch("neutron.common.rpc.get_notifier"), \ mock.patch("neutron.quota.QUOTAS.limit_check"): mac = {'mac_address_range': dict(cidr="AA:BB:CC")} self.context.is_admin = True macrng_api.create_mac_address_range(self.context, mac) self.context.is_admin = False # Setting context's tenant_id because this network needs to belong # to a regular tenant, and the network create method does not # care about the tenant_id on the network self.context.tenant_id = 'joetenant' network = network_api.create_network(self.context, network_info) subnet_info['subnet']['network_id'] = network['id'] subnet = subnet_api.create_subnet(self.context, subnet_info) self.context.tenant_id = 'advsvc' yield network, subnet
def _stubs(self, network_info, subnet_info): with contextlib.nested(mock.patch("neutron.common.rpc.get_notifier"), mock.patch("neutron.quota.QUOTAS.limit_check")): mac = {'mac_address_range': dict(cidr="AA:BB:CC")} self.context.is_admin = True macrng_api.create_mac_address_range(self.context, mac) self.context.is_admin = False # Setting context's tenant_id because this network needs to belong # to a regular tenant, and the network create method does not # care about the tenant_id on the network self.context.tenant_id = 'joetenant' network = network_api.create_network(self.context, network_info) subnet_info['subnet']['network_id'] = network['id'] subnet = subnet_api.create_subnet(self.context, subnet_info) self.context.tenant_id = 'advsvc' yield network, subnet
def _stubs(self, network_info, subnet_v4_info, subnet_v6_info=None): cls = 'QuarkSGAsyncProcessClient' mod_path = 'quark.worker_plugins.sg_update_worker.%s' % cls job_path = 'quark.plugin_modules.jobs' with mock.patch("neutron.common.rpc.get_notifier"), \ mock.patch("neutron.quota.QUOTAS.limit_check"), \ mock.patch("%s.add_job_to_context" % job_path), \ mock.patch("%s.start_update" % mod_path) as update: self.context.is_admin = True net = network_api.create_network(self.context, network_info) mac = {'mac_address_range': dict(cidr="AA:BB:CC")} macrng_api.create_mac_address_range(self.context, mac) self.context.is_admin = False subnet_v4_info['subnet']['network_id'] = net['id'] sub_v4 = subnet_api.create_subnet(self.context, subnet_v4_info) yield net, sub_v4, update
def create_subnet(self, context, subnet): return subnets.create_subnet(context, subnet)
def create_subnet(self, context, subnet): self._fix_missing_tenant_id(context, subnet["subnet"]) return subnets.create_subnet(context, subnet)