Esempio n. 1
0
def component_subparser():
    """
    A sub parser with one argument "-a"
    """
    subparser = ComponentSubParser('test')
    subparser.add_argument('a', flag=True)
    return subparser
Esempio n. 2
0
def test_component_subparser():
    """
    test to parse strings with a formula parser and retrieve the following results :
    - "" : {}
    - "--sub toto -b" :  {a:True, sub: {'toto' : {b: True}}}
    - "-b" : BadContextException(b, [toto])

    Parser description :

    - formula subparser toto binded to the argument sub with sub arguments : -b and --name
    """
    parser = MainParser(help_arg=False)

    subparser = ComponentSubParser('toto')
    subparser.add_argument('b', flag=True, action=store_true)
    parser.add_component_subparser('sub', subparser)

    check_parsing_result(parser, '', {})

    check_parsing_result(parser, '--sub toto -b',
                         {'sub': {
                             'toto': {
                                 'b': True
                             }
                         }})

    with pytest.raises(BadContextException):
        check_parsing_result(parser, '-b', None)
Esempio n. 3
0
def test_subparser_empty_token_list_default_value():
    subparser = ComponentSubParser('toto')
    subparser.add_argument('a', default=1)
    acc, result = subparser.subparse([])
    assert len(result) == 1
    assert 'a' in result
    assert result['a'] == 1
    assert acc == []
Esempio n. 4
0
def test_create_two_with_different_type_component():
    """
    Create two component with different type with the following cli :
    --sub toto --name titi --sub tutu --name tete

    test if the result is :
    {sub:{'titi' : {'type': 'toto'}, 'tete': {'type': 'tutu'}}}

    """
    parser = MainParser(help_arg=False)

    subparser = ComponentSubParser('toto')
    subparser.add_argument('n', 'name')
    parser.add_actor_subparser('sub', subparser)

    subparser = ComponentSubParser('tutu')
    subparser.add_argument('n', 'name')
    parser.add_actor_subparser('sub', subparser)

    check_parsing_result(
        parser, '--sub toto --name titi --sub tutu --name tete',
        {'sub': {
            'titi': {
                'type': 'toto'
            },
            'tete': {
                'type': 'tutu'
            }
        }})
Esempio n. 5
0
def test_add_component_subparser_that_aldready_exists2():
    """
    Add a component_subparser with no argument 'name'
    test if a SubParserWithoutNameArgumentException is raised
    """
    parser = MainParser(help_arg=False)
    subparser = ComponentSubParser('titi')

    with pytest.raises(SubParserWithoutNameArgumentException):
        parser.add_actor_subparser('toto', subparser)
Esempio n. 6
0
def test_add_actor_subparser_that_aldready_exists():
    """
    Add a component_subparser that already exists to a parser and test if an
    AlreadyAddedArgumentException is raised
    """
    parser = MainParser(help_arg=False)
    subparser = ComponentSubParser('titi')
    subparser.add_argument('n', 'name')
    parser.add_actor_subparser('toto', subparser)
    subparser2 = ComponentSubParser('titi')
    subparser2.add_argument('n', 'name')

    with pytest.raises(AlreadyAddedArgumentException):
        parser.add_actor_subparser('toto', subparser2)
Esempio n. 7
0
def test_create_two_component():
    """
    Create two component of the same type with the following cli :
    --sub toto --name titi --sub toto -b --name tutu

    test if the result is :
    {sub:{'titi' : {'type': 'toto'}, 'tutu': {'type': 'toto', 'b':True}}}

    """
    parser = MainParser(help_arg=False)

    subparser = ComponentSubParser('toto')
    subparser.add_argument('b', flag=True, action=store_true)
    subparser.add_argument('n', 'name')
    parser.add_actor_subparser('sub', subparser)

    check_parsing_result(parser,
                         '--sub toto --name titi --sub toto -b --name tutu', {
                             'sub': {
                                 'titi': {
                                     'type': 'toto'
                                 },
                                 'tutu': {
                                     'type': 'toto',
                                     'b': True
                                 }
                             }
                         })
