diff --git a/test/e2e/build.sh b/test/e2e/build.sh index 749b25b..e74227b 100755 --- a/test/e2e/build.sh +++ b/test/e2e/build.sh @@ -5,28 +5,32 @@ REPO_DIR="$(cd "${E2E_DIR}/../.." && pwd)" BIN_DIR="${BIN_DIR:-${E2E_DIR}/topologies/bin}" SCRIPTS_DIR="${SCRIPTS_DIR:-${E2E_DIR}/topologies/scripts}" BINARIES="agent dhcp metadata two-hostsvc" -UNITS="two-hostsvc.service" -SCRIPTS="bootstrap_kvm.sh" +ASSET_SCRIPTS="run-dnsmasq-in-netns.sh run-dhcp-in-netns.sh" +UNITS="two-hostsvc.service agent.service dnsmasq@.service dhcp@.service metadata@.service" +MARKERS="SHA256SUMS VERSION RELEASE" +SCRIPTS="deploy.sh bootstrap_kvm.sh" usage () { cat >&2 < | --clean] - sans option : compile ${BINARIES} pour linux/amd64 depuis l'arbre courant dans ${BIN_DIR} - et y copie ${UNITS}, copie ${SCRIPTS} dans ${SCRIPTS_DIR} ; le prochain lab - les installe par-dessus la release épinglée dans topologies/provision/hypervisor.sh - --clean : vide ${BIN_DIR} et ${SCRIPTS_DIR} ; le prochain lab teste la release seule + sans option : prépare dans ${BIN_DIR} les assets de l'arbre courant au format d'une release + (${BINARIES} compilés pour linux/amd64, ${ASSET_SCRIPTS}, units, SHA256SUMS, + VERSION) et copie ${SCRIPTS} dans ${SCRIPTS_DIR} ; le prochain lab déploie + l'arbre courant en entier, sans rien télécharger + --release : le prochain lab déploie la release telle que publiée (fichier RELEASE) + --clean : vide ${BIN_DIR} et ${SCRIPTS_DIR} ; le prochain lab refuse de démarrer USAGE exit 2 } clean () { - local file script - for file in ${BINARIES} ${UNITS}; do + local file + for file in ${BINARIES} ${ASSET_SCRIPTS} ${UNITS} ${MARKERS}; do rm -f "${BIN_DIR}/${file}" || return 1 done - for script in ${SCRIPTS}; do - rm -f "${SCRIPTS_DIR}/${script}" || return 1 + for file in ${SCRIPTS}; do + rm -f "${SCRIPTS_DIR}/${file}" || return 1 done } @@ -41,27 +45,49 @@ build_version () { fi } +sha256 () { + if command -v sha256sum >/dev/null 2>&1; then + sha256sum "$@" + else + shasum -a 256 "$@" + fi +} + build () { - local binary unit script version + local binary file version version=$(build_version) || return 1 + clean || return 1 echo "== version ${version}" >&2 for binary in ${BINARIES}; do echo "== ${binary}" >&2 (cd "${REPO_DIR}" && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=${version}" -o "${BIN_DIR}/${binary}" "./cmd/${binary}") || return 1 done - for unit in ${UNITS}; do - cp "${REPO_DIR}/systemd/${unit}" "${BIN_DIR}/${unit}" || return 1 + for file in ${ASSET_SCRIPTS}; do + install -m 0755 "${REPO_DIR}/scripts/${file}" "${BIN_DIR}/${file}" || return 1 done - for script in ${SCRIPTS}; do - echo "== ${script}" >&2 - cp "${REPO_DIR}/scripts/${script}" "${SCRIPTS_DIR}/${script}" || return 1 + for file in ${UNITS}; do + cp "${REPO_DIR}/systemd/${file}" "${BIN_DIR}/${file}" || return 1 done - (cd "${BIN_DIR}" && sha256sum ${BINARIES} ${UNITS} 2>/dev/null || shasum -a 256 ${BINARIES} ${UNITS}) + for file in ${SCRIPTS}; do + echo "== ${file}" >&2 + cp "${REPO_DIR}/scripts/${file}" "${SCRIPTS_DIR}/${file}" || return 1 + done + (cd "${BIN_DIR}" && sha256 ${BINARIES} ${ASSET_SCRIPTS} ${UNITS} > SHA256SUMS) || return 1 + echo "${version}" > "${BIN_DIR}/VERSION" || return 1 + cat "${BIN_DIR}/SHA256SUMS" +} + +release () { + [ -n "${1}" ] || usage + clean || return 1 + echo "${1}" > "${BIN_DIR}/RELEASE" || return 1 + echo "== le prochain lab déploie la release ${1}" >&2 } main () { case "${1:-}" in "") build ;; + --release) release "${2:-}" ;; --clean) clean ;; *) usage ;; esac diff --git a/test/e2e/run_test.sh b/test/e2e/run_test.sh index 9b6a560..c4b301a 100755 --- a/test/e2e/run_test.sh +++ b/test/e2e/run_test.sh @@ -856,6 +856,23 @@ test_build_version_is_the_commit_dirty_when_the_tree_changed () { teardown } +test_build_release_and_clean_prepare_the_next_lab () { + setup "build.sh : --release ne laisse que RELEASE, --clean vide tout, sans tag refusé" + local bin="${WORK}/bin" scripts="${WORK}/scripts" f + mkdir -p "${bin}" "${scripts}" + for f in agent dhcp metadata two-hostsvc run-dhcp-in-netns.sh agent.service SHA256SUMS VERSION; do : > "${bin}/${f}"; done + : > "${bin}/autre" && : > "${scripts}/deploy.sh" && : > "${scripts}/bootstrap_kvm.sh" + build_in () { BIN_DIR="${bin}" SCRIPTS_DIR="${scripts}" bash "${DIR}/build.sh" "$@" 2>&1; } + build_in --release 0.3.0 >/dev/null || fail "--release 0.3.0 en échec" + [[ $(LC_ALL=C ls "${bin}" | tr '\n' ' ') == "RELEASE autre " ]] || fail "après --release : $(LC_ALL=C ls "${bin}" | tr '\n' ' ')" + [[ $(cat "${bin}/RELEASE") == 0.3.0 ]] || fail "RELEASE : $(cat "${bin}/RELEASE")" + [[ -z $(ls "${scripts}") ]] || fail "scripts laissés : $(ls "${scripts}")" + build_in --release >/dev/null && fail "--release sans tag accepté" + build_in --clean >/dev/null || fail "--clean en échec" + [[ $(ls "${bin}") == autre ]] || fail "après --clean : $(ls "${bin}" | tr '\n' ' ')" + teardown +} + for T in $(declare -F | awk '{print $3}' | grep '^test_'); do "${T}" done diff --git a/test/e2e/topologies/provision/hypervisor.sh b/test/e2e/topologies/provision/hypervisor.sh index 0990355..449d6d9 100755 --- a/test/e2e/topologies/provision/hypervisor.sh +++ b/test/e2e/topologies/provision/hypervisor.sh @@ -1,9 +1,20 @@ #!/bin/sh set -eu -RELEASE=0.2.0 PUBLIC_VNI=1 GIT_SERVER=https://git.g3e.fr/ REPO=syonad/two +ASSETS="${LAB_FILES}/bin" +if [ -f "${ASSETS}/SHA256SUMS" ] && [ -f "${ASSETS}/VERSION" ] && [ -f "${LAB_FILES}/scripts/deploy.sh" ] && [ -f "${LAB_FILES}/scripts/bootstrap_kvm.sh" ]; then + MODE=tree + VERSION=$(cat "${ASSETS}/VERSION") +elif [ -f "${ASSETS}/RELEASE" ]; then + MODE=release + VERSION=$(cat "${ASSETS}/RELEASE") +else + echo "lab: ni arbre courant (SHA256SUMS, VERSION, scripts) ni release (RELEASE) dans ${LAB_FILES} : lancer test/e2e/build.sh" >&2 + exit 1 +fi +[ -n "${VERSION}" ] || { echo "lab: version vide (${MODE})" >&2; exit 1; } n=0 until curl -fsS -o /dev/null "${GIT_SERVER}"; do n=$((n + 1)) @@ -24,31 +35,18 @@ if [ -e /sys/class/net/lan ]; then fi mkdir -p /opt/two/scripts cd /opt/two/scripts -for script in deploy.sh bootstrap_kvm.sh; do - curl -fsS -o "${script}" "${GIT_SERVER}${REPO}/raw/tag/${RELEASE}/scripts/${script}" -done -chmod 0755 deploy.sh bootstrap_kvm.sh -bash ./deploy.sh --noup_script -i -u "${LAB_UPLINK}" -t "${RELEASE}" -DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends nftables -if [ -f "${LAB_FILES}/scripts/bootstrap_kvm.sh" ]; then - bash -c 'FLAGS_TRUE=0; FLAGS_FALSE=1; . ./deploy.sh && . "$1" && kvm_public_segment "${FLAGS_FALSE}" "${FLAGS_TRUE}" br-000000 br-public "$2"' \ - lab "${LAB_FILES}/scripts/bootstrap_kvm.sh" "${PUBLIC_VNI}" - echo "lab: segment public posé par le bootstrap_kvm.sh de l'arbre courant (VNI ${PUBLIC_VNI})" -fi -for binary in "${LAB_FILES}"/bin/*; do - [ -f "${binary}" ] || continue - name=$(basename "${binary}") - case "${name}" in *.service) continue ;; esac - install -D -m 0755 "${binary}" "/opt/two/local/bin/${name}" - ln -sfn "/opt/two/local/bin/${name}" "/opt/two/bin/${name}" - echo "lab: ${name} compilé en local remplace celui de la release ${RELEASE}" -done -for unit in "${LAB_FILES}"/bin/*.service; do - [ -f "${unit}" ] || continue - name=$(basename "${unit}") - install -m 0644 "${unit}" "/etc/systemd/system/${name}" - systemctl daemon-reload - systemctl enable "${name}" - systemctl restart "${name}" - echo "lab: unité ${name} de l'arbre local installée par-dessus la release ${RELEASE}" -done +case "${MODE}" in + tree) + install -m 0755 "${LAB_FILES}/scripts/deploy.sh" "${LAB_FILES}/scripts/bootstrap_kvm.sh" . + echo "lab: arbre courant ${VERSION}, déployé depuis ${ASSETS} sans téléchargement" + bash ./deploy.sh --noup_script -i -u "${LAB_UPLINK}" -N "${PUBLIC_VNI}" -a "${ASSETS}" -t "${VERSION}" + ;; + release) + for script in deploy.sh bootstrap_kvm.sh; do + curl -fsS -o "${script}" "${GIT_SERVER}${REPO}/raw/tag/${VERSION}/scripts/${script}" + done + chmod 0755 deploy.sh bootstrap_kvm.sh + echo "lab: release ${VERSION}, déployée telle que publiée" + bash ./deploy.sh --noup_script -i -u "${LAB_UPLINK}" -t "${VERSION}" + ;; +esac