예제 #1
0
    def check_cpu_device(self, testbed):

        test_name = "CPU %"
        testbed.tests_run.append(test_name)
        logger.info(
            f"Checking the CPU utilisation on the device for the last 5 minutes."
        )

        not_compliant = []

        for device in testbed:

            # If I couldn't connect to the device, this test auto fails
            if device.test_results['connect_device'] == "Fail":
                check.add_result_device(device, test_name, "Fail")

            # Else, let's get the data and test
            if device.test_results['connect_device'] == "Pass":

                # converting str to int
                cpu = int(check.cpu(device.name, when_tested))
                check.add_result_device(device, test_name, cpu)

                # CPU utilisation above 70% => NOK
                if cpu >= 70:
                    not_compliant.append(device.name)
                    logger.error(f"{device.name} CPU is {cpu}.")

        if len(not_compliant) != 0:
            self.failed(f"The above devices CPU utilisation is above 70%.")
예제 #2
0
    def connect_to_devices(self, testbed):

        logger.info("Verifying that I can connect to each device.")
        test_name = "connect_device"
        testbed.tests_run.append(test_name)

        for device in testbed:

            # Tracking each device.test_result
            device.test_results = {}

            # Try if I can connect to the device.
            try:
                device.connect(init_exec_commands=[],
                               init_config_commands=[],
                               log_stdout=False)
                check.add_result_device(device, test_name, "Pass")

            except ConnectionError as e:
                check.add_result_device(device, test_name, "Fail")
                logger.error(f"Could not connect to device {device.name}.")
예제 #3
0
    def check_os_current_version_device(self, testbed):

        test_name = os_target_version
        testbed.tests_run.append(test_name)
        logger.info(f"Checking that each device is using {os_target_version}")

        not_compliant = []

        for device in testbed:

            # If I couldn't connect to the device, this test auto fails
            if device.test_results['connect_device'] == "Fail":
                check.add_result_device(device, test_name, "Fail")

            # Else, let's get the data and test
            if device.test_results['connect_device'] == "Pass":

                os_version = check.os_version(device.name, when_tested)
                check.add_result_device(device, test_name, "Pass")

                # If OS version on the device is wrong, add it to the list
                if os_version != os_target_version:
                    not_compliant.append(device.name)
                    check.add_result_device(device, test_name, "Fail")
                    logger.error(
                        f"{device.name} is not using {os_target_version}. Using {os_version}"
                    )

        if len(not_compliant) != 0:
            self.failed(
                f"The above devices are not using {os_target_version}.")
예제 #4
0
    def check_xconnect_differences(self, testbed):

        test_name = "xconnect"
        testbed.tests_run.append(test_name)
        logger.info(f"Checking the differences before/after for {test_name}.")

        not_compliant = []

        for device in testbed:

            # If I couldn't connect to the device, this test auto fails
            if device.test_results['connect_device'] == "Fail":
                check.add_result_device(device, test_name, "Fail")

            # Else, let's get the data and test
            if device.test_results['connect_device'] == "Pass":
                xconnect_number = check.get_xconnect_before_after(device.name)
                check.add_result_device(device, test_name, "Pass")

                # If we have less than 80% similarity in one way OR another, something is wrong
                if (xconnect_number[0] < xconnect_number[1] * xconnect_delta
                    ) or (xconnect_number[1] <
                          xconnect_number[0] * xconnect_delta):
                    not_compliant.append(device.name)
                    check.add_result_device(device, test_name, "Fail")
                    logger.error(
                        f"{device.name} number of xconnect UP is less than {xconnect_delta*100}% similar before/after."
                    )

        if len(not_compliant) != 0:
            self.failed(
                f"The above devices have a number of xconnect UP exceeding the threshold."
            )
예제 #5
0
    def check_boot_system_order(self, testbed):

        test_name = "boot_system"
        testbed.tests_run.append(test_name)
        logger.info(
            "Checking that the `boot system bootflash:/...` lines are present and in the correct order"
        )

        not_compliant = []

        for device in testbed:

            # If I couldn't connect to the device, this test auto fails
            if device.test_results['connect_device'] == "Fail":
                check.add_result_device(device, test_name, "Fail")

            # Else, let's get the data and test
            if device.test_results['connect_device'] == "Pass":

                # Assume the test Pass
                check.add_result_device(device, test_name, "Pass")

                # If OS is not copied, add its name to the list
                if check.boot_system(device.name, when_tested) != "True":
                    not_compliant.append(device.name)
                    check.add_result_device(device, test_name, "Fail")
                    logger.error(
                        f"`boot system bootflash:/...` command missing on {device.name}"
                    )

        if len(not_compliant) != 0:
            self.failed((
                "`boot system bootflash:/...` missing, not in the right order or\n"
                "not pointing to the right folder on the devices above."))
