'validate': {'type:regex': UUID_PATTERN},
'is_visible': True},
'name': {'allow_post': True, 'allow_put': True,
- 'is_visible': True},
+ 'default': '', 'is_visible': True},
'subnets': {'allow_post': True, 'allow_put': True,
'default': [],
'is_visible': True},
'id': {'allow_post': False, 'allow_put': False,
'validate': {'type:regex': UUID_PATTERN},
'is_visible': True},
+ 'name': {'allow_post': True, 'allow_put': True, 'default': '',
+ 'is_visible': True},
'network_id': {'allow_post': True, 'allow_put': False,
'validate': {'type:regex': UUID_PATTERN},
'is_visible': True},
'id': {'allow_post': False, 'allow_put': False,
'validate': {'type:regex': UUID_PATTERN},
'is_visible': True},
+ 'name': {'allow_post': True, 'allow_put': True, 'default': '',
+ 'is_visible': True},
'ip_version': {'allow_post': True, 'allow_put': False,
'convert_to': int,
'validate': {'type:values': [4, 6]},
def _make_subnet_dict(self, subnet, fields=None):
res = {'id': subnet['id'],
+ 'name': subnet['name'],
'tenant_id': subnet['tenant_id'],
'network_id': subnet['network_id'],
'ip_version': subnet['ip_version'],
def _make_port_dict(self, port, fields=None):
res = {"id": port["id"],
+ 'name': port['name'],
"network_id": port["network_id"],
'tenant_id': port['tenant_id'],
"mac_address": port["mac_address"],
self._validate_subnet_cidr(network, s['cidr'])
subnet = models_v2.Subnet(tenant_id=tenant_id,
id=s.get('id') or utils.str_uuid(),
+ name=s['name'],
network_id=s['network_id'],
ip_version=s['ip_version'],
cidr=s['cidr'],
ips = self._allocate_ips_for_port(context, network, port)
port = models_v2.Port(tenant_id=tenant_id,
+ name=p['name'],
id=p.get('id') or utils.str_uuid(),
network_id=p['network_id'],
mac_address=p['mac_address'],
class Port(model_base.BASEV2, HasId, HasTenant):
"""Represents a port on a quantum v2 network."""
+ name = sa.Column(sa.String(255))
network_id = sa.Column(sa.String(36), sa.ForeignKey("networks.id"),
nullable=False)
fixed_ips = orm.relationship(IPAllocation, backref='ports', lazy="dynamic")
When a subnet is created the first and last entries will be created. These
are used for the IP allocation.
"""
+ name = sa.Column(sa.String(255))
network_id = sa.Column(sa.String(36), sa.ForeignKey('networks.id'))
ip_version = sa.Column(sa.Integer, nullable=False)
cidr = sa.Column(sa.String(64), nullable=False)
self.assertEqual(res.status_int, exc.HTTPBadRequest.code)
def test_create_missing_attr(self):
- data = {'network': {'what': 'who', 'tenant_id': _uuid()}}
- res = self.api.post_json(_get_path('networks'), data,
+ data = {'port': {'what': 'who', 'tenant_id': _uuid()}}
+ res = self.api.post_json(_get_path('ports'), data,
expect_errors=True)
self.assertEqual(res.status_int, 422)
self.assertEqual(res.status_int, exc.HTTPBadRequest.code)
def test_create_bulk_missing_attr(self):
- data = {'networks': [{'what': 'who', 'tenant_id': _uuid()}]}
- res = self.api.post_json(_get_path('networks'), data,
+ data = {'ports': [{'what': 'who', 'tenant_id': _uuid()}]}
+ res = self.api.post_json(_get_path('ports'), data,
expect_errors=True)
self.assertEqual(res.status_int, 422)
def test_create_bulk_partial_body(self):
- data = {'networks': [{'name': 'net1', 'admin_state_up': True,
- 'tenant_id': _uuid()},
- {'tenant_id': _uuid()}]}
- res = self.api.post_json(_get_path('networks'), data,
+ data = {'ports': [{'device_id': 'device_1',
+ 'tenant_id': _uuid()},
+ {'tenant_id': _uuid()}]}
+ res = self.api.post_json(_get_path('ports'), data,
expect_errors=True)
self.assertEqual(res.status_int, 422)
net_id = _uuid()
tenant_id = _uuid()
device_id = _uuid()
- initial_input = {'port': {'network_id': net_id, 'tenant_id': tenant_id,
- 'device_id': device_id,
- 'admin_state_up': True}}
+ initial_input = {'port': {'name': '', 'network_id': net_id,
+ 'tenant_id': tenant_id,
+ 'device_id': device_id,
+ 'admin_state_up': True}}
full_input = {'port': {'admin_state_up': True,
'mac_address': attributes.ATTR_NOT_SPECIFIED,
'fixed_ips': attributes.ATTR_NOT_SPECIFIED,
content_type = 'application/' + fmt
data = {'port': {'network_id': net_id,
'tenant_id': self._tenant_id}}
- for arg in ('admin_state_up', 'device_id', 'mac_address', 'fixed_ips'):
+ for arg in ('admin_state_up', 'device_id', 'mac_address',
+ 'name', 'fixed_ips'):
# Arg must be present and not empty
if arg in kwargs and kwargs[arg]:
data['port'][arg] = kwargs[arg]
self._delete('subnets', subnet['subnet']['id'])
@contextlib.contextmanager
- def port(self, subnet=None, fixed_ips=None, fmt='json'):
+ def port(self, subnet=None, fixed_ips=None, fmt='json', **kwargs):
if not subnet:
with self.subnet() as subnet:
net_id = subnet['subnet']['network_id']
- port = self._make_port(fmt, net_id, fixed_ips=fixed_ips)
+ port = self._make_port(fmt, net_id, fixed_ips=fixed_ips,
+ **kwargs)
yield port
self._delete('ports', port['port']['id'])
else:
net_id = subnet['subnet']['network_id']
- port = self._make_port(fmt, net_id, fixed_ips=fixed_ips)
+ port = self._make_port(fmt, net_id, fixed_ips=fixed_ips,
+ **kwargs)
yield port
self._delete('ports', port['port']['id'])
class TestPortsV2(QuantumDbPluginV2TestCase):
def test_create_port_json(self):
keys = [('admin_state_up', True), ('status', 'ACTIVE')]
- with self.port() as port:
+ with self.port(name='myname') as port:
for k, v in keys:
self.assertEquals(port['port'][k], v)
self.assertTrue('mac_address' in port['port'])
ips = port['port']['fixed_ips']
self.assertEquals(len(ips), 1)
self.assertEquals(ips[0]['ip_address'], '10.0.0.2')
+ self.assertEquals('myname', port['port']['name'])
def test_create_port_bad_tenant(self):
with self.network() as network:
def test_create_subnet(self):
gateway_ip = '10.0.0.1'
cidr = '10.0.0.0/24'
- self._test_create_subnet(gateway_ip=gateway_ip,
- cidr=cidr)
+ subnet = self._test_create_subnet(gateway_ip=gateway_ip,
+ cidr=cidr)
+ self.assertTrue('name' in subnet['subnet'])
def test_create_two_subnets(self):
gateway_ips = ['10.0.0.1', '10.0.1.1']