def _send_email(subject, body, to_address): """ Send a text email to one recipient :param subject: email subject :type subject: basestring :param body: text body of the email :type body: basestring :param to_address: email address to send to :type to_address: basestring :return: None """ host = config.get('email', 'host') port = config.getint('email', 'port') from_address = config.get('email', 'from') message = MIMEText(body) message['Subject'] = subject message['From'] = from_address message['To'] = to_address try: connection = smtplib.SMTP(host=host, port=port) except smtplib.SMTPConnectError: logger.exception('SMTP connection failed to %s on %s' % (host, port)) return try: connection.sendmail(from_address, to_address, message.as_string()) except smtplib.SMTPException, e: try: logger.exception('Error sending mail.') except AttributeError: logger.error('SMTP error while sending mail')
def _send_email(subject, body, to_address): """ Send a text email to one recipient :param subject: email subject :type subject: basestring :param body: text body of the email :type body: basestring :param to_address: email address to send to :type to_address: basestring :return: None """ host = config.get('email', 'host') port = config.getint('email', 'port') from_address = config.get('email', 'from') message = MIMEText(body) message['Subject'] = subject message['From'] = from_address message['To'] = to_address try: connection = smtplib.SMTP(host=host, port=port) except smtplib.SMTPConnectError: logger.error('SMTP connection failed to %s on %s' % (host, port)) return try: connection.sendmail(from_address, to_address, message.as_string()) except smtplib.SMTPException, e: try: logger.error('Error sending mail: %s' % e.message) except AttributeError: logger.error('SMTP error while sending mail')
def test_download_deferred_content(self): """ Make sure the monthly maintenance Task is present and properly configured. """ expected_download_deferred = { 'task': download_deferred.name, 'schedule': timedelta(minutes=config.getint('lazy', 'download_interval')), 'args': tuple(), } self.assertEqual( celery_instance.celery.conf['CELERYBEAT_SCHEDULE']['download_deferred_content'], expected_download_deferred )
def test_download_deferred_content(self): """ Make sure the monthly maintenance Task is present and properly configured. """ expected_download_deferred = { 'task': download_deferred.name, 'schedule': timedelta(minutes=config.getint('lazy', 'download_interval')), 'args': tuple(), } self.assertEqual( celery_instance.celery.conf['CELERYBEAT_SCHEDULE'] ['download_deferred_content'], expected_download_deferred)
def test_basic(self, mock_smtp): # send a message mail._send_email('hello', 'stuff', '*****@*****.**') mock_smtp.assert_called_once_with(host=config.get('email', 'host'), port=config.getint('email', 'port')) # verify mock_sendmail = mock_smtp.return_value.sendmail self.assertEqual(mock_sendmail.call_count, 1) self.assertEqual(mock_sendmail.call_args[0][0], config.get('email', 'from')) self.assertEqual(mock_sendmail.call_args[0][1], '*****@*****.**') # verify message attributes message = Parser().parsestr(mock_sendmail.call_args[0][2]) self.assertEqual(message.get_payload(), 'stuff') self.assertEqual(message.get('Subject', None), 'hello') self.assertEqual(message.get('From', None), config.get('email', 'from')) self.assertEqual(message.get('To', None), '*****@*****.**')
DEDICATED_QUEUE_EXCHANGE = 'C.dq' RESOURCE_MANAGER_QUEUE = 'resource_manager' CELERYBEAT_SCHEDULE = { 'reap_expired_documents': { 'task': 'pulp.server.db.reaper.queue_reap_expired_documents', 'schedule': timedelta(days=config.getfloat('data_reaping', 'reaper_interval')), 'args': tuple(), }, 'monthly_maintenance': { 'task': 'pulp.server.maintenance.monthly.queue_monthly_maintenance', 'schedule': timedelta(days=30), 'args': tuple(), }, 'download_deferred_content': { 'task': 'pulp.server.controllers.repository.download_deferred', 'schedule': timedelta(minutes=config.getint('lazy', 'download_interval')), 'args': tuple(), }, } celery.conf.update(CELERYBEAT_SCHEDULE=CELERYBEAT_SCHEDULE) celery.conf.update(CELERYBEAT_SCHEDULER='pulp.server.async.scheduler.Scheduler') celery.conf.update(CELERY_WORKER_DIRECT=True) celery.conf.update(CELERY_TASK_SERIALIZER='json') celery.conf.update(CELERY_ACCEPT_CONTENT=['json']) def configure_login_method(): """ Configures the celery object with BROKER_LOGIN_METHOD if not default.
'task': 'pulp.server.db.reaper.queue_reap_expired_documents', 'schedule': timedelta(days=config.getfloat('data_reaping', 'reaper_interval')), 'args': tuple(), }, 'monthly_maintenance': { 'task': 'pulp.server.maintenance.monthly.queue_monthly_maintenance', 'schedule': timedelta(days=30), 'args': tuple(), }, 'download_deferred_content': { 'task': 'pulp.server.controllers.repository.download_deferred', 'schedule': timedelta(minutes=config.getint('lazy', 'download_interval')), 'args': tuple(), }, } celery.conf.update(CELERYBEAT_SCHEDULE=CELERYBEAT_SCHEDULE) celery.conf.update( CELERYBEAT_SCHEDULER='pulp.server.async.scheduler.Scheduler') celery.conf.update(CELERY_WORKER_DIRECT=True) celery.conf.update(CELERY_TASK_SERIALIZER='json') def configure_login_method(): """ Configures the celery object with BROKER_LOGIN_METHOD if not default. """
DEDICATED_QUEUE_EXCHANGE = "C.dq" RESOURCE_MANAGER_QUEUE = "resource_manager" CELERYBEAT_SCHEDULE = { "reap_expired_documents": { "task": "pulp.server.db.reaper.queue_reap_expired_documents", "schedule": timedelta(days=config.getfloat("data_reaping", "reaper_interval")), "args": tuple(), }, "monthly_maintenance": { "task": "pulp.server.maintenance.monthly.queue_monthly_maintenance", "schedule": timedelta(days=30), "args": tuple(), }, "download_deferred_content": { "task": "pulp.server.controllers.repository.queue_download_deferred", "schedule": timedelta(minutes=config.getint("lazy", "download_interval")), "args": tuple(), }, } celery.conf.update(CELERYBEAT_SCHEDULE=CELERYBEAT_SCHEDULE) celery.conf.update(CELERYBEAT_SCHEDULER="pulp.server.async.scheduler.Scheduler") celery.conf.update(CELERY_WORKER_DIRECT=True) celery.conf.update(CELERY_TASK_SERIALIZER="json") celery.conf.update(CELERY_ACCEPT_CONTENT=["json"]) def configure_login_method(): """ Configures the celery object with BROKER_LOGIN_METHOD if not default.
from pulp.server.config import config LOCAL_STORAGE = "/var/lib/pulp/" PULP_USER_METADATA_FIELDNAME = 'pulp_user_metadata' PULP_DJANGO_SETTINGS_MODULE = 'pulp.server.webservices.settings' PULP_STREAM_REQUEST_HEADER = 'Pulp-Stream-Request' SUPER_USER_ROLE = 'super-users' # The amount of time (in seconds) between process wakeups to "heartbeat" and perform their tasks. # See https://pulp.plan.io/issues/3135#note-15 for info about this calculation. PULP_PROCESS_HEARTBEAT_INTERVAL = int( config.getint('tasks', 'worker_timeout') / 5) # The amount of time (in seconds) after which a Celery process is considered missing. PULP_PROCESS_TIMEOUT_INTERVAL = config.getint('tasks', 'worker_timeout') - \ PULP_PROCESS_HEARTBEAT_INTERVAL
from pulp.server.config import config LOCAL_STORAGE = "/var/lib/pulp/" PULP_USER_METADATA_FIELDNAME = 'pulp_user_metadata' PULP_DJANGO_SETTINGS_MODULE = 'pulp.server.webservices.settings' PULP_STREAM_REQUEST_HEADER = 'Pulp-Stream-Request' SUPER_USER_ROLE = 'super-users' # The amount of time (in seconds) between process wakeups to "heartbeat" and perform their tasks. # See https://pulp.plan.io/issues/3135#note-15 for info about this calculation. PULP_PROCESS_HEARTBEAT_INTERVAL = int(config.getint('tasks', 'worker_timeout') / 5) # The amount of time (in seconds) after which a Celery process is considered missing. PULP_PROCESS_TIMEOUT_INTERVAL = config.getint('tasks', 'worker_timeout') - \ PULP_PROCESS_HEARTBEAT_INTERVAL