Example #1
0
    def log_entry(self,
                  entry_type,
                  message,
                  task_id=None,
                  route=None,
                  task_transition_id=None,
                  result=None,
                  data=None):

        # Check entry type.
        if entry_type not in ['info', 'warn', 'error']:
            raise exc.WorkflowLogEntryError(
                'The log entry type "%s" is not valid.' % entry_type)

        # Identify the appropriate log and then log the entry.
        log = self.errors if entry_type == 'error' else self.log

        # Create the log entry.
        entry = {'type': entry_type, 'message': message}
        dict_util.set_dict_value(entry, 'task_id', task_id, insert_null=False)
        dict_util.set_dict_value(entry, 'route', route, insert_null=False)
        dict_util.set_dict_value(entry,
                                 'task_transition_id',
                                 task_transition_id,
                                 insert_null=False)
        dict_util.set_dict_value(entry, 'result', result, insert_null=False)
        dict_util.set_dict_value(entry, 'data', data, insert_null=False)

        # Ignore if this is a duplicate.
        if len(list(filter(lambda x: x == entry, log))) > 0:
            return

        # Append the log entry.
        log.append(entry)
Example #2
0
    def test_dict_dot_notation_set_value(self):
        data = {
            'a': 'foo',
            'b': {
                'c': 'bar',
                'd': {
                    'e': 123,
                    'f': False,
                    'g': {},
                    'h': None
                }
            },
            'x': {},
            'y': None
        }

        # Test basic insert.
        utils.set_dict_value(data, 'z', {'foo': 'bar'})

        # Test insert via dot notation on existing node.
        utils.set_dict_value(data, 'b.d.h', 2.0)

        # Test insert via dot notation on nonexistent nodes.
        utils.set_dict_value(data, 'm.n.o', True)

        # Test insert non-null only.
        utils.set_dict_value(data, 'b.d.i', None, insert_null=False)

        # Test insert null.
        utils.set_dict_value(data, 'b.d.j', None, insert_null=True)

        expected_data = {
            'a': 'foo',
            'b': {
                'c': 'bar',
                'd': {
                    'e': 123,
                    'f': False,
                    'g': {},
                    'h': 2.0,
                    'j': None
                }
            },
            'm': {
                'n': {
                    'o': True
                }
            },
            'x': {},
            'y': None,
            'z': {
                'foo': 'bar'
            }
        }

        self.assertDictEqual(data, expected_data)