]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Add optional 'owner' arg to sudo_write_file()
authorZack Cerza <zack@cerza.org>
Thu, 6 Feb 2014 02:14:42 +0000 (20:14 -0600)
committerZack Cerza <zack@cerza.org>
Thu, 20 Feb 2014 23:46:06 +0000 (17:46 -0600)
This gets passed directly to chown as 'sudo chown $owner $file'

Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
teuthology/misc.py

index c8c9fd0cbefa4f84fceb703024bab6ec28009153..2f455d90c7c51524265351f53c772e1acfd06def 100644 (file)
@@ -35,7 +35,7 @@ is_arm = lambda x: x.startswith('tala') or x.startswith(
 
 def config_file(string):
     """
-    Create a config file  
+    Create a config file
 
     :param string: name of yaml file used for config.
     :returns: Dictionary of configuration information.
@@ -97,7 +97,7 @@ def get_archive_dir(ctx):
 def get_http_log_path(archive_dir, job_id=None):
     """
     :param archive_dir: directory to be searched
-    :param job_id: id of job that terminates the name of the log path 
+    :param job_id: id of job that terminates the name of the log path
     :returns: http log path
     """
     http_base = config.archive_server
@@ -267,7 +267,7 @@ def skeleton_config(ctx, roles, ips):
 def roles_of_type(roles_for_host, type_):
     """
     Generator of roles.
+
     Each call returns the next possible role of the type specified.
     :param roles_for host: list of roles possible
     :param type_: type of role
@@ -326,9 +326,9 @@ def is_type(type_):
 def num_instances_of_type(cluster, type_):
     """
     Total the number of instances of the role type specified in all remotes.
-    
+
     :param cluster: Cluster extracted from ctx.
-    :param type_: role 
+    :param type_: role
     """
     remotes_and_roles = cluster.remotes.items()
     roles = [roles for (remote, roles) in remotes_and_roles]
@@ -351,7 +351,7 @@ def create_simple_monmap(ctx, remote, conf):
     def gen_addresses():
         """
         Monitor address generator.
-    
+
         Each invocation returns the next monitor address
         """
         for section, data in conf.iteritems():
@@ -411,7 +411,7 @@ def write_file(remote, path, data):
         )
 
 
-def sudo_write_file(remote, path, data, perms=None):
+def sudo_write_file(remote, path, data, perms=None, owner=None):
     """
     Write data to a remote file as super user
 
@@ -419,10 +419,16 @@ def sudo_write_file(remote, path, data, perms=None):
     :param path: Path on the remote being written to.
     :param data: Data to be written.
     :param perms: Permissions on the file being written
+    :param owner: Owner for the file being written
+
+    Both perms and owner are passed directly to chmod.
     """
     permargs = []
     if perms:
         permargs = [run.Raw('&&'), 'sudo', 'chmod', perms, path]
+    owner_args = []
+    if owner:
+        owner_args = [run.Raw('&&'), 'sudo', 'chown', owner, path]
     remote.run(
         args=[
             'sudo',
@@ -430,7 +436,7 @@ def sudo_write_file(remote, path, data, perms=None):
             '-c',
             'import shutil, sys; shutil.copyfileobj(sys.stdin, file(sys.argv[1], "wb"))',
             path,
-            ] + permargs,
+            ] + owner_args + permargs,
         stdin=data,
         )
 
@@ -720,7 +726,7 @@ def get_wwn_id_map(remote, devs):
 
     Sample dev information:    /dev/sdb: /dev/disk/by-id/wwn-0xf00bad
 
-    :returns: map of devices to device id links 
+    :returns: map of devices to device id links
     """
     stdout = None
     try: