Otherwise, the `else` case will trigger a failure, creating a log that looks like this: 2024-10-28T22:17:14.9503517Z 22:17:14 respirate.1 | {"strand":{"id":"0192d531-ec76-8f3a-9ee1-58b64e8681b4","parent_id":null,"schedule":"2024-10-28 22:17:08 +0000","lease":"2024-10-28 22:19:07 +0000","prog":"Test::Vm","label":"failed","stack":[{"link":["Test::VmGroup","verify_vms"],"subject_id":"58b27234-2601-8f74-8f76-5b35f625135e","last_label_changed_at":"2024-10-28 22:17:14 +0000"},{"vms":["58b27234-2601-8f74-8f76-5b35f625135e","d66e75c7-d28e-8374-81e6-2d1327508a33","7cfb89be-ba0e-8374-843d-71d775e3cf08"],"subnets":["6c09c1ac-c39f-8ad9-b8d1-fd0f707cf9ae","178597d1-2e89-86d9-ae8f-22868f01ec3c"],"project_id":"a0a6365a-fc07-8ad2-92e3-41948e3e801e","test_reboot":true,"storage_encrypted":true,"last_label_changed_at":"2024-10-28 22:17:06 +0000"}],"exitval":{"msg":"unexpected boot image: debian-12"},"retval":null,"try":0},"strand_started":{"prog_label":"Test::Vm.failed"},"message":"starting strand","time":"2024-10-28 22:17:14 +0000","thread":"st069dacfcet7kvgnhdjegt0v8"} 2024-10-28T22:17:21.9881320Z 22:17:21 e2e.1 | 2024-10-28T22:17:21Z | 0192d531-ec76-8f3a-9ee1-58b64e8681b4 | Test::Vm.failed | FAILED: unexpected boot image: debian-12 | Vm.wait 2024-10-28T22:17:22.5582252Z 22:17:22 e2e.1 | exited with code 1 2024-10-28T22:17:22.5584121Z 22:17:22 system | sending SIGTERM to all processes 2024-10-28T22:17:22.9722774Z 22:17:22 web.1 | terminated by SIGTERM 2024-10-28T22:17:22.9724525Z 22:17:22 respirate.1 | terminated by SIGTERM 2024-10-28T22:17:22.9726165Z 22:17:22 monitor.1 | terminated by SIGTERM 2024-10-28T22:17:22.9763138Z ##[error]Process completed with exit code 1.
123 lines
3.3 KiB
Ruby
123 lines
3.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Prog::Test::Vm < Prog::Test::Base
|
|
subject_is :vm, :sshable
|
|
|
|
label def start
|
|
hop_verify_dd
|
|
end
|
|
|
|
label def verify_dd
|
|
# Verifies basic block device health
|
|
# See https://github.com/ubicloud/ubicloud/issues/276
|
|
sshable.cmd("dd if=/dev/urandom of=~/1.txt bs=512 count=1000000")
|
|
sshable.cmd("sync ~/1.txt")
|
|
size_info = sshable.cmd("ls -s ~/1.txt").split
|
|
|
|
unless size_info[0].to_i.between?(500000, 500100)
|
|
fail_test "unexpected size after dd"
|
|
end
|
|
|
|
hop_install_packages
|
|
end
|
|
|
|
label def install_packages
|
|
if /ubuntu|debian/.match?(vm.boot_image)
|
|
sshable.cmd("sudo apt update")
|
|
sshable.cmd("sudo apt install -y build-essential")
|
|
elsif vm.boot_image.start_with?("almalinux")
|
|
sshable.cmd("sudo dnf check-update || [ $? -eq 100 ]")
|
|
sshable.cmd("sudo dnf install -y gcc gcc-c++ make")
|
|
else
|
|
fail_test "unexpected boot image: #{vm.boot_image}"
|
|
end
|
|
|
|
hop_verify_extra_disks
|
|
end
|
|
|
|
label def verify_extra_disks
|
|
vm.vm_storage_volumes[1..].each_with_index { |volume, disk_index|
|
|
mount_path = "/home/ubi/mnt#{disk_index}"
|
|
sshable.cmd("mkdir -p #{mount_path}")
|
|
sshable.cmd("sudo mkfs.ext4 #{volume.device_path.shellescape}")
|
|
sshable.cmd("sudo mount #{volume.device_path.shellescape} #{mount_path}")
|
|
sshable.cmd("sudo chown ubi #{mount_path}")
|
|
sshable.cmd("dd if=/dev/urandom of=#{mount_path}/1.txt bs=512 count=10000")
|
|
sshable.cmd("sync #{mount_path}/1.txt")
|
|
}
|
|
|
|
hop_ping_google
|
|
end
|
|
|
|
label def ping_google
|
|
sshable.cmd("ping -c 2 google.com")
|
|
hop_ping_vms_in_subnet
|
|
end
|
|
|
|
label def ping_vms_in_subnet
|
|
vms_with_same_subnet.each { |x|
|
|
# ping public IPs
|
|
sshable.cmd("ping -c 2 #{x.ephemeral_net4}")
|
|
sshable.cmd("ping -c 2 #{x.ephemeral_net6.nth(2)}")
|
|
|
|
# ping private IPs
|
|
nic = x.nics.first
|
|
private_ip6 = nic.private_ipv6.nth(2).to_s
|
|
private_ip4 = nic.private_ipv4.network.to_s
|
|
sshable.cmd("ping -c 2 #{private_ip6}")
|
|
sshable.cmd("ping -c 2 #{private_ip4}")
|
|
}
|
|
|
|
hop_ping_vms_not_in_subnet
|
|
end
|
|
|
|
label def ping_vms_not_in_subnet
|
|
vms_with_different_subnet.each { |x|
|
|
# ping public IPs should work
|
|
sshable.cmd("ping -c 2 #{x.ephemeral_net4}")
|
|
sshable.cmd("ping -c 2 #{x.ephemeral_net6.nth(2)}")
|
|
|
|
# ping private IPs shouldn't work
|
|
nic = x.nics.first
|
|
private_ip6 = nic.private_ipv6.nth(2).to_s
|
|
private_ip4 = nic.private_ipv4.network.to_s
|
|
|
|
begin
|
|
sshable.cmd("ping -c 2 #{private_ip6}")
|
|
rescue Sshable::SshError
|
|
else
|
|
raise "Unexpected successful ping to private ip6 of a vm in different subnet"
|
|
end
|
|
|
|
begin
|
|
sshable.cmd("ping -c 2 #{private_ip4}")
|
|
rescue Sshable::SshError
|
|
else
|
|
raise "Unexpected successful ping to private ip4 of a vm in different subnet"
|
|
end
|
|
}
|
|
|
|
hop_finish
|
|
end
|
|
|
|
label def finish
|
|
pop "Verified VM!"
|
|
end
|
|
|
|
label def failed
|
|
nap 15
|
|
end
|
|
|
|
def vms_in_same_project
|
|
vm.projects.first.vms.filter { _1.id != vm.id }
|
|
end
|
|
|
|
def vms_with_same_subnet
|
|
vms_in_same_project.filter { _1.private_subnets.first.id == vm.private_subnets.first.id }
|
|
end
|
|
|
|
def vms_with_different_subnet
|
|
vms_in_same_project.filter { _1.private_subnets.first.id != vm.private_subnets.first.id }
|
|
end
|
|
end
|