def test_search_srpms(pulp):
    """Test convenient method for searching srpms"""
    repo = YumRepository(id="test_repo_1", )
    repo.__dict__["_client"] = pulp.client
    unit_1 = RpmUnit(
        name="test",
        version="1.0",
        release="1",
        arch="src",
        filename="test.src.rpm",
        content_type_id="srpm",
    )
    unit_2 = RpmUnit(
        name="test-devel",
        version="1.0",
        release="1",
        arch="src",
        filename="test-devel.src.rpm",
        content_type_id="srpm",
    )

    pulp.insert_repository(repo)
    pulp.insert_units(repo, [unit_1, unit_2])

    matcher = Matcher(None, None)
    criteria = matcher._create_or_criteria(["filename"], [("test.src.rpm", )])
    # let Future return result
    result = matcher.search_srpms(criteria, [repo]).result()
    # there should be be only one unit in the result set according to criteria
    assert len(result) == 1
    assert result.pop().filename == "test.src.rpm"
Пример #2
0
def test_publish_retries(fast_poller, requests_mocker, client, caplog):
    """publish retries distributors as they fail"""
    caplog.set_level(logging.WARNING)

    repo = YumRepository(
        id="some-repo",
        distributors=(
            Distributor(id="yum_distributor", type_id="yum_distributor"),
            Distributor(id="cdn_distributor", type_id="cdn_distributor"),
        ),
    )
    repo.__dict__["_client"] = client

    requests_mocker.post(
        "https://pulp.example.com/pulp/api/v2/repositories/some-repo/actions/publish/",
        [
            {"json": {"spawned_tasks": [{"task_id": "task1"}]}},
            {"json": {"spawned_tasks": [{"task_id": "task2"}]}},
            {"json": {"spawned_tasks": [{"task_id": "task3"}]}},
        ],
    )

    requests_mocker.post(
        "https://pulp.example.com/pulp/api/v2/tasks/search/",
        [
            {"json": [{"task_id": "task1", "state": "finished"}]},
            {"json": [{"task_id": "task2", "state": "error"}]},
            {"json": [{"task_id": "task3", "state": "finished"}]},
        ],
    )

    publish_f = repo.publish()

    # It should succeed
    tasks = publish_f.result()

    # It should return only the *successful* tasks
    assert sorted([t.id for t in tasks]) == ["task1", "task3"]

    # Pick out the HTTP requests triggering distributors
    publish_reqs = [
        req
        for req in requests_mocker.request_history
        if req.url
        == "https://pulp.example.com/pulp/api/v2/repositories/some-repo/actions/publish/"
    ]
    publish_distributors = [req.json()["id"] for req in publish_reqs]

    # It should have triggered cdn_distributor twice, since the first attempt failed
    assert publish_distributors == [
        "yum_distributor",
        "cdn_distributor",
        "cdn_distributor",
    ]

    # The retry should have been logged
    messages = caplog.messages
    assert (
        messages[-1].splitlines()[0] == "Retrying due to error: Task task2 failed [1/6]"
    )
Пример #3
0
def test_publish_fail(fast_poller, requests_mocker, client):
    """publish raises TaskFailedException if publish task fails"""
    repo = YumRepository(
        id="some-repo",
        distributors=(Distributor(id="yum_distributor",
                                  type_id="yum_distributor"), ),
    )
    repo.__dict__["_client"] = client

    requests_mocker.post(
        "https://pulp.example.com/pulp/api/v2/repositories/some-repo/actions/publish/",
        json={"spawned_tasks": [{
            "task_id": "task1"
        }]},
    )

    requests_mocker.post(
        "https://pulp.example.com/pulp/api/v2/tasks/search/",
        json=[{
            "task_id": "task1",
            "state": "error"
        }],
    )

    publish_f = repo.publish()

    # It should raise this exception
    with pytest.raises(TaskFailedException) as error:
        publish_f.result()

    # The exception should have a reference to the task which failed
    assert error.value.task.id == "task1"
    assert "Task task1 failed" in str(error.value)
