Ejemplo n.º 1
0
    def test_unknown_node_instance_evaluation(self):
        yaml = """
node_types:
    webserver_type: {}
node_templates:
    webserver:
        type: webserver_type
outputs:
    port:
        description: p0
        value: { get_attribute: [ webserver, port ] }
"""
        parsed = self.parse(yaml)

        def get_node_instances(node_id=None):
            return []

        try:
            functions.evaluate_outputs(parsed['outputs'],
                                       get_node_instances,
                                       None, None)
            self.fail()
        except exceptions.FunctionEvaluationError as e:
            self.assertIn('Node specified in function does not exist', str(e))
            self.assertIn('webserver', str(e))
Ejemplo n.º 2
0
    def test_invalid_multi_instance_evaluation(self):
        yaml = """
node_types:
    webserver_type: {}
node_templates:
    webserver:
        type: webserver_type
outputs:
    port:
        description: p0
        value: { get_attribute: [ webserver, port ] }
"""
        parsed = self.parse(yaml)

        def get_node_instances():
            node_instance = NodeInstance({
                'node_id': 'webserver',
                'runtime_properties': {
                    'port': 8080
                }
            })
            return [node_instance, node_instance]

        try:
            functions.evaluate_outputs(parsed['outputs'], get_node_instances)
            self.fail()
        except exceptions.FunctionEvaluationError, e:
            self.assertIn('Multi instances of node', str(e))
            self.assertIn('webserver', str(e))
Ejemplo n.º 3
0
    def test_unknown_node_instance_evaluation(self):
        yaml = """
node_types:
    webserver_type: {}
node_templates:
    webserver:
        type: webserver_type
outputs:
    port:
        description: p0
        value: { get_attribute: [ webserver, port ] }
"""
        parsed = self.parse(yaml)

        def get_node_instances(node_id=None):
            return []

        try:
            functions.evaluate_outputs(parsed['outputs'],
                                       get_node_instances,
                                       None, None, None)
            self.fail()
        except exceptions.FunctionEvaluationError, e:
            self.assertIn('Node specified in function does not exist', str(e))
            self.assertIn('webserver', str(e))
Ejemplo n.º 4
0
    def test_invalid_multi_instance_evaluation(self):
        yaml = """
node_types:
    webserver_type: {}
node_templates:
    webserver:
        type: webserver_type
outputs:
    port:
        description: p0
        value: { get_attribute: [ webserver, port ] }
"""
        parsed = self.parse(yaml)

        def get_node_instances():
            node_instance = NodeInstance({
                'node_id': 'webserver',
                'runtime_properties': {
                    'port': 8080
                }
            })
            return [node_instance, node_instance]

        try:
            functions.evaluate_outputs(parsed['outputs'], get_node_instances)
            self.fail()
        except exceptions.FunctionEvaluationError, e:
            self.assertIn('Multi instances of node', str(e))
            self.assertIn('webserver', str(e))
 def outputs(self):
     return dsl_functions.evaluate_outputs(
         outputs_def=self.plan['outputs'],
         get_node_instances_method=self.storage.get_node_instances,
         get_node_instance_method=self.storage.get_node_instance,
         get_node_method=self.storage.get_node,
         get_secret_method=self.storage.get_secret)
Ejemplo n.º 6
0
    def test_valid_evaluation(self):
        yaml = """
node_types:
    webserver_type: {}
node_templates:
    webserver:
        type: webserver_type
outputs:
    port:
        description: p0
        value: { get_attribute: [ webserver, port ] }
"""
        parsed = self.parse(yaml)

        def get_node_instances():
            return [
                NodeInstance({
                    'node_id': 'webserver',
                    'runtime_properties': {
                        'port': 8080
                    }
                })
            ]
        o = functions.evaluate_outputs(parsed['outputs'], get_node_instances)
        self.assertEqual(8080, o['port'])
Ejemplo n.º 7
0
 def outputs(self):
     return dsl_functions.evaluate_outputs(
         outputs_def=self.plan['outputs'],
         get_node_instances_method=self.storage.get_node_instances,
         get_node_instance_method=self.storage.get_node_instance,
         get_node_method=self.storage.get_node,
         get_secret_method=self.storage.get_secret)
Ejemplo n.º 8
0
    def test_invalid_multi_instance_evaluation(self):
        yaml = """
node_types:
    webserver_type: {}
node_templates:
    webserver:
        type: webserver_type
outputs:
    port:
        description: p0
        value: { get_attribute: [ webserver, port ] }
"""
        parsed = self.parse(yaml)

        instance = {
            'id': 'webserver1',
            'node_id': 'webserver',
            'runtime_properties': {
                'port': 8080
            }
        }
        storage = self.mock_evaluation_storage(
            node_instances=[instance, instance], nodes=[{
                'id': 'webserver'
            }])
        outputs = functions.evaluate_outputs(parsed['outputs'], storage)
        self.assertIn('unambiguously', outputs['port'])
        self.assertIn('webserver', outputs['port'])
Ejemplo n.º 9
0
    def test_valid_evaluation(self):
        yaml = """
node_types:
    webserver_type: {}
node_templates:
    webserver:
        type: webserver_type
outputs:
    port:
        description: p0
        value: { get_attribute: [ webserver, port ] }
"""
        parsed = self.parse(yaml)

        def get_node_instances():
            return [
                NodeInstance({
                    'node_id': 'webserver',
                    'runtime_properties': {
                        'port': 8080
                    }
                })
            ]

        o = functions.evaluate_outputs(parsed['outputs'], get_node_instances)
        self.assertEqual(8080, o['port'])
Ejemplo n.º 10
0
def evaluate_deployment_outputs(deployment_id):
    sm = get_storage_manager()
    deployment = sm.get(Deployment, deployment_id, include=['outputs'])
    methods = _get_methods(deployment_id, sm)

    try:
        return functions.evaluate_outputs(outputs_def=deployment.outputs,
                                          **methods)
    except parser_exceptions.FunctionEvaluationError, e:
        raise DeploymentOutputsEvaluationError(str(e))
Ejemplo n.º 11
0
def evaluate_deployment_outputs(deployment_id):
    sm = get_storage_manager()
    deployment = sm.get(Deployment, deployment_id, include=['outputs'])
    storage = FunctionEvaluationStorage(deployment_id, sm)
    if not deployment.outputs:
        return {}

    try:
        return functions.evaluate_outputs(deployment.outputs, storage)
    except parser_exceptions.FunctionEvaluationError as e:
        raise DeploymentOutputsEvaluationError(str(e))
Ejemplo n.º 12
0
    def test_only_one_unknown_node_instance(self):
        yaml = """
node_types:
    webserver_type: {}
    unknown_type: {}
node_templates:
    webserver:
        type: webserver_type
    unknown:
        type: unknown_type
        instances:
            deploy: 0
outputs:
    port:
        value: { get_attribute: [ webserver, endpoint, port ] }
    protocol:
        value: { get_attribute: [ webserver, endpoint, url, protocol ] }
    unknown:
        value: { get_attribute: [ unknown, endpoint ] }
"""
        parsed = self.parse(yaml)

        def get_node_instances(node_id=None):
            if node_id == 'webserver':
                node_instance = NodeInstance({
                   'id': 'webserver1',
                   'node_id': 'webserver',
                   'runtime_properties': {
                       'endpoint': {
                           'url': {
                               'protocol': 'http'
                            },
                           'port': 8080
                       }
                   }
                })
                return [node_instance]
            return []

        def get_node_instance(node_instance_id):
            return get_node_instances()[0]

        def get_node(node_id):
            return Node({'id': node_id})

        outputs = functions.evaluate_outputs(parsed['outputs'],
                                             get_node_instances,
                                             get_node_instance,
                                             get_node,
                                             None)

        self.assertEqual(8080, outputs['port'])
        self.assertEqual('http', outputs['protocol'])
        self.assertIn('Node unknown has no instances', outputs['unknown'])
    def evaluate_deployment_outputs(deployment_id):
        deployment = get_blueprints_manager().get_deployment(
            deployment_id, include=['outputs'])

        def get_node_instances():
            return get_storage_manager().get_node_instances(deployment_id)

        try:
            return functions.evaluate_outputs(deployment.outputs,
                                              get_node_instances)
        except parser_exceptions.FunctionEvaluationError, e:
            raise manager_exceptions.DeploymentOutputsEvaluationError(str(e))
