Esempio n. 1
0
def make_users(ipa_testing_config, app):
    created_users = []

    def _make_users(users):
        now = datetime.datetime.utcnow().replace(microsecond=0)
        batch_methods = [{
            "method":
            "user_add",
            "params": [
                [name],
                dict(
                    givenname=name.title(),
                    sn="User",
                    mail=f"{name}@example.com",
                    userpassword="******",
                    loginshell='/bin/bash',
                    fascreationtime=f"{now.isoformat()}Z",
                ),
            ],
        } for name in users]
        ipa_admin.batch(batch_methods)
        created_users.extend(users)

    yield _make_users

    batch_methods = [{
        "method": "user_del",
        "params": [[name], {}]
    } for name in created_users]
    ipa_admin.batch(batch_methods)
Esempio n. 2
0
def many_dummy_groups(ipa_testing_config):
    all_fas_groups = ipa_admin.group_find(fasgroup=True)["result"]

    # Don't call remote batch method with an empty list
    if all_fas_groups:
        ipa_admin.batch(
            a_methods=[
                {"method": "group_del", "params": [[entry["cn"][0]], {}]}
                for entry in all_fas_groups
            ]
        )

    group_list = [f"dummy-group-{i:02d}" for i in range(1, 11)]
    ipa_admin.batch(
        a_methods=[
            {"method": "group_add", "params": [[name], {"fasgroup": True}]}
            for name in group_list
        ]
    )

    yield

    ipa_admin.batch(
        a_methods=[
            {"method": "group_del", "params": [[name], {}]} for name in group_list
        ]
    )

    # Add back original FAS groups
    if all_fas_groups:
        ipa_admin.batch(
            a_methods=[
                {
                    "method": "group_add",
                    "params": [
                        [entry["cn"][0]],
                        {k: v for k, v in entry.items() if k != "cn"},
                    ],
                }
                for entry in all_fas_groups
            ]
        )