]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/volumes: check for string values in uid/gid
authorJos Collin <jcollin@redhat.com>
Tue, 3 Dec 2019 09:12:28 +0000 (14:42 +0530)
committerJos Collin <jcollin@redhat.com>
Mon, 9 Dec 2019 13:55:46 +0000 (19:25 +0530)
chown allows strings as per bbbfb44453f204286a8ff312349d42afde5fced6,
which caused this error. Eventhough uid/gid are input as CephInt, the
qa tests can pass in only string values to _fs_cmd. So try converting
the incoming uid/gid to int in create_subvolume and create_group.
It might be a valid string.

Fixes: https://tracker.ceph.com/issues/43038
Signed-off-by: Jos Collin <jcollin@redhat.com>
src/pybind/mgr/volumes/fs/subvolume.py

index 0038f5e03993ceafb262d043e932cd457311ecef..6b88da20d52586785db0d89e5a8eb8e8abe6ad9f 100644 (file)
@@ -109,13 +109,23 @@ class SubVolume(object):
             groupstat = self.fs.stat(spec.group_path)
             if uid is None:
                 uid = int(groupstat.st_uid)
-            elif uid < 0:
-                raise VolumeException(-errno.EINVAL, "Provide a valid uid")
+            else:
+                try:
+                    uid = int(uid)
+                    if uid < 0:
+                        raise ValueError
+                except ValueError:
+                    raise VolumeException(-errno.EINVAL, "Invalid uid")
 
             if gid is None:
                 gid = int(groupstat.st_gid)
-            elif gid < 0:
-                raise VolumeException(-errno.EINVAL, "Provide a valid gid")
+            else:
+                try:
+                    gid = int(gid)
+                    if gid < 0:
+                        raise ValueError
+                except ValueError:
+                    raise VolumeException(-errno.EINVAL, "Invalid gid")
 
             try:
                 self.fs.chown(subvolpath, uid, gid)
@@ -302,13 +312,23 @@ class SubVolume(object):
 
             if uid is None:
                 uid = 0
-            elif uid < 0:
-                raise VolumeException(-errno.EINVAL, "Provide a valid uid")
+            else:
+                try:
+                    uid = int(uid)
+                    if uid < 0:
+                        raise ValueError
+                except ValueError:
+                    raise VolumeException(-errno.EINVAL, "Invalid uid")
 
             if gid is None:
                 gid = 0
-            elif gid < 0:
-                raise VolumeException(-errno.EINVAL, "Provide a valid gid")
+            else:
+                try:
+                    gid = int(gid)
+                    if gid < 0:
+                        raise ValueError
+                except ValueError:
+                    raise VolumeException(-errno.EINVAL, "Invalid gid")
 
             try:
                 self.fs.chown(path, uid, gid)