Exemplo n.º 1
0
def start_qemu():
    # Relies on the meta-mender layer being next to meta-mender-qemu.
    proc = subprocess.Popen("../../../meta-mender/scripts/mender-qemu")
    # Make sure we are connected.
    execute(run_after_connect, "true", hosts = conftest.current_hosts())
    execute(qemu_prep_after_boot, hosts = conftest.current_hosts())
    return proc
Exemplo n.º 2
0
def start_qemu():
    # Relies on the meta-mender layer being next to meta-mender-qemu.
    proc = subprocess.Popen("../../../meta-mender/scripts/mender-qemu")
    # Make sure we are connected.
    execute(run_after_connect, "true", hosts = conftest.current_hosts())
    execute(qemu_prep_after_boot, hosts = conftest.current_hosts())
    return proc
Exemplo n.º 3
0
    def qemu_finalizer():
        def qemu_finalizer_impl():
            try:
                manual_uboot_commit()
                run("halt")
                halt_time = time.time()
                # Wait up to 30 seconds for shutdown.
                while halt_time + 30 > time.time() and qemu.poll() is None:
                    time.sleep(1)
            except:
                # Nothing we can do about that.
                pass

            # kill qemu
            try:
                qemu.terminate()
            except OSError as oserr:
                # qemu might have exited before we reached this place
                if oserr.errno == errno.ESRCH:
                    pass
                else:
                    raise

            qemu.wait()
            os.remove(img_path)

        execute(qemu_finalizer_impl, hosts=conftest.current_hosts())
Exemplo n.º 4
0
def setup_colibri_imx7(request, clean_image):
    latest_uboot = latest_build_artifact(clean_image['build_dir'],
                                         "u-boot-nand.imx")
    latest_ubimg = latest_build_artifact(clean_image['build_dir'], ".ubimg")

    if not latest_uboot:
        pytest.fail('failed to find U-Boot binary')

    if not latest_ubimg:
        pytest.failed('failed to find latest ubimg for the board')

    def board_setup():
        common_board_setup(files=[latest_ubimg, latest_uboot],
                           remote_path='/tmp',
                           image_file=os.path.basename(latest_ubimg))

    execute(board_setup, hosts=conftest.current_hosts())

    def board_cleanup():
        def board_cleanup_impl():
            common_board_cleanup()

        execute(board_cleanup_impl, hosts=conftest.current_hosts())

    request.addfinalizer(board_cleanup)
Exemplo n.º 5
0
def qemu_running(request, latest_sdimg):
    if pytest.config.getoption("--bbb"):
        return

    kill_qemu()

    # Make sure we revert to the first root partition on next reboot, makes test
    # cases more predictable.
    def qemu_finalizer():
        def qemu_finalizer_impl():
            try:
                manual_uboot_commit()
                sudo("halt")
                halt_time = time.time()
                # Wait up to 30 seconds for shutdown.
                while halt_time + 30 > time.time() and is_qemu_running():
                    time.sleep(1)
            except:
                # Nothing we can do about that.
                pass
            kill_qemu()

        execute(qemu_finalizer_impl, hosts=conftest.current_hosts())

    request.addfinalizer(qemu_finalizer)

    start_qemu(latest_sdimg)
    execute(qemu_prep_fresh_host, hosts=conftest.current_hosts())
Exemplo n.º 6
0
    def qemu_finalizer():
        def qemu_finalizer_impl():
            try:
                manual_uboot_commit()
                run("halt")
                halt_time = time.time()
                # Wait up to 30 seconds for shutdown.
                while halt_time + 30 > time.time() and qemu.poll() is None:
                    time.sleep(1)
            except:
                # Nothing we can do about that.
                pass

            # kill qemu
            try:
                qemu.terminate()
            except OSError as oserr:
                # qemu might have exited before we reached this place
                if oserr.errno == errno.ESRCH:
                    pass
                else:
                    raise

            qemu.wait()
            os.remove(img_path)

        execute(qemu_finalizer_impl, hosts=conftest.current_hosts())
Exemplo n.º 7
0
def qemu_running(request):
    kill_qemu()

    # Make sure we revert to the first root partition on next reboot, makes test
    # cases more predictable.
    def qemu_finalizer():
        def qemu_finalizer_impl():
            try:
                sudo("fw_setenv upgrade_available 0")
                sudo("fw_setenv boot_part 2")
                sudo("fw_setenv bootcount 0")
                sudo("halt")
                halt_time = time.time()
                # Wait up to 30 seconds for shutdown.
                while halt_time + 30 > time.time() and is_qemu_running():
                    time.sleep(1)
            except:
                # Nothing we can do about that.
                pass
            kill_qemu()
        execute(qemu_finalizer_impl, hosts = conftest.current_hosts())

    request.addfinalizer(qemu_finalizer)

    start_qemu()
    execute(qemu_prep_fresh_host, hosts = conftest.current_hosts())
Exemplo n.º 8
0
def qemu_running(request):
    if pytest.config.getoption("--bbb"):
        return

    kill_qemu()

    # Make sure we revert to the first root partition on next reboot, makes test
    # cases more predictable.
    def qemu_finalizer():
        def qemu_finalizer_impl():
            try:
                set_first_root_part()
                sudo("halt")
                halt_time = time.time()
                # Wait up to 30 seconds for shutdown.
                while halt_time + 30 > time.time() and is_qemu_running():
                    time.sleep(1)
            except:
                # Nothing we can do about that.
                pass
            kill_qemu()
        execute(qemu_finalizer_impl, hosts=conftest.current_hosts())

    request.addfinalizer(qemu_finalizer)

    start_qemu()
    execute(qemu_prep_fresh_host, hosts=conftest.current_hosts())
Exemplo n.º 9
0
def setup_bbb(request):
    if pytest.config.getoption("--bbb"):
        execute(boot_from_internal)
        execute(setup_bbb_sdcard, host=conftest.current_hosts())

        def bbb_finalizer():
            def bbb_finalizer_impl():
                    execute(boot_from_internal)
            execute(bbb_finalizer_impl, hosts=conftest.current_hosts())

        request.addfinalizer(bbb_finalizer)
Exemplo n.º 10
0
def setup_bbb(request):
    if pytest.config.getoption("--bbb"):
        execute(boot_from_internal)
        execute(setup_bbb_sdcard, host=conftest.current_hosts())

        def bbb_finalizer():
            def bbb_finalizer_impl():
                    execute(boot_from_internal)
            execute(bbb_finalizer_impl, hosts=conftest.current_hosts())

        request.addfinalizer(bbb_finalizer)
Exemplo n.º 11
0
def start_qemu(latest_sdimg):
    if pytest.config.getoption("bbb"):
        return

    # Make a disposable image.
    try:
        qemu_img = os.environ["QEMU_SYSTEM_ARM"]
    except:
        qemu_img = "qemu-system-arm"
    qemu_img = re.sub("-system-arm$", "-img", qemu_img)
    subprocess.check_call([
        qemu_img, "create", "-f", "qcow2", "-o",
        "backing_file=%s" % latest_sdimg, "test-image.qcow2"
    ])

    os.environ["VEXPRESS_SDIMG"] = "test-image.qcow2"
    proc = subprocess.Popen("../../meta-mender-qemu/scripts/mender-qemu")
    # Make sure we are connected.
    execute(run_after_connect, "true", hosts=conftest.current_hosts())
    execute(qemu_prep_after_boot, hosts=conftest.current_hosts())
    return proc
Exemplo n.º 12
0
def qemu_running(request, clean_image):
    if pytest.config.getoption("--bbb"):
        return

    latest_sdimg = latest_build_artifact(clean_image['build_dir'], ".sdimg")
    latest_vexpress_nor = latest_build_artifact(clean_image['build_dir'],
                                                ".vexpress-nor")

    print("sdimg: {} vexpress-nor: {}".format(latest_sdimg,
                                              latest_vexpress_nor))

    if latest_sdimg:
        qemu, img_path = start_qemu_sdimg(latest_sdimg)
    elif latest_vexpress_nor:
        qemu, img_path = start_qemu_flash(latest_vexpress_nor)
    else:
        pytest.fail("cannot find a suitable image type")

    print("qemu started with pid {}, image {}".format(qemu.pid, img_path))

    # Make sure we revert to the first root partition on next reboot, makes test
    # cases more predictable.
    def qemu_finalizer():
        def qemu_finalizer_impl():
            try:
                manual_uboot_commit()
                run("halt")
                halt_time = time.time()
                # Wait up to 30 seconds for shutdown.
                while halt_time + 30 > time.time() and qemu.poll() is None:
                    time.sleep(1)
            except:
                # Nothing we can do about that.
                pass

            # kill qemu
            try:
                qemu.terminate()
            except OSError as oserr:
                # qemu might have exited before we reached this place
                if oserr.errno == errno.ESRCH:
                    pass
                else:
                    raise

            qemu.wait()
            os.remove(img_path)

        execute(qemu_finalizer_impl, hosts=conftest.current_hosts())

    request.addfinalizer(qemu_finalizer)

    execute(qemu_prep_fresh_host, hosts=conftest.current_hosts())
