Merge "Support extracting the main template from a CSAR archive"

This commit is contained in:
Jenkins
2015-09-27 17:34:35 +00:00
committed by Gerrit Code Review
4 changed files with 20 additions and 10 deletions

View File

@@ -100,13 +100,8 @@ class CSAR(object):
def get_main_template(self):
return self._get_metadata('Entry-Definitions')
def get_description(self):
desc = self._get_metadata('Description')
if desc is not None:
return desc
def get_main_template_yaml(self):
main_template = self.get_main_template()
# extract the description from the main template
data = self.zfile.read(main_template)
invalid_tosca_yaml_err_msg = (
_('The file %(template)s in %(csar)s does not contain valid TOSCA '
@@ -116,7 +111,15 @@ class CSAR(object):
tosca_yaml = yaml.load(data)
if type(tosca_yaml) is not dict:
raise ValidationError(message=invalid_tosca_yaml_err_msg)
self.metadata['Description'] = tosca_yaml['description']
return tosca_yaml
except Exception:
raise ValidationError(message=invalid_tosca_yaml_err_msg)
def get_description(self):
desc = self._get_metadata('Description')
if desc is not None:
return desc
self.metadata['Description'] = \
self.get_main_template_yaml()['description']
return self.metadata['Description']

View File

@@ -1,7 +1,5 @@
TOSCA-Meta-File-Version: 1.0
CSAR-Version: 1.1
Created-By: OASIS TOSCA TC
Name: Definitions/tosca_single_instance_wordpress.yaml
Entry-Definitions: Definitions/tosca_single_instance_wordpress.yaml
Content-Type: application/vnd.oasis.tosca.definitions.yaml

View File

@@ -15,6 +15,7 @@ import os
from toscaparser.common.exception import ValidationError
from toscaparser.prereq.csar import CSAR
from toscaparser.tests.base import TestCase
import toscaparser.utils
from toscaparser.utils.gettextutils import _
@@ -109,3 +110,11 @@ class CSARPrereqTest(TestCase):
self.assertEqual('tosca_helloworld.yaml', csar.get_main_template())
self.assertEqual('Template for deploying a single server with '
'predefined properties.', csar.get_description())
def test_csar_main_template(self):
path = os.path.join(self.base_path, "data/CSAR/csar_hello_world.zip")
csar = CSAR(path)
yaml_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"data/tosca_helloworld.yaml")
expected_yaml = toscaparser.utils.yamlparser.load_yaml(yaml_file)
self.assertEqual(expected_yaml, csar.get_main_template_yaml())