engine: resources, graph: Change the Close method to Cleanup

This also changes a few similarly named methods. Clearer what it's doing
in terms of cleanup vs. causing some action.
This commit is contained in:
James Shubin
2023-08-08 00:19:51 -04:00
parent 63f05e12ca
commit 514927c0b3
39 changed files with 125 additions and 123 deletions

View File

@@ -177,10 +177,10 @@ this. In other words, you should expect `Validate` to have run first, but you
shouldn't allow `Init` to dangerously `rm -rf /$the_world` if your code only shouldn't allow `Init` to dangerously `rm -rf /$the_world` if your code only
checks `$the_world` in `Validate`. Remember to always program safely! checks `$the_world` in `Validate`. Remember to always program safely!
### Close ### Cleanup
```golang ```golang
Close() error Cleanup() error
``` ```
This is called to cleanup after the resource. It is usually not necessary, but This is called to cleanup after the resource. It is usually not necessary, but
@@ -192,8 +192,8 @@ loop.
#### Example #### Example
```golang ```golang
// Close runs some cleanup code for this resource. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *FooRes) Close() error { func (obj *FooRes) Cleanup() error {
err := obj.conn.Close() // close some internal connection err := obj.conn.Close() // close some internal connection
obj.someMap = nil // free up some large data structure from memory obj.someMap = nil // free up some large data structure from memory
return err return err
@@ -579,15 +579,15 @@ It is only called from within `CheckApply`.
World provides a connection to the outside world. This is most often used for World provides a connection to the outside world. This is most often used for
communicating with the distributed database. It can be used in `Init`, communicating with the distributed database. It can be used in `Init`,
`CheckApply` and `Watch`. Use with discretion and understanding of the internals `CheckApply` and `Watch`. Use with discretion and understanding of the internals
if needed in `Close`. if needed in `Cleanup`.
### VarDir ### VarDir
VarDir is a facility for local storage. It is used to return a path to a VarDir is a facility for local storage. It is used to return a path to a
directory which may be used for temporary storage. It should be cleaned up on directory which may be used for temporary storage. It should be cleaned up on
resource `Close` if the resource would like to delete the contents. The resource resource `Cleanup` if the resource would like to delete the contents. The
should not assume that the initial directory is empty, and it should be cleaned resource should not assume that the initial directory is empty, and it should be
on `Init` if that is a requirement. cleaned on `Init` if that is a requirement.
### Debug ### Debug
@@ -724,7 +724,7 @@ two calls, this is much more difficult. A common example is that a resource
might want to open a connection to `dbus` or `http` to do resource state testing might want to open a connection to `dbus` or `http` to do resource state testing
and applying. If the methods are combined, there's no need to open and close and applying. If the methods are combined, there's no need to open and close
them twice. A counter argument might be that you could open the connection in them twice. A counter argument might be that you could open the connection in
`Init`, and close it in `Close`, however you might not want that open for the `Init`, and close it in `Cleanup`, however you might not want that open for the
full lifetime of the resource if you only change state occasionally. full lifetime of the resource if you only change state occasionally.
2. Suppose you came up with a really good reason why you wanted the two methods 2. Suppose you came up with a really good reason why you wanted the two methods
to be separate. It turns out that the current `CheckApply` can wrap this easily. to be separate. It turns out that the current `CheckApply` can wrap this easily.

View File

@@ -63,7 +63,7 @@ func (obj *NoopResTest) Init(init *engine.Init) error {
return nil return nil
} }
func (obj *NoopResTest) Close() error { func (obj *NoopResTest) Cleanup() error {
return nil return nil
} }

View File

