Example #1
0
 def test_get_next_id(self):
     expected_id = 102
     result = ganesha_utils.get_next_id(self.fake_exports)
     self.assertEqual(result, expected_id)
Example #2
0
 def test_get_next_id_first_export(self, mock_map):
     expected_id = self.STARTING_EXPORT_ID
     mock_map.side_effect = ValueError
     result = ganesha_utils.get_next_id(self.fake_exports)
     self.assertEqual(result, expected_id)
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)