def test_run_dict_arguments_has_been_deprecated_in_favor_of_list(): warn_counts = 0 with warnings.catch_warnings(record=True) as w: warnings.simplefilter("module") warn_about_deprecated_features( experiments.ExperimentWithDeprecatedProcArgsProbe) for warning in w: if issubclass(warning.category, DeprecationWarning) and \ warning.filename == deprecation.__file__: assert DeprecatedDictArgsMessage in str(warning.message) warn_counts = warn_counts + 1 assert warn_counts == 1
def test_vault_secrets_require_path(): warn_counts = 0 with warnings.catch_warnings(record=True) as w: warnings.simplefilter("module") warn_about_deprecated_features( experiments.ExperimentWithDeprecatedVaultPayload) for warning in w: if issubclass(warning.category, DeprecationWarning) and \ warning.filename == deprecation.__file__: assert DeprecatedVaultMissingPathMessage in str( warning.message) warn_counts = warn_counts + 1 assert warn_counts == 1
def ensure_experiment_is_valid(experiment: Experiment): """ A chaos experiment consists of a method made of activities to carry sequentially. There are two kinds of activities: * probe: detecting the state of a resource in your system or external to it There are two kinds of probes: `steady` and `close` * action: an operation to apply against your system Usually, an experiment is made of a set of `steady` probes that ensure the system is sound to carry further the experiment. Then, an action before another set of of ̀close` probes to sense the state of the system post-action. This function raises :exc:`InvalidExperiment`, :exc:`InvalidProbe` or :exc:`InvalidAction` depending on where it fails. """ logger.info("Validating the experiment's syntax") if not experiment: raise InvalidExperiment("an empty experiment is not an experiment") if not experiment.get("title"): raise InvalidExperiment("experiment requires a title") if not experiment.get("description"): raise InvalidExperiment("experiment requires a description") tags = experiment.get("tags") if tags: if list(filter(lambda t: t == '' or not isinstance(t, str), tags)): raise InvalidExperiment( "experiment tags must be a non-empty string") validate_extensions(experiment) config = load_configuration(experiment.get("configuration", {})) load_secrets(experiment.get("secrets", {}), config) ensure_hypothesis_is_valid(experiment) method = experiment.get("method") if not method: raise InvalidExperiment("an experiment requires a method with " "at least one activity") for activity in method: ensure_activity_is_valid(activity) # let's see if a ref is indeed found in the experiment ref = activity.get("ref") if ref and not lookup_activity(ref): raise InvalidActivity("referenced activity '{r}' could not be " "found in the experiment".format(r=ref)) rollbacks = experiment.get("rollbacks", []) for activity in rollbacks: ensure_activity_is_valid(activity) warn_about_deprecated_features(experiment) validate_controls(experiment) logger.info("Experiment looks valid")