Skip to content

Commit

Permalink
File contents can now be only strings
Browse files Browse the repository at this point in the history
Allowing file contents to be represented with lists added
unnecessary complexity also in UI implementations.
  • Loading branch information
nemesifier committed Feb 4, 2016
1 parent 75c259d commit 010ca98
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 32 deletions.
4 changes: 2 additions & 2 deletions docs/source/backends/openwrt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`` |
+-------------------+----------------+----------+----------------------------------------------------------+
Expand Down
6 changes: 2 additions & 4 deletions netjsonconfig/backends/openwrt/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,8 @@
"type": "string"
},
"contents": {
"anyOf": [
{"type": "string", "format": "textarea"},
{"type": "array"}
]
"type": "string",
"format": "textarea"
},
"mode": {
"type": "string",
Expand Down
29 changes: 3 additions & 26 deletions tests/openwrt/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand All @@ -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": [
Expand Down

0 comments on commit 010ca98

Please sign in to comment.