Added verification of cluster to scenario-framework

Added the possibility to run the verification of cluster in
scenario-tests

Change-Id: I9f6961e2d154318a40165966d7d9fd1ef599344d
This commit is contained in:
Alina Nesterova 2016-08-18 15:24:24 +03:00 committed by zemuvier
parent ed3a540bde
commit 9a93de6500
3 changed files with 97 additions and 8 deletions

View File

@ -41,6 +41,7 @@ CHECK_OK_STATUS = "OK"
CHECK_FAILED_STATUS = "FAILED"
CLUSTER_STATUS_ACTIVE = "Active"
CLUSTER_STATUS_ERROR = "Error"
HEALTH_CHECKS = ["RED", "YELLOW", "GREEN"]
def track_result(check_name, exit_with_error=True):
@ -154,9 +155,8 @@ class BaseTestCase(base.BaseTestCase):
cluster = self.sahara.get_cluster(self.cluster_id, show_progress=True)
self._get_proxy(cluster)
self.check_cinder()
if not getattr(cluster, "provision_progress", None):
return
self._check_event_logs(cluster)
if self.check_feature_available("provision_progress"):
self._check_event_logs(cluster)
def _get_proxy(self, cluster):
for ng in cluster.node_groups:
@ -218,6 +218,7 @@ class BaseTestCase(base.BaseTestCase):
self._job_batching(pre_exec)
pre_exec = []
batching = batching_size
self.check_verification(self.cluster_id)
def _job_batching(self, pre_exec):
job_exec_ids = []
@ -656,6 +657,41 @@ class BaseTestCase(base.BaseTestCase):
nodes_with_process.extend(nodegroup['instances'])
return nodes_with_process
def _get_health_status(self, cluster):
try:
return cluster.verification['status']
except (AttributeError, KeyError):
return 'UNKNOWN'
def _poll_verification_status(self, cluster_id):
with fixtures.Timeout(
timeouts.Defaults.instance.timeout_poll_cluster_status,
gentle=True):
while True:
cluster = self.sahara.get_cluster(cluster_id)
status = self._get_health_status(cluster)
if status == 'UNKNOWN':
print("Cluster verification did not start")
break
if status in HEALTH_CHECKS:
break
time.sleep(3)
@track_result("Check cluster verification")
def check_verification(self, cluster_id):
if self.check_feature_available("verification"):
self._poll_cluster_status(cluster_id)
# need to check if previous verification check is not
# in the status CHECKING
self._poll_verification_status(cluster_id)
self.sahara.start_cluster_verification(cluster_id)
# check if this verification check finished without errors
self._poll_verification_status(cluster_id)
else:
print("All tests for cluster verification were skipped")
# client ops
def __create_node_group_template(self, *args, **kwargs):
@ -733,6 +769,12 @@ class BaseTestCase(base.BaseTestCase):
self.addCleanup(self.nova.delete_keypair, key)
return key
def check_feature_available(self, feature_name):
if not getattr(self.sahara.get_cluster(self.cluster_id),
feature_name, None):
return False
return True
def tearDown(self):
tbs = []
table = prettytable.PrettyTable(["Check", "Status", "Duration, s"])

View File

@ -30,6 +30,7 @@ from swiftclient import client as swift_client
from swiftclient import exceptions as swift_exc
from tempest.lib import exceptions as exc
from sahara_tests.scenario import timeouts
from sahara_tests.scenario import utils
@ -43,8 +44,6 @@ def get_session(auth_url=None, username=None, password=None,
project_domain_name='default')
return session.Session(auth=auth, verify=verify, cert=cert)
from sahara_tests.scenario import timeouts
class Client(object):
def is_resource_deleted(self, method, *args, **kwargs):
@ -94,6 +93,10 @@ class SaharaClient(Client):
def scale_cluster(self, cluster_id, body):
return self.sahara_client.clusters.scale(cluster_id, body)
def start_cluster_verification(self, cluster_id):
return self.sahara_client.clusters.verification_update(cluster_id,
'START')
def create_datasource(self, *args, **kwargs):
data = self.sahara_client.data_sources.create(*args, **kwargs)
return data.id