Пример #4
0
def test_can_publish():
    """repo.publish() succeeds with fake client and populates publish_history."""
    controller = FakeController()

    controller.insert_repository(
        YumRepository(
            id="repo1",
            distributors=[
                Distributor(id="yum_distributor", type_id="yum_distributor"),
                Distributor(id="cdn_distributor",
                            type_id="rpm_rsync_distributor"),
            ],
        ))
    controller.insert_repository(YumRepository(id="repo2"))

    client = controller.client
    repo1 = client.get_repository("repo1")

    # Call to publish should succeed
    publish_f = repo1.publish()

    # The future should resolve successfully
    tasks = publish_f.result()

    # It should have returned at least one successful task.
    assert tasks
    for task in tasks:
        assert task.succeeded

    # The change should be reflected in the controller's publish history
    history = controller.publish_history

    assert len(history) == 1
    assert history[0].repository.id == "repo1"
    assert history[0].tasks == tasks
Пример #5
0
def test_get_population_sources():
    repo = YumRepository(
        id="rhel-8-for-x86_64-appstream-rpms",
        content_set="rhel-8-for-x86_64-appstream-rpms",
        population_sources=["src_1", "src_2"],
    )

    fake_ubipopulate = FakeUbiPopulate(
        "foo.pulp.com", ("foo", "foo"), False, ubiconfig_dir_or_url=TEST_DATA_DIR
    )

    fake_pulp = fake_ubipopulate.pulp_client_controller

    repo_1 = YumRepository(
        id="src_1",
        content_set="src_1_cs",
    )

    repo_2 = YumRepository(
        id="src_2",
        content_set="src_2_cs",
    )
    fake_pulp.insert_repository(repo_1)
    fake_pulp.insert_repository(repo_2)

    repos = fake_ubipopulate._get_population_sources(
        repo
    )  # pylint: disable=protected-access

    assert len(repos) == 2
    assert ["src_1", "src_2"] == sorted([repo.id for repo in repos])
Пример #6
0
def test_can_sync():
    """repo.sync() succeeds with fake client and populates sync_history."""
    controller = FakeController()

    controller.insert_repository(YumRepository(id="repo1"))
    controller.insert_repository(YumRepository(id="repo2"))

    client = controller.client
    repo1 = client.get_repository("repo1")

    # Call to sync should succeed
    sync_f = repo1.sync(YumSyncOptions(feed="mock://feed/"))

    # The future should resolve successfully
    tasks = sync_f.result()

    # It should have returned at least one successful task.
    assert tasks
    for task in tasks:
        assert task.succeeded

    # The change should be reflected in the controller's sync history
    history = controller.sync_history

    assert len(history) == 1
    assert history[0].repository.id == "repo1"
    assert history[0].tasks == tasks
Пример #7
0
def test_publish_out_repos(mock_ubipop_runner):
    dt = datetime(2019, 9, 12, 0, 0, 0)

    d1 = Distributor(
        id="yum_distributor",
        type_id="yum_distributor",
        repo_id="repo",
        last_publish=dt,
        relative_url="content/unit/2/client",
    )
    repo = YumRepository(
        id="repo",
        eng_product_id=102,
        distributors=[d1],
        relative_url="content/unit/2/client",
    )
    fake_pulp = FakeController()
    repo.__dict__["_client"] = fake_pulp.client

    fake_pulp.insert_repository(repo)
    # Setup output repos, leave only binary repo as the actual one
    mock_ubipop_runner.repos.out_repos = RepoSet(
        f_proxy(f_return(repo)), f_proxy(f_return()), f_proxy(f_return())
    )

    fts = mock_ubipop_runner._publish_out_repos()

    # we should publish only one repository with one distributor
    assert len(fts) == 1
    assert [hist.repository.id for hist in fake_pulp.publish_history] == ["repo"]
