-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: use mock puller and mounter in the node server tests (#83)
* edit: docs to run node server with containerd image * refactor: remove commented out code * chore: switch over from criapi `v1alpha2` -> `v1` * chore: fix import path name `csi-driver-image` -> `container-image-csi-driver` * docs: replace `warm metal` -> `container-image-csi-driver` * test: fix socket path `/tmp/csi/csi.sock` -> `/tmp/csi.sock`
- Loading branch information
1 parent
4d6fa73
commit 82d2e85
Showing
13 changed files
with
186 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package utils | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/containerd/containerd/reference/docker" | ||
"github.com/warm-metal/container-image-csi-driver/pkg/backend" | ||
"google.golang.org/grpc" | ||
criapi "k8s.io/cri-api/pkg/apis/runtime/v1" | ||
) | ||
|
||
type MockImageServiceClient struct { | ||
PulledImages map[string]bool | ||
ImagePullTime time.Duration | ||
} | ||
|
||
type MockMounter struct { | ||
ImageSvcClient MockImageServiceClient | ||
Mounted map[string]bool | ||
} | ||
|
||
const hundredMB = 104857600 | ||
|
||
func (m *MockMounter) Mount( | ||
ctx context.Context, volumeId string, target backend.MountTarget, image docker.Named, ro bool) (err error) { | ||
m.Mounted[volumeId] = true | ||
return nil | ||
} | ||
|
||
// Unmount unmounts a specific image | ||
func (m *MockMounter) Unmount(ctx context.Context, volumeId string, target backend.MountTarget) error { | ||
if m.Mounted[volumeId] { | ||
delete(m.Mounted, volumeId) | ||
return nil | ||
} | ||
return fmt.Errorf("image mount not found") | ||
} | ||
|
||
// ImageExists checks if the image already exists on the local machine | ||
func (m *MockMounter) ImageExists(ctx context.Context, image docker.Named) bool { | ||
return m.ImageSvcClient.PulledImages[image.Name()] | ||
} | ||
|
||
func (c *MockImageServiceClient) ListImages(ctx context.Context, in *criapi.ListImagesRequest, opts ...grpc.CallOption) (*criapi.ListImagesResponse, error) { | ||
resp := new(criapi.ListImagesResponse) | ||
resp.Images = []*criapi.Image{} | ||
|
||
for k := range c.PulledImages { | ||
resp.Images = append(resp.Images, &criapi.Image{ | ||
Id: k, | ||
// 100MB | ||
Size_: hundredMB, | ||
Spec: &criapi.ImageSpec{ | ||
Image: k, | ||
}, | ||
}) | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
func (c *MockImageServiceClient) ImageStatus(ctx context.Context, in *criapi.ImageStatusRequest, opts ...grpc.CallOption) (*criapi.ImageStatusResponse, error) { | ||
resp := new(criapi.ImageStatusResponse) | ||
resp.Image = &criapi.Image{ | ||
Id: in.Image.Image, | ||
Size_: hundredMB, | ||
Spec: &criapi.ImageSpec{ | ||
Image: in.Image.Image, | ||
}, | ||
} | ||
return resp, nil | ||
} | ||
|
||
func (c *MockImageServiceClient) PullImage(ctx context.Context, in *criapi.PullImageRequest, opts ...grpc.CallOption) (*criapi.PullImageResponse, error) { | ||
resp := new(criapi.PullImageResponse) | ||
resp.ImageRef = in.Image.Image | ||
time.Sleep(c.ImagePullTime) | ||
|
||
return resp, nil | ||
} | ||
|
||
func (c *MockImageServiceClient) RemoveImage(ctx context.Context, in *criapi.RemoveImageRequest, opts ...grpc.CallOption) (*criapi.RemoveImageResponse, error) { | ||
resp := new(criapi.RemoveImageResponse) | ||
delete(c.PulledImages, in.Image.Image) | ||
return resp, nil | ||
} | ||
|
||
func (c *MockImageServiceClient) ImageFsInfo(ctx context.Context, in *criapi.ImageFsInfoRequest, opts ...grpc.CallOption) (*criapi.ImageFsInfoResponse, error) { | ||
resp := new(criapi.ImageFsInfoResponse) | ||
resp.ImageFilesystems = []*criapi.FilesystemUsage{} | ||
|
||
for _ = range c.PulledImages { | ||
resp.ImageFilesystems = append(resp.ImageFilesystems, &criapi.FilesystemUsage{ | ||
Timestamp: time.Now().Unix(), | ||
FsId: &criapi.FilesystemIdentifier{ | ||
Mountpoint: "target", | ||
}, | ||
UsedBytes: &criapi.UInt64Value{ | ||
Value: hundredMB, | ||
}, | ||
InodesUsed: &criapi.UInt64Value{ | ||
// random value | ||
Value: 10, | ||
}, | ||
}) | ||
} | ||
|
||
return resp, nil | ||
} |
File renamed without changes.
Oops, something went wrong.