Example #1
0
def test_patch_package_code_by_marker(conf_dir, cmk_dir):
    # prepare file to tests
    if not cmk_dir.exists():
        pytest.skip("cmk_dir is not good")
    fname = u"test_bin.tst"
    src = cmk_dir / u"agents/wnx/test_files/msibuild/msi" / fname
    if not src.exists():
        pytest.skip("Path with MSI doesn't exist")

    uuid = msi_patch.generate_uuid()

    # prepare test file
    dst = conf_dir / fname
    shutil.copy(str(src), str(dst))
    base_content = dst.read_bytes()
    assert base_content.find(msi_patch.TRADITIONAL_UUID.encode('ascii')) != -1

    # patch 1
    pos = base_content.find(aaa_marker)
    assert pos != -1
    assert msi_patch.patch_package_code_by_marker(f_name=dst,
                                                  package_code=uuid)

    new_content = dst.read_bytes()
    check_content(new_content=new_content,
                  base_content=base_content,
                  pos=pos,
                  uuid=uuid,
                  marker=aaa_marker)

    # prepare test file
    shutil.copy(str(src), str(dst))

    # patch 2
    st_f = conf_dir / "state_file_2.yml"
    assert msi_patch.patch_package_code_by_marker(f_name=dst,
                                                  package_code=uuid,
                                                  state_file=st_f)

    new_content = dst.read_bytes()
    loc = new_content.find(uuid.encode('ascii'))
    pos, id = msi_patch.load_state_file(st_f)
    assert loc == pos
    assert id == uuid
Example #2
0
def test_patch_package_code_by_marker(conf_dir):
    # prepare file to tests
    fname = "test_bin.tst"
    src = _get_test_file(fname=fname)

    uuid = msi_patch.generate_uuid()

    # prepare test file
    dst = conf_dir / fname
    shutil.copy(str(src), str(dst))
    base_content = dst.read_bytes()
    assert base_content.find(msi_patch.TRADITIONAL_UUID.encode("ascii")) != -1

    # patch 1
    pos = base_content.find(aaa_marker)
    assert pos != -1
    assert msi_patch.patch_package_code_by_marker(f_name=dst,
                                                  package_code=uuid)

    new_content = dst.read_bytes()
    check_content(new_content=new_content,
                  base_content=base_content,
                  pos=pos,
                  uuid=uuid,
                  marker=aaa_marker)

    # prepare test file
    shutil.copy(str(src), str(dst))

    # patch 2
    st_f = conf_dir / "state_file_2.yml"
    assert msi_patch.patch_package_code_by_marker(f_name=dst,
                                                  package_code=uuid,
                                                  state_file=st_f)

    new_content = dst.read_bytes()
    _loc = new_content.find(uuid.encode("ascii"))
    _pos, _id = msi_patch.load_state_file(st_f)
    assert _loc == _pos
    assert _id == uuid
Example #3
0
def update_package_code(new_msi_file, package_code_hash=None):
    if not msi_patch.patch_package_code_by_marker(new_msi_file, package_code=package_code_hash):
        raise Exception("Failed to patch package code")