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)
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))
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)
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)
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)
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))
def _create_for_volume(self, trigger_properties=DEFAULT_PROPERTY, operation_name=None): volume = self.store(objects.Volume()) volume.create(1) return self._create_scheduled_operation([ volume, ], trigger_properties, operation_name)
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)
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)
def test_protectables_list_instances(self): res_list = self.karbor_client.protectables.list_instances( 'OS::Cinder::Volume') before_num = len(res_list) volume1 = self.store(objects.Volume()) volume1.create(1) res_list = self.karbor_client.protectables.list_instances( 'OS::Cinder::Volume') after_num = len(res_list) self.assertEqual(1, after_num - before_num)
def test_protectables_get_instance(self): volume = self.store(objects.Volume()) volume.create(1) instance = self.karbor_client.protectables.get_instance( 'OS::Cinder::Volume', volume.id) self.assertEqual(volume.id, instance.id) server = self.store(objects.Server()) server.create() instance = self.karbor_client.protectables.get_instance( 'OS::Nova::Server', server.id) self.assertEqual(server.id, instance.id)
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)
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 test_protectables_list_instances(self): volume = self.store(objects.Volume()) volume.create(1) items = self.karbor_client.protectables.list_instances( 'OS::Cinder::Volume') ids = [item.id for item in items] self.assertTrue(volume.id in ids) server = self.store(objects.Server()) server.create() items = self.karbor_client.protectables.list_instances( 'OS::Nova::Server') ids = [item.id for item in items] self.assertTrue(server.id in ids)
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)
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)
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)
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)
def test_protectables_get_with_attach_volume(self): server = self.store(objects.Server()) server.create() volume = self.store(objects.Volume()) volume.create(1) server.attach_volume(volume.id) volume_item = self.cinder_client.volumes.get(volume.id) ins_res = self.karbor_client.protectables.get_instance( 'OS::Nova::Server', volume_item.attachments[0]["server_id"]) self.assertTrue(ins_res.dependent_resources) self.assertEqual('OS::Cinder::Volume', ins_res.dependent_resources[0]["type"]) self.assertEqual(volume.id, ins_res.dependent_resources[0]["id"])
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)
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)
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)
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)
def test_protectables_list_instances(self): volume = self.store(objects.Volume()) volume.create(1) items = self.karbor_client.protectables.list_instances( 'OS::Cinder::Volume') ids = [item.id for item in items] self.assertTrue(volume.id in ids) server = self.store(objects.Server()) server.create() items = self.karbor_client.protectables.list_instances( 'OS::Nova::Server') ids = [item.id for item in items] self.assertTrue(server.id in ids) network = self.store(objects.Network()) network.create() items = self.karbor_client.protectables.list_instances( 'OS::Neutron::Network') self.assertEqual(items[0].id, network.project_id)
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)
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)
def _store_volume(self, volumes_pre, volumes_post): volumes = list(set(volumes_post).difference(set(volumes_pre))) for volume in volumes: volume_ = objects.Volume() volume_.id = volume.id self.store(volume_)