Convert virtual_interfaces to using instance_uuid.
This review converts virtual_interfaces from tracking their instances with instance_id to using instance_uuid. This should be the last review for blueprint finish-uuid-conversion. Change-Id: I303bba009fa37c72394369c8338e6e759f794cd0
This commit is contained in:
parent
d56b5fc3ad
commit
0d9d2487e2
|
@ -1288,24 +1288,24 @@ def virtual_interface_get_by_uuid(context, vif_uuid):
|
|||
|
||||
|
||||
@require_context
|
||||
@require_instance_exists
|
||||
def virtual_interface_get_by_instance(context, instance_id):
|
||||
@require_instance_exists_using_uuid
|
||||
def virtual_interface_get_by_instance(context, instance_uuid):
|
||||
"""Gets all virtual interfaces for instance.
|
||||
|
||||
:param instance_id: = id of the instance to retrieve vifs for
|
||||
:param instance_uuid: = uuid of the instance to retrieve vifs for
|
||||
"""
|
||||
vif_refs = _virtual_interface_query(context).\
|
||||
filter_by(instance_id=instance_id).\
|
||||
filter_by(instance_uuid=instance_uuid).\
|
||||
all()
|
||||
return vif_refs
|
||||
|
||||
|
||||
@require_context
|
||||
def virtual_interface_get_by_instance_and_network(context, instance_id,
|
||||
network_id):
|
||||
def virtual_interface_get_by_instance_and_network(context, instance_uuid,
|
||||
network_id):
|
||||
"""Gets virtual interface for instance that's associated with network."""
|
||||
vif_ref = _virtual_interface_query(context).\
|
||||
filter_by(instance_id=instance_id).\
|
||||
filter_by(instance_uuid=instance_uuid).\
|
||||
filter_by(network_id=network_id).\
|
||||
first()
|
||||
return vif_ref
|
||||
|
@ -1324,13 +1324,13 @@ def virtual_interface_delete(context, vif_id):
|
|||
|
||||
|
||||
@require_context
|
||||
def virtual_interface_delete_by_instance(context, instance_id):
|
||||
def virtual_interface_delete_by_instance(context, instance_uuid):
|
||||
"""Delete virtual interface records that are associated
|
||||
with the instance given by instance_id.
|
||||
|
||||
:param instance_id: = id of instance
|
||||
:param instance_uuid: = uuid of instance
|
||||
"""
|
||||
vif_refs = virtual_interface_get_by_instance(context, instance_id)
|
||||
vif_refs = virtual_interface_get_by_instance(context, instance_uuid)
|
||||
for vif_ref in vif_refs:
|
||||
virtual_interface_delete(context, vif_ref['id'])
|
||||
|
||||
|
@ -1566,7 +1566,7 @@ def instance_get_all_by_filters(context, filters, sort_key, sort_dir):
|
|||
# Filters for exact matches that we can do along with the SQL query...
|
||||
# For other filters that don't match this, we will do regexp matching
|
||||
exact_match_filter_names = ['project_id', 'user_id', 'image_ref',
|
||||
'vm_state', 'instance_type_id', 'uuid']
|
||||
'vm_state', 'instance_type_id', 'uuid']
|
||||
|
||||
# Filter the query
|
||||
query_prefix = exact_filter(query_prefix, models.Instance,
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
BEGIN TRANSACTION;
|
||||
CREATE TEMPORARY TABLE virtual_interfaces_backup (
|
||||
created_at DATETIME,
|
||||
updated_at DATETIME,
|
||||
deleted_at DATETIME,
|
||||
deleted BOOLEAN,
|
||||
id INTEGER NOT NULL,
|
||||
address VARCHAR(255),
|
||||
network_id INTEGER,
|
||||
instance_id INTEGER,
|
||||
instance_uuid VARCHAR(36),
|
||||
uuid VARCHAR(36),
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
INSERT INTO virtual_interfaces_backup
|
||||
SELECT created_at,
|
||||
updated_at,
|
||||
deleted_at,
|
||||
deleted,
|
||||
id,
|
||||
address,
|
||||
network_id,
|
||||
NULL,
|
||||
instance_uuid,
|
||||
uuid
|
||||
FROM virtual_interfaces;
|
||||
|
||||
UPDATE virtual_interfaces_backup
|
||||
SET instance_id=
|
||||
(SELECT id
|
||||
FROM instances
|
||||
WHERE virtual_interfaces_backup.instance_uuid = instances.uuid
|
||||
);
|
||||
|
||||
DROP TABLE virtual_interfaces;
|
||||
|
||||
CREATE TABLE virtual_interfaces (
|
||||
created_at DATETIME,
|
||||
updated_at DATETIME,
|
||||
deleted_at DATETIME,
|
||||
deleted BOOLEAN,
|
||||
id INTEGER NOT NULL,
|
||||
address VARCHAR(255),
|
||||
network_id INTEGER,
|
||||
instance_id VARCHAR(36) NOT NULL,
|
||||
uuid VARCHAR(36),
|
||||
PRIMARY KEY (id),
|
||||
FOREIGN KEY(instance_id) REFERENCES instances (id)
|
||||
);
|
||||
|
||||
CREATE INDEX virtual_interfaces_instance_id ON
|
||||
virtual_interfaces(instance_id);
|
||||
CREATE INDEX virtual_interfaces_network_id ON
|
||||
virtual_interfaces(network_id);
|
||||
|
||||
INSERT INTO virtual_interfaces
|
||||
SELECT created_at,
|
||||
updated_at,
|
||||
deleted_at,
|
||||
deleted,
|
||||
id,
|
||||
address,
|
||||
network_id,
|
||||
instance_id,
|
||||
uuid
|
||||
FROM virtual_interfaces_backup;
|
||||
|
||||
DROP TABLE virtual_interfaces_backup;
|
||||
|
||||
COMMIT;
|
|
@ -0,0 +1,71 @@
|
|||
BEGIN TRANSACTION;
|
||||
CREATE TEMPORARY TABLE virtual_interfaces_backup (
|
||||
created_at DATETIME,
|
||||
updated_at DATETIME,
|
||||
deleted_at DATETIME,
|
||||
deleted BOOLEAN,
|
||||
id INTEGER NOT NULL,
|
||||
address VARCHAR(255),
|
||||
network_id INTEGER,
|
||||
instance_id INTEGER,
|
||||
instance_uuid VARCHAR(36),
|
||||
uuid VARCHAR(36),
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
INSERT INTO virtual_interfaces_backup
|
||||
SELECT created_at,
|
||||
updated_at,
|
||||
deleted_at,
|
||||
deleted,
|
||||
id,
|
||||
address,
|
||||
network_id,
|
||||
instance_id,
|
||||
NULL,
|
||||
uuid
|
||||
FROM virtual_interfaces;
|
||||
|
||||
UPDATE virtual_interfaces_backup
|
||||
SET instance_uuid=
|
||||
(SELECT uuid
|
||||
FROM instances
|
||||
WHERE virtual_interfaces_backup.instance_id = instances.id
|
||||
);
|
||||
|
||||
DROP TABLE virtual_interfaces;
|
||||
|
||||
CREATE TABLE virtual_interfaces (
|
||||
created_at DATETIME,
|
||||
updated_at DATETIME,
|
||||
deleted_at DATETIME,
|
||||
deleted BOOLEAN,
|
||||
id INTEGER NOT NULL,
|
||||
address VARCHAR(255),
|
||||
network_id INTEGER,
|
||||
instance_uuid VARCHAR(36) NOT NULL,
|
||||
uuid VARCHAR(36),
|
||||
PRIMARY KEY (id),
|
||||
FOREIGN KEY(instance_uuid) REFERENCES instances (uuid)
|
||||
);
|
||||
|
||||
CREATE INDEX virtual_interfaces_instance_uuid ON
|
||||
virtual_interfaces(instance_uuid);
|
||||
CREATE INDEX virtual_interfaces_network_id ON
|
||||
virtual_interfaces(network_id);
|
||||
|
||||
INSERT INTO virtual_interfaces
|
||||
SELECT created_at,
|
||||
updated_at,
|
||||
deleted_at,
|
||||
deleted,
|
||||
id,
|
||||
address,
|
||||
network_id,
|
||||
instance_uuid,
|
||||
uuid
|
||||
FROM virtual_interfaces_backup;
|
||||
|
||||
DROP TABLE virtual_interfaces_backup;
|
||||
|
||||
COMMIT;
|
|
@ -0,0 +1,108 @@
|
|||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2011 OpenStack LLC.
|
||||
# Copyright 2012 Michael Still and Canonical Inc
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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 migrate import ForeignKeyConstraint
|
||||
from sqlalchemy import MetaData, String, Table
|
||||
from sqlalchemy import select, Column, ForeignKey, Integer
|
||||
|
||||
from nova.openstack.common import log as logging
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta = MetaData()
|
||||
meta.bind = migrate_engine
|
||||
virtual_interfaces = Table('virtual_interfaces', meta, autoload=True)
|
||||
instances = Table('instances', meta, autoload=True)
|
||||
uuid_column = Column('instance_uuid', String(36))
|
||||
uuid_column.create(virtual_interfaces)
|
||||
|
||||
try:
|
||||
virtual_interfaces.update().values(
|
||||
instance_uuid=select(
|
||||
[instances.c.uuid],
|
||||
instances.c.id == virtual_interfaces.c.instance_id)
|
||||
).execute()
|
||||
except Exception:
|
||||
uuid_column.drop()
|
||||
raise
|
||||
|
||||
fkeys = list(virtual_interfaces.c.instance_id.foreign_keys)
|
||||
if fkeys:
|
||||
try:
|
||||
fkey_name = fkeys[0].constraint.name
|
||||
ForeignKeyConstraint(
|
||||
columns=[virtual_interfaces.c.instance_id],
|
||||
refcolumns=[instances.c.id],
|
||||
name=fkey_name).drop()
|
||||
except Exception:
|
||||
LOG.error(_("foreign key constraint couldn't be removed"))
|
||||
raise
|
||||
|
||||
virtual_interfaces.c.instance_id.drop()
|
||||
|
||||
try:
|
||||
ForeignKeyConstraint(
|
||||
columns=[virtual_interfaces.c.instance_uuid],
|
||||
refcolumns=[instances.c.uuid]).create()
|
||||
except Exception:
|
||||
LOG.error(_("foreign key constraint couldn't be created"))
|
||||
raise
|
||||
|
||||
|
||||
def downgrade(migrate_engine):
|
||||
meta = MetaData()
|
||||
meta.bind = migrate_engine
|
||||
virtual_interfaces = Table('virtual_interfaces', meta, autoload=True)
|
||||
instances = Table('instances', meta, autoload=True)
|
||||
id_column = Column('instance_id', Integer, ForeignKey('instances.id'))
|
||||
id_column.create(virtual_interfaces)
|
||||
|
||||
fkeys = list(virtual_interfaces.c.instance_uuid.foreign_keys)
|
||||
if fkeys:
|
||||
try:
|
||||
fkey_name = fkeys[0].constraint.name
|
||||
ForeignKeyConstraint(
|
||||
columns=[virtual_interfaces.c.instance_uuid],
|
||||
refcolumns=[instances.c.uuid],
|
||||
name=fkey_name).drop()
|
||||
except Exception:
|
||||
LOG.error(_("foreign key constraint couldn't be removed"))
|
||||
raise
|
||||
|
||||
try:
|
||||
virtual_interfaces.update().values(
|
||||
instance_id=select(
|
||||
[instances.c.id],
|
||||
instances.c.uuid == virtual_interfaces.c.instance_uuid)
|
||||
).execute()
|
||||
except Exception:
|
||||
id_column.drop()
|
||||
raise
|
||||
|
||||
virtual_interfaces.c.instance_uuid.drop()
|
||||
|
||||
try:
|
||||
ForeignKeyConstraint(
|
||||
columns=[virtual_interfaces.c.instance_id],
|
||||
refcolumns=[instances.c.id]).create()
|
||||
except Exception:
|
||||
LOG.error(_("foreign key constraint couldn't be created"))
|
||||
raise
|
|
@ -703,7 +703,7 @@ class VirtualInterface(BASE, NovaBase):
|
|||
id = Column(Integer, primary_key=True)
|
||||
address = Column(String(255), unique=True)
|
||||
network_id = Column(Integer, nullable=False)
|
||||
instance_id = Column(Integer, nullable=False)
|
||||
instance_uuid = Column(String(36), nullable=False)
|
||||
uuid = Column(String(36))
|
||||
|
||||
|
||||
|
|
|
@ -628,19 +628,19 @@ def get_dhcp_opts(context, network_ref):
|
|||
host=host)
|
||||
|
||||
if data:
|
||||
#set of instance ids
|
||||
instance_set = set([datum['instance_id'] for datum in data])
|
||||
instance_set = set([datum['instance_uuid'] for datum in data])
|
||||
default_gw_vif = {}
|
||||
for instance_id in instance_set:
|
||||
vifs = db.virtual_interface_get_by_instance(context, instance_id)
|
||||
for instance_uuid in instance_set:
|
||||
vifs = db.virtual_interface_get_by_instance(context,
|
||||
instance_uuid)
|
||||
if vifs:
|
||||
#offer a default gateway to the first virtual interface
|
||||
default_gw_vif[instance_id] = vifs[0]['id']
|
||||
default_gw_vif[instance_uuid] = vifs[0]['id']
|
||||
|
||||
for datum in data:
|
||||
if instance_id in default_gw_vif:
|
||||
if instance_uuid in default_gw_vif:
|
||||
# we don't want default gateway for this fixed ip
|
||||
if default_gw_vif[instance_id] != datum['vif_id']:
|
||||
if default_gw_vif[instance_uuid] != datum['vif_id']:
|
||||
hosts.append(_host_dhcp_opts(datum))
|
||||
return '\n'.join(hosts)
|
||||
|
||||
|
|
|
@ -313,10 +313,11 @@ class FloatingIP(object):
|
|||
rpc.called by network_api
|
||||
"""
|
||||
instance_id = kwargs.get('instance_id')
|
||||
instance_uuid = kwargs.get('instance_uuid')
|
||||
project_id = kwargs.get('project_id')
|
||||
requested_networks = kwargs.get('requested_networks')
|
||||
LOG.debug(_("floating IP allocation for instance |%s|"), instance_id,
|
||||
context=context)
|
||||
LOG.debug(_("floating IP allocation for instance |%s|"),
|
||||
instance_uuid=instance_uuid, context=context)
|
||||
# call the next inherited class's allocate_for_instance()
|
||||
# which is currently the NetworkManager version
|
||||
# do this first so fixed ip is already allocated
|
||||
|
@ -883,7 +884,7 @@ class NetworkManager(manager.SchedulerDependentManager):
|
|||
results = []
|
||||
|
||||
for vif in vifs:
|
||||
if vif['instance_id'] is None:
|
||||
if vif['instance_uuid'] is None:
|
||||
continue
|
||||
|
||||
network = self._get_network_by_id(context, vif['network_id'])
|
||||
|
@ -894,8 +895,7 @@ class NetworkManager(manager.SchedulerDependentManager):
|
|||
context.project_id)
|
||||
|
||||
if fixed_ipv6 and ipv6_filter.match(fixed_ipv6):
|
||||
# NOTE(jkoelker) Will need to update for the UUID flip
|
||||
results.append({'instance_id': vif['instance_id'],
|
||||
results.append({'instance_uuid': vif['instance_uuid'],
|
||||
'ip': fixed_ipv6})
|
||||
|
||||
vif_id = vif['id']
|
||||
|
@ -905,26 +905,21 @@ class NetworkManager(manager.SchedulerDependentManager):
|
|||
if not fixed_ip or not fixed_ip['address']:
|
||||
continue
|
||||
if fixed_ip['address'] == fixed_ip_filter:
|
||||
results.append({'instance_id': vif['instance_id'],
|
||||
results.append({'instance_uuid': vif['instance_uuid'],
|
||||
'ip': fixed_ip['address']})
|
||||
continue
|
||||
if ip_filter.match(fixed_ip['address']):
|
||||
results.append({'instance_id': vif['instance_id'],
|
||||
results.append({'instance_uuid': vif['instance_uuid'],
|
||||
'ip': fixed_ip['address']})
|
||||
continue
|
||||
for floating_ip in fixed_ip.get('floating_ips', []):
|
||||
if not floating_ip or not floating_ip['address']:
|
||||
continue
|
||||
if ip_filter.match(floating_ip['address']):
|
||||
results.append({'instance_id': vif['instance_id'],
|
||||
results.append({'instance_uuid': vif['instance_uuid'],
|
||||
'ip': floating_ip['address']})
|
||||
continue
|
||||
|
||||
# NOTE(jkoelker) Until we switch over to instance_uuid ;)
|
||||
ids = [res['instance_id'] for res in results]
|
||||
uuid_map = self.db.instance_get_id_to_uuid_mapping(context, ids)
|
||||
for res in results:
|
||||
res['instance_uuid'] = uuid_map.get(res['instance_id'])
|
||||
return results
|
||||
|
||||
def _get_networks_for_instance(self, context, instance_id, project_id,
|
||||
|
@ -959,15 +954,14 @@ class NetworkManager(manager.SchedulerDependentManager):
|
|||
requested_networks = kwargs.get('requested_networks')
|
||||
vpn = kwargs['vpn']
|
||||
admin_context = context.elevated()
|
||||
LOG.debug(_("network allocations for instance |%s|"), instance_id,
|
||||
context=context)
|
||||
LOG.debug(_("network allocations"), instance_uuid=instance_uuid,
|
||||
context=context)
|
||||
networks = self._get_networks_for_instance(admin_context,
|
||||
instance_id, project_id,
|
||||
requested_networks=requested_networks)
|
||||
msg = _('networks retrieved for instance |%(instance_id)s|: '
|
||||
'|%(networks)s|')
|
||||
LOG.debug(msg, locals(), context=context)
|
||||
self._allocate_mac_addresses(context, instance_id, networks)
|
||||
LOG.debug(_('networks retrieved for instance: |%(networks)s|'),
|
||||
locals(), context=context, instance_uuid=instance_uuid)
|
||||
self._allocate_mac_addresses(context, instance_uuid, networks)
|
||||
self._allocate_fixed_ips(admin_context, instance_id,
|
||||
host, networks, vpn=vpn,
|
||||
requested_networks=requested_networks)
|
||||
|
@ -1003,7 +997,7 @@ class NetworkManager(manager.SchedulerDependentManager):
|
|||
|
||||
# deallocate vifs (mac addresses)
|
||||
self.db.virtual_interface_delete_by_instance(read_deleted_context,
|
||||
instance_id)
|
||||
instance['uuid'])
|
||||
|
||||
@wrap_check_policy
|
||||
def get_instance_nw_info(self, context, instance_id, instance_uuid,
|
||||
|
@ -1016,7 +1010,8 @@ class NetworkManager(manager.SchedulerDependentManager):
|
|||
where network = dict containing pertinent data from a network db object
|
||||
and info = dict containing pertinent networking data
|
||||
"""
|
||||
vifs = self.db.virtual_interface_get_by_instance(context, instance_id)
|
||||
vifs = self.db.virtual_interface_get_by_instance(context,
|
||||
instance_uuid)
|
||||
networks = {}
|
||||
|
||||
for vif in vifs:
|
||||
|
@ -1165,16 +1160,16 @@ class NetworkManager(manager.SchedulerDependentManager):
|
|||
|
||||
return subnets
|
||||
|
||||
def _allocate_mac_addresses(self, context, instance_id, networks):
|
||||
def _allocate_mac_addresses(self, context, instance_uuid, networks):
|
||||
"""Generates mac addresses and creates vif rows in db for them."""
|
||||
for network in networks:
|
||||
self.add_virtual_interface(context, instance_id, network['id'])
|
||||
self.add_virtual_interface(context, instance_uuid, network['id'])
|
||||
|
||||
def add_virtual_interface(self, context, instance_id, network_id):
|
||||
def add_virtual_interface(self, context, instance_uuid, network_id):
|
||||
vif = {'address': utils.generate_mac_address(),
|
||||
'instance_id': instance_id,
|
||||
'network_id': network_id,
|
||||
'uuid': str(utils.gen_uuid())}
|
||||
'instance_uuid': instance_uuid,
|
||||
'network_id': network_id,
|
||||
'uuid': str(utils.gen_uuid())}
|
||||
# try FLAG times to create a vif record with a unique mac_address
|
||||
for i in xrange(FLAGS.create_unique_mac_address_attempts):
|
||||
try:
|
||||
|
@ -1183,7 +1178,7 @@ class NetworkManager(manager.SchedulerDependentManager):
|
|||
vif['address'] = utils.generate_mac_address()
|
||||
else:
|
||||
self.db.virtual_interface_delete_by_instance(context,
|
||||
instance_id)
|
||||
instance_uuid)
|
||||
raise exception.VirtualInterfaceMacAddressException()
|
||||
|
||||
@wrap_check_policy
|
||||
|
@ -1251,7 +1246,7 @@ class NetworkManager(manager.SchedulerDependentManager):
|
|||
self._do_trigger_security_group_members_refresh_for_instance(
|
||||
instance_id)
|
||||
get_vif = self.db.virtual_interface_get_by_instance_and_network
|
||||
vif = get_vif(context, instance_id, network['id'])
|
||||
vif = get_vif(context, instance_ref['uuid'], network['id'])
|
||||
values = {'allocated': True,
|
||||
'virtual_interface_id': vif['id']}
|
||||
self.db.fixed_ip_update(context, address, values)
|
||||
|
@ -1546,8 +1541,9 @@ class NetworkManager(manager.SchedulerDependentManager):
|
|||
else:
|
||||
call_func = self._setup_network_on_host
|
||||
|
||||
instance = self.db.instance_by(context, instance_id)
|
||||
vifs = self.db.virtual_interface_get_by_instance(context,
|
||||
instance_id)
|
||||
instance['uuid'])
|
||||
for vif in vifs:
|
||||
network = self.db.network_get(context, vif['network_id'])
|
||||
fixed_ips = self.db.fixed_ips_by_virtual_interface(context,
|
||||
|
@ -1629,7 +1625,9 @@ class NetworkManager(manager.SchedulerDependentManager):
|
|||
@wrap_check_policy
|
||||
def get_vifs_by_instance(self, context, instance_id):
|
||||
"""Returns the vifs associated with an instance"""
|
||||
vifs = self.db.virtual_interface_get_by_instance(context, instance_id)
|
||||
instance = self.db.instance_get(context, instance_id)
|
||||
vifs = self.db.virtual_interface_get_by_instance(context,
|
||||
instance['uuid'])
|
||||
return [dict(vif.iteritems()) for vif in vifs]
|
||||
|
||||
def get_instance_id_by_floating_address(self, context, address):
|
||||
|
@ -1870,16 +1868,16 @@ class VlanManager(RPCAllocateFixedIP, FloatingIP, NetworkManager):
|
|||
|
||||
def allocate_fixed_ip(self, context, instance_id, network, **kwargs):
|
||||
"""Gets a fixed ip from the pool."""
|
||||
instance = self.db.instance_get(context, instance_id)
|
||||
|
||||
if kwargs.get('vpn', None):
|
||||
address = network['vpn_private_address']
|
||||
self.db.fixed_ip_associate(context,
|
||||
address,
|
||||
instance_id,
|
||||
instance['uuid'],
|
||||
network['id'],
|
||||
reserved=True)
|
||||
else:
|
||||
instance = self.db.instance_get(context, instance_id)
|
||||
|
||||
address = kwargs.get('address', None)
|
||||
if address:
|
||||
address = self.db.fixed_ip_associate(context, address,
|
||||
|
@ -1891,9 +1889,9 @@ class VlanManager(RPCAllocateFixedIP, FloatingIP, NetworkManager):
|
|||
instance['uuid'])
|
||||
self._do_trigger_security_group_members_refresh_for_instance(
|
||||
instance_id)
|
||||
vif = self.db.virtual_interface_get_by_instance_and_network(context,
|
||||
instance_id,
|
||||
network['id'])
|
||||
|
||||
vif = self.db.virtual_interface_get_by_instance_and_network(
|
||||
context, instance['uuid'], network['id'])
|
||||
values = {'allocated': True,
|
||||
'virtual_interface_id': vif['id']}
|
||||
self.db.fixed_ip_update(context, address, values)
|
||||
|
|
|
@ -357,7 +357,7 @@ class QuantumManager(manager.FloatingIP, manager.FlatManager):
|
|||
# TODO(tr3buchet): broken. Virtual interfaces require an integer
|
||||
# network ID and it is not nullable
|
||||
vif_rec = self.add_virtual_interface(context,
|
||||
instance_id,
|
||||
instance['uuid'],
|
||||
network['id'],
|
||||
project_id)
|
||||
|
||||
|
@ -510,20 +510,20 @@ class QuantumManager(manager.FloatingIP, manager.FlatManager):
|
|||
self.driver.update_dhcp_hostfile_with_text(interface_id, hosts)
|
||||
self.driver.restart_dhcp(context, interface_id, network_ref)
|
||||
|
||||
def add_virtual_interface(self, context, instance_id, network_id,
|
||||
def add_virtual_interface(self, context, instance_uuid, network_id,
|
||||
net_tenant_id):
|
||||
# If we're not using melange, use the default means...
|
||||
if FLAGS.use_melange_mac_generation:
|
||||
return self._add_virtual_interface(context, instance_id,
|
||||
return self._add_virtual_interface(context, instance_uuid,
|
||||
network_id, net_tenant_id)
|
||||
|
||||
return super(QuantumManager, self).add_virtual_interface(context,
|
||||
instance_id,
|
||||
instance_uuid,
|
||||
network_id)
|
||||
|
||||
def _add_virtual_interface(self, context, instance_id, network_id,
|
||||
def _add_virtual_interface(self, context, instance_uuid, network_id,
|
||||
net_tenant_id):
|
||||
vif = {'instance_id': instance_id,
|
||||
vif = {'instance_uuid': instance_uuid,
|
||||
'network_id': network_id,
|
||||
'uuid': str(utils.gen_uuid())}
|
||||
|
||||
|
@ -533,7 +533,7 @@ class QuantumManager(manager.FloatingIP, manager.FlatManager):
|
|||
# this after Trey's refactorings...
|
||||
m_ipam = melange_ipam_lib.get_ipam_lib(self)
|
||||
vif['address'] = m_ipam.create_vif(vif['uuid'],
|
||||
vif['instance_id'],
|
||||
vif['instance_uuid'],
|
||||
net_tenant_id)
|
||||
|
||||
return self.db.virtual_interface_create(context, vif)
|
||||
|
@ -553,7 +553,7 @@ class QuantumManager(manager.FloatingIP, manager.FlatManager):
|
|||
in the future.
|
||||
"""
|
||||
project_id = kwargs['project_id']
|
||||
vifs = db.virtual_interface_get_by_instance(context, instance_id)
|
||||
vifs = db.virtual_interface_get_by_instance(context, instance_uuid)
|
||||
|
||||
net_tenant_dict = dict((net_id, tenant_id)
|
||||
for (net_id, tenant_id)
|
||||
|
@ -592,8 +592,9 @@ class QuantumManager(manager.FloatingIP, manager.FlatManager):
|
|||
project_id = kwargs.pop('project_id', None)
|
||||
|
||||
admin_context = context.elevated()
|
||||
instance = db.instance_get(context, instance_id)
|
||||
vifs = db.virtual_interface_get_by_instance(admin_context,
|
||||
instance_id)
|
||||
instance['uuid'])
|
||||
|
||||
for vif in vifs:
|
||||
network = db.network_get(admin_context, vif['network_id'])
|
||||
|
|
|
@ -127,7 +127,8 @@ class QuantumNovaIPAMLib(object):
|
|||
network = db.network_get_by_uuid(admin_context, quantum_net_id)
|
||||
address = None
|
||||
if network['cidr']:
|
||||
instance = db.instance_get(context, vif_rec['instance_id'])
|
||||
instance = db.instance_get_by_uuid(context,
|
||||
vif_rec['instance_uuid'])
|
||||
address = db.fixed_ip_associate_pool(admin_context,
|
||||
network['id'],
|
||||
instance['uuid'])
|
||||
|
@ -213,7 +214,7 @@ class QuantumNovaIPAMLib(object):
|
|||
"""
|
||||
admin_context = context.elevated()
|
||||
fixed_ips = db.fixed_ips_by_virtual_interface(admin_context,
|
||||
vif_ref['id'])
|
||||
vif_ref['id'])
|
||||
# NOTE(s0mik): Sets fixed-ip to deallocated, but leaves the entry
|
||||
# associated with the instance-id. This prevents us from handing it
|
||||
# out again immediately, as allocating it to a new instance before
|
||||
|
|
|
@ -239,7 +239,7 @@ class CloudTestCase(test.TestCase):
|
|||
project_id = self.context.project_id
|
||||
nw_info = self.network.allocate_for_instance(self.context,
|
||||
instance_id=inst['id'],
|
||||
instance_uuid='',
|
||||
instance_uuid=inst['uuid'],
|
||||
host=inst['host'],
|
||||
vpn=None,
|
||||
rxtx_factor=3,
|
||||
|
|
|
@ -3142,14 +3142,18 @@ class ComputeAPITestCase(BaseTestCase):
|
|||
'instance_get_id_to_uuid_mapping',
|
||||
db.instance_get_id_to_uuid_mapping)
|
||||
|
||||
instance1 = self._create_fake_instance({'display_name': 'woot',
|
||||
'id': 0})
|
||||
instance1 = self._create_fake_instance({
|
||||
'display_name': 'woot',
|
||||
'id': 0,
|
||||
'uuid': '00000000-0000-0000-0000-000000000010'})
|
||||
instance2 = self._create_fake_instance({
|
||||
'display_name': 'woo',
|
||||
'id': 20})
|
||||
'id': 20,
|
||||
'uuid': '00000000-0000-0000-0000-000000000020'})
|
||||
instance3 = self._create_fake_instance({
|
||||
'display_name': 'not-woot',
|
||||
'id': 30})
|
||||
'id': 30,
|
||||
'uuid': '00000000-0000-0000-0000-000000000030'})
|
||||
|
||||
# ip ends up matching 2nd octet here.. so all 3 match ip
|
||||
# but 'name' only matches one
|
||||
|
|
|
@ -74,15 +74,15 @@ class FakeNetworkManager(network_manager.NetworkManager):
|
|||
|
||||
class FakeDB:
|
||||
vifs = [{'id': 0,
|
||||
'instance_id': 0,
|
||||
'instance_uuid': '00000000-0000-0000-0000-000000000010',
|
||||
'network_id': 1,
|
||||
'address': 'DC:AD:BE:FF:EF:01'},
|
||||
{'id': 1,
|
||||
'instance_id': 20,
|
||||
'instance_uuid': '00000000-0000-0000-0000-000000000020',
|
||||
'network_id': 21,
|
||||
'address': 'DC:AD:BE:FF:EF:02'},
|
||||
{'id': 2,
|
||||
'instance_id': 30,
|
||||
'instance_uuid': '00000000-0000-0000-0000-000000000030',
|
||||
'network_id': 31,
|
||||
'address': 'DC:AD:BE:FF:EF:03'}]
|
||||
|
||||
|
@ -103,7 +103,7 @@ class FakeNetworkManager(network_manager.NetworkManager):
|
|||
address='173.16.0.2',
|
||||
virtual_interface_id=2)]
|
||||
|
||||
def fixed_ip_get_by_instance(self, context, instance_id):
|
||||
def fixed_ip_get_by_instance(self, context, instance_uuid):
|
||||
return [dict(address='10.0.0.0'), dict(address='10.0.0.1'),
|
||||
dict(address='10.0.0.2')]
|
||||
|
||||
|
@ -220,7 +220,7 @@ def next_fixed_ip(network_id, num_floating_ips=0):
|
|||
return {'id': next_id,
|
||||
'network_id': network_id,
|
||||
'address': '192.168.%d.%03d' % (network_id, (next_id + 99)),
|
||||
'instance_id': 1,
|
||||
'instance_uuid': 1,
|
||||
'allocated': False,
|
||||
# and since network_id and vif_id happen to be equivalent
|
||||
'virtual_interface_id': network_id,
|
||||
|
@ -292,7 +292,7 @@ def fake_get_instance_nw_info(stubs, num_networks=1, ips_per_vif=2,
|
|||
'uuid': uuid,
|
||||
'network_id': 1,
|
||||
'network': None,
|
||||
'instance_id': 0}
|
||||
'instance_uuid': 0}
|
||||
|
||||
def network_get_fake(context, network_id):
|
||||
nets = [n for n in networks if n['id'] == network_id]
|
||||
|
|
|
@ -36,16 +36,20 @@ LOG = logging.getLogger(__name__)
|
|||
|
||||
HOST = "testhost"
|
||||
|
||||
instances = [{'id': 0,
|
||||
'host': 'fake_instance00',
|
||||
'created_at': 'fakedate',
|
||||
'updated_at': 'fakedate',
|
||||
'hostname': 'fake_instance00'},
|
||||
{'id': 1,
|
||||
'host': 'fake_instance01',
|
||||
'created_at': 'fakedate',
|
||||
'updated_at': 'fakedate',
|
||||
'hostname': 'fake_instance01'}]
|
||||
instances = {'00000000-0000-0000-0000-0000000000000000':
|
||||
{'id': 0,
|
||||
'uuid': '00000000-0000-0000-0000-0000000000000000',
|
||||
'host': 'fake_instance00',
|
||||
'created_at': 'fakedate',
|
||||
'updated_at': 'fakedate',
|
||||
'hostname': 'fake_instance00'},
|
||||
'00000000-0000-0000-0000-0000000000000001':
|
||||
{'id': 1,
|
||||
'uuid': '00000000-0000-0000-0000-0000000000000001',
|
||||
'host': 'fake_instance01',
|
||||
'created_at': 'fakedate',
|
||||
'updated_at': 'fakedate',
|
||||
'hostname': 'fake_instance01'}}
|
||||
|
||||
|
||||
addresses = [{"address": "10.0.0.1"},
|
||||
|
@ -108,7 +112,7 @@ fixed_ips = [{'id': 0,
|
|||
'instance_id': 0,
|
||||
'allocated': True,
|
||||
'virtual_interface_id': 0,
|
||||
'instance_id': 0,
|
||||
'instance_uuid': '00000000-0000-0000-0000-0000000000000000',
|
||||
'floating_ips': []},
|
||||
{'id': 1,
|
||||
'network_id': 1,
|
||||
|
@ -116,7 +120,7 @@ fixed_ips = [{'id': 0,
|
|||
'instance_id': 0,
|
||||
'allocated': True,
|
||||
'virtual_interface_id': 1,
|
||||
'instance_id': 0,
|
||||
'instance_uuid': '00000000-0000-0000-0000-0000000000000000',
|
||||
'floating_ips': []},
|
||||
{'id': 2,
|
||||
'network_id': 1,
|
||||
|
@ -124,7 +128,7 @@ fixed_ips = [{'id': 0,
|
|||
'instance_id': 1,
|
||||
'allocated': True,
|
||||
'virtual_interface_id': 2,
|
||||
'instance_id': 1,
|
||||
'instance_uuid': '00000000-0000-0000-0000-0000000000000001',
|
||||
'floating_ips': []},
|
||||
{'id': 3,
|
||||
'network_id': 0,
|
||||
|
@ -132,7 +136,7 @@ fixed_ips = [{'id': 0,
|
|||
'instance_id': 1,
|
||||
'allocated': True,
|
||||
'virtual_interface_id': 3,
|
||||
'instance_id': 1,
|
||||
'instance_uuid': '00000000-0000-0000-0000-0000000000000001',
|
||||
'floating_ips': []},
|
||||
{'id': 4,
|
||||
'network_id': 0,
|
||||
|
@ -140,7 +144,7 @@ fixed_ips = [{'id': 0,
|
|||
'instance_id': 0,
|
||||
'allocated': True,
|
||||
'virtual_interface_id': 4,
|
||||
'instance_id': 0,
|
||||
'instance_uuid': '00000000-0000-0000-0000-0000000000000000',
|
||||
'floating_ips': []},
|
||||
{'id': 5,
|
||||
'network_id': 1,
|
||||
|
@ -148,7 +152,7 @@ fixed_ips = [{'id': 0,
|
|||
'instance_id': 1,
|
||||
'allocated': True,
|
||||
'virtual_interface_id': 5,
|
||||
'instance_id': 1,
|
||||
'instance_uuid': '00000000-0000-0000-0000-0000000000000001',
|
||||
'floating_ips': []}]
|
||||
|
||||
|
||||
|
@ -156,46 +160,46 @@ vifs = [{'id': 0,
|
|||
'address': 'DE:AD:BE:EF:00:00',
|
||||
'uuid': '00000000-0000-0000-0000-0000000000000000',
|
||||
'network_id': 0,
|
||||
'instance_id': 0},
|
||||
'instance_uuid': '00000000-0000-0000-0000-0000000000000000'},
|
||||
{'id': 1,
|
||||
'address': 'DE:AD:BE:EF:00:01',
|
||||
'uuid': '00000000-0000-0000-0000-0000000000000001',
|
||||
'network_id': 1,
|
||||
'instance_id': 0},
|
||||
'instance_uuid': '00000000-0000-0000-0000-0000000000000000'},
|
||||
{'id': 2,
|
||||
'address': 'DE:AD:BE:EF:00:02',
|
||||
'uuid': '00000000-0000-0000-0000-0000000000000002',
|
||||
'network_id': 1,
|
||||
'instance_id': 1},
|
||||
'instance_uuid': '00000000-0000-0000-0000-0000000000000001'},
|
||||
{'id': 3,
|
||||
'address': 'DE:AD:BE:EF:00:03',
|
||||
'uuid': '00000000-0000-0000-0000-0000000000000003',
|
||||
'network_id': 0,
|
||||
'instance_id': 1},
|
||||
'instance_uuid': '00000000-0000-0000-0000-0000000000000001'},
|
||||
{'id': 4,
|
||||
'address': 'DE:AD:BE:EF:00:04',
|
||||
'uuid': '00000000-0000-0000-0000-0000000000000004',
|
||||
'network_id': 0,
|
||||
'instance_id': 0},
|
||||
'instance_uuid': '00000000-0000-0000-0000-0000000000000000'},
|
||||
{'id': 5,
|
||||
'address': 'DE:AD:BE:EF:00:05',
|
||||
'uuid': '00000000-0000-0000-0000-0000000000000005',
|
||||
'network_id': 1,
|
||||
'instance_id': 1}]
|
||||
'instance_uuid': '00000000-0000-0000-0000-0000000000000001'}]
|
||||
|
||||
|
||||
def get_associated(context, network_id, host=None):
|
||||
result = []
|
||||
for datum in fixed_ips:
|
||||
if (datum['network_id'] == network_id and datum['allocated']
|
||||
and datum['instance_id'] is not None
|
||||
and datum['instance_uuid'] is not None
|
||||
and datum['virtual_interface_id'] is not None):
|
||||
instance = instances[datum['instance_id']]
|
||||
instance = instances[datum['instance_uuid']]
|
||||
if host and host != instance['host']:
|
||||
continue
|
||||
cleaned = {}
|
||||
cleaned['address'] = datum['address']
|
||||
cleaned['instance_id'] = datum['instance_id']
|
||||
cleaned['instance_uuid'] = datum['instance_uuid']
|
||||
cleaned['network_id'] = datum['network_id']
|
||||
cleaned['vif_id'] = datum['virtual_interface_id']
|
||||
vif = vifs[datum['virtual_interface_id']]
|
||||
|
@ -217,8 +221,9 @@ class LinuxNetworkTestCase(test.TestCase):
|
|||
self.context = context.RequestContext('testuser', 'testproject',
|
||||
is_admin=True)
|
||||
|
||||
def get_vifs(_context, instance_id):
|
||||
return [vif for vif in vifs if vif['instance_id'] == instance_id]
|
||||
def get_vifs(_context, instance_uuid):
|
||||
return [vif for vif in vifs if vif['instance_uuid'] == \
|
||||
instance_uuid]
|
||||
|
||||
def get_instance(_context, instance_id):
|
||||
return instances[instance_id]
|
||||
|
|
|
@ -114,17 +114,17 @@ vifs = [{'id': 0,
|
|||
'address': 'DE:AD:BE:EF:00:00',
|
||||
'uuid': '00000000-0000-0000-0000-0000000000000000',
|
||||
'network_id': 0,
|
||||
'instance_id': 0},
|
||||
'instance_uuid': 0},
|
||||
{'id': 1,
|
||||
'address': 'DE:AD:BE:EF:00:01',
|
||||
'uuid': '00000000-0000-0000-0000-0000000000000001',
|
||||
'network_id': 1,
|
||||
'instance_id': 0},
|
||||
'instance_uuid': 0},
|
||||
{'id': 2,
|
||||
'address': 'DE:AD:BE:EF:00:02',
|
||||
'uuid': '00000000-0000-0000-0000-0000000000000002',
|
||||
'network_id': 2,
|
||||
'instance_id': 0}]
|
||||
'instance_uuid': 0}]
|
||||
|
||||
|
||||
class FlatNetworkTestCase(test.TestCase):
|
||||
|
@ -417,11 +417,14 @@ class VlanNetworkTestCase(test.TestCase):
|
|||
is_admin=False)
|
||||
|
||||
def test_vpn_allocate_fixed_ip(self):
|
||||
self.mox.StubOutWithMock(db, 'instance_get')
|
||||
self.mox.StubOutWithMock(db, 'fixed_ip_associate')
|
||||
self.mox.StubOutWithMock(db, 'fixed_ip_update')
|
||||
self.mox.StubOutWithMock(db,
|
||||
'virtual_interface_get_by_instance_and_network')
|
||||
|
||||
db.instance_get(mox.IgnoreArg(),
|
||||
mox.IgnoreArg()).AndReturn({'uuid': '42'})
|
||||
db.fixed_ip_associate(mox.IgnoreArg(),
|
||||
mox.IgnoreArg(),
|
||||
mox.IgnoreArg(),
|
||||
|
@ -448,7 +451,7 @@ class VlanNetworkTestCase(test.TestCase):
|
|||
self.assertRaises(exception.FixedIpNotFoundForNetwork,
|
||||
self.network.allocate_fixed_ip,
|
||||
context_admin,
|
||||
instance['uuid'],
|
||||
instance['id'],
|
||||
network,
|
||||
vpn=True)
|
||||
|
||||
|
@ -1264,30 +1267,30 @@ class CommonNetworkTestCase(test.TestCase):
|
|||
{'ip': '172.16.0.2'})
|
||||
self.assertTrue(res)
|
||||
self.assertEqual(len(res), 1)
|
||||
self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id'])
|
||||
self.assertEqual(res[0]['instance_uuid'], _vifs[1]['instance_uuid'])
|
||||
|
||||
# Get instance 2
|
||||
res = manager.get_instance_uuids_by_ip_filter(fake_context,
|
||||
{'ip': '173.16.0.2'})
|
||||
self.assertTrue(res)
|
||||
self.assertEqual(len(res), 1)
|
||||
self.assertEqual(res[0]['instance_id'], _vifs[2]['instance_id'])
|
||||
self.assertEqual(res[0]['instance_uuid'], _vifs[2]['instance_uuid'])
|
||||
|
||||
# Get instance 0 and 1
|
||||
res = manager.get_instance_uuids_by_ip_filter(fake_context,
|
||||
{'ip': '172.16.0.*'})
|
||||
self.assertTrue(res)
|
||||
self.assertEqual(len(res), 2)
|
||||
self.assertEqual(res[0]['instance_id'], _vifs[0]['instance_id'])
|
||||
self.assertEqual(res[1]['instance_id'], _vifs[1]['instance_id'])
|
||||
self.assertEqual(res[0]['instance_uuid'], _vifs[0]['instance_uuid'])
|
||||
self.assertEqual(res[1]['instance_uuid'], _vifs[1]['instance_uuid'])
|
||||
|
||||
# Get instance 1 and 2
|
||||
res = manager.get_instance_uuids_by_ip_filter(fake_context,
|
||||
{'ip': '17..16.0.2'})
|
||||
self.assertTrue(res)
|
||||
self.assertEqual(len(res), 2)
|
||||
self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id'])
|
||||
self.assertEqual(res[1]['instance_id'], _vifs[2]['instance_id'])
|
||||
self.assertEqual(res[0]['instance_uuid'], _vifs[1]['instance_uuid'])
|
||||
self.assertEqual(res[1]['instance_uuid'], _vifs[2]['instance_uuid'])
|
||||
|
||||
def test_get_instance_uuids_by_ipv6_regex(self):
|
||||
manager = fake_network.FakeNetworkManager()
|
||||
|
@ -1309,7 +1312,7 @@ class CommonNetworkTestCase(test.TestCase):
|
|||
{'ip6': '2001:.*2'})
|
||||
self.assertTrue(res)
|
||||
self.assertEqual(len(res), 1)
|
||||
self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id'])
|
||||
self.assertEqual(res[0]['instance_uuid'], _vifs[1]['instance_uuid'])
|
||||
|
||||
# Get instance 2
|
||||
ip6 = '2001:db8:69:1f:dead:beff:feff:ef03'
|
||||
|
@ -1317,15 +1320,15 @@ class CommonNetworkTestCase(test.TestCase):
|
|||
{'ip6': ip6})
|
||||
self.assertTrue(res)
|
||||
self.assertEqual(len(res), 1)
|
||||
self.assertEqual(res[0]['instance_id'], _vifs[2]['instance_id'])
|
||||
self.assertEqual(res[0]['instance_uuid'], _vifs[2]['instance_uuid'])
|
||||
|
||||
# Get instance 0 and 1
|
||||
res = manager.get_instance_uuids_by_ip_filter(fake_context,
|
||||
{'ip6': '.*ef0[1,2]'})
|
||||
self.assertTrue(res)
|
||||
self.assertEqual(len(res), 2)
|
||||
self.assertEqual(res[0]['instance_id'], _vifs[0]['instance_id'])
|
||||
self.assertEqual(res[1]['instance_id'], _vifs[1]['instance_id'])
|
||||
self.assertEqual(res[0]['instance_uuid'], _vifs[0]['instance_uuid'])
|
||||
self.assertEqual(res[1]['instance_uuid'], _vifs[1]['instance_uuid'])
|
||||
|
||||
# Get instance 1 and 2
|
||||
ip6 = '2001:db8:69:1.:dead:beff:feff:ef0.'
|
||||
|
@ -1333,8 +1336,8 @@ class CommonNetworkTestCase(test.TestCase):
|
|||
{'ip6': ip6})
|
||||
self.assertTrue(res)
|
||||
self.assertEqual(len(res), 2)
|
||||
self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id'])
|
||||
self.assertEqual(res[1]['instance_id'], _vifs[2]['instance_id'])
|
||||
self.assertEqual(res[0]['instance_uuid'], _vifs[1]['instance_uuid'])
|
||||
self.assertEqual(res[1]['instance_uuid'], _vifs[2]['instance_uuid'])
|
||||
|
||||
def test_get_instance_uuids_by_ip(self):
|
||||
manager = fake_network.FakeNetworkManager()
|
||||
|
@ -1358,7 +1361,7 @@ class CommonNetworkTestCase(test.TestCase):
|
|||
{'fixed_ip': ip})
|
||||
self.assertTrue(res)
|
||||
self.assertEqual(len(res), 1)
|
||||
self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id'])
|
||||
self.assertEqual(res[0]['instance_uuid'], _vifs[1]['instance_uuid'])
|
||||
|
||||
# Get instance 2
|
||||
ip = '173.16.0.2'
|
||||
|
@ -1366,7 +1369,7 @@ class CommonNetworkTestCase(test.TestCase):
|
|||
{'fixed_ip': ip})
|
||||
self.assertTrue(res)
|
||||
self.assertEqual(len(res), 1)
|
||||
self.assertEqual(res[0]['instance_id'], _vifs[2]['instance_id'])
|
||||
self.assertEqual(res[0]['instance_uuid'], _vifs[2]['instance_uuid'])
|
||||
|
||||
def test_get_network(self):
|
||||
manager = fake_network.FakeNetworkManager()
|
||||
|
@ -1489,12 +1492,9 @@ class AllocateTestCase(test.TestCase):
|
|||
{'host': self.network.host})
|
||||
project_id = self.context.project_id
|
||||
nw_info = self.network.allocate_for_instance(self.context,
|
||||
instance_id=inst['id'],
|
||||
instance_uuid='',
|
||||
host=inst['host'],
|
||||
vpn=None,
|
||||
rxtx_factor=3,
|
||||
project_id=project_id)
|
||||
instance_id=inst['id'], instance_uuid=inst['uuid'],
|
||||
host=inst['host'], vpn=None, rxtx_factor=3,
|
||||
project_id=project_id)
|
||||
self.assertEquals(1, len(nw_info))
|
||||
fixed_ip = nw_info.fixed_ips()[0]['address']
|
||||
self.assertTrue(utils.is_valid_ipv4(fixed_ip))
|
||||
|
|
|
@ -31,27 +31,6 @@ from nova import utils
|
|||
FLAGS = flags.FLAGS
|
||||
|
||||
|
||||
def _setup_networking(instance_id, ip='1.2.3.4', flo_addr='1.2.1.2'):
|
||||
ctxt = context.get_admin_context()
|
||||
network_ref = db.project_get_networks(ctxt,
|
||||
'fake',
|
||||
associate=True)[0]
|
||||
vif = {'address': '56:12:12:12:12:12',
|
||||
'network_id': network_ref['id'],
|
||||
'instance_id': instance_id}
|
||||
vif_ref = db.virtual_interface_create(ctxt, vif)
|
||||
|
||||
fixed_ip = {'address': ip,
|
||||
'network_id': network_ref['id'],
|
||||
'virtual_interface_id': vif_ref['id'],
|
||||
'allocated': True,
|
||||
'instance_id': instance_id}
|
||||
db.fixed_ip_create(ctxt, fixed_ip)
|
||||
fix_ref = db.fixed_ip_get_by_address(ctxt, ip)
|
||||
db.floating_ip_create(ctxt, {'address': flo_addr,
|
||||
'fixed_ip_id': fix_ref['id']})
|
||||
|
||||
|
||||
class DbApiTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(DbApiTestCase, self).setUp()
|
||||
|
@ -345,7 +324,7 @@ class DbApiTestCase(test.TestCase):
|
|||
ctxt = context.get_admin_context()
|
||||
values = {'host': 'foo', 'hostname': 'myname'}
|
||||
instance = db.instance_create(ctxt, values)
|
||||
values = {'address': 'bar', 'instance_id': instance['id']}
|
||||
values = {'address': 'bar', 'instance_uuid': instance['uuid']}
|
||||
vif = db.virtual_interface_create(ctxt, values)
|
||||
values = {'address': 'baz',
|
||||
'network_id': 1,
|
||||
|
|
|
@ -741,7 +741,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
|
|||
|
||||
self.network.allocate_for_instance(ctxt,
|
||||
instance_id=2,
|
||||
instance_uuid="00000000-0000-0000-0000-000000000000",
|
||||
instance_uuid='00000000-0000-0000-0000-000000000002',
|
||||
host=FLAGS.host,
|
||||
vpn=None,
|
||||
rxtx_factor=3,
|
||||
|
@ -851,6 +851,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
|
|||
"""Creates and spawns a test instance."""
|
||||
instance_values = {
|
||||
'id': instance_id,
|
||||
'uuid': '00000000-0000-0000-0000-00000000000%d' % instance_id,
|
||||
'project_id': self.project_id,
|
||||
'user_id': self.user_id,
|
||||
'image_ref': 1,
|
||||
|
|
Loading…
Reference in New Issue