~landscape/landscape-client/trunk

« back to all changes in this revision

Viewing changes to landscape/broker/exchange.py

Merge landscape-config-dont-restart-twice [f=1376134] [r=benji,tealeg] [a=Free Ekanayaka]
This branch fixes two issues happening when switching a client
between servers.

1) Stop landscape-config from sending the reload_config() command to
   the broker, since the script has already restarted all services
   just a few moments before. This prevents the first exchange from
   happening without the monitor fully started, hence missing the
   server-uuid-change that the broker broadcasts and that the monitor
   is supposed to handle in order to clear the local hash-id map.

2) Make the Exchange downgrade the API server version currently in use
   if it gets a 404 from the server. This can happen for example if
   a client registered against a newer server is switched to an older
   server that doesn't support the same API version that the new one does.

Show diffs side-by-side

added added

removed removed

Lines of Context:
348
348
 
349
349
from twisted.internet.defer import Deferred, succeed
350
350
 
 
351
from landscape.lib.fetch import HTTPCodeError
351
352
from landscape.lib.message import got_next_expected, ANCIENT
352
353
from landscape.lib.versioning import is_version_higher, sort_versions
353
354
from landscape.log import format_delta
354
 
from landscape import SERVER_API, CLIENT_API
 
355
 
 
356
from landscape import DEFAULT_SERVER_API, SERVER_API, CLIENT_API
355
357
 
356
358
 
357
359
class MessageExchange(object):
569
571
                logging.info("Message exchange failed.")
570
572
            exchange_completed()
571
573
 
572
 
        def handle_failure(failure_type, failure_value, failure_tb):
 
574
        def handle_failure(error_class, error, traceback):
573
575
            self._exchanging = False
 
576
            if isinstance(error, HTTPCodeError) and error.http_code == 404:
 
577
                # If we got a 404 HTTP error it could be that we're trying to
 
578
                # speak a server API version that the server does not support,
 
579
                # e.g. this client was pointed at a different server. We'll to
 
580
                # downgrade to the least possible server API version and try
 
581
                # again.
 
582
                if self._message_store.get_server_api() != DEFAULT_SERVER_API:
 
583
                    self._message_store.set_server_api(DEFAULT_SERVER_API)
 
584
                    self.exchange()
 
585
                    return
574
586
            self._reactor.fire("exchange-failed")
575
587
            self._message_store.record_failure(int(self._reactor.time()))
576
588
            logging.info("Message exchange failed.")