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


Python GroupState.add_job方法代码示例

本文整理汇总了Python中otter.models.interface.GroupState.add_job方法的典型用法代码示例。如果您正苦于以下问题:Python GroupState.add_job方法的具体用法?Python GroupState.add_job怎么用?Python GroupState.add_job使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在otter.models.interface.GroupState的用法示例。


在下文中一共展示了GroupState.add_job方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_add_job_success

# 需要导入模块: from otter.models.interface import GroupState [as 别名]
# 或者: from otter.models.interface.GroupState import add_job [as 别名]
 def test_add_job_success(self):
     """
     If the job ID is not in the pending list, ``add_job`` adds it along with
     the creation time.
     """
     state = GroupState('tid', 'gid', 'name', {}, {}, None, {}, True,
                        now=lambda: 'datetime')
     state.add_job('1')
     self.assertEqual(state.pending, {'1': {'created': 'datetime'}})
开发者ID:zancas,项目名称:otter,代码行数:11,代码来源:test_interface.py

示例2: PrivateJobHelperTestCase

# 需要导入模块: from otter.models.interface import GroupState [as 别名]
# 或者: from otter.models.interface.GroupState import add_job [as 别名]
class PrivateJobHelperTestCase(SynchronousTestCase):
    """
    Tests for the private helper class `_Job`
    """

    def setUp(self):
        """
        Mock a fake supervisor, and also a fake log and group.
        """
        self.transaction_id = "transaction_id"
        self.job_id = "job_id"
        patch(self, "otter.supervisor.generate_job_id", return_value=self.job_id)
        self.state = GroupState("tenant", "group", "name", {}, {}, None, {}, False, ScalingGroupStatus.ACTIVE)
        self.group = mock_group(self.state, "tenant", "group")

        self.supervisor = iMock(ISupervisor)
        self.supervisor.deferred_pool = DeferredPool()
        self.completion_deferred = Deferred()
        self.supervisor.execute_config.return_value = self.completion_deferred

        self.log = mock_log()
        self.job = supervisor._Job(self.log, self.transaction_id, self.group, self.supervisor)

        self.del_job = patch(self, "otter.supervisor._DeleteJob")
        self.mock_launch = {"type": "launch_server", "args": {"server": {"imageRef": "imageID", "flavorRef": "1"}}}

    def test_start_binds_invalid_image_ref_to_log(self):
        """
        `start` binds the image ID to a string that says that we were unable
        to find the image id in the logs, if the image ref could not be found
        """
        del self.mock_launch["args"]["server"]["imageRef"]
        self.job.start(self.mock_launch)
        self.assertEqual(
            self.job.log,
            matches(
                IsBoundWith(
                    system="otter.job.launch", image_ref="Unable to pull image ref.", flavor_ref="1", job_id="job_id"
                )
            ),
        )

    def test_start_binds_invalid_flavor_ref_to_log(self):
        """
        `start` binds the flavor ID to a string that says that we were unable
        to find the flavor id in the logs, if the flavor ref could not be found
        """
        del self.mock_launch["args"]["server"]["flavorRef"]
        self.job.start(self.mock_launch)
        self.assertEqual(
            self.job.log,
            matches(
                IsBoundWith(
                    system="otter.job.launch",
                    image_ref="imageID",
                    flavor_ref="Unable to pull flavor ref.",
                    job_id="job_id",
                )
            ),
        )

    def test_start_calls_supervisor(self):
        """
        `start` calls the supervisor's `execute_config` method with
        log bound with imageRef and flavorRef from launch config
        """
        self.job.start(self.mock_launch)
        self.supervisor.execute_config.assert_called_once_with(
            matches(IsBoundWith(system="otter.job.launch", image_ref="imageID", flavor_ref="1", job_id="job_id")),
            self.transaction_id,
            self.group,
            self.mock_launch,
        )

    def test_modify_state_called_on_job_completion_success(self):
        """
        If the job succeeded, and modify_state is called
        """
        self.job.start("launch")
        self.assertEqual(self.group.modify_state.call_count, 0)
        self.completion_deferred.callback({"id": "blob"})
        self.assertEqual(self.group.modify_state.call_count, 1)

    def test_modify_state_called_on_job_completion_failure(self):
        """
        If the job failed, modify_state is called
        """
        self.job.start("launch")
        self.assertEqual(self.group.modify_state.call_count, 0)
        self.completion_deferred.errback(Exception("e"))
        self.assertEqual(self.group.modify_state.call_count, 1)

    def test_job_completion_success_job_marked_as_active(self):
        """
        If the job succeeded, and the job ID is still in pending, it is removed
        and added to active.
        """
        self.state.add_job(self.job_id)
        self.job.start("launch")
        self.completion_deferred.callback({"id": "active"})
#.........这里部分代码省略.........
开发者ID:pratikmallya,项目名称:otter,代码行数:103,代码来源:test_supervisor.py

示例3: RemoveServerTests

# 需要导入模块: from otter.models.interface import GroupState [as 别名]
# 或者: from otter.models.interface.GroupState import add_job [as 别名]

#.........这里部分代码省略.........
        calls were issued.
        """
        self.assertNotIn("jid", state.pending)
        self.assertEqual(self.supervisor.exec_calls, [])

    def _assert_metadata_scrubbing_scheduled(self, expected_server_id="s0"):
        """
        Assert that otter-specific metadata scrubbing was scheduled.
        """
        _, txn_id, tenant_id, server_id = self.supervisor.scrub_calls[-1]
        self.assertEqual(txn_id, self.tid)
        self.assertEqual(tenant_id, "tenant")
        self.assertEqual(server_id, expected_server_id)

    def _assert_metadata_scrubbing_not_scheduled(self):
        """
        Asserts that no metadata scrubbing was scheduled.
        """
        self.assertEqual(len(self.supervisor.scrub_calls), 0)

    def test_server_not_found(self):
        """
        If specific server is not in the group, :class:`ServerNotFoundError`
        is raised.
        """
        self.assertRaises(ServerNotFoundError, self._remove_server, server_id="BOGUS")

        self._assert_server_in_group_state(self.state)
        self._assert_create_not_scheduled(self.state)
        self._assert_delete_not_scheduled()
        self._assert_metadata_scrubbing_not_scheduled()
        self.assertEqual(self.state.desired, 1)

    def test_not_deleted_below_min(self):
        """
        :class:`CannotDeleteServerBelowMinError` is raised if the current
        (active + pending) number of servers is already the minimum.
        """
        self.state.add_job("j1")
        self.group.view_config.return_value = succeed({"minEntities": 2})
        d = self._remove_server(replace=False, purge=True)
        self.failureResultOf(d, CannotDeleteServerBelowMinError)

        self._assert_server_in_group_state(self.state)
        self._assert_delete_not_scheduled()
        self._assert_create_not_scheduled(self.state)
        self._assert_metadata_scrubbing_not_scheduled()
        self.assertEqual(self.state.desired, 1)

    def test_replaced_and_removed(self):
        """
        Server is removed, purged and replaced.
        """
        d = self._remove_server(replace=True, purge=True)
        state = self.successResultOf(d)

        self._assert_server_not_in_group_state(state)
        self._assert_delete_scheduled()
        self._assert_create_scheduled(state)
        self.assertEqual(self.state.desired, 1)

    def test_not_replaced(self):
        """
        Server is removed and purged from Nova, but not replaced. The
        desired is reduced by 1.
        """
        d = self._remove_server(replace=False, purge=True)
        state = self.successResultOf(d)

        self._assert_server_not_in_group_state(state)
        self._assert_delete_scheduled()
        self._assert_create_not_scheduled(state)
        self._assert_metadata_scrubbing_not_scheduled()
        self.assertEqual(state.desired, 0)

    def test_not_replaced_and_not_purged(self):
        """
        The server is removed, but not replaced and not purged.
        """
        d = self._remove_server(replace=False, purge=False)
        state = self.successResultOf(d)

        self._assert_server_not_in_group_state(state)
        self._assert_delete_not_scheduled()
        self._assert_create_not_scheduled(state)
        self._assert_metadata_scrubbing_scheduled()
        self.assertEqual(state.desired, 0)

    def test_replaced_but_not_purged(self):
        """
        The server is removed, replaced, but not purged.
        """
        d = self._remove_server(replace=True, purge=False)
        state = self.successResultOf(d)

        self._assert_server_not_in_group_state(state)
        self._assert_delete_not_scheduled()
        self._assert_create_scheduled(state)
        self._assert_metadata_scrubbing_scheduled()
        self.assertEqual(state.desired, 1)
开发者ID:pratikmallya,项目名称:otter,代码行数:104,代码来源:test_supervisor.py

示例4: RemoveServerTests

# 需要导入模块: from otter.models.interface import GroupState [as 别名]
# 或者: from otter.models.interface.GroupState import add_job [as 别名]
class RemoveServerTests(SynchronousTestCase):
    """
    Tests for :func:`otter.supervisor.remove_server_from_group`
    """

    def setUp(self):
        """
        Fake supervisor, group and state
        """
        self.tid = 'trans_id'
        self.log = mock_log()
        self.group = iMock(IScalingGroup, tenant_id='tenant', uuid='group')
        self.state = GroupState('tid', 'gid', 'g', {'s0': {'id': 's0'}}, {},
                                None, None, None, desired=1)
        self.supervisor = FakeSupervisor()
        set_supervisor(self.supervisor)
        self.addCleanup(set_supervisor, None)

    def test_server_not_found(self):
        """
        If specific server is not in the group `ServerNotFoundError` is raised
        """
        self.assertRaises(
            ServerNotFoundError, remove_server_from_group, self.log,
            self.tid, 's2', True, self.group, self.state)
        # no server launched or deleted
        self.assertEqual(self.supervisor.exec_calls, [])
        self.assertEqual(self.supervisor.del_calls, [])
        # desired & active/pending not changed
        self.assertEqual(self.state.desired, 1)
        self.assertEqual(self.state.active, {'s0': {'id': 's0'}})
        self.assertEqual(self.state.pending, {})

    def _check_removed(self, state):
        self.assertNotIn('s0', state.active)
        self.assertEqual(self.supervisor.del_calls[-1],
                         (matches(IsBoundWith(server_id='s0', system='otter.job.delete')),
                          self.tid, self.group, {'id': 's0'}))

    def test_replaced_and_removed(self):
        """
        Server is removed and replaced by creating new
        """
        self.group.view_launch_config.return_value = succeed('launch')
        d = remove_server_from_group(self.log, self.tid, 's0', True, self.group, self.state)
        state = self.successResultOf(d)
        # server removed?
        self._check_removed(state)
        # new server added?
        self.assertIn(1, state.pending)
        self.assertEqual(self.supervisor.exec_calls[-1],
                         (matches(IsBoundWith(image_ref=mock.ANY, flavor_ref=mock.ANY,
                                              system='otter.job.launch')),
                          self.tid, self.group, 'launch'))
        # desired not changed
        self.assertEqual(self.state.desired, 1)

    def test_not_replaced_removed(self):
        """
        Server is removed, not replaced and desired is reduced by 1
        """
        self.group.view_config.return_value = succeed({'minEntities': 0})
        d = remove_server_from_group(self.log, self.tid, 's0', False, self.group, self.state)
        state = self.successResultOf(d)
        # server removed?
        self._check_removed(state)
        # desired reduced and no server launched?
        self.assertEqual(state.desired, 0)
        self.assertEqual(len(state.pending), 0)
        self.assertEqual(len(self.supervisor.exec_calls), 0)

    def test_not_replaced_below_min(self):
        """
        `CannotDeleteServerBelowMinError` is raised if current (active + pending) == min servers
        """
        self.state.add_job('j1')
        self.group.view_config.return_value = succeed({'minEntities': 2})
        d = remove_server_from_group(self.log, self.tid, 's0', False, self.group, self.state)
        self.failureResultOf(d, CannotDeleteServerBelowMinError)
        # server is not deleted
        self.assertIn('s0', self.state.active)
        self.assertEqual(self.supervisor.del_calls, [])
        # server is not launched
        self.assertEqual(self.state.pending, matches(KeysEqual('j1')))
        self.assertEqual(len(self.supervisor.exec_calls), 0)
        # desired & active not changed
        self.assertEqual(self.state.desired, 1)
        self.assertEqual(self.state.active, {'s0': {'id': 's0'}})
开发者ID:dwcramer,项目名称:otter,代码行数:90,代码来源:test_supervisor.py


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