Пример #1
0
    def test_platform_set_data(self):
        platforms = db.platforms_list(self.env1["uuid"])
        uuid = platforms[0]["uuid"]

        self.assertTrue(db.platform_set_data(uuid))
        self.assertTrue(
            db.platform_set_data(uuid, platform_data={"platform": "data"}))
        in_db = db.platform_get(uuid)
        self.assertEqual({"platform": "data"}, in_db["platform_data"])
        self.assertEqual({}, in_db["plugin_data"])

        self.assertTrue(
            db.platform_set_data(uuid, plugin_data={"plugin": "data"}))
        in_db = db.platform_get(uuid)
        self.assertEqual({"platform": "data"}, in_db["platform_data"])
        self.assertEqual({"plugin": "data"}, in_db["plugin_data"])

        self.assertTrue(
            db.platform_set_data(uuid, platform_data={"platform": "data2"}))
        in_db = db.platform_get(uuid)
        self.assertEqual({"platform": "data2"}, in_db["platform_data"])
        self.assertEqual({"plugin": "data"}, in_db["plugin_data"])

        self.assertFalse(db.platform_set_data("non_existing",
                                              platform_data={}))
        in_db = db.platform_get(uuid)
        # just check that nothing changed after wrong uuid passed
        self.assertEqual({"platform": "data2"}, in_db["platform_data"])
Пример #2
0
    def test_platform_set_data(self):
        platforms = db.platforms_list(self.env1["uuid"])
        uuid = platforms[0]["uuid"]

        self.assertTrue(db.platform_set_data(uuid))
        self.assertTrue(
            db.platform_set_data(uuid, platform_data={"platform": "data"}))
        in_db = db.platform_get(uuid)
        self.assertEqual({"platform": "data"}, in_db["platform_data"])
        self.assertEqual({}, in_db["plugin_data"])

        self.assertTrue(
            db.platform_set_data(uuid, plugin_data={"plugin": "data"}))
        in_db = db.platform_get(uuid)
        self.assertEqual({"platform": "data"}, in_db["platform_data"])
        self.assertEqual({"plugin": "data"}, in_db["plugin_data"])

        self.assertTrue(
            db.platform_set_data(uuid, platform_data={"platform": "data2"}))
        in_db = db.platform_get(uuid)
        self.assertEqual({"platform": "data2"}, in_db["platform_data"])
        self.assertEqual({"plugin": "data"}, in_db["plugin_data"])

        self.assertFalse(db.platform_set_data(
            "non_existing", platform_data={}))
        in_db = db.platform_get(uuid)
        # just check that nothing changed after wrong uuid passed
        self.assertEqual({"platform": "data2"}, in_db["platform_data"])
Пример #3
0
    def _create_platforms(self):
        """Iterates over platform and creates them, storing results in DB.

        Do NOT use this method directly! Use create() instead.

        All platform statuses are going to be updated.
        - If everything is OK all platforms and env would have READY statuts.
        - If some of platforms failed, it will get status "FAILED TO CREATE"
          as well as Env, all following platforms would have "SKIPPED" state.
        - If there are issues with DB, and we can't store results to DB,
          platform will be destroyed so we won't keep messy env, everything
          will be logged.

        This is not ideal solution, but it's best that we can do at the moment
        """
        new_env_status = STATUS.READY

        for p in self._get_platforms():
            if new_env_status != STATUS.READY:
                db.platform_set_status(
                    p.uuid, platform.STATUS.INIT, platform.STATUS.SKIPPED)
                continue

            try:
                platform_data, plugin_data = p.create()
            except Exception:
                new_env_status = STATUS.FAILED_TO_CREATE
                LOG.exception(
                    "Failed to create platform (%(uuid)s): "
                    "%(name)s with spec: %(spec)s" %
                    {"uuid": p.uuid, "name": p.get_fullname(), "spec": p.spec})
                try:
                    db.platform_set_status(p.uuid, platform.STATUS.INIT,
                                           platform.STATUS.FAILED_TO_CREATE)
                except Exception:
                    LOG.Exception(
                        "Failed to set platform %(uuid)s status %(status)s"
                        % {"uuid": p.uuid,
                           "status": platform.STATUS.FAILED_TO_CREATE})

            if new_env_status == STATUS.FAILED_TO_CREATE:
                continue

            try:
                db.platform_set_data(
                    p.uuid,
                    platform_data=platform_data, plugin_data=plugin_data)
                db.platform_set_status(
                    p.uuid, platform.STATUS.INIT, platform.STATUS.READY)
            except Exception:
                new_env_status = STATUS.FAILED_TO_CREATE

                # NOTE(boris-42): We can't store platform data, because of
                #                 issues with DB, to keep env clean we must
                #                 destroy platform while we have complete data.
                p.status = platform.STATUS.FAILED_TO_CREATE
                p.platform_data, p.plugin_data = platform_data, plugin_data
                try:
                    p.destroy()
                    LOG.warning("Couldn't store platform %s data to DB."
                                "Attempt to destroy it succeeded." % p.uuid)
                except Exception:
                    LOG.exception(
                        "Couldn't store data of platform(%(uuid)s): %(name)s  "
                        "with spec: %(spec)s. Attempt to destroy it failed. "
                        "Sorry, but we can't do anything else for you. :("
                        % {"uuid": p.uuid,
                           "name": p.get_fullname(),
                           "spec": p.spec})

        db.env_set_status(self.uuid, STATUS.INIT, new_env_status)