def test_search_units(pulp):
    """Test simple search for units"""
    repo = YumRepository(id="test_repo", )
    repo.__dict__["_client"] = pulp.client

    unit_1 = RpmUnit(name="test", version="1.0", release="1", arch="x86_64")
    unit_2 = RpmUnit(name="test", version="1.0", release="1", arch="i386")
    pulp.insert_repository(repo)
    pulp.insert_units(repo, [unit_1, unit_2])

    matcher = Matcher(None, None)
    criteria = matcher._create_or_criteria(["name", "arch"],
                                           [("test", "x86_64")])
    # let Future return result
    search_result = matcher._search_units(repo, criteria, "rpm").result()

    # result should be set
    assert isinstance(search_result, set)
    # with only 1 item
    assert len(search_result) == 1
    unit = search_result.pop()
    # unit should be UbiUnit
    assert isinstance(unit, UbiUnit)
    # internally _unit attr should be RpmUnit
    assert isinstance(unit._unit, RpmUnit)
    # unit has name "test"
    assert unit.name == "test"
    # and proper associate_source_repo_id set
    assert unit.associate_source_repo_id == "test_repo"
def test_search_moludemds(pulp):
    """Test convenient method for searching modulemds"""
    repo = YumRepository(id="test_repo_1", )
    repo.__dict__["_client"] = pulp.client
    unit_1 = ModulemdUnit(
        name="test",
        stream="10",
        version=100,
        context="abcdef",
        arch="x86_64",
    )
    unit_2 = ModulemdUnit(
        name="test",
        stream="20",
        version=100,
        context="abcdef",
        arch="x86_64",
    )

    pulp.insert_repository(repo)
    pulp.insert_units(repo, [unit_1, unit_2])

    matcher = Matcher(None, None)
    criteria = matcher._create_or_criteria(["name", "stream"],
                                           [("test", "10")])
    # let Future return result
    result = matcher.search_modulemds(criteria, [repo]).result()
    # there should be be only one unit in the result set according to criteria
    assert len(result) == 1
    assert result.pop().nsvca == "test:10:100:abcdef:x86_64"
def test_copy_content_empty_repo(controller):
    """copy_content from empty repo succeeds and copies nothing"""
    src = YumRepository(id="empty-repo")
    dest = YumRepository(id="dest-repo")
    controller.insert_repository(src)
    controller.insert_repository(dest)

    client = controller.client

    # Repos are initially detached, re-fetch them via client
    src = client.get_repository(src.id).result()
    dest = client.get_repository(dest.id).result()

    # It should succeed
    copy_tasks = list(client.copy_content(src, dest))

    # It should have at least one task
    assert copy_tasks

    for t in copy_tasks:
        # Every task should have succeeded
        assert t.succeeded

        # No units should have been copied
        assert not t.units
def test_publish_cancel(fast_poller, requests_mocker, client, caplog):
    """Cancelling a publish future will cancel running Pulp task(s)."""

    repo = YumRepository(
        id="some-repo",
        distributors=(
            Distributor(id="yum_distributor", type_id="yum_distributor"),
            Distributor(id="cdn_distributor", type_id="cdn_distributor"),
        ),
    )
    repo.__dict__["_client"] = client

    requests_mocker.post(
        "https://pulp.example.com/pulp/api/v2/repositories/some-repo/actions/publish/",
        [{
            "json": {
                "spawned_tasks": [{
                    "task_id": "task1"
                }]
            }
        }],
    )

    task_search_url = "https://pulp.example.com/pulp/api/v2/tasks/search/"
    requests_mocker.post(task_search_url, [{
        "json": [{
            "task_id": "task1",
            "state": "running"
        }]
    }])

    requests_mocker.delete("https://pulp.example.com/pulp/api/v2/tasks/task1/")

    # Start the publish
    publish_f = repo.publish()

    # Wait until we're sure poll thread has seen this task
    for _ in range(0, 1000):
        if (requests_mocker.last_request
                and requests_mocker.last_request.url == task_search_url):
            break
        time.sleep(0.001)
    assert requests_mocker.last_request.url == task_search_url

    # We should be able to cancel it
    assert publish_f.cancel()

    # It should have cancelled the underlying Pulp task
    task_req = [
        r for r in requests_mocker.request_history
        if r.url == "https://pulp.example.com/pulp/api/v2/tasks/task1/"
    ]
    assert len(task_req) == 1
    assert task_req[0].method == "DELETE"
