Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def handle(self, *args, **options):
# use a user-specified database name, if present
# this is useful for doing dumps from databases restored from prod backups
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)

Expand Down
6 changes: 3 additions & 3 deletions cms/djangoapps/contentstore/tests/test_contentstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
from contentstore.utils import delete_course_and_groups

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):
Expand Down Expand Up @@ -101,7 +101,7 @@ def setUp(self):
self.client.login(username=uname, password=password)

def tearDown(self):
MongoClient().drop_database(TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'])
MongoClient().drop_database(TEST_DATA_CONTENTSTORE['OPTIONS']['db'])
_CONTENTSTORE.clear()

def check_components_on_page(self, component_types, expected_types):
Expand Down Expand Up @@ -1313,7 +1313,7 @@ def setUp(self):

def tearDown(self):
mongo = MongoClient()
mongo.drop_database(TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'])
mongo.drop_database(TEST_DATA_CONTENTSTORE['OPTIONS']['db'])
_CONTENTSTORE.clear()

def test_create_course(self):
Expand Down
4 changes: 2 additions & 2 deletions cms/djangoapps/contentstore/tests/test_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from xmodule.contentstore.django import _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__)

Expand Down Expand Up @@ -70,7 +70,7 @@ def touch(name):

def tearDown(self):
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()


Expand Down
4 changes: 2 additions & 2 deletions cms/djangoapps/contentstore/tests/test_import_nostatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from pymongo import MongoClient

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)
Expand Down Expand Up @@ -61,7 +61,7 @@ def setUp(self):
self.client.login(username=uname, password=password)

def tearDown(self):
MongoClient().drop_database(TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'])
MongoClient().drop_database(TEST_DATA_CONTENTSTORE['OPTIONS']['db'])
_CONTENTSTORE.clear()

def load_test_import_course(self):
Expand Down
9 changes: 3 additions & 6 deletions cms/envs/acceptance.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,30 @@ def seed():
'collection': 'acceptance_modulestore_%s' % seed(),
}

MODULESTORE_OPTIONS = {
MODULESTORE_OPTIONS = dict({
'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': TEST_ROOT / "data",
'render_template': 'mitxmako.shortcuts.render_to_string',
}
}, **DOC_STORE_CONFIG)

MODULESTORE = {
'default': {
'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': MODULESTORE_OPTIONS
},
'direct': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': MODULESTORE_OPTIONS
},
'draft': {
'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': MODULESTORE_OPTIONS
}
}

CONTENTSTORE = {
'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore',
'DOC_STORE_CONFIG': {
'OPTIONS': {
'host': 'localhost',
'db': 'acceptance_xcontent_%s' % seed(),
},
Expand Down
9 changes: 3 additions & 6 deletions cms/envs/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,23 @@
'collection': 'modulestore',
}

modulestore_options = {
modulestore_options = dict({
'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': GITHUB_REPO_ROOT,
'render_template': 'mitxmako.shortcuts.render_to_string',
}
}, **DOC_STORE_CONFIG)

MODULESTORE = {
'default': {
'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': modulestore_options
},
'direct': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': modulestore_options
},
'split': {
'ENGINE': 'xmodule.modulestore.split_mongo.SplitMongoModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': modulestore_options
}
}
Expand All @@ -52,7 +49,7 @@
# This is for static content for courseware, not system static content (e.g. javascript, css, edX branding, etc)
CONTENTSTORE = {
'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore',
'DOC_STORE_CONFIG': {
'OPTIONS': {
'host': 'localhost',
'db': 'xcontent',
},
Expand Down
10 changes: 3 additions & 7 deletions cms/envs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,38 +57,34 @@
'collection': 'test_modulestore',
}

MODULESTORE_OPTIONS = {
MODULESTORE_OPTIONS = dict({
'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': TEST_ROOT / "data",
'render_template': 'mitxmako.shortcuts.render_to_string',
}
}, **DOC_STORE_CONFIG)

MODULESTORE = {
'default': {
'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': MODULESTORE_OPTIONS
},
'direct': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': MODULESTORE_OPTIONS
},
'draft': {
'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': MODULESTORE_OPTIONS
},
'split': {
'ENGINE': 'xmodule.modulestore.split_mongo.SplitMongoModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': MODULESTORE_OPTIONS
}
}

