Skip to content

Commit

Permalink
Merge pull request #3672 from vanhalenar/vmnamevalid
Browse files Browse the repository at this point in the history
USHIFT-1545: Full VM name validation
  • Loading branch information
openshift-merge-bot[bot] committed Jul 29, 2024
2 parents 49edab0 + 26248fe commit 74d37f3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/bin/scenario.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,32 @@ full_vm_name() {
echo "${SCENARIO//@/-}-${base}"
}

# hostname validation
# based on https://github.com/rhinstaller/anaconda/blob/c95142f76735a2e9ae6d845f8569d46632ddd619/pyanaconda/network.py#L96-L120
validate_vm_hostname() {
local vm_name="$1"

if [ -z "${vm_name}" ]; then
error "VM hostname cannot be empty string"
record_junit "${vm_name}" "vm_hostname_validation" "FAILED"
exit 1
fi

if [ ${#vm_name} -gt 64 ]; then
error "VM hostname is too long"
record_junit "${vm_name}" "vm_hostname_validation" "FAILED"
exit 1
fi

if ! echo "${vm_name}" | grep -E '^([a-zA-Z0-9]+-*[a-zA-Z0-9]+)+$|^[a-zA-Z0-9]+$' > /dev/null; then
error "VM hostname is invalid"
record_junit "${vm_name}" "vm_hostname_validation" "FAILED"
exit 1
fi

record_junit "${vm_name}" "vm_hostname_validation" "OK"
}

vm_property_filename() {
local -r vmname="$1"
local -r property="$2"
Expand Down Expand Up @@ -227,6 +253,8 @@ prepare_kickstart() {
local -r vm_hostname="${full_vmname/./-}"
local -r hostname=$(hostname)

validate_vm_hostname "${vm_hostname}"

echo "Preparing kickstart file ${template} at ${output_dir}"
if [ ! -f "${KICKSTART_TEMPLATE_DIR}/${template}" ]; then
error "No ${template} in ${KICKSTART_TEMPLATE_DIR}"
Expand Down

0 comments on commit 74d37f3

Please sign in to comment.