Exemplo n.º 1
0
def save_route_summary_db(device, list_vrf, when_tested, current_time):

    test_name = "route_summary"
    dict_final = {'vrf': {}}

    # Building the full dict, adding route_summary from each vrf
    for vrf in list_vrf:

        if vrf == "default":
            dict_vrf = device.parse(f"show ip route summary")

            # Adding the dict for the vrf to the concatenated dict
            dict_final['vrf'][vrf] = dict_vrf['vrf'][vrf]
        else:
            try:
                dict_vrf = device.parse(f"show ip route vrf {vrf} summary")

                # Adding the dict for the vrf to the concatenated dict
                dict_final['vrf'][vrf] = dict_vrf['vrf'][vrf]

            # The VRF doesn't exist
            except SchemaEmptyParserError as e:
                # Silently dicard the error, and move to the next VRF
                pass

    # Converting as a string to be saved in the DB
    output = json.dumps(dict_final)

    db.add_output(device.name, test_name, output, current_time)
    db.add_timestamp(device.name, test_name, when_tested, current_time)
Exemplo n.º 2
0
def save_boot_system_db(device, folder_images, when_tested, current_time):

    test_name = "boot_system"
    boot_flash = 'False'
    folder_new_os = folder_images['new_os']
    folder_backup_os = folder_images['backup_os']

    # This will return a big string
    config_string = device.execute('show startup')
    # Splitting in a list, for each line in the config
    config = config_string.split('\n')

    for line in config:

        # Matching the first line
        if line in f"boot system bootflash:/{folder_new_os}/packages.conf\r":

            # If the next line is the backup OS (the old one), expected answer.
            if config[config.index(
                    line
            ) + 1] in f"boot system bootflash:/{folder_backup_os}/packages.conf\r":
                boot_flash = 'True'

                # No need to continue
                break

    db.add_output(device.name, test_name, boot_flash, current_time)
    db.add_timestamp(device.name, test_name, when_tested, current_time)
Exemplo n.º 3
0
def save_os_current_version_db(device, when_tested, current_time):

    test_name = "os_version"

    os_current_version = device.parse('show version')['version']['version']

    db.add_output(device.name, test_name, os_current_version, current_time)
    db.add_timestamp(device.name, test_name, when_tested, current_time)
Exemplo n.º 4
0
def save_isis_db(device, when_tested, current_time):

    test_name = "isis"

    # Converting as a string to be saved in the DB
    output = json.dumps(device.parse('show isis neighbors'))

    db.add_output(device.name, test_name, output, current_time)
    db.add_timestamp(device.name, test_name, when_tested, current_time)
Exemplo n.º 5
0
def save_routes_db(device, when_tested, current_time):

    test_name = "routes"

    # Converting as a string to be saved in the DB
    output = json.dumps(device.parse('show ip route vrf *'))

    db.add_output(device.name, test_name, output, current_time)
    db.add_timestamp(device.name, test_name, when_tested, current_time)
Exemplo n.º 6
0
def save_cpu(device, when_tested, current_time):

    test_name = "cpu"

    # Converting int as str, to be saved in the DB
    cpu = str(device.parse('show processes cpu')['five_sec_cpu_total'])

    db.add_output(device.name, test_name, cpu, current_time)
    db.add_timestamp(device.name, test_name, when_tested, current_time)
Exemplo n.º 7
0
def save_xconnect_db(device, when_tested, current_time):

    test_name = "xconnect"

    # Converting as a string to be saved in the DB
    output = json.dumps(device.parse('show xconnect all'))

    db.add_output(device.name, test_name, output, current_time)
    db.add_timestamp(device.name, test_name, when_tested, current_time)
Exemplo n.º 8
0
def save_os_copied_db(device, os_target, rommon_target, folder_images,
                      when_tested, current_time):

    test_name = "os_copied"
    folder_new_os = folder_images['new_os']
    folder_rommon = folder_images['rommon']

    # List of Booleans to store if os has been copied
    # Each item in the list will be the result for each RSP
    # Converted as string, because I can't store booleans in the DB
    os_copied = []

    # Set device attribute `number_rsp` with the number of RSP inserted on the device
    set_number_rsp(device)

    # If device has two RSP, we will also check the files on the standby-bootflash
    if device.number_rsp == 2:
        bootflash_list = ['bootflash', 'stby-bootflash']
    if device.number_rsp == 1:
        bootflash_list = ['bootflash']

    for bootflash in bootflash_list:

        # List to store the names of files that have been successfully copied on the device.
        # Reset to empty for each RSP
        # Will compare to len(os_target)
        number_files_copied = []

        # Verify that the folder exists
        try:

            # Checking OS files
            files = device.parse(f"dir {bootflash}:{folder_new_os}")

            for file in files['dir'][f'{bootflash}:/{folder_new_os}/'][
                    'files']:
                for os in os_target:

                    # If we have a match
                    if file == os:
                        number_files_copied.append(os)

            # Checking Rommon
            files = device.parse(f'dir {bootflash}:{folder_rommon}')

            for file in files['dir'][f'{bootflash}:/{folder_rommon}/'][
                    'files']:
                for rommon in rommon_target:

                    # If we have a match
                    if file == rommon:
                        number_files_copied.append(rommon)

            # If we have all OS + Rommon files
            if len(number_files_copied) == len(os_target) + len(rommon_target):
                os_copied.append("True")
            else:
                os_copied.append("False")

        # If the parser is empty == the directory doesn't exist
        except SchemaEmptyParserError as e:
            # Silently discard it, test is failed by default
            os_copied.append("False")

        # If the parser is not empty == the directory exist, but it is empty
        except SchemaMissingKeyError as e:
            # Silently discard it, test is failed by default
            os_copied.append("False")

    # If the test has not failed for all the RSP, True
    # Else False
    if "False" not in os_copied: os_copied_result = "True"
    else: os_copied_result = "False"

    db.add_output(device.name, test_name, os_copied_result, current_time)
    db.add_timestamp(device.name, test_name, when_tested, current_time)