Commit 7ba3ec4f authored by Xavier Thompson's avatar Xavier Thompson

slapproxy: Add test for forwarded requests entries

parent 61d0e497
...@@ -1781,7 +1781,7 @@ database_uri = %(rootdir)s/lib/external_proxy.db ...@@ -1781,7 +1781,7 @@ database_uri = %(rootdir)s/lib/external_proxy.db
""" """
Test there is no instance on local proxy. Test there is no instance on local proxy.
Test there is instance on external proxy. Test there is instance on external proxy.
Test there is instance reference in external table of databse of local proxy. Test there is instance reference in external table of database of local proxy.
""" """
# Adjust name to match forwarding prefix # Adjust name to match forwarding prefix
name = '%s_%s' % (requester or 'user', name) name = '%s_%s' % (requester or 'user', name)
...@@ -1853,7 +1853,7 @@ database_uri = %(rootdir)s/lib/external_proxy.db ...@@ -1853,7 +1853,7 @@ database_uri = %(rootdir)s/lib/external_proxy.db
def testForwardToMasterInList(self): def testForwardToMasterInList(self):
""" """
Test that explicitely asking a master_url in SLA causes Test that explicitly asking a master_url in SLA causes
proxy to forward request to this master. proxy to forward request to this master.
""" """
dummy_parameter_dict = {'foo': 'bar'} dummy_parameter_dict = {'foo': 'bar'}
...@@ -1871,6 +1871,32 @@ database_uri = %(rootdir)s/lib/external_proxy.db ...@@ -1871,6 +1871,32 @@ database_uri = %(rootdir)s/lib/external_proxy.db
self.external_master_url self.external_master_url
) )
def testForwardToMasterInList_NoDuplicates(self):
"""
Test that multiple explicitly forwarded requests for the same instance
do not result in duplicate entries in the proxy database.
"""
dummy_parameter_dict = {'foo': 'bar'}
instance_reference = 'MyFirstInstance'
self.format_for_number_of_partitions(1)
self.external_proxy_format_for_number_of_partitions(1)
filter_kw = {'master_url': self.external_master_url}
for _ in range(2):
partition = self.request(self.software_release_not_in_list, None, instance_reference, 'slappart0',
filter_kw=filter_kw, partition_parameter_kw=dummy_parameter_dict)
# Explicitly do the relevant test, even if _checkInstanceIsFowarded does it too
entries = slapos.proxy.views.execute_db('forwarded_partition_request', 'SELECT * from %s', db=self.db)
self.assertEqual(len(entries), 1)
self._checkInstanceIsFowarded(instance_reference, 'slappart0', dummy_parameter_dict, self.software_release_not_in_list)
self.assertEqual(
partition._master_url,
self.external_master_url
)
def testForwardToMasterNotInList(self): def testForwardToMasterNotInList(self):
""" """
Test that explicitely asking a master_url in SLA causes Test that explicitely asking a master_url in SLA causes
...@@ -1904,6 +1930,32 @@ database_uri = %(rootdir)s/lib/external_proxy.db ...@@ -1904,6 +1930,32 @@ database_uri = %(rootdir)s/lib/external_proxy.db
self.assertEqual(self.external_software_release, partition.getSoftwareRelease()) self.assertEqual(self.external_software_release, partition.getSoftwareRelease())
self.assertEqual({}, partition.getConnectionParameterDict()) self.assertEqual({}, partition.getConnectionParameterDict())
def testForwardRequest_SoftwareReleaseList_NoDuplicates(self):
"""
Test that multiple automatically forwarded requests for the same instance
do not result in duplicate entries in the proxy database.
"""
dummy_parameter_dict = {'foo': 'bar'}
instance_reference = 'MyFirstInstance'
self.format_for_number_of_partitions(1)
self.external_proxy_format_for_number_of_partitions(1)
for _ in range(2):
partition = self.request(self.external_software_release, None, instance_reference, 'slappart0',
partition_parameter_kw=dummy_parameter_dict)
# Explicitly do the relevant test, even if _checkInstanceIsFowarded does it too
entries = slapos.proxy.views.execute_db('forwarded_partition_request', 'SELECT * from %s', db=self.db)
self.assertEqual(len(entries), 1)
self._checkInstanceIsFowarded(instance_reference, 'slappart0', dummy_parameter_dict, self.external_software_release)
instance_parameter_dict = partition.getInstanceParameterDict()
instance_parameter_dict.pop('timestamp')
self.assertEqual(dummy_parameter_dict, instance_parameter_dict)
self.assertEqual(self.external_software_release, partition.getSoftwareRelease())
self.assertEqual({}, partition.getConnectionParameterDict())
def testForwardRequestFromPartition(self): def testForwardRequestFromPartition(self):
""" """
Test that instance request is forwarded and requested from computer partition. Test that instance request is forwarded and requested from computer partition.
......
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