8000 Bosh simulate consistency patch by DarrinFong · Pull Request #605 · boutiques/boutiques · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Bosh simulate consistency patch #605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue a 8000 nd contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions tools/python/boutiques/bosh.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ def execute(*params):
"requireComplete": results.complete,
"sandbox": results.sandbox})
if not inp:
executor.generateRandomParams(1)
# Add optional inputs with default-value to inputs_dict,
# which is then populated with random params
executor.in_dict = addDefaultValues(executor.desc_dict, {})
executor.generateRandomParams(generateCmdLineFromInDict=True)

if results.json:
sout = [json.dumps(
Expand Down Expand Up @@ -674,7 +677,7 @@ def example(*params):
"skipDataCollect": True,
"requireComplete": results.complete,
"sandbox": results.sandbox})
executor.generateRandomParams(1)
executor.generateRandomParams()
return json.dumps(
customSortInvocationByInput(executor.in_dict, descriptor), indent=4)

Expand Down
48 changes: 24 additions & 24 deletions tools/python/boutiques/localExec.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,8 @@ def checkMutualRequirements(targ):

# Start actual dictionary filling part
# Clear the dictionary
self.in_dict = {}
self.in_dict = self.in_dict if hasattr(self, 'in_dict') and\
self.in_dict is not None else {}
for params in [r for r in self.inputs if not r.get('optional')]:
self.in_dict[params['id']] = makeParam(params)

Expand Down Expand Up @@ -913,36 +914,35 @@ def checkMutualRequirements(targ):
# Function to generate random parameter values
# This fills the in_dict with random values, validates the input,
# and generates the appropriate command line
def generateRandomParams(self, n):
def generateRandomParams(self, generateCmdLineFromInDict=False):

'''
The generateRandomParams method fills the in_dict field
with randomly generated values following the schema.
It then generates command line strings based on these
values (more than 1 if -n was given).
It then generates command line strings based on these values
'''

self.cmd_line = []
for i in range(0, n):
# Set in_dict with random values
self._randomFillInDict()
# Look at generated input, if debugging
if self.debug:
print_info("Input: " + str(self.in_dict))
# Check results (as much as possible)
try:
args = [self.desc_path, "-i", json.dumps(self.in_dict)]
if self.sandbox:
args.append("--sandbox")
boutiques.invocation(*args)
# If an error occurs, print out the problems already
# encountered before blowing up
except Exception as e: # Avoid BaseExceptions like SystemExit
sys.stderr.write("An error occurred in validation\n"
"Previously saved issues\n")
for err in self.errs:
sys.stderr.write("\t" + str(err) + "\n")
raise e # Pass on (throw) the caught exception
# Set in_dict with random values
self._randomFillInDict()
# Look at generated input, if debugging
if self.debug:
print_info("Input: " + str(self.in_dict))
# Check results (as much as possible)
try:
args = [self.desc_path, "-i", json.dumps(self.in_dict)]
if self.sandbox:
args.append("--sandbox")
boutiques.invocation(*args)
# If an error occurs, print out the problems already
# encountered before blowing up
except Exception as e: # Avoid BaseExceptions like SystemExit
sys.stderr.write("An error occurred in validation\n"
"Previously saved issues\n")
for err in self.errs:
sys.stderr.write("\t" + str(err) + "\n")
raise e # Pass on (throw) the caught exception
if generateCmdLineFromInDict:
# Add new command line
self.cmd_line.append(self._generateCmdLineFromInDict())

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "tool",
"tool-version": "1",
"description": "a tool",
"command-line": "tool_cli [VALUE]",
"schema-version": "0.5",
"inputs": [
{
"id": "value",
"name": "value",
"type": "String",
"value-key": "[VALUE]",
"value-choices": ["yes", "no"],
"default-value": "no",
"optional": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "tool",
"tool-version": "1",
"description": "a tool",
"command-line": "tool_cli [CONFIG_FILE]",
"schema-version": "0.5",
"inputs": [
{
"id": "value",
"name": "value",
"type": "String",
"value-key": "[VALUE]",
"value-choices": ["yes", "no"],
"default-value": "no",
"optional": true
}
],
"output-files": [
{
"id": "config_file",
"name": "Configuration file",
"value-key": "[CONFIG_FILE]",
"path-template": "tmpConfig.toml",
"file-template": [
"hi__",
"value = [VALUE]",
"__bye"
]
}
]
}
6 changes: 4 additions & 2 deletions tools/python/boutiques/tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,7 @@ def test_example_requires_group_complete_x10(self):
# Bosh example is inherently random,
# Couldn't even inject prederemined input to executor.in_dict
# because _randomFillInDict clears it
executor.generateRandomParams(100)
self.assertGreater(len(executor.in_dict), 0)
for _ in range(0, 100):
executor.generateRandomParams()
self.assertGreater(len(executor.in_dict), 0)
executor.in_dict = None
34 changes: 34 additions & 0 deletions tools/python/boutiques/tests/test_simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,37 @@ def test_collapsing_whitespace_requireds(self):
command = re.search(r"(test[ \da-z]+)", output).group(0)

self.assertNotIn(" ", command)

def test_consistency_withAndWithout_invoc(self):
descriptor = os.path.join(os.path.split(bfile)[0],
'schema/examples/'
'test_simulate_consistency.json')
noInvoc = bosh.execute("simulate", descriptor).stdout
wInvoc = bosh.execute("simulate", descriptor, "-i",
bosh.example(descriptor)).stdout
6D47 self.assertEqual(noInvoc, wInvoc)

def test_consistency_withAndWithout_invoc_withConfigFile(self):
descriptor = os.path.join(os.path.split(bfile)[0],
'schema/examples/'
'test_simulate_consistency_configFile.json')
invoc = "tmpInvoc.json"
config = "tmpConfig.toml"
wInvocCommand = ("bosh example {0}" +
" > {1} " +
" && bosh exec simulate {0} -i {1}").format(descriptor,
invoc)
noInvocCommand = "bosh exec simulate {0}".format(descriptor, invoc)

subprocess.call(wInvocCommand, shell=True)
with open(config, "r+") as configFile:
wInvoc = configFile.readlines()
os.remove(config)
os.remove(invoc)

subprocess.call(noInvocCommand, shell=True)
with open(config, "r+") as configFile:
noInvoc = configFile.readlines()
os.remove(config)

self.assertEqual(wInvoc, noInvoc)
0