Rework `ConfigManagementStateMachine` rules for higher data generation success rates
Marco Ricci

Marco Ricci commited on 2024-12-20 15:06:20
Zeige 1 geänderte Dateien mit 16 Einfügungen und 33 Löschungen.


Lower the failure/retry rate for data generation by moving all data
generation into initialization rules and by removing data restrictions
on rule inputs as far as possible, turning the rule effectively into
a no-op if necessary.

The only currently remaining operation with notable retry rate is the
top-level rule selection.
... ...
@@ -2706,8 +2706,8 @@ class ConfigManagementStateMachine(stateful.RuleBasedStateMachine):
2706 2706
         target=configuration,
2707 2707
         configs=strategies.lists(
2708 2708
             _vault_full_config,
2709
-            min_size=4,
2710
-            max_size=4,
2709
+            min_size=8,
2710
+            max_size=8,
2711 2711
         ),
2712 2712
     )
2713 2713
     def declare_initial_configs(
... ...
@@ -2718,37 +2718,20 @@ class ConfigManagementStateMachine(stateful.RuleBasedStateMachine):
2718 2718
 
2719 2719
     @stateful.initialize(
2720 2720
         target=setting,
2721
-        config=_vault_full_config,
2722
-    )
2723
-    def extract_initial_settings(
2724
-        self,
2725
-        config: _types.VaultConfig,
2726
-    ) -> Iterable[_types.VaultConfigServicesSettings]:
2727
-        return stateful.multiple(
2728
-            *map(copy.deepcopy, config['services'].values())
2729
-        )
2730
-
2731
-    @stateful.rule(
2732
-        target=configuration,
2733
-        config=_vault_full_config,
2721
+        configs=strategies.lists(
2722
+            _vault_full_config,
2723
+            min_size=4,
2724
+            max_size=4,
2734 2725
         )
2735
-    def declare_config(
2736
-        self,
2737
-        config: _types.VaultConfig,
2738
-    ) -> _types.VaultConfig:
2739
-        return config
2740
-
2741
-    @stateful.rule(
2742
-        target=setting,
2743
-        config=_vault_full_config,
2744 2726
     )
2745
-    def extract_settings(
2727
+    def extract_initial_settings(
2746 2728
         self,
2747
-        config: _types.VaultConfig,
2729
+        configs: list[_types.VaultConfig],
2748 2730
     ) -> Iterable[_types.VaultConfigServicesSettings]:
2749
-        return stateful.multiple(
2750
-            *map(copy.deepcopy, config['services'].values())
2751
-        )
2731
+        settings: list[_types.VaultConfigServicesSettings] = []
2732
+        for c in configs:
2733
+            settings.extend(c['services'].values())
2734
+        return stateful.multiple(*map(copy.deepcopy, settings))
2752 2735
 
2753 2736
     @staticmethod
2754 2737
     def fold_configs(
... ...
@@ -2846,14 +2829,14 @@ class ConfigManagementStateMachine(stateful.RuleBasedStateMachine):
2846 2829
 
2847 2830
     @stateful.rule(
2848 2831
         target=configuration,
2849
-        config=configuration.filter(lambda c: 'global' in c),
2832
+        config=configuration,
2850 2833
     )
2851 2834
     def purge_global(
2852 2835
         self,
2853 2836
         config: _types.VaultConfig,
2854 2837
     ) -> _types.VaultConfig:
2855 2838
         cli._save_config(config)
2856
-        config.pop('global')
2839
+        config.pop('global', None)
2857 2840
         _result = self.runner.invoke(
2858 2841
             cli.derivepassphrase_vault,
2859 2842
             ['--delete-globals'],
... ...
@@ -2868,7 +2851,7 @@ class ConfigManagementStateMachine(stateful.RuleBasedStateMachine):
2868 2851
     @stateful.rule(
2869 2852
         target=configuration,
2870 2853
         config_and_service=configuration.filter(
2871
-            lambda c: len(c['services']) > 1
2854
+            lambda c: bool(c['services'])
2872 2855
         ).flatmap(
2873 2856
             lambda c: strategies.tuples(
2874 2857
                 strategies.just(c),
... ...
@@ -2896,7 +2879,7 @@ class ConfigManagementStateMachine(stateful.RuleBasedStateMachine):
2896 2879
 
2897 2880
     @stateful.rule(
2898 2881
         target=configuration,
2899
-        config=configuration.filter(lambda c: 0 < len(c['services']) < 5),
2882
+        config=configuration,
2900 2883
     )
2901 2884
     def purge_all(
2902 2885
         self,
2903 2886