Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if parameters.isc doesn't exist, don't try to switch to manager user #18

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
})
})
})
})
Loading