def handle_nodelist(ff): ''' Entry function to receive a ``--nodelist`` and store determined results into both :attr:`api` and ``--rankfile`` (if specified). :param ff: running :class:`ffflash.main.FFFlash` instance :return: ``True`` if :attr:`api` was modified else ``False`` ''' if not ff.access_for('nodelist'): return False nodelist = _nodelist_fetch(ff) if not nodelist: return False modified = [] nodes, clients = _nodelist_count(ff, nodelist) if all([nodes, clients]): modified.append(_nodelist_dump(ff, nodes, clients)) if ff.access_for('rankfile'): modified.append(handle_rankfile(ff, nodelist)) return any(modified)
def handle_nodelist(ff): ''' Entry function to receive a ``--nodelist`` and store determined results into both :attr:`api` and ``--rankfile`` (if specified). :param ff: running :class:`ffflash.main.FFFlash` instance :return: ``True`` if :attr:`api` was modified else ``False`` ''' if not ff.access_for('nodelist'): return False nodelist = _nodelist_fetch(ff) if not nodelist: return False modified = [] nodes, clients = _nodelist_count(ff, nodelist) if all([nodes, clients]): modified.append( _nodelist_dump(ff, nodes, clients) ) if ff.access_for('rankfile'): modified.append( handle_rankfile(ff, nodelist) ) return any(modified)
def test_handle_rankfile_empty_nodelist(tmpdir, fffake): apifile = tmpdir.join('api_file.json') apifile.write_text(dumps({'a': 'b'}), 'utf-8') nodelist = tmpdir.join('nodelist.json') nodelist.write_text(dumps({'a': 'b'}), 'utf-8') ff = fffake( apifile, nodelist=nodelist, rankfile=tmpdir.join('rankfile.json'), dry=True ) assert ff.access_for('nodelist') is True assert ff.access_for('rankfile') is True assert handle_rankfile(ff, None) is False assert handle_rankfile(ff, {}) is False assert tmpdir.remove() is None
def test_handle_rankfile_empty_nodelist(tmpdir, fffake): apifile = tmpdir.join('api_file.json') apifile.write_text(dumps({'a': 'b'}), 'utf-8') nodelist = tmpdir.join('nodelist.json') nodelist.write_text(dumps({'a': 'b'}), 'utf-8') ff = fffake(apifile, nodelist=nodelist, rankfile=tmpdir.join('rankfile.json'), dry=True) assert ff.access_for('nodelist') is True assert ff.access_for('rankfile') is True assert handle_rankfile(ff, None) is False assert handle_rankfile(ff, {}) is False assert tmpdir.remove() is None
def test_handle_rankfile_trashy_nodelist(tmpdir, fffake): apifile = tmpdir.join('api_file.json') apifile.write_text(dumps({'a': 'b'}), 'utf-8') nodelist = tmpdir.join('nodelist.json') nodelist.write_text(dumps({'a': 'b'}), 'utf-8') rankfile = tmpdir.join('rankfile.json') rankfile.write_text(dumps({'nodes': [], 'updated_at': 'now'}), 'utf-8') ff = fffake(apifile, nodelist=nodelist, rankfile=rankfile, dry=True) assert handle_rankfile(ff, {'a': 'b'}) is False assert tmpdir.remove() is None
def test_handle_rankfile_trashy_nodelist(tmpdir, fffake): apifile = tmpdir.join('api_file.json') apifile.write_text(dumps({'a': 'b'}), 'utf-8') nodelist = tmpdir.join('nodelist.json') nodelist.write_text(dumps({'a': 'b'}), 'utf-8') rankfile = tmpdir.join('rankfile.json') rankfile.write_text(dumps({'nodes': [], 'updated_at': 'now'}), 'utf-8') ff = fffake( apifile, nodelist=nodelist, rankfile=rankfile, dry=True ) assert handle_rankfile(ff, {'a': 'b'}) is False assert tmpdir.remove() is None
def test_handle_rankfile_without_nodelist(tmpdir, fffake): ff = fffake(tmpdir.join('api_file.json'), dry=True) assert handle_rankfile(ff, {}) is False assert tmpdir.remove() is None