Exemplo n.º 1
0
    def test_plans_list(self):
        nplans_before = len(self.karbor_client.plans.list())
        # create plan
        volume = self.store(objects.Volume())
        volume.create(1)
        plan1 = self.store(objects.Plan())
        plan2 = self.store(objects.Plan())
        plan1.create(self.provider_id, [volume, ])
        plan2.create(self.provider_id, [volume, ])

        # list plans after creating
        nplans_after = len(self.karbor_client.plans.list())
        self.assertEqual(2, nplans_after - nplans_before)
Exemplo n.º 2
0
    def test_checkpoint_for_server_attached_volume(self):
        """Test checkpoint for server which has attached some volumes"""
        volume = self.store(objects.Volume())
        volume.create(1)
        server = self.store(objects.Server())
        server.create()
        server.attach_volume(volume.id)

        plan0 = self.store(objects.Plan())
        plan0.create(self.provider_id, [
            server,
        ])

        checkpoints = self.karbor_client.checkpoints.list(self.provider_id)
        before_checkpoints_num = len(checkpoints)
        backups = self.cinder_client.backups.list()
        before_backups_num = len(backups)

        checkpoint = self.store(objects.Checkpoint())
        checkpoint.create(self.provider_id, plan0.id, timeout=900)

        checkpoints = self.karbor_client.checkpoints.list(self.provider_id)
        after_checkpoints_num = len(checkpoints)
        self.assertEqual(1, after_checkpoints_num - before_checkpoints_num)

        backups = self.cinder_client.backups.list()
        after_backups_num = len(backups)
        self.assertEqual(1, after_backups_num - before_backups_num)

        plan1 = self.store(objects.Plan())
        plan1.create(self.provider_id, [server, volume])

        checkpoints = self.karbor_client.checkpoints.list(self.provider_id)
        before_checkpoints_num = len(checkpoints)
        backups = self.cinder_client.backups.list()
        before_backups_num = len(backups)

        checkpoint = self.store(objects.Checkpoint())
        checkpoint.create(self.provider_id, plan1.id, timeout=720)

        checkpoints = self.karbor_client.checkpoints.list(self.provider_id)
        after_checkpoints_num = len(checkpoints)
        self.assertEqual(1, after_checkpoints_num - before_checkpoints_num)

        backups = self.cinder_client.backups.list()
        after_backups_num = len(backups)
        self.assertEqual(1, after_backups_num - before_backups_num)

        server.detach_volume(volume.id)
Exemplo n.º 3
0
    def test_restore_list(self):
        volume = self.store(objects.Volume())
        volume.create(1)
        plan = self.store(objects.Plan())
        plan.create(self.provider_id_noop, [
            volume,
        ])
        checkpoint = self.store(objects.Checkpoint())
        checkpoint.create(self.provider_id_noop, plan.id)

        restores = self.karbor_client.restores.list()
        before_num = len(restores)

        restore_target = self.get_restore_target(self.keystone_endpoint)
        restore1 = self.store(objects.Restore())
        restore1.create(self.provider_id_noop, checkpoint.id, restore_target,
                        self.parameters, self.restore_auth)
        restore2 = self.store(objects.Restore())
        restore2.create(self.provider_id_noop, checkpoint.id, restore_target,
                        self.parameters, self.restore_auth)

        restores = self.karbor_client.restores.list()
        after_num = len(restores)
        self.assertLessEqual(2, after_num - before_num)

        item1 = self.karbor_client.restores.get(restore1.id)
        self._store(item1.resources_status)
        item2 = self.karbor_client.restores.get(restore2.id)
        self._store(item2.resources_status)
Exemplo n.º 4
0
    def test_server_attached_volume_protect_both(self):
        """Test checkpoint for server with attached volume

        Test checkpoint for server which has attached one volume,
        and add server and volume both in protect source
        """
        volume = self.store(objects.Volume())
        volume.create(1)
        server = self.store(objects.Server())
        server.create()
        server.attach_volume(volume.id)

        plan = self.store(objects.Plan())
        plan.create(self.provider_id, [server, volume])

        checkpoint = self.store(objects.Checkpoint())
        checkpoint.create(self.provider_id, plan.id, timeout=2400)

        items = self.karbor_client.checkpoints.list(self.provider_id)
        ids = [item.id for item in items]
        self.assertTrue(checkpoint.id in ids)
        search_opts = {"volume_id": volume.id}
        backups = self.cinder_client.backups.list(search_opts=search_opts)
        self.assertEqual(1, len(backups))
        server.detach_volume(volume.id)
