Esempio n. 1
0
def test_workflow_host_select_condemned(mock_glbl_cfg):
    """Ensure condemned hosts are filtered out."""
    mock_glbl_cfg(
        'cylc.flow.host_select.glbl_cfg', f'''
            [scheduler]
                [[run hosts]]
                    available = {localhost}
                    condemned = {localhost_fqdn}
        ''')
    with pytest.raises(HostSelectException) as excinfo:
        select_workflow_host()
    assert 'blacklisted' in str(excinfo.value)
    assert 'condemned host' in str(excinfo.value)
Esempio n. 2
0
def _can_auto_restart():
    """Determine whether this workflow can safely auto stop-restart."""
    # Check whether there is currently an available host to restart on.
    try:
        select_workflow_host(cached=False)
    except HostSelectException:
        LOG.critical('Workflow cannot automatically restart because:\n' +
                     'No alternative host to restart workflow on.')
        return False
    except Exception:
        # Any unexpected error in host selection shouldn't be able to take
        # down the workflow.
        LOG.critical('Workflow cannot automatically restart because:\n' +
                     'Error in host selection:\n' + traceback.format_exc())
        return False
    else:
        return True
Esempio n. 3
0
def test_workflow_host_select(mock_glbl_cfg):
    """Run the workflow_host_select mechanism."""
    mock_glbl_cfg(
        'cylc.flow.host_select.glbl_cfg', f'''
            [scheduler]
                [[run hosts]]
                    available= {localhost}
        ''')
    assert select_workflow_host() == (localhost, localhost_fqdn)
Esempio n. 4
0
def test_remote_workflow_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_workflow_host() == (remote_platform, remote_platform_fqdn)
Esempio n. 5
0
def _distribute(host):
    """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_workflow_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)
Esempio n. 6
0
def test_workflow_host_select_default(mock_glbl_cfg):
    """Ensure "localhost" is provided as a default host."""
    mock_glbl_cfg(
        'cylc.flow.host_select.glbl_cfg', '''
            [scheduler]
                [[run hosts]]
                    available =
        ''')
    hostname, host_fqdn = select_workflow_host()
    assert hostname in localhost_aliases + [localhost]
    assert host_fqdn == localhost_fqdn
Esempio n. 7
0
def test_remote_workflow_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_workflow_host() == (local_host, local_host_fqdn)
Esempio n. 8
0
def test_remote_workflow_host_rankings(mock_glbl_cfg):
    """test [scheduler][run hosts]rankings"""
    mock_glbl_cfg(
        'cylc.flow.host_select.glbl_cfg', f'''
            [scheduler]
                [[run hosts]]
                    available = {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_workflow_host()
    # ensure that host selection actually evaluated 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())