Skip to content

Commit

Permalink
if parameters.isc doesn't exist, don't try to switch to manager user
Browse files Browse the repository at this point in the history
  • Loading branch information
b-dean committed May 28, 2024
1 parent 4ac2c8f commit 2456827
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
21 changes: 21 additions & 0 deletions instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ func (i *Instance) managerSysProc() (*syscall.SysProcAttr, error) {

mgr, _, err := i.DetermineManager()
if err != nil {
var pIscErr *ParametersISCNotExistError
if errors.As(err, &pIscErr) {
log.WithError(pIscErr).Debug("cannot determine manager")
return nil, nil
}
return nil, err
}

Expand Down Expand Up @@ -644,11 +649,27 @@ func (i *Instance) ExecuteString(namespace string, code string) (string, error)
return i.Execute(namespace, b)
}

type ParametersISCNotExistError struct {
dir string
err error
}

func (e *ParametersISCNotExistError) Error() string {
return fmt.Sprintf("parameters.isc not found in %s. err: %s", e.dir, e.err.Error())
}

func (e *ParametersISCNotExistError) Unwrap() error {
return e.err
}

// ReadParametersISC will read the current instances parameters ISC file into a simple data structure.
// It returns the ParametersISC data structure and any error encountered.
func (i *Instance) ReadParametersISC() (ParametersISC, error) {
f, err := parameterReader(i.Directory, iscParametersFile)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return nil, &ParametersISCNotExistError{dir: i.Directory, err: err}
}
return nil, err
}
defer f.Close()
Expand Down
21 changes: 21 additions & 0 deletions instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"fmt"
"io"
"os"
"os/user"
"syscall"
"time"
Expand Down Expand Up @@ -192,6 +193,7 @@ var _ = Describe("Instance", func() {
})
})
})

Describe("DetermineISCDatFileName", func() {
Context("The product is Cache", func() {
It("Returns the correct DAT filename", func() {
Expand Down Expand Up @@ -550,4 +552,23 @@ var _ = Describe("Instance", func() {
})
})
})

Describe("Update", func() {
// To test instance updates when running somewhere that doesn't actually have access to the
// parameters.isc file, such as `iscenv` wrapping `csession` or `iris`
Context("Valid qlist without parameters.isc", func() {
BeforeEach(func() {
parameterReader = func(directory string, file string) (io.ReadCloser, error) {
return nil, os.ErrNotExist
}
instance, err = InstanceFromQList(cacheqlist)
Expect(err).ToNot(HaveOccurred())
})

It("Does not return an error", func() {
err := instance.Update()
Expect(err).NotTo(HaveOccurred())
})
})
})
})

0 comments on commit 2456827

Please sign in to comment.