Ejemplo n.º 14
0
    def evaluate_deployment_outputs(deployment_id):
        deployment = get_blueprints_manager().get_deployment(
            deployment_id, include=['outputs'])

        def get_node_instances():
            return get_storage_manager().get_node_instances(deployment_id)

        try:
            return functions.evaluate_outputs(deployment.outputs,
                                              get_node_instances)
        except parser_exceptions.FunctionEvaluationError, e:
            raise manager_exceptions.DeploymentOutputsEvaluationError(str(e))
def evaluate_deployment_outputs(deployment_id):
    sm = get_storage_manager()
    deployment = sm.get(Deployment, deployment_id, include=['outputs'])
    methods = _get_methods(deployment_id, sm)

    try:
        return functions.evaluate_outputs(
            outputs_def=deployment.outputs,
            **methods
            )
    except parser_exceptions.FunctionEvaluationError, e:
        raise DeploymentOutputsEvaluationError(str(e))
Ejemplo n.º 16
0
    def test_invalid_multi_instance_evaluation(self):
        yaml = """
node_types:
    webserver_type: {}
node_templates:
    webserver:
        type: webserver_type
outputs:
    port:
        description: p0
        value: { get_attribute: [ webserver, port ] }
"""
        parsed = self.parse(yaml)

        def get_node_instances(node_id=None):
            node_instance = NodeInstance({
                'id': 'webserver1',
                'node_id': 'webserver',
                'runtime_properties': {
                    'port': 8080
                }
            })
            return [node_instance, node_instance]

        def get_node_instance(node_instance_id):
            return get_node_instances()[0]

        def get_node(node_id):
            return Node({'id': node_id})

        try:
            functions.evaluate_outputs(parsed['outputs'], get_node_instances,
                                       get_node_instance, get_node, None)
            self.fail()
        except exceptions.FunctionEvaluationError as e:
            self.assertIn('unambiguously', str(e))
            self.assertIn('webserver', str(e))
    def test_get_attribute_nested_property(self):
        yaml = """
node_types:
    webserver_type: {}
node_templates:
    webserver:
        type: webserver_type
outputs:
    port:
        value: { get_attribute: [ webserver, endpoint, port ] }
    protocol:
        value: { get_attribute: [ webserver, endpoint, url, protocol ] }
    none:
        value: { get_attribute: [ webserver, endpoint, url, none ] }
"""
        parsed = self.parse(yaml)

        def get_node_instances(node_id=None):
            node_instance = NodeInstance({
                'id': 'webserver1',
                'node_id': 'webserver',
                'runtime_properties': {
                    'endpoint': {
                        'url': {
                            'protocol': 'http'
                        },
                        'port': 8080
                    }
                }
            })
            return [node_instance]

        def get_node_instance(node_instance_id):
            return get_node_instances()[0]

        def get_node(node_id):
            return Node({'id': node_id})

        outputs = functions.evaluate_outputs(parsed['outputs'],
                                             get_node_instances,
                                             get_node_instance,
                                             get_node,
                                             None)
        self.assertEqual(8080, outputs['port'])
        self.assertEqual('http', outputs['protocol'])
        self.assertIsNone(outputs['none'])
Ejemplo n.º 18
0
    def test_get_attribute_nested_property(self):
        yaml = """
node_types:
    webserver_type: {}
node_templates:
    webserver:
        type: webserver_type
outputs:
    port:
        value: { get_attribute: [ webserver, endpoint, port ] }
    protocol:
        value: { get_attribute: [ webserver, endpoint, url, protocol ] }
    none:
        value: { get_attribute: [ webserver, endpoint, url, none ] }
"""
        parsed = self.parse(yaml)

        def get_node_instances(node_id=None):
            node_instance = NodeInstance({
                'id': 'webserver1',
                'node_id': 'webserver',
                'runtime_properties': {
                    'endpoint': {
                        'url': {
                            'protocol': 'http'
                        },
                        'port': 8080
                    }
                }
            })
            return [node_instance]

        def get_node_instance(node_instance_id):
            return get_node_instances()[0]

        def get_node(node_id):
            return Node({'id': node_id})

        outputs = functions.evaluate_outputs(parsed['outputs'],
                                             get_node_instances,
                                             get_node_instance,
                                             get_node,
                                             None)
        self.assertEqual(8080, outputs['port'])
        self.assertEqual('http', outputs['protocol'])
        self.assertIsNone(outputs['none'])
