]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add EnvironmentDescription, pass it down
authorJohn Schwarz <jschwarz@redhat.com>
Sun, 9 Aug 2015 14:00:57 +0000 (17:00 +0300)
committerJohn Schwarz <jschwarz@redhat.com>
Thu, 20 Aug 2015 12:34:25 +0000 (15:34 +0300)
* The EnvironmentDescription class describes an entire fullstack
  environment (as opposed to the currently implemented host-only
  descriptions). This will allow future patches to signify that a test
  should set up an environment that supports tunneling, l2pop, QoS and
  more.
* Now, most fullstack fixtures (config and process ones, at least),
  expect both the EnvironmentDescription for the current test and the
  HostDescription for the 'host' the config/process is on. This allows
  for easier and most robust future changes, as now adding a new
  parameter to one of the description objects doesn't mean adding that
  argument to a number of other objects which are using it.
* Changed HostDescription's default argument of l3_agent to False, since
  adding new configurations and defualting them to True forces the
  author to go through ALL the tests and explicitly turn them on/off.
  However, defaulting new configurations to False only requires
  explicitly turning them on, which we ought to do anyway.

Change-Id: Ib2f12016ba4371bfda76c82e11d0794acc759955

neutron/tests/fullstack/base.py
neutron/tests/fullstack/resources/config.py
neutron/tests/fullstack/resources/environment.py
neutron/tests/fullstack/resources/process.py
neutron/tests/fullstack/test_connectivity.py
neutron/tests/fullstack/test_l3_agent.py

index 579831524f0f34da44c605ad5c73dcc279ecfe41..012ace848c33abcd90d69b6546bc554d69ab0791 100644 (file)
@@ -24,17 +24,12 @@ from neutron.tests.fullstack.resources import client as client_resource
 class BaseFullStackTestCase(base.MySQLTestCase):
     """Base test class for full-stack tests."""
 
-    def __init__(self, environment, *args, **kwargs):
-        super(BaseFullStackTestCase, self).__init__(*args, **kwargs)
-        self.environment = environment
-
-    def setUp(self):
+    def setUp(self, environment):
         super(BaseFullStackTestCase, self).setUp()
         self.create_db_tables()
-
+        self.environment = environment
         self.environment.test_name = self.get_name()
         self.useFixture(self.environment)
-
         self.client = self.environment.neutron_server.client
         self.safe_client = self.useFixture(
             client_resource.ClientFixture(self.client))
