def skip_if_needed(cls): from cinderclient.exceptions import NotFound, ClientException try: cgm = ConsistencygroupManager(get_cinder_v2_client()) cgm.list() except (ImportError, NotFound, ClientException): raise SkipTest("This openstack version doesn't support consistency groups")
def remove_volumes_from_cgs(): cinder_client = get_cinder_v2_client() cgm = ConsistencygroupManager(get_cinder_v2_client()) for volume in cinder_client.volumes.list(): if volume.consistencygroup_id: cg = cgm.get(volume.consistencygroup_id) cg.update(remove_volumes=volume.id) cls.wait_for_removal_from_consistencygroup(volume, timeout=30)
def cg_context(self, name, pool): cgm = ConsistencygroupManager(get_cinder_v2_client()) cg = cgm.create(name=name, volume_types=self.get_infinidat_volume_type(pool)) self.wait_for_object_creation(cg, timeout=30) try: yield cg finally: cg.delete() self.wait_for_object_deletion(cg, timeout=30)
def volume_context(self, name, pool, consistencygroup_id=None, delete=True): from cinderclient.v2.volumes import VolumeManager vm = VolumeManager(get_cinder_v2_client()) cgm = ConsistencygroupManager(get_cinder_v2_client()) kwargs = {"name": name, "size": 1, "volume_type": self.get_infinidat_volume_type(pool)} if consistencygroup_id: kwargs["consistencygroup_id"] = consistencygroup_id vol = vm.create(**kwargs) self.wait_for_object_creation(vol, timeout=30) try: yield vol finally: if delete: vol.get() if vol.consistencygroup_id: cg = cgm.get(vol.consistencygroup_id) cg.update(remove_volumes=vol.id) self.wait_for_removal_from_consistencygroup(vol, timeout=30) vol.delete() self.wait_for_object_deletion(vol, timeout=30)
def cleanup_cgs(): cgm = ConsistencygroupManager(get_cinder_v2_client()) for cg in cgm.list(): cg.delete()