当前位置: 首页>>代码示例>>Python>>正文


Python OpenEdXInstanceFactory.terminate_obsolete_appservers方法代码示例

本文整理汇总了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),
        ])
开发者ID:open-craft,项目名称:opencraft,代码行数:37,代码来源:test_openedx_instance.py

示例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),
        ])
开发者ID:open-craft,项目名称:opencraft,代码行数:48,代码来源:test_openedx_instance.py


注:本文中的instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory.terminate_obsolete_appservers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。