本文整理汇总了Python中instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory.terminate_obsolete_appservers方法的典型用法代码示例。如果您正苦于以下问题:Python OpenEdXInstanceFactory.terminate_obsolete_appservers方法的具体用法?Python OpenEdXInstanceFactory.terminate_obsolete_appservers怎么用?Python OpenEdXInstanceFactory.terminate_obsolete_appservers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory
的用法示例。
在下文中一共展示了OpenEdXInstanceFactory.terminate_obsolete_appservers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_terminate_obsolete_appservers_no_active
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import terminate_obsolete_appservers [as 别名]
def test_terminate_obsolete_appservers_no_active(self):
"""
Test that `terminate_obsolete_appservers` does not terminate any app servers
if an instance does not have an active app server.
"""
instance = OpenEdXInstanceFactory()
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))
appserver = self._create_running_appserver(instance, reference_date)
appserver_failed = self._create_failed_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))
# Terminate app servers
instance.terminate_obsolete_appservers()
# Check status of app servers (should be unchanged)
self._assert_status([
(obsolete_appserver, AppServerStatus.Running, ServerStatus.Pending),
(obsolete_appserver_failed, AppServerStatus.ConfigurationFailed, ServerStatus.Pending),
(recent_appserver, AppServerStatus.Running, ServerStatus.Pending),
(recent_appserver_failed, AppServerStatus.ConfigurationFailed, ServerStatus.Pending),
(appserver, AppServerStatus.Running, ServerStatus.Pending),
(appserver_failed, AppServerStatus.ConfigurationFailed, ServerStatus.Pending),
(newer_appserver, AppServerStatus.Running, ServerStatus.Pending),
(newer_appserver_failed, AppServerStatus.ConfigurationFailed, ServerStatus.Pending),
])
示例2: test_terminate_obsolete_appservers
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import terminate_obsolete_appservers [as 别名]
def test_terminate_obsolete_appservers(self, days):
"""
Test that `terminate_obsolete_appservers` correctly identifies and terminates app servers
that were created (more than) `days` before the currently-active app server of the parent instance.
"""
instance = OpenEdXInstanceFactory()
reference_date = timezone.now()
# Create app servers
obsolete_appserver = self._create_running_appserver(instance, reference_date - timedelta(days=days + 1))
obsolete_appserver_failed = self._create_failed_appserver(instance, reference_date - timedelta(days=days + 1))
recent_appserver = self._create_running_appserver(instance, reference_date - timedelta(days=days - 1))
recent_appserver_failed = self._create_failed_appserver(instance, reference_date - timedelta(days=days - 1))
active_appserver = self._create_running_appserver(instance, reference_date)
newer_appserver = self._create_running_appserver(instance, reference_date + timedelta(days=days))
newer_appserver_failed = self._create_failed_appserver(instance, reference_date + timedelta(days=days))
# Set single app server active
instance.active_appserver = active_appserver
instance.save()
# Terminate app servers
instance.terminate_obsolete_appservers(days=days)
# Check status of running app servers
self._assert_status([
(obsolete_appserver, AppServerStatus.Terminated, ServerStatus.Terminated),
(recent_appserver, AppServerStatus.Running, ServerStatus.Pending),
(active_appserver, AppServerStatus.Running, ServerStatus.Pending),
(newer_appserver, AppServerStatus.Running, ServerStatus.Pending),
])
# 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 `terminate_obsolete_appservers` 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.Pending),
(newer_appserver_failed, AppServerStatus.ConfigurationFailed, ServerStatus.Pending),
])