Add task argument to network wrapper
This adds a new mandatory task argument to the network wrapper; this will be used in a future commit to generate the random names for ephemeral resources created by the wrapper. Change-Id: I5fc8053ecfba2ff477c3ff904384f42026ac0642
This commit is contained in:
parent
f08c8e2395
commit
df581dc4fe
@ -126,8 +126,9 @@ class UserGenerator(UserContextMixin, context.Context):
|
||||
if consts.Service.NEUTRON not in clients.services().values():
|
||||
return
|
||||
|
||||
use_sg, msg = network.wrap(clients).supports_extension(
|
||||
"security-group")
|
||||
use_sg, msg = network.wrap(clients,
|
||||
self.context["task"]).supports_extension(
|
||||
"security-group")
|
||||
if not use_sg:
|
||||
LOG.debug("Security group context is disabled: %s" % msg)
|
||||
return
|
||||
|
@ -96,7 +96,8 @@ class AllowSSH(context.Context):
|
||||
|
||||
net_wrapper = network.wrap(
|
||||
osclients.Clients(admin_or_user["endpoint"]),
|
||||
self.config)
|
||||
self.context["task"],
|
||||
config=self.config)
|
||||
use_sg, msg = net_wrapper.supports_extension("security-group")
|
||||
if not use_sg:
|
||||
LOG.info(_("Security group context is disabled: %s") % msg)
|
||||
|
@ -44,7 +44,8 @@ class ExistingNetwork(context.Context):
|
||||
self.context.get("users", [])):
|
||||
net_wrapper = network_wrapper.wrap(
|
||||
osclients.Clients(user["endpoint"]),
|
||||
self.config)
|
||||
self.context["task"],
|
||||
config=self.config)
|
||||
self.context["tenants"][tenant_id]["networks"] = (
|
||||
net_wrapper.list_networks())
|
||||
|
||||
|
@ -67,7 +67,8 @@ class Network(context.Context):
|
||||
# creating a connection in setup and cleanup separately.
|
||||
net_wrapper = network_wrapper.wrap(
|
||||
osclients.Clients(self.context["admin"]["endpoint"]),
|
||||
self.config)
|
||||
self.context["task"],
|
||||
config=self.config)
|
||||
for user, tenant_id in (utils.iterate_per_tenants(
|
||||
self.context.get("users", []))):
|
||||
self.context["tenants"][tenant_id]["networks"] = []
|
||||
@ -85,7 +86,8 @@ class Network(context.Context):
|
||||
def cleanup(self):
|
||||
net_wrapper = network_wrapper.wrap(
|
||||
osclients.Clients(self.context["admin"]["endpoint"]),
|
||||
self.config)
|
||||
self.context["task"],
|
||||
config=self.config)
|
||||
for tenant_id, tenant_ctx in six.iteritems(self.context["tenants"]):
|
||||
for network in tenant_ctx.get("networks", []):
|
||||
with logging.ExceptionLogger(
|
||||
|
@ -53,7 +53,8 @@ class Lbaas(context.Context):
|
||||
def setup(self):
|
||||
net_wrapper = network_wrapper.wrap(
|
||||
osclients.Clients(self.context["admin"]["endpoint"]),
|
||||
self.config)
|
||||
self.context["task"],
|
||||
config=self.config)
|
||||
|
||||
use_lb, msg = net_wrapper.supports_extension("lbaas")
|
||||
if not use_lb:
|
||||
@ -80,7 +81,8 @@ class Lbaas(context.Context):
|
||||
def cleanup(self):
|
||||
net_wrapper = network_wrapper.wrap(
|
||||
osclients.Clients(self.context["admin"]["endpoint"]),
|
||||
self.config)
|
||||
self.context["task"],
|
||||
config=self.config)
|
||||
for tenant_id, tenant_ctx in six.iteritems(self.context["tenants"]):
|
||||
for network in tenant_ctx.get("networks", []):
|
||||
for pool in network.get("lb_pools", []):
|
||||
|
@ -641,6 +641,7 @@ class NovaServers(utils.NovaScenario,
|
||||
:param kwargs: Optional additional arguments for server creation
|
||||
"""
|
||||
server = self._boot_server(image, flavor, **kwargs)
|
||||
address = network_wrapper.wrap(self.clients).create_floating_ip(
|
||||
tenant_id=server.tenant_id)
|
||||
address = network_wrapper.wrap(
|
||||
self.clients, self.context["task"]).create_floating_ip(
|
||||
tenant_id=server.tenant_id)
|
||||
self._associate_floating_ip(server, address["ip"])
|
||||
|
@ -128,7 +128,8 @@ class VMScenario(nova_utils.NovaScenario, cinder_utils.CinderScenario):
|
||||
internal_network = list(server.networks)[0]
|
||||
fixed_ip = server.addresses[internal_network][0]["addr"]
|
||||
|
||||
fip = network_wrapper.wrap(self.clients).create_floating_ip(
|
||||
fip = network_wrapper.wrap(self.clients,
|
||||
self.context["task"]).create_floating_ip(
|
||||
ext_network=floating_network,
|
||||
tenant_id=server.tenant_id, fixed_ip=fixed_ip)
|
||||
|
||||
@ -142,8 +143,10 @@ class VMScenario(nova_utils.NovaScenario, cinder_utils.CinderScenario):
|
||||
LOG, _("Unable to delete IP: %s") % fip["ip"]):
|
||||
if self.check_ip_address(fip["ip"])(server):
|
||||
self._dissociate_floating_ip(server, fip["ip"])
|
||||
network_wrapper.wrap(self.clients).delete_floating_ip(fip["id"],
|
||||
wait=True)
|
||||
network_wrapper.wrap(
|
||||
self.clients, self.context["task"]).delete_floating_ip(
|
||||
fip["id"],
|
||||
wait=True)
|
||||
|
||||
def _delete_server_with_fip(self, server, fip, force_delete=False):
|
||||
if fip["is_floating"]:
|
||||
|
@ -66,12 +66,13 @@ class NetworkWrapper(object):
|
||||
START_CIDR = "10.2.0.0/24"
|
||||
SERVICE_IMPL = None
|
||||
|
||||
def __init__(self, clients, config=None):
|
||||
def __init__(self, clients, task, config=None):
|
||||
if hasattr(clients, self.SERVICE_IMPL):
|
||||
self.client = getattr(clients, self.SERVICE_IMPL)()
|
||||
else:
|
||||
self.client = clients(self.SERVICE_IMPL)
|
||||
self.config = config or {}
|
||||
self.task = task
|
||||
self.start_cidr = self.config.get("start_cidr", self.START_CIDR)
|
||||
|
||||
@abc.abstractmethod
|
||||
@ -102,8 +103,8 @@ class NetworkWrapper(object):
|
||||
class NovaNetworkWrapper(NetworkWrapper):
|
||||
SERVICE_IMPL = consts.Service.NOVA
|
||||
|
||||
def __init__(self, *args):
|
||||
super(NovaNetworkWrapper, self).__init__(*args)
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(NovaNetworkWrapper, self).__init__(*args, **kwargs)
|
||||
self.skip_cidrs = [n.cidr for n in self.client.networks.list()]
|
||||
|
||||
def _generate_cidr(self):
|
||||
@ -441,7 +442,7 @@ class NeutronWrapper(NetworkWrapper):
|
||||
return False, _("Neutron driver does not support %s") % (extension)
|
||||
|
||||
|
||||
def wrap(clients, config=None):
|
||||
def wrap(clients, task, config=None):
|
||||
"""Returns available network wrapper instance.
|
||||
|
||||
:param clients: rally.osclients.Clients instance
|
||||
@ -454,5 +455,5 @@ def wrap(clients, config=None):
|
||||
services = clients("services")
|
||||
|
||||
if consts.Service.NEUTRON in services.values():
|
||||
return NeutronWrapper(clients, config)
|
||||
return NovaNetworkWrapper(clients, config)
|
||||
return NeutronWrapper(clients, task, config)
|
||||
return NovaNetworkWrapper(clients, task, config)
|
||||
|
@ -117,7 +117,7 @@ class UserGeneratorTestCase(test.ScenarioTestCase):
|
||||
|
||||
user_generator._remove_default_security_group()
|
||||
|
||||
mock_wrap.assert_called_once_with(admin_clients)
|
||||
mock_wrap.assert_called_once_with(admin_clients, self.context["task"])
|
||||
net_wrapper.supports_extension.assert_called_once_with(
|
||||
"security-group")
|
||||
|
||||
@ -147,7 +147,8 @@ class UserGeneratorTestCase(test.ScenarioTestCase):
|
||||
|
||||
user_generator._remove_default_security_group()
|
||||
|
||||
mock_network.wrap.assert_called_once_with(admin_clients)
|
||||
mock_network.wrap.assert_called_once_with(admin_clients,
|
||||
self.context["task"])
|
||||
|
||||
mock_iterate_per_tenants.assert_called_once_with(
|
||||
user_generator.context["users"])
|
||||
|
@ -125,7 +125,8 @@ class AllowSSHContextTestCase(test.TestCase):
|
||||
mock_clients.mock_calls)
|
||||
|
||||
mock_network_wrap.assert_called_once_with(
|
||||
mock_clients.return_value, {})
|
||||
mock_clients.return_value, self.ctx_with_secgroup["task"],
|
||||
config={})
|
||||
|
||||
@mock.patch("%s.osclients.Clients" % CTX)
|
||||
@mock.patch("rally.plugins.openstack.wrappers.network.wrap")
|
||||
@ -144,4 +145,5 @@ class AllowSSHContextTestCase(test.TestCase):
|
||||
mock_clients.assert_called_once_with("admin_endpoint")
|
||||
|
||||
mock_network_wrap.assert_called_once_with(
|
||||
mock_clients.return_value, {})
|
||||
mock_clients.return_value, self.ctx_without_secgroup["task"],
|
||||
config={})
|
||||
|
@ -63,8 +63,10 @@ class ExistingNetworkTestCase(test.TestCase):
|
||||
mock_clients.assert_has_calls([
|
||||
mock.call(u["endpoint"]) for u in self.context["users"]])
|
||||
mock_network_wrap.assert_has_calls([
|
||||
mock.call(mock_clients.return_value, self.config),
|
||||
mock.call(mock_clients.return_value, self.config)])
|
||||
mock.call(mock_clients.return_value, self.context["task"],
|
||||
config=self.config),
|
||||
mock.call(mock_clients.return_value, self.context["task"],
|
||||
config=self.config)])
|
||||
for net_wrapper in net_wrappers.values():
|
||||
net_wrapper.list_networks.assert_called_once_with()
|
||||
|
||||
|
@ -281,7 +281,8 @@ class VMScenarioTestCase(test.ScenarioTestCase):
|
||||
scenario._attach_floating_ip(
|
||||
server, floating_network="bar_network")
|
||||
|
||||
mock_wrap.assert_called_once_with(scenario.clients)
|
||||
mock_wrap.assert_called_once_with(scenario.clients,
|
||||
self.context["task"])
|
||||
netwrap.create_floating_ip.assert_called_once_with(
|
||||
ext_network="bar_network",
|
||||
tenant_id="foo_tenant", fixed_ip="foo_ip")
|
||||
@ -305,6 +306,7 @@ class VMScenarioTestCase(test.ScenarioTestCase):
|
||||
_check_addr.assert_called_once_with(server)
|
||||
scenario._dissociate_floating_ip.assert_called_once_with(
|
||||
server, "foo_ip")
|
||||
mock_wrap.assert_called_once_with(scenario.clients)
|
||||
mock_wrap.assert_called_once_with(scenario.clients,
|
||||
self.context["task"])
|
||||
mock_wrap.return_value.delete_floating_ip.assert_called_once_with(
|
||||
"foo_id", wait=True)
|
||||
|
@ -38,7 +38,9 @@ class NovaNetworkWrapperTestCase(test.TestCase):
|
||||
mock_clients = mock.Mock()
|
||||
mock_clients.nova.return_value.networks.list.return_value = [
|
||||
self.Net(cidr=cidr) for cidr in skip_cidrs]
|
||||
return network.NovaNetworkWrapper(mock_clients, kwargs)
|
||||
return network.NovaNetworkWrapper(mock_clients,
|
||||
test.get_test_context()["task"],
|
||||
config=kwargs)
|
||||
|
||||
def test__init__(self):
|
||||
skip_cidrs = ["foo_cidr", "bar_cidr"]
|
||||
@ -164,7 +166,9 @@ class NovaNetworkWrapperTestCase(test.TestCase):
|
||||
|
||||
class NeutronWrapperTestCase(test.TestCase):
|
||||
def get_wrapper(self, *skip_cidrs, **kwargs):
|
||||
return network.NeutronWrapper(mock.Mock(), kwargs)
|
||||
return network.NeutronWrapper(mock.Mock(),
|
||||
test.get_test_context()["task"],
|
||||
config=kwargs)
|
||||
|
||||
def test_SUBNET_IP_VERSION(self):
|
||||
self.assertEqual(network.NeutronWrapper.SUBNET_IP_VERSION, 4)
|
||||
@ -543,11 +547,17 @@ class FunctionsTestCase(test.TestCase):
|
||||
def test_wrap(self):
|
||||
mock_clients = mock.Mock()
|
||||
mock_clients.nova().networks.list.return_value = []
|
||||
config = {"fakearg": "fake"}
|
||||
task = {"task": "fake_task_uuid"}
|
||||
|
||||
mock_clients.services.return_value = {"foo": consts.Service.NEUTRON}
|
||||
self.assertIsInstance(network.wrap(mock_clients, {}),
|
||||
network.NeutronWrapper)
|
||||
wrapper = network.wrap(mock_clients, task, config)
|
||||
self.assertIsInstance(wrapper, network.NeutronWrapper)
|
||||
self.assertEqual(wrapper.task, task)
|
||||
self.assertEqual(wrapper.config, config)
|
||||
|
||||
mock_clients.services.return_value = {"foo": "bar"}
|
||||
self.assertIsInstance(network.wrap(mock_clients, {}),
|
||||
network.NovaNetworkWrapper)
|
||||
wrapper = network.wrap(mock_clients, task, config)
|
||||
self.assertIsInstance(wrapper, network.NovaNetworkWrapper)
|
||||
self.assertEqual(wrapper.task, task)
|
||||
self.assertEqual(wrapper.config, config)
|
||||
|
Loading…
x
Reference in New Issue
Block a user