def wait_for_stack_action_to_complete(self, stack_name, action, timeout): allowed_actions = ["create", "update", "delete"] assert action.lower() in allowed_actions, "action argument must be one of {0}".format(allowed_actions) time_jitter_window = timedelta(seconds=10) minimum_event_timestamp = get_cfn_api_server_time() - time_jitter_window expected_start_event_state = action.upper() + "_IN_PROGRESS" start_event = self.wait_for_stack_event(stack_name, expected_start_event_state, minimum_event_timestamp, timeout=120) self.logger.info("Stack {0} started".format(action)) minimum_event_timestamp = start_event["Timestamp"] expected_complete_event_state = action.upper() + "_COMPLETE" end_event = self.wait_for_stack_event(stack_name, expected_complete_event_state, minimum_event_timestamp, timeout) elapsed = end_event["Timestamp"] - start_event["Timestamp"] self.logger.info("Stack {0} completed after {1}s".format(action, elapsed.seconds))
def wait_for_stack_action_to_complete(self, stack_name, action, timeout): allowed_actions = ["create", "update", "delete"] assert action.lower( ) in allowed_actions, "action argument must be one of {0}".format( allowed_actions) time_jitter_window = timedelta(seconds=10) minimum_event_timestamp = get_cfn_api_server_time( ) - time_jitter_window expected_start_event_state = action.upper() + "_IN_PROGRESS" start_event = self.wait_for_stack_event(stack_name, expected_start_event_state, minimum_event_timestamp, timeout=120) self.logger.info("Stack {0} started".format(action)) minimum_event_timestamp = start_event["Timestamp"] expected_complete_event_state = action.upper() + "_COMPLETE" end_event = self.wait_for_stack_event(stack_name, expected_complete_event_state, minimum_event_timestamp, timeout) elapsed = end_event["Timestamp"] - start_event["Timestamp"] self.logger.info("Stack {0} completed after {1}s".format( action, elapsed.seconds))
def test_get_cfn_api_server_time_returns_gmt_datetime(self, urlopen_mock): urlopen_mock.return_value.info.return_value.get.return_value = "Mon, 21 Sep 2015 17:17:26 GMT" expected_timestamp = datetime(year=2015, month=9, day=21, hour=17, minute=17, second=26, tzinfo=tzutc()) self.assertEqual(expected_timestamp, util.get_cfn_api_server_time())
def test_get_cfn_api_server_time_raises_exception_on_empty_date_header(self, urlopen_mock): urlopen_mock.return_value.info.return_value.get.return_value = "" with self.assertRaises(CfnSphereException): util.get_cfn_api_server_time()