From 6247377a792fb2aea88dd6b0ceda3e67188aa93b Mon Sep 17 00:00:00 2001 From: Douglas Cerna Date: Wed, 10 May 2017 08:58:30 -0600 Subject: [PATCH 1/3] Added workaround for broken CMS course export/import when using ephemeral databases --- instance/models/mixins/openedx_storage.py | 5 ++++- instance/templates/instance/ansible/ephemeral.yml | 1 + instance/tests/models/test_openedx_instance.py | 3 ++- .../tests/models/test_openedx_storage_mixins.py | 13 ++++++++++++- 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 instance/templates/instance/ansible/ephemeral.yml diff --git a/instance/models/mixins/openedx_storage.py b/instance/models/mixins/openedx_storage.py index 2f98375fe..ea55b6db2 100644 --- a/instance/models/mixins/openedx_storage.py +++ b/instance/models/mixins/openedx_storage.py @@ -61,7 +61,10 @@ def get_storage_settings(self): Only needed when not using ephemeral databases """ if self.use_ephemeral_databases: - return '' + # Workaround for broken CMS course export/import + # caused by https://github.com/edx/edx-platform/pull/14552 + template = loader.get_template('instance/ansible/ephemeral.yml') + return template.render() new_settings = '' if self.s3_access_key and self.s3_secret_access_key and self.s3_bucket_name: diff --git a/instance/templates/instance/ansible/ephemeral.yml b/instance/templates/instance/ansible/ephemeral.yml new file mode 100644 index 000000000..563a877f1 --- /dev/null +++ b/instance/templates/instance/ansible/ephemeral.yml @@ -0,0 +1 @@ +EDXAPP_IMPORT_EXPORT_BUCKET: !!null diff --git a/instance/tests/models/test_openedx_instance.py b/instance/tests/models/test_openedx_instance.py index f5416b042..9c39420d2 100644 --- a/instance/tests/models/test_openedx_instance.py +++ b/instance/tests/models/test_openedx_instance.py @@ -242,7 +242,8 @@ def test_spawn_appserver(self, mocks, mock_provision): getattr(appserver, field_name), ) self.assertEqual(appserver.configuration_database_settings, "") - self.assertEqual(appserver.configuration_storage_settings, "") + ephemeral_settings = 'EDXAPP_IMPORT_EXPORT_BUCKET: !!null\n' + self.assertEqual(appserver.configuration_storage_settings, ephemeral_settings) configuration_vars = yaml.load(appserver.configuration_settings) self.assertEqual(configuration_vars['COMMON_HOSTNAME'], instance.domain) self.assertEqual(configuration_vars['EDXAPP_PLATFORM_NAME'], instance.name) diff --git a/instance/tests/models/test_openedx_storage_mixins.py b/instance/tests/models/test_openedx_storage_mixins.py index e354bc1e9..859f6fad4 100644 --- a/instance/tests/models/test_openedx_storage_mixins.py +++ b/instance/tests/models/test_openedx_storage_mixins.py @@ -85,7 +85,18 @@ def test_ansible_s3_settings_ephemeral(self): s3_bucket_name='test-s3-bucket-name', use_ephemeral_databases=True, ) - self.assertEqual(instance.get_storage_settings(), '') + ephemeral_settings = 'EDXAPP_IMPORT_EXPORT_BUCKET: !!null\n' + self.assertEqual(instance.get_storage_settings(), ephemeral_settings) + + def test_import_export_bucket_setting_ephemeral(self): + """ + Test that get_storage_settings() sets EDXAPP_IMPORT_EXPORT_BUCKET to null when in ephemeral mode + """ + instance = OpenEdXInstanceFactory( + use_ephemeral_databases=True, + ) + ephemeral_settings = 'EDXAPP_IMPORT_EXPORT_BUCKET: !!null\n' + self.assertEqual(instance.get_storage_settings(), ephemeral_settings) class SwiftContainerInstanceTestCase(TestCase): From 152014f60fc6eaad597f481745b91e59ff87509c Mon Sep 17 00:00:00 2001 From: Douglas Cerna Date: Wed, 5 Jul 2017 21:56:00 -0600 Subject: [PATCH 2/3] Changed EDXAPP_IMPORT_EXPORT_BUCKET setting to empty string and removed old comment --- instance/models/mixins/openedx_storage.py | 2 -- instance/templates/instance/ansible/ephemeral.yml | 2 +- instance/tests/models/test_openedx_storage_mixins.py | 7 ++++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/instance/models/mixins/openedx_storage.py b/instance/models/mixins/openedx_storage.py index ea55b6db2..2e25d3da6 100644 --- a/instance/models/mixins/openedx_storage.py +++ b/instance/models/mixins/openedx_storage.py @@ -57,8 +57,6 @@ def swift_container_names(self): def get_storage_settings(self): """ Get configuration_storage_settings to pass to a new AppServer - - Only needed when not using ephemeral databases """ if self.use_ephemeral_databases: # Workaround for broken CMS course export/import diff --git a/instance/templates/instance/ansible/ephemeral.yml b/instance/templates/instance/ansible/ephemeral.yml index 563a877f1..9ae885c8d 100644 --- a/instance/templates/instance/ansible/ephemeral.yml +++ b/instance/templates/instance/ansible/ephemeral.yml @@ -1 +1 @@ -EDXAPP_IMPORT_EXPORT_BUCKET: !!null +EDXAPP_IMPORT_EXPORT_BUCKET: "" diff --git a/instance/tests/models/test_openedx_storage_mixins.py b/instance/tests/models/test_openedx_storage_mixins.py index 859f6fad4..860fa1b47 100644 --- a/instance/tests/models/test_openedx_storage_mixins.py +++ b/instance/tests/models/test_openedx_storage_mixins.py @@ -85,17 +85,18 @@ def test_ansible_s3_settings_ephemeral(self): s3_bucket_name='test-s3-bucket-name', use_ephemeral_databases=True, ) - ephemeral_settings = 'EDXAPP_IMPORT_EXPORT_BUCKET: !!null\n' + ephemeral_settings = 'EDXAPP_IMPORT_EXPORT_BUCKET: ""\n' self.assertEqual(instance.get_storage_settings(), ephemeral_settings) def test_import_export_bucket_setting_ephemeral(self): """ - Test that get_storage_settings() sets EDXAPP_IMPORT_EXPORT_BUCKET to null when in ephemeral mode + Test that get_storage_settings() sets EDXAPP_IMPORT_EXPORT_BUCKET to an empty string + when in ephemeral mode """ instance = OpenEdXInstanceFactory( use_ephemeral_databases=True, ) - ephemeral_settings = 'EDXAPP_IMPORT_EXPORT_BUCKET: !!null\n' + ephemeral_settings = 'EDXAPP_IMPORT_EXPORT_BUCKET: ""\n' self.assertEqual(instance.get_storage_settings(), ephemeral_settings) From ea696bb0cc3829e951e2a67b4c176812fd1ea8da Mon Sep 17 00:00:00 2001 From: Douglas Cerna Date: Wed, 5 Jul 2017 22:44:13 -0600 Subject: [PATCH 3/3] Fixed appserver test --- instance/tests/models/test_openedx_instance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instance/tests/models/test_openedx_instance.py b/instance/tests/models/test_openedx_instance.py index 9c39420d2..0fea7e22e 100644 --- a/instance/tests/models/test_openedx_instance.py +++ b/instance/tests/models/test_openedx_instance.py @@ -242,7 +242,7 @@ def test_spawn_appserver(self, mocks, mock_provision): getattr(appserver, field_name), ) self.assertEqual(appserver.configuration_database_settings, "") - ephemeral_settings = 'EDXAPP_IMPORT_EXPORT_BUCKET: !!null\n' + ephemeral_settings = 'EDXAPP_IMPORT_EXPORT_BUCKET: ""\n' self.assertEqual(appserver.configuration_storage_settings, ephemeral_settings) configuration_vars = yaml.load(appserver.configuration_settings) self.assertEqual(configuration_vars['COMMON_HOSTNAME'], instance.domain)