func TestClusterStatus(t *testing.T) {
	minikubeRunner := util.MinikubeRunner{
		Args:       *args,
		BinaryPath: *binaryPath,
		T:          t}
	minikubeRunner.EnsureRunning()

	kubectlRunner := util.NewKubectlRunner(t)
	cs := api.ComponentStatusList{}

	healthy := func() error {
		if err := kubectlRunner.RunCommandParseOutput([]string{"get", "cs"}, &cs); err != nil {
			return err
		}
		for _, i := range cs.Items {
			status := api.ConditionFalse
			for _, c := range i.Conditions {
				if c.Type != api.ComponentHealthy {
					continue
				}
				fmt.Printf("Component: %s, Healthy: %s.\n", i.GetName(), c.Status)
				status = c.Status
			}
			if status != api.ConditionTrue {
				return fmt.Errorf("Component %s is not Healthy! Status: %s", i.GetName(), status)
			}
		}
		return nil
	}

	if err := commonutil.RetryAfter(4, healthy, 1*time.Second); err != nil {
		t.Fatalf("Cluster is not healthy: %s", err)
	}
}
Beispiel #2
0
func TestAddons(t *testing.T) {
	minikubeRunner := util.MinikubeRunner{
		BinaryPath: *binaryPath,
		Args:       *args,
		T:          t}

	minikubeRunner.EnsureRunning()
	kubectlRunner := util.NewKubectlRunner(t)

	checkAddon := func() error {
		pods := api.PodList{}
		if err := kubectlRunner.RunCommandParseOutput(addonManagerCmd, &pods); err != nil {
			return err
		}

		for _, p := range pods.Items {
			if strings.HasPrefix(p.ObjectMeta.Name, "kube-addon-manager-") {
				if p.Status.Phase == "Running" {
					return nil
				} else {
					return fmt.Errorf("Pod is not Running. Status: %s", p.Status.Phase)
				}
			}
		}

		return fmt.Errorf("Addon manager not found. Found pods: %s", pods)
	}

	if err := commonutil.RetryAfter(20, checkAddon, 5*time.Second); err != nil {
		t.Fatalf("Addon Manager pod is unhealthy: %s", err)
	}
}
func TestClusterSSH(t *testing.T) {
	minikubeRunner := util.MinikubeRunner{
		Args:       *args,
		BinaryPath: *binaryPath,
		T:          t}
	minikubeRunner.EnsureRunning()

	expectedStr := "hello"
	sshCmdOutput := minikubeRunner.RunCommand("ssh echo "+expectedStr, true)
	if !strings.Contains(sshCmdOutput, expectedStr) {
		t.Fatalf("ExpectedStr sshCmdOutput to be: %s. Output was: %s", expectedStr, sshCmdOutput)
	}
}
func TestClusterLogs(t *testing.T) {
	minikubeRunner := util.MinikubeRunner{
		Args:       *args,
		BinaryPath: *binaryPath,
		T:          t}
	minikubeRunner.EnsureRunning()

	logsCmdOutput := minikubeRunner.RunCommand("logs", true)
	//check for # of lines or check for strings
	logFiles := []string{constants.RemoteOpenShiftErrPath, constants.RemoteOpenShiftOutPath}
	for _, logFile := range logFiles {
		if !strings.Contains(logsCmdOutput, logFile) {
			t.Fatalf("Error in logsCmdOutput, expected to find: %s. Output: %s", logFile, logsCmdOutput)
		}
	}
}
func TestClusterDNS(t *testing.T) {
	minikubeRunner := util.MinikubeRunner{
		BinaryPath: *binaryPath,
		Args:       *args,
		T:          t}
	minikubeRunner.EnsureRunning()

	kubectlRunner := util.NewKubectlRunner(t)
	podName := "busybox"
	podPath, _ := filepath.Abs("testdata/busybox.yaml")

	dnsTest := func() error {
		podNamespace := kubectlRunner.CreateRandomNamespace()
		defer kubectlRunner.DeleteNamespace(podNamespace)

		if _, err := kubectlRunner.RunCommand([]string{"create", "-f", podPath, "--namespace=" + podNamespace}); err != nil {
			return err
		}
		defer kubectlRunner.RunCommand([]string{"delete", "-f", podPath, "--namespace=" + podNamespace})

		p := api.Pod{}
		for p.Status.Phase != "Running" {
			if err := kubectlRunner.RunCommandParseOutput([]string{"get", "pod", podName, "--namespace=" + podNamespace}, &p); err != nil {
				return err
			}
		}

		dnsByteArr, err := kubectlRunner.RunCommand([]string{"exec", podName, "--namespace=" + podNamespace,
			"nslookup", "kubernetes.default"})
		dnsOutput := string(dnsByteArr)
		if err != nil {
			return err
		}

		if !strings.Contains(dnsOutput, "10.0.0.1") || !strings.Contains(dnsOutput, "10.0.0.10") {
			return fmt.Errorf("DNS lookup failed, could not find both 10.0.0.1 and 10.0.0.10.  Output: %s", dnsOutput)
		}
		return nil
	}

	if err := commonutil.RetryAfter(4, dnsTest, 1*time.Second); err != nil {
		t.Fatalf("DNS lookup failed with error:", err)
	}
}
func TestClusterEnv(t *testing.T) {
	minikubeRunner := util.MinikubeRunner{
		Args:       *args,
		BinaryPath: *binaryPath,
		T:          t}
	minikubeRunner.EnsureRunning()

	dockerEnvVars := minikubeRunner.RunCommand("docker-env", true)
	if err := minikubeRunner.SetEnvFromEnvCmdOutput(dockerEnvVars); err != nil {
		t.Fatalf("Error: No environment variables were found in docker-env command output: ", dockerEnvVars)
	}
	path, err := exec.LookPath("docker")

	var output []byte
	dockerPs := func() error {
		cmd := exec.Command(path, "ps")
		output, err = cmd.CombinedOutput()
		return err
	}
	if err := commonutil.RetryAfter(5, dockerPs, 3*time.Second); err != nil {
		t.Fatalf("Error running command: %s. Error: %s Output: %s", "docker ps", err, output)
	}
}