Commit cd2203eb by Adam Committed by GitHub

Merge pull request #13521 from edx/adam/update-dump-neo4j-command

set neo4j configuration at the command line
parents 4c56c242 23986796
...@@ -139,7 +139,22 @@ class ModuleStoreSerializer(object): ...@@ -139,7 +139,22 @@ class ModuleStoreSerializer(object):
class Command(BaseCommand): class Command(BaseCommand):
""" """
Command to dump modulestore data to neo4j Command to dump modulestore data to neo4j
Takes the following named arguments:
host: the host of the neo4j server
port: the port on the server that accepts https requests
user: the username for the neo4j user
password: the user's password
Example usage:
python manage.py lms dump_to_neo4j --host localhost --port 7473 \
--user user --password password --settings=aws
""" """
def add_arguments(self, parser):
parser.add_argument('--host', type=unicode)
parser.add_argument('--port', type=int)
parser.add_argument('--user', type=unicode)
parser.add_argument('--password', type=unicode)
@staticmethod @staticmethod
def add_to_transaction(neo4j_entities, transaction): def add_to_transaction(neo4j_entities, transaction):
...@@ -156,16 +171,25 @@ class Command(BaseCommand): ...@@ -156,16 +171,25 @@ class Command(BaseCommand):
Iterates through each course, serializes them into graphs, and saves Iterates through each course, serializes them into graphs, and saves
those graphs to neo4j. those graphs to neo4j.
""" """
# first, make sure that there's a valid neo4j configuration host = options['host']
if settings.NEO4J_CONFIG is None: port = options['port']
raise CommandError( neo4j_user = options['user']
"No neo4j configuration (NEO4J_CONFIG) defined in lms.auth.json." neo4j_password = options['password']
authenticate(
"{host}:{port}".format(host=host, port=port),
neo4j_user,
neo4j_password,
) )
auth_params = ["{host}:{https_port}", "{user}", "{password}"] graph = Graph(
authenticate(*[param.format(**settings.NEO4J_CONFIG) for param in auth_params]) bolt=True,
password=neo4j_password,
graph = Graph(**settings.NEO4J_CONFIG) user=neo4j_user,
https_port=port,
host=host,
secure=True
)
mss = ModuleStoreSerializer() mss = ModuleStoreSerializer()
......
...@@ -36,6 +36,7 @@ class TestDumpToNeo4jCommandBase(SharedModuleStoreTestCase): ...@@ -36,6 +36,7 @@ class TestDumpToNeo4jCommandBase(SharedModuleStoreTestCase):
cls.course2 = CourseFactory.create() cls.course2 = CourseFactory.create()
@ddt.ddt
class TestDumpToNeo4jCommand(TestDumpToNeo4jCommandBase): class TestDumpToNeo4jCommand(TestDumpToNeo4jCommandBase):
""" """
Tests for the dump to neo4j management command Tests for the dump to neo4j management command
...@@ -50,7 +51,13 @@ class TestDumpToNeo4jCommand(TestDumpToNeo4jCommandBase): ...@@ -50,7 +51,13 @@ class TestDumpToNeo4jCommand(TestDumpToNeo4jCommandBase):
mock_transaction = mock.Mock() mock_transaction = mock.Mock()
mock_graph.begin.return_value = mock_transaction mock_graph.begin.return_value = mock_transaction
call_command('dump_to_neo4j') call_command(
'dump_to_neo4j',
host='mock_host',
port=7473,
user='mock_user',
password='mock_password',
)
self.assertEqual(mock_graph.begin.call_count, 2) self.assertEqual(mock_graph.begin.call_count, 2)
self.assertEqual(mock_transaction.commit.call_count, 2) self.assertEqual(mock_transaction.commit.call_count, 2)
...@@ -72,21 +79,18 @@ class TestDumpToNeo4jCommand(TestDumpToNeo4jCommandBase): ...@@ -72,21 +79,18 @@ class TestDumpToNeo4jCommand(TestDumpToNeo4jCommandBase):
mock_graph.begin.return_value = mock_transaction mock_graph.begin.return_value = mock_transaction
mock_transaction.run.side_effect = ValueError('Something went wrong!') mock_transaction.run.side_effect = ValueError('Something went wrong!')
call_command('dump_to_neo4j') call_command(
'dump_to_neo4j',
host='mock_host',
port=7473,
user='mock_user',
password='mock_password',
)
self.assertEqual(mock_graph.begin.call_count, 2) self.assertEqual(mock_graph.begin.call_count, 2)
self.assertEqual(mock_transaction.commit.call_count, 0) self.assertEqual(mock_transaction.commit.call_count, 0)
self.assertEqual(mock_transaction.rollback.call_count, 2) self.assertEqual(mock_transaction.rollback.call_count, 2)
@mock.patch('django.conf.settings.NEO4J_CONFIG', None)
def test_dump_to_neo4j_no_config(self):
"""
Tests that the command errors out if there isn't a configuration
file found
"""
with self.assertRaises(CommandError):
call_command('dump_to_neo4j')
@ddt.ddt @ddt.ddt
class TestModuleStoreSerializer(TestDumpToNeo4jCommandBase): class TestModuleStoreSerializer(TestDumpToNeo4jCommandBase):
......
...@@ -871,10 +871,6 @@ APP_UPGRADE_CACHE_TIMEOUT = ENV_TOKENS.get('APP_UPGRADE_CACHE_TIMEOUT', APP_UPGR ...@@ -871,10 +871,6 @@ APP_UPGRADE_CACHE_TIMEOUT = ENV_TOKENS.get('APP_UPGRADE_CACHE_TIMEOUT', APP_UPGR
AFFILIATE_COOKIE_NAME = ENV_TOKENS.get('AFFILIATE_COOKIE_NAME', AFFILIATE_COOKIE_NAME) AFFILIATE_COOKIE_NAME = ENV_TOKENS.get('AFFILIATE_COOKIE_NAME', AFFILIATE_COOKIE_NAME)
############## Settings for Neo4j ############################
NEO4J_CONFIG = AUTH_TOKENS.get('NEO4J_CONFIG')
############## Settings for LMS Context Sensitive Help ############## ############## Settings for LMS Context Sensitive Help ##############
DOC_LINK_BASE_URL = ENV_TOKENS.get('DOC_LINK_BASE_URL', DOC_LINK_BASE_URL) DOC_LINK_BASE_URL = ENV_TOKENS.get('DOC_LINK_BASE_URL', DOC_LINK_BASE_URL)
...@@ -2974,11 +2974,6 @@ AFFILIATE_COOKIE_NAME = 'affiliate_id' ...@@ -2974,11 +2974,6 @@ AFFILIATE_COOKIE_NAME = 'affiliate_id'
REDIRECT_CACHE_TIMEOUT = None # The length of time we cache Redirect model data REDIRECT_CACHE_TIMEOUT = None # The length of time we cache Redirect model data
REDIRECT_CACHE_KEY_PREFIX = 'redirects' REDIRECT_CACHE_KEY_PREFIX = 'redirects'
############## Settings for Neo4j ############################
# This should be set in configuration
NEO4J_CONFIG = None
############## Settings for LMS Context Sensitive Help ############## ############## Settings for LMS Context Sensitive Help ##############
DOC_LINK_BASE_URL = None DOC_LINK_BASE_URL = None
...@@ -592,13 +592,3 @@ COMPREHENSIVE_THEME_DIRS = [REPO_ROOT / "themes", REPO_ROOT / "common/test"] ...@@ -592,13 +592,3 @@ COMPREHENSIVE_THEME_DIRS = [REPO_ROOT / "themes", REPO_ROOT / "common/test"]
COMPREHENSIVE_THEME_LOCALE_PATHS = [REPO_ROOT / "themes/conf/locale", ] COMPREHENSIVE_THEME_LOCALE_PATHS = [REPO_ROOT / "themes/conf/locale", ]
LMS_ROOT_URL = "http://localhost:8000" LMS_ROOT_URL = "http://localhost:8000"
# Test configuration for neo4j
NEO4J_CONFIG = {
'bolt': True,
'password': 'password',
'user': 'neo4j',
'https_port': 7473,
'host': 'localhost',
'secure': True,
}
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