]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool: let 'domain level raise' call check_and_update_fl() in a transaction
authorStefan Metzmacher <metze@samba.org>
Wed, 21 Jun 2023 10:07:08 +0000 (12:07 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 21 Jun 2023 19:08:37 +0000 (19:08 +0000)
This makes it possible to raise the levels without starting
'samba' first, which is very useful for blackbox tests.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/netcmd/domain/level.py

index e3c8f35169afbe983302ae52fef43759c134d8f1..c4361eed342ecc72dc8f4be085905fcfb76882db 100644 (file)
@@ -25,7 +25,7 @@
 import ldb
 import samba.getopt as options
 from samba.auth import system_session
-from samba.dsdb import DS_DOMAIN_FUNCTION_2000
+from samba.dsdb import check_and_update_fl, DS_DOMAIN_FUNCTION_2000
 from samba.netcmd import Command, CommandError, Option
 from samba.samdb import SamDB
 
@@ -68,6 +68,16 @@ class cmd_domain_level(Command):
 
         domain_dn = samdb.domain_dn()
 
+        in_transaction = False
+        if subcommand == "raise" and not H.startswith("ldap"):
+            samdb.transaction_start()
+            in_transaction = True
+            try:
+                check_and_update_fl(samdb, lp)
+            except Exception as e:
+                samdb.transaction_cancel()
+                raise e
+
         try:
             res_forest = samdb.search("CN=Partitions,%s" % samdb.get_config_basedn(),
                                       scope=ldb.SCOPE_BASE, attrs=["msDS-Behavior-Version"])
@@ -117,6 +127,8 @@ class cmd_domain_level(Command):
             if level_domain > min_level_dc:
                 raise CommandError("Domain function level is higher than the lowest function level of a DC. Correct this or reprovision!")
         except Exception as e:
+            if in_transaction:
+                samdb.transaction_cancel()
             raise e
 
         def do_show():
@@ -222,10 +234,18 @@ class cmd_domain_level(Command):
             return
 
         if subcommand == "show":
+            assert not in_transaction
             do_show()
             return
         elif subcommand == "raise":
-            do_raise()
+            try:
+                do_raise()
+            except Exception as e:
+                if in_transaction:
+                    samdb.transaction_cancel()
+                raise e
+            if in_transaction:
+                samdb.transaction_commit()
             return
 
         raise AssertionError("Internal Error subcommand[%s] not handled" % subcommand)