Пример #1
0
 def test_change_status_description(self):
     ctx = context.ctx()
     cluster = self._make_sample()
     cluster_id = cluster.id
     cluster = general.change_cluster_status_description(cluster, "desc")
     self.assertEqual('desc', cluster.status_description)
     self.api.cluster_destroy(ctx, cluster)
     cluster = general.change_cluster_status_description(cluster_id, "desc")
     self.assertIsNone(cluster)
Пример #2
0
        def wrapper(cluster_id, *args, **kwds):
            ctx = context.ctx()
            try:
                # Clearing status description before executing
                g.change_cluster_status_description(cluster_id, "")
                f(cluster_id, *args, **kwds)
            except Exception as ex:
                # something happened during cluster operation
                cluster = conductor.cluster_get(ctx, cluster_id)
                # check if cluster still exists (it might have been removed)
                if cluster is None or cluster.status == 'Deleting':
                    LOG.debug(
                        "Cluster id={id} was deleted or marked for "
                        "deletion. Canceling current operation.".format(
                            id=cluster_id))
                    return

                msg = six.text_type(ex)
                LOG.error(
                    _LE("Error during operating on cluster {name} (reason: "
                        "{reason})").format(name=cluster.name, reason=msg))

                try:
                    # trying to rollback
                    desc = description.format(reason=msg)
                    if _rollback_cluster(cluster, ex):
                        g.change_cluster_status(cluster, "Active", desc)
                    else:
                        g.change_cluster_status(cluster, "Error", desc)
                except Exception as rex:
                    cluster = conductor.cluster_get(ctx, cluster_id)
                    # check if cluster still exists (it might have been
                    # removed during rollback)
                    if cluster is None or cluster.status == 'Deleting':
                        LOG.debug(
                            "Cluster id={id} was deleted or marked for "
                            "deletion. Canceling current operation."
                            .format(id=cluster_id))
                        return

                    LOG.error(
                        _LE("Error during rollback of cluster {name} (reason:"
                            " {reason})").format(name=cluster.name,
                                                 reason=six.text_type(rex)))
                    desc = "{0}, {1}".format(msg, six.text_type(rex))
                    g.change_cluster_status(
                        cluster, "Error", description.format(reason=desc))