View File

@ -39,7 +39,6 @@ class FakeSaharaClient(object):
NodeGroupTemplateManager(None))
self.plugins = plugins.PluginManager(None)
self.images = images.ImageManager(None)
self.data_sources = data_sources.DataSourceManager(None)
self.jobs = jobs.JobsManager(None)
self.job_executions = job_executions.JobExecutionsManager(None)
@ -58,7 +57,7 @@ class FakeCluster(object):
class FakeResponse(object):
def __init__(self, set_id=None, set_status=None, status_description=None,
node_groups=None, url=None, job_id=None, name=None,
job_type=None):
job_type=None, verification=None):
self.id = set_id
self.status = set_status
self.status_description = status_description
@ -67,6 +66,7 @@ class FakeResponse(object):
self.job_id = job_id
self.name = name
self.type = job_type
self.verification = verification
class TestBase(testtools.TestCase):
@ -434,7 +434,9 @@ class TestBase(testtools.TestCase):
@mock.patch('sahara_tests.scenario.base.BaseTestCase._create_datasources',
return_value=('id_for_datasource', 'id_for_datasource'))
@mock.patch('saharaclient.client.Client', return_value=FakeSaharaClient())
def test_check_run_jobs(self, mock_saharaclient, mock_datasources,
@mock.patch('sahara_tests.scenario.base.BaseTestCase.check_verification')
def test_check_run_jobs(self, mock_verification,
mock_saharaclient, mock_datasources,
mock_job_binaries, mock_job,
mock_node_group_template, mock_cluster_template,
mock_cluster, mock_cluster_status, mock_create,
@ -605,3 +607,45 @@ class TestBase(testtools.TestCase):
self.assertIn('/user/test/data-', (
self.base_scenario._create_dfs_data(input_path, None,
'test', 'hdfs')))
@mock.patch('saharaclient.api.base.ResourceManager._get',
return_value=FakeResponse(
set_status=base.CLUSTER_STATUS_ACTIVE,
verification={'verification': {
'status': 'GREEN',
'cluster_id': 'id_cluster'
}}))
@mock.patch('saharaclient.api.clusters.ClusterManager.verification_update')
@mock.patch('keystoneauth1.session.Session')
@mock.patch('sahara_tests.scenario.base.BaseTestCase.'
'check_feature_available', return_value=True)
def test_check_verification_did_not_start(self, mock_feature,
mock_session, mock_verification,
mock_get_status):
self.base_scenario._init_clients()
self.assertIsNone(self.base_scenario.check_verification('id_cluster'))
@mock.patch('saharaclient.api.base.ResourceManager._get',
return_value=FakeResponse(
set_status=base.CLUSTER_STATUS_ACTIVE))
@mock.patch('saharaclient.api.clusters.ClusterManager.verification_update')
@mock.patch('keystoneauth1.session.Session')
@mock.patch('sahara_tests.scenario.base.BaseTestCase.'
'check_feature_available', return_value=True)
@mock.patch('sahara_tests.scenario.base'
'.BaseTestCase._get_health_status', return_value='GREEN')
def test_verification_start(self, mock_status, mock_feature,
mock_session, mock_verification,
mock_get_status):
self.base_scenario._init_clients()
self.assertIsNone(self.base_scenario.check_verification('id_cluster'))
@mock.patch('saharaclient.api.base.ResourceManager._get',
return_value=FakeResponse(
set_status=base.CLUSTER_STATUS_ACTIVE))
@mock.patch('saharaclient.api.clusters.ClusterManager.verification_update')
@mock.patch('keystoneauth1.session.Session')
def test_verification_skipped(self, mock_session, mock_verification,
mock_get_status):
self.base_scenario._init_clients()
self.assertIsNone(self.base_scenario.check_verification('id_cluster'))