Exemplo n.º 13
0
def qemu_running(request, clean_image):
    if pytest.config.getoption("--bbb"):
        return

    latest_sdimg = latest_build_artifact(clean_image['build_dir'], ".sdimg")
    latest_vexpress_nor = latest_build_artifact(clean_image['build_dir'], ".vexpress-nor")

    print("sdimg: {} vexpress-nor: {}".format(latest_sdimg, latest_vexpress_nor))

    if latest_sdimg:
        qemu, img_path = start_qemu_sdimg(latest_sdimg)
    elif latest_vexpress_nor:
        qemu, img_path = start_qemu_flash(latest_vexpress_nor)
    else:
        pytest.fail("cannot find a suitable image type")

    print("qemu started with pid {}, image {}".format(qemu.pid, img_path))

    # Make sure we revert to the first root partition on next reboot, makes test
    # cases more predictable.
    def qemu_finalizer():
        def qemu_finalizer_impl():
            try:
                manual_uboot_commit()
                run("halt")
                halt_time = time.time()
                # Wait up to 30 seconds for shutdown.
                while halt_time + 30 > time.time() and qemu.poll() is None:
                    time.sleep(1)
            except:
                # Nothing we can do about that.
                pass

            # kill qemu
            try:
                qemu.terminate()
            except OSError as oserr:
                # qemu might have exited before we reached this place
                if oserr.errno == errno.ESRCH:
                    pass
                else:
                    raise

            qemu.wait()
            os.remove(img_path)

        execute(qemu_finalizer_impl, hosts=conftest.current_hosts())

    request.addfinalizer(qemu_finalizer)

    execute(qemu_prep_fresh_host, hosts=conftest.current_hosts())
Exemplo n.º 14
0
def start_qemu(qenv=None):
    """Start qemu and return a subprocess.Popen object corresponding to a running
    qemu process. `qenv` is a dict of environment variables that will be added
    to `subprocess.Popen(..,env=)`.

    Once qemu is stated, a connection over ssh will attempted, so the returned
    process is actually a qemu instance with fully booted guest os.

    The helper uses `meta-mender-qemu/scripts/mender-qemu` to start qemu, thus
    you can use `VEXPRESS_IMG`, `QEMU_DRIVE` and other environment variables to
    override the default behavior.

    """
    env = dict(os.environ)
    if qenv:
        env.update(qenv)

    proc = subprocess.Popen(["../../meta-mender-qemu/scripts/mender-qemu", "-snapshot"],
                            env=env)

    try:
        # make sure we are connected.
        execute(run_after_connect, "true", hosts = conftest.current_hosts())
        execute(qemu_prep_after_boot, hosts = conftest.current_hosts())
    except:
        # or do the necessary cleanup if we're not
        try:
            # qemu might have exited and this would raise an exception
            print('cleaning up qemu instance with pid {}'.format(proc.pid))
            proc.kill()
        except:
            pass

        proc.wait()

        raise

    return proc
Exemplo n.º 15
0
def start_qemu(qenv=None):
    """Start qemu and return a subprocess.Popen object corresponding to a running
    qemu process. `qenv` is a dict of environment variables that will be added
    to `subprocess.Popen(..,env=)`.

    Once qemu is stated, a connection over ssh will attempted, so the returned
    process is actually a qemu instance with fully booted guest os.

    The helper uses `meta-mender-qemu/scripts/mender-qemu` to start qemu, thus
    you can use `VEXPRESS_IMG`, `QEMU_DRIVE` and other environment variables to
    override the default behavior.

    """
    env = dict(os.environ)
    if qenv:
        env.update(qenv)

    proc = subprocess.Popen(
        ["../../meta-mender-qemu/scripts/mender-qemu", "-snapshot"], env=env)

    try:
        # make sure we are connected.
        execute(run_after_connect, "true", hosts=conftest.current_hosts())
        execute(qemu_prep_after_boot, hosts=conftest.current_hosts())
    except:
        # or do the necessary cleanup if we're not
        try:
            # qemu might have exited and this would raise an exception
            print('cleaning up qemu instance with pid {}'.format(proc.pid))
            proc.kill()
        except:
            pass

        proc.wait()

        raise

    return proc
Exemplo n.º 16
0
 def qemu_finalizer():
     def qemu_finalizer_impl():
         try:
             set_first_root_part()
             sudo("halt")
             halt_time = time.time()
             # Wait up to 30 seconds for shutdown.
             while halt_time + 30 > time.time() and is_qemu_running():
                 time.sleep(1)
         except:
             # Nothing we can do about that.
             pass
         kill_qemu()
     execute(qemu_finalizer_impl, hosts=conftest.current_hosts())
