From f31d3a69e14dccd6d1145fee22ef1c439e1f029d Mon Sep 17 00:00:00 2001 From: EarthmanT Date: Tue, 16 Mar 2021 14:40:23 +0200 Subject: [PATCH] Rd 1714 (#50) * fix image fetch (#49) * __NODOCS__ * __NODOCS__ * 1 * update test * updates * handle teardown on uninstall Co-authored-by: AdarShaked <59121240+AdarShaked@users.noreply.github.com> --- .circleci/config.yml | 2 +- .circleci/test_examples.py | 45 ++++++++++++-------------------- .circleci/update_test_manager.py | 2 +- CHANGELOG.txt | 2 ++ cloudify_tf/tasks.py | 2 ++ cloudify_tf/utils.py | 18 +++++++++++++ plugin.yaml | 2 +- 7 files changed, 41 insertions(+), 32 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b98b896..f8f0731 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -260,7 +260,7 @@ commands: run_tf_vm_test: steps: - - run: ecosystem-test local-blueprint-test -b examples/blueprint-examples/virtual-machine/aws-terraform.yaml --test-id=virtual-machine -i aws_region_name=us-east-1 --on-failure=uninstall-force --timeout=1800 + - run: ecosystem-test local-blueprint-test -b examples/blueprint-examples/virtual-machine/aws-terraform.yaml --test-id=virtual-machine -i aws_region_name=us-east-1 --on-failure=uninstall-force --timeout=1800 --nested-test=.circleci/test_examples.py --uninstall-on-success=false jobs: diff --git a/.circleci/test_examples.py b/.circleci/test_examples.py index c6e962f..c8e949f 100644 --- a/.circleci/test_examples.py +++ b/.circleci/test_examples.py @@ -13,37 +13,24 @@ # See the License for the specific language governing permissions and # limitations under the License. +import unittest -import os -import pytest +from ecosystem_tests.dorkl.runners import handle_uninstall_on_success +from ecosystem_tests.dorkl import (cleanup_on_failure, executions_start) -from ecosystem_tests.dorkl import ( - basic_blueprint_test, - cleanup_on_failure, prepare_test -) +reload_url = 'https://github.com/cloudify-community/blueprint-examples/' \ + 'raw/master/virtual-machine/resources/terraform/template.zip' -SECRETS_TO_CREATE = { - 'aws_access_key_id': False, - 'aws_secret_access_key': False, -} -prepare_test(secrets=SECRETS_TO_CREATE) +class TestWorflow(unittest.TestCase): -blueprint_list = [ - 'examples/blueprint-examples/virtual-machine/aws-terraform.yaml'] - - -@pytest.fixture(scope='function', params=blueprint_list) -def blueprint_examples(request): - dirname_param = os.path.dirname(request.param).split('/')[-1:][0] - try: - basic_blueprint_test( - request.param, dirname_param, - inputs='aws_region_name=us-east-1', timeout=3000) - except: - cleanup_on_failure(dirname_param) - raise - - -def test_blueprints(blueprint_examples): - assert blueprint_examples is None + def test_blueprint_examples(self): + try: + executions_start('reload_terraform_template', + 'virtual-machine', + timeout=300, + params={'source': reload_url}) + except: + cleanup_on_failure('virtual-machine') + raise + handle_uninstall_on_success('virtual-machine', 300) diff --git a/.circleci/update_test_manager.py b/.circleci/update_test_manager.py index 3e5131a..6f79fd3 100644 --- a/.circleci/update_test_manager.py +++ b/.circleci/update_test_manager.py @@ -1,6 +1,6 @@ from os import path, pardir -from ecosystem_tests.dorkl import replace_plugin_package_on_manager from ecosystem_cicd_tools.validations import validate_plugin_version +from ecosystem_tests.dorkl.commands import replace_plugin_package_on_manager abs_path = path.join( path.abspath(path.join(path.dirname(__file__), pardir))) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 91647e9..92374c3 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,5 @@ +0.15.3: + - Fix bug in reload. 0.15.2: - Fix permission denied issue with installing terraform plugins. 0.15.1: diff --git a/cloudify_tf/tasks.py b/cloudify_tf/tasks.py index 5f74108..e5e2f97 100644 --- a/cloudify_tf/tasks.py +++ b/cloudify_tf/tasks.py @@ -96,6 +96,8 @@ def reload_template(ctx, source, destroy_previous, **_): raise NonRecoverableError( "New source path/URL for Terraform template was not provided") + source = utils.handle_previous_source_format(source) + if destroy_previous: with utils.get_terraform_source() as terraform_source: _destroy(Terraform.from_ctx(ctx, terraform_source)) diff --git a/cloudify_tf/utils.py b/cloudify_tf/utils.py index 9cb3495..0d83de7 100644 --- a/cloudify_tf/utils.py +++ b/cloudify_tf/utils.py @@ -15,12 +15,14 @@ import os import copy +import json import base64 import ntpath import shutil import zipfile import filecmp import tempfile +import requests import threading import subprocess from io import BytesIO @@ -717,6 +719,22 @@ def refresh_resources_properties(state): ctx.instance.runtime_properties['resources'] = resources +def is_url(string): + try: + return requests.get(string) + except requests.ConnectionError: + return False + + +def handle_previous_source_format(source): + try: + return json.loads(source) + except ValueError: + if is_url(source): + return {'location': source} + return source + + # Stolen from the script plugin, until this class # moves to a utils module in cloudify-common. class OutputConsumer(object): diff --git a/plugin.yaml b/plugin.yaml index 8a844e8..3de41b3 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -2,7 +2,7 @@ plugins: tf: executor: central_deployment_agent package_name: cloudify-terraform-plugin - package_version: '0.15.2' + package_version: '0.15.3' dsl_definitions: