From 3eac4650498d4d061a6c0b9f1d175742e861b912 Mon Sep 17 00:00:00 2001 From: vgusev Date: Fri, 27 May 2016 15:23:09 +0300 Subject: [PATCH] Add system tests for toolchain Added scale tests Added test with fuel-createmirror Change-Id: I9135117b597f9b27ff3de4cc207aea3b2be5a056 --- .../elasticsearch_kibana/test_system.py | 10 +- stacklight_tests/helpers/helpers.py | 15 +- stacklight_tests/influxdb_grafana/api.py | 2 +- .../influxdb_grafana/test_system.py | 4 +- .../test_system.py | 62 +++--- stacklight_tests/run_tests.py | 1 + stacklight_tests/toolchain/api.py | 22 ++- stacklight_tests/toolchain/test_system.py | 180 ++++++++++++++++++ 8 files changed, 248 insertions(+), 48 deletions(-) create mode 100644 stacklight_tests/toolchain/test_system.py diff --git a/stacklight_tests/elasticsearch_kibana/test_system.py b/stacklight_tests/elasticsearch_kibana/test_system.py index 5061593..da8b493 100644 --- a/stacklight_tests/elasticsearch_kibana/test_system.py +++ b/stacklight_tests/elasticsearch_kibana/test_system.py @@ -22,7 +22,7 @@ from stacklight_tests.elasticsearch_kibana import api class TestNodesElasticsearchPlugin(api.ElasticsearchPluginApi): """Class for system tests for Elasticsearch-Kibana plugin.""" - @test(depends_on_groups=['deploy_ha_elasticsearch_kibana'], + @test(depends_on_groups=["deploy_ha_elasticsearch_kibana"], groups=["check_scaling_elasticsearch_kibana", "scaling", "elasticsearch_kibana", "system", "add_remove_controller_elasticsearch_kibana"]) @@ -61,7 +61,7 @@ class TestNodesElasticsearchPlugin(api.ElasticsearchPluginApi): self.helpers.run_ostf(should_fail=1) - @test(depends_on_groups=['deploy_ha_elasticsearch_kibana'], + @test(depends_on_groups=["deploy_ha_elasticsearch_kibana"], groups=["check_scaling_elasticsearch_kibana", "scaling", "elasticsearch_kibana", "system", "add_remove_compute_elasticsearch_kibana"]) @@ -100,7 +100,7 @@ class TestNodesElasticsearchPlugin(api.ElasticsearchPluginApi): self.helpers.run_ostf(should_fail=1) - @test(depends_on_groups=['deploy_ha_elasticsearch_kibana'], + @test(depends_on_groups=["deploy_ha_elasticsearch_kibana"], groups=["check_scaling_elasticsearch_kibana", "scaling", "elasticsearch_kibana", "system", "add_remove_elasticsearch_kibana_node"]) @@ -179,7 +179,7 @@ class TestNodesElasticsearchPlugin(api.ElasticsearchPluginApi): self.helpers.run_ostf() - @test(depends_on_groups=['prepare_slaves_3'], + @test(depends_on_groups=["prepare_slaves_3"], groups=["elasticsearch_kibana_createmirror_deploy_plugin", "system", "elasticsearch_kibana", "createmirror"]) @log_snapshot_after_test @@ -191,7 +191,7 @@ class TestNodesElasticsearchPlugin(api.ElasticsearchPluginApi): install the plugin. 2. Run the following command on the master node: fuel-createmirror - 3. Create an environment with enabled plugins in the + 3. Create an environment with enabled plugin in the Fuel Web UI and deploy it. 4. Run OSTF. diff --git a/stacklight_tests/helpers/helpers.py b/stacklight_tests/helpers/helpers.py index 9c55d29..20b7ce1 100644 --- a/stacklight_tests/helpers/helpers.py +++ b/stacklight_tests/helpers/helpers.py @@ -55,6 +55,10 @@ def get_plugin_version(filename): return None +class NotFound(Exception): + pass + + class PluginHelper(object): """Class for common help functions.""" @@ -308,11 +312,12 @@ class PluginHelper(object): 'when it is deployed'.format(name=plugin_name, version=plugin_version)) - def get_fuel_node_name(self, changed_node): - for node in self.fuel_web.client.list_cluster_nodes(self.cluster_id): - if node["name"] == changed_node: - return node["hostname"] - return None + def get_hostname_by_node_name(self, changed_node): + node = self.fuel_web.get_nailgun_node_by_base_name(changed_node) + if node is None: + raise NotFound("Nailgun node with '{}' in name not found".format( + changed_node)) + return node['hostname'] def fuel_createmirror(self, option="", exit_code=0): logger.info("Executing 'fuel-createmirror' command.") diff --git a/stacklight_tests/influxdb_grafana/api.py b/stacklight_tests/influxdb_grafana/api.py index 62f249d..9ed61c9 100644 --- a/stacklight_tests/influxdb_grafana/api.py +++ b/stacklight_tests/influxdb_grafana/api.py @@ -101,7 +101,7 @@ class InfluxdbPluginApi(base_test.PluginApi): nodes_count_responsed = len( response.json()["results"][0]["series"][0]["values"]) - msg = "Expected {0} InfluxDB nodes, got {}".format( + msg = "Expected {0} InfluxDB nodes, got {1}".format( count, nodes_count_responsed) asserts.assert_equal(count, nodes_count_responsed, msg) diff --git a/stacklight_tests/influxdb_grafana/test_system.py b/stacklight_tests/influxdb_grafana/test_system.py index 836592e..7721a24 100644 --- a/stacklight_tests/influxdb_grafana/test_system.py +++ b/stacklight_tests/influxdb_grafana/test_system.py @@ -25,7 +25,7 @@ class TestNodesInfluxdbPlugin(api.InfluxdbPluginApi): @test(depends_on_groups=["deploy_ha_influxdb_grafana"], groups=["check_scaling_influxdb_grafana", "scaling", "influxdb_grafana", "system", - "check_add_delete_controller_influxdb_grafana"]) + "add_remove_controller_influxdb_grafana"]) @log_snapshot_after_test def add_remove_controller_influxdb_grafana(self): """Verify that the number of controllers can scale up and down @@ -101,7 +101,7 @@ class TestNodesInfluxdbPlugin(api.InfluxdbPluginApi): self.helpers.run_ostf(should_fail=1) - # Add controller + # Add compute self.helpers.add_node_to_cluster(manipulated_node) self.check_plugin_online() diff --git a/stacklight_tests/lma_infrastructure_alerting/test_system.py b/stacklight_tests/lma_infrastructure_alerting/test_system.py index b219546..c9be999 100644 --- a/stacklight_tests/lma_infrastructure_alerting/test_system.py +++ b/stacklight_tests/lma_infrastructure_alerting/test_system.py @@ -23,7 +23,7 @@ from stacklight_tests.lma_infrastructure_alerting import api class TestLMAInfraAlertingPluginSystem(api.InfraAlertingPluginApi): """Class for system testing the LMA Infrastructure Alerting plugin.""" - @test(depends_on_groups=['deploy_ha_lma_infrastructure_alerting'], + @test(depends_on_groups=["deploy_ha_lma_infrastructure_alerting"], groups=["add_remove_controller_lma_infrastructure_alerting", "system", "lma_infrastructure_alerting", "scaling"]) @log_snapshot_after_test @@ -47,19 +47,22 @@ class TestLMAInfraAlertingPluginSystem(api.InfraAlertingPluginApi): """ self.env.revert_snapshot("deploy_ha_lma_infrastructure_alerting") - target_node = self.helpers.get_fuel_node_name('slave-02_controller') - self.helpers.remove_node_from_cluster({'slave-02': ['controller']}) + target_node = {'slave-02': ['controller']} + target_node_hostname = self.helpers.get_hostname_by_node_name( + target_node.keys()[0]) + self.helpers.remove_node_from_cluster(target_node) self.helpers.run_ostf(should_fail=1) self.check_plugin_online() - self.check_node_in_nagios(target_node, False) + self.check_node_in_nagios(target_node_hostname, False) - self.helpers.add_node_to_cluster({'slave-02': ['controller']}) + self.helpers.add_node_to_cluster(target_node) self.helpers.run_ostf(should_fail=1) self.check_plugin_online() - target_node = self.helpers.get_fuel_node_name('slave-02_controller') - self.check_node_in_nagios(target_node, True) + target_node_hostname = self.helpers.get_hostname_by_node_name( + target_node.keys()[0]) + self.check_node_in_nagios(target_node_hostname, True) - @test(depends_on_groups=['deploy_ha_lma_infrastructure_alerting'], + @test(depends_on_groups=["deploy_ha_lma_infrastructure_alerting"], groups=["add_remove_compute_lma_infrastructure_alerting", "system", "lma_infrastructure_alerting", "scaling"]) @log_snapshot_after_test @@ -83,22 +86,22 @@ class TestLMAInfraAlertingPluginSystem(api.InfraAlertingPluginApi): """ self.env.revert_snapshot("deploy_ha_lma_infrastructure_alerting") - target_node = self.helpers.get_fuel_node_name( - 'slave-04_compute_cinder') - self.helpers.remove_node_from_cluster( - {'slave-04': ['compute', 'cinder']}, False, True) + target_node = {'slave-04': ['compute', 'cinder']} + target_node_hostname = self.helpers.get_hostname_by_node_name( + target_node.keys()[0]) + self.helpers.remove_node_from_cluster(target_node, False, True) self.helpers.run_ostf(should_fail=1) self.check_plugin_online() - self.check_node_in_nagios(target_node, False) + self.check_node_in_nagios(target_node_hostname, False) - self.helpers.add_node_to_cluster({'slave-04': ['compute', 'cinder']}) + self.helpers.add_node_to_cluster(target_node) self.helpers.run_ostf(should_fail=1) self.check_plugin_online() - target_node = self.helpers.get_fuel_node_name( - 'slave-04_compute_cinder') - self.check_node_in_nagios(target_node, True) + target_node_hostname = self.helpers.get_hostname_by_node_name( + target_node.keys()[0]) + self.check_node_in_nagios(target_node_hostname, True) - @test(depends_on_groups=['deploy_ha_lma_infrastructure_alerting'], + @test(depends_on_groups=["deploy_ha_lma_infrastructure_alerting"], groups=["add_remove_infrastructure_alerting_node", "system", "lma_infrastructure_alerting", "scaling"]) @log_snapshot_after_test @@ -121,23 +124,22 @@ class TestLMAInfraAlertingPluginSystem(api.InfraAlertingPluginApi): """ self.env.revert_snapshot("deploy_ha_lma_infrastructure_alerting") - target_node = self.helpers.get_fuel_node_name( - 'slave-05_{0}'.format(self.settings.role_name[0])) - self.helpers.remove_node_from_cluster( - {'slave-05': self.settings.role_name}) + target_node = {'slave-05': self.settings.role_name} + target_node_hostname = self.helpers.get_hostname_by_node_name( + target_node.keys()[0]) + self.helpers.remove_node_from_cluster(target_node) self.helpers.run_ostf(should_fail=1) self.check_plugin_online() - self.check_node_in_nagios(target_node, False) + self.check_node_in_nagios(target_node_hostname, False) - self.helpers.add_node_to_cluster( - {'slave-05': self.settings.role_name}) + self.helpers.add_node_to_cluster(target_node) self.helpers.run_ostf(should_fail=1) self.check_plugin_online() - target_node = self.helpers.get_fuel_node_name( - 'slave-05_{0}'.format(self.settings.role_name[0])) - self.check_node_in_nagios(target_node, True) + target_node_hostname = self.helpers.get_hostname_by_node_name( + target_node.keys()[0]) + self.check_node_in_nagios(target_node_hostname, True) - @test(depends_on_groups=['deploy_ha_lma_infrastructure_alerting'], + @test(depends_on_groups=["deploy_ha_lma_infrastructure_alerting"], groups=["shutdown_infrastructure_alerting_node", "system", "lma_infrastructure_alerting", "shutdown"]) @log_snapshot_after_test @@ -165,7 +167,7 @@ class TestLMAInfraAlertingPluginSystem(api.InfraAlertingPluginApi): self.check_plugin_online() self.helpers.run_ostf() - @test(depends_on_groups=['prepare_slaves_3'], + @test(depends_on_groups=["prepare_slaves_3"], groups=["lma_infrastructure_alerting_createmirror_deploy_plugin", "system", "lma_infrastructure_alerting", "createmirror"]) @log_snapshot_after_test diff --git a/stacklight_tests/run_tests.py b/stacklight_tests/run_tests.py index 5f4b345..beee79f 100644 --- a/stacklight_tests/run_tests.py +++ b/stacklight_tests/run_tests.py @@ -54,6 +54,7 @@ def import_tests(): test_system) from stacklight_tests.toolchain import test_detached_plugins # noqa from stacklight_tests.toolchain import test_smoke_bvt # noqa + from stacklight_tests.toolchain import test_system # noqa def run_tests(): diff --git a/stacklight_tests/toolchain/api.py b/stacklight_tests/toolchain/api.py index 93e1246..12bdeed 100644 --- a/stacklight_tests/toolchain/api.py +++ b/stacklight_tests/toolchain/api.py @@ -35,11 +35,14 @@ class ToolchainApi(object): self.checkers = checkers self.remote_ops = remote_ops self.ui_tester = ui_tester - self.plugins = [ - elasticsearch_api.ElasticsearchPluginApi(), - influx_api.InfluxdbPluginApi(), - collector_api.LMACollectorPluginApi(), - infrastructure_alerting_api.InfraAlertingPluginApi()] + self.plugins_mapping = { + "elasticsearch_kibana": elasticsearch_api.ElasticsearchPluginApi(), + "influxdb_grafana": influx_api.InfluxdbPluginApi(), + "lma_collector": collector_api.LMACollectorPluginApi(), + "lma_infrastructure_alerting": + infrastructure_alerting_api.InfraAlertingPluginApi() + } + self.plugins = set(self.plugins_mapping.values()) def __getattr__(self, item): return getattr(self.test, item) @@ -61,6 +64,15 @@ class ToolchainApi(object): logger.info(msg.format(plugin.get_plugin_settings().name)) plugin.check_plugin_online() + def check_nodes_count(self, count, hostname, state): + self.plugins_mapping[ + 'elasticsearch_kibana'].check_elasticsearch_nodes_count(count) + self.plugins_mapping[ + 'influxdb_grafana'].check_influxdb_nodes_count(count) + self.plugins_mapping[ + 'lma_infrastructure_alerting'].check_node_in_nagios( + hostname, state) + def uninstall_plugins(self): for plugin in self.plugins: plugin.uninstall_plugin() diff --git a/stacklight_tests/toolchain/test_system.py b/stacklight_tests/toolchain/test_system.py new file mode 100644 index 0000000..955dc0d --- /dev/null +++ b/stacklight_tests/toolchain/test_system.py @@ -0,0 +1,180 @@ +# Copyright 2016 Mirantis, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from fuelweb_test.helpers.decorators import log_snapshot_after_test +from proboscis import test + +from stacklight_tests.toolchain import api + + +@test(groups=["plugins"]) +class TestNodesToolchain(api.ToolchainApi): + """Class for system tests for the LMA Toolchain plugins.""" + + @test(depends_on_groups=["deploy_ha_toolchain"], + groups=["check_scaling_toolchain", "scaling", "toolchain", "system", + "add_remove_controller_toolchain"]) + @log_snapshot_after_test + def add_remove_controller_toolchain(self): + """Verify that the number of controllers can scale up and down + + Scenario: + 1. Revert snapshot with 9 deployed nodes in HA configuration + 2. Remove one controller node and update the cluster + 3. Check that plugin is working + 4. Run OSTF + 5. Add one controller node (return previous state) and + update the cluster + 6. Check that plugins are working + 7. Run OSTF + + Duration 120m + """ + self.env.revert_snapshot("deploy_ha_toolchain") + + manipulated_node = {'slave-03': ['controller']} + + # Remove controller + self.helpers.remove_node_from_cluster(manipulated_node) + + self.check_plugins_online() + + self.helpers.run_ostf(should_fail=1) + + # Add controller + self.helpers.add_node_to_cluster(manipulated_node) + + self.check_plugins_online() + + self.helpers.run_ostf(should_fail=1) + + @test(depends_on_groups=["deploy_ha_toolchain"], + groups=["check_scaling_toolchain", "scaling", "toolchain", "system", + "add_remove_compute_toolchain"]) + @log_snapshot_after_test + def add_remove_compute_toolchain(self): + """Verify that the number of computes can scale up and down + + Scenario: + 1. Revert snapshot with 9 deployed nodes in HA configuration + 2. Remove one compute node and update the cluster + 3. Check that plugin is working + 4. Run OSTF + 5. Add one compute node (return previous state) and + update the cluster + 6. Check that plugins are working + 7. Run OSTF + + Duration 120m + """ + self.env.revert_snapshot("deploy_ha_toolchain") + + manipulated_node = {'slave-04': ['compute', 'cinder']} + + # Remove compute + self.helpers.remove_node_from_cluster(manipulated_node) + + self.check_plugins_online() + + self.helpers.run_ostf(should_fail=1) + + # Add compute + self.helpers.add_node_to_cluster(manipulated_node) + + self.check_plugins_online() + + self.helpers.run_ostf(should_fail=1) + + @test(depends_on_groups=["deploy_ha_toolchain"], + groups=["check_scaling_toolchain", "scaling", + "toolchain", "system", + "add_remove_toolchain_node"]) + @log_snapshot_after_test + def add_remove_toolchain_node(self): + """Verify that the number of StackLight nodes can scale up and down + + Scenario: + 1. Revert snapshot with 9 deployed nodes in HA configuration + 2. Remove one node with StackLight roles and update the cluster + 3. Check that plugin are working + 4. Run OSTF + 5. Add one node with StackLight roles (return previous state) and + update the cluster + 6. Check that plugins are working + 7. Run OSTF + + Duration 120m + """ + self.env.revert_snapshot("deploy_ha_toolchain") + + manipulated_node = {'slave-07': self.settings.role_name} + manipulated_node_hostname = self.helpers.get_hostname_by_node_name( + manipulated_node.keys()[0]) + + self.check_nodes_count(3, manipulated_node_hostname, True) + + # Remove node with StackLight roles + self.helpers.remove_node_from_cluster(manipulated_node) + + self.check_plugin_online() + + self.check_nodes_count(2, manipulated_node_hostname, False) + + self.fuel_web.run_ostf() + + # Add node with StackLight roles + self.helpers.add_node_to_cluster(manipulated_node) + + self.check_plugin_online() + + manipulated_node_hostname = self.helpers.get_hostname_by_node_name( + manipulated_node.keys()[0]) + + self.check_nodes_count(3, manipulated_node_hostname, True) + + self.helpers.run_ostf() + + @test(depends_on_groups=["prepare_slaves_3"], + groups=["toolchain_createmirror_deploy_plugins", "system", + "toolchain", "createmirror"]) + @log_snapshot_after_test + def toolchain_createmirror_deploy_plugins(self): + """Run fuel-createmirror and deploy environment + + Scenario: + 1. Copy the LMA Toolchais plugins to the Fuel Master node and + install the plugins. + 2. Run the following command on the master node: + fuel-createmirror + 3. Create an environment with enabled plugins in the + Fuel Web UI and deploy it. + 4. Run OSTF. + + Duration 60m + """ + self.env.revert_snapshot("ready_with_3_slaves") + + self.prepare_plugins() + + self.helpers.fuel_createmirror() + + self.helpers.create_cluster(name=self.__class__.__name__) + + self.activate_plugins() + + self.helpers.deploy_cluster(self.base_nodes) + + self.check_plugins_online() + + self.helpers.run_ostf()