Skip to content

Commit b3d686f

Browse files
moved get_free_port and updated import
Signed-off-by: Lanuti_emanuele <[email protected]> Signed-off-by: Emanuele Lanuti <[email protected]>
1 parent cffe720 commit b3d686f

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

tests/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from suzieq.shared.schema import Schema
2424
from suzieq.shared.utils import load_sq_config
2525
from suzieq.sqobjects import get_sqobject, get_tables
26+
import socket
27+
from contextlib import closing
2628

2729
suzieq_cli_path = './suzieq/cli/sq_cli.py'
2830
suzieq_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]

tests/unit/poller/controller/sources/netbox/test_netbox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
NetboxFaker
1515
from 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

tests/unit/poller/shared/utils.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import random
2-
import socket
3-
from contextlib import closing
42
from pathlib import Path
53
from 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]

0 commit comments

Comments
 (0)