def create_share_from_snapshot(self, context, share, snapshot, share_server=None): """Create a share from a snapshot.""" LOG.debug('Entering create_share_from_snapshot. The source ' 'snapshot=%(snap)s. The created share=%(share)s', {'snap': snapshot['id'], 'share': share['id']}) snapshot_id = (snapshot.get('provider_location') or self.private_storage.get(snapshot['id'], 'snapshot_id')) if not snapshot_id: LOG.warning('Snapshot %s does not exist', snapshot['id']) raise exception.SnapshotResourceNotFound(name=snapshot['id']) LOG.debug('snapshot_id: %s', snapshot_id) create_share_name = self._gen_random_name("share") # if sharename exist, need to change another created_share = self.api_executor.get_share_info( self.configuration.qnap_poolname, vol_label=create_share_name) if created_share is not None: msg = _("Failed to create an unused share name.") raise exception.ShareBackendException(msg=msg) self.api_executor.clone_snapshot(snapshot_id, create_share_name) create_volID = "" created_share = self.api_executor.get_share_info( self.configuration.qnap_poolname, vol_label=create_share_name) if created_share.find('vol_no') is not None: create_volID = created_share.find('vol_no').text else: msg = _("Failed to clone a snapshot in time.") raise exception.ShareBackendException(msg=msg) snap_share = self.share_api.get(context, snapshot['share_instance']['share_id']) LOG.debug('snap_share[size]: %s', snap_share['size']) if (share['size'] > snap_share['size']): share_dict = {'sharename': create_share_name, 'old_sharename': create_share_name, 'new_size': share['size']} self.api_executor.edit_share(share_dict) # Use private_storage to record volume ID and Name created in the NAS. _metadata = { 'volID': create_volID, 'volName': create_share_name, } self.private_storage.update(share['id'], _metadata) # Test to get value from private_storage. volName = self.private_storage.get(share['id'], 'volName') LOG.debug('volName: %s', volName) return self._get_location_path(create_share_name, share['share_proto'], self.configuration.qnap_share_ip)
def test_snapshot_resource_not_found(self): # verify response code for exception.SnapshotResourceNotFound name = "fake_name" e = exception.SnapshotResourceNotFound(name=name) self.assertEqual(404, e.code) self.assertIn(name, e.msg)