]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tasks/cephfs: new hooks for auth keys and config
authorJohn Spray <john.spray@redhat.com>
Mon, 9 Nov 2015 13:19:23 +0000 (13:19 +0000)
committerJohn Spray <john.spray@redhat.com>
Tue, 5 Jan 2016 18:57:33 +0000 (18:57 +0000)
Used when configuring clients with dynamically
generated auth keys, and pointing them at mount paths.

Signed-off-by: John Spray <john.spray@redhat.com>
tasks/cephfs/mount.py
tasks/cephfs/vstart_runner.py

index db39dc3d9e4820523b303b6454302b38a1c36d82..2a720c4cec5b114f357175daf9cc887006e20ed8 100644 (file)
@@ -32,7 +32,7 @@ class CephFSMount(object):
     def is_mounted(self):
         raise NotImplementedError()
 
-    def mount(self):
+    def mount(self, mount_path=None):
         raise NotImplementedError()
 
     def umount(self):
@@ -53,6 +53,17 @@ class CephFSMount(object):
     def wait_until_mounted(self):
         raise NotImplementedError()
 
+    def get_keyring_path(self):
+        return '/etc/ceph/ceph.client.{id}.keyring'.format(id=self.client_id)
+
+    @property
+    def config_path(self):
+        """
+        Path to ceph.conf: override this if you're not a normal systemwide ceph install
+        :return: stringv
+        """
+        return "/etc/ceph/ceph.conf"
+
     @contextmanager
     def mounted(self):
         """
@@ -107,6 +118,7 @@ class CephFSMount(object):
     def run_python(self, pyscript):
         p = self._run_python(pyscript)
         p.wait()
+        return p.stdout.getvalue().strip()
 
     def run_shell(self, args, wait=True):
         args = ["cd", self.mountpoint, run.Raw('&&'), "sudo"] + args
index 53c2662d5985ee665d543f32464a104830f7245b..3e2dd5cf28103882e5bf87b67a20baa7703b25c9 100644 (file)
@@ -160,6 +160,10 @@ class LocalRemote(object):
         shutil.copy(path, tmpfile)
         return tmpfile
 
+    def put_file(self, src, dst, sudo=False):
+        assert sudo is False
+        shutil.copy(src, dst)
+
     def run(self, args, check_status=True, wait=True,
             stdout=None, stderr=None, cwd=None, stdin=None,
             logger=None, label=None):
@@ -359,6 +363,15 @@ class LocalFuseMount(FuseMount):
         super(LocalFuseMount, self).__init__(None, test_dir, client_id, LocalRemote())
         self.mountpoint = mount_point
 
+    @property
+    def config_path(self):
+        return "./ceph.conf"
+
+    def get_keyring_path(self):
+        # This is going to end up in a config file, so use an absolute path
+        # to avoid assumptions about daemons' pwd
+        return os.path.abspath("./client.{0}.keyring".format(self.client_id))
+
     def run_shell(self, args, wait=True):
         # FIXME maybe should add a pwd arg to teuthology.orchestra so that
         # the "cd foo && bar" shenanigans isn't needed to begin with and
@@ -387,7 +400,7 @@ class LocalFuseMount(FuseMount):
         if self.is_mounted():
             super(LocalFuseMount, self).umount()
 
-    def mount(self):
+    def mount(self, mount_path=None):
         self.client_remote.run(
             args=[
                 'mkdir',
@@ -424,6 +437,9 @@ class LocalFuseMount(FuseMount):
         if os.getuid() != 0:
             prefix += ["--client-die-on-failed-remount=false"]
 
+        if mount_path is not None:
+            prefix += ["--client_mountpoint={0}".format(mount_path)]
+
         self._proc = self.client_remote.run(args=
                                             prefix + [
                                                 "--name",
@@ -610,9 +626,23 @@ class LocalFilesystem(Filesystem):
         for subsys, kvs in self._conf.items():
             existing_str += "\n[{0}]\n".format(subsys)
             for key, val in kvs.items():
-                # comment out any existing instances
-                if key in existing_str:
-                    existing_str = existing_str.replace(key, "#{0}".format(key))
+                # Comment out existing instance if it exists
+                log.info("Searching for existing instance {0}/{1}".format(
+                    key, subsys
+                ))
+                existing_section = re.search("^\[{0}\]$([\n]|[^\[])+".format(
+                    subsys
+                ), existing_str, re.MULTILINE)
+
+                if existing_section:
+                    section_str = existing_str[existing_section.start():existing_section.end()]
+                    existing_val = re.search("^\s*[^#]({0}) =".format(key), section_str, re.MULTILINE)
+                    if existing_val:
+                        start = existing_section.start() + existing_val.start(1)
+                        log.info("Found string to replace at {0}".format(
+                            start
+                        ))
+                        existing_str = existing_str[0:start] + "#" + existing_str[start:]
 
                 existing_str += "{0} = {1}\n".format(key, val)
 
@@ -665,8 +695,8 @@ def exec_test():
 
     test_dir = tempfile.mkdtemp()
 
-    # Run with two clients because some tests require the second one
-    clients = ["0", "1"]
+    # Create as many of these as the biggest test requires
+    clients = ["0", "1", "2"]
 
     remote = LocalRemote()