1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
18 from aria.utils.caching import cachedmethod
19 from aria.parser.loading import LiteralLocation
21 from .utils import (create_context, create_consumer)
22 from ..helpers import (get_example_uri, get_service_template_uri)
25 def consume_literal(literal, consumer_class_name='instance', cache=True, no_issues=True):
26 cachedmethod.ENABLED = cache
27 context = create_context(LiteralLocation(literal))
28 consumer, dumper = create_consumer(context, consumer_class_name)
31 context.validation.dump_issues()
32 assert not context.validation.has_issues
33 return context, dumper
36 def consume_use_case(use_case_name, consumer_class_name='instance', cache=True):
37 cachedmethod.ENABLED = cache
38 uri = get_example_uri('tosca-simple-1.0', 'use-cases', use_case_name,
39 '{0}.yaml'.format(use_case_name))
40 context = create_context(uri)
41 inputs_file = get_example_uri('tosca-simple-1.0', 'use-cases', use_case_name, 'inputs.yaml')
42 if os.path.isfile(inputs_file):
43 context.args.append('--inputs={0}'.format(inputs_file))
44 consumer, dumper = create_consumer(context, consumer_class_name)
46 context.validation.dump_issues()
47 assert not context.validation.has_issues
48 return context, dumper
51 def consume_types_use_case(use_case_name, consumer_class_name='instance', cache=True):
52 cachedmethod.ENABLED = cache
53 uri = get_service_template_uri('tosca-simple-1.0', 'types', use_case_name,
54 '{0}.yaml'.format(use_case_name))
55 context = create_context(uri)
56 inputs_file = get_example_uri('tosca-simple-1.0', 'types', use_case_name, 'inputs.yaml')
57 if os.path.isfile(inputs_file):
58 context.args.append('--inputs={0}'.format(inputs_file))
59 consumer, dumper = create_consumer(context, consumer_class_name)
61 context.validation.dump_issues()
62 assert not context.validation.has_issues
63 return context, dumper
66 def consume_node_cellar(consumer_class_name='instance', cache=True):
68 get_service_template_uri('tosca-simple-1.0', 'node-cellar', 'node-cellar.yaml'),
69 consumer_class_name=consumer_class_name,
70 inputs_uri=get_service_template_uri('tosca-simple-1.0', 'node-cellar', 'inputs.yaml'),
76 def consume_test_case(uri, inputs_uri=None, consumer_class_name='instance', cache=True):
77 cachedmethod.ENABLED = cache
78 uri = get_service_template_uri(uri)
79 context = create_context(uri)
81 context.args.append('--inputs=' + get_service_template_uri(inputs_uri))
82 consumer, dumper = create_consumer(context, consumer_class_name)
84 context.validation.dump_issues()
85 assert not context.validation.has_issues
86 return context, dumper