Ejemplo n.º 19
0
    def test_unknown_node_instance_evaluation(self):
        yaml = """
node_types:
    webserver_type: {}
node_templates:
    webserver:
        type: webserver_type
outputs:
    port:
        description: p0
        value: { get_attribute: [ webserver, port ] }
"""
        parsed = self.parse(yaml)

        outputs = functions.evaluate_outputs(parsed['outputs'],
                                             self.mock_evaluation_storage())
        self.assertIn('Node webserver has no instances', outputs['port'])
        self.assertIn('webserver', outputs['port'])
Ejemplo n.º 20
0
    def test_only_one_unknown_node_instance(self):
        yaml = """
node_types:
    webserver_type: {}
    unknown_type: {}
node_templates:
    webserver:
        type: webserver_type
    unknown:
        type: unknown_type
        instances:
            deploy: 0
outputs:
    port:
        value: { get_attribute: [ webserver, endpoint, port ] }
    protocol:
        value: { get_attribute: [ webserver, endpoint, url, protocol ] }
    unknown:
        value: { get_attribute: [ unknown, endpoint ] }
"""
        parsed = self.parse(yaml)

        node_instance = {
            'id': 'webserver1',
            'node_id': 'webserver',
            'runtime_properties': {
                'endpoint': {
                    'url': {
                        'protocol': 'http'
                    },
                    'port': 8080
                }
            }
        }
        storage = self.mock_evaluation_storage(node_instances=[node_instance],
                                               nodes=[{
                                                   'id': 'webserver'
                                               }])
        outputs = functions.evaluate_outputs(parsed['outputs'], storage)

        self.assertEqual(8080, outputs['port'])
        self.assertEqual('http', outputs['protocol'])
        self.assertIn('Node unknown has no instances', outputs['unknown'])
    def evaluate_deployment_outputs(self, deployment_id):
        deployment = self.get_deployment(
            deployment_id, include=['outputs'])

        def get_node_instances(node_id=None):
            return self.sm.get_node_instances(deployment_id, node_id)

        def get_node_instance(node_instance_id):
            return self.sm.get_node_instance(node_instance_id)

        def get_node(node_id):
            return self.sm.get_node(deployment_id, node_id)

        try:
            return functions.evaluate_outputs(
                outputs_def=deployment.outputs,
                get_node_instances_method=get_node_instances,
                get_node_instance_method=get_node_instance,
                get_node_method=get_node)
        except parser_exceptions.FunctionEvaluationError, e:
            raise manager_exceptions.DeploymentOutputsEvaluationError(str(e))
Ejemplo n.º 22
0
    def test_unknown_node_instance_evaluation(self):
        yaml = """
node_types:
    webserver_type: {}
node_templates:
    webserver:
        type: webserver_type
outputs:
    port:
        description: p0
        value: { get_attribute: [ webserver, port ] }
"""
        parsed = self.parse(yaml)

        def get_node_instances(node_id=None):
            return []

        outputs = functions.evaluate_outputs(parsed['outputs'],
                                             get_node_instances,
                                             None, None, None)
        self.assertIn('Node webserver has no instances', outputs['port'])
        self.assertIn('webserver', outputs['port'])
    def evaluate_deployment_outputs(self, deployment_id):
        deployment = self.get_deployment(deployment_id, include=['outputs'])

        def get_node_instances(node_id=None):
            filters = self.create_filters_dict(deployment_id=deployment_id,
                                               node_id=node_id)
            return self.sm.get_node_instances(filters=filters).items

        def get_node_instance(node_instance_id):
            return self.sm.get_node_instance(node_instance_id)

        def get_node(node_id):
            return self.sm.get_node(deployment_id, node_id)

        try:
            return functions.evaluate_outputs(
                outputs_def=deployment.outputs,
                get_node_instances_method=get_node_instances,
                get_node_instance_method=get_node_instance,
                get_node_method=get_node)
        except parser_exceptions.FunctionEvaluationError, e:
            raise manager_exceptions.DeploymentOutputsEvaluationError(str(e))
