Beispiel #1
0
def make_readonly_master(run_scheduler=False):
    """Prepare a readonly master."""
    treadmill_sched.DIMENSION_COUNT = 3

    backend = zkbackend.ZkReadonlyBackend(context.GLOBAL.zk.conn)

    # set timezone to master's
    data = backend.get('/')
    if data and 'timezone' in data:
        _LOGGER.debug('Setting timezone to %s', data['timezone'])
        os.environ['TZ'] = data['timezone']
        time.tzset()
    else:
        _LOGGER.warning('Missing timezone info.')

    cell_master = loader.Loader(
        backend,
        context.GLOBAL.cell
    )
    cell_master.load_model()

    if run_scheduler:
        cell_master.cell.schedule()

    return cell_master
Beispiel #2
0
def make_readonly_master(run_scheduler=False):
    """Prepare a readonly master."""
    treadmill_sched.DIMENSION_COUNT = 3

    cell_master = loader.Loader(
        zkbackend.ZkReadonlyBackend(context.GLOBAL.zk.conn),
        context.GLOBAL.cell
    )
    cell_master.load_model()

    if run_scheduler:
        cell_master.cell.schedule()

    return cell_master
Beispiel #3
0
def get_readonly_scheduler():
    """Prepare a readonly master."""
    # C0103(invalid-name): invalid variable name
    # W0603(global-statement): using the global statement
    # pylint: disable=C0103,W0603
    global _RO_SHEDULER_INSTANCE, _LAST_CACHE_UPDATE
    if (time.time() - _LAST_CACHE_UPDATE > _CACHE_TIMEOUT
            or not _RO_SHEDULER_INSTANCE):
        tm_sched.DIMENSION_COUNT = 3

        _RO_SHEDULER_INSTANCE = loader.Loader(
            zkbackend.ZkReadonlyBackend(context.GLOBAL.zk.conn),
            context.GLOBAL.cell)
        _RO_SHEDULER_INSTANCE.load_model()
        _LAST_CACHE_UPDATE = time.time()

    return _RO_SHEDULER_INSTANCE
Beispiel #4
0
    def test_readonly_master(self):
        """Tests the ZK operations of a readonly master."""
        zk_content = {
            'server.presence': {
                'test1.xx.com': {},
                'test2.xx.com': {},
            },
            'cell': {
                'pod:pod1': {},
            },
            'buckets': {
                'pod:pod1': {
                    'traits': None,
                },
                'rack:1234': {
                    'traits': None,
                    'parent': 'pod:pod1',
                },
            },
            'identity-groups': {},
            'partitions': {},
            'servers': {
                'test1.xx.com': {
                    'memory': '16G',
                    'disk': '128G',
                    'cpu': '400%',
                    'parent': 'rack:1234',
                    'up_since': 100,
                },
                'test2.xx.com': {
                    'memory': '16G',
                    'disk': '128G',
                    'cpu': '400%',
                    'parent': 'rack:1234',
                    'up_since': 200,
                },
            },
            # Comments indicate zkutils functions that would get called
            # for each entity if the master weren't in readonly mode
            'placement': {  # ensure_exists and put on each placement
                'test1.xx.com': {
                    '.data': """
                        state: up
                        since: 100
                    """,
                    'xxx.app1#1234': '',  # on two servers: ensure_deleted
                    'xxx.app2#2345': '',  # not scheduled: ensure_deleted
                },
                'test2.xx.com': {
                    '.data': """
                        state: up
                        since: 100
                    """,
                    'xxx.app1#1234': '',  # on two servers: ensure_deleted
                }
            },
            'scheduled': {
                'xxx.app1#1234': {
                    'affinity': 'app1',
                    'memory': '1G',
                    'disk': '1G',
                    'cpu': '100%',
                },
                'xxx.app3#6789': {  # gets scheduled by init_schedule: put
                    'affinity': 'app3',
                    'memory': '1G',
                    'disk': '1G',
                    'cpu': '100%',
                },
            }
        }

        time.time.return_value = 500
        self.make_mock_zk(zk_content)
        ro_master = master.Master(
            zkbackend.ZkReadonlyBackend(kazoo.client.KazooClient()),
            'test-cell',

        )
        ro_master.load_model()
        ro_master.init_schedule()

        self.assertFalse(treadmill.zkutils.ensure_deleted.called)
        self.assertFalse(treadmill.zkutils.ensure_exists.called)
        self.assertFalse(treadmill.zkutils.put.called)