def test_clone_object_volume_exists(self): jdssd, ctx = self.get_driver(CONFIG_OK) origin = jcom.vname(UUID_1) clone = jcom.vname(UUID_2) jdssd.ra.create_snapshot.return_value = None jdssd.ra.create_volume_from_snapshot.side_effect = ( jexc.JDSSVolumeExistsException(volume=clone)) self.assertRaises(exception.Duplicate, jdssd._clone_object, origin, clone) jdssd.ra.create_snapshot.assert_called_once_with(origin, clone) jdssd.ra.create_volume_from_snapshot.assert_called_once_with( clone, clone, origin, sparse=CONFIG_OK['san_thin_provision'])
def get_jdss_exceptions(): out = [ jexc.JDSSException(reason="Testing"), jexc.JDSSRESTException(request="ra request", reason="Testing"), jexc.JDSSRESTProxyException(host="test_host", reason="Testing"), jexc.JDSSResourceNotFoundException(res="test_resource"), jexc.JDSSVolumeNotFoundException(volume="test_volume"), jexc.JDSSSnapshotNotFoundException(snapshot="test_snapshot"), jexc.JDSSResourceExistsException(res="test_resource"), jexc.JDSSSnapshotExistsException(snapshot="test_snapshot"), jexc.JDSSVolumeExistsException(volume="test_volume"), jexc.JDSSSnapshotIsBusyException(snapshot="test_snapshot") ] return out
def create_volume_from_snapshot(self, volume_name, snapshot_name, original_vol_name, **options): """create_volume_from_snapshot. POST /volumes/<string:volumename>/clone :param volume_name: volume that is going to be created :param snapshot_name: slice of original volume :param original_vol_name: sample copy :return: """ req = '/volumes/%s/clone' % original_vol_name jbody = { 'name': volume_name, 'snapshot': snapshot_name, 'sparse': False } if 'sparse' in options: jbody['sparse'] = options['sparse'] LOG.debug("create volume %(vol)s from snapshot %(snap)s", {'vol': volume_name, 'snap': snapshot_name}) resp = self.rproxy.pool_request('POST', req, json_data=jbody) if not resp["error"] and resp["code"] in (200, 201, 204): return if resp["code"] == 500: if resp["error"]: if resp["error"]["errno"] == 100: raise jexc.JDSSVolumeExistsException( volume=volume_name) if resp["error"]["errno"] == 1: raise jexc.JDSSResourceNotFoundException( res="%(vol)s@%(snap)s" % {'vol': original_vol_name, 'snap': snapshot_name}) self._general_error(req, resp)
def create_volume_from_snapshot(self, volume_name, snapshot_name, original_vol_name, **options): """create_volume_from_snapshot. POST /volumes/<string:volumename>/clone :param volume_name: volume that is going to be created :param snapshot_name: slice of original volume :param original_vol_name: sample copy :return: """ req = '/volumes/' + original_vol_name + '/clone' jbody = { 'name': volume_name, 'snapshot': snapshot_name, 'sparse': False } if 'sparse' in options: jbody['sparse'] = options['sparse'] LOG.debug("create volume %(vol)s from snapshot %(snap)s", { 'vol': volume_name, 'snap': snapshot_name }) resp = self.rproxy.pool_request('POST', req, json_data=jbody) if not resp["error"] and resp["code"] in (200, 201, 204): return if resp["code"] == 500: if resp["error"]: if resp["error"]["errno"] == 100: raise jexc.JDSSVolumeExistsException(volume=volume_name) args = {"vol": volume_name, "e": resp['error']['message']} msg = _('Failed to create volume %(vol)s, err: %(e)s') % args raise jexc.JDSSRESTException(msg) raise jexc.JDSSRESTException('unable to create volume')