Use Network Context in security groups scenario
This patch replaces code that creates networking resources in NovaSecGroup.boot_and_delete_server_with_secgroups with usage of our new Network Context. Change-Id: I9e63256d409978763ee3bb9bf0d896313ba6dec9
This commit is contained in:
parent
f72bc702a0
commit
15b058c3cf
@ -20,6 +20,9 @@
|
||||
"users": {
|
||||
"tenants": 3,
|
||||
"users_per_tenant": 2
|
||||
},
|
||||
"network": {
|
||||
"start_cidr": "100.1.0.0/26"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,3 +16,5 @@
|
||||
users:
|
||||
tenants: 3
|
||||
users_per_tenant: 2
|
||||
network:
|
||||
start_cidr: "100.1.0.0/26"
|
||||
|
@ -560,6 +560,8 @@
|
||||
users:
|
||||
tenants: 3
|
||||
users_per_tenant: 2
|
||||
network:
|
||||
start_cidr: "100.1.0.0/26"
|
||||
quotas:
|
||||
neutron:
|
||||
security_group: -1
|
||||
|
@ -1270,6 +1270,8 @@
|
||||
users:
|
||||
tenants: 3
|
||||
users_per_tenant: 2
|
||||
network:
|
||||
start_cidr: "100.1.0.0/26"
|
||||
quotas:
|
||||
nova:
|
||||
security_groups: -1
|
||||
|
@ -14,7 +14,6 @@
|
||||
# under the License.
|
||||
|
||||
from rally.benchmark.scenarios import base
|
||||
from rally.benchmark.scenarios.neutron import utils as neutron_utils
|
||||
from rally.benchmark.scenarios.nova import utils
|
||||
from rally.benchmark import types
|
||||
from rally.benchmark import validation
|
||||
@ -27,28 +26,6 @@ class NovaSecurityGroupException(exceptions.RallyException):
|
||||
msg_fmt = _("%(message)s")
|
||||
|
||||
|
||||
# FIXME(akurilin): remove this wrapper, when NetworkContext will be finished
|
||||
class NeutronNetwork(neutron_utils.NeutronScenario):
|
||||
# NOTE(akurilin): NovaSecGroup scenarios should work for both environment
|
||||
# (nova-network and neutron), but no security groups will be attached to
|
||||
# vm in neutron environment, if tenant doesn't have at least one network.
|
||||
def __init__(self, clients, context):
|
||||
super(NeutronNetwork, self).__init__(context=context, clients=clients)
|
||||
|
||||
def __enter__(self):
|
||||
if consts.Service.NEUTRON in self.clients("services").values():
|
||||
self._net, subnet = self._create_network_and_subnets(
|
||||
network_create_args=None, subnet_create_args=None,
|
||||
subnets_per_network=1, subnet_cidr_start=None)
|
||||
return {"nics": [{"net-id": self._net["network"]["id"]}]}
|
||||
return {}
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
if (consts.Service.NEUTRON in self.clients("services").values() and
|
||||
hasattr(self, "_net")):
|
||||
self._delete_network(self._net["network"])
|
||||
|
||||
|
||||
class NovaSecGroup(utils.NovaScenario):
|
||||
|
||||
RESOURCE_NAME_PREFIX = "rally_novasecgrp_"
|
||||
@ -105,6 +82,7 @@ class NovaSecGroup(utils.NovaScenario):
|
||||
@validation.image_valid_on_flavor("flavor", "image")
|
||||
@validation.required_parameters("security_group_count",
|
||||
"rules_per_security_group")
|
||||
@validation.required_contexts("network")
|
||||
@validation.required_services(consts.Service.NOVA)
|
||||
@validation.required_openstack(users=True)
|
||||
@base.scenario(context={"cleanup": ["nova"]})
|
||||
@ -115,13 +93,11 @@ class NovaSecGroup(utils.NovaScenario):
|
||||
|
||||
Plan of this scenario:
|
||||
- create N security groups with M rules per group
|
||||
- [neutron-specific]: create network with 1 subnet(required to boot
|
||||
vm with security groups)
|
||||
- boot a VM with created security groups
|
||||
- get list of attached security groups to server
|
||||
- delete server
|
||||
- delete all security groups
|
||||
- [neutron-specific]: delete created network
|
||||
- check that all groups were attached to server
|
||||
|
||||
:param image: ID of the image to be used for server creation
|
||||
@ -135,23 +111,21 @@ class NovaSecGroup(utils.NovaScenario):
|
||||
self._create_rules_for_security_group(security_groups,
|
||||
rules_per_security_group)
|
||||
|
||||
boot_kwargs = {"security_groups": [sg.name for sg in security_groups]}
|
||||
with NeutronNetwork(self._clients, self.context) as net_kwargs:
|
||||
boot_kwargs.update(net_kwargs)
|
||||
server = self._boot_server(self._generate_random_name(),
|
||||
image, flavor, **boot_kwargs)
|
||||
secgroups_names = [sg.name for sg in security_groups]
|
||||
server = self._boot_server(self._generate_random_name(), image,
|
||||
flavor, security_groups=secgroups_names)
|
||||
|
||||
action_name = "nova.get_attached_security_groups"
|
||||
with base.AtomicAction(self, action_name):
|
||||
attached_security_groups = server.list_security_group()
|
||||
action_name = "nova.get_attached_security_groups"
|
||||
with base.AtomicAction(self, action_name):
|
||||
attached_security_groups = server.list_security_group()
|
||||
|
||||
self._delete_server(server)
|
||||
try:
|
||||
self._delete_security_groups(security_groups)
|
||||
except Exception as e:
|
||||
if hasattr(e, "http_status") and e.http_status == 400:
|
||||
raise NovaSecurityGroupException(e.message)
|
||||
raise
|
||||
self._delete_server(server)
|
||||
try:
|
||||
self._delete_security_groups(security_groups)
|
||||
except Exception as e:
|
||||
if hasattr(e, "http_status") and e.http_status == 400:
|
||||
raise NovaSecurityGroupException(e.message)
|
||||
raise
|
||||
|
||||
if sorted([sg.id for sg in security_groups]) != sorted(
|
||||
[sg.id for sg in attached_security_groups]):
|
||||
|
@ -16,7 +16,6 @@
|
||||
import mock
|
||||
|
||||
from rally.benchmark.scenarios.nova import security_group
|
||||
from rally import consts
|
||||
from tests.unit import fakes
|
||||
from tests.unit import test
|
||||
|
||||
@ -86,9 +85,7 @@ class NovaSecurityGroupTestCase(test.TestCase):
|
||||
return mock.MagicMock(
|
||||
list_security_group=mock.MagicMock(return_value=sg_list)), sg_list
|
||||
|
||||
@mock.patch("%s.NeutronContext" % SECGROUP, new=FakeNeutronScenario)
|
||||
def _test_boot_and_delete_server_with_secgroups(self,
|
||||
mock_neutron_context):
|
||||
def _test_boot_and_delete_server_with_secgroups(self):
|
||||
fake_server, sg_list = self._generate_fake_server_with_sg(2)
|
||||
|
||||
nova_scenario = security_group.NovaSecGroup()
|
||||
@ -108,7 +105,6 @@ class NovaSecurityGroupTestCase(test.TestCase):
|
||||
|
||||
nova_scenario.boot_and_delete_server_with_secgroups(
|
||||
image, flavor, security_group_count, rules_per_security_group)
|
||||
|
||||
nova_scenario._create_security_groups.assert_called_once_with(
|
||||
security_group_count)
|
||||
self.assertEqual(1, nova_scenario._generate_random_name.call_count)
|
||||
@ -121,9 +117,7 @@ class NovaSecurityGroupTestCase(test.TestCase):
|
||||
nova_scenario._delete_server.assert_called_once_with(fake_server)
|
||||
nova_scenario._delete_security_groups.assert_called_once_with(sg_list)
|
||||
|
||||
@mock.patch("%s.NeutronContext" % SECGROUP, new=FakeNeutronScenario)
|
||||
def _test_boot_and_delete_server_with_sg_not_attached(
|
||||
self, mock_neutron_context):
|
||||
def _test_boot_and_delete_server_with_sg_not_attached(self):
|
||||
fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1"),
|
||||
fakes.FakeSecurityGroup(None, None, 2, "uuid2")]
|
||||
|
||||
@ -161,39 +155,3 @@ class NovaSecurityGroupTestCase(test.TestCase):
|
||||
nova_scenario._delete_server.assert_called_once_with(fake_server)
|
||||
nova_scenario._delete_security_groups.assert_called_once_with(
|
||||
fake_secgroups)
|
||||
|
||||
|
||||
class NeutronNetworkTestCase(test.TestCase):
|
||||
@mock.patch("%s.NeutronNetwork._delete_network" % SECGROUP)
|
||||
@mock.patch("%s.NeutronNetwork._create_network_and_subnets" % SECGROUP)
|
||||
@mock.patch("%s.NeutronNetwork.clients" % SECGROUP)
|
||||
def test_neutron_is_enabled(self, mock_clients, mock_create_net,
|
||||
mock_delete_net):
|
||||
fake_net = {"network": {"id": "fake_id"}}
|
||||
mock_create_net.return_value = (fake_net, None)
|
||||
mock_clients.return_value = {
|
||||
consts.ServiceType.NETWORK: consts.Service.NEUTRON}
|
||||
|
||||
with security_group.NeutronNetwork(None, None) as boot_kwargs:
|
||||
self.assertEqual({"nics": [{"net-id": fake_net["network"]["id"]}]},
|
||||
boot_kwargs)
|
||||
|
||||
self.assertEqual(2, mock_clients.call_count)
|
||||
mock_create_net.assert_called_once_with(network_create_args=None,
|
||||
subnet_create_args=None,
|
||||
subnets_per_network=1,
|
||||
subnet_cidr_start=None)
|
||||
mock_delete_net.assert_called_once_with(fake_net["network"])
|
||||
|
||||
@mock.patch("%s.NeutronNetwork._delete_network" % SECGROUP)
|
||||
@mock.patch("%s.NeutronNetwork._create_network_and_subnets" % SECGROUP)
|
||||
@mock.patch("%s.NeutronNetwork.clients" % SECGROUP, return_value={})
|
||||
def test_neutron_is_disabled(self, mock_clients, mock_create_net,
|
||||
mock_delete_net):
|
||||
|
||||
with security_group.NeutronNetwork(None, None) as boot_kwargs:
|
||||
self.assertEqual({}, boot_kwargs)
|
||||
|
||||
self.assertEqual(2, mock_clients.call_count)
|
||||
self.assertFalse(mock_create_net.called)
|
||||
self.assertFalse(mock_delete_net.called)
|
||||
|
Loading…
x
Reference in New Issue
Block a user