Commit 5ae90086 authored by Jérome Perrin's avatar Jérome Perrin

cli/request: support yaml format for --parameters-file option

parent 69d8890a
......@@ -75,6 +75,7 @@ setup(name=name,
'cachecontrol',
'lockfile',
'jsonschema',
'pyaml',
'uritemplate', # used by hateoas navigator
'subprocess32; python_version<"3"',
'ipaddress; python_version<"3"', # used by whitelistfirewall
......
......@@ -33,6 +33,7 @@ import os.path
import pprint
import lxml.etree
import yaml
from slapos.cli.config import ClientConfigCommand
from slapos.client import (ClientConfig, _getSoftwareReleaseFromSoftwareString,
......@@ -49,7 +50,9 @@ except ImportError:
def getParametersFromFile(file, serialisation):
# type: (IO[str], SoftwareReleaseSerialisation) -> Dict
extension = os.path.splitext(file.name)[1]
if extension == '.xml':
if extension in ('.yaml', '.yml'):
params = yaml.safe_load(file)
elif extension == '.xml':
tree = lxml.etree.parse(file)
params = {e.attrib['id']: e.text for e in tree.findall('/parameter')}
# because the use case of xml files is to copy paste existing XML parameters
......
......@@ -739,6 +739,19 @@ class TestCliRequestParametersFileJson(CliMixin):
)
class TestCliRequestParametersFileYaml(TestCliRequestParametersFileJson):
def _makeParameterFile(self):
f = tempfile.NamedTemporaryFile(suffix='.yaml', mode='w', delete=False)
f.write(textwrap.dedent('''\
{
"foo": ["bar"]
}
'''))
f.flush()
self.addCleanup(os.unlink, f.name)
return f.name
class TestCliRequestParametersFileXml(TestCliRequestParametersFileJson):
expected_partition_parameter_kw = {'foo': 'bar'}
def _makeParameterFile(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment