Passed
Pull Request — master (#114)
by Aldo
04:31
created

build.tracing.trace_msg   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 65
ccs 25
cts 30
cp 0.8333
rs 10
c 0
b 0
f 0
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A TraceMsg.request_id() 0 4 3
A TraceMsg._instantiate_vars() 0 9 1
A TraceMsg.step() 0 4 3
A TraceMsg.__init__() 0 4 1
1
""" This module creates the TraceID message to be used as the
2
Ethernet payload of the PacketOut. This msg is important to
3
differentiate parallel traces.
4
"""
5
6
7 1
class TraceMsg(object):
8
    """ This class will be used to create, retrieve and update the
9
    payload message sent through the trace process
10
11
    Basically the msg is a dictionary:
12
13
    {"trace": {
14
            "request_id": "number to identify this trace"
15
        }
16
    }
17
    """
18
19 1
    def __init__(self, r_id='0', step=0):
20 1
        self._request_id = None
21 1
        self._step = None
22 1
        self._instantiate_vars(r_id, step)
23
24 1
    def _instantiate_vars(self, r_id, step):
25
        """ Attributes in the TraceMsg are processed as
26
        Getter and Setters.
27
28
        Args:
29
            r_id: request ID
30
        """
31 1
        self.request_id = r_id
32 1
        self.step = step
33
34 1
    @property
35 1
    def request_id(self):
36
        """ Getter: Request ID """
37 1
        return self._request_id
38
39 1
    @request_id.setter
40 1
    def request_id(self, r_id):
41
        """ Setter: Request ID """
42 1
        try:
43 1
            if isinstance(r_id, int):
44 1
                self._request_id = r_id
45
            else:
46 1
                self._request_id = int(r_id)
47
        except ValueError:
48
            raise ValueError("Invalid ID provided: %s" % r_id)
49
50 1
    @property
51 1
    def step(self):
52
        """ Getter: Step number """
53 1
        return self._step
54
55 1
    @step.setter
56 1
    def step(self, step):
57
        """ Setter: Step number """
58 1
        try:
59 1
            if isinstance(step, int):
60 1
                self._step = step
61
            else:
62
                self._step = int(step)
63
        except ValueError:
64
            raise ValueError(f"Invalid step number provided: f{step}")
65