Skip to content

Commit b9bfd4f

Browse files
committed
ft-orchestration add docstrings and type hints
1 parent ee8aa83 commit b9bfd4f

9 files changed

Lines changed: 294 additions & 226 deletions

File tree

tools/ft-orchestration/src/probe/cento.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,13 @@
5757
@dataclass
5858
class CentoSettings(ABC):
5959
"""
60-
These settings can be set in the probes.yml under `connector:`\\
61-
For example with:
62-
```
63-
connector:
64-
sample_rate: "1:1"
65-
```
66-
For information on possible values see `cento --help`\\
67-
If it's not clear which setting affects which arg see `SETTINGS_TO_ARGS` dict above\\
68-
Settings not in that dict are ignored
60+
These settings can be set in probes.yml under `connector:`.
61+
Example:
62+
connector:
63+
sample_rate: "1:1"
64+
For possible values see `cento --help`.
65+
If unclear which setting affects which arg, see `SETTINGS_TO_ARGS` above.
66+
Settings not in that dict are ignored.
6967
"""
7068

7169
# general options
@@ -251,7 +249,9 @@ def _before_start(self):
251249
self._set_rss_queues(name)
252250

253251
def start(self):
254-
"""Start the probe."""
252+
"""
253+
Start the probe.
254+
"""
255255
logging.getLogger().info(
256256
"Starting cento exporter on %s.", ",".join(self._interfaces)
257257
)
@@ -326,7 +326,9 @@ def _stop_process(self, pid):
326326
).run()
327327

