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

View File

@@ -1,7 +1,5 @@
TOSCA-Meta-File-Version: 1.0 TOSCA-Meta-File-Version: 1.0
CSAR-Version: 1.1 CSAR-Version: 1.1
Created-By: OASIS TOSCA TC Created-By: OASIS TOSCA TC
Entry-Definitions: Definitions/tosca_single_instance_wordpress.yaml
Name: Definitions/tosca_single_instance_wordpress.yaml
Content-Type: application/vnd.oasis.tosca.definitions.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.common.exception import ValidationError
from toscaparser.prereq.csar import CSAR from toscaparser.prereq.csar import CSAR
from toscaparser.tests.base import TestCase from toscaparser.tests.base import TestCase
import toscaparser.utils
from toscaparser.utils.gettextutils import _ from toscaparser.utils.gettextutils import _
@@ -109,3 +110,11 @@ class CSARPrereqTest(TestCase):
self.assertEqual('tosca_helloworld.yaml', csar.get_main_template()) self.assertEqual('tosca_helloworld.yaml', csar.get_main_template())
self.assertEqual('Template for deploying a single server with ' self.assertEqual('Template for deploying a single server with '
'predefined properties.', csar.get_description()) '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())