# Path: rpaas/storage.py
# class InstanceNotFoundError(Exception):
# class PlanNotFoundError(Exception):
# class FlavorNotFoundError(Exception):
# class DuplicateError(Exception):
# class MongoDBStorage(storage.MongoDBStorage):
#     def store_hc(self, hc):
#     def retrieve_hc(self, name):
#     def remove_hc(self, name):
#     def store_healing(self, instance, machine):
#     def update_healing(self, id, status):
#     def list_healings(self, quantity):
#     def store_task(self, name):
#     def remove_task(self, query):
#     def update_task(self, name, task_id_or_spec):
#     def find_task(self, query):
#     def store_instance_metadata(self, instance_name, **data):
#     def find_instance_metadata(self, instance_name):
#     def find_host_id(self, name):
#     def remove_instance_metadata(self, instance_name):
#     def store_plan(self, plan):
#     def update_plan(self, name, description=None, config=None):
#     def delete_plan(self, name):
#     def find_plan(self, name):
#     def list_plans(self):
#     def _plan_from_dict(self, dict):
#     def store_flavor(self, flavor):
#     def update_flavor(self, name, description=None, config=None):
#     def delete_flavor(self, name):
#     def find_flavor(self, name):
#     def list_flavors(self):
#     def _flavor_from_dict(self, dict):
#     def store_binding(self, name, app_host, app_host_only=False):
#     def remove_binding(self, name):
#     def remove_root_binding(self, name, remove_root_binding_path):
#     def find_binding(self, name):
#     def replace_binding_path(self, name, path, destination=None, content=None, https_only=False):
#     def delete_binding_path(self, name, path):
#     def set_team_quota(self, teamname, quota):
#     def find_team_quota(self, teamname):
#     def _find_team_quota(self, teamname):
#     def increment_quota(self, teamname, prev_used, servicename):
#     def decrement_quota(self, servicename):
#     def store_le_certificate(self, name, domain):
#     def remove_le_certificate(self, name, domain):
#     def find_le_certificates(self, query):
# 
# Path: rpaas/tasks.py
# def setup_redis_url():
# def initialize_celery():
#     def __init__(self, config=None):
#     def ensure_ready(self, name):
#     def remove(self, name):
#     def create(self, name):
#     def update(self, name, task_id):
#     def init_config(self, config=None):
#     def _get_conf(self, key, default=config.undefined):
#     def _add_host(self, name, lb=None):
#     def _delete_host(self, name, host, lb=None):
#     def run(self, config, name):
#     def _should_destroy_lb(self):
#     def run(self, config, name):
#     def run(self, config, name, quantity):
#     def run(self, config):
#     def _restore_machine(self, task, config, healthcheck_timeout):
#     def _failure_instances(self, retry_failure_query, retry_failure_delay):
#     def run(self, config):
#     def _check_machine_exists(self, address):
#     def run(self, config, name, plugin, csr, key, domain):
#     def run(self, config, name, plugin, domain):
#     def run(self, config):
#     def renew(self, cert, config):
#     def run(self, config):
#     def rotate_session_ticket(self, hosts):
#     def add_session_ticket(self, host, session_ticket):
# class NotReadyError(Exception):
# class TaskNotFoundError(Exception):
# class TaskManager(object):
# class BaseManagerTask(Task):
# class NewInstanceTask(BaseManagerTask):
# class RemoveInstanceTask(BaseManagerTask):
# class ScaleInstanceTask(BaseManagerTask):
# class RestoreMachineTask(BaseManagerTask):
# class CheckMachineTask(BaseManagerTask):
# class DownloadCertTask(BaseManagerTask):
# class RevokeCertTask(BaseManagerTask):
# class RenewCertsTask(BaseManagerTask):
# class SessionResumptionTask(BaseManagerTask):
# 
# Path: rpaas/ssl_plugins/le_renewer.py
# class LeRenewer(scheduler.JobScheduler):
#     def __init__(self, config=None, *args, **kwargs):
#     def run(self):


import datetime
import mock
import time
import unittest
import redis
from rpaas import storage, tasks
from rpaas.ssl_plugins import le_renewer
        self.config = {
            "MONGO_DATABASE": "le_renewer_test",
            "RPAAS_SERVICE_NAME": "test_rpaas_renewer",
            "LE_RENEWER_RUN_INTERVAL": 2,
        }
        self.storage = storage.MongoDBStorage(self.config)
        colls = self.storage.db.collection_names(False)
        for coll in colls:
            self.storage.db.drop_collection(coll)

        now = datetime.datetime.utcnow()
        certs = [
            {"_id": "instance0", "domain": "i0.tsuru.io",
             "created": now - datetime.timedelta(days=88)},
            {"_id": "instance1", "domain": "i1.tsuru.io",
             "created": now - datetime.timedelta(days=89)},
            {"_id": "instance2", "domain": "i2.tsuru.io",
             "created": now},
            {"_id": "instance3", "domain": "i3.tsuru.io",
             "created": now - datetime.timedelta(days=30)},
            {"_id": "instance4", "domain": "i4.tsuru.io",
             "created": now - datetime.timedelta(days=90)},
            {"_id": "instance5", "domain": "i5.tsuru.io",
             "created": now - datetime.timedelta(days=365)},
            {"_id": "instance6", "domain": "i6.tsuru.io",
             "created": now - datetime.timedelta(days=87)},
            {"_id": "instance7", "domain": "i7.tsuru.io",
             "created": now - datetime.timedelta(days=86)},
        ]
        for cert in certs:

