Skip to content

Instantly share code, notes, and snippets.

@zonggen
Last active November 5, 2019 17:15
Show Gist options
  • Save zonggen/c4418f7d86d015759fc345c3891697c2 to your computer and use it in GitHub Desktop.
Save zonggen/c4418f7d86d015759fc345c3891697c2 to your computer and use it in GitHub Desktop.
Script for testing `fcos`
#!/bin/bash
# FCOS_INSTALLER_DIR=/home/abai/git/coreos-installer
# LATEST_BUILD=${PWD}/builds/latest/x86_64
# export COREOS_ASSEMBLER_GIT=/home/abai/git/coreos-assembler
COREOS_PINGER=/home/abai/git/fedora-coreos-pinger
cecho(){
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[1;33m"
# ... ADD MORE COLORS
NC="\033[0m" # No Color
printf "${!1}${2} ${NC}\n"
}
cosa() {
env | grep COREOS_ASSEMBLER
set -x # so we can see what command gets run
podman run --rm -ti --security-opt label=disable --privileged \
--uidmap=1000:0:1 --uidmap=0:1:1000 --uidmap 1001:1001:64536 \
-v ${PWD}:/srv/ --device /dev/kvm --device /dev/fuse \
--tmpfs /tmp -v /var/tmp:/var/tmp --name cosa \
${COREOS_PINGER:+-v $COREOS_PINGER/target:/fedora-coreos-pinger} \
${COREOS_ASSEMBLER_CONFIG_GIT:+-v $COREOS_ASSEMBLER_CONFIG_GIT:/srv/src/config/:ro} \
${COREOS_ASSEMBLER_GIT:+-v $COREOS_ASSEMBLER_GIT/src/:/usr/lib/coreos-assembler/:ro} \
${COREOS_ASSEMBLER_CONTAINER_RUNTIME_ARGS} \
${COREOS_ASSEMBLER_CONTAINER:-quay.io/coreos-assembler/coreos-assembler:latest} $@
rc=$?; set +x; return $rc
}
cp_installer() {
set -x
rm -rf ${PWD}/overrides/rootfs
mkdir -p ${PWD}/overrides/rootfs/usr/libexec/
mkdir -p ${PWD}/overrides/rootfs/usr/lib/dracut/modules.d/30coreos-installer/
# cp ${FCOS_INSTALLER_DIR}/dracut/30coreos-installer/module-setup.sh ${PWD}/overrides/rootfs/usr/lib/dracut/modules.d/30coreos-installer/module-setup.sh
cp ${FCOS_INSTALLER_DIR}/dracut/30coreos-installer/parse-coreos.sh ${PWD}/overrides/rootfs/usr/lib/dracut/modules.d/30coreos-installer/parse-coreos.sh
cp ${FCOS_INSTALLER_DIR}/coreos-installer ${PWD}/overrides/rootfs/usr/libexec/coreos-installer
cosa fetch
cosa build
set +x
}
base_ign(){
local f="${LATEST_BUILD}/base.ign"
# Get target architecture
local arch=$(uname -m)
case $arch in
"x86_64") VM_TERMINAL="ttyS0" ;;
"ppc64le") VM_TERMINAL="hvc0" ;;
"aarch64") VM_TERMINAL="ttyAMA0" ;;
"s390x") VM_TERMINAL="ttysclp0" ;;
*) cecho "RED" "Architecture $(arch) not supported"
esac
rm -f "${f}"
touch "${f}"
cat > "${f}" <<EOF
{
"ignition": {
"config": {
"replace": {
"source": null,
"verification": {}
}
},
"security": {
"tls": {}
},
"timeouts": {},
"version": "3.0.0"
},
"passwd": {
"users": [
{
"name": "core",
"sshAuthorizedKeys": [
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC6jeR8fMqwxDsoVdc62m+V6L9QWH7MSJ+zmmrE0UWClF3iuFJ5belHxXNg/6wnpefyu5hKrrwCGjcfxNxH438MYuUOBxo5CwZHI3d3+kkMudidEhFJxMhk+S9I5XnBRjhzQrTnqcf2BULW4kV6JfrLSx2TQxvaUh9d59tJa5J6sFtob6Iil/qY9oyKQQHA/+7+xgCqWW2P/lgkBCLk1+ll+F0nNCTygUJjWyRWy3lUDo5edwyV8cqoYJVmE1dcBAqV7GwflrlSf+RzAVa8S5hxpdKyXs9SVVlFoN3/SjwaJnJX/oQWPbubraBm3/7sAC2pLAo9BuSRYdylUJyS9NGhNK2ibdB4o5rWREynnX6Lr4FotzIAQg+xDFRc9EX+sHHaTOWXDebFzL4aJEPn1XA0hQ5zzK5PZyL6l1v+qiz16o4hO4PlRaW5FmNndjCJ3yREalIZBp6a9PCdNw9K4LPcPQ1ZYjxx6bn1SWXbRodKpdSQqLlzKeUNjH0Aro6+TB8= abai@unused-10-15-17-19.yyz.redhat.com"
]
}
]
},
"storage": {},
"systemd": {
"units": [
{
"dropins": [
{
"contents": "[Service]\nTTYVTDisallocate=no\nExecStart=\nExecStart=-/usr/sbin/agetty --autologin core --noclear %I $TERM",
"name": "autologin.conf"
}
],
"name": "serial-getty@ttyS0.service"
}
]
}
}
EOF
}
test_installer() {
# set -x
local version="30.20190905.dev.2"
local metal_img_gz="fedora-coreos-${version}-metal.raw.gz"
local metal_img="fedora-coreos-${version}-metal.raw"
local installer_iso="fedora-coreos-${version}-installer.iso"
# local installer_iso=$(ls ${LATEST_BUILD} | grep ".*installer\.iso$")
rm -f ${PWD}/fcos.qcow2 ${LATEST_BUILD}/metal.raw.gz ${LATEST_BUILD}/${metal_img} ${LATEST_BUILD}/${metal_img_gz}
rm -f ${LATEST_BUILD}/${installer_iso}
base_ign
cosa buildextend-metal
cosa buildextend-installer --force
gzip ${LATEST_BUILD}/${metal_img}
mv ${LATEST_BUILD}/${metal_img_gz} ${LATEST_BUILD}/metal.raw.gz
qemu-img create -f qcow2 fcos.qcow2 10G
qemu-system-x86_64 -nographic -accel kvm -name fcos -m 2048 -cpu host -smp 2 -netdev user,id=eth0,hostname=coreos \
-device virtio-net-pci,netdev=eth0 -drive file=${PWD}/fcos.qcow2,format=qcow2 \
-cdrom ${LATEST_BUILD}/${installer_iso}
# virt-install --name cdrom --ram 4500 --vcpus 2 --disk size=20 --accelerate --cdrom ./builds/latest/x86_64/fedora-coreos-30.20190905.dev.1-installer.iso --network default
set +x
}
test_ignition_dracut() {
set -x
if [ ! -d ../fedora-rpm/ignition ]; then
mkdir -p ../fedora-rpm
git clone https://src.fedoraproject.org/rpms/ignition.git
echo "ignition rpm repo cloned, please modify first!"
exit 1
fi
cd ../fedora-rpm/ignition
spectool -g ignition.spec
sudo dnf -y builddep ignition.spec
fedpkg local
cd -
rm -rf overrides/rpm/*
cp ../fedora-rpm/ignition/x86_64/* overrides/rpm/
cosa build --force-nocache
cosa run
}
test_pinger_systemd() {
set -x
rm -rf ${PWD}/overrides/rootfs
mkdir -p ${PWD}/overrides/rootfs/lib/systemd/system/
mkdir -p ${PWD}/overrides/rootfs/usr/libexec/
mkdir -p ${PWD}/overrides/rootfs/etc/fedora-coreos-pinger/config.d/
cp $COREOS_PINGER/dist/systemd/fedora-coreos-pinger.service ${PWD}/overrides/rootfs/lib/systemd/system/fedora-coreos-pinger.service
cp $COREOS_PINGER/target/debug/fedora-coreos-pinger ${PWD}/overrides/rootfs/usr/libexec/fedora-coreos-pinger
cat > ${PWD}/overrides/rootfs/etc/fedora-coreos-pinger/config.d/99-enable-on-dev.toml <<EOF
# /usr/lib/fedora-coreos-pinger/config.d/10-default-enable.toml
# fedora-coreos-pinger configuration
[collecting]
# Default collecting.level is minimal. May be set to "minimal" or "full".
level = "full"
[reporting]
# Required. May be set to `true` or `false`.
enabled = true
EOF
set +x
}
print_help(){
cecho "GREEN"\
"options:\n\
-c | --clean-dir: rm whole dir except auto-cosa\n\
-i | --init: cosa init\n\
-f | --fetch: cosa fetch\n\
-b | --build: cosa build\n\
-r | --run: cosa run\n\
--clean: cosa clean\n\
--cp-installer: cp installer to overrides/rootfs\n\
--base-ign: build base.ign in builds/latest/base.ign\n\
--test-installer: clean install fcos using bare metal and installer iso\n\
--test-ignition-dracut: build ignition rpm && cosa build && cosa run\n\
--pinger: mount fedora-coreos-pinger/target\n\
--shell: log into the vm shell"
exit 1
}
if [[ "$#" -eq 0 ]]; then
print_help
fi
# Call getopt to validate the provided input.
rc=0
options=$(getopt --options=hcifbr --longoptions=help,clean-dir,init,fetch,build,run,clean,cp-installer,base-ign,test-installer,test-ignition-dracut,pinger,shell,pinger-systemd -- "$@") || rc=$?
[ $rc -eq 0 ] || {
print_help
exit 1
}
eval set -- "$options"
while true; do
case "$1" in
-e | --env)
setup_env
;;
-h | --help)
print_help
;;
-c | --clean-dir)
shopt -s extglob
$(rm -rf !(auto-cosa))
;;
-i | --init)
cosa init --force https://github.com/coreos/fedora-coreos-config
;;
-f | --fetch)
cosa fetch
;;
-b | --build)
cosa build
;;
-r | --run)
cosa run
;;
--pinger-systemd)
test_pinger_systemd
cosa build
;;
--pinger)
cosa run --srv /fedora-coreos-pinger
;;
--clean)
cosa clean
;;
--cp-installer)
cp_installer
;;
--base-ign)
base_ign
;;
--test-installer)
test_installer
;;
--test-ignition-dracut)
test_ignition_dracut
;;
--shell)
cosa shell
;;
--)
shift
break
;;
-*)
cecho "RED" "$0: unrecognized option: $1"
exit 1
;;
*)
break
;;
esac
shift
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment