예제 #1
0
def test_get_all_service_list(mock_config_db, mock_run, mock_docker_client):
    mock_db_data = MagicMock()
    mock_get_table = MagicMock()
    mock_db_data.get_table = mock_get_table
    mock_config_db.return_value = mock_db_data
    mock_get_table.return_value = {
        'radv': {
            'state': 'enabled',
            'has_global_scope': 'True',
            'has_per_asic_scope': 'False',
        },
        'bgp': {
            'state': 'enabled',
            'has_global_scope': 'True',
            'has_per_asic_scope': 'False',
        },
        'pmon': {
            'state': 'disabled',
            'has_global_scope': 'True',
            'has_per_asic_scope': 'False',
        }
    }
    sysmon = Sysmonitor()
    print("mock get table:{}".format(mock_get_table.return_value))
    result = sysmon.get_all_service_list()
    print("result get all service list:{}".format(result))
    assert 'radv.service' in result
    assert 'pmon.service' not in result
예제 #2
0
def test_update_system_status():
    sysmon = Sysmonitor()
    sysmon.update_system_status()
    result = swsscommon.SonicV2Connector.get(MockConnector, 0,
                                             "SYSTEM_READY|SYSTEM_STATE",
                                             'Status')
    assert result == "UP"
예제 #3
0
def test_post_system_status():
    sysmon = Sysmonitor()
    sysmon.post_system_status("UP")
    result = swsscommon.SonicV2Connector.get(MockConnector, 0,
                                             "SYSTEM_READY|SYSTEM_STATE",
                                             'Status')
    print("post system status result:{}".format(result))
    assert result == "UP"
def test_post_unit_status():
    sysmon = Sysmonitor()
    sysmon.post_unit_status("mock_bgp", 'OK', 'Down', 'mock reason', '-') 
    result = swsscommon.SonicV2Connector.get_all(MockConnector, 0, 'ALL_SERVICE_STATUS|mock_bgp')
    print(result)
    assert result['service_status'] == 'OK'
    assert result['app_ready_status'] == 'Down'
    assert result['fail_reason'] == 'mock reason'
예제 #5
0
def test_get_app_ready_status(mock_config_db, mock_run, mock_docker_client):
    mock_db_data = MagicMock()
    mock_get_table = MagicMock()
    mock_db_data.get_table = mock_get_table
    mock_config_db.return_value = mock_db_data
    mock_get_table.return_value = {
        'radv': {
            'state': 'enabled',
            'has_global_scope': 'True',
            'has_per_asic_scope': 'False',
            'check_up_status': 'True'
        },
        'bgp': {
            'state': 'enabled',
            'has_global_scope': 'True',
            'has_per_asic_scope': 'False',
            'check_up_status': 'True'
        },
        'snmp': {
            'state': 'enabled',
            'has_global_scope': 'True',
            'has_per_asic_scope': 'False',
            'check_up_status': 'False'
        }
    }

    MockConnector.data.update({
        'FEATURE|radv': {
            'up_status': 'True',
            'fail_reason': '-',
            'update_time': '-'
        },
        'FEATURE|bgp': {
            'up_status': 'False',
            'fail_reason': 'some error',
            'update_time': '-'
        }
    })

    sysmon = Sysmonitor()
    result = sysmon.get_app_ready_status('radv')
    print(result)
    assert 'Up' in result
    result = sysmon.get_app_ready_status('bgp')
    print(result)
    assert 'Down' in result
    result = sysmon.get_app_ready_status('snmp')
    print(result)
    assert 'Up' in result
def test_get_service_from_feature_table():
    sysmon = Sysmonitor()
    sysmon.config_db = MagicMock()
    sysmon.config_db.get_table = MagicMock()
    sysmon.config_db.get_table.side_effect = [
        {
            'bgp': {},
            'swss': {}
        },
        {
            'bgp': {'state': 'enabled'},
            'swss': {'state': 'disabled'}
        }
    ]
    dir_list = []
    sysmon.get_service_from_feature_table(dir_list)
    assert 'bgp.service' in dir_list
    assert 'swss.service' not in dir_list
예제 #7
0
def test_system_service():
    sysmon = Sysmonitor()
    sysmon.task_run()
    assert sysmon._task_process is not None
    sysmon.task_stop()
예제 #8
0
def test_get_all_system_status_not_ok():
    sysmon = Sysmonitor()
    result = sysmon.get_all_system_status()
    print("result:{}".format(result))
    assert result == 'DOWN'
예제 #9
0
def test_get_unit_status_not_ok():
    sysmon = Sysmonitor()
    result = sysmon.get_unit_status('mock_bgp.service')
    print("get_unit_status:{}".format(result))
    assert result == 'NOT OK'
예제 #10
0
def test_check_unit_status():
    sysmon = Sysmonitor()
    sysmon.check_unit_status('mock_bgp.service')
    assert 'mock_bgp.service' in sysmon.dnsrvs_name