def test_flatten_dict_no_original_modification(self):
     sjutils.flatten_dict(self.simple_dictionary)
     self.assertEqual(self.simple_dictionary, {
         'first': 'value',
         'second': {
             'nested': 'hello'
         }
     })
Example #2
0
 def test_flatten_dict_no_original_modification(self):
     sjutils.flatten_dict(self.simple_dictionary)
     self.assertEqual(self.simple_dictionary, {
         "first": "value",
         "second": {
             "nested": "hello"
         }
     })
 def test_flatten_dict_medium_with_sep(self):
     self.assertEqual(sjutils.flatten_dict(self.nested_dictionary, sep=':'),
                      {
                          'first:1:2': '3',
                          'first:a:b:c': 'd',
                          'first:a:b:e': 'f'
                      })
Example #4
0
 def test_flatten_dict_simple_with_sep(self):
     self.assertEqual(
         sjutils.flatten_dict(self.simple_dictionary, sep=":"),
         {
             "first": "value",
             "second:nested": "hello"
         },
     )
Example #5
0
 def test_flatten_dict_simple(self):
     self.assertEqual(
         sjutils.flatten_dict(self.simple_dictionary),
         {
             "first": "value",
             "second/nested": "hello"
         },
     )
Example #6
0
 def test_flatten_dict_medium(self):
     self.assertEqual(
         sjutils.flatten_dict(self.nested_dictionary),
         {
             "first/1/2": "3",
             "first/a/b/c": "d",
             "first/a/b/e": "f"
         },
     )
Example #7
0
 def test_flatten_dict_medium_with_sep(self):
     self.assertEqual(
         sjutils.flatten_dict(self.nested_dictionary, sep=":"),
         {
             "first:1:2": "3",
             "first:a:b:c": "d",
             "first:a:b:e": "f"
         },
     )
Example #8
0
def set_checks_status(pg_manager, ctx_list, _request, checks):
    """ Sets results of provided @checks.

    @checks: must be a list of check dictionaries of the form
        [{'status_id': sts_id_value,
         'sequence_id': seq_id_value,
         'status': sts_value,
         'message': msg_value,
         'status_infos': infos_dict,
         }, ... ]
    """

    for check in checks:
        if check['status_id'] == None:
            logger.error(
                'set_checks_status: Trying to set check status with invalid input parameter (status_id): %s'
                % (str(check)))
            continue

        query = """SELECT repeat, repeat_on_error FROM spv.status NATURAL JOIN spv.checks_group NATURAL JOIN spv.checks WHERE status_id=%(status_id)s"""
        pg_manager.execute(ctx_list[0], query, check)
        res = pg_manager.fetchone(ctx_list[0])
        if not res:
            logger.error(
                'status_id %s does not exist anymore. Skipping status update' %
                (str(check)))
            continue
        repeat, repeat_on_error = res

        if check['status'] == 'ERROR':
            set_next_check = """, next_check = next_check
                                             - CAST ('%s seconds' AS INTERVAL)
                                             + CAST ('%s seconds' AS INTERVAL)""" % (
                repeat, repeat_on_error)
        else:
            set_next_check = ""
        query = """UPDATE status SET last_check=now(), check_status=%(status)s, check_message=%(message)s, seq_id = seq_id + 1"""
        query += set_next_check
        query += """ WHERE status_id=%(status_id)s AND seq_id=%(sequence_id)s"""
        pg_manager.execute(ctx_list[0], query, check)
        if check.get('status_infos'):
            tmp_dict = sjutils.flatten_dict(check['status_infos'], sep=':')
            for key, value in tmp_dict.iteritems():
                query = """INSERT INTO status_infos_view (status_id, key, value) VALUES (%(status_id)s, %(key)s, %(value)s)"""
                pg_manager.execute(
                    ctx_list[0], query, {
                        'status_id': check['status_id'],
                        'key': str(key),
                        'value': str(value)
                    })

    pg_manager.commit(ctx_list[0])
