本文整理汇总了Python中instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory.shut_down方法的典型用法代码示例。如果您正苦于以下问题:Python OpenEdXInstanceFactory.shut_down方法的具体用法?Python OpenEdXInstanceFactory.shut_down怎么用?Python OpenEdXInstanceFactory.shut_down使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory
的用法示例。
在下文中一共展示了OpenEdXInstanceFactory.shut_down方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_shut_down
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import shut_down [as 别名]
def test_shut_down(self, mock_reconfigure, mock_disable_monitoring, mock_remove_dns_records):
"""
Test that `shut_down` method terminates all app servers belonging to an instance
and disables monitoring.
"""
instance = OpenEdXInstanceFactory()
instance.load_balancing_server = LoadBalancingServer.objects.select_random()
instance.save()
reference_date = timezone.now()
# Create app servers
obsolete_appserver = self._create_running_appserver(instance, reference_date - timedelta(days=5))
obsolete_appserver_failed = self._create_failed_appserver(instance, reference_date - timedelta(days=5))
recent_appserver = self._create_running_appserver(instance, reference_date - timedelta(days=1))
recent_appserver_failed = self._create_failed_appserver(instance, reference_date - timedelta(days=1))
active_appserver = self._create_running_appserver(instance, reference_date)
newer_appserver = self._create_running_appserver(instance, reference_date + timedelta(days=3))
newer_appserver_failed = self._create_failed_appserver(instance, reference_date + timedelta(days=3))
# Set single app server active
instance.active_appserver = active_appserver
instance.save()
active_appserver.instance.refresh_from_db()
self.assertEqual(mock_reconfigure.call_count, 0)
self.assertEqual(mock_disable_monitoring.call_count, 0)
self.assertEqual(mock_remove_dns_records.call_count, 0)
# Shut down instance
instance.shut_down()
self.assertEqual(mock_reconfigure.call_count, 1)
self.assertEqual(mock_disable_monitoring.call_count, 1)
self.assertEqual(mock_remove_dns_records.call_count, 1)
# Check status of running app servers
self._assert_status([
(obsolete_appserver, AppServerStatus.Terminated, ServerStatus.Terminated),
(recent_appserver, AppServerStatus.Terminated, ServerStatus.Terminated),
(active_appserver, AppServerStatus.Terminated, ServerStatus.Terminated),
(newer_appserver, AppServerStatus.Terminated, ServerStatus.Terminated),
])
# Check status of failed app servers:
# AppServerStatus.Terminated is reserved for instances that were running successfully at some point,
# so app servers with AppServerStatus.ConfigurationFailed will still have that status
# after `shut_down` calls `terminate_vm` on them.
# However, the VM (OpenStackServer) that an app server is associated with
# *should* have ServerStatus.Terminated if the app server was old enough to be terminated.
self._assert_status([
(obsolete_appserver_failed, AppServerStatus.ConfigurationFailed, ServerStatus.Terminated),
(recent_appserver_failed, AppServerStatus.ConfigurationFailed, ServerStatus.Terminated),
(newer_appserver_failed, AppServerStatus.ConfigurationFailed, ServerStatus.Terminated),
])
示例2: test_shut_down_no_active_appserver
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import shut_down [as 别名]
def test_shut_down_no_active_appserver(self, mock_reconfigure, mock_disable_monitoring, mock_remove_dns_records):
"""
Test that the shut_down method works correctly if no appserver is active.
"""
instance = OpenEdXInstanceFactory()
instance.load_balancing_server = LoadBalancingServer.objects.select_random()
instance.save()
appserver = self._create_running_appserver(instance)
instance.shut_down()
self.assertEqual(mock_reconfigure.call_count, 1)
self.assertEqual(mock_disable_monitoring.call_count, 0)
self.assertEqual(mock_remove_dns_records.call_count, 1)
self._assert_status([
(appserver, AppServerStatus.Terminated, ServerStatus.Terminated)
])
示例3: test_shut_down_monitors_not_found
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import shut_down [as 别名]
def test_shut_down_monitors_not_found(self, *mock_methods):
"""
Test that instance `is_shut_down` after calling `shut_down` on it,
even if monitors associated with it no longer exist.
"""
monitor_ids = [str(uuid4()) for i in range(3)]
instance = OpenEdXInstanceFactory()
appserver = self._create_running_appserver(instance)
instance.active_appserver = appserver
instance.save()
appserver.instance.refresh_from_db()
for monitor_id in monitor_ids:
instance.new_relic_availability_monitors.create(pk=monitor_id)
responses.add(
responses.DELETE,
'{0}/monitors/{1}'.format(newrelic.SYNTHETICS_API_URL, monitor_id),
status=requests.codes.not_found # pylint: disable=no-member
)
# Preconditions
self.assertEqual(instance.new_relic_availability_monitors.count(), 3)
self.assertFalse(instance.is_shut_down)
# Shut down instance
instance.shut_down()
# Instance should
# - no longer have any monitors associated with it
# - no longer have any running app servers
# - be considered "shut down"
self.assertEqual(instance.new_relic_availability_monitors.count(), 0)
self._assert_status([
(appserver, AppServerStatus.Terminated, ServerStatus.Terminated),
])
self.assertTrue(instance.is_shut_down)