コード例 #1
0
def test_filter():
    """Test that hosts are filtered out if specified."""
    message = 'Localhost not allowed'
    with pytest.raises(HostSelectException) as excinfo:
        select_host([localhost],
                    blacklist=[localhost],
                    blacklist_name='Localhost not allowed')
    assert message in str(excinfo.value)
コード例 #2
0
def test_metric_command_failure():
    """If the psutil command (or SSH) fails ensure the host is excluded."""
    with pytest.raises(HostSelectException) as excinfo:
        select_host([localhost],
                    ranking_string='''
                # elephant is not a psutil attribute
                # so will cause the command to fail
                elephant
            ''')
    assert excinfo.value.data[localhost_fqdn]['get_metrics'] == (
        'Command failed (exit: 1)')
コード例 #3
0
def test_remote_blacklict():
    """Test that blacklisting works with remote host names."""
    # blacklist by fqdn
    with pytest.raises(HostSelectException):
        select_host([remote_platform], blacklist=[remote_platform])
    # blacklist by short name
    with pytest.raises(HostSelectException):
        select_host([remote_platform], blacklist=[remote_platform_fqdn])
    # make extra sure filters are really being applied
    for _ in range(10):
        assert select_host([remote_platform, local_host],
                           blacklist=[remote_platform]) == (local_host,
                                                            local_host_fqdn)
コード例 #4
0
def test_unreasonable_rankings():
    """Negative test that rankings are evaluated.

    (doesn't prove anything by itself hence test_rankings)
    """
    with pytest.raises(HostSelectException) as excinfo:
        select_host([localhost],
                    ranking_string='''
                # if this test fails due to race conditions
                # then you are very lucky
                virtual_memory().available > 123456789123456789
                getloadavg()[0] < 1
                cpu_count() > 512
                disk_usage('/').free > 123456789123456789
            ''')
    assert ('virtual_memory().available > 123456789123456789: False') in str(
        excinfo.value)
コード例 #5
0
def test_remote_rankings():
    """Test that ranking evaluation works on hosts (via SSH)."""
    assert select_host([remote_platform],
                       ranking_string='''
            # if this test fails due to race conditions
            # then you have bigger issues than a test failure
            virtual_memory().available > 1
            getloadavg()[0] < 500
            cpu_count() > 1
            disk_usage('/').free > 1
        ''') == (remote_platform, remote_platform_fqdn)
コード例 #6
0
def test_rankings():
    """Positive test that rankings are evaluated.

    (doesn't prove anything by itself hence test_unreasonable_rankings)
    """
    assert select_host([localhost],
                       ranking_string='''
            # if this test fails due to race conditions
            # then you have bigger issues than a test failure
            virtual_memory().available > 1
            getloadavg()[0] < 500
            cpu_count() > 1
            disk_usage('/').free > 1
        ''') == (localhost, localhost_fqdn)
コード例 #7
0
def test_remote_exclude(monkeypatch):
    """Ensure that hosts get excluded if they don't meet the rankings.

    Already tested elsewhere but this double-checks that it works if more
    than one host is provided to choose from."""
    def mocked_get_metrics(hosts, metrics, _=None):
        # pretend that ssh to remote_platform failed
        return ({f'{local_host_fqdn}': {('cpu_count', ): 123}}, {})

    monkeypatch.setattr('cylc.flow.host_select._get_metrics',
                        mocked_get_metrics)
    assert select_host([local_host, remote_platform],
                       ranking_string='''
            cpu_count()
        ''') == (local_host, local_host_fqdn)
コード例 #8
0
def test_unique():
    """Basic test choosing from multiple forms of localhost"""
    name, fqdn = select_host(localhost_aliases + [localhost])
    assert name in localhost_aliases + [localhost]
    assert fqdn == localhost_fqdn
コード例 #9
0
def test_localhost():
    """Basic test with one host to choose from."""
    assert select_host([localhost]) == (localhost, localhost_fqdn)
コード例 #10
0
def test_remote_select():
    """Test host selection works with remote host names."""
    assert select_host([remote_platform]) == (remote_platform,
                                              remote_platform_fqdn)