-
Notifications
You must be signed in to change notification settings - Fork 5
/
bug_harness.py
100 lines (79 loc) · 3.2 KB
/
bug_harness.py
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
from bug_harness import DSAdminHarness as DSAdmin
from dsadmin import Entry
from dsadmin.tools import DSAdminTools
"""
An harness for bug replication.
"""
import os
REPLBINDDN = ''
REPLBINDPW = ''
@static_var("REPLICAID", 1)
def get_next_replicaid(replica_id=None, replica_type=None):
if replica_id:
REPLICAID = replica_id
return REPLICAID
# get a default replica_id if it's a MASTER,
# or 0 if consumer
if replica_type == MASTER_TYPE:
REPLICAID += 1
return REPLICAID
return 0
class DSAdminHarness(DSAdmin, DSAdminTools):
"""Harness wrapper around dsadmin.
Specialize the DSAdmin behavior (No, I don't care about Liskov ;))
"""
def setupSSL(self, secport, sourcedir=os.environ['SECDIR'], secargs=None):
"""Bug scripts requires SECDIR."""
return DSAdminTools.setupSSL(self, secport, sourcedir, secargs)
def setupAgreement(self, repoth, args):
"""Set default replia credentials """
args.setdefault('binddn', REPLBINDDN)
args.setdefault('bindpw', REPLBINDPW)
return DSAdmin.setupAgreement(self, repoth, args)
def setupReplica(self, args):
"""Set default replia credentials """
args.setdefault('binddn', REPLBINDDN)
args.setdefault('bindpw', REPLBINDPW)
# manage a progressive REPLICAID
args.setdefault(
'id', get_next_replicaid(args.get('id'), args.get('type')))
return DSAdmin.setupReplica(self, args)
def setupBindDN(self, binddn=REPLBINDDN, bindpw=REPLBINDPW):
return DSAdmin.setupBindDN(self, binddn, bindpw)
def setupReplBindDN(self, binddn=REPLBINDDN, bindpw=REPLBINDPW):
return self.setupBindDN(binddn, bindpw)
def setupBackend(self, suffix, binddn=None, bindpw=None, urls=None, attrvals=None, benamebase=None, verbose=False):
"""Create a backends using the first available cn."""
# if benamebase is set, try creating without appending
if benamebase:
benum = 0
else:
benum = 1
# figure out what type of be based on args
if binddn and bindpw and urls: # its a chaining be
benamebase = benamebase or "chaindb"
else: # its a ldbm be
benamebase = benamebase or "localdb"
done = False
while not done:
# if benamebase is set, benum starts at 0
# and the first attempt tries to create the
# simple benamebase. On failure benum is
# incremented and the suffix is appended
# to the cn
if benum:
benamebase_tmp = benamebase + str(benum) # e.g. localdb1
else:
benamebase_tmp = benamebase
try:
cn = DSAdmin.setupBackend(suffix, binddn, bindpw,
urls, attrvals, benamebase, verbose)
done = True
except ldap.ALREADY_EXISTS:
benum += 1
return cn
def createInstance(args):
# eventually set prefix
args.setdefault('prefix', os.environ.get('PREFIX', None))
args.setdefault('sroot', os.environ.get('SERVER_ROOT', None))
DSAdminTools.createInstance(args)