Exemplo n.º 5
0
    def test_server_boot_from_volume_with_attached_volume(self):
        """Test checkpoint for server with a bootable volume

        Test checkpoint for server which has booted form one bootable
        volume.
        """
        bootable_volume = self.store(objects.Volume())
        bootable_volume_id = bootable_volume.create(1, create_from_image=True)
        volume = self.store(objects.Volume())
        volume.create(1)
        server = self.store(objects.Server())
        server.create(volume=bootable_volume_id)
        server.attach_volume(volume.id)

        plan = self.store(objects.Plan())
        plan.create(self.provider_id, [
            server,
        ])

        checkpoint = self.store(objects.Checkpoint())
        checkpoint.create(self.provider_id, plan.id, timeout=2400)

        items = self.karbor_client.checkpoints.list(self.provider_id)
        ids = [item.id for item in items]
        self.assertTrue(checkpoint.id in ids)
        search_opts = {"volume_id": volume.id}
        backups = self.cinder_client.backups.list(search_opts=search_opts)
        self.assertEqual(1, len(backups))
        search_opts = {"volume_id": bootable_volume_id}
        bootable_backups = self.cinder_client.backups.list(
            search_opts=search_opts)
        self.assertEqual(1, len(bootable_backups))
        server.detach_volume(volume.id)
Exemplo n.º 6
0
    def test_checkpoint_share_projection(self):
        share = self.store(objects.Share())
        share.create("NFS", 1)
        plan = self.store(objects.Plan())

        share_parameter_key = "OS::Manila::Share#{id}".format(id=share.id)
        snapshot_name = "share-snapshot-{id}".format(id=share.id)
        parameters = {
            "OS::Manila::Share": {
                "force": False
            },
            share_parameter_key: {
                "snapshot_name": snapshot_name
            }
        }
        plan.create(self.provider_id_os, [
            share,
        ], parameters=parameters)

        checkpoint = self.store(objects.Checkpoint())
        checkpoint.create(self.provider_id, plan.id, timeout=2400)

        search_opts = {"share_id": share.id}
        snapshots = self.manila_client.share_snapshots.list(
            search_opts=search_opts)
        self.assertEqual(1, len(snapshots))

        search_opts = {"name": snapshot_name}
        backups = self.manila_client.share_snapshots.list(
            search_opts=search_opts)
        self.assertEqual(1, len(backups))
Exemplo n.º 7
0
    def test_checkpoint_volume_snapshot(self):
        volume = self.store(objects.Volume())
        volume.create(1)
        plan = self.store(objects.Plan())
        volume_parameter_key = "OS::Cinder::Volume#{id}".format(id=volume.id)
        snapshot_name = "volume-snapshot-{id}".format(id=volume.id)
        parameters = {
            "OS::Cinder::Volume": {
                "force": False
            },
            volume_parameter_key: {
                "snapshot_name": snapshot_name
            }
        }
        plan.create(self.provider_id_os_volume_snapshot, [
            volume,
        ],
                    parameters=parameters)

        checkpoint = self.store(objects.Checkpoint())
        checkpoint.create(self.provider_id_os_volume_snapshot,
                          plan.id,
                          timeout=2400)

        search_opts = {"volume_id": volume.id}
        snapshots = self.cinder_client.volume_snapshots.list(
            search_opts=search_opts)
        self.assertEqual(1, len(snapshots))

        search_opts = {"name": snapshot_name}
        snapshots = self.cinder_client.volume_snapshots.list(
            search_opts=search_opts)
        self.assertEqual(1, len(snapshots))