Ejemplo n.º 24
0
    def test_get_attribute_nested_property(self):
        yaml = """
node_types:
    webserver_type: {}
node_templates:
    webserver:
        type: webserver_type
outputs:
    port:
        value: { get_attribute: [ webserver, endpoint, port ] }
    protocol:
        value: { get_attribute: [ webserver, endpoint, url, protocol ] }
    none:
        value: { get_attribute: [ webserver, endpoint, url, none ] }
"""
        parsed = self.parse(yaml)

        node_instance = {
            'id': 'webserver1',
            'node_id': 'webserver',
            'runtime_properties': {
                'endpoint': {
                    'url': {
                        'protocol': 'http'
                    },
                    'port': 8080
                }
            }
        }
        storage = self.mock_evaluation_storage(node_instances=[node_instance],
                                               nodes=[{
                                                   'id': 'webserver'
                                               }])
        outputs = functions.evaluate_outputs(parsed['outputs'], storage)
        self.assertEqual(8080, outputs['port'])
        self.assertEqual('http', outputs['protocol'])
        self.assertIsNone(outputs['none'])
    def test_registration(self):
        @functions.register(name='to_upper',
                            func_eval_type=functions.HYBRID_FUNC)
        class ToUpper(functions.Function):
            def __init__(self, args, **kwargs):
                self.arg = None
                super(ToUpper, self).__init__(args, **kwargs)

            def parse_args(self, args):
                self.arg = args

            def evaluate(self, handler):
                if functions.parse(self.arg) != self.arg:
                    return self.raw
                return str(self.arg).upper()

            def validate(self, plan):
                pass

        yaml = """
node_types:
    webserver_type:
        properties:
            property:
                default: property_value
node_templates:
    webserver:
        type: webserver_type
outputs:
    output1:
        value: { to_upper: first }
    output2:
        value: { to_upper: { get_property: [webserver, property] } }
    output3:
        value: { to_upper: { get_attribute: [webserver, attribute] } }
    output4:
        value: { to_upper: { get_secret: secret } }
    output5:
        value: { to_upper: { get_capability: [ dep_1, cap_a ] } }
"""
        node_instances = [{
            'id': 'webserver1',
            'node_id': 'webserver',
            'runtime_properties': {
                'attribute': 'attribute_value'
            }
        }]
        nodes = [{'id': 'webserver'}]
        storage = self._mock_evaluation_storage(node_instances, nodes)

        parsed = prepare_deployment_plan(self.parse(yaml), storage.get_secret)

        outputs = parsed['outputs']
        self.assertEqual('FIRST', outputs['output1']['value'])
        self.assertEqual('PROPERTY_VALUE', outputs['output2']['value'])
        self.assertEqual(
            {'to_upper': {
                'get_attribute': ['webserver', 'attribute']
            }}, outputs['output3']['value'])

        outputs = functions.evaluate_outputs(parsed['outputs'], storage)
        self.assertEqual('FIRST', outputs['output1'])
        self.assertEqual('PROPERTY_VALUE', outputs['output2'])
        self.assertEqual('ATTRIBUTE_VALUE', outputs['output3'])
        self.assertEqual('SECRET_VALUE', outputs['output4'])
        self.assertEqual('VALUE_A_1', outputs['output5'])
    def test_registration(self):
        @functions.register(name="to_upper")
        class ToUpper(functions.Function):
            def __init__(self, args, **kwargs):
                self.arg = None
                super(ToUpper, self).__init__(args, **kwargs)

            def parse_args(self, args):
                self.arg = args

            def evaluate_runtime(self, storage):
                return self.evaluate(plan=None)

            def evaluate(self, plan):
                if functions.parse(self.arg) != self.arg:
                    return self.raw
                return str(self.arg).upper()

            def validate(self, plan):
                pass

        yaml = """
node_types:
    webserver_type:
        properties:
            property:
                default: property_value
node_templates:
    webserver:
        type: webserver_type
outputs:
    output1:
        value: { to_upper: first }
    output2:
        value: { to_upper: { get_property: [webserver, property] } }
    output3:
        value: { to_upper: { get_attribute: [webserver, attribute] } }
"""
        parsed = prepare_deployment_plan(self.parse(yaml))
        outputs = parsed["outputs"]
        self.assertEqual("FIRST", outputs["output1"]["value"])
        self.assertEqual("PROPERTY_VALUE", outputs["output2"]["value"])
        self.assertEqual({"to_upper": {"get_attribute": ["webserver", "attribute"]}}, outputs["output3"]["value"])

        def get_node_instances(node_id=None):
            return [
                NodeInstance(
                    {"id": "webserver1", "node_id": "webserver", "runtime_properties": {"attribute": "attribute_value"}}
                )
            ]

        def get_node_instance(node_instance_id):
            return get_node_instances()[0]

        def get_node(node_id):
            return Node({"id": node_id})

        o = functions.evaluate_outputs(parsed["outputs"], get_node_instances, get_node_instance, get_node)

        self.assertEqual("FIRST", o["output1"])
        self.assertEqual("PROPERTY_VALUE", o["output2"])
        self.assertEqual("ATTRIBUTE_VALUE", o["output3"])