Пример #12
0
def test_related_repositories_not_found(client, requests_mocker):
    """test Repository.get_*_repository returns Future[None] if repository is not found"""

    repo_binary_test = YumRepository(id="repo_binary", relative_url="some/repo/os")
    repo_binary_test.__dict__["_client"] = client

    requests_mocker.post(
        "https://pulp.example.com/pulp/api/v2/repositories/search/", json=[]
    )

    repo = repo_binary_test.get_source_repository()
    assert repo.result() is None
Пример #13
0
def test_upload_empty_comps_xml(client, requests_mocker):
    """A client can upload an empty comps.xml, which merely removes existing units."""

    repo_id = "repo1"
    repo = YumRepository(id=repo_id)
    repo.__dict__["_client"] = client

    xml = BytesIO(b"<comps/>")

    # Set up the requests it'll do:
    #
    # It should unassociate previous units
    requests_mocker.post(
        "https://pulp.example.com/pulp/api/v2/repositories/repo1/actions/unassociate/",
        json={"spawned_tasks": [{
            "task_id": "remove-task"
        }]},
    )

    # It'll search for the status of tasks.
    requests_mocker.post(
        "https://pulp.example.com/pulp/api/v2/tasks/search/",
        json=[{
            "task_id": "remove-task",
            "state": "finished"
        }],
    )

    # And... that's it.

    # It should start the upload OK
    upload_f = repo.upload_comps_xml(xml)

    # I can await the result
    tasks = upload_f.result()

    # It should just return the removal task
    assert [t.id for t in tasks] == ["remove-task"]
    assert tasks[0].completed
    assert tasks[0].succeeded

    # Check exactly the removed types
    assert requests_mocker.request_history[0].json() == {
        "criteria": {
            "type_ids": [
                "package_group",
                "package_category",
                "package_environment",
                "package_langpacks",
            ]
        }
    }
Пример #14
0
def test_publish_with_options(requests_mocker, client):
    """publish passes expected config into distributors based on publish options"""
    repo = YumRepository(
        id="some-repo",
        distributors=(
            Distributor(id="yum_distributor", type_id="yum_distributor"),
            Distributor(id="cdn_distributor", type_id="rpm_rsync_distributor"),
        ),
    )
    repo.__dict__["_client"] = client

    requests_mocker.post(
        "https://pulp.example.com/pulp/api/v2/repositories/some-repo/actions/publish/",
        [
            {"json": {"spawned_tasks": [{"task_id": "task1"}]}},
            {"json": {"spawned_tasks": [{"task_id": "task2"}]}},
        ],
    )

    requests_mocker.post(
        "https://pulp.example.com/pulp/api/v2/tasks/search/",
        [
            {"json": [{"task_id": "task1", "state": "finished"}]},
            {"json": [{"task_id": "task2", "state": "finished"}]},
        ],
    )

    options = PublishOptions(
        clean=True, force=True, origin_only=True, rsync_extra_args=["-a"]
    )

    # It should have succeeded, with the tasks as retrieved from Pulp
    assert sorted(repo.publish(options)) == [
        Task(id="task1", succeeded=True, completed=True),
        Task(id="task2", succeeded=True, completed=True),
    ]

    req = requests_mocker.request_history

    # The yum_distributor request should have set force_full, but not
    # delete since it's not recognized by that distributor
    assert req[0].json()["override_config"] == {"force_full": True}

    # The cdn_distributor request should have set force_full, delete
    # and content_units_only
    assert req[2].json()["override_config"] == {
        "force_full": True,
        "delete": True,
        "content_units_only": True,
        "rsync_extra_args": ["-a"],
    }
