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, ...@@ -75,6 +75,7 @@ setup(name=name,
'cachecontrol', 'cachecontrol',
'lockfile', 'lockfile',
'jsonschema', 'jsonschema',
'pyaml',
'uritemplate', # used by hateoas navigator 'uritemplate', # used by hateoas navigator
'subprocess32; python_version<"3"', 'subprocess32; python_version<"3"',
'ipaddress; python_version<"3"', # used by whitelistfirewall 'ipaddress; python_version<"3"', # used by whitelistfirewall
......
...@@ -33,6 +33,7 @@ import os.path ...@@ -33,6 +33,7 @@ import os.path
import pprint import pprint
import lxml.etree import lxml.etree
import yaml
from slapos.cli.config import ClientConfigCommand from slapos.cli.config import ClientConfigCommand
from slapos.client import (ClientConfig, _getSoftwareReleaseFromSoftwareString, from slapos.client import (ClientConfig, _getSoftwareReleaseFromSoftwareString,
...@@ -49,7 +50,9 @@ except ImportError: ...@@ -49,7 +50,9 @@ except ImportError:
def getParametersFromFile(file, serialisation): def getParametersFromFile(file, serialisation):
# type: (IO[str], SoftwareReleaseSerialisation) -> Dict # type: (IO[str], SoftwareReleaseSerialisation) -> Dict
extension = os.path.splitext(file.name)[1] 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) tree = lxml.etree.parse(file)
params = {e.attrib['id']: e.text for e in tree.findall('/parameter')} 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 # because the use case of xml files is to copy paste existing XML parameters
......
...@@ -739,6 +739,19 @@ class TestCliRequestParametersFileJson(CliMixin): ...@@ -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): class TestCliRequestParametersFileXml(TestCliRequestParametersFileJson):
expected_partition_parameter_kw = {'foo': 'bar'} expected_partition_parameter_kw = {'foo': 'bar'}
def _makeParameterFile(self): 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