Ejemplo n.º 1
0
def test_append_overlays_update_guestfs(caplog, mocker, tmpdir):
    caplog.set_level(logging.DEBUG)
    params = {
        "format": "ext4",
        "overlays": {
            "modules": {
                "url": "http://example.com/modules.tar.xz",
                "compression": "xz",
                "format": "tar",
                "path": "/lib",
            }
        },
    }

    action = AppendOverlays("rootfs", params)
    action.job = Job(1234, {}, None)
    action.parameters = {
        "rootfs": {
            "url": "http://example.com/rootff.ext4",
            **params
        },
        "namespace": "common",
    }
    action.data = {
        "common": {
            "download-action": {
                "rootfs": {
                    "file": str(tmpdir / "rootfs.ext4"),
                    "compression": "gz",
                    "decompressed": True,
                },
                "rootfs.modules": {
                    "file": str(tmpdir / "modules.tar")
                },
            }
        }
    }

    guestfs = mocker.MagicMock()
    guestfs.add_drive = mocker.MagicMock()
    mocker.patch(
        "lava_dispatcher.actions.deploy.apply_overlay.guestfs.GuestFS",
        guestfs)
    action.update_guestfs()

    guestfs.assert_called_once_with(python_return_dict=True)
    guestfs().launch.assert_called_once_with()
    guestfs().list_devices.assert_called_once_with()
    guestfs().add_drive.assert_called_once_with(str(tmpdir / "rootfs.ext4"))
    guestfs().mount.assert_called_once_with(guestfs().list_devices()[0], "/")
    guestfs().mkdir_p.assert_called_once_with("/lib")
    guestfs().tar_in.assert_called_once_with(str(tmpdir / "modules.tar"),
                                             "/lib",
                                             compress=None)
    assert caplog.record_tuples == [
        ("dispatcher", 20, f"Modifying '{tmpdir}/rootfs.ext4'"),
        ("dispatcher", 10, "Overlays:"),
        ("dispatcher", 10,
         f"- rootfs.modules: '{tmpdir}/modules.tar' to '/lib'"),
    ]
Ejemplo n.º 2
0
def test_append_overlays_run(mocker):
    params = {
        "format": "cpio.newc",
        "overlays": {
            "modules": {
                "url": "http://example.com/modules.tar.xz",
                "compression": "xz",
                "format": "tar",
                "path": "/",
            }
        },
    }
    action = AppendOverlays("rootfs", params)
    action.update_cpio = mocker.stub()
    action.update_guestfs = mocker.stub()
    action.update_tar = mocker.stub()
    assert action.run(None, 0) is None
    action.update_cpio.assert_called_once_with()

    params["format"] = "ext4"
    assert action.run(None, 0) is None
    action.update_guestfs.assert_called_once_with()

    params["format"] = "tar"
    assert action.run(None, 0) is None
    action.update_tar.assert_called_once_with()