From bd175fc5207cfa7bf30ca62e2ef830192059ba68 Mon Sep 17 00:00:00 2001 From: Nico Cesar Date: Tue, 16 Mar 2021 11:25:25 -0400 Subject: [PATCH] Added getImage() setImage() to the ThinContainerExecRunner interface Arvados-DCO-1.1-Signed-off-by: Nico Cesar --- build/run-tests.sh | 2 +- lib/crunchrun/container_exec_types.go | 4 ++++ lib/crunchrun/crunchrun.go | 6 +++--- lib/crunchrun/crunchrun_test.go | 8 ++++---- lib/crunchrun/docker_adapter.go | 7 +++++++ lib/crunchrun/singularity.go | 8 ++++++++ 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/build/run-tests.sh b/build/run-tests.sh index d6dc43416a..4a2a12c17e 100755 --- a/build/run-tests.sh +++ b/build/run-tests.sh @@ -964,7 +964,7 @@ install_services/api() { set -ex cd "$WORKSPACE/services/api" export RAILS_ENV=test - if "$bundle" exec rails db:environment:set ; then + if bin/rails db:environment:set ; then "$bundle" exec rake db:drop fi "$bundle" exec rake db:setup diff --git a/lib/crunchrun/container_exec_types.go b/lib/crunchrun/container_exec_types.go index cc78a29dff..fc865af73e 100644 --- a/lib/crunchrun/container_exec_types.go +++ b/lib/crunchrun/container_exec_types.go @@ -19,6 +19,7 @@ import ( // "It should hold only portable information about the container." // and for Singularity TBD type ContainerConfig struct { + Image string OpenStdin bool StdinOnce bool AttachStdin bool @@ -280,6 +281,9 @@ type ThinContainerExecRunner interface { GetContainerConfig() (ContainerConfig, error) GetHostConfig() (HostConfig, error) + GetImage() (imageID string) + SetImage(imageID string) + ContainerAttach(ctx context.Context, container string, options ContainerAttachOptions) (HijackedResponse, error) ContainerCreate(ctx context.Context, config ContainerConfig, hostConfig HostConfig, networkingConfig *NetworkingConfig, containerName string) (ContainerCreateResponse, error) ContainerStart(ctx context.Context, container string, options ContainerStartOptions) error diff --git a/lib/crunchrun/crunchrun.go b/lib/crunchrun/crunchrun.go index fb6aaee999..ad10b6f9cf 100644 --- a/lib/crunchrun/crunchrun.go +++ b/lib/crunchrun/crunchrun.go @@ -98,8 +98,8 @@ type ContainerRunner struct { ContainerExecRunner ThinContainerExecRunner //Docker ThinDockerClient - ContainerConfig dockercontainer.Config //FIXME: translate this to the ThinContainerRunner interface - HostConfig dockercontainer.HostConfig //FIXME: translate this to the ThinContainerRunner interface + //ContainerConfig dockercontainer.Config //FIXME: translate this to the ThinContainerRunner interface + HostConfig dockercontainer.HostConfig //FIXME: translate this to the ThinContainerRunner interface //-------------- // Dispatcher client is initialized with the Dispatcher token. @@ -311,7 +311,7 @@ func (runner *ContainerRunner) LoadImage() (err error) { runner.CrunchLog.Print("Docker image is available") } - runner.ContainerConfig.Image = imageID + runner.ContainerExecRunner.SetImage(imageID) runner.ContainerKeepClient.ClearBlockCache() diff --git a/lib/crunchrun/crunchrun_test.go b/lib/crunchrun/crunchrun_test.go index ddf40543e7..08f3a938dd 100644 --- a/lib/crunchrun/crunchrun_test.go +++ b/lib/crunchrun/crunchrun_test.go @@ -457,7 +457,7 @@ func (s *TestSuite) TestLoadImage(c *C) { // (1) Test loading image from keep c.Check(kc.Called, Equals, false) - c.Check(cr.ContainerConfig.Image, Equals, "") + c.Check(cr.ContainerExecRunner.GetImage(), Equals, "") err = cr.LoadImage() @@ -467,19 +467,19 @@ func (s *TestSuite) TestLoadImage(c *C) { }() c.Check(kc.Called, Equals, true) - c.Check(cr.ContainerConfig.Image, Equals, hwImageID) + c.Check(cr.ContainerExecRunner.GetImage(), Equals, hwImageID) _, _, err = cr.ContainerExecRunner.ImageInspectWithRaw(nil, hwImageID) c.Check(err, IsNil) // (2) Test using image that's already loaded kc.Called = false - cr.ContainerConfig.Image = "" + cr.ContainerExecRunner.SetImage("") err = cr.LoadImage() c.Check(err, IsNil) c.Check(kc.Called, Equals, false) - c.Check(cr.ContainerConfig.Image, Equals, hwImageID) + c.Check(cr.ContainerExecRunner.GetImage(), Equals, hwImageID) } diff --git a/lib/crunchrun/docker_adapter.go b/lib/crunchrun/docker_adapter.go index 795d06b567..1019e7df7b 100644 --- a/lib/crunchrun/docker_adapter.go +++ b/lib/crunchrun/docker_adapter.go @@ -211,6 +211,13 @@ func (a *DockerAdapter) GetContainerConfig() (ContainerConfig, error) { func (a *DockerAdapter) GetHostConfig() (HostConfig, error) { return a.hostConfig, nil } +func (a *DockerAdapter) GetImage() (imageID string) { + return a.containerConfig.Image +} + +func (a *DockerAdapter) SetImage(imageID string) { + a.containerConfig.Image = imageID +} func adapter(docker ThinDockerClient) ThinContainerExecRunner { return_object := &DockerAdapter{docker: docker} diff --git a/lib/crunchrun/singularity.go b/lib/crunchrun/singularity.go index 91ec0ea114..6b36e68669 100644 --- a/lib/crunchrun/singularity.go +++ b/lib/crunchrun/singularity.go @@ -24,6 +24,14 @@ func (c SingularityClient) GetHostConfig() (HostConfig, error) { return c.hostConfig, nil } +func (c SingularityClient) GetImage() (imageID string) { + return c.containerConfig.Image +} + +func (c SingularityClient) SetImage(imageID string) { + c.containerConfig.Image = imageID +} + func (c SingularityClient) ContainerAttach(ctx context.Context, container string, options ContainerAttachOptions) (HijackedResponse, error) { fmt.Printf("placeholder for container ContainerAttach %s", container) -- 2.30.2