Skip to content

Commit

Permalink
TIG-2470 Change AutoRun syntax (mongodb#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
rtimmons authored Apr 3, 2020
1 parent ef834d1 commit 2ab79db
Show file tree
Hide file tree
Showing 21 changed files with 128 additions and 160 deletions.
51 changes: 28 additions & 23 deletions src/python/gennylib/genny_auto_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ def __init__(self, required_dict, prepare_environment_with):
self.required_dict = required_dict
# A dictionary representing the yaml within the PrepareEnvironmentWith section of the workload AutoRun yaml
self.prepare_environment_with = prepare_environment_with
AutoRunSpec._rename_prepare_environment(prepare_environment_with)

@staticmethod
def _rename_prepare_environment(prepare_environment_with: dict):
# Temporary limitation and workaround until we switch to the new f_run_dsi_workload
# (or similarly-named) evergreen function in TIG-2474.
if prepare_environment_with is None:
return
if "mongodb_setup" in prepare_environment_with:
prepare_environment_with["setup"] = prepare_environment_with["mongodb_setup"]
del(prepare_environment_with["mongodb_setup"])
if len(prepare_environment_with) > 1:
raise Exception(
f"Can only provide 'mongodb_setup' (or 'setup') in PrepareEnvironmentWith")

@staticmethod
def create_from_workload_yaml(workload_yaml):
Expand All @@ -40,10 +54,6 @@ def create_from_workload_yaml(workload_yaml):
required_dict = None
if 'Requires' in workload_yaml['AutoRun'] and isinstance(autorun['Requires'], dict):
required_dict = autorun['Requires']
for module, config in required_dict.items():
if not isinstance(config, dict):
required_dict = None
break

prepare_environment_with = None
if 'PrepareEnvironmentWith' in autorun and isinstance(autorun['PrepareEnvironmentWith'], dict):
Expand Down Expand Up @@ -72,6 +82,7 @@ def get_prepare_environment_vars(self, prepare_environment_vars_template):
prepare_environment_vars.append(curr)
return prepare_environment_vars


def to_snake_case(str):
"""
Converts str to snake_case, useful for generating test id's
Expand Down Expand Up @@ -130,6 +141,13 @@ def modified_workload_files():
return short_filenames


def _simplified_env_dict(env_dict: dict) -> dict:
out = {}
for value in env_dict.values():
out.update(value)
return out


def workload_should_autorun(autorun_spec, env_dict):
"""
Check if the given workload's AutoRun conditions are met by the current environment
Expand All @@ -140,28 +158,15 @@ def workload_should_autorun(autorun_spec, env_dict):
if autorun_spec is None or autorun_spec.required_dict is None:
return False

for module, required_config in autorun_spec.required_dict.items():
if module not in env_dict:
simplified = _simplified_env_dict(env_dict)
for key, values in autorun_spec.required_dict.items():
if not isinstance(values, list):
raise Exception(f"Must give a list for key {key}")
if key not in simplified:
return False
if not isinstance(required_config, dict):
if not any([simplified[key] == value for value in values]):
return False

# True if set of config key-vaue pairs is subset of env_dict key-value pairs
# This will be false if the AutoRun yaml uses a list to represent multiple matching criteria, but it is efficient so we use it for a first-pass.
if not required_config.items() <= env_dict[module].items():
# Now have to check all k, v pairs individually
for key, autorun_val in required_config.items():
if key not in env_dict[module]:
return False
if autorun_val == env_dict[module][key]:
continue

# Values not exactly equal, but the AutoRun value could be a list of possibilities.
if not isinstance(autorun_val, list):
return False
if env_dict[module][key] not in autorun_val:
return False

return True


Expand Down
9 changes: 5 additions & 4 deletions src/python/tests/auto_tasks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_construct_all_tasks_json_multiple_setups(self, mock_glob, mock_safe_loa
mock_safe_load.return_value = {
'AutoRun': {
'PrepareEnvironmentWith': {
'setup': ['first', 'second']
'mongodb_setup': ['first', 'second']
}
}
}
Expand Down Expand Up @@ -310,6 +310,7 @@ def test_workload_should_autorun(self):
env_dict = tc[1]
expected = tc[2]

autorun_spec = AutoRunSpec.create_from_workload_yaml(workload_yaml)
actual = workload_should_autorun(autorun_spec, env_dict)
self.assertEqual(expected, actual)
with self.subTest(tc):
autorun_spec = AutoRunSpec.create_from_workload_yaml(workload_yaml)
actual = workload_should_autorun(autorun_spec, env_dict)
self.assertEqual(expected, actual)
114 changes: 48 additions & 66 deletions src/python/tests/fixtures/auto_tasks_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@
{
'AutoRun': {
'Requires': {
'bootstrap': {
'platform': 'linux',
'storageEngine': 'wiredTiger'
},
'runtime': {
'build_variant': 'variant1',
'is_patch': 'true'
}
'platform': ['linux'],
'storageEngine': ['wiredTiger'],
'build_variant': ['variant1'],
'is_patch': ['true']
}
}
},
Expand All @@ -32,16 +28,14 @@
{
'AutoRun': {
'Requires': {
'bootstrap': {
'platform': 'linux'
}
'platform': ['linux']
}
}
},
{
'bootstrap': {
'platform': 'linux',
'storageEngine': 'wiredTiger'
'storageEngine': 'wiredTiger',
},
'runtime': {
'build_variant': 'variant1',
Expand All @@ -54,11 +48,26 @@
{
'AutoRun': {
'Requires': {
'runtime': {},
'bootstrap': {}
'platform': ['linux']
}
}
},
{
'expansions': {
'platform': 'linux',
'storageEngine': 'wiredTiger',
'build_variant': 'variant1',
'is_patch': 'true'
}
},
True
),
(
{
'AutoRun': {
'Requires': {}
}
},
{
'bootstrap': {
'platform': 'linux',
Expand Down Expand Up @@ -93,13 +102,9 @@
{
'AutoRun': {
'Requires': {
'bootstrap': {
'platform': ['osx', 'windows', 'linux']
},
'runtime': {
'build_variant': 'variant1',
'is_patch': 'true'
}
'platform': ['osx', 'windows', 'linux'],
'build_variant': ['variant1'],
'is_patch': ['true']
}
}
},
Expand All @@ -119,15 +124,11 @@
{
'AutoRun': {
'Requires': {
'bootstrap': {
'platform': ['osx', 'windows', 'debian']
},
'runtime': {
'build_variant': 'variant1',
'is_patch': 'true'
'platform': ['osx', 'windows', 'debian'],
'build_variant': ['variant1'],
'is_patch': ['true']
}
}
}
},
{
'bootstrap': {
Expand All @@ -145,13 +146,9 @@
{
'AutoRun': {
'Requires': {
'bootstrap': {
'platform': ['osx', 'windows', 'linux']
},
'runtime': {
'build_variant': 'variant1',
'is_patch': 'false'
}
'platform': ['osx', 'windows', 'linux'],
'build_variant': ['variant1'],
'is_patch': ['false']
}
}
},
Expand All @@ -171,16 +168,12 @@
{
'AutoRun': {
'Requires': {
'bootstrap': {
'platform': 'linux',
'storageEngine': 'wiredTiger'
},
'runtime': {
'build_variant': 'variant1',
'is_patch': 'true'
'platform': ['linux'],
'storageEngine': ['wiredTiger'],
'build_variant': ['variant1'],
'is_patch': ['true']
}
}
}
},
{
'bootstrap': {
Expand All @@ -198,19 +191,13 @@
{
'AutoRun': {
'Requires': {
'bootstrap': {
'platform': 'linux',
'storageEngine': 'wiredTiger'
},
'runtime': {
'build_variant': 'variant1',
'is_patch': 'true'
},
'other': {
'key': 'value'
'platform': ['linux'],
'storageEngine': ['wiredTiger'],
'build_variant': ['variant1'],
'is_patch': ['true'],
'key': ['value']
}
}
}
},
{
'bootstrap': {
Expand All @@ -228,11 +215,8 @@
{
'AutoRun': {
'Requires': {
'bootstrap': {
'platform': 'linux',
'storageEngine': 'other'
},

'platform': ['linux'],
'storageEngine': ['other']
}
}
},
Expand All @@ -252,8 +236,8 @@
{},
{
'bootstrap': {
'platform': 'linux',
'storageEngine': 'wiredTiger'
'platform': ['linux'],
'storageEngine': ['wiredTiger']
},
'runtime': {
'build_variant': 'variant1',
Expand Down Expand Up @@ -298,11 +282,9 @@
{
'AutoRun': {
'Requires': {
'bootstrap': {
'platform': 'linux',
'storageEngine': 'wiredTiger'
},
'runtime': 'string-runtime'
'platform': ['linux'],
'storageEngine': ['wiredTiger'],
'runtime': ['string-runtime']
}
}
},
Expand Down
9 changes: 4 additions & 5 deletions src/workloads/docs/ParallelInsert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,10 @@ Actors:

AutoRun:
Requires:
bootstrap:
mongodb_setup:
- replica
- replica-noflowcontrol
mongodb_setup:
- replica
- replica-noflowcontrol
PrepareEnvironmentWith:
setup:
mongodb_setup:
- replica-delay-mixed
- replica
3 changes: 1 addition & 2 deletions src/workloads/execution/BackgroundValidateCmd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,4 @@ Actors:

AutoRun:
Requires:
bootstrap:
mongodb_setup: standalone
mongodb_setup: [standalone]
3 changes: 1 addition & 2 deletions src/workloads/execution/CreateBigIndex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,4 @@ Actors:

AutoRun:
Requires:
bootstrap:
mongodb_setup: single-replica
mongodb_setup: [single-replica]
3 changes: 1 addition & 2 deletions src/workloads/execution/CreateIndex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,4 @@ Actors:

AutoRun:
Requires:
bootstrap:
mongodb_setup: single-replica
mongodb_setup: [single-replica]
7 changes: 3 additions & 4 deletions src/workloads/execution/CreateIndexSharded.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ Actors:

AutoRun:
Requires:
bootstrap:
mongodb_setup:
- shard
- shard-lite
mongodb_setup:
- shard
- shard-lite
3 changes: 1 addition & 2 deletions src/workloads/execution/ExternalSort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,4 @@ Actors:

AutoRun:
Requires:
bootstrap:
mongodb_setup: standalone
mongodb_setup: [standalone]
9 changes: 4 additions & 5 deletions src/workloads/execution/UnionWith.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ Actors:

AutoRun:
Requires:
bootstrap:
mongodb_setup:
- standalone
- replica
- shard-lite
mongodb_setup:
- standalone
- replica
- shard-lite
3 changes: 1 addition & 2 deletions src/workloads/execution/ValidateCmd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@ Actors:

AutoRun:
Requires:
bootstrap:
mongodb_setup: standalone
mongodb_setup: [standalone]
Loading

0 comments on commit 2ab79db

Please sign in to comment.