Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
a55b406c
Commit
a55b406c
authored
Aug 04, 2014
by
Nimisha Asthagiri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LMS-11177 Add Split to configuration settings.
parent
cc624fd6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
9 deletions
+105
-9
common/lib/xmodule/xmodule/modulestore/mixed.py
+2
-1
common/lib/xmodule/xmodule/modulestore/modulestore_settings.py
+22
-0
common/lib/xmodule/xmodule/modulestore/tests/test_modulestore_settings.py
+71
-8
lms/envs/common.py
+10
-0
No files found.
common/lib/xmodule/xmodule/modulestore/mixed.py
View file @
a55b406c
...
...
@@ -508,9 +508,10 @@ class MixedModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase):
if
store
.
get_modulestore_type
()
==
store_type
:
self
.
modulestores
.
insert
(
0
,
self
.
modulestores
.
pop
(
i
))
found
=
True
yield
break
if
not
found
:
raise
Exception
(
u"Cannot find store of type {}"
.
format
(
store_type
))
yield
finally
:
self
.
modulestores
=
previous_store_list
...
...
common/lib/xmodule/xmodule/modulestore/modulestore_settings.py
View file @
a55b406c
...
...
@@ -3,6 +3,7 @@ This file contains helper functions for configuring module_store_setting setting
"""
import
warnings
import
copy
def
convert_module_store_setting_if_needed
(
module_store_setting
):
...
...
@@ -66,6 +67,27 @@ def convert_module_store_setting_if_needed(module_store_setting):
)
assert
isinstance
(
module_store_setting
[
'default'
][
'OPTIONS'
][
'stores'
],
list
)
# If Split is not defined but the DraftMongoModuleStore is configured, add Split as a copy of Draft
mixed_stores
=
module_store_setting
[
'default'
][
'OPTIONS'
][
'stores'
]
is_split_defined
=
any
((
'DraftVersioningModuleStore'
in
store
[
'ENGINE'
])
for
store
in
mixed_stores
)
if
not
is_split_defined
:
# find first setting of mongo store
mongo_store
=
next
(
(
store
for
store
in
mixed_stores
if
(
'DraftMongoModuleStore'
in
store
[
'ENGINE'
]
or
'DraftModuleStore'
in
store
[
'ENGINE'
]
)),
None
)
if
mongo_store
:
# deepcopy mongo -> split
split_store
=
copy
.
deepcopy
(
mongo_store
)
# update the ENGINE and NAME fields
split_store
[
'ENGINE'
]
=
'xmodule.modulestore.split_mongo.split_draft.DraftVersioningModuleStore'
split_store
[
'NAME'
]
=
'split'
# add split to the end of the list
mixed_stores
.
append
(
split_store
)
return
module_store_setting
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_modulestore_settings.py
View file @
a55b406c
...
...
@@ -77,15 +77,48 @@ class ModuleStoreSettingsMigration(TestCase):
}
}
ALREADY_UPDATED_MIXED_CONFIG
=
{
'default'
:
{
'ENGINE'
:
'xmodule.modulestore.mixed.MixedModuleStore'
,
'OPTIONS'
:
{
'mappings'
:
{},
'reference_type'
:
'Location'
,
'stores'
:
[
{
'NAME'
:
'split'
,
'ENGINE'
:
'xmodule.modulestore.split_mongo.split_draft.DraftVersioningModuleStore'
,
'DOC_STORE_CONFIG'
:
{},
'OPTIONS'
:
{
'default_class'
:
'xmodule.hidden_module.HiddenDescriptor'
,
'fs_root'
:
"fs_root"
,
'render_template'
:
'edxmako.shortcuts.render_to_string'
,
}
},
{
'NAME'
:
'draft'
,
'ENGINE'
:
'xmodule.modulestore.mongo.draft.DraftModuleStore'
,
'DOC_STORE_CONFIG'
:
{},
'OPTIONS'
:
{
'default_class'
:
'xmodule.hidden_module.HiddenDescriptor'
,
'fs_root'
:
"fs_root"
,
'render_template'
:
'edxmako.shortcuts.render_to_string'
,
}
},
]
}
}
}
def
_get_mixed_stores
(
self
,
mixed_setting
):
"""
Helper for accessing stores in a configuration setting for the Mixed modulestore
Helper for accessing stores in a configuration setting for the Mixed modulestore
.
"""
return
mixed_setting
[
"default"
][
"OPTIONS"
][
"stores"
]
def
assertStoreValuesEqual
(
self
,
store_setting1
,
store_setting2
):
"""
Tests whether the fields in the given store_settings are equal
Tests whether the fields in the given store_settings are equal
.
"""
store_fields
=
[
"OPTIONS"
,
"DOC_STORE_CONFIG"
]
for
field
in
store_fields
:
...
...
@@ -108,26 +141,56 @@ class ModuleStoreSettingsMigration(TestCase):
return
new_mixed_setting
,
new_stores
[
0
]
def
is_split_configured
(
self
,
mixed_setting
):
"""
Tests whether the split module store is configured in the given setting.
"""
stores
=
self
.
_get_mixed_stores
(
mixed_setting
)
split_settings
=
[
store
for
store
in
stores
if
'DraftVersioningModuleStore'
in
store
[
'ENGINE'
]]
if
len
(
split_settings
):
# there should only be one setting for split
self
.
assertEquals
(
len
(
split_settings
),
1
)
# verify name
self
.
assertEquals
(
split_settings
[
0
][
'NAME'
],
'split'
)
# verify split config settings equal those of mongo
self
.
assertStoreValuesEqual
(
split_settings
[
0
],
next
((
store
for
store
in
stores
if
'DraftModuleStore'
in
store
[
'ENGINE'
]),
None
)
)
return
len
(
split_settings
)
>
0
def
test_convert_into_mixed
(
self
):
old_setting
=
self
.
OLD_CONFIG
_
,
new_default_store_setting
=
self
.
assertMigrated
(
old_setting
)
new_mixed_setting
,
new_default_store_setting
=
self
.
assertMigrated
(
old_setting
)
self
.
assertStoreValuesEqual
(
new_default_store_setting
,
old_setting
[
"default"
])
self
.
assertEqual
(
new_default_store_setting
[
"ENGINE"
],
old_setting
[
"default"
][
"ENGINE"
])
self
.
assertFalse
(
self
.
is_split_configured
(
new_mixed_setting
))
def
test_convert_from_old_mongo_to_draft_store
(
self
):
old_setting
=
self
.
OLD_CONFIG_WITH_DIRECT_MONGO
_
,
new_default_store_setting
=
self
.
assertMigrated
(
old_setting
)
new_mixed_setting
,
new_default_store_setting
=
self
.
assertMigrated
(
old_setting
)
self
.
assertStoreValuesEqual
(
new_default_store_setting
,
old_setting
[
"default"
])
self
.
assertEqual
(
new_default_store_setting
[
"ENGINE"
],
"xmodule.modulestore.mongo.draft.DraftModuleStore"
)
self
.
assertTrue
(
self
.
is_split_configured
(
new_mixed_setting
))
def
test_convert_from_dict_to_list
(
self
):
old_mixed_setting
=
self
.
OLD_MIXED_CONFIG_WITH_DICT
new_mixed_setting
,
new_default_store_setting
=
self
.
assertMigrated
(
old_mixed_setting
)
self
.
assertEqual
(
new_default_store_setting
[
"ENGINE"
],
"the_default_store"
)
self
.
assertTrue
(
self
.
is_split_configured
(
new_mixed_setting
))
# compare each store configured in mixed
# exclude split when comparing old and new, since split was added as part of the migration
new_stores
=
[
store
for
store
in
self
.
_get_mixed_stores
(
new_mixed_setting
)
if
store
[
'NAME'
]
!=
'split'
]
old_stores
=
self
.
_get_mixed_stores
(
self
.
OLD_MIXED_CONFIG_WITH_DICT
)
new_stores
=
self
.
_get_mixed_stores
(
new_mixed_setting
)
# compare each store configured in mixed
self
.
assertEqual
(
len
(
new_stores
),
len
(
old_stores
))
for
new_store_setting
in
self
.
_get_mixed_stores
(
new_mixed_setting
):
self
.
assertStoreValuesEqual
(
new_store_setting
,
old_stores
[
new_store_setting
[
'NAME'
]])
for
new_store
in
new_stores
:
self
.
assertStoreValuesEqual
(
new_store
,
old_stores
[
new_store
[
'NAME'
]])
def
test_no_conversion
(
self
):
# make sure there is no migration done on an already updated config
old_mixed_setting
=
self
.
ALREADY_UPDATED_MIXED_CONFIG
new_mixed_setting
,
new_default_store_setting
=
self
.
assertMigrated
(
old_mixed_setting
)
self
.
assertTrue
(
self
.
is_split_configured
(
new_mixed_setting
))
self
.
assertEquals
(
old_mixed_setting
,
new_mixed_setting
)
lms/envs/common.py
View file @
a55b406c
...
...
@@ -524,6 +524,16 @@ MODULESTORE = {
'default_class'
:
'xmodule.hidden_module.HiddenDescriptor'
,
}
},
{
'NAME'
:
'split'
,
'ENGINE'
:
'xmodule.modulestore.split_mongo.split_draft.DraftVersioningModuleStore'
,
'DOC_STORE_CONFIG'
:
DOC_STORE_CONFIG
,
'OPTIONS'
:
{
'default_class'
:
'xmodule.hidden_module.HiddenDescriptor'
,
'fs_root'
:
DATA_DIR
,
'render_template'
:
'edxmako.shortcuts.render_to_string'
,
}
},
]
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment