]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/volumes: Move ganesha common config to vstart
authorVarsha Rao <varao@redhat.com>
Mon, 30 Mar 2020 10:17:15 +0000 (15:47 +0530)
committerVarsha Rao <varao@redhat.com>
Wed, 8 Apr 2020 11:51:17 +0000 (17:21 +0530)
This is a preparatoy patch before calling orchestrator for nfs cluster
deployment. All the ganesha config is moved to vstart. Keyring creation is also
taken care by vstart.

The volumes fs nfs cluster create interface does the following things:
1) Create a common recovery pool for all ganesha clusters. Each cluster will
   have their own namespace.
2) Create an empty rados conf object named 'conf-nfs' for saving all export
   urls.

Call to orch interface will be done in future patch.

Signed-off-by: Varsha Rao <varao@redhat.com>
src/pybind/mgr/volumes/fs/nfs.py
src/vstart.sh

index 871883281a11b0dafa55e69f123839878b5fad49..831fc414367b00131df5d3660b762ccfb95e2375 100644 (file)
@@ -267,7 +267,7 @@ class GaneshaConf(object):
                         "export-{}".format(ex.export_id))
                 })
         for daemon_id, conf_blocks in daemon_map.items():
-            self._write_raw_config(conf_blocks, "conf-{}".format(daemon_id))
+            self._write_raw_config(conf_blocks, "conf-nfs")
 
     def _delete_export(self, export_id):
         self._persist_daemon_configuration()
@@ -337,50 +337,13 @@ class NFSConfig(object):
             if ret!= 0:
                 return ret, out, err
 
-    def create_common_config(self, nodeid):
-        # TODO change rados url to "%url rados://{}/{}/{}".format(self.pool_name, self.pool_ns, nodeid)
-        result = """NFS_CORE_PARAM {{
-        Enable_NLM = false;
-        Enable_RQUOTA = false;
-        Protocols = 4;
-        }}
-
-        CACHEINODE {{
-        Dir_Chunk = 0;
-        NParts = 1;
-        Cache_Size = 1;
-        }}
-
-        NFSv4 {{
-        RecoveryBackend = rados_cluster;
-        Minor_Versions = 1, 2;
-        }}
-
-        RADOS_URLS {{
-        userid = {2};
-        }}
-
-        %url rados://{0}/{1}/export-1
-
-        RADOS_KV {{
-        pool = {0};
-        namespace = {1};
-        UserId = {2};
-        nodeid = {3};
-        }}""".format(self.pool_name, self.pool_ns, self.cluster_id, nodeid)
-        #self.ganeshaconf._write_raw_config(result, nodeid)
-
-        with self.mgr.rados.open_ioctx(self.pool_name) as ioctx:
-            if self.pool_ns:
-                ioctx.set_namespace(self.pool_ns)
-            ioctx.write_full(nodeid, result.encode('utf-8'))
-            log.debug(
-                    "write configuration into rados object %s/%s/%s:\n%s",
-                    self.pool_name, self.pool_ns, nodeid, result)
-
     def create_instance(self):
-        assert self.ganeshaconf is not None
         self.ganeshaconf = GaneshaConf(self)
+        ret, out, err = self.mgr.mon_command({'prefix': 'auth get','entity': "client.%s" % (self.cluster_id), 'format': 'json',})
+
+        if not out:
+            json_res = json.loads(out)
+            self.key = json_res[0]['key']
 
     def create_export(self):
         assert self.ganeshaconf is not None
@@ -412,6 +375,17 @@ class NFSConfig(object):
         return [{'id': fs['id'], 'name': fs['mdsmap']['fs_name']}
                 for fs in fs_map['filesystems']]
 
+    def create_empty_rados_obj(self):
+        common_conf = 'conf-nfs'
+        result = ''
+        with self.mgr.rados.open_ioctx(self.pool_name) as ioctx:
+            if self.pool_ns:
+                ioctx.set_namespace(self.pool_ns)
+            ioctx.write_full(common_conf, result.encode('utf-8'))
+            log.debug(
+                    "write configuration into rados object %s/%s/%s\n",
+                    self.pool_name, self.pool_ns, common_conf)
+
     def create_nfs_cluster(self, size):
         pool_list = [p['pool_name'] for p in self.mgr.get_osdmap().dump().get('pools', [])]
         client = 'client.%s' % self.cluster_id
@@ -428,27 +402,8 @@ class NFSConfig(object):
             if r != 0:
                 return r, out, err
 
-        ret, out, err = self.mgr.mon_command({
-            'prefix': 'auth get-or-create',
-            'entity': client,
-            'caps' : ['mon', 'allow r', 'osd', 'allow rw pool=%s namespace=%s, allow rw tag cephfs data=a' % (self.pool_name, self.pool_ns), 'mds', 'allow rw path=/'],
-            'format': 'json',
-            })
-
-        if ret!= 0:
-            return ret, out, err
-
-        json_res = json.loads(out)
-        self.key = json_res[0]['key']
-        log.info("The user created is {}".format(json_res[0]['entity']))
-
-        """
-        Not required, this just gives mgr keyring location.
-        keyring = self.mgr.rados.conf_get("keyring")
-        log.info("The keyring location is {}".format(keyring))
-        """
-
-        log.info("Calling up common config")
-        self.create_common_config("a")
+        self.create_empty_rados_obj()
+        #TODO Check if cluster exists
+        #TODO Call Orchestrator to deploy cluster
 
         return 0, "", "NFS Cluster Created Successfully"
index 2e493708862b418913d040e6e659dc6c0611d688..b51b40fa094cbe1f971d6cf879a952bef6bc19d9 100755 (executable)
@@ -1084,21 +1084,49 @@ start_ganesha() {
         port=$(($GANESHA_PORT + ganesha))
         ganesha=$(($ganesha + 1))
         ganesha_dir="$CEPH_DEV_DIR/ganesha.$name"
+        test_user="ganesha-$name"
+        pool_name="nfs-ganesha"
+        namespace=$name
 
         prun rm -rf $ganesha_dir
         prun mkdir -p $ganesha_dir
-        prun ceph_adm fs nfs cluster create tester
-       keyring=$(ceph_adm auth print-key client.ganesha-tester)
-       prun $SUDO "$CEPH_BIN/ceph-authtool" --name=client.ganesha-tester --add-key=$keyring keyring
-
-        echo "%url rados://nfs-ganesha/tester/a
-
-NFS_CORE_PARAM {
-        Enable_NLM = false;
-        Enable_RQUOTA = false;
-        Protocols = 4;
-        NFS_Port = $port;
-}" > "$ganesha_dir/ganesha.conf"
+        prun ceph_adm auth get-or-create client.$test_user \
+            mon "allow r" \
+            osd "allow rw pool=$pool_name namespace=$namespace, allow rw tag cephfs data=a" \
+            mds "allow rw path=/" \
+            >> "$keyring_fn"
+        prun ceph_adm fs nfs cluster create $name
+
+        echo "NFS_CORE_PARAM {
+            Enable_NLM = false;
+            Enable_RQUOTA = false;
+            Protocols = 4;
+            NFS_Port = $port;
+        }
+
+        CACHEINODE {
+           Dir_Chunk = 0;
+           NParts = 1;
+           Cache_Size = 1;
+        }
+
+        NFSv4 {
+           RecoveryBackend = rados_cluster;
+           Minor_Versions = 1, 2;
+        }
+
+        %url rados://$pool_name/$namespace/nfs-conf
+
+        RADOS_KV {
+           pool = $pool_name;
+           namespace = $namespace;
+           UserId = $test_user;
+           nodeid = $name;
+        }
+
+        RADOS_URLS {
+          Userid = $test_user;
+        }" > "$ganesha_dir/ganesha.conf"
        wconf <<EOF
 [ganesha.$name]
         host = $HOSTNAME
@@ -1108,26 +1136,26 @@ NFS_CORE_PARAM {
         pid file = $ganesha_dir/ganesha.pid
 EOF
 
-        prun ceph_adm fs nfs export create --fs-name="a"
-        prun ganesha-rados-grace -p nfs-ganesha -n tester add $name
-        prun ganesha-rados-grace -p nfs-ganesha -n tester
+        prun ceph_adm fs nfs export create "a"
+        prun ganesha-rados-grace -p $pool_name -n $namespace add $name
+        prun ganesha-rados-grace -p $pool_name -n $namespace
 
         prun env CEPH_CONF="${conf_fn}" /usr/bin/ganesha.nfsd -L "$ganesha_dir/ganesha.log" -f "$ganesha_dir/ganesha.conf" -p "$ganesha_dir/ganesha.pid" -N NIV_DEBUG
 
         # Wait few seconds for grace period to be removed
         sleep 2
 
-        prun ganesha-rados-grace -p nfs-ganesha -n tester
+        prun ganesha-rados-grace -p $pool_name -n $namespace
 
         if $with_mgr_dashboard; then
-            $CEPH_BIN/rados -p nfs-ganesha put "conf-$name" "$ganesha_dir/ganesha.conf"
+            $CEPH_BIN/rados -p $pool_name put "conf-$name" "$ganesha_dir/ganesha.conf"
         fi
 
-        echo "ganesha.$name started on port: $port"
+        echo "$test_user started on port: $port"
     done
 
     if $with_mgr_dashboard; then
-        ceph_adm dashboard set-ganesha-clusters-rados-pool-namespace nfs-ganesha
+        ceph_adm dashboard set-ganesha-clusters-rados-pool-namespace $pool_name
     fi
 
     echo "Mount using: mount -t nfs -o port=<ganesha-port-num> <address>:<ganesha pseudo path>"