def handle(self, request, data): try: driver_options = data.get('driver_options') or {} driver_options_error_msg = _( "Got improper value for field 'driver_options'. " "Expected only pairs of key=value.") if driver_options and isinstance(driver_options, six.string_types): try: set_dict, unset_list = utils.parse_str_meta(driver_options) if unset_list: raise ValidationError(message=driver_options_error_msg) driver_options = set_dict except ValidationError as e: self.api_error(e.messages[0]) return False elif not isinstance(driver_options, dict): self.api_error(driver_options_error_msg) return False manila.share_manage( request, service_host=data['host'], protocol=data['protocol'], export_path=data['export_location'], driver_options=driver_options, share_type=data['share_type'], name=data['name'], description=data['description'], is_public=data['is_public']) share_name = data.get('name', data.get('id')) messages.success( request, _('Successfully sent the request to manage share: %s') % share_name) return True except Exception: exceptions.handle(request, _("Unable to manage share")) return False
def handle(self, request, data): try: driver_options = data.get('driver_options') or {} driver_options_error_msg = _( "Got improper value for field 'driver_options'. " "Expected only pairs of key=value.") if driver_options and isinstance(driver_options, str): try: set_dict, unset_list = utils.parse_str_meta(driver_options) if unset_list: raise ValidationError(message=driver_options_error_msg) driver_options = set_dict except ValidationError as e: self.api_error(e.messages[0]) return False elif not isinstance(driver_options, dict): self.api_error(driver_options_error_msg) return False manila.share_manage( request, service_host=data['host'], protocol=data['protocol'], export_path=data['export_location'], driver_options=driver_options, share_type=data['share_type'], name=data['name'], description=data['description'], is_public=data['is_public']) share_name = data.get('name', data.get('id')) messages.success( request, _('Successfully sent the request to manage share: %s') % share_name) return True except Exception: exceptions.handle(request, _("Unable to manage share")) return False
def test_share_manage(self): api.share_manage( self.request, service_host="fake_service_host", protocol="fake_protocol", export_path="fake_export_path", driver_options={"fake_key": "fake_value"}, share_type="fake_share_type", name="fake_name", description="fake_description", is_public="fake_is_public", ) self.manilaclient.shares.manage.assert_called_once_with( service_host="fake_service_host", protocol="fake_protocol", export_path="fake_export_path", driver_options={"fake_key": "fake_value"}, share_type="fake_share_type", name="fake_name", description="fake_description", is_public="fake_is_public", )