Commit 92a7d75b by John Jarvis

Merge pull request #1305 from edx/jarv/revert-1240

Revert "Merge pull request #1240 from edx/dhm/config_separation"
parents 82e42cc5 a517dc20
...@@ -29,7 +29,7 @@ class Command(BaseCommand): ...@@ -29,7 +29,7 @@ class Command(BaseCommand):
# use a user-specified database name, if present # use a user-specified database name, if present
# this is useful for doing dumps from databases restored from prod backups # this is useful for doing dumps from databases restored from prod backups
if len(args) == 3: if len(args) == 3:
settings.MODULESTORE['direct']['DOC_STORE_CONFIG']['db'] = args[2] settings.MODULESTORE['direct']['OPTIONS']['db'] = args[2]
loc = CourseDescriptor.id_to_location(course_id) loc = CourseDescriptor.id_to_location(course_id)
......
...@@ -58,7 +58,7 @@ from student.models import CourseEnrollment ...@@ -58,7 +58,7 @@ from student.models import CourseEnrollment
from contentstore.utils import delete_course_and_groups from contentstore.utils import delete_course_and_groups
TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE)
TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex TEST_DATA_CONTENTSTORE['OPTIONS']['db'] = 'test_xcontent_%s' % uuid4().hex
class MongoCollectionFindWrapper(object): class MongoCollectionFindWrapper(object):
...@@ -101,7 +101,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -101,7 +101,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.client.login(username=uname, password=password) self.client.login(username=uname, password=password)
def tearDown(self): def tearDown(self):
MongoClient().drop_database(TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db']) MongoClient().drop_database(TEST_DATA_CONTENTSTORE['OPTIONS']['db'])
_CONTENTSTORE.clear() _CONTENTSTORE.clear()
def check_components_on_page(self, component_types, expected_types): def check_components_on_page(self, component_types, expected_types):
...@@ -1313,7 +1313,7 @@ class ContentStoreTest(ModuleStoreTestCase): ...@@ -1313,7 +1313,7 @@ class ContentStoreTest(ModuleStoreTestCase):
def tearDown(self): def tearDown(self):
mongo = MongoClient() mongo = MongoClient()
mongo.drop_database(TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db']) mongo.drop_database(TEST_DATA_CONTENTSTORE['OPTIONS']['db'])
_CONTENTSTORE.clear() _CONTENTSTORE.clear()
def test_create_course(self): def test_create_course(self):
......
...@@ -20,7 +20,7 @@ from django.conf import settings ...@@ -20,7 +20,7 @@ from django.conf import settings
from xmodule.contentstore.django import _CONTENTSTORE from xmodule.contentstore.django import _CONTENTSTORE
TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE)
TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex TEST_DATA_CONTENTSTORE['OPTIONS']['db'] = 'test_xcontent_%s' % uuid4().hex
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -70,7 +70,7 @@ class ImportTestCase(CourseTestCase): ...@@ -70,7 +70,7 @@ class ImportTestCase(CourseTestCase):
def tearDown(self): def tearDown(self):
shutil.rmtree(self.content_dir) shutil.rmtree(self.content_dir)
MongoClient().drop_database(TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db']) MongoClient().drop_database(TEST_DATA_CONTENTSTORE['OPTIONS']['db'])
_CONTENTSTORE.clear() _CONTENTSTORE.clear()
......
...@@ -28,7 +28,7 @@ from uuid import uuid4 ...@@ -28,7 +28,7 @@ from uuid import uuid4
from pymongo import MongoClient from pymongo import MongoClient
TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE)
TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex TEST_DATA_CONTENTSTORE['OPTIONS']['db'] = 'test_xcontent_%s' % uuid4().hex
@override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE, MODULESTORE=TEST_MODULESTORE) @override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE, MODULESTORE=TEST_MODULESTORE)
...@@ -61,7 +61,7 @@ class ContentStoreImportNoStaticTest(ModuleStoreTestCase): ...@@ -61,7 +61,7 @@ class ContentStoreImportNoStaticTest(ModuleStoreTestCase):
self.client.login(username=uname, password=password) self.client.login(username=uname, password=password)
def tearDown(self): def tearDown(self):
MongoClient().drop_database(TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db']) MongoClient().drop_database(TEST_DATA_CONTENTSTORE['OPTIONS']['db'])
_CONTENTSTORE.clear() _CONTENTSTORE.clear()
def load_test_import_course(self): def load_test_import_course(self):
......
...@@ -30,33 +30,30 @@ DOC_STORE_CONFIG = { ...@@ -30,33 +30,30 @@ DOC_STORE_CONFIG = {
'collection': 'acceptance_modulestore_%s' % seed(), 'collection': 'acceptance_modulestore_%s' % seed(),
} }
MODULESTORE_OPTIONS = { MODULESTORE_OPTIONS = dict({
'default_class': 'xmodule.raw_module.RawDescriptor', 'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': TEST_ROOT / "data", 'fs_root': TEST_ROOT / "data",
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string',
} }, **DOC_STORE_CONFIG)
MODULESTORE = { MODULESTORE = {
'default': { 'default': {
'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore', 'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': MODULESTORE_OPTIONS 'OPTIONS': MODULESTORE_OPTIONS
}, },
'direct': { 'direct': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': MODULESTORE_OPTIONS 'OPTIONS': MODULESTORE_OPTIONS
}, },
'draft': { 'draft': {
'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore', 'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': MODULESTORE_OPTIONS 'OPTIONS': MODULESTORE_OPTIONS
} }
} }
CONTENTSTORE = { CONTENTSTORE = {
'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore', 'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore',
'DOC_STORE_CONFIG': { 'OPTIONS': {
'host': 'localhost', 'host': 'localhost',
'db': 'acceptance_xcontent_%s' % seed(), 'db': 'acceptance_xcontent_%s' % seed(),
}, },
......
...@@ -23,26 +23,23 @@ DOC_STORE_CONFIG = { ...@@ -23,26 +23,23 @@ DOC_STORE_CONFIG = {
'collection': 'modulestore', 'collection': 'modulestore',
} }
modulestore_options = { modulestore_options = dict({
'default_class': 'xmodule.raw_module.RawDescriptor', 'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': GITHUB_REPO_ROOT, 'fs_root': GITHUB_REPO_ROOT,
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string',
} }, **DOC_STORE_CONFIG)
MODULESTORE = { MODULESTORE = {
'default': { 'default': {
'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore', 'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': modulestore_options 'OPTIONS': modulestore_options
}, },
'direct': { 'direct': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': modulestore_options 'OPTIONS': modulestore_options
}, },
'split': { 'split': {
'ENGINE': 'xmodule.modulestore.split_mongo.SplitMongoModuleStore', 'ENGINE': 'xmodule.modulestore.split_mongo.SplitMongoModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': modulestore_options 'OPTIONS': modulestore_options
} }
} }
...@@ -52,7 +49,7 @@ MODULESTORE = { ...@@ -52,7 +49,7 @@ MODULESTORE = {
# This is for static content for courseware, not system static content (e.g. javascript, css, edX branding, etc) # This is for static content for courseware, not system static content (e.g. javascript, css, edX branding, etc)
CONTENTSTORE = { CONTENTSTORE = {
'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore', 'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore',
'DOC_STORE_CONFIG': { 'OPTIONS': {
'host': 'localhost', 'host': 'localhost',
'db': 'xcontent', 'db': 'xcontent',
}, },
......
...@@ -57,38 +57,34 @@ DOC_STORE_CONFIG = { ...@@ -57,38 +57,34 @@ DOC_STORE_CONFIG = {
'collection': 'test_modulestore', 'collection': 'test_modulestore',
} }
MODULESTORE_OPTIONS = { MODULESTORE_OPTIONS = dict({
'default_class': 'xmodule.raw_module.RawDescriptor', 'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': TEST_ROOT / "data", 'fs_root': TEST_ROOT / "data",
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string',
} }, **DOC_STORE_CONFIG)
MODULESTORE = { MODULESTORE = {
'default': { 'default': {
'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore', 'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': MODULESTORE_OPTIONS 'OPTIONS': MODULESTORE_OPTIONS
}, },
'direct': { 'direct': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': MODULESTORE_OPTIONS 'OPTIONS': MODULESTORE_OPTIONS
}, },
'draft': { 'draft': {
'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore', 'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': MODULESTORE_OPTIONS 'OPTIONS': MODULESTORE_OPTIONS
}, },
'split': { 'split': {
'ENGINE': 'xmodule.modulestore.split_mongo.SplitMongoModuleStore', 'ENGINE': 'xmodule.modulestore.split_mongo.SplitMongoModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': MODULESTORE_OPTIONS 'OPTIONS': MODULESTORE_OPTIONS
} }
} }
CONTENTSTORE = { CONTENTSTORE = {
'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore', 'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore',
'DOC_STORE_CONFIG': { 'OPTIONS': {
'host': 'localhost', 'host': 'localhost',
'db': 'test_xcontent', 'db': 'test_xcontent',
}, },
......
...@@ -25,7 +25,7 @@ from xmodule.modulestore.xml_importer import import_from_xml ...@@ -25,7 +25,7 @@ from xmodule.modulestore.xml_importer import import_from_xml
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE)
TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex TEST_DATA_CONTENTSTORE['OPTIONS']['db'] = 'test_xcontent_%s' % uuid4().hex
TEST_MODULESTORE = studio_store_config(settings.TEST_ROOT / "data") TEST_MODULESTORE = studio_store_config(settings.TEST_ROOT / "data")
...@@ -80,7 +80,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -80,7 +80,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
def tearDown(self): def tearDown(self):
MongoClient().drop_database(TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db']) MongoClient().drop_database(TEST_DATA_CONTENTSTORE['OPTIONS']['db'])
_CONTENTSTORE.clear() _CONTENTSTORE.clear()
def test_unlocked_asset(self): def test_unlocked_asset(self):
......
...@@ -175,7 +175,7 @@ def reset_databases(scenario): ...@@ -175,7 +175,7 @@ def reset_databases(scenario):
If no data is created during the test, these lines equivilently do nothing. If no data is created during the test, these lines equivilently do nothing.
''' '''
mongo = MongoClient() mongo = MongoClient()
mongo.drop_database(settings.CONTENTSTORE['DOC_STORE_CONFIG']['db']) mongo.drop_database(settings.CONTENTSTORE['OPTIONS']['db'])
_CONTENTSTORE.clear() _CONTENTSTORE.clear()
modulestore = xmodule.modulestore.django.editable_modulestore() modulestore = xmodule.modulestore.django.editable_modulestore()
......
...@@ -21,7 +21,7 @@ def contentstore(name='default'): ...@@ -21,7 +21,7 @@ def contentstore(name='default'):
if name not in _CONTENTSTORE: if name not in _CONTENTSTORE:
class_ = load_function(settings.CONTENTSTORE['ENGINE']) class_ = load_function(settings.CONTENTSTORE['ENGINE'])
options = {} options = {}
options.update(settings.CONTENTSTORE['DOC_STORE_CONFIG']) options.update(settings.CONTENTSTORE['OPTIONS'])
if 'ADDITIONAL_OPTIONS' in settings.CONTENTSTORE: if 'ADDITIONAL_OPTIONS' in settings.CONTENTSTORE:
if name in settings.CONTENTSTORE['ADDITIONAL_OPTIONS']: if name in settings.CONTENTSTORE['ADDITIONAL_OPTIONS']:
options.update(settings.CONTENTSTORE['ADDITIONAL_OPTIONS'][name]) options.update(settings.CONTENTSTORE['ADDITIONAL_OPTIONS'][name])
......
...@@ -397,12 +397,7 @@ class ModuleStoreBase(ModuleStore): ...@@ -397,12 +397,7 @@ class ModuleStoreBase(ModuleStore):
''' '''
Implement interface functionality that can be shared. Implement interface functionality that can be shared.
''' '''
def __init__( def __init__(self, metadata_inheritance_cache_subsystem=None, request_cache=None, modulestore_update_signal=None, xblock_mixins=()):
self,
doc_store_config=None, # ignore if passed up
metadata_inheritance_cache_subsystem=None, request_cache=None,
modulestore_update_signal=None, xblock_mixins=()
):
''' '''
Set up the error-tracking logic. Set up the error-tracking logic.
''' '''
......
...@@ -38,7 +38,7 @@ def load_function(path): ...@@ -38,7 +38,7 @@ def load_function(path):
return getattr(import_module(module_path), name) return getattr(import_module(module_path), name)
def create_modulestore_instance(engine, doc_store_config, options): def create_modulestore_instance(engine, options):
""" """
This will return a new instance of a modulestore given an engine and options This will return a new instance of a modulestore given an engine and options
""" """
...@@ -66,7 +66,6 @@ def create_modulestore_instance(engine, doc_store_config, options): ...@@ -66,7 +66,6 @@ def create_modulestore_instance(engine, doc_store_config, options):
request_cache=request_cache, request_cache=request_cache,
modulestore_update_signal=Signal(providing_args=['modulestore', 'course_id', 'location']), modulestore_update_signal=Signal(providing_args=['modulestore', 'course_id', 'location']),
xblock_mixins=getattr(settings, 'XBLOCK_MIXINS', ()), xblock_mixins=getattr(settings, 'XBLOCK_MIXINS', ()),
doc_store_config=doc_store_config,
**_options **_options
) )
...@@ -107,11 +106,8 @@ def modulestore(name=None): ...@@ -107,11 +106,8 @@ def modulestore(name=None):
name = get_default_store_name_for_current_request() name = get_default_store_name_for_current_request()
if name not in _MODULESTORES: if name not in _MODULESTORES:
_MODULESTORES[name] = create_modulestore_instance( _MODULESTORES[name] = create_modulestore_instance(settings.MODULESTORE[name]['ENGINE'],
settings.MODULESTORE[name]['ENGINE'], settings.MODULESTORE[name]['OPTIONS'])
settings.MODULESTORE[name].get('DOC_STORE_CONFIG', {}),
settings.MODULESTORE[name].get('OPTIONS', {})
)
# inject loc_mapper into newly created modulestore if it needs it # inject loc_mapper into newly created modulestore if it needs it
if name == 'split' and _loc_singleton is not None: if name == 'split' and _loc_singleton is not None:
_MODULESTORES['split'].loc_mapper = _loc_singleton _MODULESTORES['split'].loc_mapper = _loc_singleton
......
...@@ -30,12 +30,8 @@ class MixedModuleStore(ModuleStoreBase): ...@@ -30,12 +30,8 @@ class MixedModuleStore(ModuleStoreBase):
raise Exception('Missing a default modulestore in the MixedModuleStore __init__ method.') raise Exception('Missing a default modulestore in the MixedModuleStore __init__ method.')
for key, store in stores.items(): for key, store in stores.items():
self.modulestores[key] = create_modulestore_instance( self.modulestores[key] = create_modulestore_instance(store['ENGINE'],
store['ENGINE'], store['OPTIONS'])
# XMLModuleStore's don't have doc store configs
store.get('DOC_STORE_CONFIG', {}),
store['OPTIONS']
)
def _get_modulestore_for_courseid(self, course_id): def _get_modulestore_for_courseid(self, course_id):
""" """
......
...@@ -256,35 +256,25 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -256,35 +256,25 @@ class MongoModuleStore(ModuleStoreBase):
""" """
# TODO (cpennington): Enable non-filesystem filestores # TODO (cpennington): Enable non-filesystem filestores
# pylint: disable=C0103 def __init__(self, host, db, collection, fs_root, render_template,
# pylint: disable=W0201 port=27017, default_class=None,
def __init__(self, doc_store_config, fs_root, render_template,
default_class=None,
error_tracker=null_error_tracker, error_tracker=null_error_tracker,
**kwargs): user=None, password=None, mongo_options=None, **kwargs):
"""
:param doc_store_config: must have a host, db, and collection entries. Other common entries: port, tz_aware.
"""
super(MongoModuleStore, self).__init__(**kwargs) super(MongoModuleStore, self).__init__(**kwargs)
def do_connection( if mongo_options is None:
db, collection, host, port=27017, tz_aware=True, user=None, password=None, **kwargs mongo_options = {}
):
"""
Create & open the connection, authenticate, and provide pointers to the collection
"""
self.collection = pymongo.connection.Connection(
host=host,
port=port,
tz_aware=tz_aware,
**kwargs
)[db][collection]
if user is not None and password is not None: self.collection = pymongo.connection.Connection(
self.collection.database.authenticate(user, password) host=host,
port=port,
tz_aware=True,
**mongo_options
)[db][collection]
do_connection(**doc_store_config) if user is not None and password is not None:
self.collection.database.authenticate(user, password)
# Force mongo to report errors, at the expense of performance # Force mongo to report errors, at the expense of performance
self.collection.safe = True self.collection.safe = True
...@@ -292,8 +282,7 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -292,8 +282,7 @@ class MongoModuleStore(ModuleStoreBase):
# Force mongo to maintain an index over _id.* that is in the same order # Force mongo to maintain an index over _id.* that is in the same order
# that is used when querying by a location # that is used when querying by a location
self.collection.ensure_index( self.collection.ensure_index(
zip(('_id.' + field for field in Location._fields), repeat(1)) zip(('_id.' + field for field in Location._fields), repeat(1)))
)
if default_class is not None: if default_class is not None:
module_path, _, class_name = default_class.rpartition('.') module_path, _, class_name = default_class.rpartition('.')
......
...@@ -48,48 +48,37 @@ class SplitMongoModuleStore(ModuleStoreBase): ...@@ -48,48 +48,37 @@ class SplitMongoModuleStore(ModuleStoreBase):
A Mongodb backed ModuleStore supporting versions, inheritance, A Mongodb backed ModuleStore supporting versions, inheritance,
and sharing. and sharing.
""" """
# pylint: disable=W0201 # pylint: disable=C0103
def __init__(self, doc_store_config, fs_root, render_template, def __init__(self, host, db, collection, fs_root, render_template,
default_class=None, port=27017, default_class=None,
error_tracker=null_error_tracker, error_tracker=null_error_tracker,
user=None, password=None,
mongo_options=None,
loc_mapper=None, loc_mapper=None,
**kwargs): **kwargs):
"""
:param doc_store_config: must have a host, db, and collection entries. Other common entries: port, tz_aware.
"""
super(SplitMongoModuleStore, self).__init__(**kwargs) super(SplitMongoModuleStore, self).__init__(**kwargs)
self.loc_mapper = loc_mapper self.loc_mapper = loc_mapper
if mongo_options is None:
mongo_options = {}
def do_connection( self.db = pymongo.database.Database(pymongo.MongoClient(
db, collection, host, port=27017, tz_aware=True, user=None, password=None, **kwargs host=host,
): port=port,
""" tz_aware=True,
Create & open the connection, authenticate, and provide pointers to the collections **mongo_options
""" ), db)
self.db = pymongo.database.Database(
pymongo.MongoClient(
host=host,
port=port,
tz_aware=tz_aware,
**kwargs
),
db
)
if user is not None and password is not None:
self.db.authenticate(user, password)
self.course_index = self.db[collection + '.active_versions']
self.structures = self.db[collection + '.structures']
self.definitions = self.db[collection + '.definitions']
do_connection(**doc_store_config) self.course_index = self.db[collection + '.active_versions']
self.structures = self.db[collection + '.structures']
self.definitions = self.db[collection + '.definitions']
# Code review question: How should I expire entries? # Code review question: How should I expire entries?
# _add_cache could use a lru mechanism to control the cache size? # _add_cache could use a lru mechanism to control the cache size?
self.thread_cache = threading.local() self.thread_cache = threading.local()
if user is not None and password is not None:
self.db.authenticate(user, password)
# every app has write access to the db (v having a flag to indicate r/o v write) # every app has write access to the db (v having a flag to indicate r/o v write)
# Force mongo to report errors, at the expense of performance # Force mongo to report errors, at the expense of performance
......
import re import re
from xmodule.contentstore.content import StaticContent from xmodule.contentstore.content import StaticContent
from xmodule.modulestore import Location from xmodule.modulestore import Location
from xmodule.modulestore.mongo import MongoModuleStore
from xmodule.modulestore.inheritance import own_metadata from xmodule.modulestore.inheritance import own_metadata
import logging import logging
......
...@@ -52,13 +52,11 @@ def mongo_store_config(data_dir): ...@@ -52,13 +52,11 @@ def mongo_store_config(data_dir):
store = { store = {
'default': { 'default': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'DOC_STORE_CONFIG': { 'OPTIONS': {
'default_class': 'xmodule.raw_module.RawDescriptor',
'host': 'localhost', 'host': 'localhost',
'db': 'test_xmodule', 'db': 'test_xmodule',
'collection': 'modulestore_%s' % uuid4().hex, 'collection': 'modulestore_%s' % uuid4().hex,
},
'OPTIONS': {
'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': data_dir, 'fs_root': data_dir,
'render_template': 'mitxmako.shortcuts.render_to_string' 'render_template': 'mitxmako.shortcuts.render_to_string'
} }
...@@ -76,6 +74,9 @@ def draft_mongo_store_config(data_dir): ...@@ -76,6 +74,9 @@ def draft_mongo_store_config(data_dir):
modulestore_options = { modulestore_options = {
'default_class': 'xmodule.raw_module.RawDescriptor', 'default_class': 'xmodule.raw_module.RawDescriptor',
'host': 'localhost',
'db': 'test_xmodule',
'collection': 'modulestore_%s' % uuid4().hex,
'fs_root': data_dir, 'fs_root': data_dir,
'render_template': 'mitxmako.shortcuts.render_to_string' 'render_template': 'mitxmako.shortcuts.render_to_string'
} }
...@@ -83,11 +84,6 @@ def draft_mongo_store_config(data_dir): ...@@ -83,11 +84,6 @@ def draft_mongo_store_config(data_dir):
store = { store = {
'default': { 'default': {
'ENGINE': 'xmodule.modulestore.mongo.draft.DraftModuleStore', 'ENGINE': 'xmodule.modulestore.mongo.draft.DraftModuleStore',
'DOC_STORE_CONFIG': {
'host': 'localhost',
'db': 'test_xmodule',
'collection': 'modulestore_%s' % uuid4().hex,
},
'OPTIONS': modulestore_options 'OPTIONS': modulestore_options
} }
} }
...@@ -118,13 +114,11 @@ def studio_store_config(data_dir): ...@@ -118,13 +114,11 @@ def studio_store_config(data_dir):
""" """
Defines modulestore structure used by Studio tests. Defines modulestore structure used by Studio tests.
""" """
store_config = { options = {
'default_class': 'xmodule.raw_module.RawDescriptor',
'host': 'localhost', 'host': 'localhost',
'db': 'test_xmodule', 'db': 'test_xmodule',
'collection': 'modulestore_%s' % uuid4().hex, 'collection': 'modulestore_%s' % uuid4().hex,
}
options = {
'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': data_dir, 'fs_root': data_dir,
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string',
} }
...@@ -132,22 +126,18 @@ def studio_store_config(data_dir): ...@@ -132,22 +126,18 @@ def studio_store_config(data_dir):
store = { store = {
'default': { 'default': {
'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore', 'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore',
'DOC_STORE_CONFIG': store_config,
'OPTIONS': options 'OPTIONS': options
}, },
'direct': { 'direct': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'DOC_STORE_CONFIG': store_config,
'OPTIONS': options 'OPTIONS': options
}, },
'draft': { 'draft': {
'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore', 'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore',
'DOC_STORE_CONFIG': store_config,
'OPTIONS': options 'OPTIONS': options
}, },
'split': { 'split': {
'ENGINE': 'xmodule.modulestore.split_mongo.SplitMongoModuleStore', 'ENGINE': 'xmodule.modulestore.split_mongo.SplitMongoModuleStore',
'DOC_STORE_CONFIG': store_config,
'OPTIONS': options 'OPTIONS': options
} }
} }
...@@ -216,7 +206,7 @@ class ModuleStoreTestCase(TestCase): ...@@ -216,7 +206,7 @@ class ModuleStoreTestCase(TestCase):
If using a Mongo-backed modulestore, drop the collection. If using a Mongo-backed modulestore, drop the collection.
""" """
# This will return the mongo-backed modulestore # This will return the mongo-backed modulestore
# even if we're using a mixed modulestore # even if we're using a mixed modulestore
store = editable_modulestore() store = editable_modulestore()
......
...@@ -47,13 +47,11 @@ OPTIONS = { ...@@ -47,13 +47,11 @@ OPTIONS = {
}, },
'default': { 'default': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'DOC_STORE_CONFIG': { 'OPTIONS': {
'default_class': DEFAULT_CLASS,
'host': HOST, 'host': HOST,
'db': DB, 'db': DB,
'collection': COLLECTION, 'collection': COLLECTION,
},
'OPTIONS': {
'default_class': DEFAULT_CLASS,
'fs_root': DATA_DIR, 'fs_root': DATA_DIR,
'render_template': RENDER_TEMPLATE, 'render_template': RENDER_TEMPLATE,
} }
......
...@@ -56,19 +56,14 @@ class TestMongoModuleStore(object): ...@@ -56,19 +56,14 @@ class TestMongoModuleStore(object):
@staticmethod @staticmethod
def initdb(): def initdb():
# connect to the db # connect to the db
doc_store_config = { store = MongoModuleStore(HOST, DB, COLLECTION, FS_ROOT, RENDER_TEMPLATE, default_class=DEFAULT_CLASS)
'host': HOST,
'db': DB,
'collection': COLLECTION,
}
store = MongoModuleStore(doc_store_config, FS_ROOT, RENDER_TEMPLATE, default_class=DEFAULT_CLASS)
# since MongoModuleStore and MongoContentStore are basically assumed to be together, create this class # since MongoModuleStore and MongoContentStore are basically assumed to be together, create this class
# as well # as well
content_store = MongoContentStore(HOST, DB) content_store = MongoContentStore(HOST, DB)
# #
# Also test draft store imports # Also test draft store imports
# #
draft_store = DraftModuleStore(doc_store_config, FS_ROOT, RENDER_TEMPLATE, default_class=DEFAULT_CLASS) draft_store = DraftModuleStore(HOST, DB, COLLECTION, FS_ROOT, RENDER_TEMPLATE, default_class=DEFAULT_CLASS)
# Explicitly list the courses to load (don't want the big one) # Explicitly list the courses to load (don't want the big one)
courses = ['toy', 'simple', 'simple_with_draft', 'test_unicode'] courses = ['toy', 'simple', 'simple_with_draft', 'test_unicode']
import_from_xml(store, DATA_DIR, courses, draft_store=draft_store, static_content_store=content_store) import_from_xml(store, DATA_DIR, courses, draft_store=draft_store, static_content_store=content_store)
...@@ -118,10 +113,7 @@ class TestMongoModuleStore(object): ...@@ -118,10 +113,7 @@ class TestMongoModuleStore(object):
pprint([Location(i['_id']).url() for i in ids]) pprint([Location(i['_id']).url() for i in ids])
def test_mongo_modulestore_type(self): def test_mongo_modulestore_type(self):
store = MongoModuleStore( store = MongoModuleStore(HOST, DB, COLLECTION, FS_ROOT, RENDER_TEMPLATE, default_class=DEFAULT_CLASS)
{'host': HOST, 'db': DB, 'collection': COLLECTION},
FS_ROOT, RENDER_TEMPLATE, default_class=DEFAULT_CLASS
)
assert_equals(store.get_modulestore_type('foo/bar/baz'), 'mongo') assert_equals(store.get_modulestore_type('foo/bar/baz'), 'mongo')
def test_get_courses(self): def test_get_courses(self):
......
...@@ -26,18 +26,18 @@ class TestPublish(unittest.TestCase): ...@@ -26,18 +26,18 @@ class TestPublish(unittest.TestCase):
'db': 'test_xmodule', 'db': 'test_xmodule',
} }
modulestore_options = { modulestore_options = dict({
'default_class': 'xmodule.raw_module.RawDescriptor', 'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': '', 'fs_root': '',
'render_template': mock.Mock(return_value=""), 'render_template': mock.Mock(return_value=""),
'xblock_mixins': (InheritanceMixin,) 'xblock_mixins': (InheritanceMixin,)
} }, **db_config)
def setUp(self): def setUp(self):
self.db_config['collection'] = 'modulestore{0}'.format(uuid.uuid4().hex) self.modulestore_options['collection'] = 'modulestore{0}'.format(uuid.uuid4().hex)
self.old_mongo = MongoModuleStore(self.db_config, **self.modulestore_options) self.old_mongo = MongoModuleStore(**self.modulestore_options)
self.draft_mongo = DraftMongoModuleStore(self.db_config, **self.modulestore_options) self.draft_mongo = DraftMongoModuleStore(**self.modulestore_options)
self.addCleanup(self.tear_down_mongo) self.addCleanup(self.tear_down_mongo)
self.course_location = None self.course_location = None
......
...@@ -34,22 +34,20 @@ class TestMigration(unittest.TestCase): ...@@ -34,22 +34,20 @@ class TestMigration(unittest.TestCase):
'collection': 'modulestore{0}'.format(uuid.uuid4().hex), 'collection': 'modulestore{0}'.format(uuid.uuid4().hex),
} }
modulestore_options = { modulestore_options = dict({
'default_class': 'xmodule.raw_module.RawDescriptor', 'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': '', 'fs_root': '',
'render_template': mock.Mock(return_value=""), 'render_template': mock.Mock(return_value=""),
'xblock_mixins': (InheritanceMixin,) 'xblock_mixins': (InheritanceMixin,)
} }, **db_config)
def setUp(self): def setUp(self):
super(TestMigration, self).setUp() super(TestMigration, self).setUp()
self.loc_mapper = LocMapperStore(**self.db_config) self.loc_mapper = LocMapperStore(**self.db_config)
self.old_mongo = MongoModuleStore(self.db_config, **self.modulestore_options) self.old_mongo = MongoModuleStore(**self.modulestore_options)
self.draft_mongo = DraftModuleStore(self.db_config, **self.modulestore_options) self.draft_mongo = DraftModuleStore(**self.modulestore_options)
self.split_mongo = SplitMongoModuleStore( self.split_mongo = SplitMongoModuleStore(
doc_store_config=self.db_config, loc_mapper=self.loc_mapper, **self.modulestore_options
loc_mapper=self.loc_mapper,
**self.modulestore_options
) )
self.migrator = SplitMigrator(self.split_mongo, self.old_mongo, self.draft_mongo, self.loc_mapper) self.migrator = SplitMigrator(self.split_mongo, self.old_mongo, self.draft_mongo, self.loc_mapper)
self.course_location = None self.course_location = None
......
...@@ -28,21 +28,18 @@ class SplitModuleTest(unittest.TestCase): ...@@ -28,21 +28,18 @@ class SplitModuleTest(unittest.TestCase):
versions. It creates unique collection names and removes them after all versions. It creates unique collection names and removes them after all
tests finish. tests finish.
''' '''
# Snippets of what would be in the django settings envs file # Snippet of what would be in the django settings envs file
DOC_STORE_CONFIG = { modulestore_options = {
'default_class': 'xmodule.raw_module.RawDescriptor',
'host': 'localhost', 'host': 'localhost',
'db': 'test_xmodule', 'db': 'test_xmodule',
'collection': 'modulestore{0}'.format(uuid.uuid4().hex), 'collection': 'modulestore{0}'.format(uuid.uuid4().hex),
}
modulestore_options = {
'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': '', 'fs_root': '',
'xblock_mixins': (InheritanceMixin, XModuleMixin) 'xblock_mixins': (InheritanceMixin, XModuleMixin)
} }
MODULESTORE = { MODULESTORE = {
'ENGINE': 'xmodule.modulestore.split_mongo.SplitMongoModuleStore', 'ENGINE': 'xmodule.modulestore.split_mongo.SplitMongoModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': modulestore_options 'OPTIONS': modulestore_options
} }
...@@ -69,8 +66,8 @@ class SplitModuleTest(unittest.TestCase): ...@@ -69,8 +66,8 @@ class SplitModuleTest(unittest.TestCase):
Loads the initial data into the db ensuring the collection name is Loads the initial data into the db ensuring the collection name is
unique. unique.
''' '''
collection_prefix = SplitModuleTest.MODULESTORE['DOC_STORE_CONFIG']['collection'] + '.' collection_prefix = SplitModuleTest.MODULESTORE['OPTIONS']['collection'] + '.'
dbname = SplitModuleTest.MODULESTORE['DOC_STORE_CONFIG']['db'] dbname = SplitModuleTest.MODULESTORE['OPTIONS']['db']
processes = [ processes = [
subprocess.Popen([ subprocess.Popen([
'mongoimport', '-d', dbname, '-c', 'mongoimport', '-d', dbname, '-c',
...@@ -92,7 +89,7 @@ class SplitModuleTest(unittest.TestCase): ...@@ -92,7 +89,7 @@ class SplitModuleTest(unittest.TestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
collection_prefix = SplitModuleTest.MODULESTORE['DOC_STORE_CONFIG']['collection'] + '.' collection_prefix = SplitModuleTest.MODULESTORE['OPTIONS']['collection'] + '.'
if SplitModuleTest.modulestore: if SplitModuleTest.modulestore:
for collection in ('active_versions', 'structures', 'definitions'): for collection in ('active_versions', 'structures', 'definitions'):
modulestore().db.drop_collection(collection_prefix + collection) modulestore().db.drop_collection(collection_prefix + collection)
...@@ -1118,10 +1115,7 @@ def modulestore(): ...@@ -1118,10 +1115,7 @@ def modulestore():
options['render_template'] = render_to_template_mock options['render_template'] = render_to_template_mock
# pylint: disable=W0142 # pylint: disable=W0142
SplitModuleTest.modulestore = class_( SplitModuleTest.modulestore = class_(**options)
SplitModuleTest.MODULESTORE['DOC_STORE_CONFIG'],
**options
)
return SplitModuleTest.modulestore return SplitModuleTest.modulestore
......
...@@ -32,11 +32,11 @@ DOC_STORE_CONFIG = { ...@@ -32,11 +32,11 @@ DOC_STORE_CONFIG = {
'collection': 'acceptance_modulestore_%s' % seed(), 'collection': 'acceptance_modulestore_%s' % seed(),
} }
modulestore_options = { modulestore_options = dict({
'default_class': 'xmodule.raw_module.RawDescriptor', 'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': TEST_ROOT / "data", 'fs_root': TEST_ROOT / "data",
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string',
} }, **DOC_STORE_CONFIG)
MODULESTORE = { MODULESTORE = {
'default': { 'default': {
...@@ -46,7 +46,6 @@ MODULESTORE = { ...@@ -46,7 +46,6 @@ MODULESTORE = {
'stores': { 'stores': {
'default': { 'default': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': modulestore_options 'OPTIONS': modulestore_options
} }
} }
...@@ -58,7 +57,7 @@ MODULESTORE['direct'] = MODULESTORE['default'] ...@@ -58,7 +57,7 @@ MODULESTORE['direct'] = MODULESTORE['default']
CONTENTSTORE = { CONTENTSTORE = {
'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore', 'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore',
'DOC_STORE_CONFIG': { 'OPTIONS': {
'host': 'localhost', 'host': 'localhost',
'db': 'acceptance_xcontent_%s' % seed(), 'db': 'acceptance_xcontent_%s' % seed(),
} }
......
...@@ -28,16 +28,15 @@ DOC_STORE_CONFIG = { ...@@ -28,16 +28,15 @@ DOC_STORE_CONFIG = {
'collection': 'modulestore', 'collection': 'modulestore',
} }
modulestore_options = { modulestore_options = dict({
'default_class': 'xmodule.raw_module.RawDescriptor', 'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': DATA_DIR, 'fs_root': DATA_DIR,
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string',
} }, **DOC_STORE_CONFIG)
MODULESTORE = { MODULESTORE = {
'default': { 'default': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': modulestore_options 'OPTIONS': modulestore_options
}, },
'draft': { 'draft': {
...@@ -48,7 +47,7 @@ MODULESTORE = { ...@@ -48,7 +47,7 @@ MODULESTORE = {
CONTENTSTORE = { CONTENTSTORE = {
'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore', 'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore',
'DOC_STORE_CONFIG': { 'OPTIONS': {
'host': 'localhost', 'host': 'localhost',
'db': 'xcontent', 'db': 'xcontent',
} }
......
...@@ -25,13 +25,11 @@ MODULESTORE = { ...@@ -25,13 +25,11 @@ MODULESTORE = {
}, },
'default': { 'default': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'DOC_STORE_CONFIG': { 'OPTIONS': {
'default_class': 'xmodule.raw_module.RawDescriptor',
'host': 'localhost', 'host': 'localhost',
'db': 'xmodule', 'db': 'xmodule',
'collection': 'modulestore', 'collection': 'modulestore',
},
'OPTIONS': {
'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': DATA_DIR, 'fs_root': DATA_DIR,
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string',
} }
......
...@@ -11,7 +11,6 @@ from .dev import * ...@@ -11,7 +11,6 @@ from .dev import *
MODULESTORE = { MODULESTORE = {
'default': { 'default': {
'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore', 'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': modulestore_options 'OPTIONS': modulestore_options
}, },
} }
...@@ -13,13 +13,11 @@ GITHUB_REPO_ROOT = ENV_ROOT / "data" ...@@ -13,13 +13,11 @@ GITHUB_REPO_ROOT = ENV_ROOT / "data"
MODULESTORE = { MODULESTORE = {
'default': { 'default': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'DOC_STORE_CONFIG': { 'OPTIONS': {
'default_class': 'xmodule.raw_module.RawDescriptor',
'host': 'localhost', 'host': 'localhost',
'db': 'xmodule', 'db': 'xmodule',
'collection': 'modulestore', 'collection': 'modulestore',
},
'OPTIONS': {
'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': GITHUB_REPO_ROOT, 'fs_root': GITHUB_REPO_ROOT,
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string',
} }
......
...@@ -40,7 +40,7 @@ MITX_FEATURES['ENABLE_SHOPPING_CART'] = True ...@@ -40,7 +40,7 @@ MITX_FEATURES['ENABLE_SHOPPING_CART'] = True
WIKI_ENABLED = True WIKI_ENABLED = True
# Makes the tests run much faster... # Makes the tests run much faster...
SOUTH_TESTS_MIGRATE = False # To disable migrations and use syncdb instead SOUTH_TESTS_MIGRATE = False # To disable migrations and use syncdb instead
# Nose Test Runner # Nose Test Runner
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
...@@ -78,7 +78,7 @@ XQUEUE_INTERFACE = { ...@@ -78,7 +78,7 @@ XQUEUE_INTERFACE = {
}, },
"basic_auth": ('anant', 'agarwal'), "basic_auth": ('anant', 'agarwal'),
} }
XQUEUE_WAITTIME_BETWEEN_REQUESTS = 5 # seconds XQUEUE_WAITTIME_BETWEEN_REQUESTS = 5 # seconds
# Don't rely on a real staff grading backend # Don't rely on a real staff grading backend
...@@ -115,7 +115,7 @@ INIT_MODULESTORE_ON_STARTUP = False ...@@ -115,7 +115,7 @@ INIT_MODULESTORE_ON_STARTUP = False
CONTENTSTORE = { CONTENTSTORE = {
'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore', 'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore',
'DOC_STORE_CONFIG': { 'OPTIONS': {
'host': 'localhost', 'host': 'localhost',
'db': 'xcontent', 'db': 'xcontent',
} }
...@@ -247,4 +247,4 @@ PASSWORD_HASHERS = ( ...@@ -247,4 +247,4 @@ PASSWORD_HASHERS = (
# Generated checkid_setup request to http://testserver/openid/provider/login/ with assocication {HMAC-SHA1}{51d49995}{s/kRmA==} # Generated checkid_setup request to http://testserver/openid/provider/login/ with assocication {HMAC-SHA1}{51d49995}{s/kRmA==}
import openid.oidutil import openid.oidutil
openid.oidutil.log = lambda message, level = 0: None openid.oidutil.log = lambda message, level=0: None
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment