Example #1
0
 def test_publish_ganesha_config(self):
     configpath = self.fake_configpath
     methods = ('_publish_local_config', '_publish_remote_config')
     for method in methods:
         self.stubs.Set(ganesha_utils, method, mock.Mock())
     ganesha_utils.publish_ganesha_config(self.servers, self.sshlogin,
                                          self.sshkey, configpath,
                                          self.fake_pre_lines,
                                          self.fake_exports)
     ganesha_utils._publish_local_config.assert_called_once_with(
         configpath, self.fake_pre_lines, self.fake_exports)
     for remote_ip in self.remote_ips:
         ganesha_utils._publish_remote_config.assert_any_call(
             remote_ip, self.sshlogin, self.sshkey, configpath)
 def test_publish_ganesha_config(self):
     configpath = self.fake_configpath
     methods = ('_publish_local_config', '_publish_remote_config')
     for method in methods:
         self.mock_object(ganesha_utils, method)
     ganesha_utils.publish_ganesha_config(self.servers, self.sshlogin,
                                          self.sshkey, configpath,
                                          self.fake_pre_lines,
                                          self.fake_exports)
     ganesha_utils._publish_local_config.assert_called_once_with(
         configpath, self.fake_pre_lines, self.fake_exports
     )
     for remote_ip in self.remote_ips:
         ganesha_utils._publish_remote_config.assert_any_call(
             remote_ip, self.sshlogin, self.sshkey, configpath
         )
Example #3
0
    def _ganesha_process_request(self, req_type, local_path,
                                 share, access_type=None,
                                 access=None, force=False):
        cfgpath = self.configuration.ganesha_config_path
        gservice = self.configuration.ganesha_service_name
        gservers = self.configuration.gpfs_nfs_server_list
        sshlogin = self.configuration.gpfs_ssh_login
        sshkey = self.configuration.gpfs_ssh_private_key
        pre_lines, exports = ganesha_utils.parse_ganesha_config(cfgpath)
        reload_needed = True

        if (req_type == "allow_access"):
            export_opts = self._get_export_options(share)
            # add the new share if it's not already defined
            if not ganesha_utils.export_exists(exports, local_path):
                # Add a brand new export definition
                new_id = ganesha_utils.get_next_id(exports)
                export = ganesha_utils.get_export_template()
                export['fsal'] = '"GPFS"'
                export['export_id'] = new_id
                export['tag'] = '"fs%s"' % new_id
                export['path'] = '"%s"' % local_path
                export['pseudo'] = '"%s"' % local_path
                export['rw_access'] = (
                    '"%s"' % ganesha_utils.format_access_list(access)
                )
                for key in export_opts:
                    export[key] = export_opts[key]

                exports[new_id] = export
                LOG.info(_LI('Add %(share)s with access from %(access)s'),
                         {'share': share['name'], 'access': access})
            else:
                # Update existing access with new/extended access information
                export = ganesha_utils.get_export_by_path(exports, local_path)
                initial_access = export['rw_access'].strip('"')
                merged_access = ','.join([access, initial_access])
                updated_access = ganesha_utils.format_access_list(
                    merged_access
                )
                if initial_access != updated_access:
                    LOG.info(_LI('Update %(share)s with access from '
                                 '%(access)s'),
                             {'share': share['name'], 'access': access})
                    export['rw_access'] = '"%s"' % updated_access
                else:
                    LOG.info(_LI('Do not update %(share)s, access from '
                                 '%(access)s already defined'),
                             {'share': share['name'], 'access': access})
                    reload_needed = False

        elif (req_type == "deny_access"):
            export = ganesha_utils.get_export_by_path(exports, local_path)
            initial_access = export['rw_access'].strip('"')
            updated_access = ganesha_utils.format_access_list(
                initial_access,
                deny_access=access
            )

            if initial_access != updated_access:
                LOG.info(_LI('Update %(share)s removing access from '
                             '%(access)s'),
                         {'share': share['name'], 'access': access})
                export['rw_access'] = '"%s"' % updated_access
            else:
                LOG.info(_LI('Do not update %(share)s, access from %(access)s '
                             'already removed'), {'share': share['name'],
                                                  'access': access})
                reload_needed = False

        elif (req_type == "remove_export"):
            export = ganesha_utils.get_export_by_path(exports, local_path)
            if export:
                exports.pop(export['export_id'])
                LOG.info(_LI('Remove export for %s'), share['name'])
            else:
                LOG.info(_LI('Export for %s is not defined in Ganesha '
                             'config.'),
                         share['name'])
                reload_needed = False

        if reload_needed:
            # publish config to all servers and reload or restart
            ganesha_utils.publish_ganesha_config(gservers, sshlogin, sshkey,
                                                 cfgpath, pre_lines, exports)
            ganesha_utils.reload_ganesha_config(gservers, sshlogin, gservice)