Commit 3e48b13d authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

Added message sequence verification for TestSlapgridCPWithMaster tests

parent 45a87f19
...@@ -156,8 +156,9 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase): ...@@ -156,8 +156,9 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
self.assertSortedListEqual(os.listdir(self.software_root), []) self.assertSortedListEqual(os.listdir(self.software_root), [])
def test_one_partition(self): def test_one_partition(self):
def server_response(self, path, method, body, header): def server_response(self_httplib, path, method, body, header):
parsed_url = urlparse.urlparse(path.lstrip('/')) parsed_url = urlparse.urlparse(path.lstrip('/'))
self.sequence.append(parsed_url.path)
if method == 'GET': if method == 'GET':
parsed_qs = urlparse.parse_qs(parsed_url.query) parsed_qs = urlparse.parse_qs(parsed_url.query)
else: else:
...@@ -183,7 +184,10 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase): ...@@ -183,7 +184,10 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
return (200, {}, '') return (200, {}, '')
else: else:
return (404, {}, '') return (404, {}, '')
httplib.HTTPConnection._callback = server_response httplib.HTTPConnection._callback = server_response
self.sequence = []
os.mkdir(self.software_root) os.mkdir(self.software_root)
os.mkdir(self.instance_root) os.mkdir(self.instance_root)
partition_path = os.path.join(self.instance_root, '0') partition_path = os.path.join(self.instance_root, '0')
...@@ -206,11 +210,15 @@ touch worked""") ...@@ -206,11 +210,15 @@ touch worked""")
'buildout.cfg']) 'buildout.cfg'])
self.assertSortedListEqual(os.listdir(self.software_root), self.assertSortedListEqual(os.listdir(self.software_root),
[software_hash]) [software_hash])
self.assertEqual(self.sequence,
['getFullComputerInformation', 'availableComputerPartition',
'stoppedComputerPartition'])
def test_one_partition_started(self): def test_one_partition_started(self):
def server_response(self, path, method, body, header): def server_response(self_httplib, path, method, body, header):
parsed_url = urlparse.urlparse(path.lstrip('/')) parsed_url = urlparse.urlparse(path.lstrip('/'))
self.sequence.append(parsed_url.path)
if method == 'GET': if method == 'GET':
parsed_qs = urlparse.parse_qs(parsed_url.query) parsed_qs = urlparse.parse_qs(parsed_url.query)
else: else:
...@@ -233,11 +241,16 @@ touch worked""") ...@@ -233,11 +241,16 @@ touch worked""")
return (200, {}, '') return (200, {}, '')
if parsed_url.path == 'startedComputerPartition' and \ if parsed_url.path == 'startedComputerPartition' and \
method == 'POST' and 'computer_partition_id' in parsed_qs: method == 'POST' and 'computer_partition_id' in parsed_qs:
self.assertEqual(parsed_qs['computer_partition_id'][0], '0')
self.started = True
return (200, {}, '') return (200, {}, '')
else: else:
return (404, {}, '') return (404, {}, '')
httplib.HTTPConnection._callback = server_response httplib.HTTPConnection._callback = server_response
self.sequence = []
self.started = False
os.mkdir(self.software_root) os.mkdir(self.software_root)
os.mkdir(self.instance_root) os.mkdir(self.instance_root)
partition_path = os.path.join(self.instance_root, '0') partition_path = os.path.join(self.instance_root, '0')
...@@ -272,11 +285,17 @@ chmod 755 etc/run/wrapper ...@@ -272,11 +285,17 @@ chmod 755 etc/run/wrapper
self.assertTrue('Working' in open(wrapper_log, 'r').read()) self.assertTrue('Working' in open(wrapper_log, 'r').read())
self.assertSortedListEqual(os.listdir(self.software_root), self.assertSortedListEqual(os.listdir(self.software_root),
[software_hash]) [software_hash])
self.assertEqual(self.sequence,
['getFullComputerInformation', 'availableComputerPartition',
'startedComputerPartition'])
self.assertTrue(self.started)
def test_one_partition_started_stopped(self): def test_one_partition_started_stopped(self):
def server_response(self, path, method, body, header): def server_response(self_httplib, path, method, body, header):
parsed_url = urlparse.urlparse(path.lstrip('/')) parsed_url = urlparse.urlparse(path.lstrip('/'))
self.sequence.append(parsed_url.path)
if method == 'GET': if method == 'GET':
parsed_qs = urlparse.parse_qs(parsed_url.query) parsed_qs = urlparse.parse_qs(parsed_url.query)
else: else:
...@@ -299,11 +318,16 @@ chmod 755 etc/run/wrapper ...@@ -299,11 +318,16 @@ chmod 755 etc/run/wrapper
return (200, {}, '') return (200, {}, '')
if parsed_url.path == 'startedComputerPartition' and \ if parsed_url.path == 'startedComputerPartition' and \
method == 'POST' and 'computer_partition_id' in parsed_qs: method == 'POST' and 'computer_partition_id' in parsed_qs:
self.assertEqual(parsed_qs['computer_partition_id'][0], '0')
self.started = True
return (200, {}, '') return (200, {}, '')
else: else:
return (404, {}, '') return (404, {}, '')
httplib.HTTPConnection._callback = server_response httplib.HTTPConnection._callback = server_response
self.started = True
self.sequence = []
os.mkdir(self.software_root) os.mkdir(self.software_root)
os.mkdir(self.instance_root) os.mkdir(self.instance_root)
partition_path = os.path.join(self.instance_root, '0') partition_path = os.path.join(self.instance_root, '0')
...@@ -350,8 +374,13 @@ chmod 755 etc/run/wrapper ...@@ -350,8 +374,13 @@ chmod 755 etc/run/wrapper
self.assertTrue('Working' in open(wrapper_log, 'r').read()) self.assertTrue('Working' in open(wrapper_log, 'r').read())
self.assertSortedListEqual(os.listdir(self.software_root), self.assertSortedListEqual(os.listdir(self.software_root),
[software_hash]) [software_hash])
def server_response(self, path, method, body, header): self.assertEqual(self.sequence,
['getFullComputerInformation', 'availableComputerPartition',
'startedComputerPartition'])
self.assertTrue(self.started)
def server_response(self_httplib, path, method, body, header):
parsed_url = urlparse.urlparse(path.lstrip('/')) parsed_url = urlparse.urlparse(path.lstrip('/'))
self.sequence.append(parsed_url.path)
if method == 'GET': if method == 'GET':
parsed_qs = urlparse.parse_qs(parsed_url.query) parsed_qs = urlparse.parse_qs(parsed_url.query)
else: else:
...@@ -374,11 +403,16 @@ chmod 755 etc/run/wrapper ...@@ -374,11 +403,16 @@ chmod 755 etc/run/wrapper
return (200, {}, '') return (200, {}, '')
if parsed_url.path == 'stoppedComputerPartition' and \ if parsed_url.path == 'stoppedComputerPartition' and \
method == 'POST' and 'computer_partition_id' in parsed_qs: method == 'POST' and 'computer_partition_id' in parsed_qs:
self.assertEqual(parsed_qs['computer_partition_id'][0], '0')
self.stopped = True
return (200, {}, '') return (200, {}, '')
else: else:
return (404, {}, '') return (404, {}, '')
httplib.HTTPConnection._callback = server_response httplib.HTTPConnection._callback = server_response
self.stopped = False
self.sequence = []
self.setSlapgrid() self.setSlapgrid()
self.assertTrue(self.grid.processComputerPartitionList()) self.assertTrue(self.grid.processComputerPartitionList())
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
'var']) 'var'])
...@@ -393,11 +427,17 @@ chmod 755 etc/run/wrapper ...@@ -393,11 +427,17 @@ chmod 755 etc/run/wrapper
break break
time.sleep(0.2) time.sleep(0.2)
self.assertTrue(found) self.assertTrue(found)
self.assertEqual(self.sequence,
['getFullComputerInformation', 'availableComputerPartition',
'stoppedComputerPartition'])
self.assertTrue(self.stopped)
def test_one_partition_stopped_started(self): def test_one_partition_stopped_started(self):
def server_response(self, path, method, body, header): def server_response(self_httplib, path, method, body, header):
parsed_url = urlparse.urlparse(path.lstrip('/')) parsed_url = urlparse.urlparse(path.lstrip('/'))
self.sequence.append(parsed_url.path)
if method == 'GET': if method == 'GET':
parsed_qs = urlparse.parse_qs(parsed_url.query) parsed_qs = urlparse.parse_qs(parsed_url.query)
else: else:
...@@ -420,11 +460,16 @@ chmod 755 etc/run/wrapper ...@@ -420,11 +460,16 @@ chmod 755 etc/run/wrapper
return (200, {}, '') return (200, {}, '')
if parsed_url.path == 'stoppedComputerPartition' and \ if parsed_url.path == 'stoppedComputerPartition' and \
method == 'POST' and 'computer_partition_id' in parsed_qs: method == 'POST' and 'computer_partition_id' in parsed_qs:
self.assertEqual(parsed_qs['computer_partition_id'][0], '0')
self.stopped = True
return (200, {}, '') return (200, {}, '')
else: else:
return (404, {}, '') return (404, {}, '')
httplib.HTTPConnection._callback = server_response httplib.HTTPConnection._callback = server_response
self.stopped = False
self.sequence = []
os.mkdir(self.software_root) os.mkdir(self.software_root)
os.mkdir(self.instance_root) os.mkdir(self.instance_root)
partition_path = os.path.join(self.instance_root, '0') partition_path = os.path.join(self.instance_root, '0')
...@@ -452,9 +497,14 @@ chmod 755 etc/run/wrapper ...@@ -452,9 +497,14 @@ chmod 755 etc/run/wrapper
'buildout.cfg']) 'buildout.cfg'])
self.assertSortedListEqual(os.listdir(self.software_root), self.assertSortedListEqual(os.listdir(self.software_root),
[software_hash]) [software_hash])
self.assertEqual(self.sequence,
['getFullComputerInformation', 'availableComputerPartition',
'stoppedComputerPartition'])
self.assertTrue(self.stopped)
def server_response(self, path, method, body, header): def server_response(self_httplib, path, method, body, header):
parsed_url = urlparse.urlparse(path.lstrip('/')) parsed_url = urlparse.urlparse(path.lstrip('/'))
self.sequence.append(parsed_url.path)
if method == 'GET': if method == 'GET':
parsed_qs = urlparse.parse_qs(parsed_url.query) parsed_qs = urlparse.parse_qs(parsed_url.query)
else: else:
...@@ -482,6 +532,9 @@ chmod 755 etc/run/wrapper ...@@ -482,6 +532,9 @@ chmod 755 etc/run/wrapper
return (404, {}, '') return (404, {}, '')
httplib.HTTPConnection._callback = server_response httplib.HTTPConnection._callback = server_response
self.started = True
self.sequence = []
self.setSlapgrid() self.setSlapgrid()
self.assertTrue(self.grid.processComputerPartitionList()) self.assertTrue(self.grid.processComputerPartitionList())
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
...@@ -499,6 +552,11 @@ chmod 755 etc/run/wrapper ...@@ -499,6 +552,11 @@ chmod 755 etc/run/wrapper
break break
time.sleep(0.2) time.sleep(0.2)
self.assertTrue('Working' in open(wrapper_log, 'r').read()) self.assertTrue('Working' in open(wrapper_log, 'r').read())
self.assertEqual(self.sequence,
['getFullComputerInformation', 'availableComputerPartition',
'startedComputerPartition'])
self.assertTrue(self.started)
class TestSlapgridArgumentTuple(unittest.TestCase): class TestSlapgridArgumentTuple(unittest.TestCase):
""" """
...@@ -981,11 +1039,6 @@ else ...@@ -981,11 +1039,6 @@ else
exit 127 exit 127
fi""" % {'worked_file': worked_file, 'lockfile': lockfile}) fi""" % {'worked_file': worked_file, 'lockfile': lockfile})
os.chmod(promise, 0777) os.chmod(promise, 0777)
print "-------------------------------------------"
print open(promise,'r').read()
print "-------------------------------------------"
self.assertFalse(self.grid.processComputerPartitionList()) self.assertFalse(self.grid.processComputerPartitionList())
for file_ in promises_files: for file_ in promises_files:
self.assertTrue(os.path.isfile(file_)) self.assertTrue(os.path.isfile(file_))
......
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