Пример #4
0
    def _create_platforms(self):
        """Iterates over platform and creates them, storing results in DB.

        Do NOT use this method directly! Use create() instead.

        All platform statuses are going to be updated.
        - If everything is OK all platforms and env would have READY statuts.
        - If some of platforms failed, it will get status "FAILED TO CREATE"
          as well as Env, all following platforms would have "SKIPPED" state.
        - If there are issues with DB, and we can't store results to DB,
          platform will be destroyed so we won't keep messy env, everything
          will be logged.

        This is not ideal solution, but it's best that we can do at the moment
        """
        new_env_status = STATUS.READY

        for p in self._get_platforms():
            if new_env_status != STATUS.READY:
                db.platform_set_status(
                    p.uuid, platform.STATUS.INIT, platform.STATUS.SKIPPED)
                continue

            try:
                platform_data, plugin_data = p.create()
            except Exception:
                new_env_status = STATUS.FAILED_TO_CREATE
                LOG.exception(
                    "Failed to create platform (%(uuid)s): "
                    "%(name)s with spec: %(spec)s" %
                    {"uuid": p.uuid, "name": p.get_fullname(), "spec": p.spec})
                try:
                    db.platform_set_status(p.uuid, platform.STATUS.INIT,
                                           platform.STATUS.FAILED_TO_CREATE)
                except Exception:
                    LOG.exception(
                        "Failed to set platform %(uuid)s status %(status)s"
                        % {"uuid": p.uuid,
                           "status": platform.STATUS.FAILED_TO_CREATE})

            if new_env_status == STATUS.FAILED_TO_CREATE:
                continue

            try:
                db.platform_set_data(
                    p.uuid,
                    platform_data=platform_data, plugin_data=plugin_data)
                db.platform_set_status(
                    p.uuid, platform.STATUS.INIT, platform.STATUS.READY)
            except Exception:
                new_env_status = STATUS.FAILED_TO_CREATE

                # NOTE(boris-42): We can't store platform data, because of
                #                 issues with DB, to keep env clean we must
                #                 destroy platform while we have complete data.
                p.status = platform.STATUS.FAILED_TO_CREATE
                p.platform_data, p.plugin_data = platform_data, plugin_data
                try:
                    p.destroy()
                    LOG.warning("Couldn't store platform %s data to DB."
                                "Attempt to destroy it succeeded." % p.uuid)
                except Exception:
                    LOG.exception(
                        "Couldn't store data of platform(%(uuid)s): %(name)s  "
                        "with spec: %(spec)s. Attempt to destroy it failed. "
                        "Sorry, but we can't do anything else for you. :("
                        % {"uuid": p.uuid,
                           "name": p.get_fullname(),
                           "spec": p.spec})

        db.env_set_status(self.uuid, STATUS.INIT, new_env_status)