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

systemd: provide more detailed errors for unimplemented method in emulation mode #11150

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 27 additions & 22 deletions systemd/emulation.go
Expand Up @@ -20,7 +20,6 @@
package systemd

import (
"errors"
"fmt"
"io"
"os"
Expand All @@ -39,18 +38,24 @@ type emulation struct {
rootDir string
}

var errNotImplemented = errors.New("not implemented in emulation mode")
type notImplementedError struct {
op string
}

func (e *notImplementedError) Error() string {
return fmt.Sprintf("%q is not implemented in emulation mode", e.op)
}

func (s *emulation) Backend() Backend {
return EmulationModeBackend
}

func (s *emulation) DaemonReload() error {
return errNotImplemented
return &notImplementedError{"DaemonReload"}
}

func (s *emulation) DaemonReexec() error {
return errNotImplemented
return &notImplementedError{"DaemonReexec"}
}

func (s *emulation) Enable(service string) error {
Expand All @@ -64,59 +69,59 @@ func (s *emulation) Disable(service string) error {
}

func (s *emulation) Start(service ...string) error {
return errNotImplemented
return &notImplementedError{"Start"}
}

func (s *emulation) StartNoBlock(service ...string) error {
return errNotImplemented
return &notImplementedError{"StartNoBlock"}
}

func (s *emulation) Stop(service string, timeout time.Duration) error {
return errNotImplemented
return &notImplementedError{"Stop"}
}

func (s *emulation) Kill(service, signal, who string) error {
return errNotImplemented
return &notImplementedError{"Kill"}
}

func (s *emulation) Restart(service string, timeout time.Duration) error {
return errNotImplemented
return &notImplementedError{"Restart"}
}

func (s *emulation) ReloadOrRestart(service string) error {
return errNotImplemented
return &notImplementedError{"ReloadOrRestart"}
}

func (s *emulation) RestartAll(service string) error {
return errNotImplemented
return &notImplementedError{"RestartAll"}
}

func (s *emulation) Status(units ...string) ([]*UnitStatus, error) {
return nil, errNotImplemented
return nil, &notImplementedError{"Status"}
}

func (s *emulation) InactiveEnterTimestamp(unit string) (time.Time, error) {
return time.Time{}, errNotImplemented
return time.Time{}, &notImplementedError{"InactiveEnterTimestamp"}
}

func (s *emulation) CurrentMemoryUsage(unit string) (quantity.Size, error) {
return 0, errNotImplemented
return 0, &notImplementedError{"CurrentMemoryUsage"}
}

func (s *emulation) CurrentTasksCount(unit string) (uint64, error) {
return 0, errNotImplemented
return 0, &notImplementedError{"CurrentTasksCount"}
}

func (s *emulation) IsEnabled(service string) (bool, error) {
return false, errNotImplemented
return false, &notImplementedError{"IsEnabled"}
}

func (s *emulation) IsActive(service string) (bool, error) {
return false, errNotImplemented
return false, &notImplementedError{"IsActive"}
}

func (s *emulation) LogReader(services []string, n int, follow bool) (io.ReadCloser, error) {
return nil, errNotImplemented
return nil, fmt.Errorf("LogReader")
}

func (s *emulation) AddMountUnitFile(snapName, revision, what, where, fstype string) (string, error) {
Expand Down Expand Up @@ -163,7 +168,7 @@ func (s *emulation) AddMountUnitFile(snapName, revision, what, where, fstype str
}

func (s *emulation) AddMountUnitFileWithOptions(unitOptions *MountUnitOptions) (string, error) {
return "", errNotImplemented
return "", &notImplementedError{"AddMountUnitFileWithOptions"}
}

func (s *emulation) RemoveMountUnitFile(mountedDir string) error {
Expand Down Expand Up @@ -197,7 +202,7 @@ func (s *emulation) RemoveMountUnitFile(mountedDir string) error {
}

func (s *emulation) ListMountUnits(snapName, origin string) ([]string, error) {
return nil, errNotImplemented
return nil, &notImplementedError{"ListMountUnits"}
}

func (s *emulation) Mask(service string) error {
Expand All @@ -211,9 +216,9 @@ func (s *emulation) Unmask(service string) error {
}

func (s *emulation) Mount(what, where string, options ...string) error {
return errNotImplemented
return &notImplementedError{"Mount"}
}

func (s *emulation) Umount(whatOrWhere string) error {
return errNotImplemented
return &notImplementedError{"Umount"}
}