Example #9
0
def set_checks_status(pg_manager, ctx_list, _request, checks):
    """ Sets results of provided @checks.

    @checks: must be a list of check dictionaries of the form
        [{'status_id': sts_id_value,
         'sequence_id': seq_id_value,
         'status': sts_value,
         'message': msg_value,
         'status_infos': infos_dict,
         }, ... ]
    """

    for check in checks:
        if check['status_id'] == None:
            logger.error('set_checks_status: Trying to set check status with invalid input parameter (status_id): %s' % (str(check)))
            continue

        query = """SELECT repeat, repeat_on_error FROM spv.status NATURAL JOIN spv.checks_group NATURAL JOIN spv.checks WHERE status_id=%(status_id)s"""
        pg_manager.execute(ctx_list[0], query, check)
        res  = pg_manager.fetchone(ctx_list[0])
        if not res:
            logger.error('status_id %s does not exist anymore. Skipping status update' % (str(check)))
            continue
        repeat, repeat_on_error = res


        if check['status'] == 'ERROR':
            set_next_check = """, next_check = next_check
                                             - CAST ('%s seconds' AS INTERVAL)
                                             + CAST ('%s seconds' AS INTERVAL)""" % (repeat, repeat_on_error)
        else:
            set_next_check = ""
        query  = """UPDATE status SET last_check=now(), check_status=%(status)s, check_message=%(message)s, seq_id = seq_id + 1"""
        query += set_next_check
        query += """ WHERE status_id=%(status_id)s AND seq_id=%(sequence_id)s"""
        pg_manager.execute(ctx_list[0], query, check)
        if check.get('status_infos'):
            tmp_dict = sjutils.flatten_dict(check['status_infos'], sep = ':')
            for key, value in tmp_dict.iteritems():
                query = """INSERT INTO status_infos_view (status_id, key, value) VALUES (%(status_id)s, %(key)s, %(value)s)"""
                pg_manager.execute(ctx_list[0], query, {'status_id': check['status_id'],
                                     'key': str(key),
                                     'value': str(value)})

    pg_manager.commit(ctx_list[0])
Example #10
0
 def test_flatten_dict_simple(self):
     self.assertEqual(sjutils.flatten_dict(self.simple_dictionary),
                      {'first': 'value',
                       'second/nested': 'hello'})
Example #11
0
 def test_flatten_dict_medium_with_sep(self):
     self.assertEqual(sjutils.flatten_dict(self.nested_dictionary, sep = ':'),
                      {'first:1:2': '3',
                       'first:a:b:c': 'd',
                       'first:a:b:e': 'f'})
Example #12
0
 def test_flatten_dict_medium(self):
     self.assertEqual(sjutils.flatten_dict(self.nested_dictionary),
                      {'first/1/2': '3',
                       'first/a/b/c': 'd',
                       'first/a/b/e': 'f'})
 def test_flatten_dict_medium(self):
     self.assertEqual(sjutils.flatten_dict(self.nested_dictionary), {
         'first/1/2': '3',
         'first/a/b/c': 'd',
         'first/a/b/e': 'f'
     })
 def test_flatten_dict_simple_with_sep(self):
     self.assertEqual(sjutils.flatten_dict(self.simple_dictionary, sep=':'),
                      {
                          'first': 'value',
                          'second:nested': 'hello'
                      })
 def test_flatten_dict_simple(self):
     self.assertEqual(sjutils.flatten_dict(self.simple_dictionary), {
         'first': 'value',
         'second/nested': 'hello'
     })
Example #16
0
 def test_flatten_dict_no_original_modification(self):
     sjutils.flatten_dict(self.simple_dictionary)
     self.assertEqual(self.simple_dictionary,
                      {'first': 'value',
                       'second': {'nested': 'hello'}})
Example #17
0
 def test_flatten_dict_simple_with_sep(self):
     self.assertEqual(sjutils.flatten_dict(self.simple_dictionary, sep = ':'),
                      {'first': 'value',
                       'second:nested': 'hello'})