From 31f871a37f84e95de129164dfa9006c340bb36c1 Mon Sep 17 00:00:00 2001 From: Antoine Catton <acatton@tiolive.com> Date: Thu, 11 Aug 2011 14:05:12 +0200 Subject: [PATCH] Adding test_one_succeeding_one_timing_out_promises --- slapos/tests/slapgrid.py | 69 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/slapos/tests/slapgrid.py b/slapos/tests/slapgrid.py index 40c96cdf17..f68618cc5e 100644 --- a/slapos/tests/slapgrid.py +++ b/slapos/tests/slapgrid.py @@ -787,3 +787,72 @@ exit 127""" % {'worked_file': worked_file_failed}) self.assertTrue(os.path.isfile(worked_file_failed)) self.assertEquals(self.error, 1) + + def test_one_succeeding_one_timing_out_promises(self): + + def server_response(self_httplib, path, method, body, header): + parsed_url = urlparse.urlparse(path.lstrip('/')) + + if method == 'GET': + parsed_qs = urlparse.parse_qs(parsed_url.query) + else: + parsed_qs = urlparse.parse_qs(body) + + if parsed_url.path == 'getComputerInformation' and \ + 'computer_id' in parsed_qs: + slap_computer = slapos.slap.Computer(parsed_qs['computer_id'][0]) + slap_computer._software_release_list = [] + partition = slapos.slap.ComputerPartition(parsed_qs['computer_id'][0], + '0') + partition._need_modification = True + sr = slapos.slap.SoftwareRelease() + sr._software_release = 'http://sr/' + partition._software_release_document = sr + partition._requested_state = 'stopped' + slap_computer._computer_partition_list = [partition] + return (200, {}, xml_marshaller.xml_marshaller.dumps(slap_computer)) + if parsed_url.path == 'softwareInstanceError' and \ + method == 'POST' and 'computer_partition_id' in parsed_qs: + self.error += 1 + # XXX: Hardcoded dropPrivileges line ignore + 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, {}, '') + else: + return (404, {}, '') + + httplib.HTTPConnection._callback = server_response + self.fake_waiting_time = 0.2 + self.error = 0 + + instance_path = self._create_instance('0') + software_hash = self._bootstrap() + + promise_path = os.path.join(instance_path, 'etc', 'promise') + os.makedirs(promise_path) + + succeed = os.path.join(promise_path, 'succeed') + worked_file_succeed = os.path.join(instance_path, 'succeed_worked') + with open(succeed, 'w') as f: + f.write("""#!/usr/bin/env sh +touch "%(worked_file)s" +exit 0""" % {'worked_file': worked_file_succeed}) + os.chmod(succeed, 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(os.path.isfile(worked_file_succeed)) + self.assertTrue(os.path.isfile(worked_file_timeout)) + + self.assertEquals(self.error, 1) + -- 2.30.9