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


Python interface.GroupState类代码示例

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


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

示例1: test_remove_job_success

 def test_remove_job_success(self):
     """
     If the job ID is in the pending list, ``remove_job`` removes it.
     """
     state = GroupState('tid', 'gid', 'name', {}, {'1': {}}, None, {}, True)
     state.remove_job('1')
     self.assertEqual(state.pending, {})
开发者ID:zancas,项目名称:otter,代码行数:7,代码来源:test_interface.py

示例2: test_remove_active_success

 def test_remove_active_success(self):
     """
     If the server ID is in the active list, ``remove_active`` removes it.
     """
     state = GroupState('tid', 'gid', 'name', {'1': {}}, {}, None, {}, True)
     state.remove_active('1')
     self.assertEqual(state.active, {})
开发者ID:zancas,项目名称:otter,代码行数:7,代码来源:test_interface.py

示例3: test_pending_server_delete

    def test_pending_server_delete(self):
        """
        When a pending job is cancelled, it is deleted from the job list. When
        the server finishes building, then ``execute_launch_config`` is called
        to remove the job from pending job list. It then notices that pending
        job_id is not there in job list and calls ``execute_delete_server``
        to delete the server.
        """
        self.supervisor.execute_delete_server.return_value = succeed(None)

        s = GroupState('tenant', 'group', 'name', {}, {'1': {}}, None, {}, False)

        def fake_modify_state(callback, *args, **kwargs):
            callback(self.group, s, *args, **kwargs)

        self.group.modify_state.side_effect = fake_modify_state
        supervisor.execute_launch_config(self.log, '1', self.fake_state,
                                         'launch', self.group, 1)

        s.remove_job('1')
        self.execute_config_deferreds[0].callback({'id': 's1'})

        # first bind is system='otter.job.launch', second is job_id='1'
        self.del_job.assert_called_once_with(
            matches(IsInstance(self.log.__class__)), '1', self.group,
            {'id': 's1'}, self.supervisor)
        self.del_job.return_value.start.assert_called_once_with()
开发者ID:dwcramer,项目名称:otter,代码行数:27,代码来源:test_supervisor.py

示例4: test_add_job_success

 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,代码行数:9,代码来源:test_interface.py

示例5: test_mark_executed_updates_policy_and_group

 def test_mark_executed_updates_policy_and_group(self):
     """
     Marking executed updates the policy touched and group touched to the
     same time.
     """
     t = ['0']
     state = GroupState('tid', 'gid', 'name', {}, {}, 'date', {}, True, now=t.pop)
     state.mark_executed('pid')
     self.assertEqual(state.group_touched, '0')
     self.assertEqual(state.policy_touched, {'pid': '0'})
开发者ID:zancas,项目名称:otter,代码行数:10,代码来源:test_interface.py

示例6: test_add_active_success_preserves_creation_time

 def test_add_active_success_preserves_creation_time(self):
     """
     If the server ID is not in the active list, ``add_active`` adds it along
     with server info, and does not change the server info's creation time.
     """
     state = GroupState('tid', 'gid', 'name', {}, {}, None, {}, True,
                        now=lambda: 'other_now')
     state.add_active('1', {'stuff': 'here', 'created': 'now'})
     self.assertEqual(state.active,
                      {'1': {'stuff': 'here', 'created': 'now'}})
开发者ID:zancas,项目名称:otter,代码行数:10,代码来源:test_interface.py

示例7: test_add_active_success_adds_creation_time

 def test_add_active_success_adds_creation_time(self):
     """
     If the server ID is not in the active list, ``add_active`` adds it along
     with server info, and adds the creation time to server info that
     does not already have it.
     """
     state = GroupState('tid', 'gid', 'name', {}, {}, None, {}, True,
                        now=lambda: 'datetime')
     state.add_active('1', {'stuff': 'here'})
     self.assertEqual(state.active,
                      {'1': {'stuff': 'here', 'created': 'datetime'}})
开发者ID:zancas,项目名称:otter,代码行数:11,代码来源:test_interface.py

示例8: test_get_capacity

 def test_get_capacity(self):
     """
     Getting capacity returns a dictionary with the desired capacity,
     active capacity, and pending capacity
     """
     state = GroupState('tid', 'gid', 'name',
                        {str(i): {} for i in range(5)},
                        {str(i): {} for i in range(6)},
                        'date', {}, True, now='0')
     self.assertEqual(state.get_capacity(), {
         'desired_capacity': 11,
         'pending_capacity': 6,
         'current_capacity': 5
     })
开发者ID:zancas,项目名称:otter,代码行数:14,代码来源:test_interface.py

示例9: setUp

    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'}}}
开发者ID:stanzikratel,项目名称:otter,代码行数:25,代码来源:test_supervisor.py

