Merge "Add create and delete routers scenarios for Neutron"

This commit is contained in:
Jenkins 2015-02-17 10:31:52 +00:00 committed by Gerrit Code Review
commit 7f468d8389
7 changed files with 245 additions and 0 deletions

View File

@ -275,6 +275,31 @@
failure_rate:
max: 0
NeutronNetworks.create_and_delete_routers:
-
args:
network_create_args: {}
subnet_create_args: {}
subnet_cidr_start: "1.1.0.0/30"
subnets_per_network: 2
router_create_args: {}
runner:
type: "constant"
times: 30
concurrency: 10
context:
users:
tenants: 1
users_per_tenant: 1
quotas:
neutron:
network: -1
subnet: -1
router: -1
sla:
failure_rate:
max: 0
NeutronNetworks.create_and_delete_ports:
-
args:

View File

@ -223,6 +223,48 @@ class NeutronNetworks(utils.NeutronScenario):
{"subnet_id": subnet["subnet"]["id"]})
self._update_router(router, router_update_args)
@base.scenario(context={"cleanup": ["neutron"]})
@validation.required_parameters("subnets_per_network")
@validation.required_services(consts.Service.NEUTRON)
def create_and_delete_routers(self,
network_create_args=None,
subnet_create_args=None,
subnet_cidr_start=None,
subnets_per_network=None,
router_create_args=None):
"""Create and delete a given number of routers.
Create a network, a given number of subnets and routers
and then delete all routers.
:param network_create_args: dict, POST /v2.0/networks request options
:param subnet_create_args: dict, POST /v2.0/subnets request options
:param subnet_cidr_start: str, start value for subnets CIDR
:param subnets_per_network: int, number of subnets for one network
:param router_create_args: dict, POST /v2.0/routers request options
"""
network, subnets = self._create_network_and_subnets(
network_create_args or {},
subnet_create_args or {},
subnets_per_network,
subnet_cidr_start)
routers = []
for subnet in subnets:
router = self._create_router(router_create_args or {})
self.clients("neutron").add_interface_router(
router["router"]["id"],
{"subnet_id": subnet["subnet"]["id"]})
routers.append(router)
for e in range(subnets_per_network):
router = routers[e]
subnet = subnets[e]
self.clients("neutron").remove_interface_router(
router["router"]["id"],
{"subnet_id": subnet["subnet"]["id"]})
self._delete_router(router)
@validation.number("ports_per_network", minval=1, integer_only=True)
@validation.required_services(consts.Service.NEUTRON)
@validation.required_openstack(users=True)

View File

@ -162,6 +162,14 @@ class NeutronScenario(base.Scenario):
"""Returns user routers list."""
return self.clients("neutron").list_routers()["routers"]
@base.atomic_action_timer("neutron.delete_router")
def _delete_router(self, router):
"""Delete neutron router
:param router: Router object
"""
self.clients("neutron").delete_router(router["router"]["id"])
@base.atomic_action_timer("neutron.update_router")
def _update_router(self, router, router_update_args):
"""Update the neutron router name and admin state.
@ -269,3 +277,13 @@ class NeutronScenario(base.Scenario):
"""
self.clients("neutron").add_interface_router(
router["id"], {"subnet_id": subnet["id"]})
@base.atomic_action_timer("neutron.remove_interface_router")
def _remove_interface_router(self, subnet, router):
"""Remove subnet from router
:param subnet: dict, neutron subnet
:param router: dict, neutron router
"""
self.clients("neutron").remove_interface_router(
router["id"], {"subnet_id": subnet["id"]})

View File

@ -0,0 +1,31 @@
{
"NeutronNetworks.create_and_delete_routers": [
{
"args": {
"network_create_args": {},
"subnet_create_args": {},
"subnet_cidr_start": "1.1.0.0/30",
"subnets_per_network": 2,
"router_create_args": {}
},
"runner": {
"type": "constant",
"times": 30,
"concurrency": 10
},
"context": {
"users": {
"tenants": 1,
"users_per_tenant": 1
},
"quotas": {
"neutron": {
"network": -1,
"subnet": -1,
"router": -1
}
}
}
}
]
}

View File

@ -0,0 +1,22 @@
---
NeutronNetworks.create_and_delete_routers:
-
args:
network_create_args: {}
subnet_create_args: {}
subnet_cidr_start: "1.1.0.0/30"
subnets_per_network: 2
router_create_args: {}
runner:
type: "constant"
times: 30
concurrency: 10
context:
users:
tenants: 1
users_per_tenant: 1
quotas:
neutron:
network: -1
subnet: -1
router: -1