Esempio n. 8
0
def test_add_component_subparser_with_two_name():
    """
    add a component subparser with one short name and one long name
    parse a string and test if the value is only bind to the long name
    """
    parser = MainParser(help_arg=False)
    subparser = ComponentSubParser('titi')
    subparser.add_argument('a', 'aaa', flag=True, action=store_true, default=False)
    subparser.add_argument('n', 'name')
    parser.add_component_subparser('sub', subparser)
    check_parsing_result(parser, '--sub titi -a --name tutu', {'sub': {'titi': {'tutu': {'aaa': True, 'name': 'tutu'}}}})
Esempio n. 9
0
def test_actor_subparser():
    """
    test to parse strings with a parser and retrieve the following results :

    - "" : {}
    - "-z" : UnknowArgException(z)
    - "-a" : {a: True}
    - "-a --sub toto -b" : NoNameSpecifiedForComponentException
    - "-a --sub toto -b --name titi" : {a:True, sub: { titi: { 'type': 'toto', b: True}}}
    - "-b" : BadContextException(b, [toto])

    Parser description :

    - base parser arguments : -a
    - subparser toto binded to the argument sub with sub arguments : -b and --name
    """
    parser = MainParser(help_arg=False)
    parser.add_argument('a', flag=True, action=store_true)

    subparser = ComponentSubParser('toto')
    subparser.add_argument('b', flag=True, action=store_true)
    subparser.add_argument('n', 'name')
    parser.add_actor_subparser('sub', subparser)

    check_parsing_result(parser, '', {})

    with pytest.raises(UnknowArgException):
        check_parsing_result(parser, '-z', None)

    check_parsing_result(parser, '-a', {'a': True})

    with pytest.raises(NoNameSpecifiedForComponentException):
        check_parsing_result(parser, '-a --sub toto -b', {})

    check_parsing_result(parser, '-a --sub toto -b --name titi', {
        'a': True,
        'sub': {
            'titi': {
                'type': 'toto',
                'b': True
            }
        }
    })

    with pytest.raises(BadContextException):
        check_parsing_result(parser, '-b', None)
Esempio n. 10
0
def test_create_component_that_already_exist():
    """
    Create two component with the same name with the following cli
    --sub toto --name titi --sub toto --name titi

    test if an ComponentAlreadyExistException is raised
    """
    parser = MainParser(help_arg=False)

    subparser = ComponentSubParser('toto')
    subparser.add_argument('b', flag=True, action=store_true)
    subparser.add_argument('n', 'name')
    parser.add_actor_subparser('sub', subparser)

    with pytest.raises(ComponentAlreadyExistException):
        check_parsing_result(parser,
                             '--sub toto --name titi --sub toto --name titi',
                             None)
Esempio n. 11
0
 def __init__(self, name: str):
     ConfigParser.__init__(self)
     self.subparser = {}
     self.cli_parser = ComponentSubParser(name)
     self.name = name
