コード例 #1
0
ファイル: test_acl.py プロジェクト: simonvonwinkle/sonic-mgmt
    def acl_rules(self, duthost, localhost, setup, acl_table):
        """
        setup/teardown ACL rules based on test class requirements
        :param duthost: DUT host object
        :param localhost: localhost object
        :param setup: setup information
        :param acl_table: table creating fixture
        :return:
        """

        loganalyzer = LogAnalyzer(ansible_host=duthost, marker_prefix='acl_rules')
        loganalyzer.load_common_config()

        try:
            loganalyzer.expect_regex = [LOG_EXPECT_ACL_RULE_CREATE_RE]
            with loganalyzer:
                self.setup_rules(duthost, setup, acl_table)
            self.post_setup_hook(duthost, localhost)
        except LogAnalyzerError as err:
            # cleanup config DB in case of log analysis error
            self.teardown_rules(duthost, setup)
            raise err

        try:
            yield
        finally:
            loganalyzer.expect_regex = [LOG_EXPECT_ACL_RULE_REMOVE_RE]
            with loganalyzer:
                self.teardown_rules(duthost, setup)
コード例 #2
0
ファイル: test_acl.py プロジェクト: simonvonwinkle/sonic-mgmt
def acl_table(duthost, acl_table_config):
    """
    fixture to apply ACL table configuration and remove after tests
    :param duthost: DUT object
    :param acl_table_config: ACL table configuration dictionary
    :return: forwards acl_table_config
    """

    name = acl_table_config['name']
    conf = acl_table_config['config_file']

    loganalyzer = LogAnalyzer(ansible_host=duthost, marker_prefix='acl')
    loganalyzer.load_common_config()

    try:
        loganalyzer.expect_regex = [LOG_EXPECT_ACL_TABLE_CREATE_RE]
        with loganalyzer:
            logger.info('creating ACL table: applying {}'.format(conf))
            # TODO: use sonic config CLI
            duthost.command('sonic-cfggen -j {} --write-to-db'.format(conf))
    except LogAnalyzerError as err:
        # cleanup config DB if create failed
        duthost.command('config acl remove table {}'.format(name))
        raise err

    try:
        yield acl_table_config
    finally:
        loganalyzer.expect_regex = [LOG_EXPECT_ACL_TABLE_REMOVE_RE]
        with loganalyzer:
            logger.info('removing ACL table {}'.format(name))
            duthost.command('config acl remove table {}'.format(name))

        # save cleaned configuration
        duthost.command('config save -y')
コード例 #3
0
def check_thermal_control_load_invalid_file(testbed_devices, file_name):
    """
    @summary: Load an invalid thermal policy file check thermal
              control daemon is up and there is an error log printed
    """
    dut = testbed_devices["dut"]
    loganalyzer = LogAnalyzer(ansible_host=dut,
                              marker_prefix='thermal_control')
    with ThermalPolicyFileContext(dut, file_name):
        loganalyzer.expect_regex = [LOG_EXPECT_POLICY_FILE_INVALID]
        with loganalyzer:
            restart_thermal_control_daemon(dut)
コード例 #4
0
def test_thermal_control_fan_status(testbed_devices, mocker_factory):
    """
    @summary: Make FAN absence, over speed and under speed, check logs and LED color.
    """
    dut = testbed_devices["dut"]
    loganalyzer = LogAnalyzer(ansible_host=dut,
                              marker_prefix='thermal_control')
    loganalyzer.load_common_config()

    with ThermalPolicyFileContext(dut, THERMAL_POLICY_VALID_FILE):
        fan_mocker = mocker_factory(dut, 'FanStatusMocker')
        if fan_mocker is None:
            pytest.skip(
                "No FanStatusMocker for %s, skip rest of the testing in this case"
                % dut.facts['asic_type'])

        logging.info('Mock FAN status data...')
        fan_mocker.mock_data()  # make data random
        restart_thermal_control_daemon(dut)
        wait_until(THERMAL_CONTROL_TEST_WAIT_TIME,
                   THERMAL_CONTROL_TEST_CHECK_INTERVAL,
                   fan_mocker.check_all_fan_speed, 60)
        check_thermal_algorithm_status(dut, mocker_factory, False)

        single_fan_mocker = mocker_factory(dut, 'SingleFanMocker')
        time.sleep(THERMAL_CONTROL_TEST_WAIT_TIME)
        loganalyzer.expect_regex = [LOG_EXPECT_FAN_REMOVE_RE]
        with loganalyzer:
            logging.info('Mocking an absence FAN...')
            single_fan_mocker.mock_absence()
            check_cli_output_with_mocker(dut, single_fan_mocker,
                                         CMD_PLATFORM_FANSTATUS,
                                         THERMAL_CONTROL_TEST_WAIT_TIME)

        loganalyzer.expect_regex = [LOG_EXPECT_FAN_REMOVE_CLEAR_RE]
        with loganalyzer:
            logging.info('Make the absence FAN back to presence...')
            single_fan_mocker.mock_presence()
            check_cli_output_with_mocker(dut, single_fan_mocker,
                                         CMD_PLATFORM_FANSTATUS,
                                         THERMAL_CONTROL_TEST_WAIT_TIME)

        loganalyzer.expect_regex = [LOG_EXPECT_FAN_OVER_SPEED_RE]
        with loganalyzer:
            logging.info('Mocking an over speed FAN...')
            single_fan_mocker.mock_over_speed()
            check_cli_output_with_mocker(dut, single_fan_mocker,
                                         CMD_PLATFORM_FANSTATUS,
                                         THERMAL_CONTROL_TEST_WAIT_TIME)

        loganalyzer.expect_regex = [LOG_EXPECT_FAN_OVER_SPEED_CLEAR_RE]
        with loganalyzer:
            logging.info('Make the over speed FAN back to normal...')
            single_fan_mocker.mock_normal_speed()
            check_cli_output_with_mocker(dut, single_fan_mocker,
                                         CMD_PLATFORM_FANSTATUS,
                                         THERMAL_CONTROL_TEST_WAIT_TIME)

        loganalyzer.expect_regex = [LOG_EXPECT_FAN_UNDER_SPEED_RE]
        with loganalyzer:
            logging.info('Mocking an under speed FAN...')
            single_fan_mocker.mock_under_speed()
            check_cli_output_with_mocker(dut, single_fan_mocker,
                                         CMD_PLATFORM_FANSTATUS,
                                         THERMAL_CONTROL_TEST_WAIT_TIME)

        loganalyzer.expect_regex = [LOG_EXPECT_FAN_UNDER_SPEED_CLEAR_RE]
        with loganalyzer:
            logging.info('Make the under speed FAN back to normal...')
            single_fan_mocker.mock_normal_speed()
            check_cli_output_with_mocker(dut, single_fan_mocker,
                                         CMD_PLATFORM_FANSTATUS,
                                         THERMAL_CONTROL_TEST_WAIT_TIME)