Exemple #1
0
def create_ad_sudousers(session_multihost, request):
    """ create Ad sudo users and groups """
    ad = ADOperations(session_multihost.ad[0])
    for idx in range(1, 10):
        ad_user = '******' % idx
        ad_group = 'sudo_idmgroup%d' % idx
        ad.delete_ad_user_group(ad_group)
        ad.delete_ad_user_group(ad_user)
        ad.create_ad_unix_user_group(ad_user, ad_group)
    ad_user1 = 'sudo_user1'
    ad_group2 = 'sudo_group2'
    ad.create_ad_unix_user_group(ad_user1, ad_group2)
    ad_group1 = 'sudo_groupx'
    ad.create_ad_nonposix_group(ad_group1)
    ad.add_user_member_of_group(ad_group1, ad_user1)

    def remove_ad_sudousers():
        """ Remove AD sudo users and groups """
        for idx in range(1, 10):
            ad_user = '******' % idx
            ad_group = 'sudo_idmgroup%d' % idx
            ad.delete_ad_user_group(ad_group)
            ad.delete_ad_user_group(ad_user)
        for object in [ad_group1, ad_group2, ad_user1]:
            ad.delete_ad_user_group(object)
    request.addfinalizer(remove_ad_sudousers)
Exemple #2
0
def fixture_prepare_users(session_multihost, request):
    """Prepare users and groups"""
    uid = random.randint(9999, 99999)
    ad_op = ADOperations(session_multihost.ad[0])

    # Setup non-posix user 1
    ad_user_1 = 'testuser1%d' % uid
    ad_group_1 = 'testgroup1%d' % uid
    ad_op.create_ad_nonposix_user(ad_user_1)
    ad_op.create_ad_nonposix_group(ad_group_1)
    ad_op.add_user_member_of_group(ad_group_1, ad_user_1)

    # Add gecos to user 1
    usr = f"powershell.exe -inputformat none -noprofile 'Set-ADUser " \
          f"-Identity \"{ad_user_1}\" -Add @{{" \
          f"gecos = \"{ad_user_1}\";}}'"
    session_multihost.ad[0].run_command(usr, raiseonerr=False)

    # Set user primary group
    upg = f"powershell.exe -inputformat none -noprofile " \
          f"'Set-ADUserPrimaryGroup {ad_user_1} \'{ad_group_1}\''"
    session_multihost.ad[0].run_command(upg, raiseonerr=False)

    # Setup posix user 2
    ad_user_2 = 'testuser2%d' % uid
    ad_group_2 = 'testgroup2%d' % uid
    ad_op.create_ad_unix_user_group(ad_user_2, ad_group_2)

    # Add gecos to user 2
    usr = f"powershell.exe -inputformat none -noprofile 'Set-ADUser " \
          f"-Identity \"{ad_user_2}\" -Add @{{" \
          f"gecos = \"{ad_user_2}\";}}'"
    session_multihost.ad[0].run_command(usr, raiseonerr=False)

    def remove_ad_user_groups():
        """ Remove windows AD users and groups"""
        ad_op.delete_ad_user_group(ad_user_1)
        ad_op.delete_ad_user_group(ad_group_1)
        ad_op.delete_ad_user_group(ad_user_2)
        ad_op.delete_ad_user_group(ad_group_2)

    request.addfinalizer(remove_ad_user_groups)
    return ad_user_1, ad_group_1, ad_user_2, ad_group_2