Exemplo n.º 8
0
    def test_checkpoint_create(self):
        volume = self.store(objects.Volume())
        volume.create(1)
        plan = self.store(objects.Plan())
        volume_parameter_key = "OS::Cinder::Volume#{id}".format(id=volume.id)
        backup_name = "volume-backup-{id}".format(id=volume.id)
        parameters = {
            "OS::Cinder::Volume": {
                "backup_mode": "full",
                "force": False
            },
            volume_parameter_key: {
                "backup_name": backup_name
            }
        }
        plan.create(self.provider_id_os, [
            volume,
        ], parameters=parameters)

        checkpoint = self.store(objects.Checkpoint())
        checkpoint.create(self.provider_id, plan.id, timeout=2400)

        search_opts = {"volume_id": volume.id}
        backups = self.cinder_client.backups.list(search_opts=search_opts)
        self.assertEqual(1, len(backups))

        search_opts = {"name": backup_name}
        backups = self.cinder_client.backups.list(search_opts=search_opts)
        self.assertEqual(1, len(backups))
Exemplo n.º 9
0
    def test_restore_create(self):
        volume = self.store(objects.Volume())
        volume.create(1)
        plan = self.store(objects.Plan())
        plan.create(self.provider_id, [
            volume,
        ])
        checkpoint = self.store(objects.Checkpoint())
        checkpoint.create(self.provider_id, plan.id)

        restores = self.karbor_client.restores.list()
        before_num = len(restores)
        volumes_pre = self.cinder_client.volumes.list()

        restore_target = self.get_restore_target(self.keystone_endpoint)
        restore = self.store(objects.Restore())
        restore.create(self.provider_id, checkpoint.id, restore_target,
                       self.parameters, self.restore_auth)

        restores = self.karbor_client.restores.list()
        after_num = len(restores)
        self.assertEqual(1, after_num - before_num)

        volumes_post = self.cinder_client.volumes.list()
        self._store_volume(volumes_pre, volumes_post)
Exemplo n.º 10
0
    def test_plans_get(self):
        plan_name = "Fullstack Test Get"
        volume = self.store(objects.Volume())
        volume.create(1)
        plan = self.store(objects.Plan())
        plan.create(self.provider_id, [volume, ], name=plan_name)

        plan_item = self.karbor_client.plans.get(plan.id)
        self.assertEqual(plan_name, plan_item.name)
Exemplo n.º 11
0
    def test_checkpoint_list(self):
        volume = self.store(objects.Volume())
        volume.create(1)
        plan = self.store(objects.Plan())
        plan.create(self.provider_id_noop, [
            volume,
        ])

        checkpoint = self.store(objects.Checkpoint())
        checkpoint.create(self.provider_id_noop, plan.id, timeout=2400)

        items = self.karbor_client.checkpoints.list(self.provider_id_noop)
        ids = [item.id for item in items]
        self.assertTrue(checkpoint.id in ids)
 def _create_scheduled_operation_for_server(
         self, trigger_properties=DEFAULT_PROPERTY, operation_name=None):
     server = self.store(objects.Server())
     server.create()
     plan = self.store(objects.Plan())
     plan.create(self.provider_id, [
         server,
     ])
     operation_definition = {
         'plan_id': plan.id,
         'provider_id': self.provider_id
     }
     return self._create_scheduled_operation(trigger_properties,
                                             operation_definition,
                                             operation_name)
 def _create_scheduled_operation_for_volume(
         self, trigger_properties=DEFAULT_PROPERTY, operation_name=None):
     volume = self.store(objects.Volume())
     volume.create(1)
     plan = self.store(objects.Plan())
     plan.create(self.provider_id, [
         volume,
     ])
     operation_definition = {
         'plan_id': plan.id,
         'provider_id': self.provider_id
     }
     return self._create_scheduled_operation(trigger_properties,
                                             operation_definition,
                                             operation_name)
Exemplo n.º 14
0
    def test_checkpoint_list(self):
        volume = self.store(objects.Volume())
        volume.create(1)
        plan = self.store(objects.Plan())
        plan.create(self.provider_id, [volume, ])

        checkpoints = self.karbor_client.checkpoints.list(self.provider_id)
        before_num = len(checkpoints)

        checkpoint = self.store(objects.Checkpoint())
        checkpoint.create(self.provider_id, plan.id)

        checkpoints = self.karbor_client.checkpoints.list(self.provider_id)
        after_num = len(checkpoints)
        self.assertEqual(1, after_num - before_num)