Ejemplo n.º 27
0
 def outputs(self):
     return dsl_functions.evaluate_outputs(outputs_def=self.plan['outputs'],
                                           storage=self.storage)
    def test_registration(self):
        @functions.register(name='to_upper')
        class ToUpper(functions.Function):
            def __init__(self, args, **kwargs):
                self.arg = None
                super(ToUpper, self).__init__(args, **kwargs)

            def parse_args(self, args):
                self.arg = args

            def evaluate_runtime(self, storage):
                return self.evaluate(plan=None)

            def evaluate(self, plan):
                if functions.parse(self.arg) != self.arg:
                    return self.raw
                return str(self.arg).upper()

            def validate(self, plan):
                pass

        yaml = """
node_types:
    webserver_type:
        properties:
            property:
                default: property_value
node_templates:
    webserver:
        type: webserver_type
outputs:
    output1:
        value: { to_upper: first }
    output2:
        value: { to_upper: { get_property: [webserver, property] } }
    output3:
        value: { to_upper: { get_attribute: [webserver, attribute] } }
    output4:
        value: { to_upper: { get_secret: secret } }
"""
        parsed = prepare_deployment_plan(self.parse(yaml),
                                         self._get_secret_mock)
        outputs = parsed['outputs']
        self.assertEqual('FIRST', outputs['output1']['value'])
        self.assertEqual('PROPERTY_VALUE', outputs['output2']['value'])
        self.assertEqual(
            {'to_upper': {
                'get_attribute': ['webserver', 'attribute']
            }}, outputs['output3']['value'])

        def get_node_instances(node_id=None):
            return [
                NodeInstance({
                    'id': 'webserver1',
                    'node_id': 'webserver',
                    'runtime_properties': {
                        'attribute': 'attribute_value'
                    }
                })
            ]

        def get_node_instance(node_instance_id):
            return get_node_instances()[0]

        def get_node(node_id):
            return Node({'id': node_id})

        o = functions.evaluate_outputs(parsed['outputs'], get_node_instances,
                                       get_node_instance, get_node,
                                       self._get_secret_mock)

        self.assertEqual('FIRST', o['output1'])
        self.assertEqual('PROPERTY_VALUE', o['output2'])
        self.assertEqual('ATTRIBUTE_VALUE', o['output3'])
        self.assertEqual('SECRET_VALUE', o['output4'])
Ejemplo n.º 29
0
    def test_valid_evaluation(self):
        yaml = """
inputs:
    input:
        default: input_value
node_types:
    webserver_type:
        properties:
            property:
                default: property_value
node_templates:
    webserver:
        type: webserver_type
outputs:
    port:
        description: p0
        value: { get_attribute: [ webserver, port ] }
    endpoint:
        value:
            port: { get_attribute: [ webserver, port ] }
    concatenated:
        value: { concat: [one,
                          {get_property: [webserver, property]},
                          {get_attribute: [webserver, attribute]},
                          {get_input: input},
                          five] }
"""

        def assertion(tested):
            self.assertEqual('one', tested[0])
            self.assertEqual('property_value', tested[1])
            self.assertEqual({'get_attribute': ['webserver', 'attribute']},
                             tested[2])
            self.assertEqual('input_value', tested[3])
            self.assertEqual('five', tested[4])

        parsed = prepare_deployment_plan(self.parse_1_1(yaml))
        concatenated = parsed['outputs']['concatenated']['value']['concat']
        assertion(concatenated)

        def get_node_instances(node_id=None):
            return [
                NodeInstance({
                    'id': 'webserver1',
                    'node_id': 'webserver',
                    'runtime_properties': {
                        'port': 8080,
                        'attribute': 'attribute_value'
                    }
                })
            ]

        def get_node_instance(node_instance_id):
            return get_node_instances()[0]

        def get_node(node_id):
            return Node({'id': node_id})

        o = functions.evaluate_outputs(parsed['outputs'], get_node_instances,
                                       get_node_instance, get_node)
        self.assertEqual(8080, o['port'])
        self.assertEqual(8080, o['endpoint']['port'])
        self.assertEqual('oneproperty_valueattribute_valueinput_valuefive',
                         o['concatenated'])
