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

Fix error injection surface in FakeRuntimeService #77814

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
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func (r *FakeRuntimeService) popError(f string) error {
return nil
}
err, errs := errs[0], errs[1:]
r.Errors[f] = errs
return err
}

Expand All @@ -144,6 +145,9 @@ func (r *FakeRuntimeService) Version(apiVersion string) (*runtimeapi.VersionResp
defer r.Unlock()

r.Called = append(r.Called, "Version")
if err := r.popError("Version"); err != nil {
return nil, err
}

return &runtimeapi.VersionResponse{
Version: FakeVersion,
Expand All @@ -158,6 +162,9 @@ func (r *FakeRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
defer r.Unlock()

r.Called = append(r.Called, "Status")
if err := r.popError("Status"); err != nil {
return nil, err
}

return r.FakeStatus, nil
}
Expand All @@ -167,6 +174,9 @@ func (r *FakeRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig,
defer r.Unlock()

r.Called = append(r.Called, "RunPodSandbox")
if err := r.popError("RunPodSandbox"); err != nil {
return "", err
}

// PodSandboxID should be randomized for real container runtime, but here just use
// fixed name from BuildSandboxName() for easily making fake sandboxes.
Expand Down Expand Up @@ -196,6 +206,9 @@ func (r *FakeRuntimeService) StopPodSandbox(podSandboxID string) error {
defer r.Unlock()

r.Called = append(r.Called, "StopPodSandbox")
if err := r.popError("StopPodSandbox"); err != nil {
return err
}

if s, ok := r.Sandboxes[podSandboxID]; ok {
s.State = runtimeapi.PodSandboxState_SANDBOX_NOTREADY
Expand All @@ -211,6 +224,9 @@ func (r *FakeRuntimeService) RemovePodSandbox(podSandboxID string) error {
defer r.Unlock()

r.Called = append(r.Called, "RemovePodSandbox")
if err := r.popError("RemovePodSandbox"); err != nil {
return err
}

// Remove the pod sandbox
delete(r.Sandboxes, podSandboxID)
Expand All @@ -223,6 +239,9 @@ func (r *FakeRuntimeService) PodSandboxStatus(podSandboxID string) (*runtimeapi.
defer r.Unlock()

r.Called = append(r.Called, "PodSandboxStatus")
if err := r.popError("PodSandboxStatus"); err != nil {
return nil, err
}

s, ok := r.Sandboxes[podSandboxID]
if !ok {
Expand All @@ -238,6 +257,9 @@ func (r *FakeRuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter)
defer r.Unlock()

r.Called = append(r.Called, "ListPodSandbox")
if err := r.popError("ListPodSandbox"); err != nil {
return nil, err
}

result := make([]*runtimeapi.PodSandbox, 0)
for id, s := range r.Sandboxes {
Expand Down Expand Up @@ -272,6 +294,10 @@ func (r *FakeRuntimeService) PortForward(*runtimeapi.PortForwardRequest) (*runti
defer r.Unlock()

r.Called = append(r.Called, "PortForward")
if err := r.popError("PortForward"); err != nil {
return nil, err
}

return &runtimeapi.PortForwardResponse{}, nil
}

Expand All @@ -280,6 +306,9 @@ func (r *FakeRuntimeService) CreateContainer(podSandboxID string, config *runtim
defer r.Unlock()

r.Called = append(r.Called, "CreateContainer")
if err := r.popError("CreateContainer"); err != nil {
return "", err
}

// ContainerID should be randomized for real container runtime, but here just use
// fixed BuildContainerName() for easily making fake containers.
Expand Down Expand Up @@ -309,6 +338,9 @@ func (r *FakeRuntimeService) StartContainer(containerID string) error {
defer r.Unlock()

r.Called = append(r.Called, "StartContainer")
if err := r.popError("StartContainer"); err != nil {
return err
}

c, ok := r.Containers[containerID]
if !ok {
Expand All @@ -327,6 +359,9 @@ func (r *FakeRuntimeService) StopContainer(containerID string, timeout int64) er
defer r.Unlock()

r.Called = append(r.Called, "StopContainer")
if err := r.popError("StopContainer"); err != nil {
return err
}

c, ok := r.Containers[containerID]
if !ok {
Expand All @@ -347,6 +382,9 @@ func (r *FakeRuntimeService) RemoveContainer(containerID string) error {
defer r.Unlock()

r.Called = append(r.Called, "RemoveContainer")
if err := r.popError("RemoveContainer"); err != nil {
return err
}

// Remove the container
delete(r.Containers, containerID)
Expand All @@ -359,6 +397,9 @@ func (r *FakeRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter)
defer r.Unlock()

r.Called = append(r.Called, "ListContainers")
if err := r.popError("ListContainers"); err != nil {
return nil, err
}

result := make([]*runtimeapi.Container, 0)
for _, s := range r.Containers {
Expand Down Expand Up @@ -398,6 +439,9 @@ func (r *FakeRuntimeService) ContainerStatus(containerID string) (*runtimeapi.Co
defer r.Unlock()

r.Called = append(r.Called, "ContainerStatus")
if err := r.popError("ContainerStatus"); err != nil {
return nil, err
}

c, ok := r.Containers[containerID]
if !ok {
Expand All @@ -413,22 +457,27 @@ func (r *FakeRuntimeService) UpdateContainerResources(string, *runtimeapi.LinuxC
defer r.Unlock()

r.Called = append(r.Called, "UpdateContainerResources")
return nil
return r.popError("UpdateContainerResources")
}

func (r *FakeRuntimeService) ExecSync(containerID string, cmd []string, timeout time.Duration) (stdout []byte, stderr []byte, err error) {
r.Lock()
defer r.Unlock()

r.Called = append(r.Called, "ExecSync")
return nil, nil, nil
err = r.popError("ExecSync")
return
}

func (r *FakeRuntimeService) Exec(*runtimeapi.ExecRequest) (*runtimeapi.ExecResponse, error) {
r.Lock()
defer r.Unlock()

r.Called = append(r.Called, "Exec")
if err := r.popError("Exec"); err != nil {
return nil, err
}

return &runtimeapi.ExecResponse{}, nil
}

Expand All @@ -437,11 +486,19 @@ func (r *FakeRuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeapi.
defer r.Unlock()

r.Called = append(r.Called, "Attach")
if err := r.popError("Attach"); err != nil {
return nil, err
}

return &runtimeapi.AttachResponse{}, nil
}

func (r *FakeRuntimeService) UpdateRuntimeConfig(runtimeCOnfig *runtimeapi.RuntimeConfig) error {
return nil
r.Lock()
defer r.Unlock()

r.Called = append(r.Called, "UpdateRuntimeConfig")
return r.popError("UpdateRuntimeConfig")
}

func (r *FakeRuntimeService) SetFakeContainerStats(containerStats []*runtimeapi.ContainerStats) {
Expand All @@ -459,6 +516,9 @@ func (r *FakeRuntimeService) ContainerStats(containerID string) (*runtimeapi.Con
defer r.Unlock()

r.Called = append(r.Called, "ContainerStats")
if err := r.popError("ContainerStats"); err != nil {
return nil, err
}

s, found := r.FakeContainerStats[containerID]
if !found {
Expand All @@ -472,6 +532,9 @@ func (r *FakeRuntimeService) ListContainerStats(filter *runtimeapi.ContainerStat
defer r.Unlock()

r.Called = append(r.Called, "ListContainerStats")
if err := r.popError("ListContainerStats"); err != nil {
return nil, err
}

var result []*runtimeapi.ContainerStats
for _, c := range r.Containers {
Expand Down