Пример #15
0
def test_load_ubiconfig_by_content_set_regex_and_version():
    """Ensure correct config is returned when given a content set regex and version"""
    repo = YumRepository(
        id="ubi-8-for-x86_64-appstream-rpms__8",
        content_set="ubi-8-for-x86_64-appstream-rpms",
    )

    fake_ubipopulate = FakeUbiPopulate(
        "foo.pulp.com",
        ("foo", "foo"),
        False,
        ubiconfig_dir_or_url=TEST_DATA_DIR,
        version="8",
        content_set_regex="x86_64",
    )

    fake_pulp = fake_ubipopulate.pulp_client_controller
    fake_pulp.insert_repository(repo)

    # two config files are matched according to testdata
    assert len(fake_ubipopulate.ubiconfig_list) == 2

    fake_ubipopulate.ubiconfig_list.sort(key=lambda x: x.file_name)
    conf_1 = fake_ubipopulate.ubiconfig_list[0]
    conf_2 = fake_ubipopulate.ubiconfig_list[1]

    assert conf_1.file_name == "ubiconf_golang.yaml"
    assert conf_1.content_sets.rpm.output == "ubi-8-for-x86_64-appstream-rpms"

    assert conf_2.file_name == "ubiconf_golang2.yaml"
    assert conf_2.content_sets.rpm.output == "ubi-8-for-x86_64-appstream-rpms"
def test_can_upload_comps(data_path):
    """repo.upload_comps_xml() succeeds with fake client."""

    xml_path = os.path.join(data_path, "sample-comps.xml")

    controller = FakeController()

    controller.insert_repository(YumRepository(id="repo1"))

    client = controller.client
    repo1 = client.get_repository("repo1").result()

    upload_f = repo1.upload_comps_xml(xml_path)

    # Upload should complete successfully.
    tasks = upload_f.result()

    # At least one task.
    assert tasks

    # Every task should have succeeded.
    for t in tasks:
        assert t.succeeded

    # If I now search for all content...
    units_all = list(client.search_content())

    # There should still be nothing, as the fake does not actually store
    # and reproduce comps-related units.
    assert units_all == []
def populated_repo(controller):
    units = [
        RpmUnit(name="bash", version="4.0", release="1", arch="x86_64"),
        RpmUnit(content_type_id="srpm",
                name="bash",
                version="4.0",
                release="1",
                arch="src"),
        RpmUnit(name="glibc", version="5.0", release="1", arch="x86_64"),
        ModulemdUnit(name="module1",
                     stream="s1",
                     version=1234,
                     context="a1b2",
                     arch="x86_64"),
        ModulemdUnit(name="module2",
                     stream="s2",
                     version=1234,
                     context="a1b2",
                     arch="x86_64"),
    ]

    repo = YumRepository(id="repo1")
    controller.insert_repository(repo)
    controller.insert_units(repo, units)

    return controller.client.get_repository(repo.id).result()
def test_search_content_empty_repo(controller):
    """search_content on empty repo gives no results"""
    repo = YumRepository(id="empty-repo")
    controller.insert_repository(repo)

    assert list(
        controller.client.get_repository("empty-repo").search_content()) == []