Exemplo n.º 15
0
    def test_checkpoint_get(self):
        volume = self.store(objects.Volume())
        volume.create(1)
        plan = self.store(objects.Plan())
        plan.create(self.provider_id, [volume, ])

        checkpoint = self.store(objects.Checkpoint())
        checkpoint.create(self.provider_id, plan.id)

        # sanity
        checkpoint_item = self.karbor_client.checkpoints.get(self.provider_id,
                                                             checkpoint.id)
        self.assertEqual(constants.CHECKPOINT_STATUS_AVAILABLE,
                         checkpoint_item.status)
        self.assertEqual(checkpoint.id, checkpoint_item.id)
Exemplo n.º 16
0
    def test_restore_create_without_target_and_auth(self):
        volume = self.store(objects.Volume())
        volume.create(1)
        plan = self.store(objects.Plan())
        plan.create(self.provider_id_noop, [volume, ])
        checkpoint = self.store(objects.Checkpoint())
        checkpoint.create(self.provider_id_noop, plan.id)

        restore = self.store(objects.Restore())
        restore.create(self.provider_id_noop, checkpoint.id,
                       None, self.parameters, None)

        item = self.karbor_client.restores.get(restore.id)
        self.assertEqual(constants.RESTORE_STATUS_SUCCESS,
                         item.status)
        self._store(item.resources_status)
Exemplo n.º 17
0
    def test_restore_resources_with_fs_bank(self):
        volume = self.store(objects.Volume())
        volume.create(1)
        plan = self.store(objects.Plan())
        plan.create(self.provider_id_noop, [volume, ])
        checkpoint = self.store(objects.Checkpoint())
        checkpoint.create(self.provider_id_noop, plan.id)

        restore_target = self.get_restore_target(self.keystone_endpoint)
        restore = self.store(objects.Restore())
        restore.create(self.provider_id_noop, checkpoint.id,
                       restore_target, self.parameters, self.restore_auth)

        item = self.karbor_client.restores.get(restore.id)
        self.assertEqual(constants.RESTORE_STATUS_SUCCESS,
                         item.status)
Exemplo n.º 18
0
    def _create_scheduled_operation(self,
                                    resources,
                                    trigger_properties=DEFAULT_PROPERTY,
                                    operation_name=None):
        plan = self.store(objects.Plan())
        plan.create(self.provider_id, resources)
        operation_definition = {
            'plan_id': plan.id,
            'provider_id': self.provider_id
        }
        trigger = self.store(objects.Trigger())
        trigger.create('time', trigger_properties)

        operation = objects.ScheduledOperation()
        operation.create('protect', trigger.id, operation_definition,
                         operation_name)
        return operation
Exemplo n.º 19
0
    def test_restore_network_resources(self):
        network = self.store(objects.Network())
        network.create()
        plan = self.store(objects.Plan())
        plan.create(self.provider_id_os, [network, ])
        checkpoint = self.store(objects.Checkpoint())
        checkpoint.create(self.provider_id_os, plan.id)
        network.close()

        restore_target = self.get_restore_target(self.keystone_endpoint)
        restore = self.store(objects.Restore())
        restore.create(self.provider_id_os, checkpoint.id,
                       restore_target, self.parameters, self.restore_auth)

        item = self.karbor_client.restores.get(restore.id)
        self.assertEqual(constants.RESTORE_STATUS_SUCCESS,
                         item.status)
        self._store(item.resources_status)
Exemplo n.º 20
0
    def test_checkpoint_create(self):
        self.skipTest('Requires cinder protection plugin adjustment')
        volume = self.store(objects.Volume())
        volume.create(1)
        plan = self.store(objects.Plan())
        plan.create(self.provider_id_os, [
            volume,
        ])

        backups = self.cinder_client.backups.list()
        before_num = len(backups)

        checkpoint = self.store(objects.Checkpoint())
        checkpoint.create(self.provider_id, plan.id)

        backups = self.cinder_client.backups.list()
        after_num = len(backups)
        self.assertEqual(1, after_num - before_num)
