Skip to content

Commit

Permalink
Fixed bug when parsing bool and fix test helper delay. Also avoid
Browse files Browse the repository at this point in the history
spamming log.
  • Loading branch information
nuwang committed Oct 14, 2015
1 parent 9086b94 commit f76a935
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
19 changes: 12 additions & 7 deletions cloudbridge/providers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,24 @@ def wait_for(self, target_states, terminal_states=None, timeout=600,
end_time = time.time() + timeout
while True:
if self.state in target_states:
log.debug(
"Object: {0} successfully reached target state:"
" {1}".format(self, self.state))
return True
elif self.state in terminal_states:
raise WaitStateException(
"Object: {0} is in state: {1} which is a terminal state"
" and cannot be waited on.".format(self, self.state))
else:
log.debug(
"Object {0} is in state: {1}. Waiting another {2} seconds"
" to reach target state(s): {3}...".format(
self,
self.state,
int(end_time - time.time()),
target_states))
# print output every 30 seconds to avoid spamming log
if (int(end_time - time.time()) % 15 == 0):
log.debug(
"Object {0} is in state: {1}. Waiting another {2}"
" seconds to reach target state(s): {3}...".format(
self,
self.state,
int(end_time - time.time()),
target_states))
time.sleep(interval)
if time.time() > end_time:
raise WaitStateException(
Expand Down
11 changes: 9 additions & 2 deletions test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def create_test_instance(provider, instance_name):

def get_test_instance(provider, name):
instance = create_test_instance(provider, name)
instance.wait_till_ready()
instance.wait_till_ready(interval=TEST_WAIT_INTERVAL)
return instance


Expand Down Expand Up @@ -142,13 +142,20 @@ def generate_test_suite_for_provider(self, provider_class):
map(suite.addTest, suites)
return suite

def _parse_bool(self, val):
if val:
return str(val).upper() in ['TRUE', 'YES']
else:
return False

def generate_tests(self):
"""
Generate and return a suite of tests for all provider and test class
combinations
"""
factory = CloudProviderFactory()
use_mock_drivers = os.environ.get("CB_USE_MOCK_DRIVERS", True)
use_mock_drivers = self._parse_bool(
os.environ.get("CB_USE_MOCK_DRIVERS", True))
provider_name = os.environ.get("CB_TEST_PROVIDER", None)
if provider_name:
provider_classes = [
Expand Down

0 comments on commit f76a935

Please sign in to comment.