View File

@ -413,6 +413,89 @@ class NeutronNetworksTestCase(test.TestCase):
[mock.call(router, router_update_args)
] * subnets_per_network)
@mock.patch(NEUTRON_NETWORKS + "._delete_router")
@mock.patch(NEUTRON_NETWORKS + "._create_router")
@mock.patch(NEUTRON_NETWORKS + "._create_network_and_subnets")
@mock.patch(NEUTRON_NETWORKS + ".clients")
def test_create_and_delete_routers(self,
mock_clients,
mock_create_network_and_subnets,
mock_create_router,
mock_delete_router):
scenario = network.NeutronNetworks()
subnets_per_network = 1
subnet_cidr_start = "default_cidr"
net = {
"network": {
"id": "network-id"
}
}
subnet = {
"subnet": {
"name": "subnet-name",
"id": "subnet-id",
"enable_dhcp": False
}
}
router = {
"router": {
"name": "router-name",
"id": "router-id"
}
}
mock_create_router.return_value = router
mock_create_network_and_subnets.return_value = (net, [subnet])
mock_clients("neutron").add_interface_router = mock.Mock()
# Default options
scenario.create_and_delete_routers(
subnet_cidr_start=subnet_cidr_start,
subnets_per_network=subnets_per_network)
mock_create_network_and_subnets.assert_has_calls(
[mock.call({}, {}, subnets_per_network, subnet_cidr_start)])
mock_create_router.assert_has_calls(
[mock.call({})] * subnets_per_network)
mock_clients("neutron").add_interface_router.assert_has_calls(
[mock.call(router["router"]["id"],
{"subnet_id": subnet["subnet"]["id"]})
] * subnets_per_network)
mock_delete_router.assert_has_calls(
[mock.call(router)] * subnets_per_network)
mock_create_network_and_subnets.reset_mock()
mock_create_router.reset_mock()
mock_clients("neutron").add_interface_router.reset_mock()
mock_delete_router.reset_mock()
# Custom options
subnet_cidr_start = "custom_cidr"
subnet_create_args = {"allocation_pools": []}
router_create_args = {"admin_state_up": False}
scenario.create_and_delete_routers(
subnet_create_args=subnet_create_args,
subnet_cidr_start="custom_cidr",
subnets_per_network=subnets_per_network,
router_create_args=router_create_args)
mock_create_network_and_subnets.assert_has_calls(
[mock.call({}, subnet_create_args, subnets_per_network,
subnet_cidr_start)])
mock_create_router.assert_has_calls(
[mock.call(router_create_args)] * subnets_per_network)
mock_clients("neutron").add_interface_router.assert_has_calls(
[mock.call(router["router"]["id"],
{"subnet_id": subnet["subnet"]["id"]})
] * subnets_per_network)
mock_delete_router.assert_has_calls(
[mock.call(router)] * subnets_per_network)
@mock.patch(NEUTRON_NETWORKS + "._generate_random_name")
@mock.patch(NEUTRON_NETWORKS + "._list_ports")
@mock.patch(NEUTRON_NETWORKS + "._create_port")

View File

@ -242,6 +242,30 @@ class NeutronScenarioTestCase(test.TestCase):
self._test_atomic_action_timer(scenario.atomic_actions(),
"neutron.update_router")
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
def test_delete_router(self, mock_clients):
scenario = utils.NeutronScenario()
router = scenario._create_router({})
scenario._delete_router(router)
mock_clients("neutron").delete_router.assert_called_once_with(
router["router"]["id"])
self._test_atomic_action_timer(scenario.atomic_actions(),
"neutron.delete_router")
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
def test_remove_interface_router(self, mock_clients):
subnet = {"name": "subnet-name", "id": "subnet-id"}
router_data = {"id": 1}
scenario = utils.NeutronScenario()
router = scenario._create_router(router_data)
scenario._add_interface_router(subnet, router)
scenario._remove_interface_router(subnet, router)
mock_remove_router = mock_clients("neutron").remove_interface_router
mock_remove_router.assert_called_once_with(
router["id"], {"subnet_id": subnet["id"]})
self._test_atomic_action_timer(scenario.atomic_actions(),
"neutron.remove_interface_router")
def test_SUBNET_IP_VERSION(self):
"""Curent NeutronScenario implementation supports only IPv4."""
self.assertEqual(utils.NeutronScenario.SUBNET_IP_VERSION, 4)