Commit 202a9bcd authored by Rafael Monnerat's avatar Rafael Monnerat

core: Update certificates as late as possible

  This changes aims minimize the unecessary accessed to master while the
  instance is going to be skipped to process or won't post informations to master.

  This in best cases reduces access from 1+n to 1 while n = number of used partitions.
parent c56ff8b7
Pipeline #16763 failed with stage
in 0 seconds
...@@ -452,7 +452,6 @@ class Partition(object): ...@@ -452,7 +452,6 @@ class Partition(object):
self.partition_id + '.key') self.partition_id + '.key')
self.cert_file = os.path.join(certificate_repository_path, self.cert_file = os.path.join(certificate_repository_path,
self.partition_id + '.crt') self.partition_id + '.crt')
self._updateCertificate()
try: try:
self.retention_delay = float(retention_delay) self.retention_delay = float(retention_delay)
...@@ -485,6 +484,9 @@ class Partition(object): ...@@ -485,6 +484,9 @@ class Partition(object):
required=bytes2human(required))) required=bytes2human(required)))
def _updateCertificate(self): def _updateCertificate(self):
if getattr(self, "key_file", None) is None:
return
try: try:
partition_certificate = self.computer_partition.getCertificate() partition_certificate = self.computer_partition.getCertificate()
except NotFoundError: except NotFoundError:
......
...@@ -954,9 +954,11 @@ stderr_logfile_backups=1 ...@@ -954,9 +954,11 @@ stderr_logfile_backups=1
except PromiseError as e: except PromiseError as e:
self.logger.error(e) self.logger.error(e)
if partition_access_status is None or not status_error: if partition_access_status is None or not status_error:
local_partition._updateCertificate()
computer_partition.error(e, logger=self.logger) computer_partition.error(e, logger=self.logger)
else: else:
if partition_access_status is None or status_error: if partition_access_status is None or status_error:
local_partition._updateCertificate()
computer_partition.started() computer_partition.started()
def processPromise(self, computer_partition): def processPromise(self, computer_partition):
...@@ -1184,6 +1186,9 @@ stderr_logfile_backups=1 ...@@ -1184,6 +1186,9 @@ stderr_logfile_backups=1
self.logger.info(' Software path: %s' % software_path) self.logger.info(' Software path: %s' % software_path)
self.logger.info(' Instance path: %s' % instance_path) self.logger.info(' Instance path: %s' % instance_path)
# Update certifcate at late as possible
local_partition._updateCertificate()
# XXX this line breaks 37 tests # XXX this line breaks 37 tests
# self.logger.info(' Instance type: %s' % computer_partition.getType()) # self.logger.info(' Instance type: %s' % computer_partition.getType())
self.logger.info(' Instance status: %s' % computer_partition_state) self.logger.info(' Instance status: %s' % computer_partition_state)
...@@ -1788,6 +1793,7 @@ stderr_logfile_backups=1 ...@@ -1788,6 +1793,7 @@ stderr_logfile_backups=1
ipv4_global_network=self.ipv4_global_network, ipv4_global_network=self.ipv4_global_network,
) )
local_partition.stop() local_partition.stop()
local_partition._updateCertificate()
try: try:
computer_partition.stopped() computer_partition.stopped()
except (SystemExit, KeyboardInterrupt): except (SystemExit, KeyboardInterrupt):
......
  • Isn't it the cause for test failures like https://erp5js.nexedi.net/#/test_result_module/20210728-155A30071/18 ?

    2021-07-29 00:14:56 slapos[91569] ERROR 
    Traceback (most recent call last):
      File "/srv/slapgrid/slappart16/srv/testnode/cvr/soft/821aa19e41adea2f5866bc0579f61ba8/parts/slapos.core-repository/slapos/grid/slapgrid.py", line 1796, in agregateAndSendUsage
        local_partition._updateCertificate()
      File "/srv/slapgrid/slappart16/srv/testnode/cvr/soft/821aa19e41adea2f5866bc0579f61ba8/parts/slapos.core-repository/slapos/grid/SlapObject.py", line 510, in _updateCertificate
        with os.fdopen(os.open(path, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o400), 'wb') as fout:
    FileNotFoundError: [Errno 2] No such file or directory: ''
    2021-07-29 00:14:56 slapos[91569] INFO Finished usage reports.
    ERROR
  • mentioned in commit ace5b33b

    Toggle commit list
  • mentioned in commit 3a267a34

    Toggle commit list
  • mentioned in merge request !321 (merged)

    Toggle commit list
  • mentioned in commit df764e0a

    Toggle commit list
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