def test_create_for_sg_rule(self): sg_id = uuidutils.generate_uuid() sg_name = 'test-sg' in_chain_id = uuidutils.generate_uuid() out_chain_id = uuidutils.generate_uuid() self.mock_api_cfg.chains_in = [ _create_test_sg_in_chain(sg_id, sg_name, in_chain_id, self._tenant_id), _create_test_sg_out_chain(sg_id, sg_name, out_chain_id, self._tenant_id) ] sg_rule_id = uuidutils.generate_uuid() sg_rule = _create_test_sg_rule(self._tenant_id, sg_id, sg_rule_id) props = {"os_sg_rule_id": sg_rule_id} calls = [ mock.call.add_rule().port_group(None).type('accept').nw_proto( 6).nw_src_address('192.168.1.0').nw_src_length( 24).tp_src_start(None).tp_src_end(None).tp_dst_start( 1).tp_dst_end(65535).properties(props).create() ] self.client.create_for_sg_rule(sg_rule) # Egress chain rule added self.mock_api_cfg.chains_out[0].assert_has_calls(calls)
def test_delete_for_sg(self): sg_id = uuidutils.generate_uuid() sg_name = 'test-sg' in_chain_id = uuidutils.generate_uuid() out_chain_id = uuidutils.generate_uuid() pg_id = uuidutils.generate_uuid() self.mock_api_cfg.chains_in = [ _create_test_sg_in_chain(sg_id, sg_name, in_chain_id, self._tenant_id), _create_test_sg_out_chain(sg_id, sg_name, out_chain_id, self._tenant_id) ] self.mock_api_cfg.port_groups_in = [ _create_test_port_group(sg_id, sg_name, pg_id, self._tenant_id) ] calls = [ mock.call.get_chains({"tenant_id": self._tenant_id}), mock.call.delete_chain(in_chain_id), mock.call.delete_chain(out_chain_id), mock.call.get_port_groups({"tenant_id": self._tenant_id}), mock.call.delete_port_group(pg_id) ] self.client.delete_for_sg(self._tenant_id, sg_id, sg_name) self.mock_api.assert_has_calls(calls)
def test_create_for_sg_rule(self): sg_id = uuidutils.generate_uuid() sg_name = 'test-sg' in_chain_id = uuidutils.generate_uuid() out_chain_id = uuidutils.generate_uuid() self.mock_api_cfg.chains_in = [ _create_test_sg_in_chain(sg_id, sg_name, in_chain_id, self._tenant_id), _create_test_sg_out_chain(sg_id, sg_name, out_chain_id, self._tenant_id)] sg_rule_id = uuidutils.generate_uuid() sg_rule = _create_test_sg_rule(self._tenant_id, sg_id, sg_rule_id) props = {"os_sg_rule_id": sg_rule_id} calls = [mock.call.add_rule().port_group(None).type( 'accept').nw_proto(6).nw_src_address( '192.168.1.0').nw_src_length(24).tp_src_start( None).tp_src_end(None).tp_dst_start(1).tp_dst_end( 65535).properties(props).create()] self.client.create_for_sg_rule(sg_rule) # Egress chain rule added self.mock_api_cfg.chains_out[0].assert_has_calls(calls)
def create_security_group(self, context, security_group, default_sg=False): """Create security group. If default_sg is true that means we are a default security group for a given tenant if it does not exist. """ s = security_group['security_group'] tenant_id = self._get_tenant_id_for_create(context, s) if not default_sg: self._ensure_default_security_group(context, tenant_id) with context.session.begin(subtransactions=True): security_group_db = SecurityGroup(id=s.get('id') or ( uuidutils.generate_uuid()), description=s['description'], tenant_id=tenant_id, name=s['name']) context.session.add(security_group_db) if s.get('name') == 'default': for ethertype in ext_sg.sg_supported_ethertypes: # Allow intercommunication db = SecurityGroupRule( id=uuidutils.generate_uuid(), tenant_id=tenant_id, security_group=security_group_db, direction='ingress', ethertype=ethertype, source_group=security_group_db) context.session.add(db) return self._make_security_group_dict(security_group_db)
def get_random_params(self): """create random parameters for portinfo test""" tenant = uuidutils.generate_uuid() network = uuidutils.generate_uuid() port = uuidutils.generate_uuid() _filter = uuidutils.generate_uuid() none = uuidutils.generate_uuid() return tenant, network, port, _filter, none
def get_portinfo_random_params(self): """create random parameters for portinfo test""" port_id = uuidutils.generate_uuid() datapath_id = hex(random.randint(0, 0xffffffff)) port_no = random.randint(1, 100) vlan_id = random.randint(0, 4095) mac = ':'.join(["%02x" % random.randint(0, 0xff) for x in range(6)]) none = uuidutils.generate_uuid() return port_id, datapath_id, port_no, vlan_id, mac, none
def get_ofc_item_random_params(self): """create random parameters for ofc_item test""" tenant_id = uuidutils.generate_uuid() network_id = uuidutils.generate_uuid() port_id = uuidutils.generate_uuid() portinfo = nmodels.PortInfo(id=port_id, datapath_id="0x123456789", port_no=1234, vlan_id=321, mac="11:22:33:44:55:66") return tenant_id, network_id, portinfo
def get_ofc_item_random_params(self): """create random parameters for ofc_item test""" tenant_id = uuidutils.generate_uuid() network_id = uuidutils.generate_uuid() port_id = uuidutils.generate_uuid() portinfo = nmodels.PortInfo( id=port_id, datapath_id="0x123456789", port_no=1234, vlan_id=321, mac="11:22:33:44:55:66" ) return tenant_id, network_id, portinfo
def get_ofc_item_random_params(self): """create random parameters for ofc_item test.""" tenant_id = uuidutils.generate_uuid() network_id = uuidutils.generate_uuid() port_id = uuidutils.generate_uuid() mac = ':'.join(['%x' % random.randint(0, 255) for i in xrange(6)]) portinfo = nmodels.PortInfo(id=port_id, datapath_id="0x123456789", port_no=1234, vlan_id=321, mac=mac) return tenant_id, network_id, portinfo
def test_get_port_groups_for_sg(self): sg_id = uuidutils.generate_uuid() pg_id = uuidutils.generate_uuid() self.mock_api_cfg.port_groups_in = [ _create_test_port_group(sg_id, 'test-sg', pg_id, self._tenant_id)] pg = self.client.get_port_groups_for_sg(self._tenant_id, sg_id) self.assertIsNotNone(pg) self.assertEqual(pg.get_id(), pg_id)
def test_get_ready_devices_multiple_vips_and_pools(self): ctx = context.get_admin_context() # add 3 pools and 2 vips directly to DB # to create 2 "ready" devices and one pool without vip pools = [] for i in xrange(0, 3): pools.append( ldb.Pool( id=uuidutils.generate_uuid(), subnet_id=self._subnet_id, protocol="HTTP", lb_method="ROUND_ROBIN", status=constants.ACTIVE, admin_state_up=True, ) ) ctx.session.add(pools[i]) vip0 = ldb.Vip( id=uuidutils.generate_uuid(), protocol_port=80, protocol="HTTP", pool_id=pools[0].id, status=constants.ACTIVE, admin_state_up=True, connection_limit=3, ) ctx.session.add(vip0) pools[0].vip_id = vip0.id vip1 = ldb.Vip( id=uuidutils.generate_uuid(), protocol_port=80, protocol="HTTP", pool_id=pools[1].id, status=constants.ACTIVE, admin_state_up=True, connection_limit=3, ) ctx.session.add(vip1) pools[1].vip_id = vip1.id ctx.session.flush() self.assertEqual(ctx.session.query(ldb.Pool).count(), 3) self.assertEqual(ctx.session.query(ldb.Vip).count(), 2) ready = self.callbacks.get_ready_devices(ctx) self.assertEqual(len(ready), 2) self.assertIn(pools[0].id, ready) self.assertIn(pools[1].id, ready) self.assertNotIn(pools[2].id, ready) # cleanup ctx.session.query(ldb.Pool).delete() ctx.session.query(ldb.Vip).delete()
def test_get_port_groups_for_sg(self): sg_id = uuidutils.generate_uuid() pg_id = uuidutils.generate_uuid() self.mock_api_cfg.port_groups_in = [ _create_test_port_group(sg_id, 'test-sg', pg_id, self._tenant_id) ] pg = self.client.get_port_groups_for_sg(self._tenant_id, sg_id) self.assertIsNotNone(pg) self.assertEqual(pg.get_id(), pg_id)
def test_delete_quantum_ports(self): port1 = ovs_lib.VifPort('tap1234', 1, uuidutils.generate_uuid(), 'ca:fe:de:ad:be:ef', 'br') port2 = ovs_lib.VifPort('tap5678', 2, uuidutils.generate_uuid(), 'ca:ee:de:ad:be:ef', 'br') self.mox.StubOutWithMock(self.br, 'get_vif_ports') self.br.get_vif_ports().AndReturn([port1, port2]) self.mox.StubOutWithMock(self.br, 'delete_port') self.br.delete_port('tap1234') self.br.delete_port('tap5678') self.mox.ReplayAll() self.br.delete_ports(all_ports=False) self.mox.VerifyAll()
def create_security_group(self, context, security_group, default_sg=False): """Create security group. If default_sg is true that means we are a default security group for a given tenant if it does not exist. """ s = security_group['security_group'] if (cfg.CONF.SECURITYGROUP.proxy_mode and not context.is_admin): raise ext_sg.SecurityGroupProxyModeNotAdmin() if (cfg.CONF.SECURITYGROUP.proxy_mode and not s.get('external_id')): raise ext_sg.SecurityGroupProxyMode() if not cfg.CONF.SECURITYGROUP.proxy_mode and s.get('external_id'): raise ext_sg.SecurityGroupNotProxyMode() tenant_id = self._get_tenant_id_for_create(context, s) # if in proxy mode a default security group will be created by source if not default_sg and not cfg.CONF.SECURITYGROUP.proxy_mode: self._ensure_default_security_group(context, tenant_id, security_group) if s.get('external_id'): try: # Check if security group already exists sg = self.get_security_group(context, s.get('external_id')) if sg: raise ext_sg.SecurityGroupAlreadyExists( name=sg.get('name', ''), external_id=s.get('external_id')) except ext_sg.SecurityGroupNotFound: pass with context.session.begin(subtransactions=True): security_group_db = SecurityGroup(id=s.get('id') or ( uuidutils.generate_uuid()), description=s['description'], tenant_id=tenant_id, name=s['name'], external_id=s.get('external_id')) context.session.add(security_group_db) if s.get('name') == 'default': for ethertype in self.sg_supported_ethertypes: # Allow intercommunication db = SecurityGroupRule( id=uuidutils.generate_uuid(), tenant_id=tenant_id, security_group=security_group_db, direction='ingress', ethertype=ethertype, source_group=security_group_db) context.session.add(db) return self._make_security_group_dict(security_group_db)
def test_collect_quantum_ports(self): port1 = ovs_lib.VifPort('tap1234', 1, uuidutils.generate_uuid(), '11:22:33:44:55:66', 'br') port2 = ovs_lib.VifPort('tap5678', 2, uuidutils.generate_uuid(), '77:88:99:aa:bb:cc', 'br') port3 = ovs_lib.VifPort('tap90ab', 3, uuidutils.generate_uuid(), '99:00:aa:bb:cc:dd', 'br') ports = [[port1, port2], [port3]] portnames = [p.port_name for p in itertools.chain(*ports)] with mock.patch('quantum.agent.linux.ovs_lib.OVSBridge') as ovs: ovs.return_value.get_vif_ports.side_effect = ports bridges = ['br-int', 'br-ex'] ret = util.collect_quantum_ports(bridges, 'dummy_sudo') self.assertEqual(ret, portnames)
def create_security_group(self, context, security_group, default_sg=False): """Create security group. If default_sg is true that means we are a default security group for a given tenant if it does not exist. """ s = security_group['security_group'] if (cfg.CONF.SECURITYGROUP.proxy_mode and not context.is_admin): raise ext_sg.SecurityGroupProxyModeNotAdmin() if (cfg.CONF.SECURITYGROUP.proxy_mode and not s.get('external_id')): raise ext_sg.SecurityGroupProxyMode() if not cfg.CONF.SECURITYGROUP.proxy_mode and s.get('external_id'): raise ext_sg.SecurityGroupNotProxyMode() tenant_id = self._get_tenant_id_for_create(context, s) # if in proxy mode a default security group will be created by source if not default_sg and not cfg.CONF.SECURITYGROUP.proxy_mode: self._ensure_default_security_group(context, tenant_id, security_group) if s.get('external_id'): try: # Check if security group already exists sg = self.get_security_group(context, s.get('external_id')) if sg: raise ext_sg.SecurityGroupAlreadyExists( name=sg.get('name', ''), external_id=s.get('external_id')) except ext_sg.SecurityGroupNotFound: pass with context.session.begin(subtransactions=True): security_group_db = SecurityGroup(id=s.get('id') or ( uuidutils.generate_uuid()), description=s['description'], tenant_id=tenant_id, name=s['name'], external_id=s.get('external_id')) context.session.add(security_group_db) if s.get('name') == 'default': for ethertype in ext_sg.sg_supported_ethertypes: # Allow intercommunication db = SecurityGroupRule( id=uuidutils.generate_uuid(), tenant_id=tenant_id, security_group=security_group_db, direction='ingress', ethertype=ethertype, source_group=security_group_db) context.session.add(db) return self._make_security_group_dict(security_group_db)
def test_get_ready_devices_multiple_vips_and_pools(self): ctx = context.get_admin_context() # add 3 pools and 2 vips directly to DB # to create 2 "ready" devices and one pool without vip pools = [] for i in xrange(0, 3): pools.append( ldb.Pool(id=uuidutils.generate_uuid(), subnet_id=self._subnet_id, protocol="HTTP", lb_method="ROUND_ROBIN", status=constants.ACTIVE, admin_state_up=True)) ctx.session.add(pools[i]) vip0 = ldb.Vip(id=uuidutils.generate_uuid(), protocol_port=80, protocol="HTTP", pool_id=pools[0].id, status=constants.ACTIVE, admin_state_up=True, connection_limit=3) ctx.session.add(vip0) pools[0].vip_id = vip0.id vip1 = ldb.Vip(id=uuidutils.generate_uuid(), protocol_port=80, protocol="HTTP", pool_id=pools[1].id, status=constants.ACTIVE, admin_state_up=True, connection_limit=3) ctx.session.add(vip1) pools[1].vip_id = vip1.id ctx.session.flush() self.assertEqual(ctx.session.query(ldb.Pool).count(), 3) self.assertEqual(ctx.session.query(ldb.Vip).count(), 2) ready = self.callbacks.get_ready_devices(ctx) self.assertEqual(len(ready), 2) self.assertIn(pools[0].id, ready) self.assertIn(pools[1].id, ready) self.assertNotIn(pools[2].id, ready) # cleanup ctx.session.query(ldb.Pool).delete() ctx.session.query(ldb.Vip).delete()
def create_vip(self, context, vip): v = vip['vip'] tenant_id = self._get_tenant_id_for_create(context, v) with context.session.begin(subtransactions=True): if v['address'] is attributes.ATTR_NOT_SPECIFIED: address = None else: address = v['address'] vip_db = Vip(id=uuidutils.generate_uuid(), tenant_id=tenant_id, name=v['name'], description=v['description'], subnet_id=v['subnet_id'], address=address, port=v['port'], protocol=v['protocol'], pool_id=v['pool_id'], connection_limit=v['connection_limit'], admin_state_up=v['admin_state_up'], status=constants.PENDING_CREATE) vip_id = vip_db['id'] session_info = v['session_persistence'] if session_info: s_p = self._create_session_persistence_db(session_info, vip_id) vip_db.session_persistence = s_p context.session.add(vip_db) self._update_pool_vip_info(context, v['pool_id'], vip_id) vip_db = self._get_resource(context, Vip, vip_id) return self._make_vip_dict(vip_db)
def test_get_bridge(self): bridge_id = uuidutils.generate_uuid() bridge = self.client.get_bridge(bridge_id) self.assertIsNotNone(bridge) self.assertEqual(bridge.get_id(), bridge_id)
def create_port(self, ofc_network_id, portinfo, port_id=None): ofc_port_id = port_id or uuidutils.generate_uuid() path = self.attachments_path % {'network': ofc_network_id} body = {'id': ofc_port_id, 'mac': portinfo.mac} self.client.post(path, body=body) return self.attachment_path % {'network': ofc_network_id, 'attachment': ofc_port_id}
def create_floatingip(self, context, floatingip): fip = floatingip['floatingip'] tenant_id = self._get_tenant_id_for_create(context, fip) fip_id = uuidutils.generate_uuid() f_net_id = fip['floating_network_id'] if not self._network_is_external(context, f_net_id): msg = _("Network %s is not a valid external network") % f_net_id raise q_exc.BadRequest(resource='floatingip', msg=msg) try: with context.session.begin(subtransactions=True): # This external port is never exposed to the tenant. # it is used purely for internal system and admin use when # managing floating IPs. external_port = self.create_port(context.elevated(), { 'port': {'tenant_id': '', # tenant intentionally not set 'network_id': f_net_id, 'mac_address': attributes.ATTR_NOT_SPECIFIED, 'fixed_ips': attributes.ATTR_NOT_SPECIFIED, 'admin_state_up': True, 'device_id': fip_id, 'device_owner': DEVICE_OWNER_FLOATINGIP, 'name': ''}}) # Ensure IP addresses are allocated on external port if not external_port['fixed_ips']: msg = _("Unable to find any IP address on external " "network") raise q_exc.BadRequest(resource='floatingip', msg=msg) floating_fixed_ip = external_port['fixed_ips'][0] floating_ip_address = floating_fixed_ip['ip_address'] floatingip_db = FloatingIP( id=fip_id, tenant_id=tenant_id, floating_network_id=fip['floating_network_id'], floating_ip_address=floating_ip_address, floating_port_id=external_port['id']) fip['tenant_id'] = tenant_id # Update association with internal port # and define external IP address self._update_fip_assoc(context, fip, floatingip_db, external_port) context.session.add(floatingip_db) # TODO(salvatore-orlando): Avoid broad catch # Maybe by introducing base class for L3 exceptions except q_exc.BadRequest: LOG.exception(_("Unable to create Floating ip due to a " "malformed request")) raise except Exception: LOG.exception(_("Floating IP association failed")) raise router_id = floatingip_db['router_id'] if router_id: routers = self.get_sync_data(context.elevated(), [router_id]) l3_rpc_agent_api.L3AgentNotify.routers_updated(context, routers, 'create_floatingip') return self._make_floatingip_dict(floatingip_db)
def create_port(self, ofc_network_id, portinfo, port_id=None): #NOTE: This Driver create slices with Port-MAC Based bindings on Trema # Sliceable. It's REST API requires Port Based binding before you # define Port-MAC Based binding. ofc_port_id = port_id or uuidutils.generate_uuid() dummy_port_id = "dummy-%s" % ofc_port_id path = self.ports_path % {'network': ofc_network_id} body = {'id': dummy_port_id, 'datapath_id': portinfo.datapath_id, 'port': str(portinfo.port_no), 'vid': str(portinfo.vlan_id)} self.client.post(path, body=body) path = self.attachments_path % {'network': ofc_network_id, 'port': dummy_port_id} body = {'id': ofc_port_id, 'mac': portinfo.mac} self.client.post(path, body=body) path = self.port_path % {'network': ofc_network_id, 'port': dummy_port_id} self.client.delete(path) return self.attachment_path % {'network': ofc_network_id, 'port': dummy_port_id, 'attachment': ofc_port_id}
def create_dummy(self, context, dummy): d = dummy['dummy'] d['id'] = uuidutils.generate_uuid() self.dummys[d['id']] = d self.svctype_mgr.increase_service_type_refcount(context, d['service_type']) return d
def create_security_group_rule_bulk_native(self, context, security_group_rule): r = security_group_rule['security_group_rules'] scoped_session(context.session) security_group_id = self._validate_security_group_rules( context, security_group_rule) with context.session.begin(subtransactions=True): if not self.get_security_group(context, security_group_id): raise ext_sg.SecurityGroupNotFound(id=security_group_id) self._check_for_duplicate_rules(context, r) ret = [] for rule_dict in r: rule = rule_dict['security_group_rule'] tenant_id = self._get_tenant_id_for_create(context, rule) db = SecurityGroupRule( id=uuidutils.generate_uuid(), tenant_id=tenant_id, security_group_id=rule['security_group_id'], direction=rule['direction'], remote_group_id=rule.get('remote_group_id'), ethertype=rule['ethertype'], protocol=rule['protocol'], port_range_min=rule['port_range_min'], port_range_max=rule['port_range_max'], remote_ip_prefix=rule.get('remote_ip_prefix')) context.session.add(db) ret.append(self._make_security_group_rule_dict(db)) return ret
def create_port(self, ofc_tenant_id, ofc_network_id, portinfo, port_id=None): #NOTE: This Driver create slices with Port-MAC Based bindings on Trema # Sliceable. It's REST API requires Port Based binding before you # define Port-MAC Based binding. ofc_port_id = port_id or uuidutils.generate_uuid() dummy_port_id = "dummy-%s" % ofc_port_id path = self.ports_path % ofc_network_id body = { 'id': dummy_port_id, 'datapath_id': portinfo.datapath_id, 'port': str(portinfo.port_no), 'vid': str(portinfo.vlan_id) } self.client.post(path, body=body) path = self.attachments_path % (ofc_network_id, dummy_port_id) body = {'id': ofc_port_id, 'mac': portinfo.mac} self.client.post(path, body=body) path = self.port_path % (ofc_network_id, dummy_port_id) self.client.delete(path) return ofc_port_id
def create_floatingip(self, context, floatingip): fip = floatingip['floatingip'] tenant_id = self._get_tenant_id_for_create(context, fip) fip_id = uuidutils.generate_uuid() f_net_id = fip['floating_network_id'] if not self._network_is_external(context, f_net_id): msg = "Network %s is not a valid external network" % f_net_id raise q_exc.BadRequest(resource='floatingip', msg=msg) try: with context.session.begin(subtransactions=True): # This external port is never exposed to the tenant. # it is used purely for internal system and admin use when # managing floating IPs. external_port = self.create_port( context.elevated(), { 'port': { 'tenant_id': '', # tenant intentionally not set 'network_id': f_net_id, 'mac_address': attributes.ATTR_NOT_SPECIFIED, 'fixed_ips': attributes.ATTR_NOT_SPECIFIED, 'admin_state_up': True, 'device_id': fip_id, 'device_owner': DEVICE_OWNER_FLOATINGIP, 'name': '' } }) # Ensure IP addresses are allocated on external port if not external_port['fixed_ips']: msg = "Unable to find any IP address on external network" raise q_exc.BadRequest(resource='floatingip', msg=msg) floating_fixed_ip = external_port['fixed_ips'][0] floating_ip_address = floating_fixed_ip['ip_address'] floatingip_db = FloatingIP( id=fip_id, tenant_id=tenant_id, floating_network_id=fip['floating_network_id'], floating_ip_address=floating_ip_address, floating_port_id=external_port['id']) fip['tenant_id'] = tenant_id # Update association with internal port # and define external IP address self._update_fip_assoc(context, fip, floatingip_db, external_port) context.session.add(floatingip_db) # TODO(salvatore-orlando): Avoid broad catch # Maybe by introducing base class for L3 exceptions except q_exc.BadRequest: LOG.exception( _("Unable to create Floating ip due to a " "malformed request")) raise except Exception: LOG.exception(_("Floating IP association failed")) raise return self._make_floatingip_dict(floatingip_db)
def _test_list(self, req_tenant_id, real_tenant_id): env = {} if req_tenant_id: env = {'quantum.context': context.Context('', req_tenant_id)} input_dict = {'id': uuidutils.generate_uuid(), 'name': 'net1', 'admin_state_up': True, 'status': "ACTIVE", 'tenant_id': real_tenant_id, 'shared': False, 'subnets': []} return_value = [input_dict] instance = self.plugin.return_value instance.get_networks.return_value = return_value res = self.api.get(_get_path('networks'), extra_environ=env) self.assertTrue('networks' in res.json) if not req_tenant_id or req_tenant_id == real_tenant_id: # expect full list returned self.assertEqual(len(res.json['networks']), 1) output_dict = res.json['networks'][0] input_dict['shared'] = False self.assertEqual(len(input_dict), len(output_dict)) for k, v in input_dict.iteritems(): self.assertEqual(v, output_dict[k]) else: # expect no results self.assertEqual(len(res.json['networks']), 0)
def get_ofc_item_random_params(self): """create random parameters for ofc_item test.""" t, n, p = (super(TremaFilterDriverTest, self).get_ofc_item_random_params()) filter_id = uuidutils.generate_uuid() filter_dict = { 'tenant_id': t, 'id': filter_id, 'network_id': n, 'priority': 123, 'action': "ACCEPT", 'in_port': p.id, 'src_mac': p.mac, 'dst_mac': "", 'eth_type': 0, 'src_cidr': "", 'dst_cidr': "", 'src_port': 0, 'dst_port': 0, 'protocol': "TCP", 'admin_state_up': True, 'status': "ACTIVE" } filter_item = nmodels.PacketFilter(**filter_dict) return t, n, p, filter_item
def create_dummy(self, context, dummy): d = dummy['dummy'] d['id'] = uuidutils.generate_uuid() self.dummys[d['id']] = d self.svctype_mgr.increase_service_type_refcount( context, d['service_type']) return d
def create_member(self, context, member): v = member["member"] tenant_id = self._get_tenant_id_for_create(context, v) with context.session.begin(subtransactions=True): pool = None try: qry = context.session.query(Pool) pool = qry.filter_by(id=v["pool_id"]).one() except exc.NoResultFound: raise loadbalancer.PoolNotFound(pool_id=v["pool_id"]) member_db = Member( id=uuidutils.generate_uuid(), tenant_id=tenant_id, pool_id=v["pool_id"], address=v["address"], protocol_port=v["protocol_port"], weight=v["weight"], admin_state_up=v["admin_state_up"], status=constants.PENDING_CREATE, ) context.session.add(member_db) return self._make_member_dict(member_db)
def _test_list(self, req_tenant_id, real_tenant_id): env = {} if req_tenant_id: env = {"quantum.context": context.Context("", req_tenant_id)} input_dict = { "id": uuidutils.generate_uuid(), "name": "net1", "admin_state_up": True, "status": "ACTIVE", "tenant_id": real_tenant_id, "shared": False, "subnets": [], } return_value = [input_dict] instance = self.plugin.return_value instance.get_networks.return_value = return_value res = self.api.get(_get_path("networks"), extra_environ=env) self.assertTrue("networks" in res.json) if not req_tenant_id or req_tenant_id == real_tenant_id: # expect full list returned self.assertEqual(len(res.json["networks"]), 1) output_dict = res.json["networks"][0] input_dict["shared"] = False self.assertEqual(len(input_dict), len(output_dict)) for k, v in input_dict.iteritems(): self.assertEqual(v, output_dict[k]) else: # expect no results self.assertEqual(len(res.json["networks"]), 0)
def test_fields(self): return_value = {"name": "net1", "admin_state_up": True, "subnets": []} instance = self.plugin.return_value instance.get_network.return_value = return_value self.api.get(_get_path("networks", id=uuidutils.generate_uuid()))
def create_security_group_rule_bulk_native(self, context, security_group_rule): r = security_group_rule['security_group_rules'] scoped_session(context.session) security_group_id = self._validate_security_group_rules( context, security_group_rule) with context.session.begin(subtransactions=True): if not self.get_security_group(context, security_group_id): raise ext_sg.SecurityGroupNotFound(id=security_group_id) self._check_for_duplicate_rules(context, r) ret = [] for rule_dict in r: rule = rule_dict['security_group_rule'] tenant_id = self._get_tenant_id_for_create(context, rule) db = SecurityGroupRule( id=uuidutils.generate_uuid(), tenant_id=tenant_id, security_group_id=rule['security_group_id'], direction=rule['direction'], source_group_id=rule.get('source_group_id'), ethertype=rule['ethertype'], protocol=rule['protocol'], port_range_min=rule['port_range_min'], port_range_max=rule['port_range_max'], source_ip_prefix=rule.get('source_ip_prefix')) context.session.add(db) ret.append(self._make_security_group_rule_dict(db)) return ret
def setUp(self): super(MetaQuantumPluginV2Test, self).setUp() db._ENGINE = None db._MAKER = None self.fake_tenant_id = uuidutils.generate_uuid() self.context = context.get_admin_context() db.configure_db() setup_metaplugin_conf() self.mox = mox.Mox() self.stubs = stubout.StubOutForTesting() self.client_cls_p = mock.patch('quantumclient.v2_0.client.Client') client_cls = self.client_cls_p.start() self.client_inst = mock.Mock() client_cls.return_value = self.client_inst self.client_inst.create_network.return_value = \ {'id': 'fake_id'} self.client_inst.create_port.return_value = \ {'id': 'fake_id'} self.client_inst.create_subnet.return_value = \ {'id': 'fake_id'} self.client_inst.update_network.return_value = \ {'id': 'fake_id'} self.client_inst.update_port.return_value = \ {'id': 'fake_id'} self.client_inst.update_subnet.return_value = \ {'id': 'fake_id'} self.client_inst.delete_network.return_value = True self.client_inst.delete_port.return_value = True self.client_inst.delete_subnet.return_value = True self.plugin = MetaPluginV2(configfile=None)
def setUp(self): super(MetaQuantumPluginV2Test, self).setUp() db._ENGINE = None db._MAKER = None self.fake_tenant_id = uuidutils.generate_uuid() self.context = context.get_admin_context() db.configure_db() setup_metaplugin_conf() self.mox = mox.Mox() self.stubs = stubout.StubOutForTesting() args = ['--config-file', etcdir('quantum.conf.test')] self.client_cls_p = mock.patch('quantumclient.v2_0.client.Client') client_cls = self.client_cls_p.start() self.client_inst = mock.Mock() client_cls.return_value = self.client_inst self.client_inst.create_network.return_value = \ {'id': 'fake_id'} self.client_inst.create_port.return_value = \ {'id': 'fake_id'} self.client_inst.create_subnet.return_value = \ {'id': 'fake_id'} self.client_inst.update_network.return_value = \ {'id': 'fake_id'} self.client_inst.update_port.return_value = \ {'id': 'fake_id'} self.client_inst.update_subnet.return_value = \ {'id': 'fake_id'} self.client_inst.delete_network.return_value = True self.client_inst.delete_port.return_value = True self.client_inst.delete_subnet.return_value = True self.plugin = MetaPluginV2(configfile=None)
def test_fields(self): return_value = {'name': 'net1', 'admin_state_up': True, 'subnets': []} instance = self.plugin.return_value instance.get_network.return_value = return_value self.api.get(_get_path('networks', id=uuidutils.generate_uuid()))
def _add_securityprofile(self, body): fake_securityprofile = json.loads(body) fake_securityprofile["uuid"] = uuidutils.generate_uuid() fake_securityprofile["tenant_id"] = self._get_tag(fake_securityprofile, "os_tid") fake_securityprofile["nova_spid"] = self._get_tag(fake_securityprofile, "nova_spid") self._fake_securityprofile_dict[fake_securityprofile["uuid"]] = fake_securityprofile return fake_securityprofile
def test_generate_pfc_id_uuid_no_hyphen(self): # Keystone tenant_id style uuid id_str = uuidutils.generate_uuid() id_no_hyphen = id_str.replace('-', '') exp_str = (id_str[:14] + id_str[15:]).replace('-', '')[:31] ret_str = self.driver._generate_pfc_id(id_no_hyphen) self.assertEqual(exp_str, ret_str)
def testb_delete_filter(self): t, n, p = self.get_ofc_item_random_params() f_path = "/filters/%s" % uuidutils.generate_uuid() ofc_client.OFCClient.do_request("DELETE", f_path) self.mox.ReplayAll() self.driver.delete_filter(f_path) self.mox.VerifyAll()
def _add_lrouter(self, body): fake_lrouter = json.loads(body) fake_lrouter["uuid"] = uuidutils.generate_uuid() self._fake_lrouter_dict[fake_lrouter["uuid"]] = fake_lrouter fake_lrouter["tenant_id"] = self._get_tag(fake_lrouter, "os_tid") fake_lrouter["lport_count"] = 0 default_nexthop = fake_lrouter["routing_config"].get("default_route_next_hop") fake_lrouter["default_next_hop"] = default_nexthop.get("gateway_ip_address", "0.0.0.0") return fake_lrouter
def __init__(self): # Set the Queue size to 1 so that messages stay on server rather than # being buffered in the process. self.queue = eventlet.queue.Queue(1) self.connection = rpc.create_connection(new=True) topic = "%s.%s" % (rpc_notifier.CONF.notification_topics[0], api.CONF.default_notification_level.lower()) queue_name = "notification_listener_%s" % uuidutils.generate_uuid() self.connection.declare_topic_consumer(topic=topic, queue_name=queue_name, callback=self._add_to_queue) self.connection.consume_in_thread()
def test_create_for_sg(self): sg_id = uuidutils.generate_uuid() sg_name = 'test-sg' calls = [mock.call.add_chain().tenant_id(self._tenant_id), mock.call.add_port_group().tenant_id(self._tenant_id)] self.client.create_for_sg(self._tenant_id, sg_id, sg_name) self.mock_api.assert_has_calls(calls, any_order=True)
def _add_lrouter_nat(self, body, lr_uuid): fake_nat = json.loads(body) new_uuid = uuidutils.generate_uuid() fake_nat['uuid'] = new_uuid fake_nat['lr_uuid'] = lr_uuid self._fake_lrouter_nat_dict[fake_nat['uuid']] = fake_nat if 'match' in fake_nat: match_json = json.dumps(fake_nat['match']) fake_nat['match_json'] = match_json return fake_nat
def test_create_for_sg(self): sg_id = uuidutils.generate_uuid() sg_name = 'test-sg' calls = [ mock.call.add_chain().tenant_id(self._tenant_id), mock.call.add_port_group().tenant_id(self._tenant_id) ] self.client.create_for_sg(self._tenant_id, sg_id, sg_name) self.mock_api.assert_has_calls(calls, any_order=True)
def create_port(self, ofc_network_id, portinfo, port_id=None): ofc_port_id = port_id or uuidutils.generate_uuid() path = self.ports_path % {'network': ofc_network_id} body = {'id': ofc_port_id, 'datapath_id': portinfo.datapath_id, 'port': str(portinfo.port_no), 'vid': str(portinfo.vlan_id)} self.client.post(path, body=body) return self.port_path % {'network': ofc_network_id, 'port': ofc_port_id}
def _add_securityprofile(self, body): fake_securityprofile = json.loads(body) fake_securityprofile['uuid'] = uuidutils.generate_uuid() fake_securityprofile['tenant_id'] = self._get_tag( fake_securityprofile, 'os_tid') fake_securityprofile['nova_spid'] = self._get_tag( fake_securityprofile, 'nova_spid') self._fake_securityprofile_dict[fake_securityprofile['uuid']] = ( fake_securityprofile) return fake_securityprofile
def _add_lrouter(self, body): fake_lrouter = json.loads(body) fake_lrouter['uuid'] = uuidutils.generate_uuid() self._fake_lrouter_dict[fake_lrouter['uuid']] = fake_lrouter fake_lrouter['tenant_id'] = self._get_tag(fake_lrouter, 'os_tid') fake_lrouter['lport_count'] = 0 default_nexthop = fake_lrouter['routing_config'].get( 'default_route_next_hop') fake_lrouter['default_next_hop'] = default_nexthop.get( 'gateway_ip_address', '0.0.0.0') return fake_lrouter
def _add_lswitch(self, body): fake_lswitch = json.loads(body) fake_lswitch['uuid'] = uuidutils.generate_uuid() self._fake_lswitch_dict[fake_lswitch['uuid']] = fake_lswitch # put the tenant_id and the zone_uuid in the main dict # for simplyfying templating zone_uuid = fake_lswitch['transport_zones'][0]['zone_uuid'] fake_lswitch['zone_uuid'] = zone_uuid fake_lswitch['tenant_id'] = self._get_tag(fake_lswitch, 'os_tid') fake_lswitch['lport_count'] = 0 return fake_lswitch
def test_get_router_chains(self): router_id = uuidutils.generate_uuid() in_chain_id = uuidutils.generate_uuid() out_chain_id = uuidutils.generate_uuid() self.mock_api_cfg.chains_in = [ _create_test_router_in_chain(router_id, in_chain_id, self._tenant_id), _create_test_router_out_chain(router_id, out_chain_id, self._tenant_id) ] chains = self.client.get_router_chains(self._tenant_id, router_id) self.mock_api.assert_has_calls( mock.call.get_chains({"tenant_id": self._tenant_id})) self.assertEqual(len(chains), 2) self.assertIn('in', chains) self.assertIn('out', chains) self.assertEqual(chains['in'].get_id(), in_chain_id) self.assertEqual(chains['out'].get_id(), out_chain_id)
def test_delete_for_sg_rule(self): sg_id = uuidutils.generate_uuid() sg_name = 'test-sg' in_chain_id = uuidutils.generate_uuid() out_chain_id = uuidutils.generate_uuid() self.mock_api_cfg.chains_in = [ _create_test_sg_in_chain(sg_id, sg_name, in_chain_id, self._tenant_id), _create_test_sg_out_chain(sg_id, sg_name, out_chain_id, self._tenant_id) ] rule_id = uuidutils.generate_uuid() sg_rule_id = uuidutils.generate_uuid() rule = _create_test_sg_chain_rule(rule_id, in_chain_id, sg_rule_id) self.mock_api_cfg.chains_in[0]['rules'] = [rule] sg_rule = _create_test_sg_rule(self._tenant_id, sg_id, sg_rule_id) self.client.delete_for_sg_rule(sg_rule) self.mock_api.delete_rule.assert_called_once_with(rule_id)
def _add_gatewayservice(self, body): fake_gwservice = json.loads(body) fake_gwservice['uuid'] = str(uuidutils.generate_uuid()) fake_gwservice['tenant_id'] = self._get_tag(fake_gwservice, 'os_tid') # FIXME(salvatore-orlando): For simplicity we're managing only a # single device. Extend the fake client for supporting multiple devices first_gw = fake_gwservice['gateways'][0] fake_gwservice['transport_node_uuid'] = first_gw['transport_node_uuid'] fake_gwservice['device_id'] = first_gw['device_id'] self._fake_gatewayservice_dict[fake_gwservice['uuid']] = ( fake_gwservice) return fake_gwservice