コード例 #1
0
ファイル: _stack.py プロジェクト: FedericoRessi/tobiko
    def create_stack(self, retry: tobiko.Retry = None) -> stacks.Stack:
        if config.get_bool_env('TOBIKO_PREVENT_CREATE'):
            stack = self.validate_created_stack()
        else:
            for attempt in tobiko.retry(retry,
                                        count=self.retry_count,
                                        timeout=self.retry_timeout,
                                        interval=0.):
                try:
                    stack = self.try_create_stack()
                    break
                except InvalidStackError:
                    LOG.exception(f"Error creating stack '{self.stack_name}'",
                                  exc_info=1)
                    if attempt.is_last:
                        raise

                    self.delete_stack()

                    # It uses a random time sleep to make conflicting
                    # concurrent creations less probable to occur
                    sleep_time = random_sleep_time(
                        min_time=self.min_retry_interval,
                        max_time=self.max_retry_interval)
                    LOG.debug(
                        f"Failed creating stack '{self.stack_name}' "
                        f"(attempt {attempt.number} of "
                        f"{attempt.count}). It will retry after "
                        f"{sleep_time} seconds",
                        exc_info=1)
                    time.sleep(sleep_time)
            else:
                raise RuntimeError('Retry loop broken')
        return stack
コード例 #2
0
    def test_get_bool_env(self):
        env_option = "TEST_OPTION"

        true_values = ['True', 'true', 'TRUE', 'TrUe', '1']
        false_values = ['False', 'false', 'FALSE', 'FaLsE', '0']
        invalid_values = [None, 'something else', '']

        for value in true_values:
            with mock.patch.dict('os.environ', {env_option: value}):
                self.assertIs(True, config.get_bool_env(env_option))

        for value in false_values:
            with mock.patch.dict('os.environ', {env_option: value}):
                self.assertIs(False, config.get_bool_env(env_option))

        for value in invalid_values:
            with mock.patch.dict('os.environ', {env_option: value}):
                self.assertIsNone(config.get_bool_env(env_option))
コード例 #3
0
ファイル: _image.py プロジェクト: 4383/tobiko
    def __init__(self, disk_format=None, container_format=None, **kwargs):
        super(UploadGranceImageFixture, self).__init__(**kwargs)

        if container_format:
            self.container_format = disk_format
        tobiko.check_valid_type(self.container_format, str)

        if disk_format:
            self.disk_format = disk_format
        tobiko.check_valid_type(self.disk_format, str)

        self.prevent_image_create = get_bool_env('TOBIKO_PREVENT_CREATE')
コード例 #4
0
ファイル: _stack.py プロジェクト: 4383/tobiko
    def __init__(self, stack_name=None, template=None, parameters=None,
                 wait_interval=None, client=None):
        super(HeatStackFixture, self).__init__()
        self.stack_name = stack_name = (stack_name or
                                        self.stack_name or
                                        self.fixture_name)

        self.template = _template.heat_template(template or self.template)
        self.parameters = heat_stack_parameters(
            stack=self, obj=(parameters or self.parameters))
        self.client = client or self.client
        if config.get_bool_env('TOBIKO_PREVENT_CREATE'):
            self.retry_create_stack = 0

        if wait_interval:
            self.wait_interval = wait_interval
コード例 #5
0
ファイル: _operation.py プロジェクト: FedericoRessi/tobiko
 def setup_fixture(self):
     from tobiko import config
     self.after_operations = set(
         config.get_list_env('TOBIKO_AFTER_OPERATIONS'))
     self.run_operations = config.get_bool_env(
         'TOBIKO_RUN_OPERATIONS') or False