This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: allow running unit tests using podman
Refactor unit test so that podman can be used to run tests when docker is not available. Fixes: #2006 Signed-off-by: Marco Vedovati <[email protected]>
- Loading branch information
Showing
4 changed files
with
136 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright (c) 2019 SUSE LLC | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
package katautils | ||
|
||
import ( | ||
"os/exec" | ||
) | ||
|
||
type CtrEngine struct { | ||
Name string | ||
} | ||
|
||
var ( | ||
DockerLikeCtrEngines = []string{"docker", "podman"} | ||
) | ||
|
||
func (e *CtrEngine) Init(name string) (string, error) { | ||
var out string | ||
out, err := RunCommandFull([]string{name, "version"}, true) | ||
if err != nil { | ||
return out, err | ||
} | ||
|
||
e.Name = name | ||
return out, nil | ||
} | ||
|
||
func (e *CtrEngine) Inspect(image string) (string, error) { | ||
// Only hit the network if the image doesn't exist locally | ||
return RunCommand([]string{e.Name, "inspect", "--type=image", image}) | ||
} | ||
|
||
func (e *CtrEngine) Pull(image string) (string, error) { | ||
return RunCommand([]string{e.Name, "pull", image}) | ||
} | ||
|
||
func (e *CtrEngine) Create(image string) (string, error) { | ||
return RunCommand([]string{e.Name, "create", image}) | ||
} | ||
|
||
func (e *CtrEngine) Rm(ctrID string) (string, error) { | ||
return RunCommand([]string{e.Name, "rm", ctrID}) | ||
} | ||
|
||
func (e *CtrEngine) GetRootfs(ctrID string, dir string) error { | ||
cmd1 := exec.Command(e.Name, "export", ctrID) | ||
cmd2 := exec.Command("tar", "-C", dir, "-xvf", "-") | ||
|
||
cmd1Stdout, err := cmd1.StdoutPipe() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cmd2.Stdin = cmd1Stdout | ||
|
||
err = cmd2.Start() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = cmd1.Run() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = cmd2.Wait() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
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