Ejemplo n.º 30
0
    def test_valid_evaluation(self):
        yaml = """
inputs:
    input:
        default: input_value
node_types:
    webserver_type:
        properties:
            property:
                default: property_value
node_templates:
    webserver:
        type: webserver_type
outputs:
    port:
        description: p0
        value: { get_attribute: [ webserver, port ] }
    endpoint:
        value:
            port: { get_attribute: [ webserver, port ] }
    concatenated:
        value: { concat: [one,
                          {get_property: [webserver, property]},
                          {get_attribute: [webserver, attribute]},
                          {get_input: input},
                          five] }
"""

        def assertion(tested):
            self.assertEqual('one', tested[0])
            self.assertEqual('property_value', tested[1])
            self.assertEqual({'get_attribute': ['webserver', 'attribute']},
                             tested[2])
            self.assertEqual('input_value', tested[3])
            self.assertEqual('five', tested[4])

        parsed = prepare_deployment_plan(self.parse_1_1(yaml))
        concatenated = parsed['outputs']['concatenated']['value']['concat']
        assertion(concatenated)

        def get_node_instances(node_id=None):
            return [
                NodeInstance({
                    'id': 'webserver1',
                    'node_id': 'webserver',
                    'runtime_properties': {
                        'port': 8080,
                        'attribute': 'attribute_value'
                    }
                })
            ]

        def get_node_instance(node_instance_id):
            return get_node_instances()[0]

        def get_node(node_id):
            return Node({'id': node_id})

        o = functions.evaluate_outputs(parsed['outputs'],
                                       get_node_instances,
                                       get_node_instance,
                                       get_node)
        self.assertEqual(8080, o['port'])
        self.assertEqual(8080, o['endpoint']['port'])
        self.assertEqual('oneproperty_valueattribute_valueinput_valuefive',
                         o['concatenated'])
Ejemplo n.º 31
0
    def test_valid_evaluation(self):
        yaml = """
inputs:
    input:
        default: input_value
node_types:
    webserver_type:
        properties:
            property:
                default: property_value
node_templates:
    webserver:
        type: webserver_type
outputs:
    port:
        description: p0
        value: { get_attribute: [ webserver, port ] }
    endpoint:
        value:
            port: { get_attribute: [ webserver, port ] }
    concatenated:
        value: { concat: [one,
                          {get_property: [webserver, property]},
                          {get_attribute: [webserver, attribute]},
                          {get_input: input},
                          {get_secret: secret},
                          {get_capability: [ dep_1, cap_a ]},
                          six] }
"""

        def assertion(tested):
            self.assertEqual('one', tested[0])
            self.assertEqual('property_value', tested[1])
            self.assertEqual({'get_attribute': ['webserver', 'attribute']},
                             tested[2])
            self.assertEqual('input_value', tested[3])
            self.assertEqual({'get_secret': 'secret'}, tested[4])
            self.assertEqual({'get_capability': ['dep_1', 'cap_a']}, tested[5])
            self.assertEqual('six', tested[6])

        instances = [{
            'id': 'webserver1',
            'node_id': 'webserver',
            'runtime_properties': {
                'port': 8080,
                'attribute': 'attribute_value'
            }
        }]
        nodes = [{'id': 'webserver'}]
        storage = self.mock_evaluation_storage(
            instances, nodes, capabilities={'dep_1': {
                'cap_a': 'value_a_1'
            }})

        parsed = prepare_deployment_plan(self.parse_1_1(yaml),
                                         get_secret_method=storage.get_secret)
        concatenated = parsed['outputs']['concatenated']['value']['concat']
        assertion(concatenated)

        outputs = functions.evaluate_outputs(parsed['outputs'], storage)
        self.assertEqual(8080, outputs['port'])
        self.assertEqual(8080, outputs['endpoint']['port'])
        self.assertEqual(
            'oneproperty_valueattribute_'
            'valueinput_valuesecret_valuevalue_a_1six',
            outputs['concatenated'])