Commit fbb680f5 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

Improved slapproxy tests

parent bcac5a39
...@@ -214,30 +214,13 @@ class MasterMixin(BasicMixin): ...@@ -214,30 +214,13 @@ class MasterMixin(BasicMixin):
'_parameter_dict', None) '_parameter_dict', None)
return computer_partition return computer_partition
def setComputerPartitionConnectionXml(self, instance): def setConnectionDict(self, partition_id,
""" connection_dict, slave_reference=None):
Will send instance connection information to server self.app.post('/setComputerPartitionConnectionXml', data = {
including from slaves in this partition 'computer_id': self.computer_id,
""" 'computer_partition_id': partition_id,
# Will post information about slaves 'connection_xml': xml_marshaller.xml_marshaller.dumps(connection_dict),
for slave in instance._parameter_dict['slave_instance_list']: 'slave_reference': slave_reference})
request_dict = {
'slave_reference': slave['slave_reference'],
'computer_partition_id': instance._partition_id,
'connection_xml': xml_marshaller.xml_marshaller.dumps(
instance._connection_dict),
}
self.app.post('/setComputerPartitionConnectionXml',
data = request_dict)
# Will post information about instance
request_dict = {
'slave_reference': None,
'computer_partition_id': instance._partition_id,
'connection_xml': xml_marshaller.xml_marshaller.dumps(
instance._connection_dict),
}
self.app.post('/setComputerPartitionConnectionXml',
data = request_dict)
class TestRequest (MasterMixin, unittest.TestCase): class TestRequest (MasterMixin, unittest.TestCase):
...@@ -311,18 +294,23 @@ class TestRequest (MasterMixin, unittest.TestCase): ...@@ -311,18 +294,23 @@ class TestRequest (MasterMixin, unittest.TestCase):
""" """
Successfull request slave instance follow these steps: Successfull request slave instance follow these steps:
1. Provide one corresponding partition 1. Provide one corresponding partition
2. Ask for Slave instance. Error is raise because it is not ready 2. Ask for Slave instance. But no connection parameters
But slave is added to Master Instance slave list But slave is added to Master Instance slave list
3. Master Instance get updated information (including slave list) 3. Master Instance get updated information (including slave list)
4. Master instance post information about slaves and itself 4. Master instance post information about slave connection parameters
5. Ask for slave instance is successfull and return a computer instance 5. Ask for slave instance is successfull and return a computer instance
""" """
self.add_free_partition(6) self.add_free_partition(6)
# Provide partition # Provide partition
master_partition_id = self.request('http://sr//', None, master_partition_id = self.request('http://sr//', None,
'Maria', 'slappart4')._partition_id 'Maria', 'slappart4')._partition_id
# Failed request of slave instance # First request of slave instance
self.request('http://sr//', None, 'Maria', 'slappart2', shared=True) name = 'Maria'
requester = 'slappart2'
our_slave = self.request('http://sr//', None,
name, requester, shared=True)
self.assertIsInstance(our_slave, slapos.slap.ComputerPartition)
self.assertEqual(our_slave._connection_dict,{})
# Get updated information for master partition # Get updated information for master partition
rv = self.app.get('/getFullComputerInformation?computer_id=' rv = self.app.get('/getFullComputerInformation?computer_id='
+ self.computer_id) + self.computer_id)
...@@ -331,8 +319,17 @@ class TestRequest (MasterMixin, unittest.TestCase): ...@@ -331,8 +319,17 @@ class TestRequest (MasterMixin, unittest.TestCase):
if instance._partition_id == master_partition_id: if instance._partition_id == master_partition_id:
master_partition = instance master_partition = instance
# Send information about slave # Send information about slave
self.setComputerPartitionConnectionXml(master_partition) for slave in master_partition._parameter_dict.get('slave_instance_list'):
# Successfull slave request print slave
self.assertIsInstance( slave_reference=slave.get('slave_reference')
self.request('http://sr//', None, 'Maria', 'slappart2', shared=True), # Check we got the right slave
slapos.slap.ComputerPartition) if requester and name in slave_reference:
slave_address = {'url':'%s.master.com' % slave_reference}
self.setConnectionDict(partition_id=master_partition._partition_id,
connection_dict=slave_address,
slave_reference=slave_reference)
# Successfull slave request with connection parameters
our_slave = self.request('http://sr//', None,
name, requester, shared=True)
self.assertIsInstance(our_slave, slapos.slap.ComputerPartition)
self.assertEqual(slave_address, our_slave._connection_dict)
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