Skip to content

Commit

Permalink
Merge pull request #420 from pagezhou/sprintfix_remote_sync_plugins_api
Browse files Browse the repository at this point in the history
sprintfix: 修复修改远程包源和缓存源配置时接口500问题 #275
  • Loading branch information
homholueng committed May 29, 2019
2 parents 02f2a6d + 33ed4fb commit 0315584
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions gcloud/external_plugins/models/cache.py
Expand Up @@ -23,15 +23,15 @@

class CachePackageSourceManager(PackageSourceManager):
@transaction.atomic()
def add_cache_source(self, name, source_type, packages, **kwargs):
def add_cache_source(self, name, source_type, packages, desc='', **kwargs):
if source_type not in writer_cls_factory:
raise exceptions.CacheSourceTypeError('Source type[%s] does not support as cache source' % source_type)

if self.all().count() > 0:
raise exceptions.MultipleCacheSourceError('Can not add multiple cache source')

base_source = super(CachePackageSourceManager, self).add_base_source(name, source_type, packages, **kwargs)
return self.create(type=source_type, base_source_id=base_source.id)
return self.create(type=source_type, base_source_id=base_source.id, desc=desc)

def get_base_source(self):
count = self.all().count()
Expand Down
17 changes: 11 additions & 6 deletions gcloud/external_plugins/resources.py
Expand Up @@ -136,6 +136,7 @@ def obj_create(self, bundle, **kwargs):
CachePackageSource.objects.add_cache_source(cache['name'],
cache['type'],
cache_packages,
cache.get('desc', ''),
**cache['details'])
except exceptions.GcloudExternalPluginsError as e:
message = 'Create cache source raise error: %s' % e
Expand Down Expand Up @@ -212,11 +213,14 @@ def obj_update(self, bundle, skip_errors=False, **kwargs):
message = 'Invalid cache source id: %s, which cannot be found' % cache['id']
logger.error(message)
raise BadRequest(message)
if cache.get('desc', ''):
CachePackageSource.objects.filter(id=cache['id']).update(desc=cache['desc'])
else:
try:
CachePackageSource.objects.add_cache_source(cache['name'],
cache['type'],
cache_packages,
cache.get('desc', ''),
**cache['details'])
except exceptions.GcloudExternalPluginsError as e:
message = 'Create cache source raise error: %s' % e.message
Expand All @@ -239,18 +243,19 @@ def obj_update(self, bundle, skip_errors=False, **kwargs):
# original_kwargs mains field in origin model but not in base model(e.g. repo_address、desc)
source_model = source_cls_factory[source_type]
original_kwargs, base_kwargs = source_model.objects.divide_details_parts(source_type, details)
original_kwargs['desc'] = origin.get('desc', '')
if origin.get('desc', ''):
original_kwargs['desc'] = origin['desc']
if 'id' in origin:
source_model.objects.update_original_source(origin['id'],
origin['packages'],
original_kwargs,
**base_kwargs)
else:
source_model.objects.add_origin_source(origin['name'],
source_type,
origin['packages'],
original_kwargs,
**base_kwargs)
source_model.objects.add_original_source(origin['name'],
source_type,
origin['packages'],
original_kwargs,
**base_kwargs)

def obj_get(self, bundle, **kwargs):
raise NotFound("Invalid resource uri, please use obj_get_list")
Expand Down
2 changes: 1 addition & 1 deletion gcloud/external_plugins/schemas.py
Expand Up @@ -16,7 +16,7 @@
from gcloud.external_plugins.models import source_cls_factory

NAME_MAX_LENGTH = 50
NAME_PATTERN = r'^([a-zA-Z0-9_-]+)$'
NAME_PATTERN = r'^([a-zA-Z0-9_]+)$'


ADD_SOURCE_SCHEMA = {
Expand Down

0 comments on commit 0315584

Please sign in to comment.