Commit 5021ae95 authored by Antoine Catton's avatar Antoine Catton

Using a lock file to be sure of the order of failing/timing out and

success
parent 31f871a3
...@@ -766,25 +766,23 @@ exit 0""" % {'worked_file': worked_file_2}) ...@@ -766,25 +766,23 @@ exit 0""" % {'worked_file': worked_file_2})
promise_path = os.path.join(instance_path, 'etc', 'promise') promise_path = os.path.join(instance_path, 'etc', 'promise')
os.makedirs(promise_path) os.makedirs(promise_path)
succeed = os.path.join(promise_path, 'succeed') promises_files = []
worked_file_succeed = os.path.join(instance_path, 'succeed_worked') for i in range(2):
with open(succeed, 'w') as f: promise = os.path.join(promise_path, 'promise_%d')
f.write("""#!/usr/bin/env sh promises_files.append(promise)
worked_file = os.path.join(instance_path, 'promise_worked_%d')
lockfile = os.path.join(instance_path, 'lock')
with open(promise, 'w') as f:
f.write("""#!/usr/bin/env sh
touch "%(worked_file)s" touch "%(worked_file)s"
exit 0""" % {'worked_file': worked_file_succeed}) [[ ! -f "%(lockfile)s" ]] || { touch "%(lockfile)s" ; exit 127 }
os.chmod(succeed, 0777) exit 0""" % {'worked_file': worked_file, 'lockfile': lockfile})
os.chmod(promise, 0777)
fail = os.path.join(promise_path, 'fail')
worked_file_failed = os.path.join(instance_path, 'fail_worked')
with open(fail, 'w') as f:
f.write("""#!/usr/bin/env sh
touch "%(worked_file)s"
exit 127""" % {'worked_file': worked_file_failed})
os.chmod(fail, 0777)
self.assertTrue(self.grid.processComputerPartitionList()) self.assertTrue(self.grid.processComputerPartitionList())
self.assertTrue(os.path.isfile(worked_file_succeed)) for file_ in promises_files:
self.assertTrue(os.path.isfile(worked_file_failed)) self.assertTrue(os.path.isfile(file_))
self.assertEquals(self.error, 1) self.assertEquals(self.error, 1)
...@@ -814,11 +812,7 @@ exit 127""" % {'worked_file': worked_file_failed}) ...@@ -814,11 +812,7 @@ exit 127""" % {'worked_file': worked_file_failed})
if parsed_url.path == 'softwareInstanceError' and \ if parsed_url.path == 'softwareInstanceError' and \
method == 'POST' and 'computer_partition_id' in parsed_qs: method == 'POST' and 'computer_partition_id' in parsed_qs:
self.error += 1 self.error += 1
# XXX: Hardcoded dropPrivileges line ignore self.assertEqual(parsed_qs['computer_partition_id'][0], '0')
error_log = '\n'.join([line for line in parsed_qs['error_log'][0].splitlines()
if 'dropPrivileges' not in line])
# end XXX
self.assertEqual(error_log, 'The promise %r timed out' % 'timeout')
return (200, {}, '') return (200, {}, '')
else: else:
return (404, {}, '') return (404, {}, '')
...@@ -833,26 +827,23 @@ exit 127""" % {'worked_file': worked_file_failed}) ...@@ -833,26 +827,23 @@ exit 127""" % {'worked_file': worked_file_failed})
promise_path = os.path.join(instance_path, 'etc', 'promise') promise_path = os.path.join(instance_path, 'etc', 'promise')
os.makedirs(promise_path) os.makedirs(promise_path)
succeed = os.path.join(promise_path, 'succeed') promises_files = []
worked_file_succeed = os.path.join(instance_path, 'succeed_worked') for i in range(2):
with open(succeed, 'w') as f: promise = os.path.join(promise_path, 'promise_%d')
f.write("""#!/usr/bin/env sh promises_files.append(promise)
worked_file = os.path.join(instance_path, 'promise_worked_%d')
lockfile = os.path.join(instance_path, 'lock')
with open(promise, 'w') as f:
f.write("""#!/usr/bin/env sh
touch "%(worked_file)s" touch "%(worked_file)s"
exit 0""" % {'worked_file': worked_file_succeed}) [[ ! -f "%(lockfile)s" ]] || { touch "%(lockfile)s" ; sleep 5 }
os.chmod(succeed, 0777) exit 0""" % {'worked_file': worked_file, 'lockfile': lockfile})
os.chmod(promise, 0777)
timeout = os.path.join(promise_path, 'timeout')
worked_file_timeout = os.path.join(instance_path, 'timeout_worked')
with open(timeout, 'w') as f:
f.write("""#!/usr/bin/env sh
touch "%(worked_file)s"
sleep 5
exit 0""" % {'worked_file': worked_file_timeout})
os.chmod(timeout, 0777)
self.assertTrue(self.grid.processComputerPartitionList()) self.assertTrue(self.grid.processComputerPartitionList())
self.assertTrue(os.path.isfile(worked_file_succeed)) for file_ in promises_files:
self.assertTrue(os.path.isfile(worked_file_timeout)) self.assertTrue(os.path.isfile(file_))
self.assertEquals(self.error, 1) self.assertEquals(self.error, 1)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment