diff --git a/cmd/genbashcomp/gen_openshift_bash_comp.go b/cmd/genbashcomp/gen_openshift_bash_comp.go index 49f349728dab..e3545f284a88 100644 --- a/cmd/genbashcomp/gen_openshift_bash_comp.go +++ b/cmd/genbashcomp/gen_openshift_bash_comp.go @@ -49,7 +49,8 @@ func main() { openshift.GenBashCompletionFile(outFile_openshift) outFile_osc := outDir + "oc" - oc := cli.NewCommandCLI("oc", "openshift cli") + out := os.Stdout + oc := cli.NewCommandCLI("oc", "openshift cli", out) oc.GenBashCompletionFile(outFile_osc) outFile_osadm := outDir + "oadm" diff --git a/cmd/gendocs/gen_openshift_docs.go b/cmd/gendocs/gen_openshift_docs.go index 016c96ec0737..0bb775d8e270 100644 --- a/cmd/gendocs/gen_openshift_docs.go +++ b/cmd/gendocs/gen_openshift_docs.go @@ -45,7 +45,8 @@ func main() { } outFile := outDir + "oc_by_example_content.adoc" - cmd := cli.NewCommandCLI("oc", "openshift cli") + out := os.Stdout + cmd := cli.NewCommandCLI("oc", "openshift cli", out) gendocs.GenDocs(cmd, outFile) outFile = outDir + "oadm_by_example_content.adoc" diff --git a/test/extended/default_builds_test.go b/test/extended/default_builds_test.go index ed0e4ea20bd8..6ab001bd72ef 100644 --- a/test/extended/default_builds_test.go +++ b/test/extended/default_builds_test.go @@ -1,94 +1,70 @@ -// +build disabled +// +build default package extended import ( + "fmt" "path/filepath" - "strings" - "testing" + "encoding/json" - "github.com/GoogleCloudPlatform/kubernetes/pkg/fields" - "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" - exutil "github.com/openshift/origin/test/extended/util" -) + . "github.com/GoogleCloudPlatform/kubernetes/test/e2e" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" -func init() { - exutil.RequireServerVars() -} - -var ( - imageStreamFixture = filepath.Join("..", "integration", "fixtures", "test-image-stream.json") - stiEnvBuildFixture = filepath.Join("fixtures", "test-env-build.json") - stiEnvPodFixture = filepath.Join("fixtures", "test-env-pod.json") + exutil "github.com/openshift/origin/test/extended/util" ) -// TestSTIEnvironmentBuild exercises the scenario where you have .sti/environment -// file in your source code repository and you use STI build strategy. In that -// case the STI build should read that file and set all environment variables -// from that file to output image. -func TestSTIEnvironmentBuild(t *testing.T) { - oc := exutil.NewCLI("build-sti-env").Verbose() - - // Create imageStream used in this test - if err := oc.Run("create").Args("-f", imageStreamFixture).Execute(); err != nil { - t.Fatalf("Error creating imageStream: %v", err) - } - defer oc.Run("delete").Args("imageStream", "test").Execute() - - // Create watcher to watch the build - buildWatcher, err := oc.AdminRESTClient().Builds(oc.Namespace()). - Watch(labels.Everything(), fields.Everything(), "0") - if err != nil { - t.Fatalf("Unable to create watcher for builds: %v", err) - } - defer buildWatcher.Stop() - - // Create buildConfig and start the build manually - if err := oc.Run("create").Args("-f", stiEnvBuildFixture).Execute(); err != nil { - t.Fatalf("Error creating build: %v", err) - } - defer oc.Run("delete").Args("buildConfig", "test").Execute() - - buildName, err := oc.Run("start-build").Args("test").Verbose().Output() - if err != nil { - t.Fatalf("Unable to start build: %v", err) - } - - if err := exutil.WaitForBuildComplete(buildName, buildWatcher); err != nil { - logs, _ := oc.Run("build-logs").Args(buildName, "--nowait").Output() - t.Fatalf("Build error: %v\n%s\n", err, logs) - } - - // Verification: - - podWatcher, err := oc.AdminKubeRESTClient().Pods(oc.Namespace()). - Watch(labels.Everything(), fields.Everything(), "0") - if err != nil { - t.Fatalf("Unable to create watcher for pods: %v", err) - } - defer podWatcher.Stop() - - // Run the pod with the built image and verify it's content - podName, err := exutil.CreatePodForImageStream(oc, "test") - if err != nil { - t.Fatalf("Unable to create pod for verification: %v", err) - } - defer oc.Run("delete").Args("pod", podName).Execute() - - if err := exutil.WaitForPodRunning(podName, podWatcher); err != nil { - logs, _ := oc.Run("logs").Args("-p", podName).Output() - t.Fatalf("Pod error: %v\n%s\n", err, logs) - } - - result, err := oc.Run("exec"). - Args(podName, "--", "curl", "http://localhost:8080"). - Verbose(). - Output() - if err != nil { - t.Errorf("unexpected error: %v", err) - } - - if !strings.Contains(result, "success") { - t.Errorf("Expected TEST_ENV contains 'success', got: %q", result) - } -} +var _ = Describe("STI environment Build", func() { + defer GinkgoRecover() + + var imageStreamFixture = filepath.Join("..", "integration", "fixtures", "test-image-stream.json") + var stiEnvBuildFixture = filepath.Join("fixtures", "test-env-build.json") + var oc = exutil.NewCLI("build-sti-env", adminKubeConfigPath(), true) + + Describe("Building from template", func(){ + + It(fmt.Sprintf("should create a image from %q template and run it in a pod", stiEnvBuildFixture), func(){ + outputPath := getTempFilePath(oc.Namespace()) + + By(fmt.Sprintf("calling oc create -f %q", imageStreamFixture)) + if err := oc.Run("create").Args("-f", imageStreamFixture).Verbose().Execute(); err != nil { + Failf("Could not create image-streams %q: %v", imageStreamFixture, err) + } + + By(fmt.Sprintf("calling oc create -f %q", stiEnvBuildFixture)) + if err := oc.Run("create").Args("-f", stiEnvBuildFixture).Verbose().Execute(); err != nil { + Failf("Could not create build %q: %v", stiEnvBuildFixture, err) + } + + By("starting a test build") + buildName, err := oc.Run("start-build").Args("test").Output() + if err != nil { + Failf("Unable to start build: %v", err) + } + + By("expecting the build is in Complete phase") + Expect(oc.OsFramework().WaitForABuild(buildName)).NotTo(HaveOccurred()) + + By("creating and writing pod object") + pod, err := oc.OsFramework().CreatePodObjectForImageStream("test") + if err != nil { + Failf("Unable to create and write pod spec: %v", err) + } + + By(fmt.Sprintf("writing the pod object to %q", outputPath)) + podJSON, err := json.Marshal(pod) + err = writeTempJSON(outputPath, string(podJSON)) + if err != nil { + Failf("Couldn't write to %q: %v", outputPath, err) + } + + By(fmt.Sprintf("calling oc create -f %q", outputPath)) + if err := oc.Run("create").Args("-f", outputPath).Verbose().Execute(); err != nil { + Failf("Unable to create pod: %v", err) + } + + By("expecting the pod to be running") + Expect(oc.KubeFramework().WaitForPodRunning(pod.Name)).NotTo(HaveOccurred()) + }) + }) +}) diff --git a/test/extended/default_mysql_test.go b/test/extended/default_mysql_test.go index afb332c575d5..c311465592cf 100644 --- a/test/extended/default_mysql_test.go +++ b/test/extended/default_mysql_test.go @@ -20,9 +20,10 @@ var _ = Describe("MySQL ephemeral template", func() { var oc = exutil.NewCLI("mysql-create", adminKubeConfigPath(), true) Describe("Creating from a template", func() { - var outputPath string It(fmt.Sprintf("should process and create the %q template", templatePath), func() { + outputPath := getTempFilePath(oc.Namespace()) + By(fmt.Sprintf("calling oc process -f %q", templatePath)) templateOutput, err := oc.Run("process").Args("-f", templatePath).Output() if err != nil { @@ -30,7 +31,7 @@ var _ = Describe("MySQL ephemeral template", func() { } By(fmt.Sprintf("by writing the output to %q", outputPath)) - outputPath, err := writeTempJSON(oc.Namespace(), templateOutput) + err = writeTempJSON(outputPath, templateOutput) if err != nil { Failf("Couldn't write to %q: %v", outputPath, err) } diff --git a/test/extended/default_test.sh b/test/extended/default_test.sh index a90e174c9d5a..f8fcd930bea1 100755 --- a/test/extended/default_test.sh +++ b/test/extended/default_test.sh @@ -17,6 +17,9 @@ echo "[INFO] Starting extended tests" TIME_SEC=1000 TIME_MIN=$((60 * $TIME_SEC)) +TMPDIR="${TMPDIR:-"/tmp"}" +BASETMPDIR="${TMPDIR}/openshift-extended-tests" + # Use either the latest release built images, or latest. if [[ -z "${USE_IMAGES-}" ]]; then USE_IMAGES='openshift/origin-${component}:latest' @@ -28,14 +31,7 @@ fi if [[ -z "${BASETMPDIR-}" ]]; then - TMPDIR="${TMPDIR:-"/tmp"}" - BASETMPDIR="${TMPDIR}/openshift-extended-tests" - sudo rm -rf "${BASETMPDIR}" && mkdir -p ${BASETMPDIR} - if [[ $? != 0 ]]; then - echo "[INFO] Unmounting volumes ..." - findmnt -lo TARGET | grep openshift-extended-tests | xargs -r sudo umount - rm -rf ${BASETMPDIR} && mkdir -p ${BASETMPDIR} - fi + remove_tmp_dir && mkdir -p "${BASETMPDIR}" fi OS_TEST_NAMESPACE="extended-tests" @@ -97,9 +93,19 @@ cleanup() { rm -rf ${BASETMPDIR} fi + remove_tmp_dir echo "[INFO] Cleanup complete" } +remove_tmp_dir() { + rm -rf ${BASETMPDIR} &>/dev/null + if [[ $? != 0 ]]; then + echo "[INFO] Unmounting volumes ..." + findmnt -lo TARGET | grep openshift-extended-tests | xargs -r sudo umount + rm -rf ${BASETMPDIR} + fi +} + trap "exit" INT TERM trap "cleanup" EXIT @@ -122,7 +128,7 @@ do SERVER_HOSTNAME_LIST="${SERVER_HOSTNAME_LIST},${IP_ADDRESS}" done <<< "${ALL_IP_ADDRESSES}" -openshift admin create-master-certs \ +openshift admin ca create-master-certs \ --overwrite=false \ --cert-dir="${MASTER_CONFIG_DIR}" \ --hostnames="${SERVER_HOSTNAME_LIST}" \ @@ -190,7 +196,9 @@ wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/api/v1/nodes/${KUBELET_HOS # install the router echo "[INFO] Installing the router" -openshift admin router --create --credentials="${MASTER_CONFIG_DIR}/openshift-router.kubeconfig" --config="${ADMIN_KUBECONFIG}" --images="${USE_IMAGES}" +echo '{"kind":"ServiceAccount","apiVersion":"v1","metadata":{"name":"router"}}' | oc create -f - --config="${ADMIN_KUBECONFIG}" +oc get scc privileged -o json --config="${ADMIN_KUBECONFIG}" | sed '/\"users\"/a \"system:serviceaccount:default:router\",' | oc replace scc privileged -f - --config="${ADMIN_KUBECONFIG}" +openshift admin router --create --credentials="${MASTER_CONFIG_DIR}/openshift-router.kubeconfig" --config="${ADMIN_KUBECONFIG}" --images="${USE_IMAGES}" --service-account=router # install the registry. The --mount-host option is provided to reuse local storage. echo "[INFO] Installing the registry" @@ -198,8 +206,6 @@ openshift admin registry --create --credentials="${MASTER_CONFIG_DIR}/openshift- wait_for_command '[[ "$(oc get endpoints docker-registry --output-version=v1 -t "{{ if .subsets }}{{ len .subsets }}{{ else }}0{{ end }}" --config=/tmp/openshift-extended-tests/openshift.local.config/master/admin.kubeconfig || echo "0")" != "0" ]]' $((5*TIME_MIN)) -DOCKER_REGISTRY=$(oc get service docker-registry --output-version=v1 --template="{{ .spec.clusterIP }}:{{ with index .spec.ports 0 }}{{ .port }}{{ end }}" --config=/tmp/openshift-extended-tests/openshift.local.config/master/admin.kubeconfig) - echo "[INFO] Creating image streams" oc create -n openshift -f examples/image-streams/image-streams-centos7.json --config="${ADMIN_KUBECONFIG}" diff --git a/test/extended/extended_test.go b/test/extended/extended_test.go index 409c0ff5aaf5..fe5b9e8407ab 100644 --- a/test/extended/extended_test.go +++ b/test/extended/extended_test.go @@ -40,7 +40,7 @@ func init() { flag.StringVar(&testContext.CertDir, "cert-dir", kubeCertPath(), "Path to the directory containing the certs. Default is empty, which doesn't use certs.") flag.StringVar(&testContext.KubeContext, clientcmd.FlagContext, "", "kubeconfig context to use/override. If unset, will use value from 'current-context'") flag.StringVar(&testContext.Host, "host", os.Getenv("MASTER_ADDR"), "The host, or apiserver, to connect to") - flag.StringVar(&testContext.OutputDir, "e2e-output-dir", os.TempDir(), "Output directory for interesting/useful test data, like performance data, benchmarks, and other metrics.") + flag.StringVar(&testContext.OutputDir, "extended-tests-output-dir", os.TempDir(), "Output directory for interesting/useful test data, like performance data, benchmarks, and other metrics.") // Override the default Kubernetes E2E configuration SetTestContext(testContext) diff --git a/test/extended/util.go b/test/extended/util.go index 5d8ab1d6e524..c66242e946d3 100644 --- a/test/extended/util.go +++ b/test/extended/util.go @@ -24,7 +24,10 @@ func kubeCertPath() string { return filepath.Join(os.Getenv("SERVER_CONFIG_DIR"), "master") } -func writeTempJSON(name, content string) (string, error) { - p := filepath.Join(testContext.OutputDir, name+".json") - return p, ioutil.WriteFile(p, []byte(content), 0644) +func writeTempJSON(path, content string) (error) { + return ioutil.WriteFile(path, []byte(content), 0644) +} + +func getTempFilePath(name string) string { + return filepath.Join(testContext.OutputDir, name+".json") } diff --git a/test/extended/util/cli.go b/test/extended/util/cli.go index 8ce69054455b..082a6c09bb5c 100644 --- a/test/extended/util/cli.go +++ b/test/extended/util/cli.go @@ -199,7 +199,11 @@ func (c *CLI) Output() (string, error) { fmt.Printf("DEBUG: oc %s\n", c.printCmd()) } err := c.cmd.Execute() + if err != nil { + FatalErr(err) + } out := c.stdout.(*bytes.Buffer) + return strings.TrimSpace(out.String()), err } diff --git a/test/extended/util/framework.go b/test/extended/util/framework.go index 6eeb003354c7..58c6ff36bd2d 100644 --- a/test/extended/util/framework.go +++ b/test/extended/util/framework.go @@ -7,6 +7,8 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/fields" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" buildapi "github.com/openshift/origin/pkg/build/api" + kutil "github.com/GoogleCloudPlatform/kubernetes/pkg/util" + "github.com/openshift/origin/pkg/client" ) @@ -49,7 +51,7 @@ func (f *OsFramework) WaitForABuild(buildName string) error { w, err := f.Client.Builds(f.Namespace.Name).Watch( labels.Everything(), - fields.Set{"metadata.name": buildName}.AsSelector(), + fields.Set{"name": buildName}.AsSelector(), rv, ) if err != nil { @@ -74,3 +76,40 @@ func (f *OsFramework) WaitForABuild(buildName string) error { } } } + +// CreatePodObjectForImageStream creates a pod object from given imageStream +func (f *OsFramework) CreatePodObjectForImageStream(imageStreamName string) (*kapi.Pod, error) { + imageStream, err := f.Client.ImageStreams(f.Namespace.Name).Get(imageStreamName) + if err != nil { + return nil, err + } + + tags := []string{} + for tag := range imageStream.Status.Tags { + tags = append(tags, tag) + } + + imageName := imageStream.Status.Tags[tags[0]].Items[0].DockerImageReference + podName := "test-pod" + string(kutil.NewUUID()) + pod := &kapi.Pod{ + TypeMeta: kapi.TypeMeta{ + Kind: "Pod", + APIVersion: "v1", + }, + ObjectMeta: kapi.ObjectMeta{ + Name: podName, + Labels: map[string]string{"name": podName}, + }, + Spec: kapi.PodSpec{ + ServiceAccountName: "builder", + Containers: []kapi.Container{ + { + Name: "test", + Image: imageName, + }, + }, + RestartPolicy: kapi.RestartPolicyNever, + }, + } + return pod, nil +}