def test_bulk_system_by_api_set_correct_systems_and_accounts_fast_track(clean_bulk_delete_systems_and_accounts, core_session, list_of_created_systems): batch1 = ResourceManager.add_multiple_systems_with_accounts(core_session, 3, 4, list_of_created_systems) batch2 = ResourceManager.add_multiple_systems_with_accounts(core_session, 1, 2, list_of_created_systems, sys_type="Unix") batch3 = ResourceManager.add_multiple_systems_with_accounts(core_session, 5, 1, list_of_created_systems, sys_type="Unix") delete_system_ids, delete_account_ids = DataManipulation.aggregate_lists_in_dict_values([batch2]) keep_system_ids, keep_account_ids = DataManipulation.aggregate_lists_in_dict_values([batch1, batch3]) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values([batch1, batch2, batch3]) some_set_name = "ApiSet" + guid() SetsManager.create_manual_collection(core_session, some_set_name, "Server", None) set_id = SetsManager.get_collection_id(core_session, some_set_name, "Server") SetsManager.update_members_collection(core_session, 'add', list(delete_system_ids), 'Server', set_id) collection_and_filters = SetsManager.get_object_collection_and_filter_by_name(core_session, some_set_name, "Server") filters = collection_and_filters['Filters'] logger.info(f'Manual set {collection_and_filters} - members - {delete_system_ids}') result, success = ResourceManager.del_multiple_systems_by_query(core_session, filters, savepasswords=False, secretname="", run_sync=True) assert success is True, f'Delete systems job failed when expected success' SetsManager.delete_collection(core_session, set_id) assert set(ResourceManager.get_multi_added_system_ids(core_session, all_systems).values()) == keep_system_ids, "Set of expected remaining systems did not match search" assert set(ResourceManager.get_multi_added_account_ids(core_session, all_systems)) == keep_account_ids, "Set of expected remaining accounts did not match search"
def test_bulk_system_unenroll_by_api_set_correct_systems_fast_track(core_session, test_four_virtual_aapm_agents): agents, _ = test_four_virtual_aapm_agents all_agent_ids, all_server_ids = _setup_agents(core_session, agents) unenroll_agent_ids = all_agent_ids[:2] unenroll_server_ids = all_server_ids[:2] keep_agent_ids = all_agent_ids[2:] _validate_aapm_agent_details(core_session, all_agent_ids, True) some_set_name = "ApiSet" + guid() SetsManager.create_manual_collection(core_session, some_set_name, "Server", None) set_id = SetsManager.get_collection_id(core_session, some_set_name, "Server") SetsManager.update_members_collection(core_session, 'add', list(unenroll_server_ids), 'Server', set_id) collection_and_filters = SetsManager.get_object_collection_and_filter_by_name(core_session, some_set_name, "Server") filters = collection_and_filters['Filters'] logger.info(f'Manual set {collection_and_filters} - members - {unenroll_server_ids}') _, success = ResourceManager.unenroll_multiple_systems_by_query(core_session, filters, wait_time=0, SkipIfAgentReconciliationEnabled=True, run_sync=True) assert success, f'Unenroll systems job failed when expected success: {unenroll_server_ids}' SetsManager.delete_collection(core_session, set_id) _validate_aapm_agent_details(core_session, unenroll_agent_ids, False) _validate_aapm_agent_details(core_session, keep_agent_ids, True)
def test_bulk_manage_works_with_different_methods_of_specifying_systems( core_session, remote_unmanaged_users_with_mirrored_managed_local_users_qty3, windows_test_machine_config, change_method): account_ids = remote_unmanaged_users_with_mirrored_managed_local_users_qty3 job_result = None if change_method == "ids": job_result, success = ResourceManager.manage_multiple_accounts( core_session, account_ids) assert success, "Did not bulk manage account" elif change_method == "ids_with_invalid": job_result, success = ResourceManager.manage_multiple_accounts( core_session, ["foo"] + list(account_ids)) assert success, "Did not bulk manage account" elif change_method == "sql": sql_query = 'SELECT * FROM VaultAccount WHERE ' + ' OR '.join( ('VaultAccount.ID = "' + str(n) + '"' for n in account_ids)) job_result, success = ResourceManager.manage_multiple_accounts( core_session, [], set_query=sql_query) assert success, "Did not bulk manage accounts" elif change_method == "group": some_set_name = "ApiSet" + guid() SetsManager.create_manual_collection(core_session, some_set_name, "VaultAccount", None) set_id = SetsManager.get_collection_id(core_session, some_set_name, "VaultAccount") SetsManager.update_members_collection(core_session, 'add', account_ids, 'VaultAccount', set_id) filters = SetsManager.get_object_collection_and_filter_by_name( core_session, some_set_name, "VaultAccount")['Filters'] job_result, success = ResourceManager.manage_multiple_accounts( core_session, [], set_query=filters) assert success, "Did not bulk manage accounts" else: raise Exception(f"Bad input variable change_method {change_method}") _validate_accounts_are_managed(core_session, account_ids, job_result) user_info = core_session.get_current_session_user_info().json()['Result'] username = user_info['Name'] start_type = 'Cloud.Core.AsyncOperation.AccountBulkManagement.Start.Multi' end_type = 'Cloud.Core.AsyncOperation.AccountBulkManagement.Success.Multi' start_message = f'{username} initiated management of {len(account_ids)} accounts' end_message = f'{username} successfully managed {len(account_ids)} accounts' RedrockController.expect_event_message_by_type(core_session, start_type, start_message) RedrockController.expect_event_message_by_type(core_session, end_type, end_message)
def test_bulk_rotate_works_with_different_methods_of_specifying_systems( core_session, remote_users_with_mirrored_managed_local_users_qty3, windows_test_machine_config, change_method): remote_ip = windows_test_machine_config['ip_address'] account_ids, accounts = BulkOperations.grab_relevant_users(core_session, remote_users_with_mirrored_managed_local_users_qty3) passwords_fetched = BulkOperations.checkout_users(core_session, accounts) BulkOperations.validate_users_with_login(remote_ip, passwords_fetched) if change_method == "checkin": # disabled, out of scope BulkOperations.check_in_users(core_session, passwords_fetched) elif change_method == "ids": result, success = ResourceManager.rotate_multiple_passwords(core_session, account_ids) assert success, "Did not bulk rotate passwords" elif change_method == "ids_with_invalid": result, success = ResourceManager.rotate_multiple_passwords(core_session, account_ids) assert success, "Did not bulk rotate passwords" elif change_method == "sql": sql_query = 'SELECT * FROM VaultAccount ' \ 'WHERE ' + ' OR '.join(('VaultAccount.ID = "' + str(n) + '"' for n in account_ids)) result, success = ResourceManager.rotate_multiple_passwords(core_session, [], set_query=sql_query) assert success, "Did not bulk rotate passwords" elif change_method == "group": some_set_name = "ApiSet" + guid() SetsManager.create_manual_collection(core_session, some_set_name, "VaultAccount", None) set_id = SetsManager.get_collection_id(core_session, some_set_name, "VaultAccount") SetsManager.update_members_collection(core_session, 'add', account_ids, 'VaultAccount', set_id) filters = SetsManager.get_object_collection_and_filter_by_name(core_session, some_set_name, "VaultAccount")['Filters'] result, success = ResourceManager.rotate_multiple_passwords(core_session, [], set_query=filters) assert success, "Did not bulk rotate passwords" else: raise Exception(f"Bad input variable change_method {change_method}") BulkOperations.validate_users_with_login(remote_ip, passwords_fetched, [False] * len(passwords_fetched), change_method) # Verify passwords are no longer right user_info = core_session.get_current_session_user_info().json()['Result'] username = user_info['Name'] start_type = 'Cloud.Core.AsyncOperation.BulkPasswordRotationJob.Start.Multi' end_type = 'Cloud.Core.AsyncOperation.BulkPasswordRotationJob.Success.Multi' start_message = f'{username} initiated password rotation of {len(account_ids)} accounts' end_message = f'{username} successfully rotated {len(account_ids)} account passwords' RedrockController.expect_event_message_by_type(core_session, start_type, start_message) RedrockController.expect_event_message_by_type(core_session, end_type, end_message)
def test_bulk_account_by_api_set_correct_accounts( clean_bulk_delete_systems_and_accounts, core_session, list_of_created_systems, core_admin_ui): batch = ResourceManager.add_multiple_systems_with_accounts( core_session, 2, 2, list_of_created_systems) all_systems, all_accounts = DataManipulation.aggregate_lists_in_dict_values( [batch]) delete_ids, keep_ids = DataManipulation.shuffle_and_split_into_two_lists( all_accounts) some_set_name = "ApiSet" + guid() success, set_id = SetsManager.create_manual_collection( core_session, some_set_name, "VaultAccount", None) assert success, "Did not create collection" SetsManager.update_members_collection(core_session, 'add', list(delete_ids), 'VaultAccount', set_id) filters = SetsManager.get_object_collection_and_filter_by_name( core_session, some_set_name, "VaultAccount")['Filters'] result, success = ResourceManager.del_multiple_accounts_by_query( core_session, filters) assert success, "del_multiple_accounts_by_query failed " + result SetsManager.delete_collection(core_session, set_id) assert set( ResourceManager.get_multi_added_system_ids( core_session, all_systems).values()) == set( all_systems), "Wrong set of added systems found" assert set( ResourceManager.get_multi_added_account_ids( core_session, all_systems)) == set(keep_ids), "Wrong set of added accounts found"