示例10: test_job_completion_success_job_deleted_audit_logged

    def test_job_completion_success_job_deleted_audit_logged(self):
        """
        If the job succeeded, but the job ID is no longer in pending, it is
        audit logged as a "server.deletable" event.
        """
        self.state = GroupState(
            "tenant", "group", "name", {}, {}, None, {}, False, ScalingGroupStatus.ACTIVE, desired=0
        )
        self.job.start(self.mock_launch)
        self.completion_deferred.callback({"id": "yay"})

        self.successResultOf(self.completion_deferred)

        self.log.msg.assert_called_once_with(
            ("A pending server that is no longer needed is now active, " "and hence deletable.  Deleting said server."),
            event_type="server.deletable",
            server_id="yay",
            job_id=self.job_id,
            audit_log=True,
            system="otter.job.launch",
            image_ref="imageID",
            flavor_ref="1",
            current_active=0,
            current_pending=0,
            current_desired=0,
        )
开发者ID:pratikmallya,项目名称:otter,代码行数:26,代码来源:test_supervisor.py

示例11: setUp

 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)
开发者ID:dwcramer,项目名称:otter,代码行数:12,代码来源:test_supervisor.py

示例12: setUp

 def setUp(self):
     """
     Fake supervisor, group and state
     """
     self.tid = 'trans_id'
     self.log = mock_log()
     self.state = GroupState('tid', 'gid', 'g', {'s0': {'id': 's0'}}, {},
                             None, None, None, desired=1)
     self.group = mock_group(self.state)
     self.gen_jobid = patch(self, 'otter.supervisor.generate_job_id', return_value='jid')
     self.supervisor = FakeSupervisor()
     set_supervisor(self.supervisor)
     self.addCleanup(set_supervisor, None)
开发者ID:zancas,项目名称:otter,代码行数:13,代码来源:test_supervisor.py

示例13: setUp

    def setUp(self):
        """
        Fake supervisor, group and state
        """
        self.tid = "trans_id"
        self.log = mock_log()
        self.state = GroupState(
            "tid", "gid", "g", {"s0": {"id": "s0"}}, {}, None, None, None, ScalingGroupStatus.ACTIVE, desired=1
        )
        self.group = mock_group(self.state)
        self.gen_jobid = patch(self, "otter.supervisor.generate_job_id", return_value="jid")
        self.supervisor = FakeSupervisor()
        set_supervisor(self.supervisor)
        self.addCleanup(set_supervisor, None)

        self.group.view_config.return_value = succeed({"minEntities": 0})
        self.group.view_launch_config.return_value = succeed("launch")
开发者ID:pratikmallya,项目名称:otter,代码行数:17,代码来源:test_supervisor.py

示例14: PrivateJobHelperTestCase

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,代码行数:101,代码来源:test_supervisor.py

示例15: RemoveServerTests

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.state = GroupState(
            "tid", "gid", "g", {"s0": {"id": "s0"}}, {}, None, None, None, ScalingGroupStatus.ACTIVE, desired=1
        )
        self.group = mock_group(self.state)
        self.gen_jobid = patch(self, "otter.supervisor.generate_job_id", return_value="jid")
        self.supervisor = FakeSupervisor()
        set_supervisor(self.supervisor)
        self.addCleanup(set_supervisor, None)

        self.group.view_config.return_value = succeed({"minEntities": 0})
        self.group.view_launch_config.return_value = succeed("launch")

    def _remove_server(self, replace=True, purge=True, server_id="s0"):
        """
        Try to remove a server from the group.
        """
        d = remove_server_from_group(self.log, self.tid, server_id, replace, purge, self.group, self.state)
        return d

    def _assert_server_in_group_state(self, state):
        """
        Assert that the server is still in the group state.
        """
        self.assertEqual(state.active, {"s0": {"id": "s0"}})

    def _assert_server_not_in_group_state(self, state):
        """
        Assert that the server is not in the group state.
        """
        self.assertNotIn("s0", state.active)

    def _assert_delete_scheduled(self):
        """
        Assert that the server was scheduled for deletion.
        """
        self.assertEqual(
            self.supervisor.del_calls[-1],
            (matches(IsBoundWith(server_id="s0", system="otter.job.delete")), self.tid, self.group, {"id": "s0"}),
        )

    def _assert_delete_not_scheduled(self):
        """
        Assert that the server was scheduled for deletion.
        """
        self.assertEqual(self.supervisor.del_calls, [])

    def _assert_create_scheduled(self, state):
        """
        Assert that a new server is being created. Specifically, checks
        that the id is now pending, and that the supervisor has a
        create server call.
        """
        self.assertIn("jid", state.pending)
        self.assertEqual(
            self.supervisor.exec_calls[-1],
            (
                matches(IsBoundWith(image_ref=mock.ANY, flavor_ref=mock.ANY, system="otter.job.launch", job_id="jid")),
                self.tid,
                self.group,
                "launch",
            ),
        )

    def _assert_create_not_scheduled(self, state):
        """
        Assert that a new server is not being created. Specifically,
        checks that the id does not exist in pending, and no creation
        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):
        """
#.........这里部分代码省略.........
开发者ID:pratikmallya,项目名称:otter,代码行数:101,代码来源:test_supervisor.py


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