Esempio n. 12
0
    def __init__(self):
        MainParser.__init__(self)

        self.add_argument('v',
                          'verbose',
                          flag=True,
                          action=enable_log,
                          default=logging.NOTSET,
                          help='enable verbose mode')
        self.add_argument('s',
                          'stream',
                          flag=True,
                          action=store_true,
                          default=False,
                          help='enable stream mode')

        subparser_mongo_input = ComponentSubParser('mongodb')
        subparser_mongo_input.add_argument('u',
                                           'uri',
                                           help='sepcify MongoDB uri')
        subparser_mongo_input.add_argument(
            'd',
            'db',
            help='specify MongoDB database name',
        )
        subparser_mongo_input.add_argument(
            'c', 'collection', help='specify MongoDB database collection')
        subparser_mongo_input.add_argument('n',
                                           'name',
                                           help='specify puller name',
                                           default='puller_mongodb')
        subparser_mongo_input.add_argument(
            'm',
            'model',
            help='specify data type that will be storen in the database',
            default='HWPCReport')
        self.add_component_subparser(
            'input',
            subparser_mongo_input,
            help_str=
            'specify a database input : --db_output database_name ARG1 ARG2 ... '
        )

        subparser_socket_input = ComponentSubParser('socket')
        subparser_socket_input.add_argument(
            'p', 'port', help='specify port to bind the socket')
        subparser_socket_input.add_argument('n',
                                            'name',
                                            help='specify puller name',
                                            default='puller_socket')
        subparser_socket_input.add_argument(
            'm',
            'model',
            help='specify data type that will be sent through the socket',
            default='HWPCReport')
        self.add_component_subparser(
            'input',
            subparser_socket_input,
            help_str=
            'specify a database input : --db_output database_name ARG1 ARG2 ... '
        )

        subparser_csv_input = ComponentSubParser('csv')
        subparser_csv_input.add_argument(
            'f',
            'files',
            help='specify input csv files with this format : file1,file2,file3',
            action=extract_file_names,
            default=[],
            check=check_csv_files,
            check_msg='one or more csv files couldn\'t be read')
        subparser_csv_input.add_argument(
            'm',
            'model',
            help='specify data type that will be storen in the database',
            default='HWPCReport')
        subparser_csv_input.add_argument('n',
                                         'name',
                                         help='specify puller name',
                                         default='puller_csv')
        self.add_component_subparser(
            'input',
            subparser_csv_input,
            help_str=
            'specify a database input : --db_output database_name ARG1 ARG2 ... '
        )

        subparser_mongo_output = ComponentSubParser('mongodb')
        subparser_mongo_output.add_argument('u',
                                            'uri',
                                            help='sepcify MongoDB uri')
        subparser_mongo_output.add_argument(
            'd', 'db', help='specify MongoDB database name')
        subparser_mongo_output.add_argument(
            'c', 'collection', help='specify MongoDB database collection')

        subparser_mongo_output.add_argument(
            'm',
            'model',
            help='specify data type that will be storen in the database',
            default='PowerReport')
        subparser_mongo_output.add_argument('n',
                                            'name',
                                            help='specify puller name',
                                            default='pusher_mongodb')
        self.add_component_subparser(
            'output',
            subparser_mongo_output,
            help_str=
            'specify a database output : --db_output database_name ARG1 ARG2 ...'
        )

        subparser_csv_output = ComponentSubParser('csv')
        subparser_csv_output.add_argument(
            'd',
            'directory',
            help=
            'specify directory where where output  csv files will be writen')
        subparser_csv_output.add_argument(
            'm',
            'model',
            help='specify data type that will be storen in the database',
            default='PowerReport')
        subparser_csv_output.add_argument('n',
                                          'name',
                                          help='specify puller name',
                                          default='pusher_csv')
        self.add_component_subparser(
            'output',
            subparser_csv_output,
            help_str=
            'specify a database input : --db_output database_name ARG1 ARG2 ... '
        )

        subparser_influx_output = ComponentSubParser('influxdb')
        subparser_influx_output.add_argument('u',
                                             'uri',
                                             help='sepcify InfluxDB uri')
        subparser_influx_output.add_argument(
            'd', 'db', help='specify InfluxDB database name')
        subparser_influx_output.add_argument(
            'p', 'port', help='specify InfluxDB connection port', type=int)
        subparser_influx_output.add_argument(
            'm',
            'model',
            help='specify data type that will be storen in the database',
            default='PowerReport')
        subparser_influx_output.add_argument('n',
                                             'name',
                                             help='specify puller name',
                                             default='pusher_influxdb')
        self.add_component_subparser(
            'output',
            subparser_influx_output,
            help_str=
            'specify a database input : --db_output database_name ARG1 ARG2 ... '
        )

        subparser_opentsdb_output = ComponentSubParser('opentsdb')
        subparser_opentsdb_output.add_argument('u',
                                               'uri',
                                               help='sepcify openTSDB host')
        subparser_opentsdb_output.add_argument(
            'p', 'port', help='specify openTSDB connection port', type=int)
        subparser_opentsdb_output.add_argument('metric_name',
                                               help='specify metric name')

        subparser_opentsdb_output.add_argument(
            'm',
            'model',
            help='specify data type that will be storen in the database',
            default='PowerReport')
        subparser_opentsdb_output.add_argument('n',
                                               'name',
                                               help='specify puller name',
                                               default='pusher_opentsdb')
        self.add_component_subparser(
            'output',
            subparser_opentsdb_output,
            help_str=
            'specify a database input : --db_output database_name ARG1 ARG2 ... '
        )