# Path: rpaas/storage.py
# class InstanceNotFoundError(Exception):
# class PlanNotFoundError(Exception):
# class FlavorNotFoundError(Exception):
# class DuplicateError(Exception):
# class MongoDBStorage(storage.MongoDBStorage):
#     def store_hc(self, hc):
#     def retrieve_hc(self, name):
#     def remove_hc(self, name):
#     def store_healing(self, instance, machine):
#     def update_healing(self, id, status):
#     def list_healings(self, quantity):
#     def store_task(self, name):
#     def remove_task(self, query):
#     def update_task(self, name, task_id_or_spec):
#     def find_task(self, query):
#     def store_instance_metadata(self, instance_name, **data):
#     def find_instance_metadata(self, instance_name):
#     def find_host_id(self, name):
#     def remove_instance_metadata(self, instance_name):
#     def store_plan(self, plan):
#     def update_plan(self, name, description=None, config=None):
#     def delete_plan(self, name):
#     def find_plan(self, name):
#     def list_plans(self):
#     def _plan_from_dict(self, dict):
#     def store_flavor(self, flavor):
#     def update_flavor(self, name, description=None, config=None):
#     def delete_flavor(self, name):
#     def find_flavor(self, name):
#     def list_flavors(self):
#     def _flavor_from_dict(self, dict):
#     def store_binding(self, name, app_host, app_host_only=False):
#     def remove_binding(self, name):
#     def remove_root_binding(self, name, remove_root_binding_path):
#     def find_binding(self, name):
#     def replace_binding_path(self, name, path, destination=None, content=None, https_only=False):
#     def delete_binding_path(self, name, path):
#     def set_team_quota(self, teamname, quota):
#     def find_team_quota(self, teamname):
#     def _find_team_quota(self, teamname):
#     def increment_quota(self, teamname, prev_used, servicename):
#     def decrement_quota(self, servicename):
#     def store_le_certificate(self, name, domain):
#     def remove_le_certificate(self, name, domain):
#     def find_le_certificates(self, query):
# 
# Path: rpaas/tasks.py
# def setup_redis_url():
# def initialize_celery():
#     def __init__(self, config=None):
#     def ensure_ready(self, name):
#     def remove(self, name):
#     def create(self, name):
#     def update(self, name, task_id):
#     def init_config(self, config=None):
#     def _get_conf(self, key, default=config.undefined):
#     def _add_host(self, name, lb=None):
#     def _delete_host(self, name, host, lb=None):
#     def run(self, config, name):
#     def _should_destroy_lb(self):
#     def run(self, config, name):
#     def run(self, config, name, quantity):
#     def run(self, config):
#     def _restore_machine(self, task, config, healthcheck_timeout):
#     def _failure_instances(self, retry_failure_query, retry_failure_delay):
#     def run(self, config):
#     def _check_machine_exists(self, address):
#     def run(self, config, name, plugin, csr, key, domain):
#     def run(self, config, name, plugin, domain):
#     def run(self, config):
#     def renew(self, cert, config):
#     def run(self, config):
#     def rotate_session_ticket(self, hosts):
#     def add_session_ticket(self, host, session_ticket):
# class NotReadyError(Exception):
# class TaskNotFoundError(Exception):
# class TaskManager(object):
# class BaseManagerTask(Task):
# class NewInstanceTask(BaseManagerTask):
# class RemoveInstanceTask(BaseManagerTask):
# class ScaleInstanceTask(BaseManagerTask):
# class RestoreMachineTask(BaseManagerTask):
# class CheckMachineTask(BaseManagerTask):
# class DownloadCertTask(BaseManagerTask):
# class RevokeCertTask(BaseManagerTask):
# class RenewCertsTask(BaseManagerTask):
# class SessionResumptionTask(BaseManagerTask):
# 
# Path: rpaas/ssl_plugins/le_renewer.py
# class LeRenewer(scheduler.JobScheduler):
#     def __init__(self, config=None, *args, **kwargs):
#     def run(self):


# Path: tests/test_le_renewer.py
import datetime
import mock
import time
import unittest
import redis
from rpaas import storage, tasks
from rpaas.ssl_plugins import le_renewer

        self.config = {
            "MONGO_DATABASE": "le_renewer_test",
            "RPAAS_SERVICE_NAME": "test_rpaas_renewer",
            "LE_RENEWER_RUN_INTERVAL": 2,
        }
        self.storage = storage.MongoDBStorage(self.config)
        colls = self.storage.db.collection_names(False)
        for coll in colls:
            self.storage.db.drop_collection(coll)

        now = datetime.datetime.utcnow()
        certs = [
            {"_id": "instance0", "domain": "i0.tsuru.io",
             "created": now - datetime.timedelta(days=88)},
            {"_id": "instance1", "domain": "i1.tsuru.io",
             "created": now - datetime.timedelta(days=89)},
            {"_id": "instance2", "domain": "i2.tsuru.io",
             "created": now},
            {"_id": "instance3", "domain": "i3.tsuru.io",
             "created": now - datetime.timedelta(days=30)},
            {"_id": "instance4", "domain": "i4.tsuru.io",
             "created": now - datetime.timedelta(days=90)},
            {"_id": "instance5", "domain": "i5.tsuru.io",
             "created": now - datetime.timedelta(days=365)},
            {"_id": "instance6", "domain": "i6.tsuru.io",
             "created": now - datetime.timedelta(days=87)},
            {"_id": "instance7", "domain": "i7.tsuru.io",
             "created": now - datetime.timedelta(days=86)},
        ]
        for cert in certs:

            self.storage.db[self.storage.le_certificates_collection].insert(cert)