当前位置: 首页>>代码示例>>Golang>>正文


Golang RktRunCtx.Cmd方法代码示例

本文整理汇总了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
}
开发者ID:intelsdi-x,项目名称:rkt,代码行数:26,代码来源:rkt_list_test.go

示例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
}
开发者ID:kinvolk,项目名称:rkt,代码行数:31,代码来源:rkt_tests.go

示例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)
	}
}
开发者ID:ngorskig,项目名称:rkt,代码行数:29,代码来源:rkt_trust_test.go

示例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)
}
开发者ID:intelsdi-x,项目名称:rkt,代码行数:30,代码来源:rkt_api_service_test.go

示例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)
}
开发者ID:aaronlevy,项目名称:rkt,代码行数:7,代码来源:rkt_tests.go

示例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)
}
开发者ID:coderhaoxin,项目名称:rkt,代码行数:7,代码来源:rkt_tests.go

示例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]
}
开发者ID:aaronlevy,项目名称:rkt,代码行数:34,代码来源:rkt_tests.go

示例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)
	}
}
开发者ID:Snaveena,项目名称:rkt,代码行数:13,代码来源:rkt_image_rm_test.go

示例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()
}
开发者ID:sinfomicien,项目名称:rkt,代码行数:14,代码来源:rkt_api_service_bench_test.go

示例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
}
开发者ID:yanghongkjxy,项目名称:rkt,代码行数:17,代码来源:rkt_tests.go

示例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
}
开发者ID:jshxu,项目名称:rkt,代码行数:18,代码来源:rkt_image_rm_test.go

示例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)
	}
}
开发者ID:blakelapierre,项目名称:rkt,代码行数:23,代码来源:rkt_auth_test.go

示例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)
}
开发者ID:krnowak,项目名称:rkt,代码行数:20,代码来源:rkt_api_service_test.go

示例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)
}
开发者ID:intelsdi-x,项目名称:rkt,代码行数:51,代码来源:rkt_export_test.go

示例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
}
开发者ID:aaronlevy,项目名称:rkt,代码行数:40,代码来源:rkt_tests.go


注:本文中的github.com/coreos/rkt/tests/testutils.RktRunCtx.Cmd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。