Support .zip and .csar extension for CSAR files

Support .csar as well as .zip for input CSAR files.
Add unit tests to verify that both .zip and .csar
extensions are validated and parsed properly.

Change-Id: I9d531ceb0e2e1bd36817692677dcbf2b5d5520a9
Closes-Bug: #1506163
This commit is contained in:
Vahid Hashemian 2015-11-06 14:51:06 -08:00
parent fe83d5977f
commit 96c16ad97a
4 changed files with 15 additions and 1 deletions

Binary file not shown.

View File

@ -221,3 +221,10 @@ class CSARPrereqTest(TestCase):
shutil.rmtree(csar.temp_dir)
self.assertTrue(csar.temp_dir is None or
not os.path.exists(csar.temp_dir))
def test_alternate_csar_extension(self):
path = os.path.join(self.base_path, "data/CSAR/csar_elk.csar")
csar = CSAR(path)
self.assertIsNone(csar.validate())
self.assertTrue(csar.temp_dir is None or
not os.path.exists(csar.temp_dir))

View File

@ -456,3 +456,10 @@ class ToscaTemplateTest(TestCase):
ValueError,
lambda: ToscaTemplate(template_file, None, False))
self.assertEqual(expected_msg, err.__str__())
def test_csar_with_alternate_extenstion(self):
tosca_tpl = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"data/CSAR/csar_elk.csar")
tosca = ToscaTemplate(tosca_tpl)
self.assertTrue(tosca.topology_template.custom_defs)

View File

@ -170,7 +170,7 @@ class ToscaTemplate(object):
def _get_path(self, path):
if path.lower().endswith('.yaml'):
return path
elif path.lower().endswith('.zip'):
elif path.lower().endswith(('.zip', '.csar')):
# a CSAR archive
csar = CSAR(path, self.a_file)
csar.validate()