Commit 5eb61fc3 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Titouan Soulard

slapgrid: Update retrieve certificate to specific record

parent b87591ba
......@@ -501,25 +501,15 @@ class Partition(object):
available=bytes2human(available),
required=bytes2human(required)))
def _updateCertificate(self):
def _updateCertificate(self, partition_certificates):
if not self.key_file or not self.cert_file:
# Certificate files are unset, skip.
return
if self.api_backward_compatibility:
try:
partition_certificate = self.computer_partition["slap_partition"].getCertificate()
self.computer_partition["X509"] = {}
self.computer_partition["X509"]["certificate"] = partition_certificate["certificate"]
self.computer_partition["X509"]["key"] = partition_certificate["key"]
except NotFoundError:
raise NotFoundError('Partition %s is not known by SlapOS Master.' %
self.partition_id)
uid, gid = self.getUserGroupId()
for name, path in [('certificate', self.cert_file), ('key', self.key_file)]:
new_content = self.computer_partition["X509"][name]
new_content = partition_certificates[name]
old_content = None
if os.path.exists(path):
with open(path) as f:
......
......@@ -1175,6 +1175,19 @@ stderr_logfile_backups=1
self._checkAddFirewallRules(computer_partition.get("compute_partition_id"),
cmd_list, add=add_rules)
def retrieveCertificates(self, computer_partition):
if not self.api_backward_compatibility:
partition_certificates = self.slap.jio_api_connector.get({
"portal_type": "Software Instance Certificate Record",
"reference": computer_partition.get("reference"),
})
else:
try:
partition_certificates = computer_partition["slap_partition"].getCertificate()
except NotFoundError:
raise NotFoundError('Partition %s is not known by SlapOS Master.' % computer_partition.get("reference"))
return partition_certificates
def _checkPromiseAnomaly(self, local_partition, computer_partition):
partition_access_status = computer_partition.get("access_status_message", "")
status_error = False
......@@ -1187,11 +1200,11 @@ stderr_logfile_backups=1
except PromiseError as e:
self.logger.error(e)
if partition_access_status is None or not status_error:
local_partition._updateCertificate()
local_partition._updateCertificate(self.retrieveCertificates(computer_partition))
self.sendPartitionError(computer_partition, e, logger=self.logger)
else:
if partition_access_status is None or status_error:
local_partition._updateCertificate()
local_partition._updateCertificate(self.retrieveCertificates(computer_partition))
if not self.api_backward_compatibility:
self.slap.jio_api_connector.put({
"portal_type": "Software Instance",
......@@ -1408,7 +1421,7 @@ stderr_logfile_backups=1
self.logger.info(' jIO API used: %s' % (not self.api_backward_compatibility))
# Update certifcate at late as possible
local_partition._updateCertificate()
local_partition._updateCertificate(self.retrieveCertificates(computer_partition))
# XXX this line breaks 37 tests
# self.logger.info(' Instance type: %s' % computer_partition.get("software_type"))
......@@ -2085,7 +2098,7 @@ stderr_logfile_backups=1
api_backward_compatibility=self.api_backward_compatibility,
)
local_partition.stop()
local_partition._updateCertificate()
local_partition._updateCertificate(self.retrieveCertificates(computer_partition))
try:
if not self.api_backward_compatibility:
self.slap.jio_api_connector.put({
......
......@@ -580,10 +580,6 @@ class ComputerForTest(object):
"root_instance_title": requested_instance.name,
"ip_list": requested_instance.ip_list,
"full_ip_list": requested_instance.full_ip_list,
"X509": {
"certificate": requested_instance.certificate,
"key": requested_instance.key
},
"sla_parameters": requested_instance.filter_dict,
"compute_node_id": None,
"compute_partition_id": requested_instance.name,
......@@ -597,6 +593,21 @@ class ComputerForTest(object):
"message": "No document found with parameters: %s" % reference,
"name": "NotFound",
})
elif content["portal_type"] == "Software Instance Certificate Record":
reference = content["reference"]
requested_instance = None
for instance in self.instance_list:
if instance.name == reference:
requested_instance = instance
break
if requested_instance:
# We don't need to check certificates are being retrieved
return json.dumps({
"reference": requested_instance.name,
"certificate": requested_instance.certificate,
"key": requested_instance.key,
"portal_type": "Software Instance Certificate Record",
})
if req.method == 'GET':
if url.path == "/getHateoasUrl":
return ""
......@@ -849,7 +860,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
'software_release', 'worked', '.slapos-retention-lock-delay'])
six.assertCountEqual(self, os.listdir(self.software_root), [instance.software.software_hash])
self.assertEqual(computer.sequence,
['/api/allDocs/', '/api/get/', '/api/put/'])
['/api/allDocs/', '/api/get/', '/api/get/', '/api/put/'])
self.assertEqual(instance.sequence[1][1]["reported_state"], 'stopped')
self.assertEqual(instance.state, 'stopped')
......@@ -868,7 +879,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
'software_release', 'worked', '.slapos-retention-lock-delay'])
six.assertCountEqual(self, os.listdir(self.software_root), [instance.software.software_hash])
self.assertEqual(computer.sequence,
['/api/allDocs/', '/api/get/', '/api/put/'])
['/api/allDocs/', '/api/get/', '/api/get/', '/api/put/'])
self.assertEqual(instance.sequence[1][1]["reported_state"], 'stopped')
self.assertEqual(instance.state, 'stopped')
......@@ -903,7 +914,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
self.assertLogContent(wrapper_log, 'Working')
six.assertCountEqual(self, os.listdir(self.software_root), [partition.software.software_hash])
self.assertEqual(computer.sequence,
['/api/allDocs/', '/api/get/', '/api/put/'])
['/api/allDocs/', '/api/get/', '/api/get/', '/api/put/'])
self.assertEqual(partition.sequence[1][1]["reported_state"], 'started')
self.assertEqual(partition.state, 'started')
......@@ -922,7 +933,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
self.assertLogContent(wrapper_log, 'Working')
six.assertCountEqual(self, os.listdir(self.software_root), [partition.software.software_hash])
self.assertEqual(computer.sequence,
['/api/allDocs/', '/api/get/', '/api/put/'])
['/api/allDocs/', '/api/get/', '/api/get/', '/api/put/'])
self.assertEqual(partition.sequence[1][1]["reported_state"], 'started')
self.assertEqual(partition.state, 'started')
......@@ -937,8 +948,8 @@ exit 1
'etc', 'software_release', 'worked',
'.slapos-retention-lock-delay', '.slapgrid-0-error.log'])
self.assertEqual(computer.sequence,
['/api/allDocs/', '/api/get/', '/api/put/', '/getHateoasUrl',
'/api/allDocs/', '/api/get/', '/api/put/'])
['/api/allDocs/', '/api/get/', '/api/get/', '/api/put/', '/getHateoasUrl',
'/api/allDocs/', '/api/get/', '/api/get/', '/api/put/'])
self.assertEqual(instance.sequence[3][1]["reported_state"], 'error')
self.assertEqual(instance.state, 'started')
self.assertTrue(instance.error_log.startswith("Failed to run buildout profile in direct"))
......@@ -978,7 +989,7 @@ chmod 755 etc/run/wrapper
self.assertLogContent(wrapper_log, 'Working')
six.assertCountEqual(self, os.listdir(self.software_root), [instance.software.software_hash])
self.assertEqual(computer.sequence,
['/api/allDocs/', '/api/get/', '/api/put/'])
['/api/allDocs/', '/api/get/', '/api/get/', '/api/put/'])
self.assertEqual(instance.sequence[1][1]["reported_state"], 'started')
self.assertEqual(instance.state, 'started')
......@@ -992,7 +1003,7 @@ chmod 755 etc/run/wrapper
self.assertLogContent(wrapper_log, 'Signal handler called with signal 15')
self.assertEqual(computer.sequence,
['/getHateoasUrl',
'/api/allDocs/', '/api/get/', '/api/put/'])
'/api/allDocs/', '/api/get/', '/api/get/', '/api/put/'])
self.assertEqual(instance.sequence[3][1]["reported_state"], 'stopped')
self.assertEqual(instance.state, 'stopped')
......@@ -1038,6 +1049,7 @@ chmod 755 etc/run/wrapper
[instance.software.software_hash])
self.assertEqual(computer.sequence,
['/api/allDocs/',
'/api/get/',
'/api/get/',
'/api/put/'])
self.assertEqual(instance.sequence[1][1]["reported_state"], 'started')
......@@ -1059,6 +1071,7 @@ exit 1
['/getHateoasUrl',
'/api/allDocs/',
'/api/get/',
'/api/get/',
'/api/put/'])
self.assertEqual(instance.sequence[3][1]["reported_state"], 'error')
self.assertEqual(instance.state, 'started')
......@@ -1080,6 +1093,7 @@ exit 1
[instance.software.software_hash])
self.assertEqual(computer.sequence,
['/api/allDocs/',
'/api/get/',
'/api/get/',
'/api/put/'])
self.assertEqual(instance.sequence[1][1]["reported_state"], 'stopped')
......@@ -1101,6 +1115,7 @@ exit 1
['/getHateoasUrl',
'/api/allDocs/',
'/api/get/',
'/api/get/',
'/api/put/'])
self.assertEqual(instance.sequence[3][1]["reported_state"], 'started')
self.assertEqual('started', instance.state)
......@@ -1127,6 +1142,7 @@ exit 1
six.assertCountEqual(self, os.listdir(self.software_root), [instance.software.software_hash])
self.assertEqual(computer.sequence,
['/api/allDocs/',
'/api/get/',
'/api/get/',
'/api/put/'])
self.assertEqual(instance.sequence[1][1]["reported_state"], 'stopped')
......@@ -2194,6 +2210,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
six.assertCountEqual(self, os.listdir(self.software_root), [instance.software.software_hash])
self.assertEqual(computer.sequence,
['/api/allDocs/',
'/api/get/',
'/api/get/',
'/api/put/'])
self.assertEqual(instance.sequence[1][1]["reported_state"], 'started')
......@@ -2217,6 +2234,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self.assertEqual(computer.sequence,
['/api/allDocs/',
'/api/get/',
'/api/get/',
'/api/put/',
'/api/put/'])
......@@ -2252,6 +2270,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self.assertEqual(computer.sequence,
['/api/allDocs/',
'/api/get/',
'/api/get/',
'/api/put/',
'/api/put/'])
......@@ -2278,6 +2297,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
six.assertCountEqual(self, os.listdir(self.software_root), [instance.software.software_hash])
self.assertEqual(computer.sequence,
['/api/allDocs/',
'/api/get/',
'/api/get/',
'/api/put/'])
self.assertEqual(instance.sequence[1][1]["reported_state"], 'started')
......@@ -3171,6 +3191,7 @@ exit 0
'etc', 'software_release', 'worked', '.slapos-retention-lock-delay'])
self.assertEqual(computer.sequence,
['/api/allDocs/',
'/api/get/',
'/api/get/',
'/api/put/'])
self.assertEqual(partition.sequence[1][1]["reported_state"], 'started')
......@@ -3451,7 +3472,7 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.computer.sequence,
['/api/allDocs/', '/api/get/', '/api/put/'])
['/api/allDocs/', '/api/get/', '/api/get/', '/api/put/'])
self.assertEqual(self.partition.sequence[1][1]["reported_state"], 'started')
self.assertEqual(self.partition.state, 'started')
......@@ -3527,9 +3548,11 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
self.assertEqual(self.computer.sequence,
['/api/allDocs/',
'/api/get/',
'/api/get/',
'/api/put/',
'/api/get/',
'/api/get/',
'/api/put/'])
self.assertEqual(self.partition.sequence[1][1]["reported_state"], 'started')
self.assertEqual(self.partition.sequence[3][1]["reported_state"], 'started')
......@@ -4100,7 +4123,7 @@ class TestSlapgridManagerLifecycle(MasterMixin, unittest.TestCase):
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.computer.sequence,
['/api/allDocs/', '/api/get/', '/api/put/'])
['/api/allDocs/', '/api/get/', '/api/get/', '/api/put/'])
self.assertEqual(partition.sequence[1][1]["reported_state"], 'started')
self.assertEqual(partition.state, 'started')
......
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