Esempio n. 13
0
def generate_selfwatts_parser() -> ComponentSubParser:
    """
    Construct and returns the SelfWatts cli parameters parser.
    :return: SelfWatts cli parameters parser
    """
    parser = ComponentSubParser('selfwatts')

    # Formula control parameters
    parser.add_argument('disable-cpu-formula', help='Disable CPU formula', flag=True, type=bool, default=False, action=store_true)
    parser.add_argument('disable-dram-formula', help='Disable DRAM formula', flag=True, type=bool, default=False, action=store_true)

    # Formula RAPL reference event
    parser.add_argument('cpu-rapl-ref-event', help='RAPL event used as reference for the CPU power models', default='RAPL_ENERGY_PKG')
    parser.add_argument('dram-rapl-ref-event', help='RAPL event used as reference for the DRAM power models', default='RAPL_ENERGY_DRAM')

    # CPU topology information
    parser.add_argument('cpu-tdp', help='CPU TDP (in Watt)', type=int, default=125)
    parser.add_argument('cpu-base-clock', help='CPU base clock (in MHz)', type=int, default=100)
    parser.add_argument('cpu-ratio-min', help='CPU minimal frequency ratio', type=int, default=10)
    parser.add_argument('cpu-ratio-base', help='CPU base frequency ratio', type=int, default=23)
    parser.add_argument('cpu-ratio-max', help='CPU maximal frequency ratio (with Turbo-Boost)', type=int, default=40)
    parser.add_argument('cpu-num-fixed-counters', help='CPU number of available fixed counters', type=int, default=3)
    parser.add_argument('cpu-num-general-counters', help='CPU number of available general counters', type=int, default=4)

    # Formula error threshold
    parser.add_argument('cpu-error-threshold', help='Error threshold for the CPU power models (in Watt)', type=float, default=2.0)
    parser.add_argument('dram-error-threshold', help='Error threshold for the DRAM power models (in Watt)', type=float, default=2.0)

    # Sensor information
    parser.add_argument('sensor-reports-frequency', help='The frequency with which measurements are made (in milliseconds)', type=int, default=1000)

    # Learning parameters
    parser.add_argument('learn-min-samples-required', help='Minimum amount of samples required before trying to learn a power model', type=int, default=10)
    parser.add_argument('learn-history-window-size', help='Size of the history window used to keep samples to learn from', type=int, default=60)

    # Controller parameters
    parser.add_argument('controller-fixed-events', help='List of events name fixed in the controller', type=str, default='')

    return parser
