def run_with_conductor(daemon_mode, settings): logger.debug('edmigrate main program has started') url = get_broker_url(settings) celery.conf.update(BROKER_URL=url) broker_use_ssl = get_broker_use_ssl(settings) if broker_use_ssl is not False: celery.conf.update(BROKER_USE_SSL=broker_use_ssl) connect = Connection(url, ssl=broker_use_ssl) logger.debug('connection: ' + url) consumerThread = ConsumerThread(connect) try: consumerThread.start() if daemon_mode: replication_lag_tolerance = settings.getint(Constants.REPMGR_ADMIN_REPLICATION_LAG_TOLERANCE, 100) apply_lag_tolerance = settings.getint(Constants.REPMGR_ADMIN_APPLY_LAG_TOLERANCE, 100) time_lag_tolerance = settings.getint(Constants.REPMGR_ADMIN_TIME_LAG_TOLERANCE, 100) interval_check = settings.getint(Constants.REPMGR_ADMIN_CHECK_INTERVAL, 1800) replicationAdminMonitor = ReplicationAdminMonitor(replication_lag_tolerance=replication_lag_tolerance, apply_lag_tolerance=apply_lag_tolerance, time_lag_tolerance=time_lag_tolerance, interval_check=interval_check) run_cron_migrate(settings) replicationAdminMonitor.start() consumerThread.join() else: migrate_task(settings) consumerThread.stop() except KeyboardInterrupt: logger.debug('terminated by a user') os._exit(0) except Exception as e: logger.error(e) os._exit(1) logger.debug('exiting edmigrate main program')
def setUpClass(cls): Unittest_with_player.setUpClass() settings = {'migrate.celery.CELERY_ALWAYS_EAGER': True} setup_celery(settings) Test._connection = Connection(get_broker_url()) Test._queue = Test._connection.SimpleQueue(unittest_with_player.queue, no_ack=True) conductor.logger = MockLogger('test')
def setUp(self): # clean up singleton durign testing Player._instances.clear() self.hostname = 'localhost' self.cluster = 'test_cluster' self.routing_key = Constants.CONDUCTOR_ROUTING_KEY self.connection = Connection(get_broker_url()) self.exchange = Exchange(Constants.CONDUCTOR_EXCHANGE) # turn on mocket Mocket.enable()
def __init__(self): self.logger = None self.admin_logger = self.logger self.connection = Connection(get_broker_url()) self.exchange = exchange self.routing_key = 'test.test' self.hostname = 'localhost' self.node_id = 222 self.COMMAND_HANDLERS = { Constants.COMMAND_REGISTER_PLAYER: self.register_player, Constants.COMMAND_START_REPLICATION: self.connect_master, Constants.COMMAND_STOP_REPLICATION: self.disconnect_master, Constants.COMMAND_CONNECT_PGPOOL: self.connect_pgpool, Constants.COMMAND_DISCONNECT_PGPOOL: self.disconnect_pgpool, Constants.COMMAND_RESET_PLAYERS: self.reset_players }
def __init__(self, connection=Connection(get_broker_url(), ssl=get_setting(Config.BROKER_USE_SSL)), exchange=conductor.exchange, routing_key=Constants.CONDUCTOR_ROUTING_KEY): self.connection = connection self.exchange = exchange self.routing_key = routing_key self.COMMAND_HANDLERS = { Constants.COMMAND_REGISTER_PLAYER: self.register_player, Constants.COMMAND_START_REPLICATION: self.connect_master, Constants.COMMAND_STOP_REPLICATION: self.disconnect_master, Constants.COMMAND_CONNECT_PGPOOL: self.connect_pgpool, Constants.COMMAND_DISCONNECT_PGPOOL: self.disconnect_pgpool, Constants.COMMAND_RESET_PLAYERS: self.reset_players } self.hostname = socket.gethostname() self.node_id = get_node_id_from_hostname(self.hostname) self.master_hostname = get_my_master_by_id(self.node_id)
def run_with_conductor(daemon_mode, settings): logger.debug('edmigrate main program has started') url = get_broker_url(settings) celery.conf.update(BROKER_URL=url) broker_use_ssl = get_broker_use_ssl(settings) if broker_use_ssl is not False: celery.conf.update(BROKER_USE_SSL=broker_use_ssl) connect = Connection(url, ssl=broker_use_ssl) logger.debug('connection: ' + url) consumerThread = ConsumerThread(connect) try: consumerThread.start() if daemon_mode: replication_lag_tolerance = settings.getint( Constants.REPMGR_ADMIN_REPLICATION_LAG_TOLERANCE, 100) apply_lag_tolerance = settings.getint( Constants.REPMGR_ADMIN_APPLY_LAG_TOLERANCE, 100) time_lag_tolerance = settings.getint( Constants.REPMGR_ADMIN_TIME_LAG_TOLERANCE, 100) interval_check = settings.getint( Constants.REPMGR_ADMIN_CHECK_INTERVAL, 1800) replicationAdminMonitor = ReplicationAdminMonitor( replication_lag_tolerance=replication_lag_tolerance, apply_lag_tolerance=apply_lag_tolerance, time_lag_tolerance=time_lag_tolerance, interval_check=interval_check) run_cron_migrate(settings) replicationAdminMonitor.start() consumerThread.join() else: migrate_task(settings) consumerThread.stop() except KeyboardInterrupt: logger.debug('terminated by a user') os._exit(0) except Exception as e: logger.error(e) os._exit(1) logger.debug('exiting edmigrate main program')
def test_get_broker_url_eager_is_false_without_broker(self): config = configparser.ConfigParser() config['app:main'] = {'migrate.celery.celery_always_eager': False} self.assertEqual(get_broker_url(config['app:main']), "memory://")
''' from unittest.mock import patch from mocket.mocket import Mocket from edmigrate.tests.utils.unittest_with_repmgr_sqlite import Unittest_with_repmgr_sqlite from edmigrate.tasks.player import Player from edmigrate.settings.config import Config import edmigrate.settings.config from edmigrate.utils.constants import Constants from kombu import Connection from kombu.entity import Exchange from edmigrate.utils.utils import get_broker_url from edmigrate.exceptions import IptablesSaveCommandError, IptablesCommandError import subprocess import socket connection = Connection(get_broker_url()) exchange = Exchange(Constants.CONDUCTOR_EXCHANGE) class PlayerTaskTest(Unittest_with_repmgr_sqlite): @classmethod def setUpClass(cls): super().setUpClass() def setUp(self): # clean up singleton durign testing Player._instances.clear() self.hostname = 'localhost' self.cluster = 'test_cluster' self.routing_key = Constants.CONDUCTOR_ROUTING_KEY self.connection = Connection(get_broker_url())
def test_get_broker_enpty_settings_with_broker(self): config = configparser.ConfigParser() config['app:main'] = {Config.BROKER_URL: 'mybrokerURL'} self.assertEqual(get_broker_url(config['app:main']), 'mybrokerURL')
def test_get_broker_enpty_settings(self): config = configparser.ConfigParser() config['app:main'] = {} self.assertEqual(get_broker_url(config['app:main']), "memory://")
from unittest.mock import patch from mocket.mocket import Mocket from edmigrate.tests.utils.unittest_with_repmgr_sqlite import Unittest_with_repmgr_sqlite from edmigrate.tasks.player import Player from edmigrate.settings.config import Config import edmigrate.settings.config from edmigrate.utils.constants import Constants from kombu import Connection from kombu.entity import Exchange from edmigrate.utils.utils import get_broker_url from edmigrate.exceptions import IptablesSaveCommandError, IptablesCommandError import subprocess import socket connection = Connection(get_broker_url()) exchange = Exchange(Constants.CONDUCTOR_EXCHANGE) class PlayerTaskTest(Unittest_with_repmgr_sqlite): @classmethod def setUpClass(cls): super().setUpClass() def setUp(self): # clean up singleton durign testing Player._instances.clear() self.hostname = 'localhost' self.cluster = 'test_cluster' self.routing_key = Constants.CONDUCTOR_ROUTING_KEY