def test_can_upload_rpm_meta(data_path):
    rpm_path = os.path.join(data_path, "rpms/walrus-5.21-1.noarch.rpm")
    controller = FakeController()

    controller.insert_repository(YumRepository(id="repo1"))

    client = controller.client
    repo1 = client.get_repository("repo1").result()

    to_upload = rpm_path

    upload_f = repo1.upload_rpm(to_upload, cdn_path="/path/to/my-great.rpm")

    # Upload should complete successfully.
    tasks = upload_f.result()

    # At least one task.
    assert tasks

    # Every task should have succeeded.
    for t in tasks:
        assert t.succeeded

    # RPM should now be in repo.
    units_in_repo = list(repo1.search_content())
    assert len(units_in_repo) == 1
    unit = units_in_repo[0]

    # Sanity check we got the right unit.
    assert unit.filename == "walrus-5.21-1.noarch.rpm"

    # Extra fields we passed during upload should be present here.
    assert unit.cdn_path == "/path/to/my-great.rpm"
Пример #20
0
def test_publish_absent_raises():
    """repo.publish() of a nonexistent repo raises."""
    controller = FakeController()

    controller.insert_repository(
        YumRepository(
            id="repo1",
            distributors=[
                Distributor(id="yum_distributor", type_id="yum_distributor"),
                Distributor(id="cdn_distributor",
                            type_id="rpm_rsync_distributor"),
            ],
        ))

    client = controller.client
    repo_copy1 = client.get_repository("repo1")
    repo_copy2 = client.get_repository("repo1")

    # If I delete the repo through one handle...
    assert repo_copy1.delete().result()

    # ...then publish through the other handle becomes impossible
    exception = repo_copy2.publish().exception()
    assert isinstance(exception, PulpException)
    assert "repo1 not found" in str(exception)
def populated_repo(controller):
    units = [
        RpmUnit(name="bash", version="4.0", release="1", arch="x86_64"),
        RpmUnit(content_type_id="srpm",
                name="bash",
                version="4.0",
                release="1",
                arch="src"),
        RpmUnit(
            name="glibc",
            version="5.0",
            release="1",
            arch="x86_64",
            sourcerpm="glibc-5.0-1.el5_11.1.src.rpm",
        ),
        ModulemdUnit(name="module1",
                     stream="s1",
                     version=1234,
                     context="a1b2",
                     arch="x86_64"),
        ModulemdUnit(name="module2",
                     stream="s2",
                     version=1234,
                     context="a1b2",
                     arch="x86_64"),
        ErratumUnit(id="RHBA-1234:56", summary="The best advisory"),
    ]

    repo = YumRepository(id="repo1")
    controller.insert_repository(repo)
    controller.insert_units(repo, units)

    return controller.client.get_repository(repo.id).result()
Пример #22
0
def test_upload_overwrite_noop():
    """repo.upload_erratum() doesn't overwrite erratum unit if version is unmodified."""

    controller = FakeController()

    controller.insert_repository(YumRepository(id="repo1"))
    controller.insert_repository(YumRepository(id="repo2"))

    client = controller.client
    repo1 = client.get_repository("repo1").result()
    repo2 = client.get_repository("repo2").result()

    to_upload1 = ErratumUnit(id="RHBA-1234:56",
                             summary="test advisory",
                             version="3")
    to_upload2 = ErratumUnit(
        id="RHBA-1234:56",
        summary="updated test advisory",
        description="changed it, but no effect due to same version",
        version="3",
    )

    # Upload the advisory to two different repos.
    assert repo1.upload_erratum(to_upload1).result()
    assert repo2.upload_erratum(to_upload2).result()

    # Now let's check the outcome in each repo (and entire system).
    units_repo1 = sorted(repo1.search_content(), key=repr)
    units_repo2 = sorted(repo2.search_content(), key=repr)
    units_all = sorted(client.search_content(), key=repr)

    # What we expect to see is that we only have one advisory (as only
    # a single id was used), that advisory is present in two repos, and
    # the advisory content is equal to the first upload because version
    # was not bumped for the second upload.

    assert units_repo1 == [
        ErratumUnit(
            unit_id="e3e70682-c209-4cac-629f-6fbed82c07cd",
            id="RHBA-1234:56",
            summary="test advisory",
            version="3",
            repository_memberships=["repo1", "repo2"],
        )
    ]
    assert units_repo2 == units_repo1
    assert units_all == units_repo1
