Exemplo n.º 1
0
 def test_fmtd_sub_expr(self):
     expression = self.good_simple_expression
     sub_exprs = alarm_expr_parser.AlarmExprParser(expression).sub_expr_list
     self.assertEqual([x.fmtd_sub_expr_str for x in sub_exprs], [
         'MAX(cpu.idle_perc{hostname=fred}) <= 3.0 times 4',
         'AVG(CPU.PERCENT{}) < 5.0', 'MIN(cpu.percent{}) gte 3.0'
     ])
Exemplo n.º 2
0
 def test_periods(self):
     expression = self.good_simple_expression
     sub_exprs = alarm_expr_parser.AlarmExprParser(expression).sub_expr_list
     self.assertEqual([x.periods for x in sub_exprs], [4, 1, 1])
Exemplo n.º 3
0
 def test_threshold(self):
     expression = self.good_simple_expression
     sub_exprs = alarm_expr_parser.AlarmExprParser(expression).sub_expr_list
     self.assertEqual([x.threshold for x in sub_exprs], [3.0, 5.0, 3.0])
Exemplo n.º 4
0
 def test_operator(self):
     expression = self.good_simple_expression
     sub_exprs = alarm_expr_parser.AlarmExprParser(expression).sub_expr_list
     self.assertEqual([x.operator for x in sub_exprs], ['<=', '<', 'gte'])
Exemplo n.º 5
0
 def test_dimensions_as_list(self):
     expression = self.good_simple_expression
     sub_exprs = alarm_expr_parser.AlarmExprParser(expression).sub_expr_list
     print([x.dimensions_as_list for x in sub_exprs].__str__())
     self.assertEqual([x.dimensions_as_list for x in sub_exprs].__str__(),
                      "[(['hostname=fred'], {}), [], []]")
Exemplo n.º 6
0
 def test_dimensions(self):
     expression = self.good_simple_expression
     sub_exprs = alarm_expr_parser.AlarmExprParser(expression).sub_expr_list
     self.assertEqual([x.dimensions for x in sub_exprs],
                      ['hostname=fred', '', ''])
Exemplo n.º 7
0
 def test_normalized_metric_name(self):
     expression = self.good_simple_expression
     sub_exprs = alarm_expr_parser.AlarmExprParser(expression).sub_expr_list
     self.assertEqual([x.normalized_metric_name for x in sub_exprs],
                      ['cpu.idle_perc', 'cpu.percent', 'cpu.percent'])
Exemplo n.º 8
0
 def test_normalized_function(self):
     expression = self.good_simple_expression
     sub_exprs = alarm_expr_parser.AlarmExprParser(expression).sub_expr_list
     self.assertEqual([x.normalized_func for x in sub_exprs],
                      ['MAX', 'AVG', 'MIN'])
Exemplo n.º 9
0
 def test_function(self):
     expression = self.good_simple_expression
     sub_exprs = alarm_expr_parser.AlarmExprParser(expression).sub_expr_list
     self.assertEqual([x.func for x in sub_exprs], ['max', 'avg', 'min'])
Exemplo n.º 10
0
 def test_good_expression(self):
     expression = self.good_simple_expression
     sub_exprs = alarm_expr_parser.AlarmExprParser(expression).sub_expr_list
     self.assertEqual(3, len(sub_exprs))
Exemplo n.º 11
0
 def _ensure_parse_fails(self, expression):
     parser = alarm_expr_parser.AlarmExprParser(expression)
     self.assertRaises(
         (pyparsing.ParseException, pyparsing.ParseFatalException), getattr,
         parser, "sub_expr_list")
Exemplo n.º 12
0
 def test_set_id(self):
     expression = self.good_simple_expression
     sub_exprs = alarm_expr_parser.AlarmExprParser(expression).sub_expr_list
     for x in sub_exprs:
         x.id = 88
     self.assertEqual([x.id for x in sub_exprs], [88, 88, 88])
Exemplo n.º 13
0
 def test_id(self):
     expression = self.good_simple_expression
     sub_exprs = alarm_expr_parser.AlarmExprParser(expression).sub_expr_list
     self.assertEqual([x.id for x in sub_exprs], [None, None, None])
Exemplo n.º 14
0
 def test_normalized_operator(self):
     expression = self.good_simple_expression
     sub_exprs = alarm_expr_parser.AlarmExprParser(expression).sub_expr_list
     self.assertEqual([x.normalized_operator for x in sub_exprs],
                      ['LTE', 'LT', 'GTE'])
Exemplo n.º 15
0
 def test_deterministic(self):
     expression = self.good_simple_expression
     sub_exprs = alarm_expr_parser.AlarmExprParser(expression).sub_expr_list
     self.assertEqual([x.deterministic for x in sub_exprs],
                      [False, False, True])