X-Git-Url: https://git.grml.org/?p=grml-debootstrap.git;a=blobdiff_plain;f=packer%2Fdebian64.bats;fp=packer%2Fdebian64.bats;h=a67716836b50d6319c0fff5762f927de92b32caf;hp=0000000000000000000000000000000000000000;hb=7fc0e06e6bb818dd8410e8dc2341da015121203a;hpb=1081c44c4f6368490481c4c5b48281f3846cbed1 diff --git a/packer/debian64.bats b/packer/debian64.bats new file mode 100644 index 0000000..a677168 --- /dev/null +++ b/packer/debian64.bats @@ -0,0 +1,95 @@ +#!/usr/bin/env bats + +# config +mountpath="/mnt" +device="/dev/sda" +disk="${device}1" + +setup() { + mountpoint "$mountpath" &>/dev/null || mount "$disk" "$mountpath" +} + +teardown() { + mountpoint "$mountpath" &>/dev/null && umount "$mountpath" +} + +# tests +@test "debian_version exists" { + run cat "${mountpath}/etc/debian_version" + [ "$status" -eq 0 ] + [[ "$output" == [0-9].[0-9] ]] +} + +@test "kernel exists" { + run ls "${mountpath}"/boot/vmlinuz-* + [ "$status" -eq 0 ] + [[ "$output" =~ ${mountpath}/boot/vmlinuz-* ]] +} + +@test "initrd exists" { + run ls "${mountpath}"/boot/initrd.img-* + [ "$status" -eq 0 ] + [[ "$output" =~ ${mountpath}/boot/initrd.img-* ]] +} + +@test "grub-pc installed" { + run chroot $mountpath dpkg-query --show --showformat='${Status}' grub-pc + [ "$status" -eq 0 ] + [[ "$output" == "install ok installed" ]] +} + +@test "ext3/ext4 filesystem" { + fstype=$(blkid -o udev ${disk} | grep '^ID_FS_TYPE=') + run echo $fstype + [ "$status" -eq 0 ] + [[ $output =~ ID_FS_TYPE=ext[34] ]] +} + +@test "partition table" { + table_info=$(parted -s ${device} 'unit s print' | grep -A1 '^Number.*Start.*End' | tail -1) + regex='1 2048s.*primary ext[34] boot' + run echo $table_info + echo "debug: table_info = $table_info" + echo "debug: output = $output" + [[ $output =~ $regex ]] +} + +@test "tune2fs mount count setting" { + mount_count=$(tune2fs -l "$disk" | grep "^Maximum mount count:") + run echo "$mount_count" + [[ "$output" == "Maximum mount count: -1" ]] +} + +@test "kernel entry in grub config" { + run grep "Debian GNU/Linux, with Linux" "${mountpath}/boot/grub/grub.cfg" + [ "$status" -eq 0 ] +} + +@test "vim package is installed" { + run chroot "$mountpath" dpkg --list vim + [ "$status" -eq 0 ] +} + +@test "home directory for user vagrant" { + run ls -d "$mountpath"/home/vagrant + [ "$status" -eq 0 ] +} + +@test "home directory for user vagrant" { + run grep -q ssh-rsa "$mountpath"/home/vagrant/.ssh/authorized_keys + [ "$status" -eq 0 ] +} + +@test "sudo setup for user vagrant" { + run grep -q '^vagrant ALL=(ALL) NOPASSWD: ALL' "${mountpath}/etc/sudoers.d/vagrant" + [ "$status" -eq 0 ] +} + +@test "check for GRUB in MBR" { + regex='^00000180.*GRUB.*' + grub_string=$(dd if=${device} bs=512 count=1 2>/dev/null | hexdump -C | egrep "$regex") + run echo "$grub_string" + echo "debug: grub_string = $grub_string" + echo "debug: output = $output" + [[ $output =~ $regex ]] +}