本文整理汇总了Python中instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory.spawn_appserver方法的典型用法代码示例。如果您正苦于以下问题:Python OpenEdXInstanceFactory.spawn_appserver方法的具体用法?Python OpenEdXInstanceFactory.spawn_appserver怎么用?Python OpenEdXInstanceFactory.spawn_appserver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory
的用法示例。
在下文中一共展示了OpenEdXInstanceFactory.spawn_appserver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delete_instance
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import spawn_appserver [as 别名]
def test_delete_instance(self, mocks, delete_by_ref, *mock_methods):
"""
Test that an instance can be deleted directly or by its InstanceReference.
"""
instance = OpenEdXInstanceFactory(sub_domain='test.deletion', use_ephemeral_databases=True)
instance_ref = instance.ref
appserver = OpenEdXAppServer.objects.get(pk=instance.spawn_appserver())
for method in mock_methods:
self.assertEqual(
method.call_count, 0,
'{} should not have been called'.format(method._mock_name)
)
# Now delete the instance, either using InstanceReference or the OpenEdXInstance class:
if delete_by_ref:
instance_ref.delete()
else:
instance.delete()
for method in mock_methods:
self.assertEqual(
method.call_count, 1,
'{} should have been called exactly once'.format(method._mock_name)
)
with self.assertRaises(OpenEdXInstance.DoesNotExist):
OpenEdXInstance.objects.get(pk=instance.pk)
with self.assertRaises(InstanceReference.DoesNotExist):
instance_ref.refresh_from_db()
with self.assertRaises(OpenEdXAppServer.DoesNotExist):
appserver.refresh_from_db()
示例2: test_spawn_appserver_detailed
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import spawn_appserver [as 别名]
def test_spawn_appserver_detailed(self, mocks):
"""
Test spawning an AppServer in more detail; this is partially an integration test
Unlike test_spawn_appserver(), this test does not mock the .provision() method, so the
AppServer will go through the motions of provisioning and end up with the appropriate
status.
Note that OpenEdXInstance does not include auto-retry support or auto-activation upon
success; those behaviors are implemented at the task level in tasks.py and tested in
test_tasks.py
"""
mocks.mock_create_server.side_effect = [Mock(id='test-run-provisioning-server'), None]
mocks.os_server_manager.add_fixture('test-run-provisioning-server', 'openstack/api_server_2_active.json')
instance = OpenEdXInstanceFactory(
sub_domain='test.spawn',
use_ephemeral_databases=True,
)
self.assertEqual(instance.appserver_set.count(), 0)
self.assertIsNone(instance.active_appserver)
appserver_id = instance.spawn_appserver()
self.assertIsNotNone(appserver_id)
self.assertEqual(instance.appserver_set.count(), 1)
self.assertIsNone(instance.active_appserver)
appserver = instance.appserver_set.get(pk=appserver_id)
self.assertEqual(appserver.status, AppServerStatus.Running)
self.assertEqual(appserver.server.status, Server.Status.Ready)
示例3: test_get_load_balancer_configuration
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import spawn_appserver [as 别名]
def test_get_load_balancer_configuration(self, mocks):
"""
Test that the load balancer configuration gets generated correctly.
"""
instance = OpenEdXInstanceFactory(sub_domain='test.load_balancer', use_ephemeral_databases=True)
domain_names = [
"test.load_balancer.example.com",
"preview-test.load_balancer.example.com",
"studio-test.load_balancer.example.com",
]
# Test configuration for preliminary page
backend_map, config = instance.get_load_balancer_configuration()
self._check_load_balancer_configuration(
backend_map, config, domain_names, settings.PRELIMINARY_PAGE_SERVER_IP
)
# Test configuration for active appserver
appserver_id = instance.spawn_appserver()
instance.set_appserver_active(appserver_id)
backend_map, config = instance.get_load_balancer_configuration()
self._check_load_balancer_configuration(
backend_map, config, domain_names, instance.active_appserver.server.public_ip
)
# Test configuration in case an active appserver doesn't have a public IP address anymore.
# This might happen if the OpenStack server dies or gets modified from the outside, but it
# is not expected to happen under normal circumstances. We deconfigure the backend and log
# an error in this case.
with patch('instance.openstack.get_server_public_address', return_value=None), \
self.assertLogs("instance.models.instance", "ERROR"):
self.assertEqual(instance.get_load_balancer_configuration(), ([], []))
示例4: test_set_appserver_active
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import spawn_appserver [as 别名]
def test_set_appserver_active(self, mocks, mock_enable_monitoring):
"""
Check that monitoring is enabled when an appserver is activated.
"""
instance = OpenEdXInstanceFactory()
appserver_id = instance.spawn_appserver()
instance.set_appserver_active(appserver_id)
self.assertEqual(mock_enable_monitoring.call_count, 1)
示例5: test_do_not_create_insecure_secret_keys
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import spawn_appserver [as 别名]
def test_do_not_create_insecure_secret_keys(self, mocks):
"""
Test that if we have a brand-new instance with no appservers, we refuse to create insecure
keys for those appservers if we don't have a secure secret key for the instance.
"""
instance = OpenEdXInstanceFactory()
instance.secret_key_b64encoded = ''
instance.save()
expected_error_string = re.escape(
'Attempted to create secret key for instance {}, but no master key present.'.format(instance)
)
# Six provides a compatibility method for assertRaisesRegex, since the method
# is named differently between Py2k and Py3k.
with six.assertRaisesRegex(self, ValueError, expected_error_string):
instance.spawn_appserver()
示例6: test_spawn_appserver_names
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import spawn_appserver [as 别名]
def test_spawn_appserver_names(self, mocks, mock_provision):
"""
Run spawn_appserver() sequence multiple times and check names of resulting app servers
"""
instance = OpenEdXInstanceFactory(sub_domain='test.spawn_names', use_ephemeral_databases=True)
appserver_id = instance.spawn_appserver()
appserver = instance.appserver_set.get(pk=appserver_id)
self.assertEqual(appserver.name, "AppServer 1")
appserver_id = instance.spawn_appserver()
appserver = instance.appserver_set.get(pk=appserver_id)
self.assertEqual(appserver.name, "AppServer 2")
appserver_id = instance.spawn_appserver()
appserver = instance.appserver_set.get(pk=appserver_id)
self.assertEqual(appserver.name, "AppServer 3")
示例7: test_forum_api_key
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import spawn_appserver [as 别名]
def test_forum_api_key(self, mocks, mock_provision):
"""
Ensure the FORUM_API_KEY matches EDXAPP_COMMENTS_SERVICE_KEY
"""
instance = OpenEdXInstanceFactory(sub_domain='test.forum_api_key', use_ephemeral_databases=True)
appserver_id = instance.spawn_appserver()
appserver = instance.appserver_set.get(pk=appserver_id)
configuration_vars = yaml.load(appserver.configuration_settings)
api_key = configuration_vars['EDXAPP_COMMENTS_SERVICE_KEY']
self.assertIsNot(api_key, '')
self.assertIsNotNone(api_key)
self.assertEqual(configuration_vars['FORUM_API_KEY'], api_key)
示例8: test_spawn_appserver_with_lms_users
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import spawn_appserver [as 别名]
def test_spawn_appserver_with_lms_users(self, mocks, mock_provision):
"""
Provision an AppServer with a user added to lms_users.
"""
instance = OpenEdXInstanceFactory(sub_domain='test.spawn', use_ephemeral_databases=True)
user = get_user_model().objects.create_user(username='test', email='[email protected]')
instance.lms_users.add(user)
appserver_id = instance.spawn_appserver()
appserver = instance.appserver_set.get(pk=appserver_id)
self.assertEqual(appserver.lms_users.count(), 1)
self.assertEqual(appserver.lms_users.get(), user)
self.assertTrue(appserver.lms_user_settings)
示例9: test_newrelic_configuration
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import spawn_appserver [as 别名]
def test_newrelic_configuration(self, mocks, mock_provision):
"""
Check that newrelic ansible vars are set correctly
"""
instance = OpenEdXInstanceFactory(sub_domain='test.newrelic', use_ephemeral_databases=True)
appserver_id = instance.spawn_appserver()
appserver = instance.appserver_set.get(pk=appserver_id)
configuration_vars = yaml.load(appserver.configuration_settings)
self.assertIs(configuration_vars['COMMON_ENABLE_NEWRELIC'], True)
self.assertIs(configuration_vars['COMMON_ENABLE_NEWRELIC_APP'], True)
self.assertEqual(configuration_vars['COMMON_ENVIRONMENT'], 'opencraft')
self.assertEqual(configuration_vars['COMMON_DEPLOYMENT'], instance.internal_lms_domain)
self.assertEqual(configuration_vars['NEWRELIC_LICENSE_KEY'], 'newrelic-key')
示例10: test_reconfigure_load_balancer
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import spawn_appserver [as 别名]
def test_reconfigure_load_balancer(self, mock_run_playbook):
"""
Test that reconfigure_load_balancer reconfigures the load balancer and logs to the instance.
"""
instance = OpenEdXInstanceFactory(sub_domain='test.load_balancer')
appserver_id = instance.spawn_appserver()
instance.set_appserver_active(appserver_id)
with self.assertLogs("instance.models.instance") as logs:
instance.reconfigure_load_balancer()
annotation = instance.get_log_message_annotation()
for log_line in logs.output:
self.assertIn(annotation, log_line)
self.assertEqual(len(logs.output), 2)
self.assertIn("Triggering reconfiguration of the load balancing server", logs.output[0])
self.assertIn("New load-balancer configuration", logs.output[1])
示例11: test_set_appserver_active
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import spawn_appserver [as 别名]
def test_set_appserver_active(self, mocks):
"""
Test set_appserver_active()
"""
instance = OpenEdXInstanceFactory(internal_lms_domain='test.activate.opencraft.co.uk',
use_ephemeral_databases=True)
appserver_id = instance.spawn_appserver()
instance.set_appserver_active(appserver_id)
instance.refresh_from_db()
self.assertEqual(instance.active_appserver.pk, appserver_id)
self.assertEqual(mocks.mock_load_balancer_run_playbook.call_count, 2)
instance.set_appserver_inactive()
instance.refresh_from_db()
self.assertIsNone(instance.active_appserver)
self.assertEqual(mocks.mock_load_balancer_run_playbook.call_count, 3)
示例12: test_spawn_appserver_with_external_databases
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import spawn_appserver [as 别名]
def test_spawn_appserver_with_external_databases(self, mocks, mock_provision):
"""
Run spawn_appserver() sequence, with external databases
"""
instance = OpenEdXInstanceFactory(sub_domain='test.persistent', use_ephemeral_databases=False)
appserver_id = instance.spawn_appserver()
self.assertEqual(mocks.mock_provision_mysql.call_count, 1)
self.assertEqual(mocks.mock_provision_mongo.call_count, 1)
self.assertEqual(mocks.mock_provision_swift.call_count, 1)
appserver = instance.appserver_set.get(pk=appserver_id)
ansible_vars = yaml.load(appserver.configuration_settings)
for setting in ('EDXAPP_MYSQL_USER', 'EDXAPP_MONGO_PASSWORD',
'EDXAPP_MONGO_USER', 'EDXAPP_MONGO_PASSWORD',
'EDXAPP_SWIFT_USERNAME', 'EDXAPP_SWIFT_KEY'):
self.assertTrue(ansible_vars[setting])
示例13: test_spawn_appserver_failed
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import spawn_appserver [as 别名]
def test_spawn_appserver_failed(self, mocks):
"""
Test what happens when unable to completely spawn an AppServer.
"""
mocks.mock_run_ansible_playbooks.return_value = (['log: provisioning failed'], 1)
mocks.mock_create_server.side_effect = [Mock(id='test-run-provisioning-server'), None]
mocks.os_server_manager.add_fixture('test-run-provisioning-server', 'openstack/api_server_2_active.json')
instance = OpenEdXInstanceFactory(sub_domain='test.spawn', use_ephemeral_databases=True)
self.assertEqual(instance.appserver_set.count(), 0)
self.assertIsNone(instance.active_appserver)
result = instance.spawn_appserver()
self.assertIsNone(result)
self.assertIsNone(instance.active_appserver)
# however, an AppServer will still have been created:
self.assertEqual(instance.appserver_set.count(), 1)
appserver = instance.appserver_set.last()
self.assertEqual(appserver.status, AppServerStatus.ConfigurationFailed)
示例14: test_spawn_appserver_with_external_domains
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import spawn_appserver [as 别名]
def test_spawn_appserver_with_external_domains(self, mocks, mock_provision):
"""
Test that relevant configuration variables use external domains when provisioning a new app server.
"""
instance = OpenEdXInstanceFactory(
sub_domain='test.spawn',
use_ephemeral_databases=True,
external_lms_domain='lms.external.com',
external_lms_preview_domain='lmspreview.external.com',
external_studio_domain='cms.external.com'
)
appserver_id = instance.spawn_appserver()
appserver = instance.appserver_set.get(pk=appserver_id)
configuration_vars = yaml.load(appserver.configuration_settings)
self.assertEqual(configuration_vars['COMMON_HOSTNAME'], instance.external_lms_domain)
self.assertEqual(configuration_vars['EDXAPP_LMS_BASE'], instance.external_lms_domain)
self.assertEqual(configuration_vars['EDXAPP_PREVIEW_LMS_BASE'], instance.external_lms_preview_domain)
self.assertEqual(configuration_vars['EDXAPP_CMS_BASE'], instance.external_studio_domain)
示例15: test_spawn_appserver
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import spawn_appserver [as 别名]
def test_spawn_appserver(self, mocks, mock_provision):
"""
Run spawn_appserver() sequence
"""
instance = OpenEdXInstanceFactory(sub_domain='test.spawn', use_ephemeral_databases=True)
appserver_id = instance.spawn_appserver()
self.assertEqual(mock_provision.call_count, 1)
self.assertIsNotNone(appserver_id)
self.assertEqual(instance.appserver_set.count(), 1)
self.assertIsNone(instance.active_appserver)
# We are using ephemeral databases:
self.assertEqual(mocks.mock_provision_mysql.call_count, 0)
self.assertEqual(mocks.mock_provision_mongo.call_count, 0)
self.assertEqual(mocks.mock_provision_swift.call_count, 0)
lb_domain = instance.load_balancing_server.domain + '.'
dns_records = gandi.api.client.list_records('example.com')
self.assertCountEqual(dns_records, [
dict(name='test.spawn', type='CNAME', value=lb_domain, ttl=1200),
dict(name='preview-test.spawn', type='CNAME', value=lb_domain, ttl=1200),
dict(name='studio-test.spawn', type='CNAME', value=lb_domain, ttl=1200),
])
appserver = instance.appserver_set.get(pk=appserver_id)
self.assertEqual(appserver.name, "AppServer 1")
self.assertEqual(appserver.instance, instance)
for field_name in OpenEdXAppConfiguration.get_config_fields():
self.assertEqual(
getattr(instance, field_name),
getattr(appserver, field_name),
)
self.assertEqual(appserver.configuration_database_settings, "")
self.assertEqual(appserver.configuration_storage_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)
self.assertEqual(configuration_vars['EDXAPP_CONTACT_EMAIL'], instance.email)