summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rwxr-xr-xsource4/scripting/bin/upgradeprovision27
-rwxr-xr-xsource4/scripting/python/samba/upgradehelpers.py12
-rwxr-xr-xsource4/setup/upgrade_from_s318
3 files changed, 32 insertions, 25 deletions
diff --git a/source4/scripting/bin/upgradeprovision b/source4/scripting/bin/upgradeprovision
index 4ab4c007ed..b7582d00fe 100755
--- a/source4/scripting/bin/upgradeprovision
+++ b/source4/scripting/bin/upgradeprovision
@@ -22,9 +22,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import shutil
+import logging
import optparse
import os
+import shutil
import sys
import tempfile
# Allow to run from s4 source directory (without installing samba)
@@ -120,22 +121,22 @@ parser.add_option("--full", help="Perform full upgrade of the samdb (schema, con
opts = parser.parse_args()[0]
-whatToLog = define_what_to_log(opts)
+handler = logging.StreamHandler(sys.stdout)
+upgrade_logger = logging.getLogger("upgradeprovision")
+upgrade_logger.addHandler(handler)
-def messageprovision(text):
- """Print a message if quiet is not set
+provision_logger = logging.getLogger("provision")
+provision_logger.addHandler(handler)
- :param text: Message to print """
- if opts.debugprovision or opts.debugall:
- print text
+whatToLog = define_what_to_log(opts)
-def message(what,text):
+def message(what, text):
"""Print a message if this message type has been selected to be printed
:param what: Category of the message
:param text: Message to print """
if (whatToLog & what) or what <= 0:
- print text
+ upgrade_logger.info("%s", text)
if len(sys.argv) == 1:
opts.interactive = True
@@ -199,10 +200,10 @@ def sanitychecks(credentials,session_info,names,paths):
sam_ldb = Ldb(paths.samdb, session_info=session, credentials=creds,lp=lp,options=["modules:samba_dsdb"])
sam_ldb.set_session_info(session)
- res = sam_ldb.search(expression="objectClass=ntdsdsa",base=str(names.configdn),
- scope=SCOPE_SUBTREE,attrs=["dn"],controls=["search_options:1:2"])
+ res = sam_ldb.search(expression="objectClass=ntdsdsa", base=str(names.configdn),
+ scope=SCOPE_SUBTREE, attrs=["dn"], controls=["search_options:1:2"])
if len(res) == 0:
- print "No DC found, your provision is most probalby hardly broken !"
+ print "No DC found, your provision is most probably hardly broken !"
return False
elif len(res) != 1:
print "Found %d domain controllers, for the moment upgradeprovision is not able to handle upgrade on \
@@ -945,7 +946,7 @@ if __name__ == '__main__':
# With all this information let's create a fresh new provision used as reference
message(SIMPLE, "Creating a reference provision")
provisiondir = tempfile.mkdtemp(dir=paths.private_dir, prefix="referenceprovision")
- newprovision(names, setup_dir, creds, session, smbconf, provisiondir, messageprovision)
+ newprovision(names, setup_dir, creds, session, smbconf, provisiondir, provision_logger)
# Get file paths of this new provision
newpaths = get_paths(param, targetdir=provisiondir)
populate_backlink(newpaths, creds, session,names.schemadn)
diff --git a/source4/scripting/python/samba/upgradehelpers.py b/source4/scripting/python/samba/upgradehelpers.py
index a9efa9ed5a..5bd83873b3 100755
--- a/source4/scripting/python/samba/upgradehelpers.py
+++ b/source4/scripting/python/samba/upgradehelpers.py
@@ -54,11 +54,11 @@ def get_paths(param, targetdir=None, smbconf=None):
smbconf = param.default_path()
if not os.path.exists(smbconf):
- raise ProvisioningError("Unable to find smb.conf ...")
+ raise ProvisioningError("Unable to find smb.conf")
lp = param.LoadParm()
lp.load(smbconf)
- paths = provision_paths_from_lp(lp,lp.get("realm"))
+ paths = provision_paths_from_lp(lp, lp.get("realm"))
return paths
@@ -71,7 +71,8 @@ def find_provision_key_parameters(param, credentials, session_info, paths,
:param session_info: Session object
:param paths: A list of path to provision object
:param smbconf: Path to the smb.conf file
- :return: A list of key provision parameters"""
+ :return: A list of key provision parameters
+ """
lp = param.LoadParm()
lp.load(paths.smbconf)
@@ -80,14 +81,15 @@ def find_provision_key_parameters(param, credentials, session_info, paths,
# NT domain, kerberos realm, root dn, domain dn, domain dns name
names.domain = string.upper(lp.get("workgroup"))
names.realm = lp.get("realm")
- basedn = "DC=" + names.realm.replace(".",",DC=")
+ basedn = "DC=" + names.realm.replace(".", ",DC=")
names.dnsdomain = names.realm
names.realm = string.upper(names.realm)
# netbiosname
secrets_ldb = Ldb(paths.secrets, session_info=session_info,
credentials=credentials,lp=lp, options=["modules:samba_secrets"])
# Get the netbiosname first (could be obtained from smb.conf in theory)
- res = secrets_ldb.search(expression="(flatname=%s)"%names.domain,base="CN=Primary Domains", scope=SCOPE_SUBTREE, attrs=["sAMAccountName"])
+ res = secrets_ldb.search(expression="(flatname=%s)" % names.domain,
+ base="CN=Primary Domains", scope=SCOPE_SUBTREE, attrs=["sAMAccountName"])
names.netbiosname = str(res[0]["sAMAccountName"]).replace("$","")
names.smbconf = smbconf
diff --git a/source4/setup/upgrade_from_s3 b/source4/setup/upgrade_from_s3
index adae0169fe..cdc59dc9eb 100755
--- a/source4/setup/upgrade_from_s3
+++ b/source4/setup/upgrade_from_s3
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import logging
import optparse
import os, sys
@@ -45,16 +46,19 @@ parser.add_option("--targetdir", type="string", metavar="DIR",
opts, args = parser.parse_args()
-def message(text):
- """Print a message if quiet is not set."""
- if not opts.quiet:
- print text
+
+logger = logging.getLogger("upgrade")
+logger.addHandler(logging.StreamHandler(sys.stdout))
+if opts.quiet:
+ logger.setLevel(logging.WARNING)
+else:
+ logger.setLevel(logging.INFO)
if len(args) < 1:
parser.print_usage()
sys.exit(1)
-message("Reading Samba3 databases and smb.conf")
+logger.info("Reading Samba3 databases and smb.conf")
libdir = args[0]
if not os.path.isdir(libdir):
@@ -68,7 +72,7 @@ else:
samba3 = Samba3(libdir, smbconf)
-message("Provisioning")
+logger.info("Provisioning")
setup_dir = opts.setupdir
if setup_dir is None:
@@ -78,6 +82,6 @@ lp = sambaopts.get_loadparm()
smbconf = lp.configfile
creds = credopts.get_credentials(lp)
-upgrade_provision(samba3, setup_dir, message, credentials=creds,
+upgrade_provision(samba3, setup_dir, logger, credentials=creds,
session_info=system_session(), smbconf=smbconf,
targetdir=opts.targetdir)