def test_sync_no_feed(
    fast_poller,
    client,
    requests_mocker,
    fixture_sync_async_response,
    fixture_search_task_response,
):
    """Test sync fail as no feed is provided."""
    repo = YumRepository(id="some-repo")
    repo.__dict__["_client"] = client

    # empty options should fail as feed is required to be non-empty
    try:
        repo.sync().result()
        assert "Exception should have been raised"
    except ValueError:
        pass
Пример #24
0
def fixture_mock_repo():
    yield YumRepository(
        id="test_repo",
        content_set="test_repo-source-rpms",
        ubi_config_version="7.9",
        ubi_population=True,
        population_sources=["a", "b"],
    )
Пример #25
0
def fake_controller(fake_state_path):
    """Yields a pulplib FakeController which has been pre-populated with
    repos used by staged-mixed.
    """
    fake = PersistentFake(state_path=fake_state_path)
    fake.load_initial()
    controller = fake.ctrl

    # Add the repositories which are referenced from the staging area.
    controller.insert_repository(FileRepository(id="iso-dest1"))
    controller.insert_repository(
        FileRepository(id="iso-dest2", arch="x86_64", eng_product_id=123))
    controller.insert_repository(
        YumRepository(id="dest1", arch="x86_64", eng_product_id=123))
    controller.insert_repository(YumRepository(id="dest2"))

    yield controller
Пример #26
0
def test_get_ubi_repo_sets(get_debug_repository, get_source_repository):
    content_set = "rhel-8-for-x86_64-appstream-rpms"
    repo = YumRepository(
        id="ubi_binary",
        content_set="rhel-8-for-x86_64-appstream-rpms",
        population_sources=["input_binary"],
        ubi_population=True,
    )

    input_binary_repo = YumRepository(id="input_binary")
    input_source_repo = YumRepository(id="input_source")
    input_debug_repo = YumRepository(id="input_debug")

    debug_repo = get_test_repo(id="ubi_source", population_sources=["input_source"])
    source_repo = get_test_repo(id="ubi_debug", population_sources=["input_debug"])

    get_debug_repository.return_value = debug_repo
    get_source_repository.return_value = source_repo

    fake_ubipopulate = FakeUbiPopulate(
        "foo.pulp.com", ("foo", "foo"), False, ubiconfig_dir_or_url=TEST_DATA_DIR
    )

    fake_pulp = fake_ubipopulate.pulp_client_controller
    fake_pulp.insert_repository(repo)
    fake_pulp.insert_repository(input_binary_repo)
    fake_pulp.insert_repository(input_source_repo)
    fake_pulp.insert_repository(input_debug_repo)

    ubi_repo_sets = fake_ubipopulate._get_ubi_repo_sets(content_set)

    assert len(ubi_repo_sets) == 1
    ubi_repo_set = ubi_repo_sets[0]
    input_repos = ubi_repo_set.in_repos
    output_repos = ubi_repo_set.out_repos

    assert len(input_repos.rpm) == 1
    assert input_repos.rpm[0].id == "input_binary"
    assert len(input_repos.source) == 1
    assert input_repos.source[0].id == "input_source"
    assert len(input_repos.debug) == 1
    assert input_repos.debug[0].id == "input_debug"

    assert output_repos.rpm.id == "ubi_binary"
    assert output_repos.source.id == "ubi_source"
    assert output_repos.debug.id == "ubi_debug"
