Example #1
0
 def test_cluster_template_delete_bad_id(self):
     self.logger.clear_log()
     option_values = {"tenant_id": 1, "id": "badid"}
     template_api.set_conf(Config(option_values))
     template_api.do_cluster_template_delete_by_id()
     msg = ("Deletion of cluster template {id} failed, "
            "no such template".format(id=option_values["id"]))
     self.assertIn(msg, self.logger.warnings)
Example #2
0
 def test_cluster_template_delete_bad_id(self):
     self.logger.clear_log()
     option_values = {"tenant_id": 1,
                      "id": "badid"}
     template_api.set_conf(Config(option_values))
     template_api.do_cluster_template_delete_by_id()
     msg = ("Deletion of cluster template {id} failed, "
            "no such template".format(id=option_values["id"]))
     self.assertIn(msg, self.logger.warnings)
Example #3
0
    def test_cluster_template_delete_by_id(self):
        self.logger.clear_log()
        ctx = context.ctx()
        t = self.api.cluster_template_create(ctx, c.SAMPLE_CLT)

        option_values = {"tenant_id": t["tenant_id"], "id": t["id"]}
        template_api.set_conf(Config(option_values))

        template_api.do_cluster_template_delete_by_id()
        msg = 'Deleted cluster template {info}'.format(info=u.name_and_id(t))
        self.assertIn(msg, self.logger.infos)

        t = self.api.cluster_template_get(ctx, t["id"])
        self.assertIsNone(t)
Example #4
0
    def test_cluster_template_delete_by_id(self):
        self.logger.clear_log()
        ctx = context.ctx()
        t = self.api.cluster_template_create(ctx, c.SAMPLE_CLT)

        option_values = {"tenant_id": t["tenant_id"],
                         "id": t["id"]}
        template_api.set_conf(Config(option_values))

        template_api.do_cluster_template_delete_by_id()
        msg = 'Deleted cluster template {info}'.format(
            info=u.name_and_id(t))
        self.assertIn(msg, self.logger.infos)

        t = self.api.cluster_template_get(ctx, t["id"])
        self.assertIsNone(t)
Example #5
0
    def test_cluster_template_delete_by_id_skipped(self):
        self.logger.clear_log()
        ctx = context.ctx()
        template_values = copy.copy(c.SAMPLE_CLT)
        template_values["is_default"] = False
        t = self.api.cluster_template_create(ctx, template_values)

        option_values = {"tenant_id": t["tenant_id"], "id": t["id"]}
        template_api.set_conf(Config(option_values))
        template_api.do_cluster_template_delete_by_id()
        msg = ("Deletion of cluster template {info} skipped, "
               "not a default template".format(info=u.name_and_id(t)))
        self.assertIn(msg, self.logger.warnings)

        t = self.api.cluster_template_get(ctx, t["id"])
        self.assertIsNotNone(t)
Example #6
0
    def test_cluster_template_delete_by_id_skipped(self):
        self.logger.clear_log()
        ctx = context.ctx()
        template_values = copy.copy(c.SAMPLE_CLT)
        template_values["is_default"] = False
        t = self.api.cluster_template_create(ctx, template_values)

        option_values = {"tenant_id": t["tenant_id"],
                         "id": t["id"]}
        template_api.set_conf(Config(option_values))
        template_api.do_cluster_template_delete_by_id()
        msg = ("Deletion of cluster template {info} skipped, "
               "not a default template".format(info=u.name_and_id(t)))
        self.assertIn(msg, self.logger.warnings)

        t = self.api.cluster_template_get(ctx, t["id"])
        self.assertIsNotNone(t)
Example #7
0
    def test_cluster_template_delete_in_use(self):
        self.logger.clear_log()
        ctx = context.ctx()
        t = self.api.cluster_template_create(ctx, c.SAMPLE_CLT)

        # Make a cluster that references the cluster template
        cluster_values = copy.deepcopy(c.SAMPLE_CLUSTER)
        cluster_values["cluster_template_id"] = t["id"]
        del cluster_values["node_groups"]
        cl = self.api.cluster_create(ctx, cluster_values)

        # Set up the expected messages
        msgs = [
            "Cluster template {info} in use "
            "by clusters {clusters}".format(info=u.name_and_id(t),
                                            clusters=[cl["name"]])
        ]

        msgs += [
            "Deletion of cluster template {info} failed".format(
                info=u.name_and_id(t))
        ]

        # Check delete by name
        option_values = {
            "tenant_id": t["tenant_id"],
            "template_name": t["name"]
        }
        template_api.set_conf(Config(option_values))
        template_api.do_cluster_template_delete()
        for msg in msgs:
            self.assertIn(msg, self.logger.warnings)
        self.logger.clear_log()

        # Check again with delete by id
        option_values = {"tenant_id": t["tenant_id"], "id": t["id"]}
        template_api.set_conf(Config(option_values))
        template_api.do_cluster_template_delete_by_id()
        for msg in msgs:
            self.assertIn(msg, self.logger.warnings)
        self.logger.clear_log()
Example #8
0
    def test_cluster_template_delete_in_use(self):
        self.logger.clear_log()
        ctx = context.ctx()
        t = self.api.cluster_template_create(ctx, c.SAMPLE_CLT)

        # Make a cluster that references the cluster template
        cluster_values = copy.deepcopy(c.SAMPLE_CLUSTER)
        cluster_values["cluster_template_id"] = t["id"]
        del cluster_values["node_groups"]
        cl = self.api.cluster_create(ctx, cluster_values)

        # Set up the expected messages
        msgs = ["Cluster template {info} in use "
                "by clusters {clusters}".format(
                    info=u.name_and_id(t), clusters=[cl["name"]])]

        msgs += ["Deletion of cluster template {info} failed".format(
            info=u.name_and_id(t))]

        # Check delete by name
        option_values = {"tenant_id": t["tenant_id"],
                         "template_name": t["name"]}
        template_api.set_conf(Config(option_values))
        template_api.do_cluster_template_delete()
        for msg in msgs:
            self.assertIn(msg, self.logger.warnings)
        self.logger.clear_log()

        # Check again with delete by id
        option_values = {"tenant_id": t["tenant_id"],
                         "id": t["id"]}
        template_api.set_conf(Config(option_values))
        template_api.do_cluster_template_delete_by_id()
        for msg in msgs:
            self.assertIn(msg, self.logger.warnings)
        self.logger.clear_log()