index 21df3e1aa462d8ded7eb9f325ce3a4bcf84643ac..9848e2c2f0d6fb7064152e52bd5c019da3df82cd 100644 (file)
@@ -81,9 +81,11 @@ class ConfigFixture(fixtures.Fixture):
     then the dynamic configuration values won't change. The correct usage
     is initializing a new instance of the class.
     """
-    def __init__(self, temp_dir, base_filename):
+    def __init__(self, env_desc, host_desc, temp_dir, base_filename):
         super(ConfigFixture, self).__init__()
         self.config = ConfigDict()
+        self.env_desc = env_desc
+        self.host_desc = host_desc
         self.temp_dir = temp_dir
         self.base_filename = base_filename
 
@@ -96,14 +98,15 @@ class ConfigFixture(fixtures.Fixture):
 
 class NeutronConfigFixture(ConfigFixture):
 
-    def __init__(self, temp_dir, connection, rabbitmq_environment):
+    def __init__(self, env_desc, host_desc, temp_dir,
+                 connection, rabbitmq_environment):
         super(NeutronConfigFixture, self).__init__(
-            temp_dir, base_filename='neutron.conf')
+            env_desc, host_desc, temp_dir, base_filename='neutron.conf')
 
         self.config.update({
             'DEFAULT': {
                 'host': self._generate_host(),
-                'state_path': self._generate_state_path(temp_dir),
+                'state_path': self._generate_state_path(self.temp_dir),
                 'lock_path': '$state_path/lock',
                 'bind_port': self._generate_port(),
                 'api_paste_config': self._generate_api_paste(),
@@ -150,9 +153,9 @@ class NeutronConfigFixture(ConfigFixture):
 
 class ML2ConfigFixture(ConfigFixture):
 
-    def __init__(self, temp_dir, tenant_network_types):
+    def __init__(self, env_desc, host_desc, temp_dir, tenant_network_types):
         super(ML2ConfigFixture, self).__init__(
-            temp_dir, base_filename='ml2_conf.ini')
+            env_desc, host_desc, temp_dir, base_filename='ml2_conf.ini')
 
         self.config.update({
             'ml2': {
@@ -173,9 +176,10 @@ class ML2ConfigFixture(ConfigFixture):
 
 class OVSConfigFixture(ConfigFixture):
 
-    def __init__(self, temp_dir):
+    def __init__(self, env_desc, host_desc, temp_dir):
         super(OVSConfigFixture, self).__init__(
-            temp_dir, base_filename='openvswitch_agent.ini')
+            env_desc, host_desc, temp_dir,
+            base_filename='openvswitch_agent.ini')
 
         self.config.update({
             'ovs': {
@@ -205,9 +209,9 @@ class OVSConfigFixture(ConfigFixture):
 
 class L3ConfigFixture(ConfigFixture):
 
-    def __init__(self, temp_dir, integration_bridge):
+    def __init__(self, env_desc, host_desc, temp_dir, integration_bridge):
         super(L3ConfigFixture, self).__init__(
-            temp_dir, base_filename='l3_agent.ini')
+            env_desc, host_desc, temp_dir, base_filename='l3_agent.ini')
 
         self.config.update({
             'DEFAULT': {
index ef68e44ae4b87870e2d46e01b4b4997964633927..67660f813b72cde81edd15c691902e32874b3781 100644 (file)
@@ -25,13 +25,21 @@ from neutron.tests.fullstack.resources import process
 LOG = logging.getLogger(__name__)
 
 
+class EnvironmentDescription(object):
+    """A set of characteristics of an environment setup.
+
+    Does the setup, as a whole, support tunneling? How about l2pop?
+    """
+    pass
+
+
 class HostDescription(object):
     """A set of characteristics of an environment Host.
 
     What agents should the host spawn? What mode should each agent operate
     under?
     """
-    def __init__(self, l3_agent=True):
+    def __init__(self, l3_agent=False):
         self.l3_agent = l3_agent
 
 
@@ -50,18 +58,20 @@ class Host(fixtures.Fixture):
     and disconnects the host from other hosts.
     """
 
