Beispiel #1
0
def _rankfile_dump(ff, rankfile, ranks):
    '''
    Store ranks in ``rankfile``. Also sets a timestamp and writes the
    release string into the output.

    :param ff: running :class:`ffflash.main.FFFlash` instance
    :param rankfile: validated path to the ``rankfile``
    :param ranks: content to store
    :return: ``True`` on success, or ``False`` on error
    '''
    if not ff.access_for('rankfile'):
        return False
    if not all([
        rankfile, ranks, isinstance(ranks, dict), all([
            (a in ranks) for a in ['nodes', 'updated_at'] if ranks
        ])
    ]):
        return ff.log('wrong input data passed', level=False)

    ranks['updated_at'] = get_iso_timestamp()
    ranks['version'] = info.release

    if ff.args.dry:
        ff.log('\n{}'.format(make_pretty(ranks)), level='rankfile preview')
        return False

    dump_file(rankfile, ranks, as_yaml=False)
    ff.log('successfully stored rankfile {}'.format(rankfile))
    return True
Beispiel #2
0
 def set_timestamp(self):
     '''
     Inject :meth:`ffflash.lib.clock.get_iso_timestamp`
     into ``state.lastchange``.
     '''
     if self.access_for('api'):
         if self.api.pull('state', 'lastchange') is not None:
             self.api.push(get_iso_timestamp(), 'state', 'lastchange')
Beispiel #3
0
 def set_timestamp(self):
     '''
     Inject :meth:`ffflash.lib.clock.get_iso_timestamp`
     into ``state.lastchange``.
     '''
     if self.access_for('api'):
         if self.api.pull('state', 'lastchange') is not None:
             self.api.push(get_iso_timestamp(), 'state', 'lastchange')
def test_get_iso_timestamp_dt_passed():
    now = datetime.now()
    utcnow = datetime.utcnow()

    assert parser.parse(get_iso_timestamp(now)) == now
    assert parser.parse(get_iso_timestamp(utcnow)) == utcnow
def test_get_iso_timestamp_no_dt():
    assert datetime.now() <= parser.parse(get_iso_timestamp())
    assert parser.parse(get_iso_timestamp()) <= datetime.now()
    assert (
        datetime.now() <= parser.parse(get_iso_timestamp()) <= datetime.now()
    )
Beispiel #6
0
def test_get_iso_timestamp_dt_passed():
    now = datetime.now()
    utcnow = datetime.utcnow()

    assert parser.parse(get_iso_timestamp(now)) == now
    assert parser.parse(get_iso_timestamp(utcnow)) == utcnow
Beispiel #7
0
def test_get_iso_timestamp_no_dt():
    assert datetime.now() <= parser.parse(get_iso_timestamp())
    assert parser.parse(get_iso_timestamp()) <= datetime.now()
    assert (datetime.now() <= parser.parse(get_iso_timestamp()) <=
            datetime.now())