From: Tim Beale Date: Mon, 5 Nov 2018 22:27:42 +0000 (+1300) Subject: traffic_replay: Rework machine accounts to remove redundant code X-Git-Tag: tdb-1.3.17~847 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a0b5f4b7b05b8ea2bf061b8af5b702aa14a7a5a5;p=thirdparty%2Fsamba.git traffic_replay: Rework machine accounts to remove redundant code generate_users_and_groups() now generates the machine acounts as well as the user accounts, so it seems there's no need to also have generate_traffic_accounts(), which does the same job. Instead, we can just pass through the number of machine acounts to generate_users_and_groups() and delete the other function. Also updated generate_users_and_groups() so that machine_accounts is no longer optional (we want to create machine accounts in all cases). Signed-off-by: Tim Beale Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/emulate/traffic.py b/python/samba/emulate/traffic.py index 9ac8775ed60..069c4103a15 100644 --- a/python/samba/emulate/traffic.py +++ b/python/samba/emulate/traffic.py @@ -1603,7 +1603,6 @@ class ConversationAccounts(object): def generate_replay_accounts(ldb, instance_id, number, password): """Generate a series of unique machine and user account names.""" - generate_traffic_accounts(ldb, instance_id, number, password) accounts = [] for i in range(1, number + 1): netbios_name = machine_name(instance_id, i) @@ -1615,54 +1614,6 @@ def generate_replay_accounts(ldb, instance_id, number, password): return accounts -def generate_traffic_accounts(ldb, instance_id, number, password): - """Create the specified number of user and machine accounts. - - As accounts are not explicitly deleted between runs. This function starts - with the last account and iterates backwards stopping either when it - finds an already existing account or it has generated all the required - accounts. - """ - print(("Generating machine and conversation accounts, " - "as required for %d conversations" % number), - file=sys.stderr) - added = 0 - for i in range(number, 0, -1): - try: - netbios_name = machine_name(instance_id, i) - create_machine_account(ldb, instance_id, netbios_name, password) - added += 1 - if added % 50 == 0: - LOGGER.info("Created %u/%u machine accounts" % (added, number)) - except LdbError as e: - (status, _) = e.args - if status == 68: - break - else: - raise - if added > 0: - LOGGER.info("Added %d new machine accounts" % added) - - added = 0 - for i in range(number, 0, -1): - try: - username = user_name(instance_id, i) - create_user_account(ldb, instance_id, username, password) - added += 1 - if added % 50 == 0: - LOGGER.info("Created %u/%u users" % (added, number)) - - except LdbError as e: - (status, _) = e.args - if status == 68: - break - else: - raise - - if added > 0: - LOGGER.info("Added %d new user accounts" % added) - - def create_machine_account(ldb, instance_id, netbios_name, machinepass, traffic_account=True): """Create a machine account via ldap.""" @@ -1813,7 +1764,7 @@ def clean_up_accounts(ldb, instance_id): def generate_users_and_groups(ldb, instance_id, password, number_of_users, number_of_groups, - group_memberships, machine_accounts=0, + group_memberships, machine_accounts, traffic_accounts=True): """Generate the required users and groups, allocating the users to those groups.""" @@ -1826,11 +1777,10 @@ def generate_users_and_groups(ldb, instance_id, password, LOGGER.info("Generating dummy user accounts") users_added = generate_users(ldb, instance_id, number_of_users, password) - if machine_accounts > 0: - LOGGER.info("Generating dummy machine accounts") - computers_added = generate_machine_accounts(ldb, instance_id, - machine_accounts, password, - traffic_accounts) + LOGGER.info("Generating dummy machine accounts") + computers_added = generate_machine_accounts(ldb, instance_id, + machine_accounts, password, + traffic_accounts) if number_of_groups > 0: LOGGER.info("Generating dummy groups") diff --git a/script/traffic_replay b/script/traffic_replay index e8ba131445a..991c9a9eb03 100755 --- a/script/traffic_replay +++ b/script/traffic_replay @@ -346,6 +346,7 @@ def main(): number_of_users, opts.number_of_groups, opts.group_memberships, + machine_accounts=len(conversations), traffic_accounts=True) accounts = traffic.generate_replay_accounts(ldb,