From b7fac611729a1ee86b857693b7505ffc369e0501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henar=20Mu=C3=B1oz=20Frutos?= Date: Mon, 27 Apr 2015 13:32:27 +0200 Subject: [PATCH] Functional tests for Chef and Puppet examples This commit introduces some functional tests for Chef and Puppet example applications. Depends-On: I1363e46d655c8a641a1fa404faadc5f652f9fce4 Change-Id: I0a455d02a08d7c695f9f39e86b0dbb8b87deb5f2 --- murano/tests/functional/common/utils.py | 8 +- .../functional/engine/config.conf.sample | 3 + murano/tests/functional/engine/config.py | 3 + .../Classes/ExampleChef.yaml | 48 ++++++++++ .../Resources/DeployExampleChef.template | 22 +++++ .../Resources/scripts/test/README.rdoc | 7 ++ .../Resources/scripts/test/metadata.rb | 8 ++ .../Resources/scripts/test/recipes/install.rb | 10 +++ .../manifest.yaml | 10 +++ .../Classes/ExamplePuppet.yaml | 46 ++++++++++ .../Resources/DeployExamplePuppet.template | 20 +++++ .../scripts/test/manifests/install.pp | 4 + .../manifest.yaml | 10 +++ .../engine/test_conf_language_support.py | 87 +++++++++++++++++++ 14 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Classes/ExampleChef.yaml create mode 100644 murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Resources/DeployExampleChef.template create mode 100644 murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Resources/scripts/test/README.rdoc create mode 100644 murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Resources/scripts/test/metadata.rb create mode 100644 murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Resources/scripts/test/recipes/install.rb create mode 100644 murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/manifest.yaml create mode 100644 murano/tests/functional/engine/io.murano.conflang.puppet.ExamplePuppet/Classes/ExamplePuppet.yaml create mode 100644 murano/tests/functional/engine/io.murano.conflang.puppet.ExamplePuppet/Resources/DeployExamplePuppet.template create mode 100644 murano/tests/functional/engine/io.murano.conflang.puppet.ExamplePuppet/Resources/scripts/test/manifests/install.pp create mode 100644 murano/tests/functional/engine/io.murano.conflang.puppet.ExamplePuppet/manifest.yaml create mode 100644 murano/tests/functional/engine/test_conf_language_support.py diff --git a/murano/tests/functional/common/utils.py b/murano/tests/functional/common/utils.py index c69a9c708..ff5cba4b4 100644 --- a/murano/tests/functional/common/utils.py +++ b/murano/tests/functional/common/utils.py @@ -22,10 +22,12 @@ import time from heatclient import client as heatclient from keystoneclient import exceptions as ks_exceptions -from keystoneclient.v2_0 import client as ksclient +import keystoneclient.v2_0 as keystoneclientv2 +import keystoneclient.v3 as keystoneclientv3 from muranoclient import client as mclient import muranoclient.common.exceptions as exceptions from oslo_log import log as logging +import re import yaml from murano.services import states @@ -77,6 +79,10 @@ class DeployTestMixin(zip_utils.ZipUtilsMixin): @memoize def keystone_client(): region = CONF.murano.region_name + if re.match(".*/v3/?$", CONF.murano.auth_url): + ksclient = keystoneclientv3 + else: + ksclient = keystoneclientv2 return ksclient.Client(username=CONF.murano.user, password=CONF.murano.password, tenant_name=CONF.murano.tenant, diff --git a/murano/tests/functional/engine/config.conf.sample b/murano/tests/functional/engine/config.conf.sample index 4ff065461..7bbe847a7 100644 --- a/murano/tests/functional/engine/config.conf.sample +++ b/murano/tests/functional/engine/config.conf.sample @@ -26,6 +26,9 @@ # image for linux services # linux_image = default_linux +# murano instance type +# instance_type = io.murano.resources.LinuxMuranoInstance + # image for docker applications # docker_image = debian-8-docker.qcow2 diff --git a/murano/tests/functional/engine/config.py b/murano/tests/functional/engine/config.py index 1a04ea39f..36222b515 100644 --- a/murano/tests/functional/engine/config.py +++ b/murano/tests/functional/engine/config.py @@ -47,6 +47,9 @@ MuranoGroup = [ cfg.StrOpt('linux_image', default='default_linux', help="image for linux services"), + cfg.StrOpt('instance_type', + default='io.murano.resources.LinuxMuranoInstance', + help="murano instance type"), cfg.StrOpt('docker_image', default='ubuntu14.04-x64-docker', help="image for docker applications"), diff --git a/murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Classes/ExampleChef.yaml b/murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Classes/ExampleChef.yaml new file mode 100644 index 000000000..66574258f --- /dev/null +++ b/murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Classes/ExampleChef.yaml @@ -0,0 +1,48 @@ +Namespaces: + =: io.murano.conflang.chef.ExampleChef + std: io.murano + res: io.murano.resources + sys: io.murano.system + + +Name: ExampleChef + +Extends: std:Application + +Properties: + + instance: + Contract: $.class(res:Instance).notNull() + + + +Methods: + initialize: + Body: + - $._environment: $.find(std:Environment).require() + + deploy: + Body: + - If: not $.getAttr(deployed, false) + Then: + - $._environment.reporter.report($this, 'Creating VM for Chef example ') + - $securityGroupIngress: + - ToPort: 22 + FromPort: 22 + IpProtocol: tcp + External: true + - $._environment.securityGroupManager.addGroupIngress($securityGroupIngress) + - $.instance.deploy() + - $resources: new(sys:Resources) + # Deploy Chef example + - $template: $resources.yaml('DeployExampleChef.template') + + - $._environment.reporter.report($this, 'Instance is created. Deploying Chef example') + - $.instance.agent.call($template, $resources) + - If: $.instance.assignFloatingIp + Then: + - $host: $.instance.floatingIpAddress + Else: + - $host: $.instance.ipAddresses[0] + - $._environment.reporter.report($this, format('Chef example is installed at {0}', $host)) + - $.setAttr(deployed, true) diff --git a/murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Resources/DeployExampleChef.template b/murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Resources/DeployExampleChef.template new file mode 100644 index 000000000..554a16667 --- /dev/null +++ b/murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Resources/DeployExampleChef.template @@ -0,0 +1,22 @@ +FormatVersion: 2.1.0 +Version: 1.0.0 +Name: Deploy Example Chef + +Parameters: + port: $port + +Body: | + return executeRecipe(args).stdout + +Scripts: + executeRecipe: + Type: Chef + Version: 1.0.0 + EntryPoint: test::install + Files: + - test/recipes/install.rb + - test/metadata.rb + - test/README.rdoc + Options: + captureStdout: true + captureStderr: true diff --git a/murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Resources/scripts/test/README.rdoc b/murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Resources/scripts/test/README.rdoc new file mode 100644 index 000000000..131c9eb60 --- /dev/null +++ b/murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Resources/scripts/test/README.rdoc @@ -0,0 +1,7 @@ += DESCRIPTION: + += REQUIREMENTS: + += ATTRIBUTES: + += USAGE: \ No newline at end of file diff --git a/murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Resources/scripts/test/metadata.rb b/murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Resources/scripts/test/metadata.rb new file mode 100644 index 000000000..1f866d34f --- /dev/null +++ b/murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Resources/scripts/test/metadata.rb @@ -0,0 +1,8 @@ +#comment +maintainer "Telefonica I+D" +maintainer_email "henar@tid.es" +name "test" +license "All rights reserved" +description "Default cookbook for testing" +long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc')) +version "0.1.0" \ No newline at end of file diff --git a/murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Resources/scripts/test/recipes/install.rb b/murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Resources/scripts/test/recipes/install.rb new file mode 100644 index 000000000..653968ae4 --- /dev/null +++ b/murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/Resources/scripts/test/recipes/install.rb @@ -0,0 +1,10 @@ +script "install" do + interpreter "bash" + user "root" + cwd "/opt" + code <<-EOH + echo test install + EOH +end + +node.normal['test']['action_test'] = "install" \ No newline at end of file diff --git a/murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/manifest.yaml b/murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/manifest.yaml new file mode 100644 index 000000000..a3a223ee1 --- /dev/null +++ b/murano/tests/functional/engine/io.murano.conflang.chef.ExampleChef/manifest.yaml @@ -0,0 +1,10 @@ +Format: 1.0 +Type: Application +FullName: io.murano.conflang.chef.ExampleChef +Name: ExampleChef +Description: | + Example Chef. +Author: 'TID' +Tags: [Test, Chef] +Classes: + io.murano.conflang.chef.ExampleChef: ExampleChef.yaml diff --git a/murano/tests/functional/engine/io.murano.conflang.puppet.ExamplePuppet/Classes/ExamplePuppet.yaml b/murano/tests/functional/engine/io.murano.conflang.puppet.ExamplePuppet/Classes/ExamplePuppet.yaml new file mode 100644 index 000000000..6e5c8becc --- /dev/null +++ b/murano/tests/functional/engine/io.murano.conflang.puppet.ExamplePuppet/Classes/ExamplePuppet.yaml @@ -0,0 +1,46 @@ +Namespaces: + =: io.murano.conflang.puppet.ExamplePuppet + std: io.murano + res: io.murano.resources + sys: io.murano.system + + +Name: ExamplePuppet + +Extends: std:Application + +Properties: + + instance: + Contract: $.class(res:Instance).notNull() + +Methods: + initialize: + Body: + - $._environment: $.find(std:Environment).require() + + deploy: + Body: + - If: not $.getAttr(deployed, false) + Then: + - $._environment.reporter.report($this, 'Creating VM for Example Chef example ') + - $securityGroupIngress: + - ToPort: 22 + FromPort: 22 + IpProtocol: tcp + External: true + - $._environment.securityGroupManager.addGroupIngress($securityGroupIngress) + - $.instance.deploy() + - $resources: new(sys:Resources) + # Deploy Puppet example + - $template: $resources.yaml('DeployExamplePuppet.template') + + - $._environment.reporter.report($this, 'Instance is created. Deploying Example Puppet') + - $.instance.agent.call($template, $resources) + - If: $.instance.assignFloatingIp + Then: + - $host: $.instance.floatingIpAddress + Else: + - $host: $.instance.ipAddresses[0] + - $._environment.reporter.report($this, format('Example Puppet is installed at {0}', $host)) + - $.setAttr(deployed, true) diff --git a/murano/tests/functional/engine/io.murano.conflang.puppet.ExamplePuppet/Resources/DeployExamplePuppet.template b/murano/tests/functional/engine/io.murano.conflang.puppet.ExamplePuppet/Resources/DeployExamplePuppet.template new file mode 100644 index 000000000..17119f5cc --- /dev/null +++ b/murano/tests/functional/engine/io.murano.conflang.puppet.ExamplePuppet/Resources/DeployExamplePuppet.template @@ -0,0 +1,20 @@ +FormatVersion: 2.1.0 +Version: 1.0.0 +Name: Deploy Example Puppet + +Parameters: + port: $port + +Body: | + return executeRecipe(args).stdout + +Scripts: + executeRecipe: + Type: Puppet + Version: 1.0.0 + EntryPoint: test::install + Files: + - test/manifests/install.pp + Options: + captureStdout: true + captureStderr: true diff --git a/murano/tests/functional/engine/io.murano.conflang.puppet.ExamplePuppet/Resources/scripts/test/manifests/install.pp b/murano/tests/functional/engine/io.murano.conflang.puppet.ExamplePuppet/Resources/scripts/test/manifests/install.pp new file mode 100644 index 000000000..58a3594bf --- /dev/null +++ b/murano/tests/functional/engine/io.murano.conflang.puppet.ExamplePuppet/Resources/scripts/test/manifests/install.pp @@ -0,0 +1,4 @@ +class test::install($version='default_version'){ + + notify {"version: test":} +} diff --git a/murano/tests/functional/engine/io.murano.conflang.puppet.ExamplePuppet/manifest.yaml b/murano/tests/functional/engine/io.murano.conflang.puppet.ExamplePuppet/manifest.yaml new file mode 100644 index 000000000..cb309d0f8 --- /dev/null +++ b/murano/tests/functional/engine/io.murano.conflang.puppet.ExamplePuppet/manifest.yaml @@ -0,0 +1,10 @@ +Format: 1.0 +Type: Application +FullName: io.murano.conflang.puppet.ExamplePuppet +Name: ExamplePuppet +Description: | + Example Chef +Author: 'TID' +Tags: [Test, Puppet] +Classes: + io.murano.conflang.puppet.ExamplePuppet: ExamplePuppet.yaml diff --git a/murano/tests/functional/engine/test_conf_language_support.py b/murano/tests/functional/engine/test_conf_language_support.py new file mode 100644 index 000000000..3a3d9e2b8 --- /dev/null +++ b/murano/tests/functional/engine/test_conf_language_support.py @@ -0,0 +1,87 @@ +# Copyright (c) 2015 OpenStack Foundation +# +# 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. + +import uuid + +import murano.tests.functional.common.utils as common_utils +import murano.tests.functional.engine.manager as core +from nose.plugins.attrib import attr as tag + + +class LanguageSupportTest(core.MuranoTestsCore): + + @classmethod + def setUpClass(cls): + super(LanguageSupportTest, cls).setUpClass() + cls.linux = core.CONF.murano.linux_image + cls.flavor = core.CONF.murano.standard_flavor + cls.keyname = core.CONF.murano.keyname + cls.instance_type = core.CONF.murano.instance_type + + try: + # Upload the Murano test package. + cls.upload_app('io.murano.conflang.chef.ExampleChef', + 'ExampleChef', {"tags": ["tag"]}) + cls.upload_app('io.murano.conflang.puppet.ExamplePuppet', + 'ExamplePuppet', {"tags": ["tag"]}) + except Exception as e: + cls.tearDownClass() + raise e + + @classmethod + def tearDownClass(cls): + with common_utils.ignored(Exception): + try: + cls.purge_uploaded_packages() + except Exception as e: + raise e + + def _test_deploy(self, environment_name, package_name, port): + post_body = { + "instance": { + "flavor": self.flavor, + "image": self.linux, + "keyname": self.keyname, + "assignFloatingIp": True, + 'name': environment_name, + "?": { + "type": self.instance_type, + "id": str(uuid.uuid4()) + }, + }, + "name": environment_name, + "port": port, + "?": { + "type": package_name, + "id": str(uuid.uuid4()) + } + } + + environment_name = environment_name + uuid.uuid4().hex[:5] + environment = self.create_environment(name=environment_name) + session = self.create_session(environment) + self.add_service(environment, post_body, session) + self.deploy_environment(environment, session) + self.wait_for_environment_deploy(environment) + self.deployment_success_check(environment, port) + + @tag('gate', 'all', 'coverage') + def test_deploy_example_chef_example(self): + self._test_deploy('chefExample', + 'io.murano.conflang.chef.ExampleChef', 22) + + @tag('gate', 'all', 'coverage') + def test_deploy_example_puppet_example(self): + self._test_deploy('puppetExample', + "io.murano.conflang.puppet.ExamplePuppet", 22)