Added uuid for networks and made changes to the Create server API format to accept network as uuid instead of id
This commit is contained in:
@@ -760,25 +760,26 @@ class NetworkCommands(object):
|
||||
|
||||
def list(self):
|
||||
"""List all created networks"""
|
||||
print "%-5s\t%-18s\t%-15s\t%-15s\t%-15s\t%-15s\t%-15s\t%-15s" % (
|
||||
_('id'),
|
||||
_('IPv4'),
|
||||
_('IPv6'),
|
||||
_('start address'),
|
||||
_('DNS1'),
|
||||
_('DNS2'),
|
||||
_('VlanID'),
|
||||
'project')
|
||||
_fmt = "%-5s\t%-18s\t%-15s\t%-15s\t%-15s\t%-15s\t%-15s\t%-15s\t%-15s"
|
||||
print _fmt % (_('id'),
|
||||
_('IPv4'),
|
||||
_('IPv6'),
|
||||
_('start address'),
|
||||
_('DNS1'),
|
||||
_('DNS2'),
|
||||
_('VlanID'),
|
||||
_('project'),
|
||||
_("uuid"))
|
||||
for network in db.network_get_all(context.get_admin_context()):
|
||||
print "%-5s\t%-18s\t%-15s\t%-15s\t%-15s\t%-15s\t%-15s\t%-15s" % (
|
||||
network.id,
|
||||
network.cidr,
|
||||
network.cidr_v6,
|
||||
network.dhcp_start,
|
||||
network.dns1,
|
||||
network.dns2,
|
||||
network.vlan,
|
||||
network.project_id)
|
||||
print _fmt % (network.id,
|
||||
network.cidr,
|
||||
network.cidr_v6,
|
||||
network.dhcp_start,
|
||||
network.dns1,
|
||||
network.dns2,
|
||||
network.vlan,
|
||||
network.project_id,
|
||||
network.uuid)
|
||||
|
||||
@args('--network', dest="fixed_range", metavar='<x.x.x.x/yy>',
|
||||
help='Network to delete')
|
||||
|
||||
@@ -304,15 +304,6 @@ class CreateInstanceHelper(object):
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
return password
|
||||
|
||||
def _validate_fixed_ip(self, value):
|
||||
if not isinstance(value, basestring):
|
||||
msg = _("Fixed IP is not a string or unicode")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
if value.strip() == '':
|
||||
msg = _("Fixed IP is an empty string")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
def _get_requested_networks(self, requested_networks):
|
||||
"""
|
||||
Create a list of requested networks from the networks attribute
|
||||
@@ -320,31 +311,33 @@ class CreateInstanceHelper(object):
|
||||
networks = []
|
||||
for network in requested_networks:
|
||||
try:
|
||||
network_id = network['id']
|
||||
network_id = int(network_id)
|
||||
network_uuid = network['uuid']
|
||||
|
||||
if not utils.is_uuid_like(network_uuid):
|
||||
msg = _("Bad networks format: network uuid is not in"
|
||||
" proper format (%s)") % network_uuid
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
#fixed IP address is optional
|
||||
#if the fixed IP address is not provided then
|
||||
#it will use one of the available IP address from the network
|
||||
fixed_ip = network.get('fixed_ip', None)
|
||||
if fixed_ip is not None:
|
||||
self._validate_fixed_ip(fixed_ip)
|
||||
address = network.get('fixed_ip', None)
|
||||
if address is not None and not utils.is_valid_ipv4(address):
|
||||
msg = _("Invalid fixed IP address (%s)") % address
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
# check if the network id is already present in the list,
|
||||
# we don't want duplicate networks to be passed
|
||||
# at the boot time
|
||||
for id, ip in networks:
|
||||
if id == network_id:
|
||||
if id == network_uuid:
|
||||
expl = _("Duplicate networks (%s) are not allowed")\
|
||||
% network_id
|
||||
% network_uuid
|
||||
raise exc.HTTPBadRequest(explanation=expl)
|
||||
|
||||
networks.append((network_id, fixed_ip))
|
||||
networks.append((network_uuid, address))
|
||||
except KeyError as key:
|
||||
expl = _('Bad network format: missing %s') % key
|
||||
raise exc.HTTPBadRequest(explanation=expl)
|
||||
except ValueError:
|
||||
expl = _("Bad networks format: network id should "
|
||||
"be integer (%s)") % network_id
|
||||
raise exc.HTTPBadRequest(explanation=expl)
|
||||
except TypeError:
|
||||
expl = _('Bad networks format')
|
||||
raise exc.HTTPBadRequest(explanation=expl)
|
||||
@@ -543,8 +536,8 @@ class ServerXMLDeserializerV11(wsgi.MetadataXMLDeserializer):
|
||||
for network_node in self.find_children_named(node,
|
||||
"network"):
|
||||
item = {}
|
||||
if network_node.hasAttribute("id"):
|
||||
item["id"] = network_node.getAttribute("id")
|
||||
if network_node.hasAttribute("uuid"):
|
||||
item["uuid"] = network_node.getAttribute("uuid")
|
||||
if network_node.hasAttribute("fixed_ip"):
|
||||
item["fixed_ip"] = network_node.getAttribute("fixed_ip")
|
||||
networks.append(item)
|
||||
|
||||
@@ -404,14 +404,6 @@ def fixed_ip_update(context, address, values):
|
||||
"""Create a fixed ip from the values dictionary."""
|
||||
return IMPL.fixed_ip_update(context, address, values)
|
||||
|
||||
|
||||
def fixed_ip_validate_by_network_address(context, network_id,
|
||||
address):
|
||||
"""validates if the address belongs to the network"""
|
||||
return IMPL.fixed_ip_validate_by_network_address(context, network_id,
|
||||
address)
|
||||
|
||||
|
||||
####################
|
||||
|
||||
|
||||
@@ -695,9 +687,9 @@ def network_get_all(context):
|
||||
return IMPL.network_get_all(context)
|
||||
|
||||
|
||||
def network_get_networks_by_ids(context, network_ids):
|
||||
def network_get_networks_by_uuids(context, network_uuids):
|
||||
"""Return networks by ids."""
|
||||
return IMPL.network_get_networks_by_ids(context, network_ids)
|
||||
return IMPL.network_get_networks_by_uuids(context, network_uuids)
|
||||
|
||||
|
||||
# pylint: disable=C0103
|
||||
@@ -1252,14 +1244,9 @@ def project_get_networks(context, project_id, associate=True):
|
||||
return IMPL.project_get_networks(context, project_id, associate)
|
||||
|
||||
|
||||
def project_get_networks_by_ids(context, network_ids):
|
||||
"""Return the networks by ids associated with the project.
|
||||
|
||||
If associate is true, it will attempt to associate a new
|
||||
network if one is not found, otherwise it returns None.
|
||||
|
||||
"""
|
||||
return IMPL.project_get_networks_by_ids(context, network_ids)
|
||||
def project_get_networks_by_uuids(context, network_uuids):
|
||||
"""Return the networks by uuids associated with the project."""
|
||||
return IMPL.project_get_networks_by_uuids(context, network_uuids)
|
||||
|
||||
|
||||
def project_get_networks_v6(context, project_id):
|
||||
|
||||
@@ -824,26 +824,6 @@ def fixed_ip_get_by_address(context, address, session=None):
|
||||
return result
|
||||
|
||||
|
||||
@require_context
|
||||
def fixed_ip_validate_by_network_address(context, network_id,
|
||||
address):
|
||||
session = get_session()
|
||||
fixed_ip_ref = session.query(models.FixedIp).\
|
||||
filter_by(address=address).\
|
||||
filter_by(reserved=False).\
|
||||
filter_by(network_id=network_id).\
|
||||
filter_by(deleted=can_read_deleted(context)).\
|
||||
first()
|
||||
|
||||
if fixed_ip_ref is None:
|
||||
raise exception.FixedIpNotFoundForNetwork(address=address,
|
||||
network_id=network_id)
|
||||
if fixed_ip_ref.instance is not None:
|
||||
raise exception.FixedIpAlreadyInUse(address=address)
|
||||
|
||||
return fixed_ip_ref
|
||||
|
||||
|
||||
@require_context
|
||||
def fixed_ip_get_by_instance(context, instance_id):
|
||||
session = get_session()
|
||||
@@ -1778,10 +1758,10 @@ def network_get_all(context):
|
||||
|
||||
|
||||
@require_admin_context
|
||||
def network_get_networks_by_ids(context, network_ids):
|
||||
def network_get_networks_by_uuids(context, network_uuids):
|
||||
session = get_session()
|
||||
result = session.query(models.Network).\
|
||||
filter(models.Network.id.in_(network_ids)).\
|
||||
filter(models.Network.uuid.in_(network_uuids)).\
|
||||
filter_by(deleted=False).all()
|
||||
if not result:
|
||||
raise exception.NoNetworksFound()
|
||||
@@ -1794,14 +1774,14 @@ def network_get_networks_by_ids(context, network_ids):
|
||||
|
||||
#check if the result contains all the networks
|
||||
#we are looking for
|
||||
for network_id in network_ids:
|
||||
for network_uuid in network_uuids:
|
||||
found = False
|
||||
for network in result:
|
||||
if network['id'] == network_id:
|
||||
if network['uuid'] == network_uuid:
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
raise exception.NetworkNotFound(network_id=network_id)
|
||||
raise exception.NetworkNotFound(network_id=network_uuid)
|
||||
|
||||
return result
|
||||
|
||||
@@ -2962,10 +2942,10 @@ def project_get_networks(context, project_id, associate=True):
|
||||
|
||||
|
||||
@require_context
|
||||
def project_get_networks_by_ids(context, network_ids):
|
||||
def project_get_networks_by_uuids(context, network_uuids):
|
||||
session = get_session()
|
||||
result = session.query(models.Network).\
|
||||
filter(models.Network.id.in_(network_ids)).\
|
||||
filter(models.Network.uuid.in_(network_uuids)).\
|
||||
filter_by(deleted=False).\
|
||||
filter_by(project_id=context.project_id).all()
|
||||
|
||||
@@ -2980,14 +2960,14 @@ def project_get_networks_by_ids(context, network_ids):
|
||||
|
||||
#check if the result contains all the networks
|
||||
#we are looking for
|
||||
for network_id in network_ids:
|
||||
for uuid in network_uuids:
|
||||
found = False
|
||||
for network in result:
|
||||
if network['id'] == network_id:
|
||||
if network['uuid'] == uuid:
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
raise exception.NetworkNotFoundForProject(network_id=network_id,
|
||||
raise exception.NetworkNotFoundForProject(network_uuid=uuid,
|
||||
project_id=context.project_id)
|
||||
return result
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2011 OpenStack LLC.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from sqlalchemy import Column, Integer, MetaData, String, Table
|
||||
|
||||
from nova import utils
|
||||
|
||||
|
||||
meta = MetaData()
|
||||
|
||||
networks = Table("networks", meta,
|
||||
Column("id", Integer(), primary_key=True, nullable=False))
|
||||
uuid_column = Column("uuid", String(36))
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta.bind = migrate_engine
|
||||
networks.create_column(uuid_column)
|
||||
|
||||
rows = migrate_engine.execute(networks.select())
|
||||
for row in rows:
|
||||
networks_uuid = str(utils.gen_uuid())
|
||||
migrate_engine.execute(networks.update()\
|
||||
.where(networks.c.id == row[0])\
|
||||
.values(uuid=networks_uuid))
|
||||
|
||||
|
||||
def downgrade(migrate_engine):
|
||||
meta.bind = migrate_engine
|
||||
networks.drop_column(uuid_column)
|
||||
@@ -557,6 +557,7 @@ class Network(BASE, NovaBase):
|
||||
|
||||
project_id = Column(String(255))
|
||||
host = Column(String(255)) # , ForeignKey('hosts.id'))
|
||||
uuid = Column(String(36))
|
||||
|
||||
|
||||
class VirtualInterface(BASE, NovaBase):
|
||||
|
||||
@@ -428,7 +428,7 @@ class NoNetworksFound(NotFound):
|
||||
|
||||
|
||||
class NetworkNotFoundForProject(NotFound):
|
||||
message = _("Either Network %(network_id)s is not present or "
|
||||
message = _("Either Network uuid %(network_uuid)s is not present or "
|
||||
"is not assigned to the project %(project_id)s.")
|
||||
|
||||
|
||||
@@ -471,7 +471,7 @@ class FixedIpNotFoundForHost(FixedIpNotFound):
|
||||
|
||||
class FixedIpNotFoundForNetwork(FixedIpNotFound):
|
||||
message = _("Fixed IP address (%(address)s) does not exist in "
|
||||
"network (%(network_id)s).")
|
||||
"network (%(network_uuid)s).")
|
||||
|
||||
|
||||
class FixedIpAlreadyInUse(AlreadyInUse):
|
||||
|
||||
@@ -135,8 +135,8 @@ class RPCAllocateFixedIP(object):
|
||||
for network in networks:
|
||||
address = None
|
||||
if requested_networks is not None:
|
||||
for address in (fixed_ip for (id, fixed_ip) in \
|
||||
requested_networks if network['id'] == id):
|
||||
for address in (fixed_ip for (uuid, fixed_ip) in \
|
||||
requested_networks if network['uuid'] == uuid):
|
||||
break
|
||||
|
||||
# NOTE(vish): if we are not multi_host pass to the network host
|
||||
@@ -397,9 +397,9 @@ class NetworkManager(manager.SchedulerDependentManager):
|
||||
# there is a better way to determine which networks
|
||||
# a non-vlan instance should connect to
|
||||
if requested_networks is not None and len(requested_networks) != 0:
|
||||
network_ids = [id for (id, fixed_ip) in requested_networks]
|
||||
networks = self.db.network_get_networks_by_ids(context,
|
||||
network_ids)
|
||||
network_uuids = [uuid for (uuid, fixed_ip) in requested_networks]
|
||||
networks = self.db.network_get_networks_by_uuids(context,
|
||||
network_uuids)
|
||||
else:
|
||||
try:
|
||||
networks = self.db.network_get_all(context)
|
||||
@@ -827,18 +827,24 @@ class NetworkManager(manager.SchedulerDependentManager):
|
||||
if networks is None or len(networks) == 0:
|
||||
return
|
||||
|
||||
network_ids = [id for (id, fixed_ip) in networks]
|
||||
result = self.db.network_get_networks_by_ids(context, network_ids)
|
||||
for network_id, fixed_ip in networks:
|
||||
network_uuids = [uuid for (uuid, fixed_ip) in networks]
|
||||
|
||||
self.db.network_get_networks_by_uuids(context, network_uuids)
|
||||
|
||||
for network_uuid, address in networks:
|
||||
# check if the fixed IP address is valid and
|
||||
# it actually belongs to the network
|
||||
if fixed_ip is not None:
|
||||
if not utils.is_valid_ipv4(fixed_ip):
|
||||
raise exception.FixedIpInvalid(address=fixed_ip)
|
||||
if address is not None:
|
||||
if not utils.is_valid_ipv4(address):
|
||||
raise exception.FixedIpInvalid(address=address)
|
||||
|
||||
self.db.fixed_ip_validate_by_network_address(context,
|
||||
network_id,
|
||||
fixed_ip)
|
||||
fixed_ip_ref = self.db.fixed_ip_get_by_address(context,
|
||||
address)
|
||||
if fixed_ip_ref['network']['uuid'] != network_uuid:
|
||||
raise exception.FixedIpNotFoundForNetwork(address=address,
|
||||
network_uuid=network_uuid)
|
||||
if fixed_ip_ref['instance'] is not None:
|
||||
raise exception.FixedIpAlreadyInUse(address=address)
|
||||
|
||||
|
||||
class FlatManager(NetworkManager):
|
||||
@@ -878,8 +884,8 @@ class FlatManager(NetworkManager):
|
||||
for network in networks:
|
||||
address = None
|
||||
if requested_networks is not None:
|
||||
for address in (fixed_ip for (id, fixed_ip) in \
|
||||
requested_networks if network['id'] == id):
|
||||
for address in (fixed_ip for (uuid, fixed_ip) in \
|
||||
requested_networks if network['uuid'] == uuid):
|
||||
break
|
||||
|
||||
self.allocate_fixed_ip(context, instance_id,
|
||||
@@ -999,9 +1005,9 @@ class VlanManager(RPCAllocateFixedIP, FloatingIP, NetworkManager):
|
||||
"""Determine which networks an instance should connect to."""
|
||||
# get networks associated with project
|
||||
if requested_networks is not None and len(requested_networks) != 0:
|
||||
network_ids = [id for (id, fixed_ip) in requested_networks]
|
||||
networks = self.db.project_get_networks_by_ids(context,
|
||||
network_ids)
|
||||
network_uuids = [uuid for (uuid, fixed_ip) in requested_networks]
|
||||
networks = self.db.project_get_networks_by_uuids(context,
|
||||
network_uuids)
|
||||
else:
|
||||
networks = self.db.project_get_networks(context, project_id)
|
||||
return networks
|
||||
@@ -1060,19 +1066,24 @@ class VlanManager(RPCAllocateFixedIP, FloatingIP, NetworkManager):
|
||||
if networks is None or len(networks) == 0:
|
||||
return
|
||||
|
||||
network_ids = [id for (id, fixed_ip) in networks]
|
||||
result = self.db.project_get_networks_by_ids(context, network_ids)
|
||||
network_uuids = [uuid for (uuid, fixed_ip) in networks]
|
||||
|
||||
for network_id, fixed_ip in networks:
|
||||
self.db.project_get_networks_by_uuids(context, network_uuids)
|
||||
|
||||
for network_uuid, address in networks:
|
||||
# check if the fixed IP address is valid and
|
||||
# it actually belongs to the network
|
||||
if fixed_ip is not None:
|
||||
if not utils.is_valid_ipv4(fixed_ip):
|
||||
raise exception.FixedIpInvalid(address=fixed_ip)
|
||||
if not utils.is_valid_ipv4(address):
|
||||
raise exception.FixedIpInvalid(address=address)
|
||||
|
||||
self.db.fixed_ip_validate_by_network_address(context,
|
||||
network_id,
|
||||
fixed_ip)
|
||||
fixed_ip_ref = self.db.fixed_ip_get_by_address(context,
|
||||
address)
|
||||
if fixed_ip_ref['network']['uuid'] != network_uuid:
|
||||
raise exception.FixedIpNotFoundForNetwork(address=address,
|
||||
network_uuid=network_uuid)
|
||||
if fixed_ip_ref['instance'] is not None:
|
||||
raise exception.FixedIpAlreadyInUse(address=address)
|
||||
|
||||
@property
|
||||
def _bottom_reserved_ips(self):
|
||||
|
||||
@@ -43,6 +43,14 @@ FLAGS.verbose = True
|
||||
|
||||
FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
|
||||
|
||||
FAKE_NETWORKS = [('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '10.0.1.12'),
|
||||
('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', '10.0.2.12')]
|
||||
|
||||
DUPLICATE_NETWORKS = [('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '10.0.1.12'),
|
||||
('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '10.0.1.12')]
|
||||
|
||||
INVALID_NETWORKS = [('invalid', 'invalid-ip-address')]
|
||||
|
||||
|
||||
class CreateserverextTest(test.TestCase):
|
||||
|
||||
@@ -106,8 +114,8 @@ class CreateserverextTest(test.TestCase):
|
||||
server['flavorRef'] = 1
|
||||
if networks is not None:
|
||||
network_list = []
|
||||
for id, fixed_ip in networks:
|
||||
network_list.append({'id': id, 'fixed_ip': fixed_ip})
|
||||
for uuid, fixed_ip in networks:
|
||||
network_list.append({'uuid': uuid, 'fixed_ip': fixed_ip})
|
||||
server['networks'] = network_list
|
||||
return {'server': server}
|
||||
|
||||
@@ -148,8 +156,8 @@ class CreateserverextTest(test.TestCase):
|
||||
networks = server['networks']
|
||||
body_parts.append('<networks>')
|
||||
for network in networks:
|
||||
item = (network['id'], network['fixed_ip'])
|
||||
body_parts.append('<network id="%s" fixed_ip="%s"></network>'
|
||||
item = (network['uuid'], network['fixed_ip'])
|
||||
body_parts.append('<network uuid="%s" fixed_ip="%s"></network>'
|
||||
% item)
|
||||
body_parts.append('</networks>')
|
||||
body_parts.append('</server>')
|
||||
@@ -190,55 +198,44 @@ class CreateserverextTest(test.TestCase):
|
||||
self.assertEquals(networks, None)
|
||||
|
||||
def test_create_instance_with_one_network(self):
|
||||
id = 1
|
||||
fixed_ip = '10.0.1.12'
|
||||
networks = [(id, fixed_ip)]
|
||||
request, response, networks = \
|
||||
self._create_instance_with_networks_json(networks)
|
||||
self._create_instance_with_networks_json([FAKE_NETWORKS[0]])
|
||||
self.assertEquals(response.status_int, 202)
|
||||
self.assertEquals(networks, [(id, fixed_ip)])
|
||||
self.assertEquals(networks, [FAKE_NETWORKS[0]])
|
||||
|
||||
def test_create_instance_with_one_network_xml(self):
|
||||
id = 1
|
||||
fixed_ip = '10.0.1.12'
|
||||
networks = [(id, fixed_ip)]
|
||||
request, response, networks = \
|
||||
self._create_instance_with_networks_xml(networks)
|
||||
self._create_instance_with_networks_xml([FAKE_NETWORKS[0]])
|
||||
self.assertEquals(response.status_int, 202)
|
||||
self.assertEquals(networks, [(id, fixed_ip)])
|
||||
self.assertEquals(networks, [FAKE_NETWORKS[0]])
|
||||
|
||||
def test_create_instance_with_two_networks(self):
|
||||
networks = [(1, '10.0.1.12'), (2, '10.0.2.12')]
|
||||
request, response, networks = \
|
||||
self._create_instance_with_networks_json(networks)
|
||||
self._create_instance_with_networks_json(FAKE_NETWORKS)
|
||||
self.assertEquals(response.status_int, 202)
|
||||
self.assertEquals(networks, [(1, '10.0.1.12'), (2, '10.0.2.12')])
|
||||
self.assertEquals(networks, FAKE_NETWORKS)
|
||||
|
||||
def test_create_instance_with_two_networks_xml(self):
|
||||
networks = [(1, '10.0.1.12'), (2, '10.0.2.12')]
|
||||
request, response, networks = \
|
||||
self._create_instance_with_networks_xml(networks)
|
||||
self._create_instance_with_networks_xml(FAKE_NETWORKS)
|
||||
self.assertEquals(response.status_int, 202)
|
||||
self.assertEquals(networks, [(1, '10.0.1.12'), (2, '10.0.2.12')])
|
||||
self.assertEquals(networks, FAKE_NETWORKS)
|
||||
|
||||
def test_create_instance_with_duplicate_networks(self):
|
||||
networks = [(1, '10.0.1.12'), (1, '10.0.2.12')]
|
||||
request, response, networks = \
|
||||
self._create_instance_with_networks_json(networks)
|
||||
self._create_instance_with_networks_json(DUPLICATE_NETWORKS)
|
||||
self.assertEquals(response.status_int, 400)
|
||||
self.assertEquals(networks, None)
|
||||
|
||||
def test_create_instance_with_duplicate_networks_xml(self):
|
||||
networks = [(1, '10.0.1.12'), (1, '10.0.2.12')]
|
||||
request, response, networks = \
|
||||
self._create_instance_with_networks_xml(networks)
|
||||
self._create_instance_with_networks_xml(DUPLICATE_NETWORKS)
|
||||
self.assertEquals(response.status_int, 400)
|
||||
self.assertEquals(networks, None)
|
||||
|
||||
def test_create_instance_with_network_no_id(self):
|
||||
networks = [(1, '10.0.1.12')]
|
||||
body_dict = self._create_networks_request_dict(networks)
|
||||
del body_dict['server']['networks'][0]['id']
|
||||
body_dict = self._create_networks_request_dict([FAKE_NETWORKS[0]])
|
||||
del body_dict['server']['networks'][0]['uuid']
|
||||
request = self._get_create_request_json(body_dict)
|
||||
compute_api, response = \
|
||||
self._run_create_instance_with_mock_compute_api(request)
|
||||
@@ -246,26 +243,24 @@ class CreateserverextTest(test.TestCase):
|
||||
self.assertEquals(compute_api.networks, None)
|
||||
|
||||
def test_create_instance_with_network_no_id_xml(self):
|
||||
networks = [(1, '10.0.1.12')]
|
||||
body_dict = self._create_networks_request_dict(networks)
|
||||
body_dict = self._create_networks_request_dict([FAKE_NETWORKS[0]])
|
||||
request = self._get_create_request_xml(body_dict)
|
||||
request.body = request.body.replace(' id="1"', '')
|
||||
uuid = ' uuid="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"'
|
||||
request.body = request.body.replace(uuid, '')
|
||||
compute_api, response = \
|
||||
self._run_create_instance_with_mock_compute_api(request)
|
||||
self.assertEquals(response.status_int, 400)
|
||||
self.assertEquals(compute_api.networks, None)
|
||||
|
||||
def test_create_instance_with_network_invalid_id(self):
|
||||
networks = [('asd123', '10.0.1.12')]
|
||||
request, response, networks = \
|
||||
self._create_instance_with_networks_json(networks)
|
||||
self._create_instance_with_networks_json(INVALID_NETWORKS)
|
||||
self.assertEquals(response.status_int, 400)
|
||||
self.assertEquals(networks, None)
|
||||
|
||||
def test_create_instance_with_network_invalid_id_xml(self):
|
||||
networks = [('asd123', '10.0.1.12')]
|
||||
request, response, networks = \
|
||||
self._create_instance_with_networks_xml(networks)
|
||||
self._create_instance_with_networks_xml(INVALID_NETWORKS)
|
||||
self.assertEquals(response.status_int, 400)
|
||||
self.assertEquals(networks, None)
|
||||
|
||||
@@ -291,21 +286,21 @@ class CreateserverextTest(test.TestCase):
|
||||
self.assertEquals(networks, None)
|
||||
|
||||
def test_create_instance_with_network_no_fixed_ip(self):
|
||||
networks = [(1, '10.0.1.12')]
|
||||
body_dict = self._create_networks_request_dict(networks)
|
||||
body_dict = self._create_networks_request_dict([FAKE_NETWORKS[0]])
|
||||
del body_dict['server']['networks'][0]['fixed_ip']
|
||||
request = self._get_create_request_json(body_dict)
|
||||
compute_api, response = \
|
||||
self._run_create_instance_with_mock_compute_api(request)
|
||||
self.assertEquals(response.status_int, 202)
|
||||
self.assertEquals(compute_api.networks, [(1, None)])
|
||||
self.assertEquals(compute_api.networks,
|
||||
[('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', None)])
|
||||
|
||||
def test_create_instance_with_network_no_fixed_ip_xml(self):
|
||||
networks = [(1, '10.0.1.12')]
|
||||
body_dict = self._create_networks_request_dict(networks)
|
||||
body_dict = self._create_networks_request_dict([FAKE_NETWORKS[0]])
|
||||
request = self._get_create_request_xml(body_dict)
|
||||
request.body = request.body.replace(' fixed_ip="10.0.1.12"', '')
|
||||
compute_api, response = \
|
||||
self._run_create_instance_with_mock_compute_api(request)
|
||||
self.assertEquals(response.status_int, 202)
|
||||
self.assertEquals(compute_api.networks, [(1, None)])
|
||||
self.assertEquals(compute_api.networks,
|
||||
[('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', None)])
|
||||
|
||||
@@ -2662,7 +2662,7 @@ class TestServerCreateRequestXMLDeserializerV11(test.TestCase):
|
||||
<server xmlns="http://docs.openstack.org/compute/api/v1.1"
|
||||
name="new-server-test" imageRef="1" flavorRef="1">
|
||||
<networks>
|
||||
<network id="1" fixed_ip="10.0.1.12"/>
|
||||
<network uuid="1" fixed_ip="10.0.1.12"/>
|
||||
</networks>
|
||||
</server>"""
|
||||
request = self.deserializer.deserialize(serial_request, 'create')
|
||||
@@ -2670,7 +2670,7 @@ class TestServerCreateRequestXMLDeserializerV11(test.TestCase):
|
||||
"name": "new-server-test",
|
||||
"imageRef": "1",
|
||||
"flavorRef": "1",
|
||||
"networks": [{"id": "1", "fixed_ip": "10.0.1.12"}],
|
||||
"networks": [{"uuid": "1", "fixed_ip": "10.0.1.12"}],
|
||||
}}
|
||||
self.assertEquals(request['body'], expected)
|
||||
|
||||
@@ -2679,8 +2679,8 @@ class TestServerCreateRequestXMLDeserializerV11(test.TestCase):
|
||||
<server xmlns="http://docs.openstack.org/compute/api/v1.1"
|
||||
name="new-server-test" imageRef="1" flavorRef="1">
|
||||
<networks>
|
||||
<network id="1" fixed_ip="10.0.1.12"/>
|
||||
<network id="2" fixed_ip="10.0.2.12"/>
|
||||
<network uuid="1" fixed_ip="10.0.1.12"/>
|
||||
<network uuid="2" fixed_ip="10.0.2.12"/>
|
||||
</networks>
|
||||
</server>"""
|
||||
request = self.deserializer.deserialize(serial_request, 'create')
|
||||
@@ -2688,8 +2688,8 @@ class TestServerCreateRequestXMLDeserializerV11(test.TestCase):
|
||||
"name": "new-server-test",
|
||||
"imageRef": "1",
|
||||
"flavorRef": "1",
|
||||
"networks": [{"id": "1", "fixed_ip": "10.0.1.12"},
|
||||
{"id": "2", "fixed_ip": "10.0.2.12"}],
|
||||
"networks": [{"uuid": "1", "fixed_ip": "10.0.1.12"},
|
||||
{"uuid": "2", "fixed_ip": "10.0.2.12"}],
|
||||
}}
|
||||
self.assertEquals(request['body'], expected)
|
||||
|
||||
@@ -2698,10 +2698,10 @@ class TestServerCreateRequestXMLDeserializerV11(test.TestCase):
|
||||
<server xmlns="http://docs.openstack.org/compute/api/v1.1"
|
||||
name="new-server-test" imageRef="1" flavorRef="1">
|
||||
<networks>
|
||||
<network id="1" fixed_ip="10.0.1.12"/>
|
||||
<network uuid="1" fixed_ip="10.0.1.12"/>
|
||||
</networks>
|
||||
<networks>
|
||||
<network id="2" fixed_ip="10.0.2.12"/>
|
||||
<network uuid="2" fixed_ip="10.0.2.12"/>
|
||||
</networks>
|
||||
</server>"""
|
||||
request = self.deserializer.deserialize(serial_request, 'create')
|
||||
@@ -2709,7 +2709,7 @@ class TestServerCreateRequestXMLDeserializerV11(test.TestCase):
|
||||
"name": "new-server-test",
|
||||
"imageRef": "1",
|
||||
"flavorRef": "1",
|
||||
"networks": [{"id": "1", "fixed_ip": "10.0.1.12"}],
|
||||
"networks": [{"uuid": "1", "fixed_ip": "10.0.1.12"}],
|
||||
}}
|
||||
self.assertEquals(request['body'], expected)
|
||||
|
||||
@@ -2735,7 +2735,7 @@ class TestServerCreateRequestXMLDeserializerV11(test.TestCase):
|
||||
<server xmlns="http://docs.openstack.org/compute/api/v1.1"
|
||||
name="new-server-test" imageRef="1" flavorRef="1">
|
||||
<networks>
|
||||
<network id="1"/>
|
||||
<network uuid="1"/>
|
||||
</networks>
|
||||
</server>"""
|
||||
request = self.deserializer.deserialize(serial_request, 'create')
|
||||
@@ -2743,7 +2743,7 @@ class TestServerCreateRequestXMLDeserializerV11(test.TestCase):
|
||||
"name": "new-server-test",
|
||||
"imageRef": "1",
|
||||
"flavorRef": "1",
|
||||
"networks": [{"id": "1"}],
|
||||
"networks": [{"uuid": "1"}],
|
||||
}}
|
||||
self.assertEquals(request['body'], expected)
|
||||
|
||||
@@ -2752,7 +2752,7 @@ class TestServerCreateRequestXMLDeserializerV11(test.TestCase):
|
||||
<server xmlns="http://docs.openstack.org/compute/api/v1.1"
|
||||
name="new-server-test" imageRef="1" flavorRef="1">
|
||||
<networks>
|
||||
<network id="" fixed_ip="10.0.1.12"/>
|
||||
<network uuid="" fixed_ip="10.0.1.12"/>
|
||||
</networks>
|
||||
</server>"""
|
||||
request = self.deserializer.deserialize(serial_request, 'create')
|
||||
@@ -2760,7 +2760,7 @@ class TestServerCreateRequestXMLDeserializerV11(test.TestCase):
|
||||
"name": "new-server-test",
|
||||
"imageRef": "1",
|
||||
"flavorRef": "1",
|
||||
"networks": [{"id": "", "fixed_ip": "10.0.1.12"}],
|
||||
"networks": [{"uuid": "", "fixed_ip": "10.0.1.12"}],
|
||||
}}
|
||||
self.assertEquals(request['body'], expected)
|
||||
|
||||
@@ -2769,7 +2769,7 @@ class TestServerCreateRequestXMLDeserializerV11(test.TestCase):
|
||||
<server xmlns="http://docs.openstack.org/compute/api/v1.1"
|
||||
name="new-server-test" imageRef="1" flavorRef="1">
|
||||
<networks>
|
||||
<network id="1" fixed_ip=""/>
|
||||
<network uuid="1" fixed_ip=""/>
|
||||
</networks>
|
||||
</server>"""
|
||||
request = self.deserializer.deserialize(serial_request, 'create')
|
||||
@@ -2777,7 +2777,7 @@ class TestServerCreateRequestXMLDeserializerV11(test.TestCase):
|
||||
"name": "new-server-test",
|
||||
"imageRef": "1",
|
||||
"flavorRef": "1",
|
||||
"networks": [{"id": "1", "fixed_ip": ""}],
|
||||
"networks": [{"uuid": "1", "fixed_ip": ""}],
|
||||
}}
|
||||
self.assertEquals(request['body'], expected)
|
||||
|
||||
@@ -2786,8 +2786,8 @@ class TestServerCreateRequestXMLDeserializerV11(test.TestCase):
|
||||
<server xmlns="http://docs.openstack.org/compute/api/v1.1"
|
||||
name="new-server-test" imageRef="1" flavorRef="1">
|
||||
<networks>
|
||||
<network id="1" fixed_ip="10.0.1.12"/>
|
||||
<network id="1" fixed_ip="10.0.2.12"/>
|
||||
<network uuid="1" fixed_ip="10.0.1.12"/>
|
||||
<network uuid="1" fixed_ip="10.0.2.12"/>
|
||||
</networks>
|
||||
</server>"""
|
||||
request = self.deserializer.deserialize(serial_request, 'create')
|
||||
@@ -2795,8 +2795,8 @@ class TestServerCreateRequestXMLDeserializerV11(test.TestCase):
|
||||
"name": "new-server-test",
|
||||
"imageRef": "1",
|
||||
"flavorRef": "1",
|
||||
"networks": [{"id": "1", "fixed_ip": "10.0.1.12"},
|
||||
{"id": "1", "fixed_ip": "10.0.2.12"}],
|
||||
"networks": [{"uuid": "1", "fixed_ip": "10.0.1.12"},
|
||||
{"uuid": "1", "fixed_ip": "10.0.2.12"}],
|
||||
}}
|
||||
self.assertEquals(request['body'], expected)
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ class FakeModel(dict):
|
||||
|
||||
|
||||
networks = [{'id': 0,
|
||||
'uuid': "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
|
||||
'label': 'test0',
|
||||
'injected': False,
|
||||
'multi_host': False,
|
||||
@@ -60,6 +61,7 @@ networks = [{'id': 0,
|
||||
'project_id': 'fake_project',
|
||||
'vpn_public_address': '192.168.0.2'},
|
||||
{'id': 1,
|
||||
'uuid': "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
|
||||
'label': 'test1',
|
||||
'injected': False,
|
||||
'multi_host': False,
|
||||
@@ -179,15 +181,18 @@ class FlatNetworkTestCase(test.TestCase):
|
||||
self.assertDictListMatch(nw[1]['ips'], check)
|
||||
|
||||
def test_validate_networks(self):
|
||||
self.mox.StubOutWithMock(db, 'network_get_networks_by_ids')
|
||||
self.mox.StubOutWithMock(db, "fixed_ip_validate_by_network_address")
|
||||
self.mox.StubOutWithMock(db, 'network_get_networks_by_uuids')
|
||||
self.mox.StubOutWithMock(db, "fixed_ip_get_by_address")
|
||||
|
||||
requested_networks = [(1, "192.168.0.100")]
|
||||
db.network_get_networks_by_ids(mox.IgnoreArg(),
|
||||
requested_networks = [("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
|
||||
"192.168.1.100")]
|
||||
db.network_get_networks_by_uuids(mox.IgnoreArg(),
|
||||
mox.IgnoreArg()).AndReturn(networks)
|
||||
db.fixed_ip_validate_by_network_address(mox.IgnoreArg(),
|
||||
mox.IgnoreArg(),
|
||||
mox.IgnoreArg()).AndReturn(fixed_ips[0])
|
||||
|
||||
fixed_ips[1]['network'] = FakeModel(**networks[1])
|
||||
fixed_ips[1]['instance'] = None
|
||||
db.fixed_ip_get_by_address(mox.IgnoreArg(),
|
||||
mox.IgnoreArg()).AndReturn(fixed_ips[1])
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.network.validate_networks(None, requested_networks)
|
||||
@@ -202,9 +207,9 @@ class FlatNetworkTestCase(test.TestCase):
|
||||
self.network.validate_networks(None, requested_networks)
|
||||
|
||||
def test_validate_networks_invalid_fixed_ip(self):
|
||||
self.mox.StubOutWithMock(db, 'network_get_networks_by_ids')
|
||||
self.mox.StubOutWithMock(db, 'network_get_networks_by_uuids')
|
||||
requested_networks = [(1, "192.168.0.100.1")]
|
||||
db.network_get_networks_by_ids(mox.IgnoreArg(),
|
||||
db.network_get_networks_by_uuids(mox.IgnoreArg(),
|
||||
mox.IgnoreArg()).AndReturn(networks)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@@ -213,10 +218,10 @@ class FlatNetworkTestCase(test.TestCase):
|
||||
requested_networks)
|
||||
|
||||
def test_validate_networks_empty_fixed_ip(self):
|
||||
self.mox.StubOutWithMock(db, 'network_get_networks_by_ids')
|
||||
self.mox.StubOutWithMock(db, 'network_get_networks_by_uuids')
|
||||
|
||||
requested_networks = [(1, "")]
|
||||
db.network_get_networks_by_ids(mox.IgnoreArg(),
|
||||
db.network_get_networks_by_uuids(mox.IgnoreArg(),
|
||||
mox.IgnoreArg()).AndReturn(networks)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@@ -225,10 +230,10 @@ class FlatNetworkTestCase(test.TestCase):
|
||||
None, requested_networks)
|
||||
|
||||
def test_validate_networks_none_fixed_ip(self):
|
||||
self.mox.StubOutWithMock(db, 'network_get_networks_by_ids')
|
||||
self.mox.StubOutWithMock(db, 'network_get_networks_by_uuids')
|
||||
|
||||
requested_networks = [(1, None)]
|
||||
db.network_get_networks_by_ids(mox.IgnoreArg(),
|
||||
db.network_get_networks_by_uuids(mox.IgnoreArg(),
|
||||
mox.IgnoreArg()).AndReturn(networks)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@@ -271,7 +276,8 @@ class VlanNetworkTestCase(test.TestCase):
|
||||
db.instance_get(mox.IgnoreArg(),
|
||||
mox.IgnoreArg()).AndReturn({'security_groups':
|
||||
[{'id': 0}]})
|
||||
db.fixed_ip_associate_pool(mox.IgnoreArg(),
|
||||
db.fixed_ip_associate_by_address(mox.IgnoreArg(),
|
||||
mox.IgnoreArg(),
|
||||
mox.IgnoreArg(),
|
||||
mox.IgnoreArg()).AndReturn('192.168.0.1')
|
||||
db.fixed_ip_update(mox.IgnoreArg(),
|
||||
@@ -295,17 +301,20 @@ class VlanNetworkTestCase(test.TestCase):
|
||||
cidr='192.168.0.1/24', network_size=100)
|
||||
|
||||
def test_validate_networks(self):
|
||||
self.mox.StubOutWithMock(db, 'project_get_networks_by_ids')
|
||||
self.mox.StubOutWithMock(db, "fixed_ip_validate_by_network_address")
|
||||
self.mox.StubOutWithMock(db, 'project_get_networks_by_uuids')
|
||||
self.mox.StubOutWithMock(db, "fixed_ip_get_by_address")
|
||||
|
||||
requested_networks = [(1, "192.168.0.100")]
|
||||
db.project_get_networks_by_ids(mox.IgnoreArg(),
|
||||
requested_networks = [("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
|
||||
"192.168.1.100")]
|
||||
db.project_get_networks_by_uuids(mox.IgnoreArg(),
|
||||
mox.IgnoreArg()).AndReturn(networks)
|
||||
db.fixed_ip_validate_by_network_address(mox.IgnoreArg(),
|
||||
mox.IgnoreArg(),
|
||||
mox.IgnoreArg()).AndReturn(fixed_ips[0])
|
||||
self.mox.ReplayAll()
|
||||
|
||||
fixed_ips[1]['network'] = FakeModel(**networks[1])
|
||||
fixed_ips[1]['instance'] = None
|
||||
db.fixed_ip_get_by_address(mox.IgnoreArg(),
|
||||
mox.IgnoreArg()).AndReturn(fixed_ips[1])
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.network.validate_networks(None, requested_networks)
|
||||
|
||||
def test_validate_networks_none_requested_networks(self):
|
||||
@@ -313,25 +322,26 @@ class VlanNetworkTestCase(test.TestCase):
|
||||
|
||||
def test_validate_networks_empty_requested_networks(self):
|
||||
requested_networks = []
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.network.validate_networks(None, requested_networks)
|
||||
|
||||
def test_validate_networks_invalid_fixed_ip(self):
|
||||
self.mox.StubOutWithMock(db, 'project_get_networks_by_ids')
|
||||
|
||||
self.mox.StubOutWithMock(db, 'project_get_networks_by_uuids')
|
||||
requested_networks = [(1, "192.168.0.100.1")]
|
||||
db.project_get_networks_by_ids(mox.IgnoreArg(),
|
||||
db.project_get_networks_by_uuids(mox.IgnoreArg(),
|
||||
mox.IgnoreArg()).AndReturn(networks)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.assertRaises(exception.FixedIpInvalid,
|
||||
self.network.validate_networks,
|
||||
None, requested_networks)
|
||||
self.network.validate_networks, None,
|
||||
requested_networks)
|
||||
|
||||
def test_validate_networks_empty_fixed_ip(self):
|
||||
self.mox.StubOutWithMock(db, 'project_get_networks_by_ids')
|
||||
self.mox.StubOutWithMock(db, 'project_get_networks_by_uuids')
|
||||
|
||||
requested_networks = [(1, "")]
|
||||
db.project_get_networks_by_ids(mox.IgnoreArg(),
|
||||
db.project_get_networks_by_uuids(mox.IgnoreArg(),
|
||||
mox.IgnoreArg()).AndReturn(networks)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@@ -340,10 +350,10 @@ class VlanNetworkTestCase(test.TestCase):
|
||||
None, requested_networks)
|
||||
|
||||
def test_validate_networks_none_fixed_ip(self):
|
||||
self.mox.StubOutWithMock(db, 'project_get_networks_by_ids')
|
||||
self.mox.StubOutWithMock(db, 'project_get_networks_by_uuids')
|
||||
|
||||
requested_networks = [(1, None)]
|
||||
db.project_get_networks_by_ids(mox.IgnoreArg(),
|
||||
db.project_get_networks_by_uuids(mox.IgnoreArg(),
|
||||
mox.IgnoreArg()).AndReturn(networks)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user