Support ansible and puppet scripts.

Currently hardcoded by looking at the extension.
Ideally we should derive the info from implementation definitions in artifact_types,
however the parser currently doesn't support it.

Change-Id: I4a009ab6facee8ccfdce4f167e5dbb1cea93fb76
Signed-off-by: Mathieu Velten <mathieu.velten@cern.ch>
This commit is contained in:
Mathieu Velten 2016-03-31 10:33:13 +02:00
parent 6a37956cf4
commit 5244d8ab2e
4 changed files with 180 additions and 1 deletions

View File

@ -13,6 +13,7 @@
from collections import OrderedDict
import logging
import os
import six
from toscaparser.elements.interfaces import InterfacesDef
@ -44,7 +45,26 @@ class HotResource(object):
self.properties = properties or {}
# special case for HOT softwareconfig
if type == 'OS::Heat::SoftwareConfig':
self.properties['group'] = 'script'
config = self.properties.get('config')
if config:
implementation_artifact = config.get('get_file')
if implementation_artifact:
filename, file_extension = os.path.splitext(
implementation_artifact)
file_extension = file_extension.lower()
# artifact_types should be read to find the exact script
# type, unfortunately artifact_types doesn't seem to be
# supported by the parser
if file_extension == '.ansible' \
or file_extension == '.yaml' \
or file_extension == '.yml':
self.properties['group'] = 'ansible'
if file_extension == '.pp':
self.properties['group'] = 'puppet'
if self.properties.get('group') is None:
self.properties['group'] = 'script'
self.metadata = metadata
# The difference between depends_on and depends_on_nodes is

View File

@ -0,0 +1,101 @@
heat_template_version: 2013-05-23
description: >
TOSCA template to test usage of different script types like Ansible and Puppet
one.
parameters: {}
resources:
customwebserver2_create_deploy:
type: OS::Heat::SoftwareDeployment
properties:
config:
get_resource: customwebserver2_create_config
server:
get_resource: server
customwebserver_create_deploy:
type: OS::Heat::SoftwareDeployment
properties:
config:
get_resource: customwebserver_create_config
server:
get_resource: server
server:
type: OS::Nova::Server
properties:
flavor: m1.small
image: ubuntu-12.04-software-config-os-init
user_data_format: SOFTWARE_CONFIG
customwebserver2_start_config:
type: OS::Heat::SoftwareConfig
properties:
config:
get_file: start.sh
group: script
customwebserver2_start_deploy:
type: OS::Heat::SoftwareDeployment
properties:
config:
get_resource: customwebserver2_start_config
server:
get_resource: server
depends_on:
- customwebserver2_configure_deploy
customwebserver2_create_config:
type: OS::Heat::SoftwareConfig
properties:
config:
get_file: install.sh
group: script
customwebserver2_configure_config:
type: OS::Heat::SoftwareConfig
properties:
config:
get_file: configure.py
group: script
customwebserver2_configure_deploy:
type: OS::Heat::SoftwareDeployment
properties:
config:
get_resource: customwebserver2_configure_config
server:
get_resource: server
depends_on:
- customwebserver2_create_deploy
customwebserver_start_config:
type: OS::Heat::SoftwareConfig
properties:
config:
get_file: start.pp
group: puppet
customwebserver_start_deploy:
type: OS::Heat::SoftwareDeployment
properties:
config:
get_resource: customwebserver_start_config
server:
get_resource: server
depends_on:
- customwebserver_configure_deploy
customwebserver_create_config:
type: OS::Heat::SoftwareConfig
properties:
config:
get_file: install.yaml
group: ansible
customwebserver_configure_config:
type: OS::Heat::SoftwareConfig
properties:
config:
get_file: configure.yml
group: ansible
customwebserver_configure_deploy:
type: OS::Heat::SoftwareDeployment
properties:
config:
get_resource: customwebserver_configure_config
server:
get_resource: server
depends_on:
- customwebserver_create_deploy
outputs: {}

View File

@ -0,0 +1,48 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
TOSCA template to test usage of different script types like
Ansible and Puppet one.
topology_template:
node_templates:
customwebserver:
type: tosca.nodes.WebServer
requirements:
- host: server
interfaces:
Standard:
create:
implementation: install.yaml
configure:
implementation: configure.yml
start:
implementation: start.pp
customwebserver2:
type: tosca.nodes.WebServer
requirements:
- host: server
interfaces:
Standard:
create:
implementation: install.sh
configure:
implementation: configure.py
start:
implementation: start.sh
server:
type: tosca.nodes.Compute
capabilities:
host:
properties:
num_cpus: 1
mem_size: 1 GB
os:
properties:
type: Linux
distribution: Ubuntu
version: 12.04
architecture: x86_64

View File

@ -631,3 +631,13 @@ class ToscaHotTranslationTest(TestCase):
params)
self.assertEqual({}, diff, '<difference> : ' +
json.dumps(diff, indent=4, separators=(', ', ': ')))
def test_hot_script_types(self):
tosca_file = '../tests/data/test_tosca_script_types.yaml'
hot_file = '../tests/data/hot_output/hot_script_types.yaml'
params = {}
diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file,
hot_file,
params)
self.assertEqual({}, diff, '<difference> : ' +
json.dumps(diff, indent=4, separators=(', ', ': ')))