script/traffic_replay: get debug level via api
[garming/samba-autobuild/.git] / script / traffic_replay
index 764462e5be3c10d99c404aae31d2bea996de7865..a1a293b0ea0b84cbb26ed6e8cbec2b121c7d1454 100755 (executable)
@@ -26,7 +26,7 @@ import random
 
 sys.path.insert(0, "bin/python")
 
-from samba import gensec
+from samba import gensec, get_debug_level
 from samba.emulate import traffic
 import samba.getopt as options
 
@@ -134,6 +134,9 @@ def main():
         parser.print_usage()
         return
 
+    debuglevel = get_debug_level()
+    traffic.DEBUG_LEVEL = debuglevel
+
     if opts.clean_up:
         print_err("Removing user and machine accounts")
         lp    = sambaopts.get_loadparm()
@@ -195,6 +198,12 @@ def main():
                    "--number-of-groups"))
         sys.exit(1)
 
+    if opts.number_of_groups and opts.average_groups_per_user:
+        if opts.number_of_groups < opts.average_groups_per_user:
+            print_err(("--average-groups-per-user can not be more than "
+                       "--number-of-groups"))
+            sys.exit(1)
+
     if not opts.number_of_groups and opts.group_memberships:
         print_err("--group-memberships requires --number-of-groups")
         sys.exit(1)
@@ -217,8 +226,6 @@ def main():
             print_err(e)
             sys.exit()
 
-    traffic.DEBUG_LEVEL = opts.debuglevel
-
     duration = opts.duration
     if duration is None:
         duration = 60.0
@@ -263,12 +270,12 @@ def main():
     else:
         conversations = []
 
-    if opts.debuglevel > 5:
+    if debuglevel > 5:
         for c in conversations:
             for p in c.packets:
-                print("    ", p)
+                print("    ", p, file=sys.stderr)
 
-        print('=' * 72)
+        print('=' * 72, file=sys.stderr)
 
     if opts.number_of_users and opts.number_of_users < len(conversations):
         print_err(("--number-of-users (%d) is less than the "