How to use the cloudbridge.base.helpers.cleanup_action function in cloudbridge

To help you get started, we’ve selected a few cloudbridge examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CloudVE / cloudbridge / tests / helpers / __init__.py View on Github external
def cleanup_test_resources(instance=None, vm_firewall=None,
                           key_pair=None, network=None):
    """Clean up any combination of supplied resources."""
    with cb_helpers.cleanup_action(
            lambda: cleanup_network(network) if network else None):
        with cb_helpers.cleanup_action(
                lambda: key_pair.delete() if key_pair else None):
            with cb_helpers.cleanup_action(
                    lambda: vm_firewall.delete() if vm_firewall else None):
                delete_instance(instance)
github CloudVE / cloudbridge / tests / test_block_store_service.py View on Github external
def test_crud_snapshot(self):
        # Create a new volume, create a snapshot of the volume, and check
        # whether list_snapshots properly detects the new snapshot.
        # Delete everything afterwards.
        label = "cb-crudsnap-{0}".format(helpers.get_uuid())
        test_vol = self.provider.storage.volumes.create(
            label, 1)
        with cb_helpers.cleanup_action(lambda: test_vol.delete()):
            test_vol.wait_till_ready()

            def create_snap(label):
                return test_vol.create_snapshot(label=label,
                                                description=label)

            def cleanup_snap(snap):
                if snap:
                    snap.delete()
                    snap.wait_for([SnapshotState.UNKNOWN],
                                  terminal_states=[SnapshotState.ERROR])
                    snap.refresh()
                    self.assertTrue(
                        snap.state == SnapshotState.UNKNOWN,
                        "Snapshot.state must be unknown when refreshing after "
                        "a delete but got %s"
github CloudVE / cloudbridge / tests / test_dns_service.py View on Github external
def test_dns_record_properties(self):
        test_zone = None
        zone_name = "cb-recprop-{0}.com.".format(helpers.get_uuid())

        with cb_helpers.cleanup_action(lambda: test_zone.delete()):
            test_zone = self.provider.dns.host_zones.create(
                zone_name, "admin@cloudve.org")
            test_rec = None

            with cb_helpers.cleanup_action(lambda: test_rec.delete()):
                zone_name = "subdomain." + zone_name
                test_rec = test_zone.records.create(
                    zone_name, DnsRecordType.CNAME, data='hello.com.', ttl=500)
                self.assertEqual(test_rec.zone_id, test_zone.id)
                self.assertEqual(test_rec.type, DnsRecordType.CNAME)
                self.assertEqual(test_rec.data, ['hello.com.'])
                self.assertEqual(test_rec.ttl, 500)

            # Check setting data array
            test_rec2 = None
            with cb_helpers.cleanup_action(lambda: test_rec2.delete()):
                MX_DATA = ['10 mx1.hello.com.', '20 mx2.hello.com.']
                test_rec2 = test_zone.records.create(
                    zone_name, DnsRecordType.MX, data=MX_DATA, ttl=300)
                self.assertEqual(test_rec2.zone_id, test_zone.id)
                self.assertEqual(test_rec2.type, DnsRecordType.MX)
github CloudVE / cloudbridge / tests / helpers / __init__.py View on Github external
def cleanup_gateway(gateway):
    """
    Delete the supplied network and gateway.
    """
    with cb_helpers.cleanup_action(lambda: gateway.delete()):
        pass
github CloudVE / cloudbridge / tests / test_block_store_service.py View on Github external
isinstance(test_vol.description, six.string_types),
                    "Snapshot.description must be None or a string. Got: %s"
                    % test_vol.description)
                self.assertEqual(test_vol.id, test_snap.volume_id)
                self.assertIsNotNone(test_vol.create_time)
                test_snap.label = 'snapnewname1'
                test_snap.description = 'snapnewdescription1'
                test_snap.refresh()
                self.assertEqual(test_snap.label, 'snapnewname1')
                self.assertEqual(test_snap.description, 'snapnewdescription1')

                # Test volume creation from a snapshot (via VolumeService)
                sv_label = "cb-snapvol-{0}".format(test_snap.name)
                snap_vol = self.provider.storage.volumes.create(
                    sv_label, 1, snapshot=test_snap)
                with cb_helpers.cleanup_action(lambda: snap_vol.delete()):
                    snap_vol.wait_till_ready()

                # Test volume creation from a snapshot (via Snapshot)
                snap_vol2 = test_snap.create_volume()
                with cb_helpers.cleanup_action(lambda: snap_vol2.delete()):
                    snap_vol2.wait_till_ready()
github CloudVE / cloudbridge / tests / test_dns_service.py View on Github external
def test_create_dns_zones_not_fully_qualified(self):
        zone_name = "cb-dnszonenfq-{0}.com".format(helpers.get_uuid())
        test_zone = None
        with cb_helpers.cleanup_action(lambda: test_zone.delete()):
            # If zone name is not fully qualified, it should automatically be
            # handled
            test_zone = self.provider.dns.host_zones.create(
                zone_name, "admin@cloudve.org")
github CloudVE / cloudbridge / tests / test_dns_service.py View on Github external
def test_create_dns_rec_not_fully_qualified(self):
        test_zone = None
        root_zone_name = "cb-recprop-{0}.com.".format(helpers.get_uuid())

        with cb_helpers.cleanup_action(lambda: test_zone.delete()):
            test_zone = self.provider.dns.host_zones.create(
                root_zone_name, "admin@cloudve.org")
            test_rec = None

            with cb_helpers.cleanup_action(lambda: test_rec.delete()):
                zone_name = "subdomain." + root_zone_name
                test_rec = test_zone.records.create(
                    zone_name, DnsRecordType.CNAME, data='hello.com', ttl=500)

            with cb_helpers.cleanup_action(lambda: test_rec.delete()):
                test_rec = test_zone.records.create(
                    root_zone_name, DnsRecordType.MX,
                    data=['10 mx1.hello.com', '20 mx2.hello.com'], ttl=500)
github CloudVE / cloudbridge / tests / helpers / standard_interface_tests.py View on Github external
but before object cleanup. It will receive the
                            created object as a parameter.

    :type  custom_check_delete: ``func``
    :param custom_check_delete: If provided, this function will be called
                                instead of the standard check_delete function
                                to make sure that the object has been deleted.

    :type  skip_name_check: ``boolean``
    :param skip_name_check:  If True, the name related checking will be
                             skipped.

    """

    obj = None
    with cb_helpers.cleanup_action(lambda: cleanup_func(obj)):
        label = "{0}-{1}".format(label_prefix, helpers.get_uuid())
        if not skip_name_check:
            check_create(test, service, iface, label_prefix,
                         create_func, cleanup_func)
        obj = create_func(label)
        if issubclass(iface, ObjectLifeCycleMixin):
            obj.wait_till_ready()
        check_standard_behaviour(test, service, obj)
        if extra_test_func:
            extra_test_func(obj)
    if custom_check_delete:
        custom_check_delete(obj)
    else:
        check_delete(test, service, obj)
github galaxyproject / cloudlaunch / django-cloudlaunch / cloudlaunch / backend_plugins / cloudman2_app.py View on Github external
def cleanup_iam_policy(self):
        sts = self.provider.session.client('sts')
        account_id = sts.get_caller_identity()['Account']
        policy_arn = f'arn:aws:iam::{account_id}:policy/cm2-kube-policy'
        role_name = self.dpl_name + "-cm2-kube-role"
        profile_name = self.dpl_name + '-cm2-kube-role'

        with cleanup_action(lambda: self._delete_iam_role(
                self.dpl_name + "-cm2-kube-role")):
            with cleanup_action(lambda: self._delete_instance_profile(
                    self.dpl_name + '-cm2-kube-role')):
                with cleanup_action(
                        lambda: self._detach_role_from_instance_profile(
                            profile_name, role_name)):
                    with cleanup_action(lambda: self._delete_iam_policy(
                            policy_arn)):
                        with cleanup_action(
                                lambda: self._detach_policy_from_role(
                                    role_name, policy_arn)):
                            pass