-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #888 from BCDA-APS/887-apsu-subnet-check
check proper subnet for APSU beamlines
- Loading branch information
Showing
5 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
""" | ||
APS-U controls are on private subnets. Check and advise as applicable. | ||
.. autosummary:: | ||
~warn_if_not_aps_controls_subnet | ||
""" | ||
|
||
APSU_CONTROLS_SUBNET = "10.54." | ||
APSU_XRAY_SUBNET = ".xray.aps.anl.gov" | ||
|
||
|
||
def warn_if_not_aps_controls_subnet(): | ||
""" | ||
APS-U controls are on private subnets. Check and advise as applicable. | ||
Call this function early in the startup procedure. It could explain easily | ||
the reason for subsequent EPICS PV connection failures. | ||
For workstations on subnets that do not match the criteria, this function | ||
should not post any warnings. | ||
""" | ||
|
||
import socket | ||
import warnings | ||
|
||
host_name = socket.gethostname() | ||
if host_name.endswith(APSU_XRAY_SUBNET): | ||
host_ip_addr = socket.gethostbyname(host_name) | ||
if not host_ip_addr.startswith(APSU_CONTROLS_SUBNET): | ||
warnings.warn( | ||
f"Your APS workstation ({host_name}) has IP {host_ip_addr!r}." | ||
" If you experience EPICS connection timeouts," | ||
" consider switching to a workstation on the controls subnet" | ||
f" which has an IP starting with {APSU_CONTROLS_SUBNET!r}" | ||
) | ||
|
||
|
||
def warn_if_not_aps_controls_subnet(): | ||
""" | ||
APS-U controls are on private subnets. Check and advise as applicable. | ||
Call this function early in the startup procedure. It could explain easily | ||
the reason for subsequent EPICS PV connection failures. | ||
For workstations on subnets that do not match the criteria, this function | ||
should not post any warnings. | ||
""" | ||
|
||
import socket | ||
import warnings | ||
|
||
xray_subnet = ".xray.aps.anl.gov" | ||
controls_subnet = "10.54." | ||
|
||
host_name = socket.gethostname() | ||
if host_name.endswith(xray_subnet): | ||
host_ip_addr = socket.gethostbyname(host_name) | ||
if not host_ip_addr.startswith(controls_subnet): | ||
warnings.warn( | ||
f"Your APS workstation ({host_name}) has IP {host_ip_addr!r}." | ||
" If you experience EPICS connection timeouts," | ||
" consider switching to a workstation on the controls subnet" | ||
f" which has an IP starting with {controls_subnet!r}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import socket | ||
from contextlib import nullcontext as does_not_raise | ||
|
||
import pytest | ||
|
||
from ..apsu_controls_subnet import APSU_CONTROLS_SUBNET | ||
from ..apsu_controls_subnet import APSU_XRAY_SUBNET | ||
from ..apsu_controls_subnet import warn_if_not_aps_controls_subnet | ||
|
||
|
||
def test_subnet_check(): | ||
host_name = socket.gethostname() | ||
host_ip_addr = socket.gethostbyname(host_name) | ||
# fmt: off | ||
warns = ( | ||
host_name.endswith(APSU_XRAY_SUBNET) | ||
and not host_ip_addr.startswith(APSU_CONTROLS_SUBNET) | ||
) | ||
# fmt: on | ||
with pytest.raises(UserWarning) if warns else does_not_raise(): | ||
warn_if_not_aps_controls_subnet() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters