summaryrefslogtreecommitdiff
path: root/vymgmt/error_distinguish.py
blob: 1f889f8b8eb9c03cbd3771f02fe96d133b16ba43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright (c) 2016 Hochikong


def distinguish_for_set(message):
    """Distinguish the error type,PathError or ValueError

    :param message: A error message string from VyOS
    :return: The type of error
    """
    path_error_string = ['Configuration path:', 'is not valid', 'already exists']
    value_error_string = ['Value validation failed']
    all_strings = [path_error_string, value_error_string]
    condition = 0
    for i in all_strings:
        for x in i:
            if x in message:
                condition += 1

    if condition == 2:
        return "ConfigPathError"
    elif condition == 1:
        return "ConfigValueError"
    else:
        return "NonsupportButError"


def distinguish_for_delete(message):
    """Distinguish the error type,PathError or ValueError

    :param message: A error message string from VyOS
    :return: The type of error
    """
    path_error_string = ['Configuration path:', 'is not valid', 'Delete failed']
    value_error_string = ['Nothing to delete', 'the specified value does not exist',
                          "the specified node does not exist"]
    all_strings = [path_error_string, value_error_string]
    condition = 0

    for i in all_strings:
        for x in i:
            if x in message:
                condition += 1

    if condition == 3:
        return "ConfigPathError"
    elif condition == 2:
        return "ConfigValueError"
    else:
        return "NonsupportButError"


def distinguish_for_commit(message):
    """Distinguish the error type

    :param message: A error message string from VyOS
    :return: The type of error
    """
    all_strings = ['Commit failed', 'due to another commit in progress']

    for i in all_strings:
        if i in message:
            if i == all_strings[0]:
                return "CommitFailed"
            if i == all_strings[1]:
                return "CommitConflict"