From 1e06631d947a25589981b04acb221b2e4870dc2c Mon Sep 17 00:00:00 2001 From: armando-migliaccio Date: Wed, 8 Apr 2015 12:50:19 -0700 Subject: [PATCH] Update L3 Agent Scheduler API tests Changes [1,2] recently merged in temptest. Change [2] in particular is required if we run the API tests with DVR enabled, because now the binding logic has been altered by [3]. This patch ensure that should that happen, the API job doesn't fail. [1] https://review.openstack.org/#/c/169895/ [2] https://review.openstack.org/#/c/165246/ [3] https://review.openstack.org/#/c/154289/ Change-Id: Iead1b90030098139090ae6ad4b77f50068817083 --- .../api/admin/test_l3_agent_scheduler.py | 55 ++++++++++++++----- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/neutron/tests/api/admin/test_l3_agent_scheduler.py b/neutron/tests/api/admin/test_l3_agent_scheduler.py index 2d077675e..8dfda7e64 100644 --- a/neutron/tests/api/admin/test_l3_agent_scheduler.py +++ b/neutron/tests/api/admin/test_l3_agent_scheduler.py @@ -15,10 +15,18 @@ from tempest_lib.common.utils import data_utils from neutron.tests.api import base +from neutron.tests.tempest import exceptions from neutron.tests.tempest import test +AGENT_TYPE = 'L3 agent' +AGENT_MODES = ( + 'legacy', + 'dvr_snat' +) + class L3AgentSchedulerTestJSON(base.BaseAdminNetworkTest): + _agent_mode = 'legacy' """ Tests the following operations in the Neutron API using the REST client for @@ -34,21 +42,44 @@ class L3AgentSchedulerTestJSON(base.BaseAdminNetworkTest): """ @classmethod - def resource_setup(cls): - super(L3AgentSchedulerTestJSON, cls).resource_setup() + def skip_checks(cls): + super(L3AgentSchedulerTestJSON, cls).skip_checks() if not test.is_extension_enabled('l3_agent_scheduler', 'network'): msg = "L3 Agent Scheduler Extension not enabled." raise cls.skipException(msg) - # Trying to get agent details for L3 Agent + + @classmethod + def resource_setup(cls): + super(L3AgentSchedulerTestJSON, cls).resource_setup() body = cls.admin_client.list_agents() agents = body['agents'] for agent in agents: - if agent['agent_type'] == 'L3 agent': + # TODO(armax): falling back on default _agent_mode can be + # dropped as soon as Icehouse is dropped. + agent_mode = ( + agent['configurations'].get('agent_mode', cls._agent_mode)) + if agent['agent_type'] == AGENT_TYPE and agent_mode in AGENT_MODES: cls.agent = agent break else: - msg = "L3 Agent not found" - raise cls.skipException(msg) + msg = "L3 Agent Scheduler enabled in conf, but L3 Agent not found" + raise exceptions.InvalidConfiguration(msg) + cls.router = cls.create_router(data_utils.rand_name('router')) + # NOTE(armax): If DVR is an available extension, and the created router + # is indeed a distributed one, more resources need to be provisioned + # in order to bind the router to the L3 agent. + # That said, let's preserve the existing test logic, where the extra + # query and setup steps are only required if the extension is available + # and only if the router's default type is distributed. + if test.is_extension_enabled('dvr', 'network'): + is_dvr_router = cls.admin_client.show_router( + cls.router['id'])['router'].get('distributed', False) + if is_dvr_router: + cls.network = cls.create_network() + cls.create_subnet(cls.network) + cls.port = cls.create_port(cls.network) + cls.client.add_router_interface_with_port_id( + cls.router['id'], cls.port['id']) @test.attr(type='smoke') @test.idempotent_id('b7ce6e89-e837-4ded-9b78-9ed3c9c6a45a') @@ -59,22 +90,18 @@ class L3AgentSchedulerTestJSON(base.BaseAdminNetworkTest): @test.idempotent_id('9464e5e7-8625-49c3-8fd1-89c52be59d66') def test_add_list_remove_router_on_l3_agent(self): l3_agent_ids = list() - name = data_utils.rand_name('router1-') - router = self.client.create_router(name) - self.addCleanup(self.client.delete_router, router['router']['id']) self.admin_client.add_router_to_l3_agent( self.agent['id'], - router['router']['id']) - body = self.admin_client.list_l3_agents_hosting_router( - router['router']['id']) + self.router['id']) + body = ( + self.admin_client.list_l3_agents_hosting_router(self.router['id'])) for agent in body['agents']: l3_agent_ids.append(agent['id']) self.assertIn('agent_type', agent) self.assertEqual('L3 agent', agent['agent_type']) self.assertIn(self.agent['id'], l3_agent_ids) - del l3_agent_ids[:] body = self.admin_client.remove_router_from_l3_agent( self.agent['id'], - router['router']['id']) + self.router['id']) # NOTE(afazekas): The deletion not asserted, because neutron # is not forbidden to reschedule the router to the same agent -- 2.45.2