iso_test.go 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
// +build iso

/*
Copyright 2016 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package integration

import (
	"fmt"
	"strings"
	"testing"
)

func TestISO(t *testing.T) {
28
	p := profileName(t)
M
Medya Gh 已提交
29
	if toParallel() {
M
Medya Gh 已提交
30 31
		t.Parallel()
	}
32

33
	mk := NewMinikubeRunner(t, p, "--wait=false")
34
	mk.RunCommand("delete", false)
M
Medya Gh 已提交
35
	stdout, stderr, err := mk.Start()
M
Medya Gh 已提交
36
	if err != nil {
M
linting  
Medya Gh 已提交
37
		t.Fatalf("failed to start minikube (for profile %s) %s) failed : %v\nstdout: %s\nstderr: %s", t.Name(), err, stdout, stderr)
M
Medya Gh 已提交
38
	}
M
Medya Gh 已提交
39
	if !isTestNoneDriver() { // none driver doesn't need to be deleted
40
		defer mk.TearDown(t)
M
Medya Gh 已提交
41
	}
42 43

	t.Run("permissions", testMountPermissions)
D
dlorenc 已提交
44
	t.Run("packages", testPackages)
45
	t.Run("persistence", testPersistence)
M
Medya Gh 已提交
46

47 48 49
}

func testMountPermissions(t *testing.T) {
50
	p := profileName(t)
M
Medya Gh 已提交
51
	mk := NewMinikubeRunner(t, p, "--wait=false")
52 53 54 55 56 57
	// test mount permissions
	mountPoints := []string{"/Users", "/hosthome"}
	perms := "drwxr-xr-x"
	foundMount := false

	for _, dir := range mountPoints {
58
		output, err := mk.SSH(fmt.Sprintf("ls -l %s", dir))
D
dlorenc 已提交
59
		if err != nil {
60 61 62 63 64 65 66 67 68 69 70
			continue
		}
		foundMount = true
		if !strings.Contains(output, perms) {
			t.Fatalf("Incorrect permissions. Expected %s, got %s.", perms, output)
		}
	}
	if !foundMount {
		t.Fatalf("No shared mount found. Checked %s", mountPoints)
	}
}
D
dlorenc 已提交
71 72

func testPackages(t *testing.T) {
73
	p := profileName(t)
M
Medya Gh 已提交
74
	mk := NewMinikubeRunner(t, p, "--wait=false")
D
dlorenc 已提交
75 76 77 78 79 80 81 82 83 84 85 86 87

	packages := []string{
		"git",
		"rsync",
		"curl",
		"wget",
		"socat",
		"iptables",
		"VBoxControl",
		"VBoxService",
	}

	for _, pkg := range packages {
88
		if output, err := mk.SSH(fmt.Sprintf("which %s", pkg)); err != nil {
89
			t.Errorf("Error finding package: %s. Error: %v. Output: %s", pkg, err, output)
D
dlorenc 已提交
90 91 92 93
		}
	}

}
94 95

func testPersistence(t *testing.T) {
96
	p := profileName(t)
M
Medya Gh 已提交
97
	mk := NewMinikubeRunner(t, p, "--wait=false")
98 99 100 101 102 103

	for _, dir := range []string{
		"/data",
		"/var/lib/docker",
		"/var/lib/cni",
		"/var/lib/kubelet",
104
		"/var/lib/minikube",
105
		"/var/lib/toolbox",
106 107
		"/var/lib/boot2docker",
	} {
108
		output, err := mk.SSH(fmt.Sprintf("df %s | tail -n 1 | awk '{print $1}'", dir))
109
		if err != nil {
110
			t.Errorf("Error checking device for %s. Error: %v", dir, err)
111 112 113 114 115 116
		}
		if !strings.Contains(output, "/dev/sda1") {
			t.Errorf("Path %s is not mounted persistently. %s", dir, output)
		}
	}
}