Esempio n. 14
0
    def __init__(self):
        MainParser.__init__(self)

        self.add_argument('v',
                          'verbose',
                          flag=True,
                          action=enable_log,
                          default=logging.NOTSET,
                          help='enable verbose mode')
        self.add_argument('s',
                          'stream',
                          flag=True,
                          action=store_true,
                          default=False,
                          help='enable stream mode')

        subparser_mongo_input = ComponentSubParser('mongodb')
        subparser_mongo_input.add_argument('u',
                                           'uri',
                                           help='specify MongoDB uri')
        subparser_mongo_input.add_argument(
            'd',
            'db',
            help='specify MongoDB database name',
        )
        subparser_mongo_input.add_argument(
            'c', 'collection', help='specify MongoDB database collection')
        subparser_mongo_input.add_argument('n',
                                           'name',
                                           help='specify puller name',
                                           default='puller_mongodb')
        subparser_mongo_input.add_argument(
            'm',
            'model',
            help='specify data type that will be storen in the database',
            default='HWPCReport')
        self.add_component_subparser(
            'input',
            subparser_mongo_input,
            help_str=
            'specify a database input : --db_output database_name ARG1 ARG2 ... '
        )

        subparser_socket_input = ComponentSubParser('socket')
        subparser_socket_input.add_argument(
            'p', 'port', help='specify port to bind the socket')
        subparser_socket_input.add_argument('n',
                                            'name',
                                            help='specify puller name',
                                            default='puller_socket')
        subparser_socket_input.add_argument(
            'm',
            'model',
            help='specify data type that will be sent through the socket',
            default='HWPCReport')
        self.add_component_subparser(
            'input',
            subparser_socket_input,
            help_str=
            'specify a database input : --db_output database_name ARG1 ARG2 ... '
        )

        subparser_daemon_input = ComponentSubParser('tcp')
        subparser_daemon_input.add_argument('p',
                                            'port',
                                            help='specify the port to connect')
        subparser_daemon_input.add_argument('n',
                                            'name',
                                            help='specify puller name',
                                            default="puller_tcp")
        subparser_daemon_input.add_argument(
            'u',
            'uri',
            help='specify the address of the puller',
            default='localhost')
        subparser_daemon_input.add_argument(
            'm',
            'model',
            help='specify data type that will be sent through the socket',
            default='HWPCReport')

        self.add_component_subparser(
            'input',
            subparser_daemon_input,
            help_str='specify a tcp input : -p 8000 -a localhost ... ')

        subparser_csv_input = ComponentSubParser('csv')
        subparser_csv_input.add_argument(
            'f',
            'files',
            help='specify input csv files with this format : file1,file2,file3',
            action=extract_file_names,
            default=[],
            check=check_csv_files,
            check_msg='one or more csv files couldn\'t be read')
        subparser_csv_input.add_argument(
            'm',
            'model',
            help='specify data type that will be storen in the database',
            default='HWPCReport')
        subparser_csv_input.add_argument('n',
                                         'name',
                                         help='specify puller name',
                                         default='puller_csv')
        self.add_component_subparser(
            'input',
            subparser_csv_input,
            help_str=
            'specify a database input : --db_output database_name ARG1 ARG2 ... '
        )

        subparser_mongo_output = ComponentSubParser('mongodb')
        subparser_mongo_output.add_argument('u',
                                            'uri',
                                            help='specify MongoDB uri')
        subparser_mongo_output.add_argument(
            'd', 'db', help='specify MongoDB database name')
        subparser_mongo_output.add_argument(
            'c', 'collection', help='specify MongoDB database collection')

        subparser_mongo_output.add_argument(
            'm',
            'model',
            help='specify data type that will be storen in the database',
            default='PowerReport')
        subparser_mongo_output.add_argument('n',
                                            'name',
                                            help='specify puller name',
                                            default='pusher_mongodb')
        self.add_component_subparser(
            'output',
            subparser_mongo_output,
            help_str=
            'specify a database output : --db_output database_name ARG1 ARG2 ...'
        )

        subparser_prom_output = ComponentSubParser('prom')
        subparser_prom_output.add_argument('a',
                                           'addr',
                                           help='specify server address')
        subparser_prom_output.add_argument('p',
                                           'port',
                                           help='specify server port',
                                           type=int)
        subparser_prom_output.add_argument('M',
                                           'metric_name',
                                           help='speify metric name')
        subparser_prom_output.add_argument('d',
                                           'metric_description',
                                           help='specify metric description',
                                           default='energy consumption')
        subparser_prom_output.add_argument(
            'A',
            'aggregation_period',
            help=
            'specify number of second for the value must be aggregated before compute statistics on them',
            default=15,
            type=int)

        subparser_prom_output.add_argument(
            'm',
            'model',
            help='specify data type that will be storen in the database',
            default='PowerReport')
        subparser_prom_output.add_argument('n',
                                           'name',
                                           help='specify puller name',
                                           default='pusher_prom')
        self.add_component_subparser(
            'output',
            subparser_prom_output,
            help_str=
            'specify a database output : --db_output database_name ARG1 ARG2 ...'
        )

        subparser_csv_output = ComponentSubParser('csv')
        subparser_csv_output.add_argument(
            'd',
            'directory',
            help=
            'specify directory where where output  csv files will be writen')
        subparser_csv_output.add_argument(
            'm',
            'model',
            help='specify data type that will be storen in the database',
            default='PowerReport')
        subparser_csv_output.add_argument('n',
                                          'name',
                                          help='specify puller name',
                                          default='pusher_csv')
        self.add_component_subparser(
            'output',
            subparser_csv_output,
            help_str=
            'specify a database input : --db_output database_name ARG1 ARG2 ... '
        )

        subparser_influx_output = ComponentSubParser('influxdb')
        subparser_influx_output.add_argument('u',
                                             'uri',
                                             help='specify InfluxDB uri')
        subparser_influx_output.add_argument(
            'd', 'db', help='specify InfluxDB database name')
        subparser_influx_output.add_argument(
            'p', 'port', help='specify InfluxDB connection port', type=int)
        subparser_influx_output.add_argument(
            'm',
            'model',
            help='specify data type that will be storen in the database',
            default='PowerReport')
        subparser_influx_output.add_argument('n',
                                             'name',
                                             help='specify puller name',
                                             default='pusher_influxdb')
        self.add_component_subparser(
            'output',
            subparser_influx_output,
            help_str=
            'specify a database input : --db_output database_name ARG1 ARG2 ... '
        )

        subparser_opentsdb_output = ComponentSubParser('opentsdb')
        subparser_opentsdb_output.add_argument('u',
                                               'uri',
                                               help='specify openTSDB host')
        subparser_opentsdb_output.add_argument(
            'p', 'port', help='specify openTSDB connection port', type=int)
        subparser_opentsdb_output.add_argument('metric_name',
                                               help='specify metric name')

        subparser_opentsdb_output.add_argument(
            'm',
            'model',
            help='specify data type that will be storen in the database',
            default='PowerReport')
        subparser_opentsdb_output.add_argument('n',
                                               'name',
                                               help='specify puller name',
                                               default='pusher_opentsdb')
        self.add_component_subparser(
            'output',
            subparser_opentsdb_output,
            help_str=
            'specify a database input : --db_output database_name ARG1 ARG2 ... '
        )

        subparser_tcp_output = ComponentSubParser('tcp')
        subparser_tcp_output.add_argument('p', 'port', help="the port to bind")
        subparser_tcp_output.add_argument('u',
                                          'uri',
                                          help="the address to bind",
                                          default="0.0.0.0")
        subparser_tcp_output.add_argument(
            'm',
            'model',
            help='specify data type that will be send in the stream',
            default='PowerReport')
        subparser_tcp_output.add_argument('n',
                                          'name',
                                          help='specify pusher name',
                                          default='pusher_tcp')
        self.add_component_subparser(
            'output',
            subparser_tcp_output,
            help_str='specify a tcp output : -p 8001 -m PowerReport ... ')
