2121import subprocess
2222import time
2323import uuid
24- from collections .abc import Callable
24+ from collections .abc import Callable , Iterator
2525from enum import Enum
2626from typing import Any
2727
@@ -288,6 +288,9 @@ def modify(self, definition: dict[str, Any]) -> None:
288288 definition ["operator" ]["balancerd" ]["enabled" ] = self .value
289289
290290 def validate (self , mods : dict [type [Modification ], Any ]) -> None :
291+ # TODO: Reenable when database-issues#9639 is fixed
292+ return
293+
291294 if MzVersion .parse_mz (mods [EnvironmentdImageRef ]) < MzVersion .parse_mz (
292295 "v0.147.0"
293296 ):
@@ -964,7 +967,7 @@ def validate(self, mods: dict[type[Modification], Any]) -> None:
964967 bufsize = 1 ,
965968 )
966969 time .sleep (1 )
967- # ret = process.poll()
970+ process .poll ()
968971 assert process .stdout
969972 line = process .stdout .readline ()
970973 if "Forwarding from" in line :
@@ -1000,18 +1003,17 @@ def validate(self, mods: dict[type[Modification], Any]) -> None:
10001003 os .killpg (os .getpgid (process .pid ), signal .SIGTERM )
10011004
10021005
1003- class Scenario (Enum ):
1006+ class Properties (Enum ):
1007+ Defaults = "defaults"
10041008 Individual = "individual"
10051009 Combine = "combine"
1006- Defaults = "defaults"
1010+
1011+
1012+ class Action (Enum ):
1013+ Noop = "noop"
10071014 Upgrade = "upgrade"
10081015 UpgradeChain = "upgrade-chain"
10091016
1010- @classmethod
1011- def _missing_ (cls , value ):
1012- if value == "random" :
1013- return cls (random .choice ([elem .value for elem in cls ]))
1014-
10151017
10161018def workflow_default (c : Composition , parser : WorkflowArgumentParser ) -> None :
10171019 parser .add_argument (
@@ -1025,7 +1027,16 @@ def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
10251027 help = "Custom version tag to use" ,
10261028 )
10271029 parser .add_argument ("--seed" , type = str , default = random .randrange (1000000 ))
1028- parser .add_argument ("--scenario" , type = str , default = "all" )
1030+ parser .add_argument ("--scenario" , type = str )
1031+ parser .add_argument (
1032+ "--action" , type = str , default = "noop" , choices = [elem .value for elem in Action ]
1033+ )
1034+ parser .add_argument (
1035+ "--properties" ,
1036+ type = str ,
1037+ default = "individual" ,
1038+ choices = [elem .value for elem in Properties ],
1039+ )
10291040 parser .add_argument ("--modification" , action = "append" , type = str , default = [])
10301041 parser .add_argument ("--runtime" , type = int , help = "Runtime in seconds" )
10311042 args = parser .parse_args ()
@@ -1124,7 +1135,7 @@ def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
11241135 if mod_class .__name__ in args .modification
11251136 ]
11261137
1127- if not args .scenario [ 0 ]. isalpha () :
1138+ if args .scenario :
11281139 assert not args .runtime
11291140 assert not args .modification
11301141 run_scenario (
@@ -1136,32 +1147,37 @@ def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
11361147 )
11371148 return
11381149
1139- scenario = Scenario (args .scenario )
1140- if scenario == Scenario .Individual :
1141- assert not args .runtime
1142- for mod_class in mod_classes :
1143- for value in mod_class .values ():
1144- run_scenario ([[mod_class (value )]], definition )
1145- elif scenario == Scenario .Combine :
1146- assert args .runtime
1150+ if args .runtime :
11471151 end_time = (
11481152 datetime .datetime .now () + datetime .timedelta (seconds = args .runtime )
11491153 ).timestamp ()
1150- while time .time () < end_time :
1151- run_scenario (
1152- [
1153- [
1154- mod_class (rng .choice (mod_class .good_values ()))
1155- for mod_class in mod_classes
1156- ]
1157- ],
1158- definition ,
1159- )
1160- elif scenario == Scenario .Defaults :
1161- assert not args .runtime
1162- mods = [mod_class (mod_class .default ()) for mod_class in mod_classes ]
1163- run_scenario ([mods ], definition , modify = False )
1164- elif scenario == Scenario .Upgrade :
1154+
1155+ action = Action (args .action )
1156+ properties = Properties (args .properties )
1157+
1158+ def get_mods () -> Iterator [list [Modification ]]:
1159+ if properties == Properties .Defaults :
1160+ assert not args .runtime
1161+ yield [mod_class (mod_class .default ()) for mod_class in mod_classes ]
1162+ elif properties == Properties .Individual :
1163+ assert not args .runtime
1164+ for mod_class in mod_classes :
1165+ for value in mod_class .values ():
1166+ yield [mod_class (value )]
1167+ elif properties == Properties .Combine :
1168+ assert args .runtime
1169+ while time .time () < end_time :
1170+ yield [
1171+ mod_class (rng .choice (mod_class .good_values ()))
1172+ for mod_class in mod_classes
1173+ ]
1174+ else :
1175+ raise ValueError (f"Unhandled properties value { properties } " )
1176+
1177+ if action == Action .Noop :
1178+ for mod in get_mods ():
1179+ run_scenario ([mod ], definition )
1180+ elif action == Action .Upgrade :
11651181 assert args .runtime
11661182 end_time = (
11671183 datetime .datetime .now () + datetime .timedelta (seconds = args .runtime )
@@ -1171,16 +1187,12 @@ def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
11711187 versions = sorted (list (rng .sample (versions , 2 )))
11721188 run_scenario (
11731189 [
1174- [EnvironmentdImageRef (str (version ))]
1175- + [
1176- mod_class (rng .choice (mod_class .good_values ()))
1177- for mod_class in mod_classes
1178- ]
1179- for version in versions
1190+ [EnvironmentdImageRef (str (version ))] + mods
1191+ for version , mods in zip (versions , get_mods ())
11801192 ],
11811193 definition ,
11821194 )
1183- elif scenario == Scenario .UpgradeChain :
1195+ elif action == Action .UpgradeChain :
11841196 assert args .runtime
11851197 end_time = (
11861198 datetime .datetime .now () + datetime .timedelta (seconds = args .runtime )
@@ -1191,17 +1203,13 @@ def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
11911203 versions = sorted (list (rng .sample (versions , n )))
11921204 run_scenario (
11931205 [
1194- [EnvironmentdImageRef (str (version ))]
1195- + [
1196- mod_class (rng .choice (mod_class .good_values ()))
1197- for mod_class in mod_classes
1198- ]
1199- for version in versions
1206+ [EnvironmentdImageRef (str (version ))] + mods
1207+ for version , mods in zip (versions , get_mods ())
12001208 ],
12011209 definition ,
12021210 )
12031211 else :
1204- raise ValueError (f"Unhandled scenario { scenario } " )
1212+ raise ValueError (f"Unhandled action { action } " )
12051213
12061214
12071215def setup (cluster : str ):
@@ -1299,7 +1307,7 @@ def run_scenario(
12991307 else :
13001308 upgrade (definition )
13011309 mod_dict = {mod .__class__ : mod .value for mod in mods }
1302- for subclass in all_modifications ( ):
1310+ for subclass in all_subclasses ( Modification ):
13031311 if subclass not in mod_dict :
13041312 mod_dict [subclass ] = subclass .default ()
13051313 try :
0 commit comments