Permalink
Browse files

File contents can now be only strings

Allowing file contents to be represented with lists added
unnecessary complexity also in UI implementations.
  • Loading branch information...
nemesisdesign committed Feb 4, 2016
1 parent 75c259d commit 010ca98001d36e618dc9f24ae0ecfb8af4a94ea8
Showing with 7 additions and 32 deletions.
  1. +2 −2 docs/source/backends/openwrt.rst
  2. +2 −4 netjsonconfig/backends/openwrt/schema.py
  3. +3 −26 tests/openwrt/test_backend.py
@@ -202,8 +202,8 @@ dictionary is structured as follows:
+===================+================+==========+==========================================================+
| ``path`` | string | yes | path of the file in the tar.gz archive |
+-------------------+----------------+----------+----------------------------------------------------------+
| ``contents`` | string or list | yes | | *string*: plain text contents of the file |
| | | | | *list*: lines of strings representing lines of file |
| ``contents`` | string | yes | plain text contents of the file, new lines must be |
| | | | encoded as `\n` |
+-------------------+----------------+----------+----------------------------------------------------------+
| ``mode`` | string | no | permissions, if omitted will default to ``0644`` |
+-------------------+----------------+----------+----------------------------------------------------------+
@@ -297,10 +297,8 @@
"type": "string"
},
"contents": {
"anyOf": [
{"type": "string", "format": "textarea"},
{"type": "array"}
]
"type": "string",
"format": "textarea"
},
"mode": {
"type": "string",
@@ -284,10 +284,8 @@ def test_file_inclusion(self):
"files": [
{
"path": "/etc/crontabs/root",
"contents": [
'* * * * * echo "test" > /etc/testfile',
'* * * * * echo "test2" > /etc/testfile2'
]
"contents": '* * * * * echo "test" > /etc/testfile\n'
'* * * * * echo "test2" > /etc/testfile2'
},
{
"path": "/etc/dummy.conf",
@@ -304,7 +302,7 @@ def test_file_inclusion(self):
# first file
crontab = tar.getmember('etc/crontabs/root')
contents = tar.extractfile(crontab).read().decode()
self.assertEqual(contents, '\n'.join(o.config['files'][0]['contents']))
self.assertEqual(contents, o.config['files'][0]['contents'])
self.assertEqual(crontab.mtime, 0)
self.assertEqual(crontab.mode, 420)
# second file
@@ -314,27 +312,6 @@ def test_file_inclusion(self):
self.assertEqual(dummy.mode, 420)
tar.close()
def test_file_inclusion_list_contents(self):
o = OpenWrt({
"files": [
{
"path": "/root/.ssh/authorized_keys",
"contents": [
"key1 user@machine1",
"key2 user@machine2",
"key3 user@machine3",
]
}
]
})
tar = tarfile.open(fileobj=o.generate(), mode='r')
self.assertEqual(len(tar.getmembers()), 1)
# check file
crontab = tar.getmember('root/.ssh/authorized_keys')
contents = tar.extractfile(crontab).read().decode()
self.assertEqual(contents, '\n'.join(o.config['files'][0]['contents']))
tar.close()
def test_file_permissions(self):
o = OpenWrt({
"files": [

0 comments on commit 010ca98

Please sign in to comment.