Пример #27
0
def test_bad_comps_xml(client, requests_mocker, tmpdir):
    """A client requested to upload an invalid comps.xml will raise immediately
    without making any requests to Pulp."""

    repo_id = "repo1"
    repo = YumRepository(id=repo_id)
    repo.__dict__["_client"] = client

    comps_xml = tmpdir.join("comps.xml")
    comps_xml.write(b"Oops not valid comps")

    # It should raise
    with pytest.raises(ExpatError):
        repo.upload_comps_xml(str(comps_xml))

    # As we did not register anything in requests_mocker, we've already
    # implicitly tested that no requests happened. But just to be clear...
    assert not requests_mocker.request_history
def test_can_remove_content():
    """repo.remove() succeeds and removes expected units inserted via controller."""
    controller = FakeController()
    client = controller.client

    rpm_units = [
        RpmUnit(name="bash", version="4.0", release="1", arch="x86_64"),
        RpmUnit(name="glibc", version="5.0", release="1", arch="x86_64"),
    ]
    modulemd_units = [
        ModulemdUnit(
            name="module1", stream="s1", version=1234, context="a1b2", arch="x86_64"
        ),
        ModulemdUnit(
            name="module1", stream="s1", version=1235, context="a1b2", arch="x86_64"
        ),
    ]
    units = rpm_units + modulemd_units

    repo = YumRepository(id="repo1")
    controller.insert_repository(repo)
    controller.insert_units(repo, units)

    remove_rpms = client.get_repository("repo1").remove_content(type_ids=["rpm"])

    assert len(remove_rpms) == 1
    task = remove_rpms[0]

    # It should have completed successfully
    assert task.completed
    assert task.succeeded

    # It should have removed (only) RPM units
    assert sorted(task.units) == sorted(rpm_units)

    # Now if we ask to remove same content again...
    remove_rpms = client.get_repository("repo1").remove_content(type_ids=["rpm"])

    assert len(remove_rpms) == 1
    task = remove_rpms[0]

    # It should have completed successfully, but no RPMs to remove
    assert task.completed
    assert task.succeeded
    assert not task.units

    # It should still be possible to remove other content
    remove_all = client.get_repository("repo1").remove_content()

    assert len(remove_all) == 1
    task = remove_all[0]

    # It should have completed successfully, and removed the modulemds
    assert task.completed
    assert task.succeeded
    assert sorted(task.units) == sorted(modulemd_units)
Пример #29
0
def _setup_controller(controller):
    # add repo
    repo = YumRepository(
        id="repo",
        eng_product_id=101,
        distributors=[],
        relative_url="content/unit/1/client",
        mutable_urls=["mutable1", "mutable2"],
    )
    nochannel_repo = YumRepository(
        id="all-rpm-content",
        eng_product_id=100,
        distributors=[],
        relative_url="content/unit/1/all-rpm",
        mutable_urls=["mutable1", "mutable2"],
    )
    # add unit
    erratum = ErratumUnit(
        id="RHSA-1234:56",
        version="2",
        content_types=["rpm", "module"],
        references=[
            ErratumReference(
                title="title",
                href="https://example.com/test-advisory",
                type="self",
                id="self-id",
            ),
            ErratumReference(
                title="CVE-123",
                href="https://example.com/test-cve",
                type="cve",
                id="CVE-123",
            ),
        ],
        pkglist=[],
        repository_memberships=["repo", "all-rpm-content"],
    )

    controller.insert_repository(repo)
    controller.insert_repository(nochannel_repo)
    controller.insert_units(repo, [erratum])
    controller.insert_units(nochannel_repo, [erratum])
Пример #30
0
    def load_initial(self):
        """Initial load of data into the fake, in the case where no state
        has previously been persisted.

        This will populate a hardcoded handful of repos which are expected
        to always be present in a realistically configured rhsm-pulp server.
        """
        self.ctrl.insert_repository(FileRepository(id="redhat-maintenance"))
        self.ctrl.insert_repository(FileRepository(id="all-iso-content"))
        self.ctrl.insert_repository(YumRepository(id="all-rpm-content"))