Improve NeutronFixture and remove unncessary stubbing
With a small improvement on NeutronFixture that allows creating more than two ports we can let our tests to exercise and therefore cover most of the neutronv2/api code as well. To do that this path removes a lot of fake_network.set_stub_network_methods() calls from the tests. The remaining calls are not that trivial to remove so those are left in for a later patch. The numa functional tests uses the libvirt fixture and during the guest config xml generation it tries to instantiate OVOs from os_vif. To make this work the libvirt fixture has to make sure that the os_vif.initialize() is called as that call registers the OVOs. Change-Id: I1dbccc2be6ba79bf267edac9208c80e187e6256a
This commit is contained in:
parent
da31f67892
commit
a2224f38d9
@ -22,6 +22,7 @@ from contextlib import contextmanager
|
|||||||
import copy
|
import copy
|
||||||
import logging as std_logging
|
import logging as std_logging
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
@ -1121,6 +1122,7 @@ class NeutronFixture(fixtures.Fixture):
|
|||||||
'admin_state_up': True,
|
'admin_state_up': True,
|
||||||
'tenant_id': tenant_id,
|
'tenant_id': tenant_id,
|
||||||
'id': '3cb9bc59-5699-4588-a4b1-b87f96708bc6',
|
'id': '3cb9bc59-5699-4588-a4b1-b87f96708bc6',
|
||||||
|
'shared': False,
|
||||||
}
|
}
|
||||||
subnet_1 = {
|
subnet_1 = {
|
||||||
'name': 'private-subnet',
|
'name': 'private-subnet',
|
||||||
@ -1156,7 +1158,8 @@ class NeutronFixture(fixtures.Fixture):
|
|||||||
'subnet_id': subnet_1['id']
|
'subnet_id': subnet_1['id']
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'tenant_id': tenant_id
|
'tenant_id': tenant_id,
|
||||||
|
'binding:vif_type': 'ovs'
|
||||||
}
|
}
|
||||||
|
|
||||||
port_2 = {
|
port_2 = {
|
||||||
@ -1171,7 +1174,8 @@ class NeutronFixture(fixtures.Fixture):
|
|||||||
'subnet_id': subnet_1['id']
|
'subnet_id': subnet_1['id']
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'tenant_id': tenant_id
|
'tenant_id': tenant_id,
|
||||||
|
'binding:vif_type': 'ovs'
|
||||||
}
|
}
|
||||||
|
|
||||||
nw_info = [{
|
nw_info = [{
|
||||||
@ -1235,10 +1239,6 @@ class NeutronFixture(fixtures.Fixture):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(NeutronFixture, self).setUp()
|
super(NeutronFixture, self).setUp()
|
||||||
|
|
||||||
self.test.stub_out(
|
|
||||||
'nova.network.neutronv2.api.API.'
|
|
||||||
'validate_networks',
|
|
||||||
lambda *args, **kwargs: 1)
|
|
||||||
self.test.stub_out(
|
self.test.stub_out(
|
||||||
'nova.network.neutronv2.api.API.setup_networks_on_host',
|
'nova.network.neutronv2.api.API.setup_networks_on_host',
|
||||||
lambda *args, **kwargs: None)
|
lambda *args, **kwargs: None)
|
||||||
@ -1302,6 +1302,9 @@ class NeutronFixture(fixtures.Fixture):
|
|||||||
networks = copy.deepcopy(self._networks)
|
networks = copy.deepcopy(self._networks)
|
||||||
if 'id' in _params:
|
if 'id' in _params:
|
||||||
networks = [x for x in networks if x['id'] in _params['id']]
|
networks = [x for x in networks if x['id'] in _params['id']]
|
||||||
|
if 'shared' in _params:
|
||||||
|
networks = [x for x in networks if x['shared'] ==
|
||||||
|
_params['shared']]
|
||||||
return {'networks': networks}
|
return {'networks': networks}
|
||||||
|
|
||||||
def list_ports(self, retrieve_all=True, **_params):
|
def list_ports(self, retrieve_all=True, **_params):
|
||||||
@ -1314,8 +1317,23 @@ class NeutronFixture(fixtures.Fixture):
|
|||||||
return copy.deepcopy({'floatingips': self._floatingips})
|
return copy.deepcopy({'floatingips': self._floatingips})
|
||||||
|
|
||||||
def create_port(self, body=None):
|
def create_port(self, body=None):
|
||||||
self._ports.append(copy.deepcopy(NeutronFixture.port_2))
|
if self._get_first_id_match(NeutronFixture.port_2['id'],
|
||||||
return copy.deepcopy({'port': NeutronFixture.port_2})
|
self._ports) is None:
|
||||||
|
# we need the double copy as port_2 is a class variable but
|
||||||
|
# self._ports is an instance variable
|
||||||
|
new_port = copy.deepcopy(NeutronFixture.port_2)
|
||||||
|
self._ports.append(new_port)
|
||||||
|
else:
|
||||||
|
new_port = copy.deepcopy(NeutronFixture.port_2)
|
||||||
|
# we need truly random uuids instead of named sentinels as some
|
||||||
|
# tests needs more than 3 ports
|
||||||
|
new_port.update({
|
||||||
|
'id': str(uuidutils.generate_uuid()),
|
||||||
|
'mac_address': '00:' + ':'.join(
|
||||||
|
['%02x' % random.randint(0, 255) for _ in range(5)]),
|
||||||
|
})
|
||||||
|
self._ports.append(new_port)
|
||||||
|
return {'port': copy.deepcopy(new_port)}
|
||||||
|
|
||||||
def update_port(self, port_id, body=None):
|
def update_port(self, port_id, body=None):
|
||||||
new_port = self._get_first_id_match(port_id, self._ports)
|
new_port = self._get_first_id_match(port_id, self._ports)
|
||||||
@ -1326,6 +1344,10 @@ class NeutronFixture(fixtures.Fixture):
|
|||||||
|
|
||||||
return {'port': new_port}
|
return {'port': new_port}
|
||||||
|
|
||||||
|
def show_quota(self, project_id):
|
||||||
|
# unlimited quota
|
||||||
|
return {'quota': {'port': -1}}
|
||||||
|
|
||||||
|
|
||||||
class _NoopConductor(object):
|
class _NoopConductor(object):
|
||||||
def __getattr__(self, key):
|
def __getattr__(self, key):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user