Beispiel #1
0
    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'
                },
            })
Beispiel #2
0
    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
                },
            })