From 6045379feb1ef87edac417f25c2570b8e75a6961 Mon Sep 17 00:00:00 2001 From: maxinjian Date: Thu, 20 Oct 2016 03:42:59 -0400 Subject: [PATCH] Add NeutronNetworks.list_agents List all neutron agents. This simple scenario tests the "neutron agent-list" command by listing all the neutron agents. Change-Id: I96c1ba7b2be085f5436c5fa4ae85959b3e60b99d --- rally-jobs/rally-neutron.yaml | 16 ++++++++++++ .../openstack/scenarios/neutron/network.py | 19 +++++++++++++- .../openstack/scenarios/neutron/utils.py | 9 +++++++ .../tasks/scenarios/neutron/list-agents.json | 25 +++++++++++++++++++ .../tasks/scenarios/neutron/list-agents.yaml | 16 ++++++++++++ .../scenarios/neutron/test_network.py | 11 ++++++++ .../openstack/scenarios/neutron/test_utils.py | 8 ++++++ 7 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 samples/tasks/scenarios/neutron/list-agents.json create mode 100644 samples/tasks/scenarios/neutron/list-agents.yaml diff --git a/rally-jobs/rally-neutron.yaml b/rally-jobs/rally-neutron.yaml index 93bd3e9fda..7c4f3e76bd 100644 --- a/rally-jobs/rally-neutron.yaml +++ b/rally-jobs/rally-neutron.yaml @@ -174,6 +174,22 @@ failure_rate: max: 20 + NeutronNetworks.list_agents: + - + args: + agent_args: {} + runner: + type: "constant" + times: {{smoke or 10}} + concurrency: {{smoke or 3}} + context: + users: + tenants: {{smoke or 3}} + users_per_tenant: {{smoke or 2}} + sla: + failure_rate: + max: 0 + NeutronNetworks.create_and_update_networks: - args: diff --git a/rally/plugins/openstack/scenarios/neutron/network.py b/rally/plugins/openstack/scenarios/neutron/network.py index 4357cd158c..1ea2d5cb3c 100644 --- a/rally/plugins/openstack/scenarios/neutron/network.py +++ b/rally/plugins/openstack/scenarios/neutron/network.py @@ -367,4 +367,21 @@ class CreateAndDeleteFloatingIps(utils.NeutronScenario): floating_ip_args = floating_ip_args or {} floating_ip = self._create_floatingip(floating_network, **floating_ip_args) - self._delete_floating_ip(floating_ip["floatingip"]) \ No newline at end of file + self._delete_floating_ip(floating_ip["floatingip"]) + + +@validation.required_services(consts.Service.NEUTRON) +@validation.required_openstack(users=True) +@scenario.configure(name="NeutronNetworks.list_agents") +class ListAgents(utils.NeutronScenario): + + def run(self, agent_args=None): + """List all neutron agents. + + This simple scenario tests the "neutron agent-list" command by + listing all the neutron agents. + + :param agent_args: dict, POST /v2.0/agents request options + """ + agent_args = agent_args or {} + self._list_agents(**agent_args) diff --git a/rally/plugins/openstack/scenarios/neutron/utils.py b/rally/plugins/openstack/scenarios/neutron/utils.py index 3fab8a3780..8321f79e47 100644 --- a/rally/plugins/openstack/scenarios/neutron/utils.py +++ b/rally/plugins/openstack/scenarios/neutron/utils.py @@ -74,6 +74,15 @@ class NeutronScenario(scenario.OpenStackScenario): """ return self.clients("neutron").list_networks(**kwargs)["networks"] + @atomic.action_timer("neutron.list_agents") + def _list_agents(self, **kwargs): + """Fetches agents. + + :param kwargs: neutron agent list options + :returns: user agents list + """ + return self.clients("neutron").list_agents(**kwargs)["agents"] + @atomic.action_timer("neutron.update_network") def _update_network(self, network, network_update_args): """Update the network. diff --git a/samples/tasks/scenarios/neutron/list-agents.json b/samples/tasks/scenarios/neutron/list-agents.json new file mode 100644 index 0000000000..e9fbcb6bef --- /dev/null +++ b/samples/tasks/scenarios/neutron/list-agents.json @@ -0,0 +1,25 @@ +{ + "NeutronNetworks.list_agents": [ + { + "args": { + "agent_args": {} + }, + "runner": { + "type": "constant", + "times": 10, + "concurrency": 2 + }, + "context": { + "users": { + "tenants": 2, + "users_per_tenant": 3 + } + }, + "sla": { + "failure_rate": { + "max": 0 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/neutron/list-agents.yaml b/samples/tasks/scenarios/neutron/list-agents.yaml new file mode 100644 index 0000000000..b1d15cb0bf --- /dev/null +++ b/samples/tasks/scenarios/neutron/list-agents.yaml @@ -0,0 +1,16 @@ +--- + NeutronNetworks.list_agents: + - + args: + agent_args: {} + runner: + type: "constant" + times: 10 + concurrency: 2 + context: + users: + tenants: 2 + users_per_tenant: 3 + sla: + failure_rate: + max: 0 diff --git a/tests/unit/plugins/openstack/scenarios/neutron/test_network.py b/tests/unit/plugins/openstack/scenarios/neutron/test_network.py index 47348ee76d..9b3abc1cb6 100644 --- a/tests/unit/plugins/openstack/scenarios/neutron/test_network.py +++ b/tests/unit/plugins/openstack/scenarios/neutron/test_network.py @@ -209,6 +209,17 @@ class NeutronNetworksTestCase(test.ScenarioTestCase): subnets_per_network, router_create_args) scenario._list_routers.assert_called_once_with() + def test_list_agents(self): + agent_args = { + "F": "id", + "sort-dir": "asc" + } + scenario = network.ListAgents(self.context) + scenario._list_agents = mock.Mock() + + scenario.run(agent_args=agent_args) + scenario._list_agents.assert_called_once_with(**agent_args) + def test_create_and_update_routers(self): router_update_args = {"admin_state_up": False} network_create_args = {"router:external": True} diff --git a/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py b/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py index f6c791da46..d66fe87221 100644 --- a/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py @@ -270,6 +270,14 @@ class NeutronScenarioTestCase(test.ScenarioTestCase): self._test_atomic_action_timer(self.scenario.atomic_actions(), "neutron.list_routers") + def test_list_agents(self): + agents = [mock.Mock()] + self.clients("neutron").list_agents.return_value = { + "agents": agents} + self.assertEqual(agents, self.scenario._list_agents()) + self._test_atomic_action_timer(self.scenario.atomic_actions(), + "neutron.list_agents") + def test_update_router(self): expected_router = { "router": {