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
This commit is contained in:
parent
0a2f63b5e4
commit
850b06a500
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
|
@ -13,6 +13,7 @@ Scripts:
|
|||
Type: Application
|
||||
Version: 1.0.0
|
||||
EntryPoint: deployTomcat.sh
|
||||
Files: []
|
||||
Options:
|
||||
captureStdout: true
|
||||
captureStderr: true
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue