]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
obsync: implement --owner
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 3 May 2011 01:41:31 +0000 (18:41 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 3 May 2011 01:41:31 +0000 (18:41 -0700)
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/obsync/obsync.py
src/obsync/test-obsync.py

index c9048386db897dc8d7f6efd9781dffbca1aff41f..157815c0764cadd311c1d939b849cf8a44b00455 100755 (executable)
@@ -216,7 +216,7 @@ def user_type_to_attr(t):
         raise Exception("unknown user type %s" % t)
 
 def add_user_type(user):
-    """ All users that are not specifically marked as something else 
+    """ All users that are not specifically marked as something else
 are treated as canonical users"""
     for atype in ALL_ACL_TYPES:
         if (user[:len(atype)] == atype):
@@ -280,13 +280,8 @@ class AclPolicy(object):
             permission_elem.text = g.permission
         return etree.tostring(root, encoding="UTF-8")
     def translate_users(self, xusers):
-        # owner ids are always expressed in terms of canonical user id
-        if (xusers.has_key(ACL_TYPE_CANON_USER + self.owner_id)):
-            self.owner_id = \
-                strip_user_type(xusers[ACL_TYPE_CANON_USER + self.owner_id])
-            # It's not clear what the new pretty-name should be, so just leave it blank.
-            # It's not necessary when doing PUT/POST anyway.
-            self.owner_display_name = ""
+        self.owner_id = opts.owner
+        self.owner_display_name = ""
         for g in self.grants:
             g.translate_users(xusers)
 
@@ -845,6 +840,8 @@ parser.add_option("-V", "--more-verbose", action="store_true", \
 parser.add_option("-x", "--xuser", type="string", nargs=1, action="callback", \
     dest="SRC=DST", callback=xuser_cb, help="set up a user tranlation. You \
 can specify multiple user translations with multiple --xuser arguments.")
+parser.add_option("-O", "--owner", dest="owner", help="set who will \
+own the objects you create.")
 parser.add_option("--unit", action="store_true", \
     dest="run_unit_tests", help="run unit tests and quit")
 xuser = {}
@@ -852,6 +849,12 @@ xuser = {}
 if (opts.run_unit_tests):
     test_acl_policy()
     sys.exit(0)
+if (not opts.owner):
+    raise Exception("You must specify who will own the objects you create. \
+Please specify the owner as -O [OWNER].\n\
+It's not enough to have the access key, since a single account can have many \
+users.")
+
 opts.preserve_acls = not opts.no_preserve_acls
 if (opts.create and opts.dry_run):
     raise Exception("You can't run with both --create-dest and --dry-run! \
index ba7aca3bf477df1c73fd789bff8c44855e4556d2..abe382dd2a6305d75b0b728dd41da7ed56e0d057 100755 (executable)
@@ -25,6 +25,7 @@ import sys
 
 global opts
 global tdir
+global user
 
 ###### Helper functions #######
 def getenv(e):
@@ -33,6 +34,8 @@ def getenv(e):
     else:
         return None
 
+user = getenv("USER")
+
 def obsync(src, dst, misc):
     full = ["./obsync.py"]
     e = {}
@@ -48,6 +51,13 @@ def obsync(src, dst, misc):
         e["DST_SKEY"] = dst.skey
     else:
         full.append(dst)
+    has_owner = False
+    for m in misc:
+        if m == "-O" or m == "--owner":
+            has_owner = True
+    if (has_owner == False):
+        full.append("--owner")
+        full.append(user)
     full.extend(misc)
     if (opts.more_verbose):
         for f in full:
@@ -174,8 +184,7 @@ subprocess.check_call(["cp", "-r", "%s/dir1" % tdir, "%s/dir1a" % tdir])
 compare_directories("%s/dir1" % tdir, "%s/dir1a" % tdir)
 
 # we should fail here, because we didn't supply -c
-ret = subprocess.call(["./obsync.py", "file://%s/dir1" % tdir,
-                "file://%s/dir2" % tdir], stderr=opts.error_out)
+ret = obsync("file://%s/dir1" % tdir, "file://%s/dir2" % tdir, [])
 if (ret == 0):
     raise RuntimeError("expected this call to obsync to fail, because \
 we didn't supply -c. But it succeeded.")
@@ -183,14 +192,13 @@ if (opts.verbose):
     print "first call failed as expected."
 
 # now supply -c and it should work
-ret = subprocess.check_call(["./obsync.py", "-c", "file://%s/dir1" % tdir,
-                "file://%s/dir2" % tdir], stderr=opts.error_out)
+obsync_check("file://%s/dir1" % tdir, "file://%s/dir2" % tdir, ["-c"])
 compare_directories("%s/dir1" % tdir, "%s/dir2" % tdir)
 
 # test the alternate syntax where we leave off the file://, and it is assumed
 # because the url begins with / or ./
-ret = subprocess.check_call(["./obsync.py", "-c", "file://%s/dir1" % tdir,
-                "/%s/dir2" % tdir], stderr=opts.error_out)
+obsync_check("file://%s/dir1" % tdir, "/%s/dir2" % tdir, ["-c"])
+
 compare_directories("%s/dir1" % tdir, "%s/dir2" % tdir)
 
 if (opts.verbose):