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
@@ -293,6 +293,9 @@ def modify(self, definition: dict[str, Any]) -> None:
293293 definition ["operator" ]["balancerd" ]["enabled" ] = self .value
294294
295295 def validate (self , mods : dict [type [Modification ], Any ]) -> None :
296+ # TODO: Reenable when database-issues#9639 is fixed
297+ return
298+
296299 if MzVersion .parse_mz (mods [EnvironmentdImageRef ]) < MzVersion .parse_mz (
297300 "v0.147.0"
298301 ):
@@ -970,7 +973,7 @@ def validate(self, mods: dict[type[Modification], Any]) -> None:
970973 bufsize = 1 ,
971974 )
972975 time .sleep (1 )
973- # ret = process.poll()
976+ process .poll ()
974977 assert process .stdout
975978 line = process .stdout .readline ()
976979 if "Forwarding from" in line :
@@ -1006,18 +1009,17 @@ def validate(self, mods: dict[type[Modification], Any]) -> None:
10061009 os .killpg (os .getpgid (process .pid ), signal .SIGTERM )
10071010
10081011
1009- class Scenario (Enum ):
1012+ class Properties (Enum ):
1013+ Defaults = "defaults"
10101014 Individual = "individual"
10111015 Combine = "combine"
1012- Defaults = "defaults"
1016+
1017+
1018+ class Action (Enum ):
1019+ Noop = "noop"
10131020 Upgrade = "upgrade"
10141021 UpgradeChain = "upgrade-chain"
10151022
1016- @classmethod
1017- def _missing_ (cls , value ):
1018- if value == "random" :
1019- return cls (random .choice ([elem .value for elem in cls ]))
1020-
10211023
10221024def workflow_default (c : Composition , parser : WorkflowArgumentParser ) -> None :
10231025 parser .add_argument (
@@ -1031,7 +1033,16 @@ def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
10311033 help = "Custom version tag to use" ,
10321034 )
10331035 parser .add_argument ("--seed" , type = str , default = random .randrange (1000000 ))
1034- parser .add_argument ("--scenario" , type = str , default = "all" )
1036+ parser .add_argument ("--scenario" , type = str )
1037+ parser .add_argument (
1038+ "--action" , type = str , default = "noop" , choices = [elem .value for elem in Action ]
1039+ )
1040+ parser .add_argument (
1041+ "--properties" ,
1042+ type = str ,
1043+ default = "individual" ,
1044+ choices = [elem .value for elem in Properties ],
1045+ )
10351046 parser .add_argument ("--modification" , action = "append" , type = str , default = [])
10361047 parser .add_argument ("--runtime" , type = int , help = "Runtime in seconds" )
10371048 args = parser .parse_args ()
@@ -1130,7 +1141,7 @@ def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
11301141 if mod_class .__name__ in args .modification
11311142 ]
11321143
1133- if not args .scenario [ 0 ]. isalpha () :
1144+ if args .scenario :
11341145 assert not args .runtime
11351146 assert not args .modification
11361147 run_scenario (
@@ -1142,32 +1153,37 @@ def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
11421153 )
11431154 return
11441155
1145- scenario = Scenario (args .scenario )
1146- if scenario == Scenario .Individual :
1147- assert not args .runtime
1148- for mod_class in mod_classes :
1149- for value in mod_class .values ():
1150- run_scenario ([[mod_class (value )]], definition )
1151- elif scenario == Scenario .Combine :
1152- assert args .runtime
1156+ if args .runtime :
11531157 end_time = (
11541158 datetime .datetime .now () + datetime .timedelta (seconds = args .runtime )
11551159 ).timestamp ()
1156- while time .time () < end_time :
1157- run_scenario (
1158- [
1159- [
1160- mod_class (rng .choice (mod_class .good_values ()))
1161- for mod_class in mod_classes
1162- ]
1163- ],
1164- definition ,
1165- )
1166- elif scenario == Scenario .Defaults :
1167- assert not args .runtime
1168- mods = [mod_class (mod_class .default ()) for mod_class in mod_classes ]
1169- run_scenario ([mods ], definition , modify = False )
1170- elif scenario == Scenario .Upgrade :
1160+
1161+ action = Action (args .action )
1162+ properties = Properties (args .properties )
1163+
1164+ def get_mods () -> Iterator [list [Modification ]]:
1165+ if properties == Properties .Defaults :
1166+ assert not args .runtime
1167+ yield [mod_class (mod_class .default ()) for mod_class in mod_classes ]
1168+ elif properties == Properties .Individual :
1169+ assert not args .runtime
1170+ for mod_class in mod_classes :
1171+ for value in mod_class .values ():
1172+ yield [mod_class (value )]
1173+ elif properties == Properties .Combine :
1174+ assert args .runtime
1175+ while time .time () < end_time :
1176+ yield [
1177+ mod_class (rng .choice (mod_class .good_values ()))
1178+ for mod_class in mod_classes
1179+ ]
1180+ else :
1181+ raise ValueError (f"Unhandled properties value { properties } " )
1182+
1183+ if action == Action .Noop :
1184+ for mod in get_mods ():
1185+ run_scenario ([mod ], definition )
1186+ elif action == Action .Upgrade :
11711187 assert args .runtime
11721188 end_time = (
11731189 datetime .datetime .now () + datetime .timedelta (seconds = args .runtime )
@@ -1177,16 +1193,12 @@ def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
11771193 versions = sorted (list (rng .sample (versions , 2 )))
11781194 run_scenario (
11791195 [
1180- [EnvironmentdImageRef (str (version ))]
1181- + [
1182- mod_class (rng .choice (mod_class .good_values ()))
1183- for mod_class in mod_classes
1184- ]
1185- for version in versions
1196+ [EnvironmentdImageRef (str (version ))] + mods
1197+ for version , mods in zip (versions , get_mods ())
11861198 ],
11871199 definition ,
11881200 )
1189- elif scenario == Scenario .UpgradeChain :
1201+ elif action == Action .UpgradeChain :
11901202 assert args .runtime
11911203 end_time = (
11921204 datetime .datetime .now () + datetime .timedelta (seconds = args .runtime )
@@ -1197,17 +1209,13 @@ def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
11971209 versions = sorted (list (rng .sample (versions , n )))
11981210 run_scenario (
11991211 [
1200- [EnvironmentdImageRef (str (version ))]
1201- + [
1202- mod_class (rng .choice (mod_class .good_values ()))
1203- for mod_class in mod_classes
1204- ]
1205- for version in versions
1212+ [EnvironmentdImageRef (str (version ))] + mods
1213+ for version , mods in zip (versions , get_mods ())
12061214 ],
12071215 definition ,
12081216 )
12091217 else :
1210- raise ValueError (f"Unhandled scenario { scenario } " )
1218+ raise ValueError (f"Unhandled action { action } " )
12111219
12121220
12131221def setup (cluster : str ):
@@ -1308,7 +1316,7 @@ def run_scenario(
13081316 else :
13091317 upgrade (definition )
13101318 mod_dict = {mod .__class__ : mod .value for mod in mods }
1311- for subclass in all_modifications ( ):
1319+ for subclass in all_subclasses ( Modification ):
13121320 if subclass not in mod_dict :
13131321 mod_dict [subclass ] = subclass .default ()
13141322 try :
0 commit comments