File tree Expand file tree Collapse file tree 3 files changed +16
-16
lines changed
controller/sources/netbox Expand file tree Collapse file tree 3 files changed +16
-16
lines changed Original file line number Diff line number Diff line change 2323from suzieq .shared .schema import Schema
2424from suzieq .shared .utils import load_sq_config
2525from suzieq .sqobjects import get_sqobject , get_tables
26+ import socket
27+ from contextlib import closing
2628
2729suzieq_cli_path = './suzieq/cli/sq_cli.py'
2830suzieq_rest_server_path = './suzieq/restServer/sq_rest_server.py'
@@ -286,3 +288,15 @@ def validate_host_shape(df: pd.DataFrame, ns_dict: dict):
286288 if ns in df .namespace .unique ():
287289 assert df .query (
288290 f'namespace == "{ ns } "' ).hostname .nunique () == ns_dict [ns ]
291+
292+
293+ def get_free_port () -> int :
294+ """Return a free port
295+
296+ Returns:
297+ int: free port
298+ """
299+ with closing (socket .socket (socket .AF_INET , socket .SOCK_STREAM )) as s :
300+ s .bind (('' , 0 ))
301+ s .setsockopt (socket .SOL_SOCKET , socket .SO_REUSEADDR , 1 )
302+ return s .getsockname ()[1 ]
Original file line number Diff line number Diff line change 1414 NetboxFaker
1515from tests .unit .poller .controller .sources .netbox .netbox_rest_server import \
1616 NetboxRestApp
17- from tests .unit .poller .shared .utils import (get_free_port ,
18- get_src_sample_config )
17+ from tests .unit .poller .shared .utils import (get_src_sample_config )
18+ from tests . conftest import get_free_port
1919
2020# pylint: disable=redefined-outer-name
2121
Original file line number Diff line number Diff line change 11import random
2- import socket
3- from contextlib import closing
42from pathlib import Path
53from typing import Any , Dict , Tuple
64
@@ -119,15 +117,3 @@ def read_yaml_file(path: str) -> Any:
119117 if not file_path .is_file ():
120118 raise RuntimeError (f'Invalid file to read { path } ' )
121119 return yaml .safe_load (open (file_path , 'r' ))
122-
123-
124- def get_free_port () -> int :
125- """Return a free port
126-
127- Returns:
128- int: free port
129- """
130- with closing (socket .socket (socket .AF_INET , socket .SOCK_STREAM )) as s :
131- s .bind (('' , 0 ))
132- s .setsockopt (socket .SOL_SOCKET , socket .SO_REUSEADDR , 1 )
133- return s .getsockname ()[1 ]
You can’t perform that action at this time.
0 commit comments