Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/genbashcomp/gen_openshift_bash_comp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion cmd/gendocs/gen_openshift_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
146 changes: 61 additions & 85 deletions test/extended/default_builds_test.go
Original file line number Diff line number Diff line change
@@ -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())
})
})
})
5 changes: 3 additions & 2 deletions test/extended/default_mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ 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 {
Failf("Couldn't process template %q: %v", templatePath, err)
}

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)
}
Expand Down
30 changes: 18 additions & 12 deletions test/extended/default_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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"
Expand Down Expand Up @@ -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

Expand All @@ -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}" \
Expand Down Expand Up @@ -190,16 +196,16 @@ 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"
openshift admin registry --create --credentials="${MASTER_CONFIG_DIR}/openshift-registry.kubeconfig" --config="${ADMIN_KUBECONFIG}" --images="${USE_IMAGES}"

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}"

Expand Down
2 changes: 1 addition & 1 deletion test/extended/extended_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions test/extended/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
4 changes: 4 additions & 0 deletions test/extended/util/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
41 changes: 40 additions & 1 deletion test/extended/util/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand All @@ -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
}