dfilppi | 9981f55 | 2017-08-07 20:10:53 +0000 | [diff] [blame^] | 1 | import json |
| 2 | import os |
| 3 | |
| 4 | from cloudify.context import BootstrapContext |
| 5 | |
| 6 | from cloudify.mocks import MockCloudifyContext |
| 7 | |
| 8 | |
| 9 | RETRY_AFTER = 1 |
| 10 | # Time during which no retry could possibly happen. |
| 11 | NO_POSSIBLE_RETRY_TIME = RETRY_AFTER / 2.0 |
| 12 | |
| 13 | BOOTSTRAP_CONTEXTS_WITHOUT_PREFIX = ( |
| 14 | { |
| 15 | }, |
| 16 | { |
| 17 | 'resources_prefix': '' |
| 18 | }, |
| 19 | { |
| 20 | 'resources_prefix': None |
| 21 | }, |
| 22 | ) |
| 23 | |
| 24 | |
| 25 | def set_mock_provider_context(ctx, provider_context): |
| 26 | |
| 27 | def mock_provider_context(provider_name_unused): |
| 28 | return provider_context |
| 29 | |
| 30 | ctx.get_provider_context = mock_provider_context |
| 31 | |
| 32 | |
| 33 | def create_mock_ctx_with_provider_info(*args, **kw): |
| 34 | cur_dir = os.path.dirname(os.path.realpath(__file__)) |
| 35 | full_file_name = os.path.join(cur_dir, 'provider-context.json') |
| 36 | with open(full_file_name) as f: |
| 37 | provider_context = json.loads(f.read())['context'] |
| 38 | kw['provider_context'] = provider_context |
| 39 | kw['bootstrap_context'] = BootstrapContext(provider_context['cloudify']) |
| 40 | return MockCloudifyContext(*args, **kw) |