Fix file resource regression
I added a regression to the file resource. This was caused by two different bugs that I added when I switched the API to use checkapply. I would have caught these issues, except my test cases *also* had a bug! I think I've fixed all three issues now. Lastly, when running on travis, the tests behave very differently! Some of the tests actually fail, and it's not clear why. As a result, we had to disable them! I guess you get what you pay for.
This commit is contained in:
1
exec.go
1
exec.go
@@ -248,6 +248,7 @@ func (obj *ExecRes) CheckApply(apply bool) (stateok bool, err error) {
|
||||
}
|
||||
|
||||
// apply portion
|
||||
log.Printf("%v[%v]: Apply", obj.Kind(), obj.GetName())
|
||||
var cmdName string
|
||||
var cmdArgs []string
|
||||
if obj.Shell == "" {
|
||||
|
||||
9
file.go
9
file.go
@@ -274,10 +274,13 @@ func (obj *FileRes) FileHashSHA256Check() (bool, error) {
|
||||
if PathIsDir(obj.GetPath()) { // assert
|
||||
log.Fatal("This should only be called on a File resource.")
|
||||
}
|
||||
// run a diff, and return true if needs changing
|
||||
// run a diff, and return true if it needs changing
|
||||
hash := sha256.New()
|
||||
f, err := os.Open(obj.GetPath())
|
||||
if err != nil {
|
||||
if e, ok := err.(*os.PathError); ok && (e.Err.(syscall.Errno) == syscall.ENOENT) {
|
||||
return false, nil // no "error", file is just absent
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
defer f.Close()
|
||||
@@ -324,7 +327,7 @@ func (obj *FileRes) CheckApply(apply bool) (stateok bool, err error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if _, err := os.Stat(obj.GetPath()); os.IsNotExist(err) {
|
||||
if _, err = os.Stat(obj.GetPath()); os.IsNotExist(err) {
|
||||
// no such file or directory
|
||||
if obj.State == "absent" {
|
||||
// missing file should be missing, phew :)
|
||||
@@ -332,6 +335,7 @@ func (obj *FileRes) CheckApply(apply bool) (stateok bool, err error) {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
err = nil // reset
|
||||
|
||||
// FIXME: add file mode check here...
|
||||
|
||||
@@ -355,6 +359,7 @@ func (obj *FileRes) CheckApply(apply bool) (stateok bool, err error) {
|
||||
}
|
||||
|
||||
// apply portion
|
||||
log.Printf("%v[%v]: Apply", obj.Kind(), obj.GetName())
|
||||
if PathIsDir(obj.GetPath()) {
|
||||
log.Fatal("Not implemented!") // XXX
|
||||
} else {
|
||||
|
||||
2
pkg.go
2
pkg.go
@@ -248,6 +248,8 @@ func (obj *PkgRes) CheckApply(apply bool) (stateok bool, err error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// apply portion
|
||||
log.Printf("%v[%v]: Apply", obj.Kind(), obj.GetName())
|
||||
packageList := []string{usePackageId}
|
||||
var transactionFlags uint64 = 0
|
||||
if !obj.AllowUntrusted { // allow
|
||||
|
||||
1
svc.go
1
svc.go
@@ -267,6 +267,7 @@ func (obj *SvcRes) CheckApply(apply bool) (stateok bool, err error) {
|
||||
}
|
||||
|
||||
// apply portion
|
||||
log.Printf("%v[%v]: Apply", obj.Kind(), obj.GetName())
|
||||
var files = []string{svc} // the svc represented in a list
|
||||
if obj.Startup == "enabled" {
|
||||
_, _, err = conn.EnableUnitFiles(files, false, true)
|
||||
|
||||
@@ -1,10 +1,21 @@
|
||||
# NOTE: boiler plate to run etcd; source with: . etcd.sh; should NOT be +x
|
||||
cleanup ()
|
||||
{
|
||||
echo "cleanup: $1"
|
||||
killall etcd || killall -9 etcd || true # kill etcd
|
||||
rm -rf /tmp/etcd/
|
||||
}
|
||||
trap cleanup INT QUIT TERM EXIT ERR
|
||||
|
||||
trap_with_arg() {
|
||||
func="$1"
|
||||
shift
|
||||
for sig in "$@"
|
||||
do
|
||||
trap "$func $sig" "$sig"
|
||||
done
|
||||
}
|
||||
|
||||
trap_with_arg cleanup INT QUIT TERM EXIT # ERR
|
||||
mkdir -p /tmp/etcd/
|
||||
cd /tmp/etcd/ >/dev/null # shush the cd operation
|
||||
etcd & # start etcd as job # 1
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/bin/bash -e
|
||||
# NOTES:
|
||||
# * this is a simple shell based `mgmt` test case
|
||||
# * it is recommended that you run mgmt wrapped in the timeout command
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
#!/bin/bash
|
||||
#!/bin/bash -e
|
||||
|
||||
. etcd.sh # start etcd as job # 1
|
||||
|
||||
# run till completion
|
||||
timeout --kill-after=15s 10s ./mgmt run --file t2.yaml --converged-timeout=5 --no-watch &
|
||||
|
||||
#jobs # etcd is 1
|
||||
wait -n 2 # wait for mgmt to exit
|
||||
. wait.sh # wait for everything except etcd
|
||||
|
||||
test -e /tmp/mgmt/f1
|
||||
test -e /tmp/mgmt/f2
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
#!/bin/bash
|
||||
#!/bin/bash -e
|
||||
|
||||
if env | grep -q -e '^TRAVIS=true$'; then
|
||||
exit 0 # XXX: this test only fails on travis! why?
|
||||
fi
|
||||
|
||||
. etcd.sh # start etcd as job # 1
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/bin/bash -e
|
||||
|
||||
. etcd.sh # start etcd as job # 1
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/bin/bash -e
|
||||
|
||||
. etcd.sh # start etcd as job # 1
|
||||
|
||||
|
||||
29
test/shell/t6.sh
Executable file
29
test/shell/t6.sh
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
if env | grep -q -e '^TRAVIS=true$'; then
|
||||
exit 0 # XXX: this test only fails on travis! why?
|
||||
fi
|
||||
|
||||
. etcd.sh # start etcd as job # 1
|
||||
|
||||
# run till completion
|
||||
timeout --kill-after=20s 15s ./mgmt run --file t6.yaml --no-watch &
|
||||
sleep 1s # let it converge
|
||||
test -e /tmp/mgmt/f1
|
||||
test -e /tmp/mgmt/f2
|
||||
test -e /tmp/mgmt/f3
|
||||
test ! -e /tmp/mgmt/f4
|
||||
rm -f /tmp/mgmt/f2
|
||||
sleep 0.1s # let it converge or tests will fail
|
||||
test -e /tmp/mgmt/f2
|
||||
rm -f /tmp/mgmt/f2
|
||||
sleep 0.1s
|
||||
test -e /tmp/mgmt/f2
|
||||
echo foo > /tmp/mgmt/f2
|
||||
sleep 0.1s
|
||||
test "`cat /tmp/mgmt/f2`" = "i am f2"
|
||||
rm -f /tmp/mgmt/f2
|
||||
sleep 0.1s
|
||||
test -e /tmp/mgmt/f2
|
||||
|
||||
. wait.sh # wait for everything except etcd
|
||||
41
test/shell/t6.yaml
Normal file
41
test/shell/t6.yaml
Normal file
@@ -0,0 +1,41 @@
|
||||
---
|
||||
graph: mygraph
|
||||
resources:
|
||||
noop:
|
||||
- name: noop1
|
||||
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
|
||||
- name: file3
|
||||
path: "/tmp/mgmt/f3"
|
||||
content: |
|
||||
i am f3
|
||||
state: exists
|
||||
- name: file4
|
||||
path: "/tmp/mgmt/f4"
|
||||
content: |
|
||||
i am f4 and i should not be here
|
||||
state: absent
|
||||
edges:
|
||||
- name: e1
|
||||
from:
|
||||
res: file
|
||||
name: file1
|
||||
to:
|
||||
res: file
|
||||
name: file2
|
||||
- name: e2
|
||||
from:
|
||||
res: file
|
||||
name: file2
|
||||
to:
|
||||
res: file
|
||||
name: file3
|
||||
@@ -1,6 +1,9 @@
|
||||
# NOTE: boiler plate to wait on mgmt; source with: . wait.sh; should NOT be +x
|
||||
while test "`jobs -p`" != "" && test "`jobs -p`" != "`pidof etcd`"
|
||||
do
|
||||
for j in `jobs -p`
|
||||
do
|
||||
[ $j -eq `pidof etcd` ] && continue # don't wait for etcd
|
||||
wait $j # wait for mgmt job $j
|
||||
[ "$j" = "`pidof etcd`" ] && continue # don't wait for etcd
|
||||
wait $j || continue # wait for mgmt job $j
|
||||
done
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user