Skip to content

Commit

Permalink
Rd 1714 (#50)
Browse files Browse the repository at this point in the history
* fix image fetch (#49)

* __NODOCS__

* __NODOCS__

* 1

* update test

* updates

* handle teardown on uninstall

Co-authored-by: AdarShaked <[email protected]>
  • Loading branch information
EarthmanT and AdarShaked authored Mar 16, 2021
1 parent ffef7ee commit f31d3a6
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
45 changes: 16 additions & 29 deletions .circleci/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion .circleci/update_test_manager.py
Original file line number Diff line number Diff line change
@@ -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)))
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 2 additions & 0 deletions cloudify_tf/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
18 changes: 18 additions & 0 deletions cloudify_tf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit f31d3a6

Please sign in to comment.