Exemplo n.º 21
0
    def test_plans_update(self):
        plan_initial_name = "Fullstack Plan Pre-Update"
        plan_updated_name = "Fullstack Plan Post-Update"
        volume1_name = "Fullstack Plan Update Volume1"
        volume2_name = "Fullstack Plan Update Volume2"
        volume1 = self.store(objects.Volume())
        volume1.create(1, name=volume1_name)
        volume2 = self.store(objects.Volume())
        volume2.create(1, name=volume2_name)
        plan = self.store(objects.Plan())
        plan.create(self.provider_id, [
            volume1,
        ], name=plan_initial_name)

        # sanity
        plan_item = self.karbor_client.plans.get(plan.id)
        self.assertEqual(plan_initial_name, plan_item.name)
        self.assertEqual("suspended", plan_item.status)
        self.assertEqual([{
            "id": volume1.id,
            "type": constants.VOLUME_RESOURCE_TYPE,
            "name": volume1_name
        }], plan_item.resources)

        # update name
        data = {"name": plan_updated_name}
        plan_item = self.karbor_client.plans.update(plan.id, data)
        self.assertEqual(plan_updated_name, plan_item.name)

        # update resources
        data = {
            "resources": [
                volume2.to_dict(),
            ]
        }
        plan_item = self.karbor_client.plans.update(plan.id, data)
        self.assertEqual([
            volume2.to_dict(),
        ], plan_item.resources)

        # update status
        data = {"status": "started"}
        plan_item = self.karbor_client.plans.update(plan.id, data)
        self.assertEqual("started", plan_item.status)
Exemplo n.º 22
0
    def test_checkpoint_delete(self):
        volume = self.store(objects.Volume())
        volume.create(1)
        plan = self.store(objects.Plan())
        plan.create(self.provider_id, [
            volume,
        ])

        checkpoint = objects.Checkpoint()
        checkpoint.create(self.provider_id, plan.id, timeout=2400)
        checkpoint_item = self.karbor_client.checkpoints.get(
            self.provider_id, checkpoint.id)
        self.assertEqual(constants.CHECKPOINT_STATUS_AVAILABLE,
                         checkpoint_item.status)

        checkpoint.close()
        items = self.karbor_client.checkpoints.list(self.provider_id)
        ids = [item.id for item in items]
        self.assertTrue(checkpoint.id not in ids)
Exemplo n.º 23
0
    def test_checkpoint_delete(self):
        volume = self.store(objects.Volume())
        volume.create(1)
        plan = self.store(objects.Plan())
        plan.create(self.provider_id, [volume, ])

        checkpoints = self.karbor_client.checkpoints.list(self.provider_id)
        before_num = len(checkpoints)

        checkpoint = objects.Checkpoint()
        checkpoint.create(self.provider_id, plan.id)

        # sanity
        checkpoint_item = self.karbor_client.checkpoints.get(self.provider_id,
                                                             checkpoint.id)
        self.assertEqual(constants.CHECKPOINT_STATUS_AVAILABLE,
                         checkpoint_item.status)

        checkpoint.close()
        checkpoints = self.karbor_client.checkpoints.list(self.provider_id)
        after_num = len(checkpoints)
        self.assertEqual(before_num, after_num)
Exemplo n.º 24
0
    def test_server_attached_volume_only_protect_server(self):
        """Test checkpoint for server with attached volume

        Test checkpoint for server which has attached one volume,
        but only add server in protect source
        """
        volume = self.store(objects.Volume())
        volume.create(1)
        server = self.store(objects.Server())
        server.create()
        server.attach_volume(volume.id)

        plan = self.store(objects.Plan())
        plan.create(self.provider_id_noop, [
            server,
        ])

        checkpoint = self.store(objects.Checkpoint())
        checkpoint.create(self.provider_id_noop, plan.id, timeout=2400)

        items = self.karbor_client.checkpoints.list(self.provider_id_noop)
        ids = [item.id for item in items]
        self.assertTrue(checkpoint.id in ids)