Skip to content

Commit 71f6088

Browse files
author
Michal Minář
committed
e2e: schema2 config test amendments
- Quote process expansions. - Use braces for variable expansions (e.g. ${var}). - Wrap variable expandions with quotes. Signed-off-by: Michal Minář <[email protected]>
1 parent 8f81098 commit 71f6088

File tree

2 files changed

+38
-35
lines changed

2 files changed

+38
-35
lines changed

hack/util.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,11 +660,11 @@ function install_registry() {
660660
readonly -f install_registry
661661

662662
function wait_for_registry() {
663-
local generation=$(oc get dc/docker-registry -o jsonpath='{.metadata.generation}')
663+
local generation="$(oc get dc/docker-registry -o 'jsonpath={.metadata.generation}')"
664664
local onereplicajs='{.status.observedGeneration},{.status.replicas},{.status.updatedReplicas},{.status.availableReplicas}'
665-
wait_for_command "oc get dc/docker-registry -o jsonpath='$onereplicajs' --config='${ADMIN_KUBECONFIG}' | grep '^$generation,1,1,1$'" $((5*TIME_MIN))
665+
wait_for_command "oc get dc/docker-registry -o 'jsonpath=${onereplicajs}' --config='${ADMIN_KUBECONFIG}' | grep '^${generation},1,1,1$'" "$((5*TIME_MIN))"
666666
local readyjs='{.items[*].status.conditions[?(@.type=="Ready")].status}'
667-
wait_for_command "oc get pod -l deploymentconfig=docker-registry -o jsonpath='$readyjs' --config='${ADMIN_KUBECONFIG}' | grep -qi true" $TIME_MIN
667+
wait_for_command "oc get pod -l deploymentconfig=docker-registry -o 'jsonpath=${readyjs}' --config='${ADMIN_KUBECONFIG}' | grep -qi true" "${TIME_MIN}"
668668
}
669669
readonly -f wait_for_registry
670670

test/end-to-end/core.sh

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ os::cmd::expect_success 'oc status -n default'
117117

118118
# check to make sure a project admin can push an image to an image stream that doesn't exist
119119
os::cmd::expect_success 'oc project cache'
120-
e2e_user_token=$(oc whoami -t)
120+
e2e_user_token="$(oc whoami -t)"
121121

122122
echo "[INFO] Docker login as e2e-user to ${DOCKER_REGISTRY}"
123123
os::cmd::expect_success "docker login -u e2e-user -p ${e2e_user_token} -e [email protected] ${DOCKER_REGISTRY}"
@@ -129,10 +129,10 @@ os::cmd::expect_success "docker push ${DOCKER_REGISTRY}/cache/ruby-22-centos7:la
129129
echo "[INFO] Pushed ruby-22-centos7"
130130

131131
# get image's digest
132-
rubyimagedigest=$(oc get -o jsonpath='{.status.tags[?(@.tag=="latest")].items[0].image}' is/ruby-22-centos7)
132+
rubyimagedigest="$(oc get -o jsonpath='{.status.tags[?(@.tag=="latest")].items[0].image}' is/ruby-22-centos7)"
133133
echo "[INFO] Ruby image digest: $rubyimagedigest"
134134
# get a random, non-empty blob
135-
rubyimageblob=$(oc get isimage -o go-template='{{range .image.dockerImageLayers}}{{if gt .size 1024.}}{{.name}},{{end}}{{end}}' ruby-22-centos7@${rubyimagedigest} | cut -d , -f 1)
135+
rubyimageblob="$(oc get isimage -o go-template='{{range .image.dockerImageLayers}}{{if gt .size 1024.}}{{.name}},{{end}}{{end}}' ruby-22-centos7@${rubyimagedigest} | cut -d , -f 1)"
136136
echo "[INFO] Ruby's testing blob digest: $rubyimageblob"
137137

138138
# verify remote images can be pulled directly from the local registry
@@ -170,7 +170,7 @@ echo "[INFO] Cross namespace pull successful"
170170

171171
# verify we can pull from tagged image (using image digest)
172172
remove_docker_images "${DOCKER_REGISTRY}/custom/cross" namespace-pull
173-
imagedigest=$(oc get istag hello-world:latest --template={{.image.metadata.name}})
173+
imagedigest="$(oc get istag hello-world:latest --template='{{.image.metadata.name}}')"
174174
echo "[INFO] Tagging hello-world@${imagedigest} to the same image stream and pulling it"
175175
os::cmd::expect_success "oc tag hello-world@${imagedigest} hello-world:new-id-tag"
176176
os::cmd::expect_success "docker pull ${DOCKER_REGISTRY}/cache/hello-world:new-id-tag"
@@ -197,26 +197,26 @@ echo "[INFO] Cross namespace pull successful"
197197
os::cmd::expect_success 'oc login -u schema2-user -p pass'
198198
os::cmd::expect_success "oc new-project schema2"
199199
os::cmd::expect_success "oc project schema2"
200-
schema2_user_token=$(oc whoami -t)
200+
schema2_user_token="$(oc whoami -t)"
201201

202202
echo "[INFO] Fetch manifest V2 schema 2 image with old client using pullthrough"
203203
os::cmd::expect_success "oc import-image --confirm --from=hello-world:latest hello-world:pullthrough"
204204
os::cmd::expect_success_and_text "oc get -o jsonpath='{.image.dockerImageManifestMediaType}' istag hello-world:pullthrough" 'application/vnd\.docker\.distribution\.manifest\.v2\+json'
205-
hello_world_name=$(oc get -o 'jsonpath={.image.metadata.name}' istag hello-world:pullthrough)
206-
os::cmd::expect_success_and_text "echo ${hello_world_name:-}" '.+'
205+
hello_world_name="$(oc get -o 'jsonpath={.image.metadata.name}' istag hello-world:pullthrough)"
206+
os::cmd::expect_success_and_text "echo '${hello_world_name}'" '.+'
207207
# dockerImageManifest is retrievable only with "images" resource
208-
hello_world_config_name=$(oc get -o 'jsonpath={.dockerImageManifest}' image "$hello_world_name" --context="$CLUSTER_ADMIN_CONTEXT" | jq -r '.config.digest')
209-
hello_world_config_image=$(oc get -o 'jsonpath={.image.dockerImageConfig}' istag hello-world:pullthrough | jq -r '.container_config.Image')
210-
os::cmd::expect_success_and_text "echo ${hello_world_config_name:-},${hello_world_config_image:-}" '.+,.+'
208+
hello_world_config_name="$(oc get -o 'jsonpath={.dockerImageManifest}' image "${hello_world_name}" --context="${CLUSTER_ADMIN_CONTEXT}" | jq -r '.config.digest')"
209+
hello_world_config_image="$(oc get -o 'jsonpath={.image.dockerImageConfig}' istag hello-world:pullthrough | jq -r '.container_config.Image')"
210+
os::cmd::expect_success_and_text "echo '${hello_world_config_name},${hello_world_config_image}'" '.+,.+'
211211
# verify we can fetch the config
212-
os::cmd::expect_success_and_text "curl -u 'schema2-user:${schema2_user_token}' -v -s -o ${ARTIFACT_DIR}/hello-world-config.json ${DOCKER_REGISTRY}/v2/schema2/hello-world/blobs/${hello_world_config_name} 2>&1" "Docker-Content-Digest:\s*${hello_world_config_name}"
213-
os::cmd::expect_success_and_text "jq -r '.container_config.Image' ${ARTIFACT_DIR}/hello-world-config.json" "${hello_world_config_image}"
212+
os::cmd::expect_success_and_text "curl -u 'schema2-user:${schema2_user_token}' -v -s -o '${ARTIFACT_DIR}/hello-world-config.json' '${DOCKER_REGISTRY}/v2/schema2/hello-world/blobs/${hello_world_config_name}' 2>&1" "Docker-Content-Digest:\s*${hello_world_config_name}"
213+
os::cmd::expect_success_and_text "jq -r '.container_config.Image' '${ARTIFACT_DIR}/hello-world-config.json'" "${hello_world_config_image}"
214214
# no accept header provided, the registry will convert schema 2 to schema 1 on-the-fly
215-
hello_world_schema1_digest=$(curl -u schema2-user:${schema2_user_token} -s -v -o ${ARTIFACT_DIR}/hello-world-manifest.json ${DOCKER_REGISTRY}/v2/schema2/hello-world/manifests/pullthrough |& sed -n 's/.*Docker-Content-Digest:\s*\(\S\+\).*/\1/p')
215+
hello_world_schema1_digest="$(curl -u "schema2-user:${schema2_user_token}" -s -v -o "${ARTIFACT_DIR}/hello-world-manifest.json" "${DOCKER_REGISTRY}/v2/schema2/hello-world/manifests/pullthrough" |& sed -n 's/.*Docker-Content-Digest:\s*\(\S\+\).*/\1/p')"
216216
# ensure the manifest was converted to schema 1
217217
os::cmd::expect_success_and_text "jq -r '.schemaVersion' ${ARTIFACT_DIR}/hello-world-manifest.json" '^1$'
218-
os::cmd::expect_success_and_not_text "echo '${hello_world_schema1_digest:-}'" "${hello_world_name:-}"
219-
os::cmd::expect_success_and_text "echo '${hello_world_schema1_digest:-}'" ".+"
218+
os::cmd::expect_success_and_not_text "echo '${hello_world_schema1_digest}'" "${hello_world_name}"
219+
os::cmd::expect_success_and_text "echo '${hello_world_schema1_digest}'" ".+"
220220
os::cmd::expect_success_and_text "curl -I -u 'schema2-user:${schema2_user_token}' '${DOCKER_REGISTRY}/v2/schema2/hello-world/manifests/${hello_world_schema1_digest}'" "404 Not Found"
221221
echo "[INFO] Manifest V2 schema 2 image fetched successfully with old client"
222222

@@ -227,7 +227,7 @@ os::cmd::expect_success_and_text 'oc whoami' 'system:admin'
227227
# check to make sure an image-pusher can push an image
228228
os::cmd::expect_success 'oc policy add-role-to-user system:image-pusher -n cache pusher'
229229
os::cmd::expect_success 'oc login -u pusher -p pass'
230-
pusher_token=$(oc whoami -t)
230+
pusher_token="$(oc whoami -t)"
231231

232232
echo "[INFO] Docker login as pusher to ${DOCKER_REGISTRY}"
233233
os::cmd::expect_success "docker login -u e2e-user -p ${pusher_token} -e [email protected] ${DOCKER_REGISTRY}"
@@ -248,10 +248,12 @@ os::cmd::expect_success 'oc policy add-role-to-user system:image-puller system:a
248248
os::cmd::try_until_text 'oc policy who-can get imagestreams/layers -n custom' 'system:anonymous'
249249
os::cmd::expect_success "docker pull ${DOCKER_REGISTRY}/custom/cross:namespace-pull"
250250
os::cmd::expect_success "docker pull ${DOCKER_REGISTRY}/custom/cross:namespace-pull-id"
251-
# unauthorized pushes return authorization errors, regardless of backing data
252-
os::cmd::expect_failure_and_text "docker push ${DOCKER_REGISTRY}/missing/image:tag" "authentication required|not authorized"
253-
os::cmd::expect_failure_and_text "docker push ${DOCKER_REGISTRY}/custom/cross:namespace-pull" "authentication required|not authorized"
254-
os::cmd::expect_failure_and_text "docker push ${DOCKER_REGISTRY}/custom/cross:namespace-pull-id" "authentication required|not authorized"
251+
# unauthorized pushes return authorization errors, regardless of backing data; error messages differ with each docker version
252+
# docker 1.9: not authorized
253+
# docker 1.10: authentication required
254+
os::cmd::expect_failure_and_text "docker push ${DOCKER_REGISTRY}/missing/image:tag" "not authorized|authentication required"
255+
os::cmd::expect_failure_and_text "docker push ${DOCKER_REGISTRY}/custom/cross:namespace-pull" "not authorized|authentication required"
256+
os::cmd::expect_failure_and_text "docker push ${DOCKER_REGISTRY}/custom/cross:namespace-pull-id" "not authorized|authentication required"
255257
# test anonymous pushes
256258
os::cmd::expect_success 'oc policy add-role-to-user system:image-pusher system:anonymous -n custom'
257259
os::cmd::try_until_text 'oc policy who-can update imagestreams/layers -n custom' 'system:anonymous'
@@ -510,8 +512,9 @@ os::cmd::expect_success "oc exec -p ${registry_pod} du /registry > '${LOG_DIR}/p
510512
os::cmd::expect_code "diff ${LOG_DIR}/prune-images.before.txt ${LOG_DIR}/prune-images.after.txt" 1
511513
echo "[INFO] Validated image pruning"
512514

515+
# with registry's re-deployment we loose all the blobs stored in its storage until now
513516
echo "[INFO] Configure registry to accept manifest V2 schema 2"
514-
os::cmd::expect_success "oc project ${CLUSTER_ADMIN_CONTEXT}"
517+
os::cmd::expect_success "oc project '${CLUSTER_ADMIN_CONTEXT}'"
515518
os::cmd::expect_success 'oc env -n default dc/docker-registry REGISTRY_MIDDLEWARE_REPOSITORY_OPENSHIFT_ACCEPTSCHEMA2=true'
516519
wait_for_registry
517520
echo "[INFO] Registry configured to accept manifest V2 schema 2"
@@ -521,7 +524,7 @@ os::cmd::expect_success "oc login -u schema2-user -p pass"
521524
os::cmd::expect_success "oc project schema2"
522525
# tagging remote docker.io/busybox image
523526
os::cmd::expect_success "docker tag busybox '${DOCKER_REGISTRY}/schema2/busybox'"
524-
os::cmd::expect_success "docker login -u e2e-user -p ${schema2_user_token} -e [email protected] ${DOCKER_REGISTRY}"
527+
os::cmd::expect_success "docker login -u e2e-user -p '${schema2_user_token}' -e [email protected] '${DOCKER_REGISTRY}'"
525528
os::cmd::expect_success "docker push '${DOCKER_REGISTRY}/schema2/busybox'"
526529
# image accepted as schema 2
527530
os::cmd::expect_success_and_text "oc get -o jsonpath='{.image.dockerImageManifestMediaType}' istag busybox:latest" 'application/vnd\.docker\.distribution\.manifest\.v2\+json'
@@ -531,24 +534,24 @@ echo "[INFO] Convert manifest V2 schema 2 to schema 1 for older client"
531534
os::cmd::expect_success 'oc login -u schema2-user -p pass'
532535
os::cmd::expect_success "oc new-project schema2tagged"
533536
os::cmd::expect_success "oc tag --source=istag schema2/busybox:latest busybox:latest"
534-
busybox_name=$(oc get -o 'jsonpath={.image.metadata.name}' istag busybox:latest)
535-
os::cmd::expect_success_and_text "echo ${busybox_name:-}" '.+'
537+
busybox_name="$(oc get -o 'jsonpath={.image.metadata.name}' istag busybox:latest)"
538+
os::cmd::expect_success_and_text "echo '${busybox_name}'" '.+'
536539
# no accept header provided, registry converts on-the-fly to schema 1
537-
busybox_schema1_digest=$(curl -u "schema2-user:${schema2_user_token}" -s -v -o ${ARTIFACT_DIR}/busybox-manifest.json ${DOCKER_REGISTRY}/v2/schema2tagged/busybox/manifests/latest |& sed -n 's/.*Docker-Content-Digest:\s*\(\S\+\).*/\1/p')
540+
busybox_schema1_digest="$(curl -u "schema2-user:${schema2_user_token}" -s -v -o "${ARTIFACT_DIR}/busybox-manifest.json" "${DOCKER_REGISTRY}/v2/schema2tagged/busybox/manifests/latest" |& sed -n 's/.*Docker-Content-Digest:\s*\(\S\+\).*/\1/p')"
538541
# ensure the manifest was converted to schema 1
539-
os::cmd::expect_success_and_text "jq -r '.schemaVersion' ${ARTIFACT_DIR}/busybox-manifest.json" '^1$'
540-
os::cmd::expect_success_and_not_text "echo '${busybox_schema1_digest:-}'" "${busybox_name:-}"
541-
os::cmd::expect_success_and_text "echo '${busybox_schema1_digest:-}'" ".+"
542+
os::cmd::expect_success_and_text "jq -r '.schemaVersion' '${ARTIFACT_DIR}/busybox-manifest.json'" '^1$'
543+
os::cmd::expect_success_and_not_text "echo '${busybox_schema1_digest}'" "${busybox_name}"
544+
os::cmd::expect_success_and_text "echo '${busybox_schema1_digest}'" ".+"
542545
# schema 1 is generated on-the-fly, it's not stored in the registry, thus Not Found
543546
os::cmd::expect_success_and_text "curl -I -u 'schema2-user:${schema2_user_token}' '${DOCKER_REGISTRY}/v2/schema2tagged/busybox/manifests/${busybox_schema1_digest}'" "404 Not Found"
544547
# ensure we can fetch it back as schema 2
545-
os::cmd::expect_success_and_text "curl -I -u 'schema2-user:${schema2_user_token}' -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' ${DOCKER_REGISTRY}/v2/schema2tagged/busybox/manifests/latest" "Docker-Content-Digest:\s*${busybox_name}"
548+
os::cmd::expect_success_and_text "curl -I -u 'schema2-user:${schema2_user_token}' -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' '${DOCKER_REGISTRY}/v2/schema2tagged/busybox/manifests/latest'" "Docker-Content-Digest:\s*${busybox_name}"
546549
echo "[INFO] Manifest V2 schema 2 successfully converted to schema 1"
547550

548551
echo "[INFO] Verify image size calculation"
549-
busybox_expected_size=$(oc get -o jsonpath='{.dockerImageManifest}' image ${busybox_name} --context="${CLUSTER_ADMIN_CONTEXT}" | jq -r '[.. | .size?] | add')
550-
busybox_calculated_size=$(oc get -o go-template='{{.dockerImageMetadata.Size}}' image ${busybox_name} --context="${CLUSTER_ADMIN_CONTEXT}")
551-
os::cmd::expect_success_and_text "echo ${busybox_expected_size:-}:${busybox_calculated_size:-}" '^[1-9][0-9]*:[1-9][0-9]*$'
552+
busybox_expected_size="$(oc get -o 'jsonpath={.dockerImageManifest}' image "${busybox_name}" --context="${CLUSTER_ADMIN_CONTEXT}" | jq -r '[.. | .size?] | add')"
553+
busybox_calculated_size="$(oc get -o go-template='{{.dockerImageMetadata.Size}}' image "${busybox_name}" --context="${CLUSTER_ADMIN_CONTEXT}")"
554+
os::cmd::expect_success_and_text "echo '${busybox_expected_size}:${busybox_calculated_size}'" '^[1-9][0-9]*:[1-9][0-9]*$'
552555
os::cmd::expect_success_and_text "echo '${busybox_expected_size}'" "${busybox_calculated_size}"
553556
echo "[INFO] Image size matches"
554557

0 commit comments

Comments
 (0)