"""An individual site object discovered thru the configuration
naming context. Contains all DSAs that exist within the site
"""
- def __init__(self, site_dnstr):
+ def __init__(self, site_dnstr, unix_now):
self.site_dnstr = site_dnstr
self.site_guid = None
self.site_options = 0
self.site_topo_generator = None
self.site_topo_failover = 0 # appears to be in minutes
self.dsa_table = {}
+ self.unix_now = unix_now
def load_site(self, samdb):
"""Loads the NTDS Site Settions options attribute for the site
D_sort = []
d_dsa = None
- unixnow = int(time.time()) # seconds since 1970
- ntnow = unix2nttime(unixnow) # double word number of 100 nanosecond
- # intervals since 1600s
+ ntnow = unix2nttime(self.unix_now) # double word number of 100 nanosecond
+ # intervals since 1600s
for dsa in self.dsa_table.values():
D_sort.append(dsa)
import logging
import itertools
import heapq
+import time
from samba import (
getopt as options,
self.my_site_dnstr = "CN=%s,CN=Sites,%s" % (
self.samdb.server_site_name(),
self.samdb.get_config_basedn())
- site = Site(self.my_site_dnstr)
+ site = Site(self.my_site_dnstr, unix_now)
site.load_site(self.samdb)
self.site_table[str(site.site_guid)] = site
for msg in res:
sitestr = str(msg.dn)
- site = Site(sitestr)
+ site = Site(sitestr, unix_now)
site.load_site(self.samdb)
# already loaded
if failed_link.failure_count > 0:
unix_first_time_failure = nttime2unix(failed_link.time_first_failure)
# TODO guard against future
- current_time = int(time.time())
- if unix_first_time_failure > current_time:
+ if unix_first_time_failure > unix_now:
logger.error("The last success time attribute for \
repsFrom is in the future!")
# Perform calculation in seconds
- if (current_time - unix_first_time_failure) > 60 * 60 * 2:
+ if (unix_now - unix_first_time_failure) > 60 * 60 * 2:
return True
# TODO connections
help="schemaless database file to create for ldif import",
type=str, metavar="<file>")
+parser.add_option("--now",
+ help="assume current time is this ('YYYYmmddHHMMSS[tz]', default: system time)",
+ type=str, metavar="<date>")
+
logger = logging.getLogger("samba_kcc")
logger.addHandler(logging.StreamHandler(sys.stdout))
if opts.dburl is None:
opts.dburl = lp.samdb_url()
+if opts.now:
+ for timeformat in ("%Y%m%d%H%M%S%Z", "%Y%m%d%H%M%S"):
+ try:
+ now_tuple = time.strptime(opts.now, timeformat)
+ break
+ except ValueError:
+ pass
+ else:
+ # else happens if break doesn't --> no match
+ print >> sys.stderr, "could not parse time '%s'" % opts.now
+ sys.exit(1)
+
+ unix_now = int(time.mktime(now_tuple))
+else:
+ unix_now = int(time.time())
+
+
# Instantiate Knowledge Consistency Checker and perform run
kcc = KCC()