328328
def supported_fields(self):
329-
"""Get list of IPFIX fields the probe may export in its current configuration."""
329+
"""
330+
Get list of IPFIX fields the probe may export in its current configuration.
331+
"""
330332
output, _ = Tool(
331333
r"cento --help | awk '/Supported template elements \(\-\-template\):/ {p=1} p' | grep '^ %'",
332334
executor=self._executor,
@@ -336,14 +338,18 @@ def supported_fields(self):
336338
return fields
337339

338340
def get_special_fields(self):
339-
"""Return dictionary of exported fields that need special evaluation."""
341+
"""
342+
Return dictionary of exported fields that need special evaluation.
343+
"""
340344
basic_fields = set(BASIC_TEMPLATE.replace('"', "").split(","))
341345
used_fields = set(self._settings.flow_template.replace('"', "").split(","))
342346
special_fields = {field: None for field in (used_fields - basic_fields)}
343347
return special_fields
344348

345349
def stop(self):
346-
"""Stop the probe."""
350+
"""
351+
Stop the probe.
352+
"""
347353
# if process not running, method has no effect
348354
if self._process is None:
349355
return
@@ -380,17 +386,18 @@ def stop(self):
380386
self._after_stop()
381387

382388
def cleanup(self):
383-
"""Clean any artifacts which were created by the connector or the active probe itself."""
389+
"""
390+
Clean any artifacts created by the connector or the active probe itself.
391+
"""
384392
Tool(f"rm -rf {self._local_workdir}").run()
385393
self.host_statistics.cleanup()
386394

387395
def download_logs(self, directory: str):
388-
"""Download logs to given directory.
396+
"""
397+
Download logs to the given directory.
389398
390-
Parameters
391-
----------
392-
directory : str
393-
Path to a local directory where logs should be stored.
399+
Args:
400+
directory (str): Path to a local directory where logs should be stored.
394401
"""
395402
try:
396403
shutil.move(self._log_file, directory)
@@ -399,14 +406,16 @@ def download_logs(self, directory: str):
399406
logging.getLogger().warning("Cannot download ipfixprobe log, %s", err)
400407

401408
def get_timeouts(self) -> tuple[int, int]:
402-
"""Get active and inactive timeouts of the probe (in seconds).
409+
"""
410+
Get active and inactive timeouts of the probe (in seconds).
403411
404-
Returns
405-
-------
406-
tuple
407-
active_timeout, inactive_timeout
412+
Returns:
413+
tuple: active_timeout, inactive_timeout
408414
"""
409415
return self._timeouts
410416

411417
def set_prefilter(self, ip_ranges: list[str]) -> None:
418+
"""
419+
Set probe input filter. Probe will drop all traffic except specified IP ranges.
420+
"""
412421
raise NotImplementedError

tools/ft-orchestration/src/probe/interface.py

Lines changed: 82 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -14,67 +14,87 @@
1414

1515

1616
class HostStats(ABC):
17-
"""Abstract class defining an Interface for a programm that reads statistics from a host"""
17+
"""
18+
Abstract class defining an interface for a program that reads statistics from a host.
19+
"""
1820

1921
@abstractmethod
2022
def __init__(self, executor: Executor, watch_cmd: str):
21-
"""Constructor
23+
"""
24+
Constructor.
2225
2326
Args:
24-
executor (Executor): _description_
25-
watch_cmd (str): the program name to watch statistics for
27+
executor (Executor): Executor object.
28+
watch_cmd (str): Program name to watch statistics for.
2629
"""
2730
pass
2831

2932
@property
3033
@abstractmethod
3134
def cpus(self) -> int:
32-
"""number of cpus"""
35+
"""
36+
Number of CPUs.
37+
"""
3338
pass
3439

3540
@property
3641
@abstractmethod
3742
def total_ram(self) -> int:
38-
"""size of ram in kB"""
43+
"""
44+
Size of RAM in kB.
45+
"""
3946
pass
4047

4148
@property
4249
@abstractmethod
4350
def local_file(self) -> PathLike:
44-
"""Path to locally stored csv file"""
51+
"""
52+
Path to locally stored CSV file.
53+
"""
4554
pass
4655

4756
@abstractmethod
4857
def start(self):
49-
"""Start collecting statistics"""
58+
"""
59+
Start collecting statistics.
60+
"""
5061
pass
5162

5263
@abstractmethod
5364
def stop(self):
54-
"""Stop collecting statistics"""
65+
"""
66+
Stop collecting statistics.
67+
"""
5568
pass
5669

5770
@abstractmethod
5871
def cleanup(self):
59-
"""Remove temporary files"""
72+
"""
73+
Remove temporary files.
74+
"""
6075
pass
6176

6277
@abstractmethod
6378
def get_csv(self, output_dir: PathLike):
64-
"""Download the csv file containing statistics to the output_dir
79+
"""
80+
Download the CSV file containing statistics to the output directory.
6581
6682
Args:
67-
output_dir (PathLike): path where to copy csv to
83+
output_dir (PathLike): Path where to copy CSV to.
6884
"""
6985
pass
7086

7187

7288
class ProbeException(Exception):
73-
"""Basic exception raised by the probe implementations"""
89+
"""
90+
Basic exception raised by probe implementations.
91+
"""
7492

7593

7694
class ProbeInterface(ABC):
77-
"""Abstract class defining common interface for all probes"""
95+
"""
96+
Abstract class defining common interface for all probes.
97+
"""
7898

7999
@abstractmethod
80100
def __init__(
@@ -91,106 +111,96 @@ def __init__(
91111
cache_size,
92112
**kwargs,
93113
):
94-
"""Initialize the local or remote probe interface as object
95-
96-
Parameters
97-
----------
98-
99-
executor : lbr_testsuite.executable.Executor
100-
Initialized executor object with the deployed probe.
101-
102-
target : src.probe.probe_target
103-
Target object for the exporter/probe
104-
105-
protocols : list
106-
List of the networking protocols which the probe should parse and export.
107-
108-
interfaces : list(InterfaceCfg)
109-
Network interfaces where the exporting process should be initiated.
110-
111-
verbose : bool, optional
112-
Increase verbosity of probe logs.
113-
114-
mtu : int, optional
115-
The maximum transmission unit to be set at the probe input.
116-
117-
active_timeout : int, optional
118-
Maximum duration of an ongoing flow before the probe exports it (in seconds).
119-
120-
inactive_timeout : int, optional
121-
Maximum duration for which a flow is kept in the probe if no new data updates it (in seconds).
122-
123-
kwargs : dict
124-
Additional startup arguments for specific probe variants.
114+
"""
115+
Initialize the local or remote probe interface as an object.
125116
126-
Raises
127-
------
128-
ProbeException
129-
Unable to initialize the probe.
117+
Args:
118+
executor (Executor): Initialized executor object with the deployed probe.
119+
target: Target object for the exporter/probe.
120+
protocols (list): List of networking protocols to parse and export.
121+
interfaces (list[InterfaceCfg]): Network interfaces for the exporting process.
122+
verbose (bool, optional): Increase verbosity of probe logs.
123+
mtu (int, optional): Maximum transmission unit for the probe input.
124+
active_timeout (int, optional): Maximum duration of an ongoing flow before export (seconds).
125+
inactive_timeout (int, optional): Maximum duration for which a flow is kept if no new data updates it (seconds).
126+
cache_size: Additional cache size argument.
127+
**kwargs: Additional startup arguments for specific probe variants.
128+
129+
Raises:
130+
ProbeException: Unable to initialize the probe.
130131
"""
131132
raise NotImplementedError
132133

133134
@property
134135
@abstractmethod
135136
def host_statistics(self) -> HostStats:
136-
"""Class with which to read statistics from the host"""
137+
"""
138+
Class to read statistics from the host.
139+
"""
137140
pass
138141

139142
@abstractmethod
140143
def start(self):
141-
"""Start the probe."""
144+
"""
145+
Start the probe.
146+
"""
142147
raise NotImplementedError
143148

144149
@abstractmethod
145150
def supported_fields(self):
146-
"""Get list of IPFIX fields the probe may export in its current configuration."""
151+
"""
152+
Get list of IPFIX fields the probe may export in its current configuration.
153+
"""
147154
raise NotImplementedError
148155

149156
@abstractmethod
150157
def get_special_fields(self):
151-
"""Return dictionary of exported fields that need special evaluation."""
158+
"""
159+
Return dictionary of exported fields that need special evaluation.
160+
"""
152161
raise NotImplementedError
153162

154163
@abstractmethod
155164
def stop(self):
156-
"""Stop the probe."""
165+
"""
166+
Stop the probe.
167+
"""
157168
raise NotImplementedError
158169

159170
@abstractmethod
160171
def cleanup(self):
161-
"""Clean any artifacts which were created by the connector or the active probe itself."""
172+
"""
173+
Clean any artifacts created by the connector or the active probe itself.
174+
"""
162175
raise NotImplementedError
163176

164177
@abstractmethod
165178
def download_logs(self, directory: str):
166-
"""Download logs to given directory.
179+
"""
180+
Download logs to the given directory.
167181
168-
Parameters
169-
----------
170-
directory : str
171-
Path to a local directory where logs should be stored.
182+
Args:
183+
directory (str): Path to a local directory where logs should be stored.
172184
"""
173185
raise NotImplementedError
174186

175187
@abstractmethod
176188
def get_timeouts(self) -> tuple[int, int]:
177-
"""Get active and inactive timeouts of the probe (in seconds).
178-
179-
Returns
180-
-------
181-
tuple
182-
active_timeout, inactive_timeout
183189
"""
190+
Get active and inactive timeouts of the probe (in seconds).
191+
192+
Returns:
193+
tuple: active_timeout, inactive_timeout
184194
195+
"""
196+
raise NotImplementedError
185197
raise NotImplementedError
186198

187199
def set_prefilter(self, ip_ranges: list[str]) -> None:
188-
"""Set probe input filter. Probe will drop all the traffic except specified IP ranges.
189-
190-
Parameters
191-
----------
192-
ip_ranges : list[str]
193-
IP ranges passed by the filter.
194200
"""
201+
Set probe input filter. Probe will drop all traffic except specified IP ranges.
195202
203+
Args:
204+
ip_ranges (list[str]): IP ranges passed by the filter.
205+
"""
196206
raise NotImplementedError

0 commit comments

Comments
 (0)