Example #1
0
 def setUpClass(cls):
     admin_api.register_views(api.api, api.plans)
     os.environ["MONGO_DATABASE"] = "api_admin_test"
     cls.storage = storage.MongoDBStorage()
     cls.manager = managers.FakeManager(storage=cls.storage)
     api.get_manager = lambda: cls.manager
     cls.api = api.api.test_client()
Example #2
0
 def __init__(self, config=None):
     self.config = config
     self.storage = storage.MongoDBStorage(config)
     self.consul_manager = consul_manager.ConsulManager(config)
     self.nginx_manager = nginx.Nginx(config)
     self.task_manager = tasks.TaskManager(config)
     self.service_name = os.environ.get("RPAAS_SERVICE_NAME", "rpaas")
Example #3
0
 def init_config(self, config=None):
     self.config = config
     self.nginx_manager = nginx.Nginx(config)
     self.consul_manager = consul_manager.ConsulManager(config)
     self.host_manager_name = self._get_conf("HOST_MANAGER", "cloudstack")
     self.lb_manager_name = self._get_conf("LB_MANAGER",
                                           "networkapi_cloudstack")
     self.task_manager = TaskManager(config)
     self.lock_manager = lock.Lock(app.backend.client)
     self.hc = hc.Dumb()
     self.storage = storage.MongoDBStorage(config)
     self.acl_manager = acl.Dumb(self.consul_manager)
     if check_option_enable(self._get_conf("CHECK_ACL_API", None)):
         self.acl_manager = acl.AclManager(config, self.consul_manager,
                                           lock.Lock(app.backend.client))
     hc_url = self._get_conf("HCAPI_URL", None)
     if hc_url:
         self.hc = hc.HCAPI(self.storage,
                            url=hc_url,
                            user=self._get_conf("HCAPI_USER"),
                            password=self._get_conf("HCAPI_PASSWORD"),
                            hc_format=self._get_conf(
                                "HCAPI_FORMAT", "http://{}:8080/"))
     self.retry_countdown = os.environ.get("RETRY_COUNTDOWN", None)
     if self.retry_countdown:
         self.retry_countdown = int(self.retry_countdown)
     self.max_retries = os.environ.get("MAX_RETRIES", None)
     if self.max_retries:
         self.max_retries = int(self.max_retries)
Example #4
0
 def setUp(self):
     os.environ["MONGO_DATABASE"] = "storage_test"
     self.storage = storage.MongoDBStorage()
     colls = self.storage.db.collection_names(False)
     for coll in colls:
         self.storage.db.drop_collection(coll)
     self.storage.db[self.storage.plans_collection].insert(
         {"_id": "small",
          "description": "some cool plan",
          "config": {"serviceofferingid": "abcdef123456"}}
     )
     self.storage.db[self.storage.plans_collection].insert(
         {"_id": "huge",
          "description": "some cool huge plan",
          "config": {"serviceofferingid": "abcdef123459"}}
     )
     self.storage.db[self.storage.flavors_collection].insert(
         {"_id": "vanilla",
          "description": "nginx 1.10",
          "config": {"nginx_version": "1.10"}}
     )
     self.storage.db[self.storage.flavors_collection].insert(
         {"_id": "orange",
          "description": "nginx 1.12",
          "config": {"nginx_version": "1.12"}}
     )
Example #5
0
    def setUp(self):
        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)
        redis.StrictRedis().delete("le_renewer:last_run")
Example #6
0
 def setUp(self):
     os.environ["MONGO_DATABASE"] = "host_manager_test"
     os.environ.setdefault("RPAAS_SERVICE_NAME", "test-suite-rpaas")
     self.storage = storage.MongoDBStorage()
     colls = self.storage.db.collection_names(False)
     for coll in colls:
         self.storage.db.drop_collection(coll)
     plan = {
         "_id": "small",
         "description": "some cool plan",
         "config": {
             "serviceofferingid": "abcdef123456"
         }
     }
     self.plan = copy.deepcopy(plan)
     self.plan["name"] = plan["_id"]
     del self.plan["_id"]
     self.storage.db[self.storage.plans_collection].insert(plan)
     self.lb_patcher = mock.patch("rpaas.tasks.LoadBalancer")
     self.host_patcher = mock.patch("rpaas.tasks.Host")
     self.LoadBalancer = self.lb_patcher.start()
     self.Host = self.host_patcher.start()
     self.config = {
         "HOST_MANAGER": "my-host-manager",
         "LB_MANAGER": "my-lb-manager",
         "serviceofferingid": "abcdef123459",
         "CONSUL_HOST": "127.0.0.1",
         "CONSUL_TOKEN": "rpaas-test",
     }
Example #7
0
def generate_crt(config, name, plugin, csr, key, domain):
    lb = LoadBalancer.find(name, config)
    if lb is None:
        raise storage.InstanceNotFoundError()
    strg = storage.MongoDBStorage(config)
    consul_mngr = consul_manager.ConsulManager(config)

    crt = None

    plugin_class = ssl_plugins.get(plugin)
    if not plugin_class:
        raise Exception("Invalid plugin {}".format(plugin))
    plugin_obj = plugin_class(domain, os.environ.get('RPAAS_PLUGIN_LE_EMAIL', 'admin@'+domain),
                              name, consul_manager=consul_mngr)

    #  Upload csr and get an Id
    plugin_id = plugin_obj.upload_csr(csr)
    crt = plugin_obj.download_crt(id=str(plugin_id))

    #  Download the certificate and update nginx with it
    if crt:
        try:
            js_crt = json.loads(crt)
            cert = js_crt['crt']
            cert = cert+js_crt['chain'] if 'chain' in js_crt else cert
            key = js_crt['key'] if 'key' in js_crt else key
        except:
            cert = crt

        consul_mngr.set_certificate(name, cert, key)
        strg.store_le_certificate(name, domain)
    else:
        raise Exception('Could not download certificate')
Example #8
0
    def setUp(self):

        self.config = {
            "MONGO_DATABASE": "check_machine_test",
            "RPAAS_SERVICE_NAME": "test_rpaas_check_machine",
            "RESTORE_MACHINE_RUN_INTERVAL": 2,
            "HOST_MANAGER": "fake",
        }

        self.storage = storage.MongoDBStorage(self.config)

        colls = self.storage.db.collection_names(False)
        for coll in colls:
            self.storage.db.drop_collection(coll)

        self.storage.db[self.storage.hosts_collection].insert({
            "_id":
            0,
            "dns_name":
            "10.1.1.1",
            "manager":
            "fake",
            "group":
            "rpaas_01",
            "alternative_id":
            0
        })
        self.storage.db[self.storage.hosts_collection].insert({
            "_id":
            1,
            "dns_name":
            "10.2.2.2",
            "manager":
            "fake",
            "group":
            "rpaas_02",
            "alternative_id":
            0
        })
        self.storage.db[self.storage.hosts_collection].insert({
            "_id":
            2,
            "dns_name":
            "10.3.3.3",
            "manager":
            "fake",
            "group":
            "rpaas_02",
            "alternative_id":
            0
        })
        FakeManager.host_id = 0
        FakeManager.hosts = ['10.1.1.1', '10.2.2.2', '10.3.3.3']

        redis.StrictRedis().delete(
            "check_machine:test_rpaas_check_machine:last_run")
Example #9
0
    def setUp(self):
        self.config = {
            "MONGO_DATABASE": "machine_restore_test",
            "RPAAS_SERVICE_NAME": "test_rpaas_machine_restore",
            "RESTORE_MACHINE_RUN_INTERVAL": 2,
            "HOST_MANAGER": "fake"
        }

        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()
        tasks = [
            {
                "_id": "restore_10.1.1.1",
                "host": "10.1.1.1",
                "instance": "foo",
                "created": now - datetime.timedelta(minutes=8)
            },
            {
                "_id": "restore_10.2.2.2",
                "host": "10.2.2.2",
                "instance": "bar",
                "created": now - datetime.timedelta(minutes=3)
            },
            {
                "_id": "restore_10.3.3.3",
                "host": "10.3.3.3",
                "instance": "foo",
                "created": now - datetime.timedelta(minutes=5)
            },
            {
                "_id": "restore_10.4.4.4",
                "host": "10.4.4.4",
                "instance": "foo",
                "created": now - datetime.timedelta(minutes=10)
            },
            {
                "_id": "restore_10.5.5.5",
                "host": "10.5.5.5",
                "instance": "bar",
                "created": now - datetime.timedelta(minutes=15)
            },
        ]
        FakeManager.host_id = 0
        FakeManager.hosts = [
            '10.1.1.1', '10.2.2.2', '10.3.3.3', '10.4.4.4', '10.5.5.5'
        ]

        for task in tasks:
            Host.create("fake", task['instance'], self.config)
            self.storage.store_task(task)

        redis.StrictRedis().delete("restore_machine:last_run")
