Skip to content

Commit

Permalink
Integration test for a transient cluster was added
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ylobankov committed Mar 21, 2014
1 parent e0d1b09 commit 7b80f8f
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 37 deletions.
16 changes: 11 additions & 5 deletions sahara/tests/integration/configs/config.py
Expand Up @@ -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.'),
Expand Down Expand Up @@ -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)
]


Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions sahara/tests/integration/configs/itest.conf.sample
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions sahara/tests/integration/configs/itest.conf.sample-full
Expand Up @@ -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'
Expand Down Expand Up @@ -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]

Expand Down
12 changes: 6 additions & 6 deletions sahara/tests/integration/tests/base.py
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion 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.
Expand Down
18 changes: 11 additions & 7 deletions sahara/tests/integration/tests/gating/test_hdp_gating.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions sahara/tests/integration/tests/gating/test_idh_gating.py
Expand Up @@ -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',
Expand Down
54 changes: 36 additions & 18 deletions sahara/tests/integration/tests/gating/test_vanilla_gating.py
Expand Up @@ -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):
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
83 changes: 83 additions & 0 deletions 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)

0 comments on commit 7b80f8f

Please sign in to comment.