當前位置: 首頁>>代碼示例>>Golang>>正文


Golang RktRunCtx.DataDir方法代碼示例

本文整理匯總了Golang中github.com/coreos/rkt/tests/testutils.RktRunCtx.DataDir方法的典型用法代碼示例。如果您正苦於以下問題:Golang RktRunCtx.DataDir方法的具體用法?Golang RktRunCtx.DataDir怎麽用?Golang RktRunCtx.DataDir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/coreos/rkt/tests/testutils.RktRunCtx的用法示例。


在下文中一共展示了RktRunCtx.DataDir方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: mockFlannelNetwork

/*
 * mockFlannelNetwork creates fake flannel network status file and configuration pointing to this network.
 * We won't have connectivity, but we could check if: netName was correct and if default gateway was set.
 */
func mockFlannelNetwork(t *testing.T, ctx *testutils.RktRunCtx) (string, networkTemplateT, error) {
	// write fake flannel info
	subnetPath := filepath.Join(ctx.DataDir(), "subnet.env")
	file, err := os.Create(subnetPath)
	if err != nil {
		return "", networkTemplateT{}, err
	}
	mockedFlannel := strings.Join([]string{
		"FLANNEL_NETWORK=11.11.0.0/16",
		"FLANNEL_SUBNET=11.11.3.1/24",
		"FLANNEL_MTU=1472",
		"FLANNEL_IPMASQ=true",
	}, "\n")
	if _, err = file.WriteString(mockedFlannel); err != nil {
		return "", networkTemplateT{}, err
	}

	file.Close()

	// write net config for "flannel" based network
	ntFlannel := networkTemplateT{
		Name:       "rkt.kubernetes.io",
		Type:       "flannel",
		SubnetFile: subnetPath,
		Delegate: &delegateTemplateT{
			IsDefaultGateway: true,
		},
	}

	netdir := prepareTestNet(t, ctx, ntFlannel)

	return netdir, ntFlannel, nil
}
開發者ID:intelsdi-x,項目名稱:rkt,代碼行數:37,代碼來源:rkt_net_test.go

示例2: unmountPod

func unmountPod(t *testing.T, ctx *testutils.RktRunCtx, uuid string, rmNetns bool) {
	podDir := filepath.Join(ctx.DataDir(), "pods", "run", uuid)
	stage1MntPath := filepath.Join(podDir, "stage1", "rootfs")
	stage2MntPath := filepath.Join(stage1MntPath, "opt", "stage2", "rkt-inspect", "rootfs")
	netnsPath := filepath.Join(podDir, "netns")
	podNetNSPathBytes, err := ioutil.ReadFile(netnsPath)
	if err != nil {
		t.Fatalf(`cannot read "netns" stage1: %v`, err)
	}
	podNetNSPath := string(podNetNSPathBytes)

	if err := syscall.Unmount(stage2MntPath, 0); err != nil {
		t.Fatalf("cannot umount stage2: %v", err)
	}

	if err := syscall.Unmount(stage1MntPath, 0); err != nil {
		t.Fatalf("cannot umount stage1: %v", err)
	}

	if err := syscall.Unmount(podNetNSPath, 0); err != nil {
		t.Fatalf("cannot umount pod netns: %v", err)
	}

	if rmNetns {
		_ = os.RemoveAll(podNetNSPath)
	}
}
開發者ID:yanghongkjxy,項目名稱:rkt,代碼行數:27,代碼來源:rkt_tests.go

示例3: getPodDir

func getPodDir(t *testing.T, ctx *testutils.RktRunCtx, podID string) string {
	podsDir := path.Join(ctx.DataDir(), "pods")

	dirs, err := ioutil.ReadDir(podsDir)
	if err != nil {
		t.Fatalf("Unexpected error: %v", err)
	}

	for _, dir := range dirs {
		podDir := path.Join(podsDir, dir.Name(), podID)
		if _, err := os.Stat(podDir); err == nil {
			return podDir
		}
	}
	t.Fatalf("Failed to find pod directory for pod %q", podID)
	return ""
}
開發者ID:aaronlevy,項目名稱:rkt,代碼行數:17,代碼來源:rkt_tests.go

示例4: getTreeStoreIDs