Exemplo n.º 17
0
 def qemu_finalizer():
     def qemu_finalizer_impl():
         try:
             set_first_root_part()
             sudo("halt")
             halt_time = time.time()
             # Wait up to 30 seconds for shutdown.
             while halt_time + 30 > time.time() and is_qemu_running():
                 time.sleep(1)
         except:
             # Nothing we can do about that.
             pass
         kill_qemu()
     execute(qemu_finalizer_impl, hosts=conftest.current_hosts())
Exemplo n.º 18
0
 def qemu_finalizer():
     def qemu_finalizer_impl():
         try:
             sudo("fw_setenv upgrade_available 0")
             sudo("fw_setenv boot_part 2")
             sudo("fw_setenv bootcount 0")
             sudo("halt")
             halt_time = time.time()
             # Wait up to 30 seconds for shutdown.
             while halt_time + 30 > time.time() and is_qemu_running():
                 time.sleep(1)
         except:
             # Nothing we can do about that.
             pass
         kill_qemu()
     execute(qemu_finalizer_impl, hosts = conftest.current_hosts())
Exemplo n.º 19
0
def setup_colibri_imx7(request, clean_image):
    latest_uboot = latest_build_artifact(clean_image['build_dir'], "u-boot-nand.imx")
    latest_ubimg = latest_build_artifact(clean_image['build_dir'], ".ubimg")

    if not latest_uboot:
        pytest.fail('failed to find U-Boot binary')

    if not latest_ubimg:
        pytest.failed('failed to find latest ubimg for the board')

    def board_setup():
        common_board_setup(files=[latest_ubimg, latest_uboot],
                           remote_path='/tmp',
                           image_file=os.path.basename(latest_ubimg))

    execute(board_setup, hosts=conftest.current_hosts())

    def board_cleanup():
        def board_cleanup_impl():
            common_board_cleanup()
        execute(board_cleanup_impl, hosts=conftest.current_hosts())

    request.addfinalizer(board_cleanup)
Exemplo n.º 20
0
 def bbb_finalizer():
     def bbb_finalizer_impl():
             execute(boot_from_internal)
     execute(bbb_finalizer_impl, hosts=conftest.current_hosts())
Exemplo n.º 21
0
 def board_cleanup():
     def board_cleanup_impl():
         common_board_cleanup()
     execute(board_cleanup_impl, hosts=conftest.current_hosts())
Exemplo n.º 22
0
def no_image_file(setup_board):
    """Make sure 'image.dat' is not present on the device."""
    execute(no_image_file_impl, hosts=conftest.current_hosts())
Exemplo n.º 23
0
def no_image_file(qemu_running):
    execute(no_image_file_impl, hosts=conftest.current_hosts())
Exemplo n.º 24
0
 def board_cleanup():
     execute(common_board_cleanup, hosts=conftest.current_hosts())
Exemplo n.º 25
0
def setup_rpi3(request):
    def board_cleanup():
        execute(common_board_cleanup, hosts=conftest.current_hosts())

    execute(common_boot_from_internal, hosts=conftest.current_hosts())
    request.addfinalizer(board_cleanup)
Exemplo n.º 26
0
    def board_cleanup():
        def board_cleanup_impl():
            common_board_cleanup()

        execute(board_cleanup_impl, hosts=conftest.current_hosts())
Exemplo n.º 27
0
        def bbb_finalizer():
            def bbb_finalizer_impl():
                execute(boot_from_internal)

            execute(bbb_finalizer_impl, hosts=conftest.current_hosts())
Exemplo n.º 28
0
def common_board_cleanup():
    sudo("mender-qa activate-test-image off")
    with settings(warn_only=True):
        sudo("reboot")

    execute(run_after_connect, "true", hosts=conftest.current_hosts())
Exemplo n.º 29
0
def no_image_file(qemu_running):
    """Make sure 'image.dat' is not present on the device."""
    execute(no_image_file_impl, hosts=conftest.current_hosts())
Exemplo n.º 30
0
def no_image_file(setup_board):
    """Make sure 'image.dat' is not present on the device."""
    execute(no_image_file_impl, hosts=conftest.current_hosts())
Exemplo n.º 31
0
def no_image_file(qemu_running):
    execute(no_image_file_impl, hosts=conftest.current_hosts())
Exemplo n.º 32
0
def common_boot_from_internal():
    sudo("mender-qa activate-test-image on")
    with settings(warn_only=True):
        sudo("reboot")

    execute(run_after_connect, "true", hosts=conftest.current_hosts())
Exemplo n.º 33
0
def no_image_file(qemu_running):
    """Make sure 'image.dat' is not present on the device."""
    execute(no_image_file_impl, hosts=conftest.current_hosts())