resources: file: Implement file attributes

Add owner which must be username or uid of the file owner, group which is
the group name or gid of the file, and mode which is the octal unix file
permissions.

Add separate implementation for Go 1.6 and lower.
This commit is contained in:
Mildred Ki'Lya
2017-02-13 23:55:17 +01:00
committed by James Shubin
parent b9976cf693
commit 8c2c552164
8 changed files with 327 additions and 12 deletions

19
test/shell/file-mode.sh Executable file
View File

@@ -0,0 +1,19 @@
#!/bin/bash -e
set -x
# run till completion
timeout --kill-after=20s 15s ./mgmt run --yaml file-mode.yaml --converged-timeout=5 --no-watch --tmp-prefix &
pid=$!
wait $pid # get exit status
e=$?
ls -l /tmp/mgmt
test -e /tmp/mgmt/f1
test -e /tmp/mgmt/f2
test -e /tmp/mgmt/f3
test $(stat -c%a /tmp/mgmt/f2) = 741
test $(stat -c%a /tmp/mgmt/f3) = 614
exit $e

21
test/shell/file-mode.yaml Normal file
View File

@@ -0,0 +1,21 @@
---
graph: mygraph
resources:
file:
- name: file1
path: "/tmp/mgmt/f1"
content: |
i am f1
state: exists
- name: file2
path: "/tmp/mgmt/f2"
content: |
i am f2
state: exists
mode: 0741
- name: file3
path: "/tmp/mgmt/f3"
content: |
i am f3
state: exists
mode: '0614'

24
test/shell/file-owner.sh Executable file
View File

@@ -0,0 +1,24 @@
#!/bin/bash -e
# vim: noet:ts=8:sts=8:sw=8
set -x
if ! timeout 1s sudo -A true; then
echo "sudo disabled: not checking file owner and group"
exit
fi
# run till completion
timeout --kill-after=15s 10s sudo -A ./mgmt run --yaml file-owner.yaml --converged-timeout=5 --no-watch --tmp-prefix &
pid=$!
wait $pid # get exit status
e=$?
ls -l /tmp/mgmt
test -e /tmp/mgmt/f1
test -e /tmp/mgmt/f2
test $(stat -c%U:%G /tmp/mgmt/f1) = root:root
test $(stat -c%u:%g /tmp/mgmt/f2) = 1:2
exit $e

View File

@@ -0,0 +1,18 @@
---
graph: mygraph
resources:
file:
- name: file1
path: "/tmp/mgmt/f1"
content: |
i am f1
state: exists
owner: root
group: root
- name: file2
path: "/tmp/mgmt/f2"
content: |
i am f2
state: exists
owner: 1
group: 2