# Path: monasca_api/common/repositories/model/sub_alarm_definition.py
# class SubAlarmDefinition(object):
#     def __init__(self, row=None, sub_expr=None):
#     def _init_dimensions(self, dimensions_str):
#     def expression(self):
#     def __hash__(self):
#     def __repr__(self):
#     def __eq__(self, other):
#     def same_key_fields(self, other):
# 
# Path: monasca_api/common/repositories/sqla/models.py
# def get_all_metadata():
# def create_a_model(metadata=None):
# def create_sadd_model(metadata=None):
# def create_aa_model(metadata=None):
# def create_md_model(metadata=None):
# def create_mde_model(metadata=None):
# def create_nm_model(metadata=None):
# def create_nmt_model(metadata=None):
# def create_mdd_model(metadata=None):
# def create_am_model(metadata=None):
# def create_ad_model(metadata=None):
# def create_sa_model(metadata=None):
# def create_sad_model(metadata=None):
#     def __init__(self, columns, separator=',', order_by=None):
# def _group_concat_oracle(element, compiler_, **kw):
# def _group_concat_postgresql(element, compiler_, **kw):
# def _group_concat_sybase(element, compiler_, **kw):
# def _group_concat_mysql(element, compiler_, **kw):
# def _group_concat_default(element, compiler_, **kw):
#     def __init__(self, column, fields):
# def _field_sort_mysql(element, compiler_, **kw):
# def _field_sort_general(element, compiler_, **kw):
# class group_concat(expression.ColumnElement):
# class field_sort(expression.ColumnElement):
# 
# Path: monasca_api/expression_parser/alarm_expr_parser.py
# _DETERMINISTIC_ASSIGNMENT_LEN = 3
# _DETERMINISTIC_ASSIGNMENT_SHORT_LEN = 1
# _DETERMINISTIC_ASSIGNMENT_VALUE_INDEX = 2
# _DEFAULT_PERIOD = 60
# _DEFAULT_PERIODS = 1
# COMMA = pyparsing.Suppress(pyparsing.Literal(","))
# LPAREN = pyparsing.Suppress(pyparsing.Literal("("))
# RPAREN = pyparsing.Suppress(pyparsing.Literal(")"))
# EQUAL = pyparsing.Literal("=")
# LBRACE = pyparsing.Suppress(pyparsing.Literal("{"))
# RBRACE = pyparsing.Suppress(pyparsing.Literal("}"))
# MINUS = pyparsing.Literal('-')
# AND = pyparsing.CaselessLiteral("and") | pyparsing.CaselessLiteral("&&")
# OR = pyparsing.CaselessLiteral("or") | pyparsing.CaselessLiteral("||")
# class SubExpr(object):
# class BinaryOp(object):
# class AndSubExpr(BinaryOp):
# class OrSubExpr(BinaryOp):
# class AlarmExprParser(object):
#     def __init__(self, tokens):
#     def fmtd_sub_expr_str(self):
#     def dimensions_str(self):
#     def operands_list(self):
#     def func(self):
#     def normalized_func(self):
#     def metric_name(self):
#     def normalized_metric_name(self):
#     def dimensions(self):
#     def dimensions_as_list(self):
#     def operator(self):
#     def threshold(self):
#     def period(self):
#     def periods(self):
#     def deterministic(self):
#     def normalized_operator(self):
#     def id(self):
#     def id(self, id):
#     def __init__(self, tokens):
#     def operands_list(self):
# def periodValidation(instr, loc, tokens):
# def periodsValidation(instr, loc, tokens):
#     def __init__(self, expr):
#     def sub_expr_list(self):
# def main():


import datetime
import fixtures
from oslo_config import cfg
from oslo_db.sqlalchemy.engines import create_engine
from sqlalchemy import delete, MetaData, insert, bindparam, select, func
from monasca_api.common.repositories import exceptions
from monasca_api.common.repositories.model import sub_alarm_definition
from monasca_api.common.repositories.sqla import models
from monasca_api.expression_parser import alarm_expr_parser
from monasca_api.tests import base
        from monasca_api.common.repositories.sqla import alarm_definitions_repository as adr
        from monasca_api.common.repositories import exceptions
             expression if expression else ALARM_DEF_123_FIELDS['expression'],
             ALARM_DEF_123_FIELDS['match_by'],  # match-by can't change
             severity if severity else ALARM_DEF_123_FIELDS['severity'],
             actions_enabled if actions_enabled else ALARM_DEF_123_FIELDS['actions_enabled'],
             u','.join(alarm_actions) if alarm_actions else ALARM_DEF_123_FIELDS['alarm_actions'],
             u','.join(ok_actions) if ok_actions else ALARM_DEF_123_FIELDS['ok_actions'],
             (u','.join(undetermined_actions) if undetermined_actions else
              ALARM_DEF_123_FIELDS['undetermined_actions']))

        sad = self.default_sads[0]
        if expression and ALARM_DEF_123_FIELDS['expression'] != expression:
            sub_expr = sub_expr_list[0]
            sub_alarm_def = sub_alarm_definition.SubAlarmDefinition(
                row={'id': '',
                     'alarm_definition_id': sad['alarm_definition_id'],
                     'function': sub_expr.normalized_func,
                     'metric_name': sub_expr.metric_name,
                     'dimensions': u'device=1,image_id=888,flavor_id=777,metric_name=cpu',
                     'operator': sub_expr.normalized_operator,
                     'threshold': sub_expr.threshold,
                     'period': sub_expr.period,
                     'is_deterministic': sub_expr.deterministic,
                     'periods': sub_expr.periods})
            expected_sub_alarm_maps = {
                'changed': {
                    u'111': sub_alarm_def},
                'new': {},
                'old': {},
                'unchanged': {}}
        else:

# Path: monasca_api/common/repositories/model/sub_alarm_definition.py
# class SubAlarmDefinition(object):
#     def __init__(self, row=None, sub_expr=None):
#     def _init_dimensions(self, dimensions_str):
#     def expression(self):
#     def __hash__(self):
#     def __repr__(self):
#     def __eq__(self, other):
#     def same_key_fields(self, other):
# 
# Path: monasca_api/common/repositories/sqla/models.py
# def get_all_metadata():
# def create_a_model(metadata=None):
# def create_sadd_model(metadata=None):
# def create_aa_model(metadata=None):
# def create_md_model(metadata=None):
# def create_mde_model(metadata=None):
# def create_nm_model(metadata=None):
# def create_nmt_model(metadata=None):
# def create_mdd_model(metadata=None):
# def create_am_model(metadata=None):
# def create_ad_model(metadata=None):
# def create_sa_model(metadata=None):
# def create_sad_model(metadata=None):
#     def __init__(self, columns, separator=',', order_by=None):
# def _group_concat_oracle(element, compiler_, **kw):
# def _group_concat_postgresql(element, compiler_, **kw):
# def _group_concat_sybase(element, compiler_, **kw):
# def _group_concat_mysql(element, compiler_, **kw):
# def _group_concat_default(element, compiler_, **kw):
#     def __init__(self, column, fields):
# def _field_sort_mysql(element, compiler_, **kw):
# def _field_sort_general(element, compiler_, **kw):
# class group_concat(expression.ColumnElement):
# class field_sort(expression.ColumnElement):
# 
# Path: monasca_api/expression_parser/alarm_expr_parser.py
# _DETERMINISTIC_ASSIGNMENT_LEN = 3
# _DETERMINISTIC_ASSIGNMENT_SHORT_LEN = 1
# _DETERMINISTIC_ASSIGNMENT_VALUE_INDEX = 2
# _DEFAULT_PERIOD = 60
# _DEFAULT_PERIODS = 1
# COMMA = pyparsing.Suppress(pyparsing.Literal(","))
# LPAREN = pyparsing.Suppress(pyparsing.Literal("("))
# RPAREN = pyparsing.Suppress(pyparsing.Literal(")"))
# EQUAL = pyparsing.Literal("=")
# LBRACE = pyparsing.Suppress(pyparsing.Literal("{"))
# RBRACE = pyparsing.Suppress(pyparsing.Literal("}"))
# MINUS = pyparsing.Literal('-')
# AND = pyparsing.CaselessLiteral("and") | pyparsing.CaselessLiteral("&&")
# OR = pyparsing.CaselessLiteral("or") | pyparsing.CaselessLiteral("||")
# class SubExpr(object):
# class BinaryOp(object):
# class AndSubExpr(BinaryOp):
# class OrSubExpr(BinaryOp):
# class AlarmExprParser(object):
#     def __init__(self, tokens):
#     def fmtd_sub_expr_str(self):
#     def dimensions_str(self):
#     def operands_list(self):
#     def func(self):
#     def normalized_func(self):
#     def metric_name(self):
#     def normalized_metric_name(self):
#     def dimensions(self):
#     def dimensions_as_list(self):
#     def operator(self):
#     def threshold(self):
#     def period(self):
#     def periods(self):
#     def deterministic(self):
#     def normalized_operator(self):
#     def id(self):
#     def id(self, id):
#     def __init__(self, tokens):
#     def operands_list(self):
# def periodValidation(instr, loc, tokens):
# def periodsValidation(instr, loc, tokens):
#     def __init__(self, expr):
#     def sub_expr_list(self):
# def main():


