本文整理汇总了Python中app.master.cluster_master.ClusterMaster类的典型用法代码示例。如果您正苦于以下问题:Python ClusterMaster类的具体用法?Python ClusterMaster怎么用?Python ClusterMaster使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClusterMaster类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_connect_slave_adds_new_slave_if_slave_never_connected_before
def test_connect_slave_adds_new_slave_if_slave_never_connected_before(self):
master = ClusterMaster()
master.connect_slave('never-before-seen.turtles.gov', 10)
self.assertEqual(1, len(master.all_slaves_by_id()), 'Exactly one slave should be registered with the master.')
self.assertIsNotNone(master.get_slave(slave_id=None, slave_url='never-before-seen.turtles.gov'),
'Registered slave does not have the expected url.')
示例2: test_updating_slave_to_nonexistent_state_should_raise_bad_request_error
def test_updating_slave_to_nonexistent_state_should_raise_bad_request_error(self):
master = ClusterMaster()
slave_registry = SlaveRegistry.singleton()
slave_url = 'raphael.turtles.gov'
master.connect_slave(slave_url, 10)
slave = slave_registry.get_slave(slave_url=slave_url)
with self.assertRaises(BadRequestError):
master.handle_slave_state_update(slave, 'NONEXISTENT_STATE')
示例3: test_update_slave_last_heartbeat_time_calls_correspondig_slave_method
def test_update_slave_last_heartbeat_time_calls_correspondig_slave_method(self, slave_alive, method_call_count):
master = ClusterMaster()
mock_slave = self.patch('app.master.cluster_master.Slave').return_value
mock_slave.is_alive.return_value = slave_alive
master.update_slave_last_heartbeat_time(mock_slave)
self.assertEqual(mock_slave.update_last_heartbeat_time.call_count, method_call_count,
'last heartbeat time is updated for the target slave')
示例4: test_updating_slave_to_disconnected_state_should_mark_slave_as_dead
def test_updating_slave_to_disconnected_state_should_mark_slave_as_dead(self):
master = ClusterMaster()
slave_registry = SlaveRegistry.singleton()
slave_url = 'raphael.turtles.gov'
master.connect_slave(slave_url, num_executors=10)
slave = slave_registry.get_slave(slave_url=slave_url)
self.assertTrue(slave.is_alive())
master.handle_slave_state_update(slave, SlaveState.DISCONNECTED)
self.assertFalse(slave.is_alive())
示例5: test_updating_slave_to_shutdown_should_call_slave_set_shutdown_mode
def test_updating_slave_to_shutdown_should_call_slave_set_shutdown_mode(self):
master = ClusterMaster()
slave_registry = SlaveRegistry.singleton()
slave_url = 'raphael.turtles.gov'
master.connect_slave(slave_url, 10)
slave = slave_registry.get_slave(slave_url=slave_url)
slave.set_shutdown_mode = Mock()
master.handle_slave_state_update(slave, SlaveState.SHUTDOWN)
slave.set_shutdown_mode.assert_called_once_with()
示例6: test_updating_slave_to_disconnected_state_should_reset_slave_current_build_id
def test_updating_slave_to_disconnected_state_should_reset_slave_current_build_id(self):
master = ClusterMaster()
slave_registry = SlaveRegistry.singleton()
slave_url = 'raphael.turtles.gov'
master.connect_slave(slave_url, num_executors=10)
slave = slave_registry.get_slave(slave_url=slave_url)
slave.current_build_id = 4
master.handle_slave_state_update(slave, SlaveState.DISCONNECTED)
self.assertIsNone(slave.current_build_id)
示例7: test_get_slave_raises_exception_on_slave_not_found
def test_get_slave_raises_exception_on_slave_not_found(self, get_slave_kwargs):
master = ClusterMaster()
master.connect_slave('raphael.turtles.gov', 10)
master.connect_slave('leonardo.turtles.gov', 10)
master.connect_slave('donatello.turtles.gov', 10)
with self.assertRaises(ItemNotFoundError):
master.get_slave(**get_slave_kwargs)
示例8: test_update_build_with_bad_build_id_fails
def test_update_build_with_bad_build_id_fails(self):
build_id = 1
invalid_build_id = 2
update_params = {'key': 'value'}
master = ClusterMaster()
build = Mock()
master._all_builds_by_id[build_id] = build
build.validate_update_params = Mock(return_value=(True, update_params))
build.update_state = Mock()
with self.assertRaises(ItemNotFoundError):
master.handle_request_to_update_build(invalid_build_id, update_params)
示例9: test_connect_slave_with_existing_dead_slave_removes_old_slave_entry_from_registry
def test_connect_slave_with_existing_dead_slave_removes_old_slave_entry_from_registry(self):
master = ClusterMaster()
slave_registry = SlaveRegistry.singleton()
master.connect_slave('existing-slave.turtles.gov', 10)
old_existing_slave = slave_registry.get_slave(slave_id=None, slave_url='existing-slave.turtles.gov')
old_existing_slave_id = old_existing_slave.id
connect_response = master.connect_slave('existing-slave.turtles.gov', 10)
with self.assertRaises(ItemNotFoundError):
slave_registry.get_slave(slave_id=old_existing_slave_id)
示例10: test_connect_slave_with_existing_slave_running_build_cancels_build
def test_connect_slave_with_existing_slave_running_build_cancels_build(self):
master = ClusterMaster()
slave_registry = SlaveRegistry.singleton()
master.connect_slave('running-slave.turtles.gov', 10)
build_mock = MagicMock(spec_set=Build)
BuildStore._all_builds_by_id[1] = build_mock
existing_slave = slave_registry.get_slave(slave_id=None, slave_url='running-slave.turtles.gov')
existing_slave.current_build_id = 1
master.connect_slave('running-slave.turtles.gov', 10)
self.assertTrue(build_mock.cancel.called, 'The build was not cancelled.')
示例11: test_exception_raised_during_complete_subjob_does_not_prevent_slave_teardown
def test_exception_raised_during_complete_subjob_does_not_prevent_slave_teardown(self):
slave_url = 'raphael.turtles.gov'
mock_build = Mock(spec_set=Build, build_id=lambda: 777, is_finished=False)
mock_build.complete_subjob.side_effect = [RuntimeError('Write failed')]
master = ClusterMaster()
master._all_builds_by_id[mock_build.build_id()] = mock_build
master._all_slaves_by_url[slave_url] = Mock()
with self.assertRaisesRegex(RuntimeError, 'Write failed'):
master.handle_result_reported_from_slave(slave_url, mock_build.build_id(), subjob_id=888)
self.assertEqual(mock_build.execute_next_subjob_or_teardown_slave.call_count, 1)
示例12: test_update_build_with_valid_params_succeeds
def test_update_build_with_valid_params_succeeds(self):
build_id = 1
update_params = {'key': 'value'}
master = ClusterMaster()
build = Mock()
master._all_builds_by_id[build_id] = build
build.validate_update_params = Mock(return_value=(True, update_params))
build.update_state = Mock()
success, response = master.handle_request_to_update_build(build_id, update_params)
build.update_state.assert_called_once_with(update_params)
self.assertTrue(success, "Update build should return success")
self.assertEqual(response, {}, "Response should be empty")
示例13: test_connect_slave_with_existing_dead_slave_marks_it_as_alive
def test_connect_slave_with_existing_dead_slave_marks_it_as_alive(self):
master = ClusterMaster()
master.connect_slave('existing-slave.turtles.gov', 10)
existing_slave = master.get_slave(slave_id=None, slave_url='existing-slave.turtles.gov')
existing_slave.set_is_alive(False)
existing_slave_id = existing_slave.id
connect_response = master.connect_slave('existing-slave.turtles.gov', 10)
self.assertEqual(str(existing_slave_id), connect_response['slave_id'],
'The re-connected slave should not have generated a new slave id.')
self.assertTrue(existing_slave.is_alive(use_cached=True),
'The re-connected slave should have been marked as alive once reconnected.')
self.assertEquals(2, self.mock_slave_allocator.add_idle_slave.call_count,
'Expected slave to be added to the idle slaves list.')
示例14: test_add_idle_slave_does_not_mark_build_finished_when_slaves_not_done
def test_add_idle_slave_does_not_mark_build_finished_when_slaves_not_done(self):
master = ClusterMaster()
slave1 = Slave('', 1)
slave2 = Slave('', 1)
slave3 = Slave('', 1)
slave1.current_build_id = 1
slave2.current_build_id = None
slave3.current_build_id = 1
build1 = Build(BuildRequest({}))
master._all_slaves_by_url = {'1': slave1, '2': slave2, '3': slave3}
master._all_builds_by_id = {1: build1}
build1._build_id = 1
build1.finish = MagicMock()
master.add_idle_slave(slave1)
self.assertFalse(build1.finish.called)
示例15: test_get_slave_returns_expected_value_given_valid_arguments
def test_get_slave_returns_expected_value_given_valid_arguments(self):
master = ClusterMaster()
master.connect_slave('raphael.turtles.gov', 10)
master.connect_slave('leonardo.turtles.gov', 10)
master.connect_slave('donatello.turtles.gov', 10)
actual_slave_by_id = master.get_slave(slave_id=2)
actual_slave_by_url = master.get_slave(slave_url='leonardo.turtles.gov')
self.assertEqual(2, actual_slave_by_id.id, 'Retrieved slave should have the same id as requested.')
self.assertEqual('leonardo.turtles.gov', actual_slave_by_url.url,
'Retrieved slave should have the same url as requested.')