Replacing hard coded cluster status using utils in sahara-client

Change-Id: I8e0f20c82297a552a6d88949829b974c5c75040c
Closes-bug: 1517061
This commit is contained in:
luhuichun 2015-11-19 18:56:39 +08:00
parent c28fb03ad0
commit b31554e74e
2 changed files with 9 additions and 5 deletions

View File

@ -19,6 +19,7 @@ import time
import saharaclient.api.base as api_base
from saharaclient.tests.integration.configs import config as cfg
import saharaclient.tests.integration.tests.base as base
import saharaclient.tests.integration.tests.utils as ut
from neutronclient.v2_0 import client as neutron_client
import novaclient.exceptions
@ -264,12 +265,12 @@ class ClusterTest(base.ITestBase):
# Always skip teardown if we used an existing cluster
skip_teardown = True
status = self.util.poll_cluster_state(self.cluster.id)
self.assertEqual('Active', status)
self.assertEqual(ut.CLUSTER_STATUS_ACTIVE, status)
else:
try:
self.build_cluster(config, ng_templates)
status = self.util.poll_cluster_state(self.cluster.id)
self.assertEqual('Active', status)
self.assertEqual(ut.CLUSTER_STATUS_ACTIVE, status)
except Exception as e:
if not skip_teardown:
self.teardown_via_client()

View File

@ -24,12 +24,15 @@ import six
import saharaclient.api.client as client
from saharaclient.tests.integration.configs import config as cfg
from swiftclient import client as swift_client
cfg = cfg.ITConfig()
common = cfg.common_config
# cluster status
CLUSTER_STATUS_ACTIVE = "Active"
CLUSTER_STATUS_ERROR = "Error"
class Utils(object):
def __init__(self):
@ -120,8 +123,8 @@ class Utils(object):
# TODO(tmckay): this should use timeutils but we need
# to add it to openstack/common
timeout = common['CLUSTER_CREATION_TIMEOUT'] * 60
while str(cluster.status) != 'Active':
if str(cluster.status) == 'Error' or timeout <= 0:
while str(cluster.status) != CLUSTER_STATUS_ACTIVE:
if str(cluster.status) == CLUSTER_STATUS_ERROR or timeout <= 0:
break
time.sleep(10)
timeout -= 10