# Path: monasca_api/tests/test_ad_repository.py
import datetime
import fixtures
from oslo_config import cfg
from oslo_db.sqlalchemy.engines import create_engine
from sqlalchemy import delete, MetaData, insert, bindparam, select, func
from monasca_api.common.repositories import exceptions
from monasca_api.common.repositories.model import sub_alarm_definition
from monasca_api.common.repositories.sqla import models
from monasca_api.expression_parser import alarm_expr_parser
from monasca_api.tests import base
        from monasca_api.common.repositories.sqla import alarm_definitions_repository as adr
        from monasca_api.common.repositories import exceptions

             expression if expression else ALARM_DEF_123_FIELDS['expression'],
             ALARM_DEF_123_FIELDS['match_by'],  # match-by can't change
             severity if severity else ALARM_DEF_123_FIELDS['severity'],
             actions_enabled if actions_enabled else ALARM_DEF_123_FIELDS['actions_enabled'],
             u','.join(alarm_actions) if alarm_actions else ALARM_DEF_123_FIELDS['alarm_actions'],
             u','.join(ok_actions) if ok_actions else ALARM_DEF_123_FIELDS['ok_actions'],
             (u','.join(undetermined_actions) if undetermined_actions else
              ALARM_DEF_123_FIELDS['undetermined_actions']))

        sad = self.default_sads[0]
        if expression and ALARM_DEF_123_FIELDS['expression'] != expression:
            sub_expr = sub_expr_list[0]
            sub_alarm_def = sub_alarm_definition.SubAlarmDefinition(
                row={'id': '',
                     'alarm_definition_id': sad['alarm_definition_id'],
                     'function': sub_expr.normalized_func,
                     'metric_name': sub_expr.metric_name,
                     'dimensions': u'device=1,image_id=888,flavor_id=777,metric_name=cpu',
                     'operator': sub_expr.normalized_operator,
                     'threshold': sub_expr.threshold,
                     'period': sub_expr.period,
                     'is_deterministic': sub_expr.deterministic,
                     'periods': sub_expr.periods})
            expected_sub_alarm_maps = {
                'changed': {
                    u'111': sub_alarm_def},
                'new': {},
                'old': {},
                'unchanged': {}}
        else:

            sub_alarm_def = sub_alarm_definition.SubAlarmDefinition(