本文整理汇总了Golang中github.com/coreos/rkt/tests/testutils.RktRunCtx.Cmd方法的典型用法代码示例。如果您正苦于以下问题:Golang RktRunCtx.Cmd方法的具体用法?Golang RktRunCtx.Cmd怎么用?Golang RktRunCtx.Cmd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coreos/rkt/tests/testutils.RktRunCtx
的用法示例。
在下文中一共展示了RktRunCtx.Cmd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getCreationStartTime
func getCreationStartTime(t *testing.T, ctx *testutils.RktRunCtx, imageID string) (creation time.Time, start time.Time) {
// Run rkt list --full
rktCmd := fmt.Sprintf("%s list --full", ctx.Cmd())
child := spawnOrFail(t, rktCmd)
child.Wait()
// Get creation time
match := fmt.Sprintf(".*%s\t.*\t(.*)\t(.*)\t", imageID)
result, out, err := expectRegexWithOutput(child, match)
if err != nil {
t.Fatalf("%q regex not found, Error: %v\nOutput: %v", match, err, out)
}
tmStr := strings.TrimSpace(result[1])
creation, err = time.Parse(defaultTimeLayout, tmStr)
if err != nil {
t.Fatalf("Error parsing creation time: %q", err)
}
tmStr = strings.TrimSpace(result[2])
start, err = time.Parse(defaultTimeLayout, tmStr)
if err != nil {
t.Fatalf("Error parsing start time: %q", err)
}
return creation, start
}
示例2: waitPodReady
// waitPodReady waits for the pod supervisor to get ready, busy-looping until `timeout`
// while waiting for it. It returns the pod UUID or an error on failure.
func waitPodReady(ctx *testutils.RktRunCtx, t *testing.T, uuidFile string, timeout time.Duration) (string, error) {
var podUUID []byte
var err error
interval := 500 * time.Millisecond
elapsed := time.Duration(0)
for elapsed < timeout {
time.Sleep(interval)
elapsed += interval
podUUID, err = ioutil.ReadFile(uuidFile)
if err == nil {
break
}
}
if err != nil {
return "", fmt.Errorf("Can't read pod UUID: %v", err)
}
// wait up to one minute for the pod supervisor to be ready
cmd := strings.Fields(fmt.Sprintf("%s status --wait-ready=%s %s", ctx.Cmd(), timeout, podUUID))
statusCmd := exec.Command(cmd[0], cmd[1:]...)
t.Logf("Running command: %v\n", cmd)
output, err := statusCmd.CombinedOutput()
if err != nil {
return "", fmt.Errorf("Failed to wait for pod readiness, error %v output %v", err, string(output))
}
return string(podUUID), nil
}
示例3: runRktTrust
func runRktTrust(t *testing.T, ctx *testutils.RktRunCtx, prefix string) {
var cmd string
if prefix == "" {
cmd = fmt.Sprintf(`%s trust --root %s`, ctx.Cmd(), "key.gpg")
} else {
cmd = fmt.Sprintf(`%s trust --prefix %s %s`, ctx.Cmd(), prefix, "key.gpg")
}
child := spawnOrFail(t, cmd)
defer waitOrFail(t, child, true)
expected := "Are you sure you want to trust this key"
if err := expectWithOutput(child, expected); err != nil {
t.Fatalf("Expected but didn't find %q in %v", expected, err)
}
if err := child.SendLine("yes"); err != nil {
t.Fatalf("Cannot confirm rkt trust: %s", err)
}
if prefix == "" {
expected = "Added root key at"
} else {
expected = fmt.Sprintf(`Added key for prefix "%s" at`, prefix)
}
if err := expectWithOutput(child, expected); err != nil {
t.Fatalf("Expected but didn't find %q in %v", expected, err)
}
}
示例4: startAPIService
func startAPIService(t *testing.T, ctx *testutils.RktRunCtx) *gexpect.ExpectSubprocess {
noUidGid := false
gid, err := common.LookupGid(common.RktGroup)
if err != nil {
t.Logf("no %q group, will run api service with root, ONLY DO THIS FOR TESTING!", common.RktGroup)
noUidGid = true
} else {
if err := ctx.SetupDataDir(); err != nil {
t.Fatalf("failed to setup data directory: %v", err)
}
}
u, err := user.Lookup("nobody")
if err != nil {
t.Logf(`no "nobody" user, will run api service with root, ONLY DO THIS FOR TESTING!`)
noUidGid = true
}
uid, err := strconv.Atoi(u.Uid)
if err != nil {
t.Fatalf(`failed to parse "nobody" UID: %v`, err)
}
t.Logf("Running rkt api service")
apisvcCmd := fmt.Sprintf("%s api-service", ctx.Cmd())
if noUidGid {
return startRktAndCheckOutput(t, apisvcCmd, "API service running")
}
return startRktAsUidGidAndCheckOutput(t, apisvcCmd, "API service running", false, uid, gid)
}
示例5: patchImportAndRun
func patchImportAndRun(image string, patches []string, t *testing.T, ctx *testutils.RktRunCtx) {
imagePath := patchTestACI(image, patches...)
defer os.Remove(imagePath)
cmd := fmt.Sprintf("%s --insecure-skip-verify run %s", ctx.Cmd(), imagePath)
spawnAndWaitOrFail(t, cmd, true)
}
示例6: patchImportAndPrepare
func patchImportAndPrepare(image string, patches []string, t *testing.T, ctx *testutils.RktRunCtx) {
imagePath := patchTestACI(image, patches...)
defer os.Remove(imagePath)
cmd := fmt.Sprintf("%s --insecure-options=image prepare %s", ctx.Cmd(), imagePath)
spawnAndWaitOrFail(t, cmd, 0)
}
示例7: importImageAndFetchHashAsGid
func importImageAndFetchHashAsGid(t *testing.T, ctx *testutils.RktRunCtx, img string, gid int) string {
// Import the test image into store manually.
cmd := fmt.Sprintf("%s --insecure-skip-verify fetch %s", ctx.Cmd(), img)
// TODO(jonboulle): non-root user breaks trying to read root-written
// config directories. Should be a better way to approach this. Should
// config directories be readable by the rkt group too?
if gid != 0 {
cmd = fmt.Sprintf("%s --insecure-skip-verify fetch %s", ctx.CmdNoConfig(), img)
}
child, err := gexpect.Command(cmd)
if err != nil {
t.Fatalf("cannot create rkt command: %v", err)
}
if gid != 0 {
child.Cmd.SysProcAttr = &syscall.SysProcAttr{}
child.Cmd.SysProcAttr.Credential = &syscall.Credential{Uid: nobodyUid, Gid: uint32(gid)}
}
err = child.Start()
if err != nil {
t.Fatalf("cannot exec rkt: %v", err)
}
// Read out the image hash.
result, out, err := expectRegexWithOutput(child, "sha512-[0-9a-f]{32}")
if err != nil || len(result) != 1 {
t.Fatalf("Error: %v\nOutput: %v", err, out)
}
waitOrFail(t, child, true)
return result[0]
}
示例8: removeImage
func removeImage(t *testing.T, ctx *testutils.RktRunCtx, images ...string) {
cmd := fmt.Sprintf("%s image rm %s", ctx.Cmd(), strings.Join(images, " "))
child, err := gexpect.Spawn(cmd)
if err != nil {
t.Fatalf("Cannot exec: %v", err)
}
if err := expectWithOutput(child, rmImageOk); err != nil {
t.Fatalf("Expected %q but not found: %v", rmImageOk, err)
}
if err := child.Wait(); err != nil {
t.Fatalf("rkt didn't terminate correctly: %v", err)
}
}
示例9: launchPods
func launchPods(ctx *testutils.RktRunCtx, numOfPods int, imagePath string) {
t := new(testing.T) // Print no messages.
cmd := fmt.Sprintf("%s --insecure-options=all run %s", ctx.Cmd(), imagePath)
var wg sync.WaitGroup
wg.Add(numOfPods)
for i := 0; i < numOfPods; i++ {
go func() {
spawnAndWaitOrFail(t, cmd, true)
wg.Done()
}()
}
wg.Wait()
}
示例10: getImageInfo
// getImageInfo returns the image info for the given image ID.
func getImageInfo(t *testing.T, ctx *testutils.RktRunCtx, imageID string) *imageInfo {
output, err := exec.Command("/bin/bash", "-c", fmt.Sprintf("%s image list --full | grep %s", ctx.Cmd(), imageID)).CombinedOutput()
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
imgInfo := parseImageInfoOutput(t, string(output))
// Get manifest
output, err = exec.Command("/bin/bash", "-c",
fmt.Sprintf("%s image cat-manifest --pretty-print=false %s", ctx.Cmd(), imageID)).CombinedOutput()
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
imgInfo.manifest = bytes.TrimSuffix(output, []byte{'\n'})
return imgInfo
}
示例11: removeImage
func removeImage(ctx *testutils.RktRunCtx, image string, shouldWork bool) error {
expect := fmt.Sprintf(rmImageReferenced, image)
if shouldWork {
expect = rmImageOk
}
cmd := fmt.Sprintf("%s image rm %s", ctx.Cmd(), image)
child, err := gexpect.Spawn(cmd)
if err != nil {
return fmt.Errorf("Cannot exec: %v", err)
}
if err := expectWithOutput(child, expect); err != nil {
return fmt.Errorf("Expected %q but not found: %v", expect, err)
}
if err := child.Wait(); err != nil {
return fmt.Errorf("rkt didn't terminate correctly: %v", err)
}
return nil
}
示例12: expectedRunRkt
// expectedRunRkt tries to fetch and run a prog.aci from host within
// given directory on host. Note that directory can be anything - it's
// useful for ensuring that image name is unique and for descriptive
// purposes.
func expectedRunRkt(ctx *testutils.RktRunCtx, t *testing.T, host, dir, line string) {
// First, check that --insecure-options=image,tls is required
// The server does not provide signatures for now.
cmd := fmt.Sprintf(`%s --debug run --mds-register=false %s/%s/prog.aci`, ctx.Cmd(), host, dir)
child := spawnOrFail(t, cmd)
defer child.Wait()
signatureErrorLine := "error downloading the signature file"
if err := expectWithOutput(child, signatureErrorLine); err != nil {
t.Fatalf("Didn't receive expected output %q: %v", signatureErrorLine, err)
}
// Then, run with --insecure-options=image,tls
cmd = fmt.Sprintf(`%s --debug --insecure-options=image,tls run --mds-register=false %s/%s/prog.aci`, ctx.Cmd(), host, dir)
child = spawnOrFail(t, cmd)
defer child.Wait()
if err := expectWithOutput(child, line); err != nil {
t.Fatalf("Didn't receive expected output %q: %v", line, err)
}
}
示例13: startAPIService
func startAPIService(t *testing.T, ctx *testutils.RktRunCtx) *gexpect.ExpectSubprocess {
noGid := false
gid, err := common.LookupGid(common.RktGroup)
if err != nil {
t.Logf("no %q group, will run api service with root, ONLY DO THIS FOR TESTING!", common.RktGroup)
noGid = true
} else {
t.Logf("Running rkt install")
installCmd := fmt.Sprintf("%s install", ctx.Cmd())
runRktAndCheckOutput(t, installCmd, "rkt directory structure successfully created", false)
}
t.Logf("Running rkt api service")
apisvcCmd := fmt.Sprintf("%s api-service", ctx.Cmd())
if noGid {
return startRktAndCheckOutput(t, apisvcCmd, "API service running")
}
return startRktAsGidAndCheckOutput(t, apisvcCmd, "API service running", gid)
}
示例14: Execute
func (ct ExportTestCase) Execute(t *testing.T, ctx *testutils.RktRunCtx) {
tmpDir := createTempDirOrPanic("rkt-TestExport-tmp-")
defer os.RemoveAll(tmpDir)
tmpTestAci := filepath.Join(tmpDir, "test.aci")
// Prepare the image with modifications
var additionalRunArgs string
if ct.multiAppPod {
tmpAdditionalAci := patchTestACI("other.aci", "--name=other")
defer os.Remove(tmpAdditionalAci)
const otherArgs = "--write-file --file-name=test.txt --content=NotTheRightContent"
additionalRunArgs = fmt.Sprintf("%s --exec=/inspect -- %s", tmpAdditionalAci, otherArgs)
} else {
additionalRunArgs = ""
}
const runInspect = "%s %s %s %s --exec=/inspect -- %s --- %s"
prepareCmd := fmt.Sprintf(runInspect, ctx.Cmd(), "prepare", ct.runArgs, getInspectImagePath(), ct.writeArgs, additionalRunArgs)
t.Logf("Preparing 'inspect --write-file'")
uuid := runRktAndGetUUID(t, prepareCmd)
runCmd := fmt.Sprintf("%s run-prepared %s", ctx.Cmd(), uuid)
t.Logf("Running 'inspect --write-file'")
child := spawnOrFail(t, runCmd)
waitOrFail(t, child, 0)
if ct.unmountOverlay {
unmountPod(t, ctx, uuid, true)
}
// Export the image
exportCmd := fmt.Sprintf("%s export %s %s %s", ctx.Cmd(), ct.exportArgs, uuid, tmpTestAci)
t.Logf("Running 'export'")
child = spawnOrFail(t, exportCmd)
waitOrFail(t, child, 0)
// Run the newly created ACI and check the output
readCmd := fmt.Sprintf(runInspect, ctx.Cmd(), "run", ct.runArgs, tmpTestAci, ct.readArgs, "")
t.Logf("Running 'inspect --read-file'")
child = spawnOrFail(t, readCmd)
if ct.expectedResult != "" {
if _, out, err := expectRegexWithOutput(child, ct.expectedResult); err != nil {
t.Fatalf("expected %q but not found: %v\n%s", ct.expectedResult, err, out)
}
}
waitOrFail(t, child, 0)
// run garbage collector on pods and images
runGC(t, ctx)
runImageGC(t, ctx)
}
示例15: getPodInfo
// getPodInfo returns the pod info for the given pod ID.
func getPodInfo(t *testing.T, ctx *testutils.RktRunCtx, podID string) *podInfo {
p := &podInfo{
id: podID,
apps: make(map[string]*appInfo),
networks: make(map[string]*networkInfo),
}
// Read pod manifest.
output, err := exec.Command("/bin/bash", "-c", fmt.Sprintf("%s cat-manifest %s", ctx.Cmd(), podID)).CombinedOutput()
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
// Trim the last '\n' character.
p.manifest = bytes.TrimSpace(output)
// Fill app infos.
var manifest schema.PodManifest
if err := json.Unmarshal(p.manifest, &manifest); err != nil {
t.Fatalf("Unexpected error: %v", err)
}
for _, app := range manifest.Apps {
appName := app.Name.String()
p.apps[appName] = &appInfo{
name: appName,
// TODO(yifan): Get the image's name.
image: &imageInfo{id: app.Image.ID.String()},
}
}
// Fill other infos.
output, err = exec.Command("/bin/bash", "-c", fmt.Sprintf("%s status %s", ctx.Cmd(), podID)).CombinedOutput()
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
parsePodInfoOutput(t, string(output), p)
return p
}