示例#1
0
def validate_reboot_schedule(_ctx, _param, value):
    """Validate reboot schedule specification."""
    if value is None:
        return None
    try:
        utils.reboot_schedule(value)
    except ValueError:
        raise click.BadParameter('Invalid reboot schedule. (eg.: "sat,sun")')
    return value
示例#2
0
 def test_reboot_schedule(self):
     """Test reboot schedule parsing."""
     self.assertEqual(utils.reboot_schedule('sun'), {6: (23, 59, 59)})
     self.assertEqual(utils.reboot_schedule('sun/2:00:00'), {6: (2, 0, 0)})
     self.assertEqual(utils.reboot_schedule('sun/2:05:00'), {6: (2, 5, 0)})
     self.assertEqual(utils.reboot_schedule('sat,sun/02:00:00'), {
         5: (23, 59, 59),
         6: (2, 0, 0)
     })
示例#3
0
def sync_partitions():
    """Syncs partitions to Zookeeper.
    """
    _LOGGER.info('Sync: partitions.')
    zkclient = context.GLOBAL.zk.conn

    admin_cell = admin.Cell(context.GLOBAL.ldap.conn)
    partitions = admin_cell.partitions(context.GLOBAL.cell)

    zkclient.ensure_path(z.path.partition())

    in_zk = zkclient.get_children(z.path.partition())
    names = [partition['_id'] for partition in partitions]

    for extra in set(in_zk) - set(names):
        _LOGGER.debug('Delete: %s', extra)
        zkutils.ensure_deleted(zkclient, z.path.partition(extra))

    # Add or update current partitions
    for partition in partitions:
        zkname = partition['_id']

        if 'reboot-schedule' in partition:
            try:
                partition['reboot-schedule'] = utils.reboot_schedule(
                    partition['reboot-schedule']
                )
            except ValueError:
                _LOGGER.info('Invalid reboot schedule, ignoring.')

        if zkutils.put(zkclient, z.path.partition(zkname),
                       partition, check_content=True):
            _LOGGER.info('Update: %s', zkname)
        else:
            _LOGGER.info('Up to date: %s', zkname)
示例#4
0
def _sync_partitions(zkclient, entities):
    """Syncs partitions to Zookeeper.
    """
    _LOGGER.info('Sync: %s', z.path.partition())

    zkclient.ensure_path(z.path.partition())

    in_zk = zkclient.get_children(z.path.partition())
    names = [entity['_id'] for entity in entities]

    for extra in set(in_zk) - set(names):
        _LOGGER.debug('Delete: %s', extra)
        zkutils.ensure_deleted(zkclient, z.path.partition(extra))

    # Add or update current partitions
    for entity in entities:
        zkname = entity['_id']

        if 'reboot-schedule' in entity:
            try:
                entity['reboot-schedule'] = utils.reboot_schedule(
                    entity['reboot-schedule'])
            except ValueError:
                _LOGGER.info('Invalid reboot schedule, ignoring.')

        if zkutils.put(zkclient,
                       z.path.partition(zkname),
                       entity,
                       check_content=True):
            _LOGGER.info('Update: %s', zkname)
        else:
            _LOGGER.info('Up to date: %s', zkname)