def test_init_params(test_microvm_with_api):
    """Correct propagation of boot args to the kernel's command line.

    Test that init's parameters (the ones present after "--") do not get
    altered or misplaced.

    @type: negative
    """
    vm = test_microvm_with_api
    vm.jailer.daemonize = False
    vm.spawn()
    vm.memory_monitor = None

    # We will override the init with /bin/cat so that we try to read the
    # Ubuntu version from the /etc/issue file.
    vm.basic_config(
        vcpu_count=1,
        boot_args="console=ttyS0 reboot=k panic=1 pci=off"
        " init=/bin/cat -- /etc/issue",
    )

    vm.start()
    serial = Serial(vm)
    serial.open()
    # If the string does not show up, the test will fail.
    serial.rx(token="Ubuntu 18.04.5 LTS")
Example #2
0
def test_microvm_initrd_with_serial(test_microvm_with_initrd):
    """
    Test that a boot using initrd successfully loads the root filesystem.

    @type: functional
    """
    vm = test_microvm_with_initrd
    vm.jailer.daemonize = False
    vm.spawn()
    vm.memory_monitor = None

    vm.basic_config(add_root_device=False,
                    vcpu_count=1,
                    boot_args='console=ttyS0 reboot=k panic=1 pci=off',
                    use_initrd=True)

    vm.start()
    serial = Serial(vm)
    serial.open()
    serial.rx(token='login: '******'Password: '******'# ')

    serial.tx("findmnt /")
    serial.rx(token=f"/      {INITRD_FILESYSTEM} {INITRD_FILESYSTEM}")
Example #3
0
def test_microvm_initrd_with_serial(
        test_microvm_with_initrd):
    """Check microvm started with an inird has / mounted as rootfs."""
    vm = test_microvm_with_initrd
    vm.jailer.daemonize = False
    vm.spawn()
    vm.memory_monitor = None

    vm.basic_config(
        add_root_device=False,
        vcpu_count=1,
        boot_args='console=ttyS0 reboot=k panic=1 pci=off',
        use_initrd=True
    )

    vm.start()
    serial = Serial(vm)
    serial.open()
    serial.rx(token='login: '******'Password: '******'# ')

    serial.tx("findmnt /")
    serial.rx(
        token=f"/      {INITRD_FILESYSTEM} {INITRD_FILESYSTEM}")
Example #4
0
def test_serial_after_snapshot(bin_cloner_path):
    """
    Serial I/O after restoring from a snapshot.

    @type: functional
    """
    vm_builder = MicrovmBuilder(bin_cloner_path)
    vm_instance = vm_builder.build_vm_nano(
        diff_snapshots=False,
        daemonize=False,
    )
    microvm = vm_instance.vm
    root_disk = vm_instance.disks[0]
    ssh_key = vm_instance.ssh_key

    microvm.start()
    serial = Serial(microvm)
    serial.open()

    # Image used for tests on aarch64 has autologon
    if platform.machine() == "x86_64":
        serial.rx(token="login: "******"root")
        serial.rx("Password: "******"root")
    # Make sure that at the time we snapshot the vm, the user is logged in.
    serial.rx("#")

    snapshot_builder = SnapshotBuilder(microvm)
    disks = [root_disk.local_path()]
    # Create diff snapshot.
    snapshot = snapshot_builder.create(disks, ssh_key, SnapshotType.FULL)
    # Kill base microVM.
    microvm.kill()

    # Load microVM clone from snapshot.
    test_microvm, _ = vm_builder.build_from_snapshot(snapshot,
                                                     resume=True,
                                                     diff_snapshots=False,
                                                     daemonize=False)
    serial = Serial(test_microvm)
    serial.open()
    # We need to send a newline to signal the serial to flush
    # the login content.
    serial.tx("")
    serial.rx("#")
    serial.tx("pwd")
    res = serial.rx("#")
    assert "/root" in res