Example #1
0
    def atomic_delete_profile(self, profile):
        """atomic_delete_profile

        Atomically delete a profile. This occurs in two stages: first the tag,
        then the rules. Abort if the first stage fails, as we can assume that
        someone else is trying to replace the profile.

        Tolerates attempting to delete keys that are already deleted.

        This will also attempt to clean up the directory, but isn't overly
        bothered if that fails.
        """
        LOG.info(
            "Deleting profile %s, tags modified %s, rules modified %s",
            profile.id,
            profile.tags_modified_index,
            profile.rules_modified_index
        )
        etcd_profile_id = with_openstack_sg_prefix(profile.id)

        # Try to delete tags and rules. We don't care if we can't, but we
        # should log in case it's symptomatic of a wider problem.
        try:
            self.client.delete(
                datamodel_v1.key_for_profile_tags(etcd_profile_id),
                prevIndex=profile.tags_modified_index,
                timeout=ETCD_TIMEOUT
            )
        except etcd.EtcdKeyNotFound:
            LOG.info(
                "Profile %s tags already deleted, nothing to do.", profile.id
            )

        try:
            self.client.delete(
                datamodel_v1.key_for_profile_rules(etcd_profile_id),
                prevIndex=profile.rules_modified_index,
                timeout=ETCD_TIMEOUT
            )
        except etcd.EtcdKeyNotFound:
            LOG.info(
                "Profile %s rules already deleted, nothing to do.", profile.id
            )

        # Strip the rules/tags specific part of the key.
        profile_key = datamodel_v1.key_for_profile(etcd_profile_id)

        try:
            self.client.delete(profile_key, dir=True, timeout=ETCD_TIMEOUT)
        except etcd.EtcdException as e:
            LOG.debug("Failed to delete %s (%r), giving up.", profile_key, e)
Example #2
0
    def atomic_delete_profile(self, profile):
        """atomic_delete_profile

        Atomically delete a profile. This occurs in two stages: first the tag,
        then the rules. Abort if the first stage fails, as we can assume that
        someone else is trying to replace the profile.

        Tolerates attempting to delete keys that are already deleted.

        This will also attempt to clean up the directory, but isn't overly
        bothered if that fails.
        """
        LOG.info("Deleting profile %s, tags modified %s, rules modified %s",
                 profile.id, profile.tags_modified_index,
                 profile.rules_modified_index)
        etcd_profile_id = with_openstack_sg_prefix(profile.id)

        # Try to delete tags and rules. We don't care if we can't, but we
        # should log in case it's symptomatic of a wider problem.
        try:
            self.client.delete(
                datamodel_v1.key_for_profile_tags(etcd_profile_id),
                prevIndex=profile.tags_modified_index,
                timeout=ETCD_TIMEOUT)
        except etcd.EtcdKeyNotFound:
            LOG.info("Profile %s tags already deleted, nothing to do.",
                     profile.id)

        try:
            self.client.delete(
                datamodel_v1.key_for_profile_rules(etcd_profile_id),
                prevIndex=profile.rules_modified_index,
                timeout=ETCD_TIMEOUT)
        except etcd.EtcdKeyNotFound:
            LOG.info("Profile %s rules already deleted, nothing to do.",
                     profile.id)

        # Strip the rules/tags specific part of the key.
        profile_key = datamodel_v1.key_for_profile(etcd_profile_id)

        try:
            self.client.delete(profile_key, dir=True, timeout=ETCD_TIMEOUT)
        except etcd.EtcdException as e:
            LOG.debug("Failed to delete %s (%r), giving up.", profile_key, e)
 def test_key_for_profile(self):
     self.assertEqual(key_for_profile("prof1"),
                      "/calico/v1/policy/profile/prof1")
 def test_key_for_profile(self):
     self.assertEqual(key_for_profile("prof1"), "/calico/v1/policy/profile/prof1")