def test_remote_suite_host_rankings(mock_glbl_cfg): """test [suite servers]rankings""" mock_glbl_cfg( 'cylc.flow.host_select.glbl_cfg', f''' [suite servers] run hosts = {remote_platform} ranking = """ # if this test fails due to race conditions # then you are very lucky virtual_memory().available > 123456789123456789 cpu_count() > 512 disk_usage('/').free > 123456789123456789 """ ''' ) with pytest.raises(HostSelectException) as excinfo: select_suite_host() # ensure that host selection actually evuluated rankings assert set(excinfo.value.data[remote_platform_fqdn]) == { 'virtual_memory().available > 123456789123456789', 'cpu_count() > 512', "disk_usage('/').free > 123456789123456789" } # ensure that none of the rankings passed assert not any(excinfo.value.data[remote_platform_fqdn].values())
def test_suite_host_select_condemned(mock_glbl_cfg): """Ensure condemned hosts are filtered out.""" mock_glbl_cfg( 'cylc.flow.host_select.glbl_cfg', f''' [suite servers] run hosts = {localhost} condemned hosts = {localhost_fqdn} ''') with pytest.raises(HostSelectException) as excinfo: select_suite_host() assert 'blacklisted' in str(excinfo.value) assert 'condemned host' in str(excinfo.value)
def test_suite_host_select(mock_glbl_cfg): """Run the suite_host_select mechanism.""" mock_glbl_cfg( 'cylc.flow.host_select.glbl_cfg', f''' [suite servers] run hosts = {localhost} ''') assert select_suite_host() == (localhost, localhost_fqdn)
def _can_auto_restart(): """Determine whether this suite can safely auto stop-restart.""" # Check whether there is currently an available host to restart on. try: select_suite_host(cached=False) except HostSelectException: LOG.critical('Suite cannot automatically restart because:\n' + 'No alternative host to restart suite on.') return False except Exception: # Any unexpected error in host selection shouldn't be able to take # down the suite. LOG.critical('Suite cannot automatically restart because:\n' + 'Error in host selection:\n' + traceback.format_exc()) return False else: return True
def test_suite_host_select(mock_glbl_cfg): """Run the suite_host_select mechanism.""" mock_glbl_cfg( 'cylc.flow.host_select.glbl_cfg', f''' [scheduler] [[run hosts]] available= {localhost} ''') assert select_suite_host() == (localhost, localhost_fqdn)
def test_remote_suite_host_select(mock_glbl_cfg): """test [scheduler][run hosts]available""" mock_glbl_cfg( 'cylc.flow.host_select.glbl_cfg', f''' [scheduler] [[run hosts]] available = {remote_platform} ''') assert select_suite_host() == (remote_platform, remote_platform_fqdn)
def test_suite_host_select_default(mock_glbl_cfg): """Ensure "localhost" is provided as a default host.""" mock_glbl_cfg( 'cylc.flow.host_select.glbl_cfg', ''' [suite servers] run hosts = ''') hostname, host_fqdn = select_suite_host() assert hostname in localhost_aliases + [localhost] assert host_fqdn == localhost_fqdn
def test_remote_suite_host_select(mock_glbl_cfg): """test [suite servers]run hosts""" mock_glbl_cfg( 'cylc.flow.host_select.glbl_cfg', f''' [suite servers] run hosts = {remote_platform} ''' ) assert select_suite_host() == (remote_platform, remote_platform_fqdn)
def _distribute(host, is_restart): """Re-invoke this command on a different host if requested.""" # Check whether a run host is explicitly specified, else select one. if not host: host = select_suite_host()[0] if is_remote_host(host): # Prevent recursive host selection cmd = sys.argv[1:] cmd.append("--host=localhost") remote_cylc_cmd(cmd, host=host) sys.exit(0)
def test_remote_suite_host_condemned(mock_glbl_cfg): """test [scheduler][run hosts]condemned hosts""" mock_glbl_cfg( 'cylc.flow.host_select.glbl_cfg', f''' [scheduler] [[run hosts]] available = {remote_platform}, {local_host} condemned = {remote_platform} ''') for _ in range(10): assert select_suite_host() == (local_host, local_host_fqdn)