-    def __init__(self, test_name, neutron_config, host_description,
+    def __init__(self, env_desc, host_desc,
+                 test_name, neutron_config,
                  central_data_bridge, central_external_bridge):
+        self.env_desc = env_desc
+        self.host_desc = host_desc
         self.test_name = test_name
         self.neutron_config = neutron_config
-        self.host_description = host_description
         self.central_data_bridge = central_data_bridge
         self.central_external_bridge = central_external_bridge
         self.agents = {}
 
     def _setUp(self):
         agent_cfg_fixture = config.OVSConfigFixture(
-            self.neutron_config.temp_dir)
+            self.env_desc, self.host_desc, self.neutron_config.temp_dir)
         self.useFixture(agent_cfg_fixture)
 
         br_phys = self.useFixture(
@@ -71,11 +81,13 @@ class Host(fixtures.Fixture):
 
         self.ovs_agent = self.useFixture(
             process.OVSAgentFixture(
+                self.env_desc, self.host_desc,
                 self.test_name, self.neutron_config, agent_cfg_fixture))
 
-        if self.host_description.l3_agent:
+        if self.host_desc.l3_agent:
             l3_agent_cfg_fixture = self.useFixture(
                 config.L3ConfigFixture(
+                    self.env_desc, self.host_desc,
                     self.neutron_config.temp_dir,
                     self.ovs_agent.agent_cfg_fixture.get_br_int_name()))
             br_ex = self.useFixture(
@@ -84,6 +96,7 @@ class Host(fixtures.Fixture):
             self.connect_to_external_network(br_ex)
             self.l3_agent = self.useFixture(
                 process.L3AgentFixture(
+                    self.env_desc, self.host_desc,
                     self.test_name,
                     self.neutron_config,
                     l3_agent_cfg_fixture))
@@ -128,13 +141,15 @@ class Environment(fixtures.Fixture):
     the type of Host to create.
     """
 
-    def __init__(self, hosts_descriptions):
+    def __init__(self, env_desc, hosts_desc):
         """
-        :param hosts_descriptions: A list of HostDescription instances.
+        :param env_desc: An EnvironmentDescription instance.
+        :param hosts_desc: A list of HostDescription instances.
         """
 
         super(Environment, self).__init__()
-        self.hosts_descriptions = hosts_descriptions
+        self.env_desc = env_desc
+        self.hosts_desc = hosts_desc
         self.hosts = []
 
     def wait_until_env_is_up(self):
@@ -148,33 +163,37 @@ class Environment(fixtures.Fixture):
         except nc_exc.NeutronClientException:
             return False
 
-    def _create_host(self, description):
+    def _create_host(self, host_desc):
         temp_dir = self.useFixture(fixtures.TempDir()).path
         neutron_config = config.NeutronConfigFixture(
-            temp_dir, cfg.CONF.database.connection,
-            self.rabbitmq_environment)
+            self.env_desc, host_desc, temp_dir,
+            cfg.CONF.database.connection, self.rabbitmq_environment)
         self.useFixture(neutron_config)
 
         return self.useFixture(
-            Host(self.test_name,
+            Host(self.env_desc,
+                 host_desc,
+                 self.test_name,
                  neutron_config,
-                 description,
                  self.central_data_bridge,
                  self.central_external_bridge))
 
     def _setUp(self):
         self.temp_dir = self.useFixture(fixtures.TempDir()).path
+
         self.rabbitmq_environment = self.useFixture(
             process.RabbitmqEnvironmentFixture())
+
         plugin_cfg_fixture = self.useFixture(
-            config.ML2ConfigFixture(self.temp_dir, 'vlan'))
+            config.ML2ConfigFixture(
+                self.env_desc, None, self.temp_dir, 'vlan'))
         neutron_cfg_fixture = self.useFixture(
             config.NeutronConfigFixture(
-                self.temp_dir,
-                cfg.CONF.database.connection,
-                self.rabbitmq_environment))
+                self.env_desc, None, self.temp_dir,
+                cfg.CONF.database.connection, self.rabbitmq_environment))
         self.neutron_server = self.useFixture(
             process.NeutronServerFixture(
+                self.env_desc, None,
                 self.test_name, neutron_cfg_fixture, plugin_cfg_fixture))
 
         self.central_data_bridge = self.useFixture(
@@ -182,7 +201,6 @@ class Environment(fixtures.Fixture):
         self.central_external_bridge = self.useFixture(
             net_helpers.OVSBridgeFixture('cnt-ex')).bridge
 
-        self.hosts = [self._create_host(description) for description in
-                      self.hosts_descriptions]
+        self.hosts = [self._create_host(desc) for desc in self.hosts_desc]
 
         self.wait_until_env_is_up()
index 1a818426c47f0e5c54b2427f5f4d51ea93cbf4dd..4414102e21214b9f18111491dd6af6036b6a0cb3 100644 (file)
@@ -90,7 +90,10 @@ class NeutronServerFixture(fixtures.Fixture):
 
     NEUTRON_SERVER = "neutron-server"
 
-    def __init__(self, test_name, neutron_cfg_fixture, plugin_cfg_fixture):
+    def __init__(self, env_desc, host_desc,
+                 test_name, neutron_cfg_fixture, plugin_cfg_fixture):
+        self.env_desc = env_desc
+        self.host_desc = host_desc
         self.test_name = test_name
         self.neutron_cfg_fixture = neutron_cfg_fixture
         self.plugin_cfg_fixture = plugin_cfg_fixture
@@ -125,7 +128,10 @@ class OVSAgentFixture(fixtures.Fixture):
 
     NEUTRON_OVS_AGENT = "neutron-openvswitch-agent"
 
-    def __init__(self, test_name, neutron_cfg_fixture, agent_cfg_fixture):
+    def __init__(self, env_desc, host_desc,
+                 test_name, neutron_cfg_fixture, agent_cfg_fixture):
+        self.env_desc = env_desc
+        self.host_desc = host_desc
         self.test_name = test_name
         self.neutron_cfg_fixture = neutron_cfg_fixture
         self.neutron_config = self.neutron_cfg_fixture.config
@@ -151,8 +157,11 @@ class L3AgentFixture(fixtures.Fixture):
 
     NEUTRON_L3_AGENT = "neutron-l3-agent"
 
-    def __init__(self, test_name, neutron_cfg_fixture, l3_agent_cfg_fixture):
+    def __init__(self, env_desc, host_desc,
+                 test_name, neutron_cfg_fixture, l3_agent_cfg_fixture):
         super(L3AgentFixture, self).__init__()
+        self.env_desc = env_desc
+        self.host_desc = host_desc
         self.test_name = test_name
         self.neutron_cfg_fixture = neutron_cfg_fixture
         self.l3_agent_cfg_fixture = l3_agent_cfg_fixture
index 34c6c3f2a56deb44ec4cb7ae78df6464cfdc3582..b0f546a3eb32429a4a7ec20840cca2ecd0fea269 100644 (file)
@@ -21,11 +21,12 @@ from neutron.tests.fullstack.resources import machine
 
 class TestConnectivitySameNetwork(base.BaseFullStackTestCase):
 
-    def __init__(self, *args, **kwargs):
+    def setUp(self):
         host_descriptions = [
-            environment.HostDescription(l3_agent=False) for _ in range(2)]
-        env = environment.Environment(host_descriptions)
-        super(TestConnectivitySameNetwork, self).__init__(env, *args, **kwargs)
+            environment.HostDescription() for _ in range(2)]
+        env = environment.Environment(environment.EnvironmentDescription(),
+                                      host_descriptions)
+        super(TestConnectivitySameNetwork, self).setUp(env)
 
     def test_connectivity(self):
         tenant_uuid = uuidutils.generate_uuid()
index 046a4060608c6a986a5c4d6ae13c6ecdcebe1706..28f2419b8786d1a91de25156c282406317f7e35e 100644 (file)
@@ -25,10 +25,12 @@ from neutron.tests.fullstack.resources import environment
 
 
 class TestLegacyL3Agent(base.BaseFullStackTestCase):
-    def __init__(self, *args, **kwargs):
+
+    def setUp(self):
         host_descriptions = [environment.HostDescription(l3_agent=True)]
-        env = environment.Environment(host_descriptions)
-        super(TestLegacyL3Agent, self).__init__(env, *args, **kwargs)
+        env = environment.Environment(environment.EnvironmentDescription(),
+                                      host_descriptions)
+        super(TestLegacyL3Agent, self).setUp(env)
 
     def _get_namespace(self, router_id):
         return namespaces.build_ns_name(l3_agent.NS_PREFIX, router_id)
@@ -53,12 +55,13 @@ class TestLegacyL3Agent(base.BaseFullStackTestCase):
 
 
 class TestHAL3Agent(base.BaseFullStackTestCase):
-    def __init__(self, *args, **kwargs):
-        super(TestHAL3Agent, self).__init__(
-            environment.Environment(
-                [environment.HostDescription(l3_agent=True),
-                 environment.HostDescription(l3_agent=True)]),
-            *args, **kwargs)
+
+    def setUp(self):
+        host_descriptions = [
+            environment.HostDescription(l3_agent=True) for _ in range(2)]
+        env = environment.Environment(environment.EnvironmentDescription(),
+                                      host_descriptions)
+        super(TestHAL3Agent, self).setUp(env)
 
     def _is_ha_router_active_on_one_agent(self, router_id):
         agents = self.client.list_l3_agent_hosting_routers(router_id)