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
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"
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'
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
def test_system_service(): sysmon = Sysmonitor() sysmon.task_run() assert sysmon._task_process is not None sysmon.task_stop()
def test_get_all_system_status_not_ok(): sysmon = Sysmonitor() result = sysmon.get_all_system_status() print("result:{}".format(result)) assert result == 'DOWN'
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'
def test_check_unit_status(): sysmon = Sysmonitor() sysmon.check_unit_status('mock_bgp.service') assert 'mock_bgp.service' in sysmon.dnsrvs_name