traffic_replay: Move machine account creation
authorTim Beale <timbeale@catalyst.net.nz>
Mon, 5 Nov 2018 21:52:38 +0000 (10:52 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 7 Nov 2018 16:55:08 +0000 (17:55 +0100)
I was assuming that generate_users_and_groups() only gets called in the
--generate-users-only case. However, it also gets called in the default
traffic replay case.

This patch reworks the code so that the number of machine accounts to
create gets passed in, and the 'create 25% more computers than users'
assumption only applies to the --generate-users-only case.

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/emulate/traffic.py
script/traffic_replay

index af05163f145d23cf592c99f005ae8923d60e53a8..8de329b09bbca3043282a9345cb2c6ee49b43189 100644 (file)
@@ -1798,22 +1798,22 @@ def clean_up_accounts(ldb, instance_id):
 
 def generate_users_and_groups(ldb, instance_id, password,
                               number_of_users, number_of_groups,
-                              group_memberships):
+                              group_memberships, machine_accounts=0):
     """Generate the required users and groups, allocating the users to
        those groups."""
     memberships_added = 0
-    groups_added  = 0
+    groups_added = 0
+    computers_added = 0
 
     create_ou(ldb, instance_id)
 
     LOGGER.info("Generating dummy user accounts")
     users_added = generate_users(ldb, instance_id, number_of_users, password)
 
-    # assume there will be some overhang with more computer accounts than users
-    computer_accounts = int(1.25 * number_of_users)
-    LOGGER.info("Generating dummy machine accounts")
-    computers_added = generate_machine_accounts(ldb, instance_id,
-                                                computer_accounts, password)
+    if machine_accounts > 0:
+        LOGGER.info("Generating dummy machine accounts")
+        computers_added = generate_machine_accounts(ldb, instance_id,
+                                                    machine_accounts, password)
 
     if number_of_groups > 0:
         LOGGER.info("Generating dummy groups")
index 9642ea87d05a695e763fe62b8f31d4510ced1289..2cd84f7a0bbba8815c7a7dfb90fec4cf96a6acc6 100755 (executable)
@@ -324,12 +324,16 @@ def main():
         sys.exit(1)
 
     if opts.generate_users_only:
+        # generate computer accounts for added realism. Assume there will be
+        # some overhang with more computer accounts than users
+        computer_accounts = int(1.25 * number_of_users)
         traffic.generate_users_and_groups(ldb,
                                           opts.instance_id,
                                           opts.fixed_password,
                                           opts.number_of_users,
                                           opts.number_of_groups,
-                                          opts.group_memberships)
+                                          opts.group_memberships,
+                                          machine_accounts=computer_accounts)
         sys.exit()
 
     tempdir = tempfile.mkdtemp(prefix="samba_tg_")