|
| 1 | +#!/bin/bash |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | +# contributor license agreements. See the NOTICE file distributed with |
| 4 | +# this work for additional information regarding copyright ownership. |
| 5 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | +# (the "License"); you may not use this file except in compliance with |
| 7 | +# the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +set -euo pipefail |
| 18 | + |
| 19 | +TEST_DIR="${TEST_DIR:-$(dirname -- "${BASH_SOURCE[0]}")}" |
| 20 | +source "${TEST_DIR}/../../shared.sh" |
| 21 | + |
| 22 | +# Clean up any existing test containers and volumes |
| 23 | +container_cleanup "$container_name" |
| 24 | +docker volume rm "${container_name}-vol" 2>/dev/null || true |
| 25 | + |
| 26 | +# Create a Docker volume |
| 27 | +echo "Creating Docker volume" |
| 28 | +docker volume create "${container_name}-vol" |
| 29 | + |
| 30 | +# Use a temporary container to copy the old log4j2.xml into the volume |
| 31 | +echo "Copying old log4j2.xml into volume" |
| 32 | +docker run --rm \ |
| 33 | + -v "${container_name}-vol:/var/solr" \ |
| 34 | + -v "$TEST_DIR/log4j2_old.xml:/tmp/log4j2_old.xml:ro" \ |
| 35 | + "$tag" \ |
| 36 | + bash -c "cp /tmp/log4j2_old.xml /var/solr/log4j2.xml" |
| 37 | + |
| 38 | +# Verify initial state - file should contain old property name |
| 39 | +echo "Verifying initial log4j2.xml contains old property name" |
| 40 | +old_log4j=$(docker run --rm -v "${container_name}-vol:/var/solr" -e NO_INIT_VAR_SOLR=1 "$tag" cat /var/solr/log4j2.xml) |
| 41 | +if ! grep -q 'solr\.log\.dir' <<<"$old_log4j"; then |
| 42 | + echo "Test setup failed; log4j2.xml does not contain solr.log.dir" |
| 43 | + docker volume rm "${container_name}-vol" |
| 44 | + exit 1 |
| 45 | +fi |
| 46 | +echo "Confirmed: log4j2.xml contains solr.log.dir property" |
| 47 | + |
| 48 | +# Start Solr with the volume (init-var-solr will run and migrate the file) |
| 49 | +echo "Running $container_name with volume" |
| 50 | +docker run --name "$container_name" -d \ |
| 51 | + -v "${container_name}-vol:/var/solr" \ |
| 52 | + "$tag" solr-precreate gettingstarted |
| 53 | + |
| 54 | +wait_for_container_and_solr "$container_name" |
| 55 | + |
| 56 | +# Verify the log4j2.xml has been migrated |
| 57 | +echo "Verifying log4j2.xml was migrated to new property name" |
| 58 | +migrated_log4j=$(docker exec "$container_name" cat /var/solr/log4j2.xml) |
| 59 | + |
| 60 | +if grep -q 'solr\.log\.dir' <<<"$migrated_log4j"; then |
| 61 | + echo "Test $TEST_NAME $tag failed; log4j2.xml still contains old solr.log.dir property" |
| 62 | + docker exec "$container_name" cat /var/solr/log4j2.xml |
| 63 | + container_cleanup "$container_name" |
| 64 | + docker volume rm "${container_name}-vol" |
| 65 | + exit 1 |
| 66 | +fi |
| 67 | + |
| 68 | +if ! grep -q 'solr\.logs\.dir' <<<"$migrated_log4j"; then |
| 69 | + echo "Test $TEST_NAME $tag failed; log4j2.xml does not contain new solr.logs.dir property" |
| 70 | + docker exec "$container_name" cat /var/solr/log4j2.xml |
| 71 | + container_cleanup "$container_name" |
| 72 | + docker volume rm "${container_name}-vol" |
| 73 | + exit 1 |
| 74 | +fi |
| 75 | + |
| 76 | +echo "Confirmed: log4j2.xml successfully migrated from solr.log.dir to solr.logs.dir" |
| 77 | + |
| 78 | +# Clean up |
| 79 | +container_cleanup "$container_name" |
| 80 | +docker volume rm "${container_name}-vol" |
| 81 | + |
| 82 | +echo "Test $TEST_NAME $tag succeeded" |
0 commit comments