From 4fe3769cbcd891a3c538e2d52ebc58ce418891ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henar=20Mu=C3=B1oz=20Frutos?= Date: Wed, 8 Apr 2015 09:39:20 +0200 Subject: [PATCH] File key is wrongly created when the File Type is downloadable When execution plan is created in murano for dowloadable files, the file key is not the same as script file key, so that, there is an error in murano-agent. Closes-Bug: #1441187 Change-Id: I608d6b2d683f19670c6285cf40cbc265dd7227b3 --- murano/engine/system/agent.py | 103 ++++++++++-------- .../execution_plans/DeployTomcat.template | 16 +++ .../application_without_files.template | 1 + murano/tests/unit/engine/system/test_agent.py | 16 +-- 4 files changed, 82 insertions(+), 54 deletions(-) create mode 100644 murano/tests/unit/engine/system/execution_plans/DeployTomcat.template diff --git a/murano/engine/system/agent.py b/murano/engine/system/agent.py index 648a163ea..545607b2e 100644 --- a/murano/engine/system/agent.py +++ b/murano/engine/system/agent.py @@ -237,18 +237,16 @@ class Agent(murano_object.MuranoObject): raise ValueError('No entry point in script ' + name) if 'Application' in script['Type']: - script['EntryPoint'] = self._place_file( - scripts_folder, script['EntryPoint'], - template, files, resources) - scripts_files = script.get('Files', []) - script['Files'] = [] - for file in scripts_files: - file_id = self._place_file(scripts_folder, file, - template, files, resources) - if self._is_url(file): - script['Files'].append(file) - else: - script['Files'].append(file_id) + script['EntryPoint'] = self._place_file(scripts_folder, + script['EntryPoint'], + template, resources, + files) + if 'Files' in script: + for i, file in enumerate(script['Files']): + script['Files'][i] = self._place_file(scripts_folder, + file, template, + resources, + files) return template def _is_url(self, file): @@ -277,46 +275,59 @@ class Agent(murano_object.MuranoObject): name = name[1: -1] return name - def _get_file(self, file): + def _get_file_value(self, file): if isinstance(file, dict): - return file.values()[0] - else: - return file + file = file.values()[0] + return file - def _place_file(self, folder, file, template, files, resources): + def _get_body(self, file, resources, folder): + use_base64 = self._is_base64(file) + if use_base64 and file.startswith('<') and file.endswith('>'): + file = file[1: -1] + body = resources.string(os.path.join(folder, file)) + if use_base64: + body = body.encode('base64') + return body + + def _is_base64(self, file): + return file.startswith('<') and file.endswith('>') + + def _get_body_type(self, file): + return 'Base64' if self._is_base64(file) else 'Text' + + def _place_file(self, folder, file, template, resources, files): + file_value = self._get_file_value(file) name = self._get_name(file) - location = self._get_file(file) file_id = uuid.uuid4().hex - if self._is_url(location): - key = '='.join((name, location)) - if key in files: - return files[key] + if self._is_url(file_value): + template['Files'][file_id] = self._get_file_des_downloadable(file) + files[name] = file_id - template['Files'][file_id] = { - 'Name': name, - 'URL': location, - 'Type': 'Downloadable' - } - files[key] = file_id else: - if name in files: - return files[name] - - use_base64 = False - if location.startswith('<') and location.endswith('>'): - use_base64 = True - location = location[1: -1] - - body_type = 'Base64' if use_base64 else 'Text' - body = resources.string(os.path.join(folder, location)) - if use_base64: - body = body.encode('base64') - - template['Files'][file_id] = { - 'Name': name, - 'BodyType': body_type, - 'Body': body - } + template['Files'][file_id] = self._get_file_description(file, + resources, + folder) files[name] = file_id return file_id + + def _get_file_des_downloadable(self, file): + name = self._get_name(file) + file = self._get_file_value(file) + return { + 'Name': str(name), + 'URL': file, + 'Type': 'Downloadable' + } + + def _get_file_description(self, file, resources, folder): + name = self._get_name(file) + file_value = self._get_file_value(file) + + body_type = self._get_body_type(file_value) + body = self._get_body(file_value, resources, folder) + return { + 'Name': name, + 'BodyType': body_type, + 'Body': body + } diff --git a/murano/tests/unit/engine/system/execution_plans/DeployTomcat.template b/murano/tests/unit/engine/system/execution_plans/DeployTomcat.template new file mode 100644 index 000000000..26f822a78 --- /dev/null +++ b/murano/tests/unit/engine/system/execution_plans/DeployTomcat.template @@ -0,0 +1,16 @@ +FormatVersion: 2.0.0 +Version: 1.0.0 +Name: Deploy Tomcat +Parameters: + appName: $appName +Body: | + deploy(args.appName) +Scripts: + deploy: + Type: Application + Version: 1.0.0 + EntryPoint: deployTomcat.sh + Files: [] + Options: + captureStdout: false + captureStderr: true \ No newline at end of file diff --git a/murano/tests/unit/engine/system/execution_plans/application_without_files.template b/murano/tests/unit/engine/system/execution_plans/application_without_files.template index 57bc61941..91cfbed39 100644 --- a/murano/tests/unit/engine/system/execution_plans/application_without_files.template +++ b/murano/tests/unit/engine/system/execution_plans/application_without_files.template @@ -13,6 +13,7 @@ Scripts: Type: Application Version: 1.0.0 EntryPoint: deployTomcat.sh + Files: [] Options: captureStdout: true captureStderr: true \ No newline at end of file diff --git a/murano/tests/unit/engine/system/test_agent.py b/murano/tests/unit/engine/system/test_agent.py index ee8b410ec..9dd659b57 100644 --- a/murano/tests/unit/engine/system/test_agent.py +++ b/murano/tests/unit/engine/system/test_agent.py @@ -57,12 +57,6 @@ class TestExecutionPlan(base.MuranoTestCase): Loader=self.yaml_loader) template = self.agent.buildExecutionPlan(template, self.resources) self.assertEqual(template, self._get_application()) - self.assertEqual( - [ - mock.call(os.path.join('scripts', 'deployTomcat.sh')), - mock.call(os.path.join('scripts', 'installer.sh')), - mock.call(os.path.join('scripts', 'common.sh')) - ], self.resources.string.call_args_list) def test_execution_plan_v2_chef_type(self): template = yamllib.load( @@ -78,6 +72,12 @@ class TestExecutionPlan(base.MuranoTestCase): template = self.agent.buildExecutionPlan(template, self.resources) self.assertEqual(template, self._get_telnet_application()) + def test_execution_plan_v2_tomcat_application(self): + template = yamllib.load( + self._read('DeployTomcat.template'), + Loader=self.yaml_loader) + template = self.agent.buildExecutionPlan(template, self.resources) + def test_execution_plan_v2_app_without_files(self): template = yamllib.load( self._read('application_without_files.template'), @@ -189,8 +189,8 @@ class TestExecutionPlan(base.MuranoTestCase): 'deploy': { 'EntryPoint': 'cookbook/recipe', 'Files': [ - 'https://github.com/tomcat.git', - {'java': 'https://github.com/java.git'} + self.uuids[1], + self.uuids[2] ], 'Options': { 'captureStderr': True,