Skip to content

Commit 8b95388

Browse files
committed
fix(controller): volume repeat path no error
1 parent db4a107 commit 8b95388

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

rootfs/api/models/volume.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def save(self, *args, **kwargs):
3030
if self.type == "csi" and self.created == self.updated:
3131
self._create_pvc()
3232
# check path
33-
self._check_path()
33+
self.check_path()
3434
# Save to DB
3535
return super(Volume, self).save(*args, **kwargs)
3636

@@ -99,7 +99,7 @@ def _format_size(size):
9999
size = size.upper() + "i"
100100
return size
101101

102-
def _check_path(self):
102+
def check_path(self, path=None):
103103
other_volumes = self.app.volume_set.exclude(name=self.name)
104104
type_paths = {} # {'type1':[path1,path2], tyep2:[path3,path4]}
105105
for _ in other_volumes:
@@ -108,10 +108,12 @@ def _check_path(self):
108108
type_paths[k] = [v]
109109
else:
110110
type_paths[k].append(v)
111-
repeat_path = [v for k, v in self.path.items() if v in type_paths.get(k, [])]
111+
items = path.items() if path else self.path.items()
112+
repeat_path = [v for k, v in items if v in type_paths.get(k, [])]
112113
if repeat_path:
113-
raise DryccException("path {} is used by another volume".
114-
format(','.join(repeat_path)))
114+
msg = "path {} is used by another volume".format(','.join(repeat_path))
115+
self.log(msg, logging.ERROR)
116+
raise DryccException(msg)
115117

116118
def _create_pvc(self):
117119
try:

rootfs/api/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ def path(self, request, *args, **kwargs):
726726
format(','.join(container_types)))
727727
if set(path.items()).issubset(set(volume.path.items())):
728728
raise DryccException("mount path not changed")
729+
volume.check_path(path)
729730

730731
app = self.get_app()
731732
mount_app.delay(app, self.request.user, volume, path)

0 commit comments

Comments
 (0)