diff options
Diffstat (limited to 'helm/plugin/tests')
-rw-r--r-- | helm/plugin/tests/__init__.py | 14 | ||||
-rw-r--r-- | helm/plugin/tests/blueprint/blueprint.yaml | 42 | ||||
-rw-r--r-- | helm/plugin/tests/blueprint/plugin/test_plugin.yaml | 20 | ||||
-rw-r--r-- | helm/plugin/tests/test_plugin.py | 47 |
4 files changed, 123 insertions, 0 deletions
diff --git a/helm/plugin/tests/__init__.py b/helm/plugin/tests/__init__.py new file mode 100644 index 0000000..749f68f --- /dev/null +++ b/helm/plugin/tests/__init__.py @@ -0,0 +1,14 @@ +######## +# Copyright (c) 2014 GigaSpaces Technologies Ltd. All rights reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. diff --git a/helm/plugin/tests/blueprint/blueprint.yaml b/helm/plugin/tests/blueprint/blueprint.yaml new file mode 100644 index 0000000..2588e8d --- /dev/null +++ b/helm/plugin/tests/blueprint/blueprint.yaml @@ -0,0 +1,42 @@ +# DSL version, should appear in the main blueprint.yaml +# and may appear in other imports. In such case, the versions must match +tosca_definitions_version: cloudify_dsl_1_3 + +imports: + # importing cloudify related types, plugins, workflow, etc... + # to speed things up, it is possible downloading this file, + # including it in the blueprint directory and importing it + # instead. + - http://www.getcloudify.org/spec/cloudify/4.1.1/types.yaml + # relative import of plugin.yaml that resides in the blueprint directory + - plugin/test_plugin.yaml + +inputs: + # example input that could be injected by test + test_input: + description: an input for the test + default: default_test_input + +node_templates: + # defining a single node template that will serve as our test node + test_node_template: + # using base cloudify type + type: cloudify.nodes.Root + interfaces: + cloudify.interfaces.lifecycle: + start: + # here we map the single plugin task to the start operation + # of the cloudify.interfaces.lifecycle interface + implementation: plugin_name.plugin.tasks.my_task + inputs: + # my_task accepts a single property named + # some property. Here we inject this property + # from the input provided by the test + # (or 'default_test_input' if no input was provided) + some_property: { get_input: test_input } + +outputs: + # example output the could be used to simplify assertions by test + test_output: + description: an output for the test + value: { get_attribute: [test_node_template, some_property] } diff --git a/helm/plugin/tests/blueprint/plugin/test_plugin.yaml b/helm/plugin/tests/blueprint/plugin/test_plugin.yaml new file mode 100644 index 0000000..9701318 --- /dev/null +++ b/helm/plugin/tests/blueprint/plugin/test_plugin.yaml @@ -0,0 +1,20 @@ +plugins: + # Name could be anything, this name is what appears on the beginning of operation + # mappings. + plugin_name: + # Could be 'central_deployment_agent' or 'host_agent'. + # If 'central_deployment_agent', this plugin will be executed on the + # deployment dedicated agent, other wise it will be executed on the host agent. + # We set it the 'central_deployment_agent' here because 'host_agent' plugins should + # be contained in a host and this is not required for testing purposes + executor: central_deployment_agent + + # Setting install to false in testing environment. In the non-test plugin definition + # this property could be omitted usually (its default is true), in which case + # the source property should be set + install: false + + # source: URL to archive containing the plugin or name of directory containing + # the plugin if it is included in the the blueprint directory under the + # "plugins" directory. Not required in testing environments as the plugin + # need not be installed on any agent diff --git a/helm/plugin/tests/test_plugin.py b/helm/plugin/tests/test_plugin.py new file mode 100644 index 0000000..be0882f --- /dev/null +++ b/helm/plugin/tests/test_plugin.py @@ -0,0 +1,47 @@ +######## +# Copyright (c) 2014 GigaSpaces Technologies Ltd. All rights reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. + + +from os import path +import unittest + +from cloudify.test_utils import workflow_test + + +class TestPlugin(unittest.TestCase): + + @workflow_test(path.join('blueprint', 'blueprint.yaml'), + resources_to_copy=[(path.join('blueprint', 'plugin', + 'test_plugin.yaml'), + 'plugin')], + inputs={'test_input': 'new_test_input'}) + def test_my_task(self, cfy_local): + # execute install workflow + """ + + :param cfy_local: + """ + cfy_local.execute('install', task_retries=0) + + # extract single node instance + instance = cfy_local.storage.get_node_instances()[0] + + # assert runtime properties is properly set in node instance + self.assertEqual(instance.runtime_properties['some_property'], + 'new_test_input') + + # assert deployment outputs are ok + self.assertDictEqual(cfy_local.outputs(), + {'test_output': 'new_test_input'}) |