def test_cluster_template_delete_by_name(self): self.logger.clear_log() ctx = context.ctx() t = self.api.cluster_template_create(ctx, c.SAMPLE_NGT) option_values = {"tenant_id": t["tenant_id"], "template_name": t["name"]} template_api.set_conf(Config(option_values)) template_api.do_cluster_template_delete() 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)
def test_cluster_template_delete_by_name_skipped(self): self.logger.clear_log() ctx = context.ctx() template_values = copy.copy(c.SAMPLE_NGT) template_values["is_default"] = False t = self.api.cluster_template_create(ctx, template_values) option_values = {"tenant_id": t["tenant_id"], "template_name": t["name"]} template_api.set_conf(Config(option_values)) template_api.do_cluster_template_delete() msg = ("Deletion of cluster template {name} failed, " "no such template".format(name=t["name"])) self.assertIn(msg, self.logger.warnings) t = self.api.cluster_template_get(ctx, t["id"]) self.assertIsNotNone(t)
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()
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()