def resource_setup(cls): if cls.protocol not in CONF.share.enable_protocols: message = "%s tests are disabled" % cls.protocol raise cls.skipException(message) utils.skip_if_manage_not_supported_for_version() super(ManageNFSSnapshotNegativeTest, cls).resource_setup() # Create share type cls.st_name = data_utils.rand_name("tempest-manage-st-name") cls.extra_specs = { 'storage_protocol': CONF.share.capability_storage_protocol, 'driver_handles_share_servers': CONF.share.multitenancy_enabled, 'snapshot_support': six.text_type(CONF.share.capability_snapshot_support), } cls.st = cls.create_share_type(name=cls.st_name, cleanup_in_class=True, extra_specs=cls.extra_specs) # Create share cls.share = cls.create_share(share_type_id=cls.st['share_type']['id'], share_protocol=cls.protocol)
def _test_manage(self, snapshot, version=CONF.share.max_api_microversion): name = ("Name for 'managed' snapshot that had ID %s" % snapshot['id']) description = "Description for 'managed' snapshot" utils.skip_if_manage_not_supported_for_version(version) # Manage snapshot share_id = snapshot['share_id'] snapshot = self.shares_v2_client.manage_snapshot( share_id, snapshot['provider_location'], name=name, description=description, # Some drivers require additional parameters passed as driver # options, as follows: # - size: Hitachi HNAS Driver driver_options={'size': snapshot['size']}, version=version, )['snapshot'] # Add managed snapshot to cleanup queue self.method_resources.insert( 0, { 'type': 'snapshot', 'id': snapshot['id'], 'client': self.shares_v2_client }) # Wait for success waiters.wait_for_resource_status(self.shares_v2_client, snapshot['id'], constants.STATUS_AVAILABLE, resource_name='snapshot') # Verify manage snapshot API response expected_keys = [ "status", "links", "share_id", "name", "share_proto", "created_at", "description", "id", "share_size", "size", "provider_location" ] if utils.is_microversion_ge(version, '2.17'): expected_keys.extend(["user_id", "project_id"]) actual_keys = snapshot.keys() # Strict key check self.assertEqual(set(expected_keys), set(actual_keys)) # Verify data of managed snapshot get_snapshot = self.shares_v2_client.get_snapshot( snapshot['id'])['snapshot'] self.assertEqual(name, get_snapshot['name']) self.assertEqual(description, get_snapshot['description']) self.assertEqual(snapshot['share_id'], get_snapshot['share_id']) # Delete snapshot self.shares_v2_client.delete_snapshot(get_snapshot['id']) self.shares_client.wait_for_resource_deletion( snapshot_id=get_snapshot['id']) self.assertRaises(lib_exc.NotFound, self.shares_v2_client.get_snapshot, get_snapshot['id'])
def test_manage_different_versions(self, version): """Run snapshot manage test for multiple versions. This test is configured with ddt to run for the configured maximum version as well as versions 2.12 (when the API was introduced) and 2.16. """ utils.skip_if_manage_not_supported_for_version(version) # Skip in case specified version is not supported utils.check_skip_if_microversion_not_supported(version) snap_name = data_utils.rand_name("tempest-snapshot-name") snap_desc = data_utils.rand_name("tempest-snapshot-description") # Create snapshot snapshot = self.create_snapshot_wait_for_active( self.share['id'], snap_name, snap_desc) snapshot = self.shares_v2_client.get_snapshot( snapshot['id'])['snapshot'] # Unmanage snapshot self.shares_v2_client.unmanage_snapshot(snapshot['id'], version=version) self.shares_client.wait_for_resource_deletion( snapshot_id=snapshot['id']) # Manage snapshot self._test_manage(snapshot=snapshot, version=version)
def skip_checks(cls): super(ManageNFSShareTest, cls).skip_checks() if not CONF.share.run_manage_unmanage_tests: raise cls.skipException('Manage/unmanage tests are disabled.') if cls.protocol not in CONF.share.enable_protocols: message = "%s tests are disabled" % cls.protocol raise cls.skipException(message) utils.skip_if_manage_not_supported_for_version()
def _test_manage(self, is_public=False, version=CONF.share.max_api_microversion, check_manage=False): utils.skip_if_manage_not_supported_for_version(version) share = self._create_share_for_manage() name = "Name for 'managed' share that had ID %s" % share['id'] description = "Description for 'managed' share" # Unmanage share self._unmanage_share_and_wait(share) if check_manage: # After 'unmanage' operation, share instance should be deleted. # Assert not related to 'manage' test, but placed here for # resource optimization. share_instance_list = self.shares_v2_client.list_share_instances() share_ids = [si['share_id'] for si in share_instance_list] self.assertNotIn(share['id'], share_ids) # Manage share manage_params = { 'service_host': share['host'], 'export_path': share['export_locations'][0], 'protocol': share['share_proto'], 'share_type_id': self.st['share_type']['id'], 'name': name, 'description': description, 'is_public': is_public, 'version': version, } if CONF.share.multitenancy_enabled: manage_params['share_server_id'] = share['share_server_id'] managed_share = self.shares_v2_client.manage_share(**manage_params) # Add managed share to cleanup queue self.method_resources.insert( 0, { 'type': 'share', 'id': managed_share['id'], 'client': self.shares_client }) # Wait for success self.shares_v2_client.wait_for_share_status(managed_share['id'], constants.STATUS_AVAILABLE) # Verify data of managed share self.assertEqual(name, managed_share['name']) self.assertEqual(description, managed_share['description']) self.assertEqual(share['host'], managed_share['host']) self.assertEqual(share['share_proto'], managed_share['share_proto']) if utils.is_microversion_ge(version, "2.6"): self.assertEqual(self.st['share_type']['id'], managed_share['share_type']) else: self.assertEqual(self.st['share_type']['name'], managed_share['share_type']) if utils.is_microversion_ge(version, "2.8"): self.assertEqual(is_public, managed_share['is_public']) else: self.assertFalse(managed_share['is_public']) if utils.is_microversion_ge(version, "2.16"): self.assertEqual(share['user_id'], managed_share['user_id']) else: self.assertNotIn('user_id', managed_share) # Delete share self._delete_share_and_wait(managed_share) # Delete share server, since it can't be "auto-deleted" if (CONF.share.multitenancy_enabled and not CONF.share.share_network_id): # For a pre-configured share_network_id, we don't # delete the share server. self._delete_share_server_and_wait( managed_share['share_server_id'])