Esempio n. 15
0
    def __init__(self):
        MainParser.__init__(self)

        self.add_argument('v',
                          'verbose',
                          flag=True,
                          action=enable_log,
                          default=logging.NOTSET,
                          help='enable verbose mode')
        self.add_argument('s',
                          'stream',
                          flag=True,
                          action=store_true,
                          default=False,
                          help='enable stream mode')

        subparser_mongo_input = ComponentSubParser('mongodb')
        subparser_mongo_input.add_argument('u',
                                           'uri',
                                           help='sepcify MongoDB uri')
        subparser_mongo_input.add_argument(
            'd', 'db', help='specify MongoDB database name')
        subparser_mongo_input.add_argument(
            'c', 'collection', help='specify MongoDB database collection')
        subparser_mongo_input.add_argument(
            'm',
            'model',
            help='specify data type that will be storen in the database',
            default='hwpc_report')

        subparser_mongo_output = ComponentSubParser('mongodb')
        subparser_mongo_output.add_argument('u',
                                            'uri',
                                            help='sepcify MongoDB uri')
        subparser_mongo_output.add_argument(
            'd', 'db', help='specify MongoDB database name')
        subparser_mongo_output.add_argument(
            'c', 'collection', help='specify MongoDB database collection')
        subparser_mongo_output.add_argument(
            'm',
            'model',
            help='specify data type that will be storen in the database',
            default='power_report')

        self.add_component_subparser(
            'output',
            subparser_mongo_output,
            help_str=
            'specify a database output : --db_output database_name ARG1 ARG2 ...'
        )
        self.add_component_subparser(
            'input',
            subparser_mongo_input,
            help_str=
            'specify a database input : --db_output database_name ARG1 ARG2 ... '
        )