from ENM_class import EnmCli
from parser_utils import parse_eutran_cells, parse_nodeb_pars, parse_nodeb_mo_pars, parse_fea, combine_fea, parse_cosector, clean_cell, clean_band, delete_region, parse_anr_rels
from Baseline import Baseline, compare
from file_write import stat, baseline_write
from collections import Counter
from dotenv import load_dotenv
from remove_old_files import remove_old_files
from mail import send_email
from upload_reports import upload_reports
# from datetime import datetime
load_dotenv('.env')
relation_reporting_map = {
'UtranFreqRelation_prio3_base': ('UtranFreqRelation_prio3_par', Baseline.UtranFreqRelation_prio3_base),
'UtranFreqRelation_prio4_base': ('UtranFreqRelation_prio4_par', Baseline.UtranFreqRelation_prio4_base),
'GeranFreqGroupRelation_900_base': ('GeranFreqGroupRelation_900_par', Baseline.GeranFreqGroupRelation_900_base),
'GeranFreqGroupRelation_1800_base': ('GeranFreqGroupRelation_1800_par', Baseline.GeranFreqGroupRelation_1800_base),
'UeMeasControl_base': ('UeMeasControl_par', Baseline.UeMeasControl_base),
}
nodeb_children_map = {
'ENodeBFunction_node': ('ENodeBFunction_par', Baseline.ENodeBFunction_node),
'AnrFunction_node': ('AnrFunction_par', Baseline.AnrFunction_node),
'AnrFunctionEUtran_node': ('AnrFunctionEUtran_par', Baseline.AnrFunctionEUtran_node),
}
def enm_main(mo_type, enm):
if mo_type == 'BbuENodeBFunctionFea_base':
enm_bbu_feature = EnmCli.execute_cli_command('BBU_ENodeBFunction_fea', enm)
bbu_feature_sort = parse_fea(enm_bbu_feature)
bbu_features = combine_fea(bbu_feature_sort, len(EnmCli.BbuENodeBFunctionFea))
if bbu_features:
return compare(bbu_features, Baseline.BbuENodeBFunctionFea_base)
elif mo_type == 'DusENodeBFunctionFea_base':
enm_dus_feature = EnmCli.execute_cli_command('DUS_ENodeBFunction_fea', enm)
dus_feature_sort = parse_fea(enm_dus_feature)
dus_features = combine_fea(dus_feature_sort, len(EnmCli.DusENodeBFunctionFea))
if dus_features:
return compare(dus_features, Baseline.DusENodeBFunctionFea_base)
elif mo_type == 'QciProfilePredefined_traffic_base':
enm_qci_traffic = EnmCli.execute_cli_command('QciProfilePredefined_9_par', enm) + \
EnmCli.execute_cli_command('QciProfilePredefined_7_par', enm)
qci_traffic = parse_nodeb_mo_pars(enm_qci_traffic, EnmCli.QciProfilePredefined[-1], 'Sub_QciProfilePredefined')
if qci_traffic:
return compare(qci_traffic, Baseline.QciProfilePredefined_traffic_base)
elif mo_type == 'ReportConfigEUtraInterFreqLb_800_base':
enm_uemeas_interlb = EnmCli.execute_cli_command('ReportConfigEUtraInterFreqLb_par1', enm)
uemeas_interlb = parse_nodeb_mo_pars(enm_uemeas_interlb, EnmCli.ReportConfigEUtraInterFreqLb1[-1],'Sub_EUtranCellFDD')
uemeas_interlb_cleaned = clean_cell(uemeas_interlb)
uemeas_interlb_cleaned_800 = clean_band(uemeas_interlb_cleaned, '800')
if uemeas_interlb_cleaned_800:
return compare(uemeas_interlb_cleaned_800, Baseline.ReportConfigEUtraInterFreqLb_800_base)
elif mo_type == 'ReportConfigEUtraInterFreqLb_2100_base':
enm_uemeas_interlb = EnmCli.execute_cli_command('ReportConfigEUtraInterFreqLb_par1', enm)
uemeas_interlb = parse_nodeb_mo_pars(enm_uemeas_interlb, EnmCli.ReportConfigEUtraInterFreqLb1[-1],'Sub_EUtranCellFDD')
uemeas_interlb_cleaned = clean_cell(uemeas_interlb)
uemeas_interlb_cleaned_2100 = clean_band(uemeas_interlb_cleaned, '2100')
if uemeas_interlb_cleaned_2100:
return compare(uemeas_interlb_cleaned_2100, Baseline.ReportConfigEUtraInterFreqLb_2100_base)
elif mo_type == 'EUtranCellRelationCosite_base':
enm_cellrel_old = EnmCli.execute_cli_command('EUtranCellRelationCosite_par_old', enm)
enm_cellrel_new = EnmCli.execute_cli_command('EUtranCellRelationCosite_par_new', enm)
cellrel = parse_nodeb_mo_pars(enm_cellrel_old + enm_cellrel_new, EnmCli.EUtranCellRelationCosite[-1], 'Sub_EUtranCellFDD')
cosite_cellrel_cleaned = clean_cell(cellrel)
if cosite_cellrel_cleaned:
return compare(cosite_cellrel_cleaned, Baseline.EUtranCellRelationCosite_base)
elif mo_type == 'EUtranCellRelationCosector_base':
enm_scell_old = EnmCli.execute_cli_command('EUtranCellRelationCosector_par_old', enm)
enm_scell_new = EnmCli.execute_cli_command('EUtranCellRelationCosector_par_new', enm)
enm_scell_anr = EnmCli.execute_cli_command('EUtranCellRelation_anr_scell_par', enm)
scell_cellrel = parse_nodeb_mo_pars(enm_scell_old + enm_scell_new, EnmCli.EUtranCellRelationCosector[-1], 'Sub_EUtranCellFDD')
scell_wrong = parse_anr_rels(enm_scell_anr, EnmCli.EUtranCellRelationCosector[-1], 'Sub_EUtranCellFDD')
cosector_cellrel = parse_cosector(scell_cellrel + scell_wrong)
if cosector_cellrel:
return compare(cosector_cellrel, Baseline.EUtranCellRelationCosector_base)
# NodeB cildren
elif '_node' in mo_type:
command, baseline = nodeb_children_map[mo_type]
enm_output = EnmCli.execute_cli_command(command, enm)
list_name = command.split('_')[0]
parsed_output = parse_nodeb_pars(enm_output, getattr(EnmCli, list_name)[-1])
if parsed_output:
return compare(parsed_output, Baseline.ENodeBFunction_node)
# NON_SHYM
elif mo_type == 'EUtranCellFDD_def':
enm_eutrancell = EnmCli.execute_cli_command('EUtranCellFDD_par', enm)
eutrancell = parse_eutran_cells(enm_eutrancell, EnmCli.EUtranCellFDD[-1])
eutrancell_cleaned = clean_cell(eutrancell)
eutrancell_separated = delete_region(eutrancell_cleaned, 'Shymkent')
if eutrancell_separated:
return compare(eutrancell_separated, Baseline.EUtranCellFDD_def)
elif mo_type == 'ReportConfigEUtraInterFreqLb_1800_def':
enm_uemeas_interlb = EnmCli.execute_cli_command('ReportConfigEUtraInterFreqLb_par1', enm)
uemeas_interlb = parse_nodeb_mo_pars(enm_uemeas_interlb, EnmCli.ReportConfigEUtraInterFreqLb1[-1], 'Sub_EUtranCellFDD')
uemeas_interlb_cleaned = clean_cell(uemeas_interlb)
uemeas_interlb_cleaned_1800 = clean_band(uemeas_interlb_cleaned, '1800')
uemeas_interlb_cleaned_1800_separated = delete_region(uemeas_interlb_cleaned_1800, 'Shymkent')
if uemeas_interlb_cleaned_1800_separated:
return compare(uemeas_interlb_cleaned_1800_separated, Baseline.ReportConfigEUtraInterFreqLb_1800_def)
elif mo_type == 'ReportConfigEUtraInterFreqLb_def':
enm_uemeas_interlb = EnmCli.execute_cli_command('ReportConfigEUtraInterFreqLb_par2', enm)
uemeas_interlb = parse_nodeb_mo_pars(enm_uemeas_interlb, EnmCli.ReportConfigEUtraInterFreqLb2[-1], 'Sub_EUtranCellFDD')
uemeas_interlb_cleaned = clean_cell(uemeas_interlb)
uemeas_interlb_separated = delete_region(uemeas_interlb_cleaned, 'Shymkent')
if uemeas_interlb_separated:
return compare(uemeas_interlb_separated, Baseline.ReportConfigEUtraInterFreqLb_def)
# SHYM
elif mo_type == 'EUtranCellFDD_shym':
enm_eutrancell = EnmCli.execute_cli_command('EUtranCellFDD_par_shym2', enm)
eutrancell = parse_eutran_cells(enm_eutrancell, EnmCli.EUtranCellFDD[-1])
eutrancell_cleaned = clean_cell(eutrancell)
if eutrancell_cleaned:
return compare(eutrancell_cleaned, Baseline.EUtranCellFDD_shym)
elif mo_type == 'ReportConfigEUtraInterFreqLb_1800_shym':
enm_uemeas_interlb = EnmCli.execute_cli_command('ReportConfigEUtraInterFreqLb_par1_shym2', enm)
uemeas_interlb = parse_nodeb_mo_pars(enm_uemeas_interlb, EnmCli.ReportConfigEUtraInterFreqLb1[-1],'Sub_EUtranCellFDD')
uemeas_interlb_cleaned = clean_cell(uemeas_interlb)
uemeas_interlb_cleaned_1800 = clean_band(uemeas_interlb_cleaned, '1800')
if uemeas_interlb_cleaned_1800:
return compare(uemeas_interlb_cleaned_1800, Baseline.ReportConfigEUtraInterFreqLb_1800_shym)
elif mo_type == 'ReportConfigEUtraInterFreqLb_shym':
enm_uemeas_interlb = EnmCli.execute_cli_command('ReportConfigEUtraInterFreqLb_par2_shym2', enm)
uemeas_interlb = parse_nodeb_mo_pars(enm_uemeas_interlb, EnmCli.ReportConfigEUtraInterFreqLb2[-1], 'Sub_EUtranCellFDD')
uemeas_interlb_cleaned = clean_cell(uemeas_interlb)
if uemeas_interlb_cleaned:
return compare(uemeas_interlb_cleaned, Baseline.ReportConfigEUtraInterFreqLb_shym)
else:
command, baseline = relation_reporting_map[mo_type]
enm_output = EnmCli.execute_cli_command(command, enm)
list_name = command.split('_')[0]
parsed_output = parse_nodeb_mo_pars(enm_output, getattr(EnmCli, list_name)[-1], 'Sub_EUtranCellFDD')
cleaned_output = clean_cell(parsed_output)
separated_output = delete_region(cleaned_output, 'Shymkent') if 'shym' not in mo_type else cleaned_output
if separated_output:
return compare(separated_output, baseline)