desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Query routers and their related floating_ips, interfaces.'
| def get_sync_data(self, context, router_ids=None, active=None):
| with context.session.begin(subtransactions=True):
routers = self._get_sync_routers(context, router_ids=router_ids, active=active)
router_ids = [router['id'] for router in routers]
floating_ips = self._get_sync_floating_ips(context, router_ids)
interfaces = self.get_sync_interfaces(co... |
'update security groups on port
This method returns a flag which indicates request notification
is required and does not perform notification itself.
It is because another changes for the port may require notification.'
| def update_security_group_on_port(self, context, id, port, original_port, updated_port):
| need_notify = False
if (ext_sg.SECURITYGROUPS in port['port']):
port['port'][ext_sg.SECURITYGROUPS] = self._get_security_groups_on_port(context, port)
self._delete_port_security_group_bindings(context, id)
self._process_port_create_security_group(context, id, port['port'][ext_sg.SECURITY... |
'check security group member updated or not
This method returns a flag which indicates request notification
is required and does not perform notification itself.
It is because another changes for the port may require notification.'
| def is_security_group_member_updated(self, context, original_port, updated_port):
| need_notify = False
if ((original_port['fixed_ips'] != updated_port['fixed_ips']) or (not utils.compare_elements(original_port.get(ext_sg.SECURITYGROUPS), updated_port.get(ext_sg.SECURITYGROUPS)))):
self.notify_security_groups_member_updated(context, updated_port)
need_notify = True
return n... |
'notify update event of security group members
The agent setups the iptables rule to allow
ingress packet from the dhcp server (as a part of provider rules),
so we need to notify an update of dhcp server ip
address to the plugin agent.
security_groups_provider_updated() just notifies that an event
occurs and the plugin... | def notify_security_groups_member_updated(self, context, port):
| if (port['device_owner'] == q_const.DEVICE_OWNER_DHCP):
self.notifier.security_groups_provider_updated(context)
else:
self.notifier.security_groups_member_updated(context, port.get(ext_sg.SECURITYGROUPS))
|
'return security group rules for each port
also convert remote_group_id rule
to source_ip_prefix and dest_ip_prefix rule
:params devices: list of devices
:returns: port correspond to the devices with security group rules'
| def security_group_rules_for_devices(self, context, **kwargs):
| devices = kwargs.get('devices')
ports = {}
for device in devices:
port = self.get_port_from_device(device)
if (not port):
continue
if port['device_owner'].startswith('network:'):
continue
ports[port['id']] = port
return self._security_group_rules_f... |
'Given a list of resources, retrieve the quotas for the given
tenant.
:param context: The request context, for access checks.
:param resources: A dictionary of the registered resource keys.
:param tenant_id: The ID of the tenant to return quotas for.
:return dict: from resource name to dict of name and limit'
| @staticmethod
def get_tenant_quotas(context, resources, tenant_id):
| tenant_quota = dict(((key, resource.default) for (key, resource) in resources.items()))
q_qry = context.session.query(Quota).filter_by(tenant_id=tenant_id)
tenant_quota.update(((q['resource'], q['limit']) for q in q_qry.all()))
return tenant_quota
|
'Delete the quota entries for a given tenant_id.
Atfer deletion, this tenant will use default quota values in conf.'
| @staticmethod
def delete_tenant_quota(context, tenant_id):
| with context.session.begin():
tenant_quotas = context.session.query(Quota).filter_by(tenant_id=tenant_id).all()
for quota in tenant_quotas:
context.session.delete(quota)
|
'Given a list of resources, retrieve the quotas for the all
tenants.
:param context: The request context, for access checks.
:param resources: A dictionary of the registered resource keys.
:return quotas: list of dict of tenant_id:, resourcekey1:
resourcekey2: ...'
| @staticmethod
def get_all_quotas(context, resources):
| tenant_default = dict(((key, resource.default) for (key, resource) in resources.items()))
all_tenant_quotas = {}
for quota in context.session.query(Quota).all():
tenant_id = quota['tenant_id']
tenant_quota = all_tenant_quotas.get(tenant_id)
if (tenant_quota is None):
tena... |
'A helper method which retrieves the quotas for the specific
resources identified by keys, and which apply to the current
context.
:param context: The request context, for access checks.
:param tenant_id: the tenant_id to check quota.
:param resources: A dictionary of the registered resources.
:param keys: A list of th... | def _get_quotas(self, context, tenant_id, resources, keys):
| desired = set(keys)
sub_resources = dict(((k, v) for (k, v) in resources.items() if (k in desired)))
if (len(keys) != len(sub_resources)):
unknown = (desired - set(sub_resources.keys()))
raise exceptions.QuotaResourceUnknown(unknown=sorted(unknown))
quotas = DbQuotaDriver.get_tenant_quot... |
'Check simple quota limits.
For limits--those quotas for which there is no usage
synchronization function--this method checks that a set of
proposed values are permitted by the limit restriction.
This method will raise a QuotaResourceUnknown exception if a
given resource is unknown or if it is not a simple limit
resour... | def limit_check(self, context, tenant_id, resources, values):
| unders = [key for (key, val) in values.items() if (val < 0)]
if unders:
raise exceptions.InvalidQuotaValue(unders=sorted(unders))
quotas = self._get_quotas(context, tenant_id, resources, values.keys())
overs = [key for (key, val) in values.items() if ((quotas[key] >= 0) and (quotas[key] < val))]... |
'Returns a tuple of (port_security_enabled, has_ip) where
port_security_enabled and has_ip are bools. Port_security is the
value assocated with the port if one is present otherwise the value
associated with the network is returned. has_ip is if the port is
associated with an ip or not.'
| def _determine_port_security_and_has_ip(self, context, port):
| has_ip = self._ip_on_port(port)
if (port.get('device_owner') and port['device_owner'].startswith('network:')):
return (False, has_ip)
if ((psec.PORTSECURITY in port) and isinstance(port[psec.PORTSECURITY], bool)):
port_security_enabled = port[psec.PORTSECURITY]
else:
port_securit... |
'Create or update agent according to report.'
| def create_or_update_agent(self, context, agent):
| with context.session.begin(subtransactions=True):
res_keys = ['agent_type', 'binary', 'host', 'topic']
res = dict(((k, agent[k]) for k in res_keys))
configurations_dict = agent.get('configurations', {})
res['configurations'] = jsonutils.dumps(configurations_dict)
current_time... |
'Report state from agent to server.'
| def report_state(self, context, **kwargs):
| time = kwargs['time']
time = timeutils.parse_strtime(time)
if (self.START_TIME > time):
LOG.debug(_('Message with invalid timestamp received'))
return
agent_state = kwargs['agent_state']['agent_state']
plugin = manager.QuantumManager.get_plugin()
plugin.create_or_upda... |
'Override some configuration values.
The keyword arguments are the names of configuration options to
override and their values.
If a group argument is supplied, the overrides are applied to
the specified configuration option group.
All overrides are automatically cleared at the end of the current
test by the fixtures c... | def config(self, **kw):
| group = kw.pop('group', None)
for (k, v) in kw.iteritems():
CONF.set_override(k, v, group)
|
'Constructs a test dictionary and a definition of constraints.
:return: A (dictionary, constraint) tuple'
| def _construct_dict_and_constraints(self):
| constraints = {'key1': {'type:values': ['val1', 'val2'], 'required': True}, 'key2': {'type:string': None, 'required': False}, 'key3': {'type:dict': {'k4': {'type:string': None, 'required': True}}, 'required': True}}
dictionary = {'key1': 'val1', 'key2': 'a string value', 'key3': {'k4': 'a string val... |
'Deletes default egress rules given a security group ID'
| def _delete_default_security_group_egress_rules(self, security_group_id):
| res = self._list('security-group-rules', query_params=('security_group_id=%s' % security_group_id))
for r in res['security_group_rules']:
if ((r['direction'] == 'egress') and (not r['port_range_max']) and (not r['port_range_min']) and (not r['protocol']) and (not r['remote_ip_prefix'])):
sel... |
'Asserts that the sg rule has expected key/value pairs passed
in as expected_kvs dictionary'
| def _assert_sg_rule_has_kvs(self, security_group_rule, expected_kvs):
| for (k, v) in expected_kvs.iteritems():
self.assertEquals(security_group_rule[k], v)
|
'does the entity deletion based on naming convention'
| def _test_entity_delete(self, entity):
| entity_id = _uuid()
res = self.api.delete(_get_path((('lb/' + entity) + 's'), id=entity_id, fmt=self.fmt))
delete_entity = getattr(self.plugin.return_value, ('delete_' + entity))
delete_entity.assert_called_with(mock.ANY, entity_id)
self.assertEqual(res.status_int, exc.HTTPNoContent.code)
|
'Test loadbalancer db plugin via extension and directly'
| def test_create_vip_twice_for_same_pool(self):
| with self.subnet() as subnet:
with self.pool(name='pool1') as pool:
with self.vip(name='vip1', subnet=subnet, pool=pool) as vip:
vip_data = {'name': 'vip1', 'pool_id': pool['pool']['id'], 'description': '', 'protocol_port': 80, 'protocol': 'HTTP', 'connection_limit': (-1), 'admin... |
'Returns Extended Resource for dummy management'
| @classmethod
def get_resources(cls):
| q_mgr = manager.QuantumManager.get_instance()
dummy_inst = q_mgr.get_service_plugins()['DUMMY']
controller = base.create_resource(COLLECTION_NAME, RESOURCE_NAME, dummy_inst, RESOURCE_ATTRIBUTE_MAP[COLLECTION_NAME])
return [extensions.ResourceExtension(COLLECTION_NAME, controller)]
|
'Creates a bulk request from a list of objects'
| def _create_bulk_from_list(self, fmt, resource, objects, **kwargs):
| collection = ('%ss' % resource)
req_data = {collection: objects}
req = self.new_create_request(collection, req_data, fmt)
if (('set_context' in kwargs) and (kwargs['set_context'] is True) and ('tenant_id' in kwargs)):
req.environ['quantum.context'] = context.Context('', kwargs['tenant_id'])
... |
'Creates a bulk request for any kind of resource'
| def _create_bulk(self, fmt, number, resource, data, name='test', **kwargs):
| objects = []
collection = ('%ss' % resource)
for i in range(0, number):
obj = copy.deepcopy(data)
obj[resource]['name'] = ('%s_%s' % (name, i))
if (('override' in kwargs) and (i in kwargs['override'])):
obj[resource].update(kwargs['override'][i])
objects.append(ob... |
'Invoked by test cases for injecting failures in plugin'
| def _do_side_effect(self, patched_plugin, orig, *args, **kwargs):
| def second_call(*args, **kwargs):
raise q_exc.QuantumException
patched_plugin.side_effect = second_call
return orig(*args, **kwargs)
|
'If a field used by policy is selected, do not duplicate it.
Verifies that if the field parameter explicitly specifies a field
which is used by the policy engine, then it is not duplicated
in the response.'
| def test_list_with_fields_noadmin_and_policy_field(self):
| tenant_id = 'some_tenant'
self._create_network(self.fmt, 'some_net', True, tenant_id=tenant_id, set_context=True)
req = self.new_list_request('networks', params='fields=tenant_id')
req.environ['quantum.context'] = context.Context('', tenant_id)
res = req.get_response(self.api)
self._check_list_w... |
'Test update of port IP.
Check that a configured IP 10.0.0.2 is replaced by 10.0.0.10.'
| def test_update_port_update_ip(self):
| with self.subnet() as subnet:
with self.port(subnet=subnet) as port:
ips = port['port']['fixed_ips']
self.assertEqual(len(ips), 1)
self.assertEqual(ips[0]['ip_address'], '10.0.0.2')
self.assertEqual(ips[0]['subnet_id'], subnet['subnet']['id'])
data... |
'Update IP and generate new IP on port.
Check a port update with the specified subnet_id\'s. A IP address
will be allocated for each subnet_id.'
| def test_update_port_update_ips(self):
| with self.subnet() as subnet:
with self.port(subnet=subnet) as port:
data = {'port': {'admin_state_up': False, 'fixed_ips': [{'subnet_id': subnet['subnet']['id']}]}}
req = self.new_update_request('ports', data, port['port']['id'])
res = self.deserialize(self.fmt, req.get_... |
'Test update of port with additional IP.'
| def test_update_port_add_additional_ip(self):
| with self.subnet() as subnet:
with self.port(subnet=subnet) as port:
data = {'port': {'admin_state_up': False, 'fixed_ips': [{'subnet_id': subnet['subnet']['id']}, {'subnet_id': subnet['subnet']['id']}]}}
req = self.new_update_request('ports', data, port['port']['id'])
re... |
'testing the string representation of \'model\' classes'
| def test_repr(self):
| network = models_v2.Network(name='net_net', status='OK', admin_state_up=True)
actual_repr_output = repr(network)
exp_start_with = '<quantum.db.models_v2.Network'
exp_middle = ('[object at %x]' % id(network))
exp_end_with = " {tenant_id=None, id=None, name='net_net', status='OK', ... |
'Makes sure ValueError from bug 926412 is gone'
| def test_KillFilter_no_raise(self):
| f = filters.KillFilter('root', '')
usercmd = ['notkill', 999999]
self.assertFalse(f.match(usercmd))
usercmd = ['kill', 'notapid']
self.assertFalse(f.match(usercmd))
|
'Makes sure deleted exe\'s are killed correctly'
| def test_KillFilter_deleted_exe(self):
| with mock.patch('os.readlink') as mock_readlink:
mock_readlink.return_value = '/bin/commandddddd (deleted)'
f = filters.KillFilter('root', '/bin/commandddddd')
usercmd = ['kill', 1234]
self.assertTrue(f.match(usercmd))
mock_readlink.assert_called_once_with('/proc/1234/exe'... |
'Identifies resource type and relevant uuids in the uri
/ws.v1/lswitch/xxx
/ws.v1/lswitch/xxx/status
/ws.v1/lswitch/xxx/lport/yyy
/ws.v1/lswitch/xxx/lport/yyy/status
/ws.v1/lrouter/zzz
/ws.v1/lrouter/zzz/status
/ws.v1/lrouter/zzz/lport/www
/ws.v1/lrouter/zzz/lport/www/status
/ws.v1/lqueue/xxx'
| def _get_resource_type(self, path):
| uri_split = path.split('/')[1:]
suffix = ''
idx = (len(uri_split) - 1)
if ('status' in uri_split[idx]):
suffix = 'status'
idx = (idx - 1)
elif ('attachment' in uri_split[idx]):
suffix = 'attachment'
idx = (idx - 1)
uuids = []
if (uri_split[idx].replace('-', ''... |
'Verify data on fake NVP API client in order to validate
plugin did set them properly'
| def _nvp_validate_ext_gw(self, router_id, l3_gw_uuid, vlan_id):
| ports = [port for port in self.fc._fake_lrouter_lport_dict.values() if ((port['lr_uuid'] == router_id) and (port['att_type'] == 'L3GatewayAttachment'))]
self.assertEqual(len(ports), 1)
self.assertEqual(ports[0]['attachment_gwsvc_uuid'], l3_gw_uuid)
self.assertEqual(ports[0].get('vlan_id'), vlan_id)
|
'Get all networks'
| def get_all_networks(self, tenant_id):
| nets = []
try:
for net in db.network_list(tenant_id):
LOG.debug('Getting network: %s', net.uuid)
net_dict = {}
net_dict['tenant_id'] = net.tenant_id
net_dict['id'] = str(net.uuid)
net_dict['name'] = net.name
nets.append(net_di... |
'Get a network'
| def get_network(self, network_id):
| net = []
try:
for net in db.network_get(network_id):
LOG.debug('Getting network: %s', net.uuid)
net_dict = {}
net_dict['tenant_id'] = net.tenant_id
net_dict['id'] = str(net.uuid)
net_dict['name'] = net.name
net.append(net_dict... |
'Create a network'
| def create_network(self, tenant_id, net_name):
| net_dict = {}
try:
res = db.network_create(tenant_id, net_name)
LOG.debug('Created network: %s', res.uuid)
net_dict['tenant_id'] = res.tenant_id
net_dict['id'] = str(res.uuid)
net_dict['name'] = res.name
return net_dict
except Exception as exc:
L... |
'Delete a network'
| def delete_network(self, net_id):
| try:
net = db.network_destroy(net_id)
LOG.debug('Deleted network: %s', net.uuid)
net_dict = {}
net_dict['id'] = str(net.uuid)
return net_dict
except Exception as exc:
LOG.error('Failed to delete network: %s', str(exc))
|
'Rename a network'
| def update_network(self, tenant_id, net_id, param_data):
| try:
print param_data
net = db.network_update(net_id, tenant_id, **param_data)
LOG.debug('Updated network: %s', net.uuid)
net_dict = {}
net_dict['id'] = str(net.uuid)
net_dict['name'] = net.name
return net_dict
except Exception as exc:
LOG.er... |
'Get all ports'
| def get_all_ports(self, net_id):
| ports = []
try:
for port in db.port_list(net_id):
LOG.debug('Getting port: %s', port.uuid)
port_dict = {}
port_dict['id'] = str(port.uuid)
port_dict['net-id'] = str(port.network_id)
port_dict['attachment'] = port.interface_id
... |
'Get a port'
| def get_port(self, net_id, port_id):
| port_list = []
port = db.port_get(port_id, net_id)
try:
LOG.debug('Getting port: %s', port.uuid)
port_dict = {}
port_dict['id'] = str(port.uuid)
port_dict['net-id'] = str(port.network_id)
port_dict['attachment'] = port.interface_id
port_dict['state'] = p... |
'Add a port'
| def create_port(self, net_id):
| port_dict = {}
try:
port = db.port_create(net_id)
LOG.debug('Creating port %s', port.uuid)
port_dict['id'] = str(port.uuid)
port_dict['net-id'] = str(port.network_id)
port_dict['attachment'] = port.interface_id
port_dict['state'] = port.state
return ... |
'Delete a port'
| def delete_port(self, net_id, port_id):
| try:
port = db.port_destroy(port_id, net_id)
LOG.debug('Deleted port %s', port.uuid)
port_dict = {}
port_dict['id'] = str(port.uuid)
return port_dict
except Exception as exc:
LOG.error('Failed to delete port: %s', str(exc))
|
'Update a port'
| def update_port(self, net_id, port_id, **kwargs):
| try:
port = db.port_update(port_id, net_id, **kwargs)
LOG.debug('Updated port %s', port.uuid)
port_dict = {}
port_dict['id'] = str(port.uuid)
port_dict['net-id'] = str(port.network_id)
port_dict['attachment'] = port.interface_id
port_dict['state'] = port... |
'Plug interface to a port'
| def plug_interface(self, net_id, port_id, int_id):
| try:
port = db.port_set_attachment(port_id, net_id, int_id)
LOG.debug('Attached interface to port %s', port.uuid)
port_dict = {}
port_dict['id'] = str(port.uuid)
port_dict['net-id'] = str(port.network_id)
port_dict['attachment'] = port.interface_id
... |
'Unplug interface to a port'
| def unplug_interface(self, net_id, port_id):
| try:
db.port_unset_attachment(port_id, net_id)
LOG.debug('Detached interface from port %s', port_id)
except Exception as exc:
LOG.error('Failed to unplug interface: %s', str(exc))
|
'Test serialize verifies that exception InvalidContentType is raised'
| def test_serialize_unknown_content_type(self):
| input_dict = {'servers': {'test': 'pass'}}
content_type = 'application/unknown'
serializer = wsgi.Serializer()
self.assertRaises(exception.InvalidContentType, serializer.serialize, input_dict, content_type)
|
'Test get deserialize verifies
that exception InvalidContentType is raised'
| def test_get_deserialize_handler_unknown_content_type(self):
| content_type = 'application/unknown'
serializer = wsgi.Serializer()
self.assertRaises(exception.InvalidContentType, serializer.get_deserialize_handler, content_type)
|
'Test serialize with content type json'
| def test_serialize_content_type_json(self):
| input_data = {'servers': ['test=pass']}
content_type = 'application/json'
serializer = wsgi.Serializer(default_xmlns='fake')
result = serializer.serialize(input_data, content_type)
self.assertEqual('{"servers": ["test=pass"]}', result)
|
'Test serialize with content type xml'
| def test_serialize_content_type_xml(self):
| input_data = {'servers': ['test=pass']}
content_type = 'application/xml'
serializer = wsgi.Serializer(default_xmlns='fake')
result = serializer.serialize(input_data, content_type)
expected = '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<servers xmlns="http://openstack.org/quantum/api/v2.0" ... |
'Test serialize verifies that exception is raises'
| def test_deserialize_raise_bad_request(self):
| content_type = 'application/unknown'
data_string = 'test'
serializer = wsgi.Serializer(default_xmlns='fake')
self.assertRaises(webob.exc.HTTPBadRequest, serializer.deserialize, data_string, content_type)
|
'Test Serializer.deserialize with content type json'
| def test_deserialize_json_content_type(self):
| content_type = 'application/json'
data_string = '{"servers": ["test=pass"]}'
serializer = wsgi.Serializer(default_xmlns='fake')
result = serializer.deserialize(data_string, content_type)
self.assertEqual({'body': {u'servers': [u'test=pass']}}, result)
|
'Test deserialize with content type xml'
| def test_deserialize_xml_content_type(self):
| content_type = 'application/xml'
data_string = '<servers xmlns="fake"><server>test=pass</server></servers>'
serializer = wsgi.Serializer(default_xmlns='fake', metadata={'xmlns': 'fake'})
result = serializer.deserialize(data_string, content_type)
expected = {'body': {'servers': {'server': 'test=pa... |
'Test deserialize with content type xml with meta'
| def test_deserialize_xml_content_type_with_meta(self):
| content_type = 'application/xml'
data_string = '<servers><server name="s1"><test test="a">passed</test></server></servers>'
metadata = {'plurals': {'servers': 'server'}, 'xmlns': 'fake'}
serializer = wsgi.Serializer(default_xmlns='fake', metadata=metadata)
result = serializer.deserialize(data_... |
'Test Serializer.serialize with content type xml with meta dict'
| def test_serialize_xml_root_key_is_dict(self):
| content_type = 'application/xml'
data = {'servers': {'network': (2, 3)}}
metadata = {'xmlns': 'fake'}
serializer = wsgi.Serializer(default_xmlns='fake', metadata=metadata)
result = serializer.serialize(data, content_type)
result = result.replace('\n', '')
expected = '<?xml version=\'1.0\'... |
'Test serialize with content type xml with meta list'
| def test_serialize_xml_root_key_is_list(self):
| input_dict = {'servers': ['test=pass']}
content_type = 'application/xml'
metadata = {'application/xml': {'xmlns': 'fake'}}
serializer = wsgi.Serializer(default_xmlns='fake', metadata=metadata)
result = serializer.serialize(input_dict, content_type)
result = result.replace('\n', '').replace(' ... |
'Test RequestDeserializer.get_body_deserializer'
| def test_get_deserializer(self):
| expected_json_serializer = self.deserializer.get_body_deserializer('application/json')
expected_xml_serializer = self.deserializer.get_body_deserializer('application/xml')
self.assertEqual(expected_json_serializer, self.body_deserializers['application/json'])
self.assertEqual(expected_xml_serializer, se... |
'Test RequestDeserializer.get_expected_content_type'
| def test_get_expected_content_type(self):
| request = wsgi.Request.blank('/')
request.headers['Accept'] = 'application/json'
self.assertEqual(self.deserializer.get_expected_content_type(request), 'application/json')
|
'Test RequestDeserializer.get_action_args'
| def test_get_action_args(self):
| env = {'wsgiorg.routing_args': [None, {'controller': None, 'format': None, 'action': 'update', 'id': 12}]}
expected = {'action': 'update', 'id': 12}
self.assertEqual(self.deserializer.get_action_args(env), expected)
|
'Test RequestDeserializer.deserialize'
| def test_deserialize(self):
| with mock.patch.object(self.deserializer, 'get_action_args') as mock_method:
mock_method.return_value = {'action': 'create'}
request = wsgi.Request.blank('/')
request.headers['Accept'] = 'application/xml'
deserialized = self.deserializer.deserialize(request)
expected = ('crea... |
'Test get body deserializer verifies
that exception InvalidContentType is raised'
| def test_get_body_deserializer_unknown_content_type(self):
| content_type = 'application/unknown'
deserializer = wsgi.RequestDeserializer()
self.assertRaises(exception.InvalidContentType, deserializer.get_body_deserializer, content_type)
|
'Test serialize verifies
that exception InvalidContentType is raised'
| def test_serialize_unknown_content_type(self):
| self.assertRaises(exception.InvalidContentType, self.serializer.serialize, {}, 'application/unknown')
|
'Test get body serializer verifies
that exception InvalidContentType is raised'
| def test_get_body_serializer(self):
| self.assertRaises(exception.InvalidContentType, self.serializer.get_body_serializer, 'application/unknown')
|
'Test ResponseSerializer.get_body_serializer'
| def test_get_serializer(self):
| content_type = 'application/json'
self.assertEqual(self.serializer.get_body_serializer(content_type), self.body_serializers[content_type])
|
'Test ActionDispatcher.dispatch'
| def test_dispatch(self):
| serializer = wsgi.ActionDispatcher()
serializer.create = (lambda x: x)
self.assertEqual(serializer.dispatch('pants', action='create'), 'pants')
|
'Test ActionDispatcher.dispatch with none action'
| def test_dispatch_action_None(self):
| serializer = wsgi.ActionDispatcher()
serializer.create = (lambda x: (x + ' pants'))
serializer.default = (lambda x: (x + ' trousers'))
self.assertEqual(serializer.dispatch('Two', action=None), 'Two trousers')
|
'Test verifies JsonDeserializer.default
raises exception MalformedRequestBody correctly'
| def test_default_raise_Malformed_Exception(self):
| data_string = ''
deserializer = wsgi.JSONDeserializer()
self.assertRaises(exception.MalformedRequestBody, deserializer.default, data_string)
|
'Test verifies that exception MalformedRequestBody is raised'
| def test_default_raise_Malformed_Exception(self):
| data_string = ''
deserializer = wsgi.XMLDeserializer()
self.assertRaises(exception.MalformedRequestBody, deserializer.default, data_string)
|
'Register two L3 agents and two DHCP agents.'
| def _register_agent_states(self):
| l3_hosta = {'binary': 'quantum-l3-agent', 'host': L3_HOSTA, 'topic': topics.L3_AGENT, 'configurations': {'use_namespaces': True, 'router_id': None, 'handle_internal_only_routers': True, 'gateway_external_network_id': None, 'interface_driver': 'interface_driver'}, 'agent_type': constants.AGENT_TYPE_L3}
l3_hostb ... |
'Returns Ext Resources'
| @classmethod
def get_resources(cls):
| exts = []
plugin = manager.QuantumManager.get_plugin()
resource_name = 'ext_test_resource'
collection_name = (resource_name + 's')
params = RESOURCE_ATTRIBUTE_MAP.get(collection_name, dict())
quota.QUOTAS.register_resource_by_name(resource_name)
controller = base.create_resource(collection_n... |
'create random parameters for ofc_item test'
| def get_ofc_item_random_params(self):
| 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)
|
'OFC description consists of [A-Za-z0-9_].'
| def get_ofc_description(self, desc):
| return desc.replace('-', '_').replace(' ', '_')
|
'create random parameters for portinfo test'
| def get_random_params(self):
| 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)
|
'test create ofc_tenant'
| def testa_create_ofc_tenant(self):
| (t, n, p, f, none) = self.get_random_params()
self.assertFalse(ndb.get_ofc_item(self.ctx.session, 'ofc_tenant', t))
self.ofc.create_ofc_tenant(self.ctx, t)
self.assertTrue(ndb.get_ofc_item(self.ctx.session, 'ofc_tenant', t))
tenant = ndb.get_ofc_item(self.ctx.session, 'ofc_tenant', t)
self.asser... |
'test exists_ofc_tenant'
| def testb_exists_ofc_tenant(self):
| (t, n, p, f, none) = self.get_random_params()
self.assertFalse(self.ofc.exists_ofc_tenant(self.ctx, t))
self.ofc.create_ofc_tenant(self.ctx, t)
self.assertTrue(self.ofc.exists_ofc_tenant(self.ctx, t))
|
'test delete ofc_tenant'
| def testc_delete_ofc_tenant(self):
| (t, n, p, f, none) = self.get_random_params()
self.ofc.create_ofc_tenant(self.ctx, t)
self.assertTrue(ndb.get_ofc_item(self.ctx.session, 'ofc_tenant', t))
self.ofc.delete_ofc_tenant(self.ctx, t)
self.assertFalse(ndb.get_ofc_item(self.ctx.session, 'ofc_tenant', t))
|
'test create ofc_network'
| def testd_create_ofc_network(self):
| (t, n, p, f, none) = self.get_random_params()
self.ofc.create_ofc_tenant(self.ctx, t)
self.assertFalse(ndb.get_ofc_item(self.ctx.session, 'ofc_network', n))
self.ofc.create_ofc_network(self.ctx, t, n)
self.assertTrue(ndb.get_ofc_item(self.ctx.session, 'ofc_network', n))
network = ndb.get_ofc_ite... |
'test exists_ofc_network'
| def teste_exists_ofc_network(self):
| (t, n, p, f, none) = self.get_random_params()
self.ofc.create_ofc_tenant(self.ctx, t)
self.assertFalse(self.ofc.exists_ofc_network(self.ctx, n))
self.ofc.create_ofc_network(self.ctx, t, n)
self.assertTrue(self.ofc.exists_ofc_network(self.ctx, n))
|
'test delete ofc_network'
| def testf_delete_ofc_network(self):
| (t, n, p, f, none) = self.get_random_params()
self.ofc.create_ofc_tenant(self.ctx, t)
self.ofc.create_ofc_network(self.ctx, t, n)
self.assertTrue(ndb.get_ofc_item(self.ctx.session, 'ofc_network', n))
self.ofc.delete_ofc_network(self.ctx, n, {'tenant_id': t})
self.assertFalse(ndb.get_ofc_item(sel... |
'test create ofc_port'
| def testg_create_ofc_port(self):
| (t, n, p, f, none) = self.get_random_params()
self.ofc.create_ofc_tenant(self.ctx, t)
self.ofc.create_ofc_network(self.ctx, t, n)
ndb.add_portinfo(self.ctx.session, p, '0xabc', 1, 65535, '00:11:22:33:44:55')
self.assertFalse(ndb.get_ofc_item(self.ctx.session, 'ofc_port', p))
port = {'tenant_id':... |
'test exists_ofc_port'
| def testh_exists_ofc_port(self):
| (t, n, p, f, none) = self.get_random_params()
self.ofc.create_ofc_tenant(self.ctx, t)
self.ofc.create_ofc_network(self.ctx, t, n)
ndb.add_portinfo(self.ctx.session, p, '0xabc', 2, 65535, '00:12:22:33:44:55')
self.assertFalse(self.ofc.exists_ofc_port(self.ctx, p))
port = {'tenant_id': t, 'network... |
'test delete ofc_port'
| def testi_delete_ofc_port(self):
| (t, n, p, f, none) = self.get_random_params()
self.ofc.create_ofc_tenant(self.ctx, t)
self.ofc.create_ofc_network(self.ctx, t, n)
ndb.add_portinfo(self.ctx.session, p, '0xabc', 3, 65535, '00:13:22:33:44:55')
port = {'tenant_id': t, 'network_id': n}
self.ofc.create_ofc_port(self.ctx, p, port)
... |
'test create ofc_filter'
| def testj_create_ofc_packet_filter(self):
| (t, n, p, f, none) = self.get_random_params()
self.ofc.create_ofc_tenant(self.ctx, t)
self.ofc.create_ofc_network(self.ctx, t, n)
self.assertFalse(ndb.get_ofc_item(self.ctx.session, 'ofc_packet_filter', f))
pf = {'tenant_id': t, 'network_id': n}
self.ofc.create_ofc_packet_filter(self.ctx, f, pf)... |
'test exists_ofc_packet_filter'
| def testk_exists_ofc_packet_filter(self):
| (t, n, p, f, none) = self.get_random_params()
self.ofc.create_ofc_tenant(self.ctx, t)
self.ofc.create_ofc_network(self.ctx, t, n)
self.assertFalse(self.ofc.exists_ofc_packet_filter(self.ctx, f))
pf = {'tenant_id': t, 'network_id': n}
self.ofc.create_ofc_packet_filter(self.ctx, f, pf)
self.as... |
'test delete ofc_filter'
| def testl_delete_ofc_packet_filter(self):
| (t, n, p, f, none) = self.get_random_params()
self.ofc.create_ofc_tenant(self.ctx, t)
self.ofc.create_ofc_network(self.ctx, t, n)
pf = {'tenant_id': t, 'network_id': n}
self.ofc.create_ofc_packet_filter(self.ctx, f, pf)
self.assertTrue(ndb.get_ofc_item(self.ctx.session, 'ofc_packet_filter', f))
... |
'Setup for tests'
| def setUp(self):
| super(NECPluginV2DBTestBase, self).setUp()
ndb.initialize()
self.session = db_api.get_session()
self.addCleanup(ndb.clear_db)
|
'create random parameters for ofc_item test'
| def get_ofc_item_random_params(self):
| ofc_id = uuidutils.generate_uuid()
quantum_id = uuidutils.generate_uuid()
none = uuidutils.generate_uuid()
return (ofc_id, quantum_id, none)
|
'create random parameters for portinfo test'
| def get_portinfo_random_params(self):
| port_id = uuidutils.generate_uuid()
datapath_id = hex(random.randint(0, 4294967295))
port_no = random.randint(1, 100)
vlan_id = random.randint(0, 4095)
mac = ':'.join([('%02x' % random.randint(0, 255)) for x in range(6)])
none = uuidutils.generate_uuid()
return (port_id, datapath_id, port_no... |
'test add OFC item'
| def testa_add_ofc_item(self):
| (o, q, n) = self.get_ofc_item_random_params()
tenant = ndb.add_ofc_item(self.session, 'ofc_tenant', q, o)
self.assertEqual(tenant.ofc_id, o)
self.assertEqual(tenant.quantum_id, q)
self.assertRaises(nexc.NECDBException, ndb.add_ofc_item, self.session, 'ofc_tenant', q, o)
|
'test get OFC item'
| def testb_get_ofc_item(self):
| (o, q, n) = self.get_ofc_item_random_params()
ndb.add_ofc_item(self.session, 'ofc_tenant', q, o)
tenant = ndb.get_ofc_item(self.session, 'ofc_tenant', q)
self.assertEqual(tenant.ofc_id, o)
self.assertEqual(tenant.quantum_id, q)
tenant_none = ndb.get_ofc_item(self.session, 'ofc_tenant', n)
se... |
'test get OFC d'
| def testb_get_ofc_id(self):
| (o, q, n) = self.get_ofc_item_random_params()
ndb.add_ofc_item(self.session, 'ofc_tenant', q, o)
tenant_id = ndb.get_ofc_id(self.session, 'ofc_tenant', q)
self.assertEqual(tenant_id, o)
tenant_none = ndb.get_ofc_item(self.session, 'ofc_tenant', n)
self.assertEqual(None, tenant_none)
|
'test get OFC d'
| def testb_exists_ofc_item(self):
| (o, q, n) = self.get_ofc_item_random_params()
ndb.add_ofc_item(self.session, 'ofc_tenant', q, o)
ret = ndb.exists_ofc_item(self.session, 'ofc_tenant', q)
self.assertTrue(ret)
tenant_none = ndb.get_ofc_item(self.session, 'ofc_tenant', n)
self.assertEqual(None, tenant_none)
|
'test find OFC item'
| def testc_find_ofc_item(self):
| (o, q, n) = self.get_ofc_item_random_params()
ndb.add_ofc_item(self.session, 'ofc_tenant', q, o)
tenant = ndb.find_ofc_item(self.session, 'ofc_tenant', o)
self.assertEqual(tenant.ofc_id, o)
self.assertEqual(tenant.quantum_id, q)
tenant_none = ndb.find_ofc_item(self.session, 'ofc_tenant', n)
... |
'test delete OFC item'
| def testc_del_ofc_item(self):
| (o, q, n) = self.get_ofc_item_random_params()
ndb.add_ofc_item(self.session, 'ofc_tenant', q, o)
ndb.del_ofc_item(self.session, 'ofc_tenant', q)
tenant_none = ndb.get_ofc_item(self.session, 'ofc_tenant', q)
self.assertEqual(None, tenant_none)
tenant_none = ndb.find_ofc_item(self.session, 'ofc_te... |
'test add portinfo'
| def testd_add_portinfo(self):
| (i, d, p, v, m, n) = self.get_portinfo_random_params()
portinfo = ndb.add_portinfo(self.session, i, d, p, v, m)
self.assertEqual(portinfo.id, i)
self.assertEqual(portinfo.datapath_id, d)
self.assertEqual(portinfo.port_no, p)
self.assertEqual(portinfo.vlan_id, v)
self.assertEqual(portinfo.mac... |
'test get portinfo'
| def teste_get_portinfo(self):
| (i, d, p, v, m, n) = self.get_portinfo_random_params()
ndb.add_portinfo(self.session, i, d, p, v, m)
portinfo = ndb.get_portinfo(self.session, i)
self.assertEqual(portinfo.id, i)
self.assertEqual(portinfo.datapath_id, d)
self.assertEqual(portinfo.port_no, p)
self.assertEqual(portinfo.vlan_id... |
'test delete portinfo'
| def testf_del_portinfo(self):
| (i, d, p, v, m, n) = self.get_portinfo_random_params()
ndb.add_portinfo(self.session, i, d, p, v, m)
portinfo = ndb.get_portinfo(self.session, i)
self.assertEqual(portinfo.id, i)
ndb.del_portinfo(self.session, i)
portinfo_none = ndb.get_portinfo(self.session, i)
self.assertEqual(None, portin... |
'create random parameters for ofc_item test'
| def get_ofc_item_random_params(self):
| 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)
|
'create random parameters for ofc_item test'
| def get_ofc_item_random_params(self):
| (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':... |
':param details: the details to return for the device
:param func_name: the function that should be called
:returns: whether the named function was called'
| def mock_treat_devices_added(self, details, func_name):
| attrs = {'get_device_details.return_value': details}
self.agent.plugin_rpc.configure_mock(**attrs)
with mock.patch.object(self.agent, func_name) as func:
self.assertFalse(self.agent._treat_devices_added([{}]))
return func.called
|
':param details: the details to return for the device
:param port: the port that get_vif_port_by_id should return
:param func_name: the function that should be called
:returns: whether the named function was called'
| def mock_treat_devices_added(self, details, port, func_name):
| with mock.patch.object(self.agent.plugin_rpc, 'get_device_details', return_value=details):
with mock.patch.object(self.agent.int_br, 'get_vif_port_by_id', return_value=port):
with mock.patch.object(self.agent, func_name) as func:
self.assertFalse(self.agent.treat_devices_added([{... |
'create and stringify vif port, confirm no exceptions'
| def test_vifport(self):
| self.mox.ReplayAll()
pname = 'vif1.0'
ofport = 5
vif_id = uuidutils.generate_uuid()
mac = 'ca:fe:de:ad:be:ef'
port = ovs_lib.VifPort(pname, ofport, vif_id, mac, self.br)
self.assertEqual(port.port_name, pname)
self.assertEqual(port.ofport, ofport)
self.assertEqual(port.vif_id, vif_id... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.