예제 #6
0
    def check_os_copied_device(self, testbed):

        test_name = "os_copied"
        testbed.tests_run.append(test_name)
        logger.info(
            "Checking that the OS is copied on each device bootflash:/")

        not_compliant = []

        for device in testbed:

            # If I couldn't connect to the device, this test auto fails
            if device.test_results['connect_device'] == "Fail":
                check.add_result_device(device, test_name, "Fail")

            # Else, let's get the data and test
            if device.test_results['connect_device'] == "Pass":

                # Assume the test Pass
                check.add_result_device(device, test_name, "Pass")

                # If OS is not copied, add its name to the list
                if check.os_copied(device.name, os_target_filenames,
                                   when_tested) != "True":
                    not_compliant.append(device.name)
                    check.add_result_device(device, test_name, "Fail")
                    logger.error(f"OS files are missing on {device.name}.")

                if device.number_rsp == 2:
                    logger.info(f"{device.name} has 2 RSP.")

        if len(not_compliant) != 0:
            self.failed(("OS files are not copied on the above devices,\n"
                         "not in the right folder, or folder doesn't exist.\n"
                         "If device has 2 RSP, check the standby-bootflash."))
예제 #7
0
    def check_routes_delta_before_after(self, testbed, protocol, vrf):

        # test_name is a dict
        test_name = {protocol: vrf}
        testbed.tests_run.append(test_name)
        logger.info(f"Checking the differences before/after for {test_name}.")

        not_compliant_before = []
        not_compliant_after = []
        not_compliant_delta = []

        for device in testbed:

            # By default the test Pass. Prove me wrong.
            test_result = "Pass"

            # If I couldn't connect to the device, this test auto fails
            if device.test_results['connect_device'] == "Fail":
                test_result = "Fail"

            # Else, let's get the data and test
            if device.test_results['connect_device'] == "Pass":

                # Does the VRF exist in the `show ip route`? If not, add its name to the not_compliant list
                # Returns a tuple of 2 booleans
                # (vrf_exists_before, vrf_exists_after)
                vrf_exists = check.vrf_exists(device.name, vrf)

                # If the VRF doesn't exist on the router, and it did not exist in the pre-check. Pass.
                if (vrf_exists[0] == False) and (vrf_exists[1] == False):
                    test_result = "Pass"
                    logger.info(
                        f"{vrf} doesn't exist on {device.name}, and did not exist in the pre_checks."
                    )

                # It exists now, but it did not before
                elif vrf_exists[0] == False:
                    not_compliant_before.append(device.name)
                    test_result = "Fail"
                    logger.error(
                        f"{device.name} does not have VRF {vrf} in the pre_check. It does now."
                    )

                # It doesn't exist now, but it did before
                elif vrf_exists[1] == False:
                    not_compliant_after.append(device.name)
                    test_result = "Fail"
                    logger.error(
                        f"{device.name} does not have VRF {vrf} in the post_check. It did in the pre_checks."
                    )

                # If the VRF exists in both, I can compare
                elif (vrf_exists[0] == True) and (vrf_exists[1] == True):
                    routes_number = check.get_routes_before_after(
                        device.name, protocol, vrf)

                    # If we have less than 80% similarity in one way OR another, something is wrong
                    if (routes_number[0] < routes_number[1] *
                            routes_delta) or (routes_number[1] <
                                              routes_number[0] * routes_delta):
                        not_compliant_delta.append(device.name)
                        test_result = "Fail"
                        logger.error(
                            f"{device.name} number of {protocol} routes for VRF {vrf} is less than {routes_delta*100}% similar before/after."
                        )

            check.add_result_device(device, test_name, test_result)

        if len(not_compliant_before) + len(not_compliant_after) + len(
                not_compliant_delta) != 0:
            self.failed(
                f"Test failed. VRF missing or too many routes difference ({routes_delta*100}%). See logs above."
            )