CONTENTSTORE = {
'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore',
'DOC_STORE_CONFIG': {
'OPTIONS': {
'host': 'localhost',
'db': 'test_xcontent',
},
Expand Down
4 changes: 2 additions & 2 deletions common/djangoapps/contentserver/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
log = logging.getLogger(__name__)

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")

Expand Down Expand Up @@ -80,7 +80,7 @@ def setUp(self):

def tearDown(self):

MongoClient().drop_database(TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'])
MongoClient().drop_database(TEST_DATA_CONTENTSTORE['OPTIONS']['db'])
_CONTENTSTORE.clear()

def test_unlocked_asset(self):
Expand Down
2 changes: 1 addition & 1 deletion common/djangoapps/terrain/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def reset_databases(scenario):
If no data is created during the test, these lines equivilently do nothing.
'''
mongo = MongoClient()
mongo.drop_database(settings.CONTENTSTORE['DOC_STORE_CONFIG']['db'])
mongo.drop_database(settings.CONTENTSTORE['OPTIONS']['db'])
_CONTENTSTORE.clear()

modulestore = xmodule.modulestore.django.editable_modulestore()
Expand Down
2 changes: 1 addition & 1 deletion common/lib/xmodule/xmodule/contentstore/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def contentstore(name='default'):
if name not in _CONTENTSTORE:
class_ = load_function(settings.CONTENTSTORE['ENGINE'])
options = {}
options.update(settings.CONTENTSTORE['DOC_STORE_CONFIG'])
options.update(settings.CONTENTSTORE['OPTIONS'])
if 'ADDITIONAL_OPTIONS' in settings.CONTENTSTORE:
if name in settings.CONTENTSTORE['ADDITIONAL_OPTIONS']:
options.update(settings.CONTENTSTORE['ADDITIONAL_OPTIONS'][name])
Expand Down
7 changes: 1 addition & 6 deletions common/lib/xmodule/xmodule/modulestore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,7 @@ class ModuleStoreBase(ModuleStore):
'''
Implement interface functionality that can be shared.
'''
def __init__(
self,
doc_store_config=None, # ignore if passed up
metadata_inheritance_cache_subsystem=None, request_cache=None,
modulestore_update_signal=None, xblock_mixins=()
):
def __init__(self, metadata_inheritance_cache_subsystem=None, request_cache=None, modulestore_update_signal=None, xblock_mixins=()):
'''
Set up the error-tracking logic.
'''
Expand Down
10 changes: 3 additions & 7 deletions common/lib/xmodule/xmodule/modulestore/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def load_function(path):
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
"""
Expand Down Expand Up @@ -63,7 +63,6 @@ def create_modulestore_instance(engine, doc_store_config, options):
request_cache=request_cache,
modulestore_update_signal=Signal(providing_args=['modulestore', 'course_id', 'location']),
xblock_mixins=getattr(settings, 'XBLOCK_MIXINS', ()),
doc_store_config=doc_store_config,
**_options
)

Expand All @@ -74,11 +73,8 @@ def modulestore(name='default'):
modulestore or create a new one
"""
if name not in _MODULESTORES:
_MODULESTORES[name] = create_modulestore_instance(
settings.MODULESTORE[name]['ENGINE'],
settings.MODULESTORE[name].get('DOC_STORE_CONFIG', {}),
settings.MODULESTORE[name].get('OPTIONS', {})
)
_MODULESTORES[name] = create_modulestore_instance(settings.MODULESTORE[name]['ENGINE'],
settings.MODULESTORE[name]['OPTIONS'])
# inject loc_mapper into newly created modulestore if it needs it
if name == 'split' and _loc_singleton is not None:
_MODULESTORES['split'].loc_mapper = _loc_singleton
Expand Down
8 changes: 2 additions & 6 deletions common/lib/xmodule/xmodule/modulestore/mixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ def __init__(self, mappings, stores, **kwargs):
raise Exception('Missing a default modulestore in the MixedModuleStore __init__ method.')

for key, store in stores.items():
self.modulestores[key] = create_modulestore_instance(
store['ENGINE'],
# XMLModuleStore's don't have doc store configs
store.get('DOC_STORE_CONFIG', {}),
store['OPTIONS']
)
self.modulestores[key] = create_modulestore_instance(store['ENGINE'],
store['OPTIONS'])

def _get_modulestore_for_courseid(self, course_id):
"""
Expand Down
39 changes: 14 additions & 25 deletions common/lib/xmodule/xmodule/modulestore/mongo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,44 +256,33 @@ class MongoModuleStore(ModuleStoreBase):
"""

# TODO (cpennington): Enable non-filesystem filestores
# pylint: disable=C0103
# pylint: disable=W0201
def __init__(self, doc_store_config, fs_root, render_template,
default_class=None,
def __init__(self, host, db, collection, fs_root, render_template,
port=27017, default_class=None,
error_tracker=null_error_tracker,
**kwargs):
"""
:param doc_store_config: must have a host, db, and collection entries. Other common entries: port, tz_aware.
"""
user=None, password=None, mongo_options=None, **kwargs):

super(MongoModuleStore, self).__init__(**kwargs)

def do_connection(
db, collection, host, port=27017, tz_aware=True, user=None, password=None, **kwargs
):
"""
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 mongo_options is None:
mongo_options = {}

if user is not None and password is not None:
self.collection.database.authenticate(user, password)
self.collection = pymongo.connection.Connection(
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
self.collection.safe = True

# Force mongo to maintain an index over _id.* that is in the same order
# that is used when querying by a location
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:
module_path, _, class_name = default_class.rpartition('.')
Expand Down
Loading