def test_watch_placement(self): """Test loading placement. """ cell_state = state.CellState() cell_state.running = ['foo.bar#0000000001'] zkclient_mock = _create_zkclient_mock( zlib.compress( json.dumps([ [ 'foo.bar#0000000001', 'baz', 12345.67890, 'baz', 12345.67890 ], [ 'foo.bar#0000000002', 'baz', 12345.67890, 'baz', 12345.67890 ], ['foo.bar#0000000003', None, None, None, None], ]).encode() # compress needs bytes )) state.watch_placement(zkclient_mock, cell_state) self.assertEqual( cell_state.placement, { 'foo.bar#0000000001': { 'expires': 12345.6789, 'host': 'baz' }, 'foo.bar#0000000002': { 'expires': 12345.6789, 'host': 'baz' }, })
def test_watch_placement_yaml(self): """Test loading placement stored as yaml, for backward compatibility. """ cell_state = state.CellState() cell_state.running = ['foo.bar#0000000001'] zkclient_mock = _create_zkclient_mock( yaml.dump([ ['foo.bar#0000000001', 'baz', 12345.67890, 'baz', 12345.67890], ['foo.bar#0000000002', 'baz', 12345.67890, 'baz', 12345.67890], ['foo.bar#0000000003', None, None, None, None], ]).encode()) state.watch_placement(zkclient_mock, cell_state) self.assertEqual( cell_state.placement, { 'foo.bar#0000000001': { 'state': 'running', 'expires': 12345.6789, 'host': 'baz' }, 'foo.bar#0000000002': { 'state': 'scheduled', 'expires': 12345.6789, 'host': 'baz' }, 'foo.bar#0000000003': { 'state': 'pending', 'expires': None, 'host': None }, })
def setUp(self): self.cell_state = state.CellState() self.cell_state.scheduled = set(['foo.bar#0000000001']) self.cell_state.running = set(['foo.bar#0000000001']) self.cell_state.placement = { 'foo.bar#0000000001': { 'expires': 1234567890.1, 'host': 'baz1' } } self.cell_state.finished = { 'foo.bar#0000000002': { 'data': '0.0', 'host': 'baz1', 'when': '123456789.2', 'state': 'finished' }, 'foo.bar#0000000003': { 'data': '255.0', 'host': 'baz1', 'when': '123456789.3', 'state': 'finished' }, 'foo.bar#0000000004': { 'data': '256.11', 'host': 'baz1', 'when': '1234567890.4', 'state': 'finished' }, 'foo.bar#0000000005': { 'data': 'oom', 'host': 'baz2', 'when': '1234567890.5', 'state': 'killed' }, 'foo.bar#0000000006': { 'data': None, 'host': 'baz2', 'when': 1234567890.6, 'state': 'terminated' }, 'foo.bar#0000000007': { 'data': 'TypeError', 'host': 'baz2', 'when': '1234567890.7', 'state': 'aborted' } } # Disable the exit on exception hack for tests self.old_exit_on_unhandled = treadmill.utils.exit_on_unhandled treadmill.utils.exit_on_unhandled = mock.Mock(side_effect=lambda x: x)
def setUp(self): self.cell_state = state.CellState() self.cell_state.placement = { 'foo.bar#0000000001': { 'state': 'running', 'expires': 1234567890.1, 'host': 'baz1' } } self.cell_state.finished = { 'foo.bar#0000000002': { 'data': '0.0', 'host': 'baz1', 'when': '123456789.2', 'state': 'finished' }, 'foo.bar#0000000003': { 'data': '255.0', 'host': 'baz1', 'when': '123456789.3', 'state': 'finished' }, 'foo.bar#0000000004': { 'data': '256.11', 'host': 'baz1', 'when': '1234567890.4', 'state': 'finished' }, 'foo.bar#0000000005': { 'data': 'oom', 'host': 'baz1', 'when': '1234567890.5', 'state': 'killed' }, 'foo.bar#0000000006': { 'data': None, 'host': 'baz1', 'when': 1234567890.6, 'state': 'terminated' }, 'foo.bar#0000000007': { 'data': 'TypeError', 'host': 'baz1', 'when': '1234567890.7', 'state': 'aborted' } }