func getTreeStoreIDs(ctx *testutils.RktRunCtx) (map[string]struct{}, error) {
	treeStoreIDs := map[string]struct{}{}
	ls, err := ioutil.ReadDir(filepath.Join(ctx.DataDir(), "cas", "tree"))
	if err != nil {
		if os.IsNotExist(err) {
			return treeStoreIDs, nil
		}
		return nil, fmt.Errorf("cannot read treestore directory: %v", err)
	}

	for _, p := range ls {
		if p.IsDir() {
			id := filepath.Base(p.Name())
			treeStoreIDs[id] = struct{}{}
		}
	}
	return treeStoreIDs, nil
}
開發者ID:sinfomicien,項目名稱:rkt,代碼行數:18,代碼來源:rkt_image_gc_test.go

示例5: podsRemaining

func podsRemaining(t *testing.T, ctx *testutils.RktRunCtx) []os.FileInfo {
	gcDirs := []string{
		filepath.Join(ctx.DataDir(), "pods", "exited-garbage"),
		filepath.Join(ctx.DataDir(), "pods", "prepared"),
		filepath.Join(ctx.DataDir(), "pods", "garbage"),
		filepath.Join(ctx.DataDir(), "pods", "run"),
	}

	var remainingPods []os.FileInfo
	for _, dir := range gcDirs {
		pods, err := ioutil.ReadDir(dir)
		if err != nil {
			t.Fatalf("cannot read gc directory %q: %v", dir, err)
		}
		remainingPods = append(remainingPods, pods...)
	}

	return remainingPods
}
開發者ID:intelsdi-x,項目名稱:rkt,代碼行數:19,代碼來源:rkt_gc_test.go

示例6: preparePidFileRace

func preparePidFileRace(t *testing.T, ctx *testutils.RktRunCtx, sleepImage string) (*gexpect.ExpectSubprocess, *gexpect.ExpectSubprocess, string, string) {
	// Start the pod
	runCmd := fmt.Sprintf("%s --debug --insecure-options=image run --mds-register=false --interactive %s", ctx.Cmd(), sleepImage)
	runChild := spawnOrFail(t, runCmd)

	if err := expectWithOutput(runChild, "Enter text:"); err != nil {
		t.Fatalf("Waited for the prompt but not found: %v", err)
	}

	// Check the ppid file is really created
	cmd := fmt.Sprintf(`%s list --full|grep running`, ctx.Cmd())
	output, err := exec.Command("/bin/sh", "-c", cmd).CombinedOutput()
	if err != nil {
		t.Fatalf("Couldn't list the pods: %v", err)
	}
	UUID := strings.Split(string(output), "\t")[0]

	pidFileName := filepath.Join(ctx.DataDir(), "pods/run", UUID, "ppid")
	if _, err := os.Stat(pidFileName); err != nil {
		t.Fatalf("Pid file missing: %v", err)
	}

	// Temporarily move the ppid file away
	pidFileNameBackup := pidFileName + ".backup"
	if err := os.Rename(pidFileName, pidFileNameBackup); err != nil {
		t.Fatalf("Cannot move ppid file away: %v", err)
	}

	// Start the "enter" command without the pidfile
	enterCmd := fmt.Sprintf("%s --debug enter %s /inspect --print-msg=RktEnterWorksFine", ctx.Cmd(), UUID)
	t.Logf("%s", enterCmd)
	enterChild := spawnOrFail(t, enterCmd)

	// Enter should be able to wait until the ppid file appears
	time.Sleep(1 * time.Second)

	return runChild, enterChild, pidFileName, pidFileNameBackup
}
開發者ID:coderhaoxin,項目名稱:rkt,代碼行數:38,代碼來源:rkt_pid_file_test.go

示例7: 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, 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 for the pod supervisor to be ready
	podReadyFile := filepath.Join(ctx.DataDir(), "pods", "run", string(podUUID), "stage1/rootfs/rkt/supervisor-status")
	target := ""
	elapsed = time.Duration(0)
	for elapsed < timeout {
		time.Sleep(interval)
		elapsed += interval
		target, err = os.Readlink(podReadyFile)
		if err == nil && target == "ready" {
			break
		}
	}
	if err != nil || target != "ready" {
		return "", fmt.Errorf("Pod failed to become ready while checking %q", podReadyFile)
	}

	return string(podUUID), nil
}
開發者ID:intelsdi-x,項目名稱:rkt,代碼行數:38,代碼來源:rkt_tests.go


注:本文中的github.com/coreos/rkt/tests/testutils.RktRunCtx.DataDir方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。