<commit_before># Copyright (c) 2016 Intracom S.A. Telecom Solutions. All rights reserved.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v1.0 which accompanies this distribution,
# and is available at http://www.eclipse.org/legal/epl-v10.html

""" Oftraf Class- All oftraf monitor-related functionality is here. Note that
Oftraf Monitor runs thereto the controller is located (Controller-SB
interface) """

import logging
import os
import requests
import stress_test.oftraf_exceptions
import sys
import traceback
import util.netutil


class Oftraf:

    def __init__(self, controller, test_config):
        """Create an Oftraf Monitor Controller object.
        Options from JSON input file
        :param controller: object of the Controller class
        :param test_config: JSON input configuration
        :type controller: object
        :type test_config: parsed json file with test configuration
        """
        if 'oftraf_test_interval_ms' in test_config:
            self.interval_ms = test_config['oftraf_test_interval_ms']
        else:
            self.interval_ms = 0
        self.rest_server_port = test_config['oftraf_rest_server_port']
        self.rest_server_ip = controller.ip
        self.ssh_user = controller.ssh_user
        self.ssh_pass = controller.ssh_pass

        self.of_port = controller.of_port
        self.status = 'UNKNOWN'
        self._ssh_conn = controller.init_ssh()
        self.traceback_enabled = False

    def __error_handling(self, error_message, error_num=1):
        """Handles custom errors of oftraf
        :param error_message: message of the handled error
        :param error_num: error number of the handled error, used to define
        subcases of raised errors.
        :type error_message: str
        :type error_num: int
        :raises oftraf_exceptions.OftrafError: to terminate execution of
        test after error handling
        """
        exc_type, exc_obj, exc_tb = sys.exc_info()
        logging.error('{0} :::::::::: Exception :::::::::::'.
                      format(exc_obj))
        logging.error(error_message)
        logging.error('Error number:{0}'.format(error_num))
        logging.error('{0} - {1} Exception: {2}, {3}'.
                      format(exc_obj, self.name, exc_type, exc_tb.tb_lineno))
        if self.traceback_enabled:
            traceback.print_exc()
        # Propagate error outside the class to stop execution
        raise(stress_test.oftraf_exceptions.OftrafError)

    def get_oftraf_path(self):
        """Returns oftraf base directory path, using as base to the project
        path
        :returns: oftraf folder path
        :rtype: str
        """
        stress_test_base_dir = os.path.abspath(os.path.join(
            os.path.realpath(__file__), os.pardir))
        monitors_base_dir = os.path.abspath(os.path.join(stress_test_base_dir,
                                                         os.pardir))
        oftraf_path = os.path.sep.join(
            [monitors_base_dir, 'monitors', 'oftraf', ''])
        return str(oftraf_path)

    def build(self):
        """ Wrapper to the oftraf monitor build handler
        :raises IOError: if the handler does not exist on the remote host
        :raises oftraf_exceptions.OftrafBuildError: if build process fails
        """
        logging.info('[Oftraf] Building')
        self.status = 'BUILDING'
        try:
            try:
                oftraf_path = str(self.get_oftraf_path())
                build_hnd = os.path.join(str(oftraf_path), 'build.sh')
                if not util.netutil.isfile(self.rest_server_ip,
                                           self.rest_server_port,
                                           self.ssh_user,
                                           self.ssh_pass,
                                           [build_hnd]):
                    self.status = 'NOT_BUILT'
                    raise(IOError(
                        '{0} build handler does not exist'.
                        format('[nb_generator.build]')))
                else:
                    util.netutil.make_remote_file_executable2(
                        self.ip, self.ssh_port, self.ssh_user, self.ssh_pass,<commit_msg>Instert OFtraf debug msg<commit_after># Copyright (c) 2016 Intracom S.A. Telecom Solutions. All rights reserved.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v1.0 which accompanies this distribution,
# and is available at http://www.eclipse.org/legal/epl-v10.html

""" Oftraf Class- All oftraf monitor-related functionality is here. Note that
Oftraf Monitor runs thereto the controller is located (Controller-SB
interface) """

import logging
import os
import requests
import stress_test.oftraf_exceptions
import sys
import traceback
import util.netutil


class Oftraf:

    def __init__(self, controller, test_config):
        """Create an Oftraf Monitor Controller object.
        Options from JSON input file
        :param controller: object of the Controller class
        :param test_config: JSON input configuration
        :type controller: object
        :type test_config: parsed json file with test configuration
        """
        if 'oftraf_test_interval_ms' in test_config:
            self.interval_ms = test_config['oftraf_test_interval_ms']
        else:
            self.interval_ms = 0
        self.rest_server_port = test_config['oftraf_rest_server_port']
        self.rest_server_ip = controller.ip
        self.ssh_user = controller.ssh_user
        self.ssh_pass = controller.ssh_pass

        self.of_port = controller.of_port
        self.status = 'UNKNOWN'
        self._ssh_conn = controller.init_ssh()
        self.traceback_enabled = False

    def __error_handling(self, error_message, error_num=1):
        """Handles custom errors of oftraf
        :param error_message: message of the handled error
        :param error_num: error number of the handled error, used to define
        subcases of raised errors.
        :type error_message: str
        :type error_num: int
        :raises oftraf_exceptions.OftrafError: to terminate execution of
        test after error handling
        """
        exc_type, exc_obj, exc_tb = sys.exc_info()
        logging.error('{0} :::::::::: Exception :::::::::::'.
                      format(exc_obj))
        logging.error(error_message)
        logging.error('Error number:{0}'.format(error_num))
        logging.error('{0} - {1} Exception: {2}, {3}'.
                      format(exc_obj, self.name, exc_type, exc_tb.tb_lineno))
        if self.traceback_enabled:
            traceback.print_exc()
        # Propagate error outside the class to stop execution
        raise(stress_test.oftraf_exceptions.OftrafError)

    def get_oftraf_path(self):
        """Returns oftraf base directory path, using as base to the project
        path
        :returns: oftraf folder path
        :rtype: str
        """
        stress_test_base_dir = os.path.abspath(os.path.join(
            os.path.realpath(__file__), os.pardir))
        monitors_base_dir = os.path.abspath(os.path.join(stress_test_base_dir,
                                                         os.pardir))
        oftraf_path = os.path.sep.join(
            [monitors_base_dir, 'monitors', 'oftraf', ''])
        print(oftraf_path)
        exit()
        return str(oftraf_path)

    def build(self):
        """ Wrapper to the oftraf monitor build handler
        :raises IOError: if the handler does not exist on the remote host
        :raises oftraf_exceptions.OftrafBuildError: if build process fails
        """
        logging.info('[Oftraf] Building')
        self.status = 'BUILDING'
        try:
            try:
                oftraf_path = str(self.get_oftraf_path())
                build_hnd = os.path.join(str(oftraf_path), 'build.sh')
                if not util.netutil.isfile(self.rest_server_ip,
                                           self.rest_server_port,
                                           self.ssh_user,
                                           self.ssh_pass,
                                           [build_hnd]):
                    self.status = 'NOT_BUILT'
                    raise(IOError(
                        '{0} build handler does not exist'.
                        format('[nb_generator.build]')))
                else:
                    util.netutil.make_remote_file_executable2(
                        self.ip, self.ssh_port, self.ssh_user, self.ssh_pass,
{'fraction_non_alphanumeric': 0.08444806327788763, 'fraction_numerical': 0.0041875072699778994, 'mean_word_length': 2.051100070972321, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2843959', 'n_tokens_mistral': 2415, 'n_tokens_neox': 2301, 'n_words': 624}