]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
[RM-11694] Add optional directory to write_file()
authorTravis Rhoden <trhoden@redhat.com>
Fri, 22 May 2015 14:33:07 +0000 (10:33 -0400)
committerTravis Rhoden <trhoden@redhat.com>
Fri, 22 May 2015 14:33:07 +0000 (10:33 -0400)
This is mostly for testing purposes.  The method has no way to
specify a directory independently from the file name, which it
makes it difficult to use with automated tests.  It will get
refactored more later, but for now add a new kwarg that pass
in a dir to write to.  Since a lot of callers are passing in
absolute paths (.e.g. "/etc/ceph/keyring"), we look for the
beginning slash and chop it off so that we can use os.path.join()
and write into something like /tmp/etc/ceph.

Signed-off-by: Travis Rhoden <trhoden@redhat.com>
ceph_deploy/hosts/remotes.py

index 6c8e63aab8c96717442be750c92c1e7f415a96dd..19be3e46c3d4ea493ee8930451ee4a8a5f41c14e 100644 (file)
@@ -200,7 +200,11 @@ def write_monitor_keyring(keyring, monitor_keyring):
     write_file(keyring, monitor_keyring)
 
 
-def write_file(path, content):
+def write_file(path, content, directory=None):
+    if directory:
+        if path.startswith("/"):
+            path = path[1:]
+        path = os.path.join(directory, path)
     with file(path, 'w') as f:
         f.write(content)