From 7b80f8fef4e9b09d28e4f31256092e1a78b512d0 Mon Sep 17 00:00:00 2001 From: Yaroslav Lobankov Date: Tue, 25 Feb 2014 19:00:06 +0400 Subject: [PATCH] Integration test for a transient cluster was added * The test is to create transient cluster (simple cluster with single node) and wait for cluster deleting. If cluster is not deleted within some timeout (for example, 3 minutes), error will be handled. EDP job will not be run on cluster. * Option to run only test for transient cluster was added. Implements blueprint trust-support-in-i-tests Change-Id: Icc69b4706d441798d933feec484b13efae8df380 --- sahara/tests/integration/configs/config.py | 16 ++-- .../integration/configs/itest.conf.sample | 1 + .../configs/itest.conf.sample-full | 6 ++ sahara/tests/integration/tests/base.py | 12 +-- sahara/tests/integration/tests/cinder.py | 2 +- .../tests/gating/test_hdp_gating.py | 18 ++-- .../tests/gating/test_idh_gating.py | 3 + .../tests/gating/test_vanilla_gating.py | 54 ++++++++---- .../tests/vanilla_transient_cluster.py | 83 +++++++++++++++++++ 9 files changed, 158 insertions(+), 37 deletions(-) create mode 100644 sahara/tests/integration/tests/vanilla_transient_cluster.py diff --git a/sahara/tests/integration/configs/config.py b/sahara/tests/integration/configs/config.py index 4c74ac1465..988d78f5d4 100644 --- a/sahara/tests/integration/configs/config.py +++ b/sahara/tests/integration/configs/config.py @@ -87,6 +87,10 @@ def get_instance(): default=5, help='Timeout for job launch (in minutes); ' 'minimal value is 1.'), + cfg.IntOpt('TRANSIENT_CLUSTER_TIMEOUT', + default=3, + help='Timeout for a poll of state of transient cluster ' + '(in minutes); minimal value is 1.'), cfg.StrOpt('CLUSTER_NAME', default='test-cluster', help='Name for cluster.'), @@ -219,7 +223,9 @@ def get_instance(): cfg.BoolOpt('SKIP_EDP_TEST', default=False), cfg.BoolOpt('SKIP_MAP_REDUCE_TEST', default=False), cfg.BoolOpt('SKIP_SWIFT_TEST', default=False), - cfg.BoolOpt('SKIP_SCALING_TEST', default=False) + cfg.BoolOpt('SKIP_SCALING_TEST', default=False), + cfg.BoolOpt('SKIP_TRANSIENT_CLUSTER_TEST', default=False), + cfg.BoolOpt('ONLY_TRANSIENT_CLUSTER_TEST', default=False) ] @@ -412,10 +418,10 @@ def __init__(self): config_files = [] config_path = '%s/sahara/tests/integration/configs/%s' if not os.path.exists(config_path % (os.getcwd(), config)): - message = '\n**************************************************' \ - '\nINFO: Configuration file "%s" not found *\n' \ - '**************************************************' \ - % config + message = ('\n**************************************************' + '\nINFO: Configuration file "%s" not found *\n' + '**************************************************' + % config) print(RuntimeError(message), file=sys.stderr) else: diff --git a/sahara/tests/integration/configs/itest.conf.sample b/sahara/tests/integration/configs/itest.conf.sample index 01fd11faeb..e2fccc5952 100644 --- a/sahara/tests/integration/configs/itest.conf.sample +++ b/sahara/tests/integration/configs/itest.conf.sample @@ -3,6 +3,7 @@ OS_USERNAME = 'admin' OS_PASSWORD = 'admin' OS_TENANT_NAME = 'admin' +OS_TENANT_ID = 'c5853430df5840a18ada297baae76184' OS_AUTH_URL = 'http://127.0.0.1:5000/v2.0' SAHARA_HOST = '127.0.0.1' FLAVOR_ID = 2 diff --git a/sahara/tests/integration/configs/itest.conf.sample-full b/sahara/tests/integration/configs/itest.conf.sample-full index 4da4c0ef5a..4ce5e8b76f 100644 --- a/sahara/tests/integration/configs/itest.conf.sample-full +++ b/sahara/tests/integration/configs/itest.conf.sample-full @@ -53,6 +53,10 @@ # Timeout for job creation (in minutes); minimal value is 1 (integer value) #JOB_LAUNCH_TIMEOUT = 5 +# Timeout for a poll of state of transient cluster (in minutes); +# minimal value is 1 (integer value) +#TRANSIENT_CLUSTER_TIMEOUT = 3 + # Name for cluster (string value) #CLUSTER_NAME = 'test-cluster' @@ -165,6 +169,8 @@ #SKIP_MAP_REDUCE_TEST = False #SKIP_SWIFT_TEST = False #SKIP_SCALING_TEST = False +#SKIP_TRANSIENT_CLUSTER_TEST = False +#ONLY_TRANSIENT_CLUSTER_TEST = False [HDP] diff --git a/sahara/tests/integration/tests/base.py b/sahara/tests/integration/tests/base.py index 089dc734ee..521f7d01d6 100644 --- a/sahara/tests/integration/tests/base.py +++ b/sahara/tests/integration/tests/base.py @@ -134,14 +134,14 @@ def create_cluster_template(self, name, plugin_config, description, cluster_template_id = data.id return cluster_template_id - def create_cluster_and_get_info(self, plugin_config, cluster_template_id, - description, cluster_configs, - node_groups=None, anti_affinity=None, - net_id=None, is_transient=False): + def create_cluster_and_get_info(self, name, plugin_config, + cluster_template_id, description, + cluster_configs, node_groups=None, + anti_affinity=None, net_id=None, + is_transient=False): self.cluster_id = None data = self.sahara.clusters.create( - self.common_config.CLUSTER_NAME + '-' + plugin_config.PLUGIN_NAME, - plugin_config.PLUGIN_NAME, plugin_config.HADOOP_VERSION, + name, plugin_config.PLUGIN_NAME, plugin_config.HADOOP_VERSION, cluster_template_id, plugin_config.IMAGE_ID, is_transient, description, cluster_configs, node_groups, self.common_config.USER_KEYPAIR_ID, anti_affinity, net_id) diff --git a/sahara/tests/integration/tests/cinder.py b/sahara/tests/integration/tests/cinder.py index 5b5c69d596..ae08ec29d0 100644 --- a/sahara/tests/integration/tests/cinder.py +++ b/sahara/tests/integration/tests/cinder.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013 Mirantis Inc. +# Copyright (c) 2014 Mirantis Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/sahara/tests/integration/tests/gating/test_hdp_gating.py b/sahara/tests/integration/tests/gating/test_hdp_gating.py index 567e6d1d6f..3fb380071c 100644 --- a/sahara/tests/integration/tests/gating/test_hdp_gating.py +++ b/sahara/tests/integration/tests/gating/test_hdp_gating.py @@ -28,13 +28,14 @@ class HDPGatingTest(cinder.CinderVolumeTest, edp.EDPTest, map_reduce.MapReduceTest, swift.SwiftTest, scaling.ScalingTest): - SKIP_CINDER_TEST = cfg.ITConfig().hdp_config.SKIP_CINDER_TEST - SKIP_EDP_TEST = cfg.ITConfig().hdp_config.SKIP_EDP_TEST - SKIP_MAP_REDUCE_TEST = cfg.ITConfig().hdp_config.SKIP_MAP_REDUCE_TEST - SKIP_SWIFT_TEST = cfg.ITConfig().hdp_config.SKIP_SWIFT_TEST - SKIP_SCALING_TEST = cfg.ITConfig().hdp_config.SKIP_SCALING_TEST - - @unittest2.skipIf(cfg.ITConfig().hdp_config.SKIP_ALL_TESTS_FOR_PLUGIN, + config = cfg.ITConfig().hdp_config + SKIP_CINDER_TEST = config.SKIP_CINDER_TEST + SKIP_EDP_TEST = config.SKIP_EDP_TEST + SKIP_MAP_REDUCE_TEST = config.SKIP_MAP_REDUCE_TEST + SKIP_SWIFT_TEST = config.SKIP_SWIFT_TEST + SKIP_SCALING_TEST = config.SKIP_SCALING_TEST + + @unittest2.skipIf(config.SKIP_ALL_TESTS_FOR_PLUGIN, 'All tests for HDP plugin were skipped') @testcase.attr('hdp') def test_hdp_plugin_gating(self): @@ -120,8 +121,11 @@ def test_hdp_plugin_gating(self): #-------------------------------Cluster creation------------------------------- + cluster_name = (self.common_config.CLUSTER_NAME + '-' + + self.hdp_config.PLUGIN_NAME) try: cluster_info = self.create_cluster_and_get_info( + name=cluster_name, plugin_config=self.hdp_config, cluster_template_id=cluster_template_id, description='test cluster', diff --git a/sahara/tests/integration/tests/gating/test_idh_gating.py b/sahara/tests/integration/tests/gating/test_idh_gating.py index 89bec2c8b4..c8c5ba4d1e 100644 --- a/sahara/tests/integration/tests/gating/test_idh_gating.py +++ b/sahara/tests/integration/tests/gating/test_idh_gating.py @@ -164,7 +164,10 @@ def _create_cluster_template(self): @errormessage("Failure while cluster creation: ") def _create_cluster(self): + cluster_name = (self.common_config.CLUSTER_NAME + '-' + + self.idh_config.PLUGIN_NAME) cluster = { + 'name': cluster_name, 'plugin_config': self.idh_config, 'cluster_template_id': self.cluster_template_id, 'description': 'test cluster', diff --git a/sahara/tests/integration/tests/gating/test_vanilla_gating.py b/sahara/tests/integration/tests/gating/test_vanilla_gating.py index 20fd436b63..281438f8dc 100644 --- a/sahara/tests/integration/tests/gating/test_vanilla_gating.py +++ b/sahara/tests/integration/tests/gating/test_vanilla_gating.py @@ -24,22 +24,24 @@ from sahara.tests.integration.tests import map_reduce from sahara.tests.integration.tests import scaling from sahara.tests.integration.tests import swift +from sahara.tests.integration.tests import vanilla_transient_cluster class VanillaGatingTest(cinder.CinderVolumeTest, cluster_configs.ClusterConfigTest, edp.EDPTest, map_reduce.MapReduceTest, swift.SwiftTest, - scaling.ScalingTest): - - SKIP_CINDER_TEST = cfg.ITConfig().vanilla_config.SKIP_CINDER_TEST - SKIP_CLUSTER_CONFIG_TEST = ( - cfg.ITConfig().vanilla_config.SKIP_CLUSTER_CONFIG_TEST) - SKIP_EDP_TEST = cfg.ITConfig().vanilla_config.SKIP_EDP_TEST - SKIP_MAP_REDUCE_TEST = cfg.ITConfig().vanilla_config.SKIP_MAP_REDUCE_TEST - SKIP_SWIFT_TEST = cfg.ITConfig().vanilla_config.SKIP_SWIFT_TEST - SKIP_SCALING_TEST = cfg.ITConfig().vanilla_config.SKIP_SCALING_TEST - - @unittest2.skipIf(cfg.ITConfig().vanilla_config.SKIP_ALL_TESTS_FOR_PLUGIN, + scaling.ScalingTest, + vanilla_transient_cluster.TransientClusterTest): + config = cfg.ITConfig().vanilla_config + SKIP_CINDER_TEST = config.SKIP_CINDER_TEST + SKIP_CLUSTER_CONFIG_TEST = config.SKIP_CLUSTER_CONFIG_TEST + SKIP_EDP_TEST = config.SKIP_EDP_TEST + SKIP_MAP_REDUCE_TEST = config.SKIP_MAP_REDUCE_TEST + SKIP_SWIFT_TEST = config.SKIP_SWIFT_TEST + SKIP_SCALING_TEST = config.SKIP_SCALING_TEST + SKIP_TRANSIENT_CLUSTER_TEST = config.SKIP_TRANSIENT_CLUSTER_TEST + + @unittest2.skipIf(config.SKIP_ALL_TESTS_FOR_PLUGIN, 'All tests for Vanilla plugin were skipped') @testcase.attr('vanilla') def test_vanilla_plugin_gating(self): @@ -55,19 +57,25 @@ def test_vanilla_plugin_gating(self): floating_ip_pool = self.get_floating_ip_pool_id_for_neutron_net() internal_neutron_net = self.get_internal_neutron_net_id() - if not self.vanilla_config.SKIP_CINDER_TEST: - volumes_per_node = 2 - volume_size = 2 - else: - volumes_per_node = 0 - volume_size = 0 +#----------------------------TRANSIENT CLUSTER TESTING------------------------- - node_group_template_id_list = [] + try: + self.transient_cluster_testing( + self.vanilla_config, floating_ip_pool, internal_neutron_net) + except Exception as e: + with excutils.save_and_reraise_exception(): + message = 'Failure while transient cluster testing: ' + self.print_error_log(message, e) + + if self.vanilla_config.ONLY_TRANSIENT_CLUSTER_TEST: + return #-------------------------------CLUSTER CREATION------------------------------- #---------------------"tt-dn" node group template creation--------------------- + node_group_template_id_list = [] + try: node_group_template_tt_dn_id = self.create_node_group_template( name='test-node-group-template-vanilla-tt-dn', @@ -90,6 +98,13 @@ def test_vanilla_plugin_gating(self): #-----------------------"tt" node group template creation---------------------- + if not self.vanilla_config.SKIP_CINDER_TEST: + volumes_per_node = 2 + volume_size = 2 + else: + volumes_per_node = 0 + volume_size = 0 + try: node_group_template_tt_id = self.create_node_group_template( name='test-node-group-template-vanilla-tt', @@ -197,7 +212,10 @@ def test_vanilla_plugin_gating(self): #-------------------------------Cluster creation------------------------------- try: + cluster_name = (self.common_config.CLUSTER_NAME + '-' + + self.vanilla_config.PLUGIN_NAME) cluster_info = self.create_cluster_and_get_info( + name=cluster_name, plugin_config=self.vanilla_config, cluster_template_id=cluster_template_id, description='test cluster', diff --git a/sahara/tests/integration/tests/vanilla_transient_cluster.py b/sahara/tests/integration/tests/vanilla_transient_cluster.py new file mode 100644 index 0000000000..cbab1962a5 --- /dev/null +++ b/sahara/tests/integration/tests/vanilla_transient_cluster.py @@ -0,0 +1,83 @@ +# Copyright (c) 2014 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. + +import time + +import saharaclient.api.base as sab + +from sahara.openstack.common import timeutils +from sahara.tests.integration.tests import base + + +class TransientClusterTest(base.ITestCase): + @base.skip_test( + 'SKIP_TRANSIENT_CLUSTER_TEST', + message='Test for transient cluster was skipped.') + def transient_cluster_testing(self, plugin_config, floating_ip_pool, + internal_neutron_net): + cluster_template_id = self.create_cluster_template( + name='test-transient-cluster-template-vanilla', + plugin_config=self.vanilla_config, + description=('test cluster template for transient cluster ' + 'of Vanilla plugin'), + cluster_configs={}, + node_groups=[ + dict( + name='single-node', + flavor_id=self.flavor_id, + node_processes=['namenode'], + floating_ip_pool=floating_ip_pool, + count=1) + ], + net_id=internal_neutron_net + ) + + try: + try: + cluster_name = (self.common_config.CLUSTER_NAME + '-transient-' + + plugin_config.PLUGIN_NAME) + cluster_info = self.create_cluster_and_get_info( + name=cluster_name, + plugin_config=plugin_config, + cluster_template_id=cluster_template_id, + description='test transient cluster', + cluster_configs={}, + is_transient=True + ) + except Exception: + self.delete_objects(cluster_id=self.cluster_id) + raise + + # set timeout in seconds + timeout = self.common_config.TRANSIENT_CLUSTER_TIMEOUT * 60 + s_time = timeutils.utcnow() + raise_failure = True + while timeutils.delta_seconds( + s_time, timeutils.utcnow()) < timeout: + try: + self.sahara.clusters.get(cluster_info['cluster_id']) + except sab.APIException as api_ex: + if 'not found' in api_ex.message: + raise_failure = False + break + time.sleep(2) + + if raise_failure: + self.delete_objects(cluster_id=cluster_info['cluster_id']) + self.fail('Transient cluster has not been deleted within %s ' + 'minutes.' + % self.common_config.TRANSIENT_CLUSTER_TIMEOUT) + finally: + self.delete_objects(cluster_template_id=cluster_template_id)