/usr/lib/python3/dist-packages/lib389/ldclt.py is in python3-lib389 1.3.7.10-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | # --- BEGIN COPYRIGHT BLOCK ---
# Copyright (C) 2016 Red Hat, Inc.
# All rights reserved.
#
# License: GPL (version 3 or any later version).
# See LICENSE for details.
# --- END COPYRIGHT BLOCK ---
import subprocess
"""
This class will allow general usage of ldclt.
It's not meant to expose all the functions. Just use ldclt for that.
It's meant to expose general use cases for tests in 389.
Calling this on a production DS instance is likely a fast way to MESS THINGS UP.
"""
class Ldclt(object):
def __init__(self, ds):
self.ds = ds
self.verbose = self.ds.verbose
self.log = self.ds.log
def create_users(self, subtree, min=1000, max=9999, template=None):
"""
Creates users as user<min through max>. Password will be set to
password<number>
This will automatically work with the bind loadtest.
"""
# Should we check max > min?
# Create the template file given the data.
if template is None:
template = """
objectClass: top
objectclass: person
objectClass: organizationalPerson
objectClass: inetorgperson
objectClass: posixAccount
objectClass: shadowAccount
sn: user[A]
cn: user[A]
givenName: user[A]
description: description [A]
userPassword: user[A]
mail: user[A]@example.com
uidNumber: 1[A]
gidNumber: 2[A]
shadowMin: 0
shadowMax: 99999
shadowInactive: 30
shadowWarning: 7
homeDirectory: /home/user[A]
loginShell: /bin/false
"""
with open('/tmp/ldclt_template_lib389.ldif', 'wb') as f:
f.write(template)
# call ldclt with the current rootdn and rootpass
digits = len('%s' % max)
cmd = [
'%s/bin/ldclt' % self.ds.prefix,
'-h',
self.ds.host,
'-p',
'%s' % self.ds.port,
'-D',
self.ds.binddn,
'-w',
self.ds.bindpw,
'-b',
subtree,
'-e',
'add,commoncounter',
'-e',
"object=/tmp/ldclt_template_lib389.ldif,rdn=uid:user[A=INCRNNOLOOP(%s;%s;%s)]" % (min, max, digits),
]
result = None
if self.verbose:
self.log.info("ldclt begining user create ...")
self.log.info(' '.join(cmd))
try:
result = subprocess.check_output(cmd)
# If verbose, capture / log the output.
except subprocess.CalledProcessError as e:
print(' '.join(cmd))
print(result)
raise(e)
if self.verbose:
self.log.info(result)
def bind_loadtest(self, subtree, min=1000, max=9999, rounds=3):
# The bind users will be uid=userXXXX
digits = len('%s' % max)
cmd = [
'%s/bin/ldclt' % self.ds.prefix,
'-h',
self.ds.host,
'-p',
'%s' % self.ds.port,
'-N',
'%s' % rounds,
'-D',
'uid=user%s,%s' % ('X' * digits, subtree),
'-w',
'user%s' % ('X' * digits),
'-e',
"randombinddn,randombinddnlow=%s,randombinddnhigh=%s" % (min, max),
'-e',
'bindonly',
]
result = None
if self.verbose:
self.log.info("ldclt loadtest ...")
self.log.info(' '.join(cmd))
try:
result = subprocess.check_output(cmd)
# If verbose, capture / log the output.
except subprocess.CalledProcessError as e:
print(' '.join(cmd))
print(result)
raise(e)
if self.verbose:
self.log.info(result)
|