@@ -257,7 +257,7 @@ func (obj *Engine) Commit() error {
// close the state and resource // close the state and resource
// FIXME: will this mess up the sync and block the engine? // FIXME: will this mess up the sync and block the engine?
if err := obj.state[vertex].Close(); err != nil { if err := obj.state[vertex].Cleanup(); err != nil {
return errwrap.Wrapf(err, "the Res did not Close") return errwrap.Wrapf(err, "the Res did not Close")
} }

View File

@@ -231,9 +231,9 @@ func (obj *State) ReversalInit() error {
return obj.ReversalWrite(str, res.ReversibleMeta().Overwrite) // Store! return obj.ReversalWrite(str, res.ReversibleMeta().Overwrite) // Store!
} }
// ReversalClose performs the reversal shutdown steps if necessary for this // ReversalCleanup performs the reversal shutdown steps if necessary for this
// resource. // resource.
func (obj *State) ReversalClose() error { func (obj *State) ReversalCleanup() error {
res, ok := obj.Vertex.(engine.ReversibleRes) res, ok := obj.Vertex.(engine.ReversibleRes)
if !ok { if !ok {
return nil // nothing to do return nil // nothing to do

View File

@@ -263,9 +263,9 @@ func (obj *State) Init() error {
return nil return nil
} }
// Close shuts down and performs any cleanup. This is most akin to a "post" or // Cleanup shuts down and performs any cleanup. This is most akin to a "post" or
// cleanup command as the initiator for closing a vertex happens in graph sync. // cleanup command as the initiator for closing a vertex happens in graph sync.
func (obj *State) Close() error { func (obj *State) Cleanup() error {
res, isRes := obj.Vertex.(engine.Res) res, isRes := obj.Vertex.(engine.Res)
if !isRes { if !isRes {
return fmt.Errorf("vertex is not a Res") return fmt.Errorf("vertex is not a Res")
@@ -288,13 +288,13 @@ func (obj *State) Close() error {
var reverr error var reverr error
// clear the reverse request from the disk... // clear the reverse request from the disk...
if err := obj.ReversalClose(); err != nil { if err := obj.ReversalCleanup(); err != nil {
// TODO: test this code path... // TODO: test this code path...
// TODO: should this be an error or a warning? // TODO: should this be an error or a warning?
reverr = err reverr = err
} }
reterr := res.Close() reterr := res.Cleanup()
if obj.Debug { if obj.Debug {
obj.Logf("Close(%s): Return(%+v)", res, reterr) obj.Logf("Close(%s): Return(%+v)", res, reterr)
} }

View File

@@ -190,8 +190,8 @@ type Res interface {
// and data from the engine. // and data from the engine.
Init(*Init) error Init(*Init) error
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
Close() error Cleanup() error
// Watch is run by the engine to monitor for state changes. If it // Watch is run by the engine to monitor for state changes. If it
// detects any, it notifies the engine which will usually run CheckApply // detects any, it notifies the engine which will usually run CheckApply

View File

@@ -118,8 +118,8 @@ func (obj *AugeasRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *AugeasRes) Close() error { func (obj *AugeasRes) Cleanup() error {
return nil return nil
} }

View File

@@ -388,10 +388,11 @@ func (obj *AwsEc2Res) Init(init *engine.Init) error {
return nil return nil
} }
// Close cleans up when we're done. This is needed to delete some of the AWS // Cleanup cleans up when we're done. This is needed to delete some of the AWS
// objects created for the SNS endpoint. // objects created for the SNS endpoint.
func (obj *AwsEc2Res) Close() error { func (obj *AwsEc2Res) Cleanup() error {
var errList error var errList error
// XXX: do these in a defer of Watch instead.
// clean up sns objects created by Init/snsWatch // clean up sns objects created by Init/snsWatch
if obj.snsClient != nil { if obj.snsClient != nil {
// delete the topic and associated subscriptions // delete the topic and associated subscriptions

View File

@@ -86,8 +86,8 @@ func (obj *ConfigEtcdRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *ConfigEtcdRes) Close() error { func (obj *ConfigEtcdRes) Cleanup() error {
return nil return nil
} }

View File

@@ -108,8 +108,8 @@ func (obj *ConsulKVRes) Init(init *engine.Init) error {
return errwrap.Wrapf(err, "could not create Consul client") return errwrap.Wrapf(err, "could not create Consul client")
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *ConsulKVRes) Close() error { func (obj *ConsulKVRes) Cleanup() error {
if obj.config != nil && obj.config.Transport != nil { if obj.config != nil && obj.config.Transport != nil {
obj.config.Transport.CloseIdleConnections() obj.config.Transport.CloseIdleConnections()
} }

View File

@@ -212,10 +212,10 @@ func (obj *CronRes) Init(init *engine.Init) error {
return obj.file.Init(init) return obj.file.Init(init)
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *CronRes) Close() error { func (obj *CronRes) Cleanup() error {
if obj.file != nil { if obj.file != nil {
return obj.file.Close() return obj.file.Cleanup()
} }
return nil return nil
} }

View File

@@ -377,8 +377,8 @@ func (obj *DHCPServerRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *DHCPServerRes) Close() error { func (obj *DHCPServerRes) Cleanup() error {
// NOTE: if this ever panics, it might mean the engine is running Close // NOTE: if this ever panics, it might mean the engine is running Close
// before Watch finishes exiting, which is an engine bug in that code... // before Watch finishes exiting, which is an engine bug in that code...
//obj.mutex.RUnlock() //obj.mutex.RUnlock()
@@ -1045,8 +1045,8 @@ func (obj *DHCPHostRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *DHCPHostRes) Close() error { func (obj *DHCPHostRes) Cleanup() error {
return nil return nil
} }

View File

@@ -164,8 +164,8 @@ func (obj *DockerContainerRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *DockerContainerRes) Close() error { func (obj *DockerContainerRes) Cleanup() error {
return obj.client.Close() // close the docker client return obj.client.Close() // close the docker client
} }

View File

@@ -125,8 +125,8 @@ func (obj *DockerImageRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *DockerImageRes) Close() error { func (obj *DockerImageRes) Cleanup() error {
return obj.client.Close() // close the docker client return obj.client.Close() // close the docker client
} }

View File

@@ -161,8 +161,8 @@ func (obj *ExecRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *ExecRes) Close() error { func (obj *ExecRes) Cleanup() error {
return nil return nil
} }

View File

@@ -62,8 +62,8 @@ func TestExecSendRecv1(t *testing.T) {
t.Errorf("validate failed with: %v", err) t.Errorf("validate failed with: %v", err)
} }
defer func() { defer func() {
if err := r1.Close(); err != nil { if err := r1.Cleanup(); err != nil {
t.Errorf("close failed with: %v", err) t.Errorf("cleanup failed with: %v", err)
} }
}() }()
init, execSends := fakeExecInit(t) init, execSends := fakeExecInit(t)
@@ -107,8 +107,8 @@ func TestExecSendRecv2(t *testing.T) {
t.Errorf("validate failed with: %v", err) t.Errorf("validate failed with: %v", err)
} }
defer func() { defer func() {
if err := r1.Close(); err != nil { if err := r1.Cleanup(); err != nil {
t.Errorf("close failed with: %v", err) t.Errorf("cleanup failed with: %v", err)
} }
}() }()
init, execSends := fakeExecInit(t) init, execSends := fakeExecInit(t)
@@ -152,8 +152,8 @@ func TestExecSendRecv3(t *testing.T) {
t.Errorf("validate failed with: %v", err) t.Errorf("validate failed with: %v", err)
} }
defer func() { defer func() {
if err := r1.Close(); err != nil { if err := r1.Cleanup(); err != nil {
t.Errorf("close failed with: %v", err) t.Errorf("cleanup failed with: %v", err)
} }
}() }()
init, execSends := fakeExecInit(t) init, execSends := fakeExecInit(t)

View File

@@ -350,8 +350,8 @@ func (obj *FileRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *FileRes) Close() error { func (obj *FileRes) Cleanup() error {
return nil return nil
} }

View File

@@ -71,8 +71,8 @@ func (obj *GroupRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *GroupRes) Close() error { func (obj *GroupRes) Cleanup() error {
return nil return nil
} }

View File

@@ -361,8 +361,9 @@ func (obj *HetznerVMRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close deletes the authentication info before closing the resource. // Cleanup is run by the engine to clean up after the resource is done. It
func (obj *HetznerVMRes) Close() error { // deletes the authentication info before closing the resource.
func (obj *HetznerVMRes) Cleanup() error {
obj.APIToken = "" obj.APIToken = ""
obj.client = nil obj.client = nil
return nil return nil

View File

@@ -101,8 +101,8 @@ func (obj *HostnameRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *HostnameRes) Close() error { func (obj *HostnameRes) Cleanup() error {
return nil return nil
} }

View File

@@ -224,8 +224,8 @@ func (obj *HTTPServerRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *HTTPServerRes) Close() error { func (obj *HTTPServerRes) Cleanup() error {
return nil return nil
} }
@@ -713,8 +713,8 @@ func (obj *HTTPFileRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *HTTPFileRes) Close() error { func (obj *HTTPFileRes) Cleanup() error {
return nil return nil
} }

View File

@@ -123,8 +123,8 @@ func (obj *KVRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *KVRes) Close() error { func (obj *KVRes) Cleanup() error {
return nil return nil
} }

View File

@@ -185,8 +185,8 @@ func (obj *MountRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *MountRes) Close() error { func (obj *MountRes) Cleanup() error {
return nil return nil
} }

View File

@@ -88,8 +88,8 @@ func (obj *MsgRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *MsgRes) Close() error { func (obj *MsgRes) Cleanup() error {
return nil return nil
} }

View File

@@ -186,8 +186,8 @@ func (obj *NetRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close cleans up when we're done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *NetRes) Close() error { func (obj *NetRes) Cleanup() error {
if obj.socketFile == "/" { if obj.socketFile == "/" {
return fmt.Errorf("socket file should not be the root path") return fmt.Errorf("socket file should not be the root path")
} }

View File

@@ -57,8 +57,8 @@ func (obj *NoopRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *NoopRes) Close() error { func (obj *NoopRes) Cleanup() error {
return nil return nil
} }

View File

@@ -132,10 +132,10 @@ func (obj *NspawnRes) Init(init *engine.Init) error {
return obj.svc.Init(init) return obj.svc.Init(init)
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *NspawnRes) Close() error { func (obj *NspawnRes) Cleanup() error {
if obj.svc != nil { if obj.svc != nil {
return obj.svc.Close() return obj.svc.Cleanup()
} }
return nil return nil
} }

View File

@@ -89,8 +89,8 @@ func (obj *PasswordRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *PasswordRes) Close() error { func (obj *PasswordRes) Cleanup() error {
return nil return nil
} }

View File

@@ -87,8 +87,8 @@ func (obj *PippetRes) Init(init *engine.Init) error {
return obj.runner.Register() return obj.runner.Register()
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *PippetRes) Close() error { func (obj *PippetRes) Cleanup() error {
return obj.runner.Unregister() return obj.runner.Unregister()
} }

View File

@@ -96,8 +96,8 @@ func (obj *PkgRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *PkgRes) Close() error { func (obj *PkgRes) Cleanup() error {
return nil return nil
} }

View File

@@ -64,8 +64,8 @@ func (obj *PrintRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *PrintRes) Close() error { func (obj *PrintRes) Cleanup() error {
return nil return nil
} }

View File

@@ -543,9 +543,9 @@ func TestResources1(t *testing.T) {
} }
}() }()
closeFn := func() { closeFn := func() {
// run close (we don't ever expect an error on close!) // run cleanup (we don't ever expect an error on cleanup!)
t.Logf("test #%d: running Close", index) t.Logf("test #%d: running Cleanup", index)
if err := res.Close(); err != nil { if err := res.Cleanup(); err != nil {
t.Errorf("test #%d: FAIL", index) t.Errorf("test #%d: FAIL", index)
t.Errorf("test #%d: could not close Res: %+v", index, err) t.Errorf("test #%d: could not close Res: %+v", index, err)
//return //return
@@ -793,11 +793,11 @@ func TestResources2(t *testing.T) {
} }
return resCheckApplyError(res, expCheckOK, errOK) return resCheckApplyError(res, expCheckOK, errOK)
} }
// resClose runs Close on the res. // resCleanup runs CLeanup on the res.
resClose := func(res engine.Res) func() error { resCleanup := func(res engine.Res) func() error {
// run Close // run CLeanup
return func() error { return func() error {
return res.Close() return res.Cleanup()
} }
} }
// resReversal runs Reverse on the resource and stores the result in the // resReversal runs Reverse on the resource and stores the result in the
@@ -928,7 +928,7 @@ func TestResources2(t *testing.T) {
resCheckApply(r1, false), // changed resCheckApply(r1, false), // changed
fileExpect(p, content), fileExpect(p, content),
resCheckApply(r1, true), // it's already good resCheckApply(r1, true), // it's already good
resClose(r1), resCleanup(r1),
fileExpect(p, content), // ensure it exists fileExpect(p, content), // ensure it exists
} }
@@ -960,7 +960,7 @@ func TestResources2(t *testing.T) {
resCheckApply(r1, false), // changed resCheckApply(r1, false), // changed
fileExpect(p, content), fileExpect(p, content),
resCheckApply(r1, true), // it's already good resCheckApply(r1, true), // it's already good
resClose(r1), resCleanup(r1),
fileExpect(p, content), // ensure it exists fileExpect(p, content), // ensure it exists
} }
@@ -992,7 +992,7 @@ func TestResources2(t *testing.T) {
resInit(r1), resInit(r1),
resCheckApplyError(r1, false, ErrIsNotExistOK), // should error resCheckApplyError(r1, false, ErrIsNotExistOK), // should error
resCheckApplyError(r1, false, ErrIsNotExistOK), // double check resCheckApplyError(r1, false, ErrIsNotExistOK), // double check
resClose(r1), resCleanup(r1),
fileAbsent(p), // ensure it's absent fileAbsent(p), // ensure it's absent
} }
@@ -1021,7 +1021,7 @@ func TestResources2(t *testing.T) {
resInit(r1), resInit(r1),
resCheckApply(r1, true), resCheckApply(r1, true),
resCheckApply(r1, true), resCheckApply(r1, true),
resClose(r1), resCleanup(r1),
fileAbsent(p), // ensure it's absent fileAbsent(p), // ensure it's absent
} }
@@ -1050,7 +1050,7 @@ func TestResources2(t *testing.T) {
resInit(r1), resInit(r1),
resCheckApply(r1, false), resCheckApply(r1, false),
resCheckApply(r1, true), resCheckApply(r1, true),
resClose(r1), resCleanup(r1),
fileAbsent(p), // ensure it's absent fileAbsent(p), // ensure it's absent
} }
@@ -1094,7 +1094,7 @@ func TestResources2(t *testing.T) {
resCheckApply(r1, false), // changed resCheckApply(r1, false), // changed
fileExpect(p, content), fileExpect(p, content),
resCheckApply(r1, true), // it's already good resCheckApply(r1, true), // it's already good
resClose(r1), resCleanup(r1),
//resValidate(r2), // no!!! //resValidate(r2), // no!!!
func() error { func() error {
// wrap it b/c it is currently nil // wrap it b/c it is currently nil
@@ -1110,7 +1110,7 @@ func TestResources2(t *testing.T) {
return resCheckApply(r2, true)() return resCheckApply(r2, true)()
}, },
func() error { func() error {
return resClose(r2)() return resCleanup(r2)()
}, },
fileAbsent(p), // ensure it's absent fileAbsent(p), // ensure it's absent
} }
@@ -1156,7 +1156,7 @@ func TestResources2(t *testing.T) {
resCheckApply(r1, false), // changed resCheckApply(r1, false), // changed
fileExpect(p, content), fileExpect(p, content),
resCheckApply(r1, true), // it's already good resCheckApply(r1, true), // it's already good
resClose(r1), resCleanup(r1),
//resValidate(r2), //resValidate(r2),
func() error { func() error {
// wrap it b/c it is currently nil // wrap it b/c it is currently nil
@@ -1172,7 +1172,7 @@ func TestResources2(t *testing.T) {
return resCheckApply(r2, true)() return resCheckApply(r2, true)()
}, },
func() error { func() error {
return resClose(r2)() return resCleanup(r2)()
}, },
fileExpect(p, original), // we restored the contents! fileExpect(p, original), // we restored the contents!
fileRemove(p), // cleanup fileRemove(p), // cleanup
@@ -1220,7 +1220,7 @@ func TestResources2(t *testing.T) {
resCheckApplyError(r1, false, ErrIsNotExistOK), // changed resCheckApplyError(r1, false, ErrIsNotExistOK), // changed
//fileExpect(p, content), //fileExpect(p, content),
//resCheckApply(r1, true), // it's already good //resCheckApply(r1, true), // it's already good
resClose(r1), resCleanup(r1),
//func() error { //func() error {
// // wrap it b/c it is currently nil // // wrap it b/c it is currently nil
// return r2.Validate() // return r2.Validate()
@@ -1232,7 +1232,7 @@ func TestResources2(t *testing.T) {
// return resCheckApply(r2, true)() // return resCheckApply(r2, true)()
//}, //},
//func() error { //func() error {
// return resClose(r2)() // return resCleanup(r2)()
//}, //},
//fileExpect(p, content), // we never changed it back... //fileExpect(p, content), // we never changed it back...
//fileRemove(p), // cleanup //fileRemove(p), // cleanup
@@ -1275,7 +1275,7 @@ func TestResources2(t *testing.T) {
resCheckApply(r1, false), // changed resCheckApply(r1, false), // changed
fileAbsent(p), // ensure it got removed fileAbsent(p), // ensure it got removed
resCheckApply(r1, true), // it's already good resCheckApply(r1, true), // it's already good
resClose(r1), resCleanup(r1),
//resValidate(r2), // no!!! //resValidate(r2), // no!!!
func() error { func() error {
// wrap it b/c it is currently nil // wrap it b/c it is currently nil
@@ -1291,7 +1291,7 @@ func TestResources2(t *testing.T) {
return resCheckApply(r2, true)() return resCheckApply(r2, true)()
}, },
func() error { func() error {
return resClose(r2)() return resCleanup(r2)()
}, },
fileExpect(p, original), // ensure it's back to original fileExpect(p, original), // ensure it's back to original
} }
@@ -1357,7 +1357,7 @@ func TestResources2(t *testing.T) {
resCheckApply(r1, false), // changed resCheckApply(r1, false), // changed
fileExpect(p, content), fileExpect(p, content),
resCheckApply(r1, true), // it's already good resCheckApply(r1, true), // it's already good
resClose(r1), resCleanup(r1),
fileExpect(p, content), // ensure it exists fileExpect(p, content), // ensure it exists
} }
@@ -1394,7 +1394,7 @@ func TestResources2(t *testing.T) {
resCheckApply(r1, true), // it's already good resCheckApply(r1, true), // it's already good
fileExpect(p, content), // should already be like this fileExpect(p, content), // should already be like this
fileExpect(p2, content), // should not change either fileExpect(p2, content), // should not change either
resClose(r1), resCleanup(r1),
} }
testCases = append(testCases, test{ testCases = append(testCases, test{
@@ -1423,7 +1423,7 @@ func TestResources2(t *testing.T) {
fileExists(p, true), // ensure it's a dir fileExists(p, true), // ensure it's a dir
resCheckApply(r1, true), // it's already good resCheckApply(r1, true), // it's already good
fileExists(p, true), // ensure it's a dir fileExists(p, true), // ensure it's a dir
resClose(r1), resCleanup(r1),
} }
testCases = append(testCases, test{ testCases = append(testCases, test{
@@ -1494,7 +1494,7 @@ func TestResources2(t *testing.T) {
fileExists(d2f2, false), fileExists(d2f2, false),
fileExists(d2f3, false), fileExists(d2f3, false),
resCheckApply(r1, true), // it's already good resCheckApply(r1, true), // it's already good
resClose(r1), resCleanup(r1),
} }
testCases = append(testCases, test{ testCases = append(testCases, test{
@@ -1560,7 +1560,7 @@ func TestResources2(t *testing.T) {
fileAbsent(d2f2), fileAbsent(d2f2),
fileAbsent(d2f3), fileAbsent(d2f3),
resCheckApply(r1, true), // it's already good resCheckApply(r1, true), // it's already good
resClose(r1), resCleanup(r1),
} }
testCases = append(testCases, test{ testCases = append(testCases, test{
@@ -1646,17 +1646,17 @@ func TestResources2(t *testing.T) {
resValidate(r2), resValidate(r2),
resInit(r2), resInit(r2),
//resCheckApply(r2, false), // not really needed in test //resCheckApply(r2, false), // not really needed in test
resClose(r2), resCleanup(r2),
resValidate(r3), resValidate(r3),
resInit(r3), resInit(r3),
//resCheckApply(r3, false), // not really needed in test //resCheckApply(r3, false), // not really needed in test
resClose(r3), resCleanup(r3),
resValidate(r4), resValidate(r4),
resInit(r4), resInit(r4),
//resCheckApply(r4, false), // not really needed in test //resCheckApply(r4, false), // not really needed in test
resClose(r4), resCleanup(r4),
resValidate(r1), resValidate(r1),
resInit(r1, addGraph(graph), addLogf(nil)), // show the full graph resInit(r1, addGraph(graph), addLogf(nil)), // show the full graph
@@ -1675,7 +1675,7 @@ func TestResources2(t *testing.T) {
fileExists(p3, true), // ensure it's a dir fileExists(p3, true), // ensure it's a dir
fileExists(p4, false), fileExists(p4, false),
resCheckApply(r1, true), // it's already good resCheckApply(r1, true), // it's already good
resClose(r1), resCleanup(r1),
} }
testCases = append(testCases, test{ testCases = append(testCases, test{

View File

@@ -76,8 +76,8 @@ func (obj *SvcRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *SvcRes) Close() error { func (obj *SvcRes) Cleanup() error {
return nil return nil
} }

View File

@@ -119,8 +119,8 @@ func (obj *TestRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *TestRes) Close() error { func (obj *TestRes) Cleanup() error {
return nil return nil
} }

View File

@@ -134,8 +134,8 @@ func (obj *TFTPServerRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *TFTPServerRes) Close() error { func (obj *TFTPServerRes) Cleanup() error {
return nil return nil
} }
@@ -540,8 +540,8 @@ func (obj *TFTPFileRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *TFTPFileRes) Close() error { func (obj *TFTPFileRes) Cleanup() error {
return nil return nil
} }

View File

@@ -60,8 +60,8 @@ func (obj *TimerRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *TimerRes) Close() error { func (obj *TimerRes) Cleanup() error {
return nil return nil
} }

View File

@@ -105,8 +105,8 @@ func (obj *UserRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close is run by the engine to clean up after the resource is done. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *UserRes) Close() error { func (obj *UserRes) Cleanup() error {
return nil return nil
} }

View File

@@ -239,8 +239,8 @@ func (obj *VirtRes) Init(init *engine.Init) error {
return nil return nil
} }
// Close runs some cleanup code for this resource. // Cleanup is run by the engine to clean up after the resource is done.
func (obj *VirtRes) Close() error { func (obj *VirtRes) Cleanup() error {
// By the time that this Close method is called, the engine promises // By the time that this Close method is called, the engine promises
// that the Watch loop has previously shutdown! (Assuming no bugs!) // that the Watch loop has previously shutdown! (Assuming no bugs!)
// TODO: As a result, this is an extra check which shouldn't be needed, // TODO: As a result, this is an extra check which shouldn't be needed,

View File

@@ -178,7 +178,7 @@ type testEngineRes struct {
func (t *testEngineRes) CheckApply(bool) (bool, error) { return false, nil } func (t *testEngineRes) CheckApply(bool) (bool, error) { return false, nil }
func (t *testEngineRes) Close() error { return nil } func (t *testEngineRes) Cleanup() error { return nil }
func (t *testEngineRes) Cmp(engine.Res) error { return nil } func (t *testEngineRes) Cmp(engine.Res) error { return nil }