Example #10
0
 def setUp(self):
     os.environ['MONGO_DATABASE'] = 'host_manager_test'
     self.storage = storage.MongoDBStorage()
     colls = self.storage.db.collection_names(False)
     for coll in colls:
         self.storage.db.drop_collection(coll)
     self.hc = hc.HCAPI(self.storage,
                        "http://localhost",
                        hc_format="http://{}:8080/")
     self.hc._issue_request = self.issue_request = mock.Mock()
Example #11
0
 def __init__(self, config=None):
     self.config = config
     self.storage = storage.MongoDBStorage(config)
     self.consul_manager = consul_manager.ConsulManager(config)
     self.nginx_manager = nginx.Nginx(config)
     self.task_manager = tasks.TaskManager(config)
     self.service_name = os.environ.get("RPAAS_SERVICE_NAME", "rpaas")
     self.acl_manager = acl.Dumb(self.consul_manager)
     if check_option_enable(os.environ.get("CHECK_ACL_API", None)):
         self.acl_manager = acl.AclManager(config, self.consul_manager, lock.Lock(tasks.app.backend.client))
Example #12
0
 def init_config(self, config=None):
     self.config = config
     self.nginx_manager = nginx.NginxDAV(config)
     self.host_manager_name = self._get_conf("HOST_MANAGER", "cloudstack")
     self.lb_manager_name = self._get_conf("LB_MANAGER",
                                           "networkapi_cloudstack")
     self.hc = hc.Dumb()
     self.storage = storage.MongoDBStorage(config)
     hc_url = self._get_conf("HCAPI_URL", None)
     if hc_url:
         self.hc = hc.HCAPI(self.storage,
                            url=hc_url,
                            user=self._get_conf("HCAPI_USER"),
                            password=self._get_conf("HCAPI_PASSWORD"),
                            hc_format=self._get_conf(
                                "HCAPI_FORMAT", "http://{}:8080/"))
 def setUp(self):
     self.master_token = "rpaas-test"
     self.config = {
         "CONSUL_HOST": "127.0.0.1",
         "CONSUL_TOKEN": self.master_token,
         "MONGO_DATABASE": "session_resumption_test",
         "RPAAS_SERVICE_NAME": "test_rpaas_session_resumption",
         "HOST_MANAGER": "fake",
         "SESSION_RESUMPTION_RUN_INTERVAL": 2,
         u"CA_CERT": unicode(self.ca_cert),
         u"CA_KEY": unicode(self.ca_key)
     }
     self.consul = consul.Consul(token=self.master_token)
     self.consul.kv.delete("test_rpaas_session_resumption", recurse=True)
     self.storage = storage.MongoDBStorage(self.config)
     self.consul_manager = consul_manager.ConsulManager(self.config)
     colls = self.storage.db.collection_names(False)
     for coll in colls:
         self.storage.db.drop_collection(coll)
     redis.StrictRedis().flushall()
Example #14
0
 def __init__(self, config=None):
     self.storage = storage.MongoDBStorage(config)
Example #15
0
 def setUpClass(cls):
     os.environ["MONGO_DATABASE"] = "api_test"
     cls.storage = storage.MongoDBStorage()
     cls.manager = managers.FakeManager(storage=cls.storage)
     api.get_manager = lambda: cls.manager
     cls.api = api.api.test_client()
Example #16
0
 def setUpClass(cls):
     cls.storage = storage.MongoDBStorage()
     cls.manager = managers.FakeManager(storage=cls.storage)
     api.get_manager = lambda: cls.manager
     cls.api = api.api.test_client()
Example #17
0
 def setUpClass(cls):
     admin_api.register_views(api.api, api.plans)
     cls.storage = storage.MongoDBStorage()
     cls.manager = managers.FakeManager(storage=cls.storage)
     api.get_manager = lambda: cls.manager
     cls.api = api.api.test_client()
Example #18
0
 def __init__(self, config=None):
     self.config = config
     self.storage = storage.MongoDBStorage(config)
     self.nginx_manager = nginx.NginxDAV(config)
     self.service_name = os.environ.get("RPAAS_SERVICE_NAME", "rpaas")