Skip to content

Commit

Permalink
Merge pull request #1343 from fabianofranz/test_e2e_with_login
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot committed Mar 31, 2015
2 parents b4a971f + 91d458c commit 3c53474
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
2 changes: 2 additions & 0 deletions examples/sample-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ This section covers how to perform all the steps of building, deploying, and upd
installation, users would generate their own keys and not have access
to the system keys.)

$ osc login -u test-admin --client-certificate=`pwd`/openshift.local.certificates/admin/cert.crt --client-key=`pwd`/openshift.local.certificates/admin/key.key --certificate-authority=`pwd`/openshift.local.certificates/ca/cert.crt

$ export KUBECONFIG=`pwd`/openshift.local.certificates/admin/.kubeconfig
$ export CURL_CA_BUNDLE=`pwd`/openshift.local.certificates/ca/cert.crt
$ sudo chmod +r "$KUBECONFIG"
Expand Down
19 changes: 12 additions & 7 deletions hack/test-end-to-end.sh
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ done <<< "${ALL_IP_ADDRESSES}"
openshift admin create-master-certs --overwrite=false --cert-dir="${CERT_DIR}" --hostnames="${SERVER_HOSTNAME_LIST}" --master="${MASTER_ADDR}" --public-master="${API_SCHEME}://${PUBLIC_MASTER_HOST}"
openshift admin create-node-config --listen="https://0.0.0.0:10250" --node-dir="${CERT_DIR}/node-127.0.0.1" --node="127.0.0.1" --hostnames="${SERVER_HOSTNAME_LIST}" --master="${MASTER_ADDR}" --certificate-authority="${CERT_DIR}/ca/cert.crt" --signer-cert="${CERT_DIR}/ca/cert.crt" --signer-key="${CERT_DIR}/ca/key.key" --signer-serial="${CERT_DIR}/ca/serial.txt"


echo "[INFO] Starting OpenShift server"
sudo env "PATH=${PATH}" OPENSHIFT_PROFILE=web OPENSHIFT_ON_PANIC=crash openshift start \
--listen="${API_SCHEME}://0.0.0.0:${API_PORT}" --master="${MASTER_ADDR}" --public-master="${API_SCHEME}://${PUBLIC_MASTER_HOST}" \
Expand All @@ -204,17 +203,15 @@ if [[ "${API_SCHEME}" == "https" ]]; then

# Make osc use ${CERT_DIR}/admin/.kubeconfig, and ignore anything in the running user's $HOME dir
export HOME="${CERT_DIR}/admin"
export KUBECONFIG="${CERT_DIR}/admin/.kubeconfig"
echo "[INFO] To debug: export KUBECONFIG=$KUBECONFIG"
sudo chmod -R a+rwX "${HOME}"
export OPENSHIFTCONFIG="${CERT_DIR}/admin/.kubeconfig"
echo "[INFO] To debug: export OPENSHIFTCONFIG=$OPENSHIFTCONFIG"
fi

wait_for_url "${KUBELET_SCHEME}://127.0.0.1:${KUBELET_PORT}/healthz" "kubelet: " 0.5 60
wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/healthz" "apiserver: " 0.25 80
wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/api/v1beta1/minions/127.0.0.1" "apiserver(minions): " 0.25 80

# Set KUBERNETES_MASTER for osc
export KUBERNETES_MASTER="${API_SCHEME}://${API_HOST}:${API_PORT}"

# add e2e-user as a viewer for the default namespace so we can see infrastructure pieces appear
openshift ex policy add-role-to-user view e2e-user --namespace=default

Expand Down Expand Up @@ -261,8 +258,13 @@ osc process -n test -f examples/sample-app/application-template-stibuild.json >
osc process -n docker -f examples/sample-app/application-template-dockerbuild.json > "${DOCKER_CONFIG_FILE}"
osc process -n custom -f examples/sample-app/application-template-custombuild.json > "${CUSTOM_CONFIG_FILE}"

# Client setup (log in as e2e-user and set 'test' as the default project)
echo "[INFO] Logging in as a regular user (e2e-user:pass) with project 'test'..."
osc login -u e2e-user -p pass
osc project test

echo "[INFO] Applying STI application config"
osc create -n test -f "${STI_CONFIG_FILE}"
osc create -f "${STI_CONFIG_FILE}"

# Trigger build
echo "[INFO] Starting build from ${STI_CONFIG_FILE} and streaming its logs..."
Expand All @@ -286,6 +288,9 @@ wait_for_app "test"

# ensure the router is started
# TODO: simplify when #4702 is fixed upstream
echo "[INFO] Back to 'master' context with 'admin' user..."
osc project master

wait_for_command '[[ "$(osc get endpoints router -t "{{ if .endpoints }}{{ len .endpoints }}{{ else }}0{{ end }}" || echo "0")" != "0" ]]' $((5*TIME_MIN))

echo "[INFO] Validating routed app response..."
Expand Down
7 changes: 7 additions & 0 deletions pkg/cmd/cli/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ func NewCmdLogin(f *osclientcmd.Factory, reader io.Reader, out io.Writer) *cobra
options.Reader = reader
options.ClientConfig = f.OpenShiftClientConfig

if certFile := cmdutil.GetFlagString(cmd, "client-certificate"); len(certFile) > 0 {
options.CertFile = certFile
}
if keyFile := cmdutil.GetFlagString(cmd, "client-key"); len(keyFile) > 0 {
options.KeyFile = keyFile
}

checkErr(options.GatherInfo())

forcePath := cmdutil.GetFlagString(cmd, config.OpenShiftConfigFlagName)
Expand Down
10 changes: 10 additions & 0 deletions pkg/cmd/cli/cmd/loginoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ type LoginOptions struct {
Config *kclient.Config
Reader io.Reader

// cert data to be used when authenticating
CertFile string
CertData []byte
KeyFile string
KeyData []byte

// flow controllers
gatheredServerInfo bool
gatheredAuthInfo bool
Expand Down Expand Up @@ -135,6 +141,10 @@ func (o *LoginOptions) gatherAuthInfo() error {
// if not, we need to log in again

o.Config.BearerToken = ""
o.Config.CertFile = o.CertFile
o.Config.CertData = o.CertData
o.Config.KeyFile = o.KeyFile
o.Config.KeyData = o.KeyData
token, err := tokencmd.RequestToken(o.Config, o.Reader, o.Username, o.Password)
if err != nil {
return err
Expand Down
12 changes: 10 additions & 2 deletions pkg/cmd/cli/cmd/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ func NewCmdProject(f *clientcmd.Factory, out io.Writer) *cobra.Command {
}

if rawCfg.CurrentContext != currentProject {
fmt.Fprintf(out, "Using project %q from context named %q on server %q.\n", currentProject, rawCfg.CurrentContext, clientCfg.Host)
if len(currentProject) > 0 {
fmt.Fprintf(out, "Using project %q from context named %q on server %q.\n", currentProject, rawCfg.CurrentContext, clientCfg.Host)
} else {
fmt.Fprintf(out, "Using context named %q on server %q.\n", rawCfg.CurrentContext, clientCfg.Host)
}
} else {
fmt.Fprintf(out, "Using project %q on server %q.\n", currentProject, clientCfg.Host)
}
Expand Down Expand Up @@ -169,7 +173,11 @@ func NewCmdProject(f *clientcmd.Factory, out io.Writer) *cobra.Command {
}

if contextInUse != namespaceInUse {
fmt.Fprintf(out, "Now using project %q from context named %q on server %q.\n", namespaceInUse, contextInUse, clientCfg.Host)
if len(namespaceInUse) > 0 {
fmt.Fprintf(out, "Now using project %q from context named %q on server %q.\n", namespaceInUse, contextInUse, clientCfg.Host)
} else {
fmt.Fprintf(out, "Now using context named %q on server %q.\n", contextInUse, clientCfg.Host)
}
} else {
fmt.Fprintf(out, "Now using project %q on server %q.\n", namespaceInUse, clientCfg.Host)
}
Expand Down

0 comments on commit 3c53474

Please sign in to comment.