Skip to content

Commit eeadb6c

Browse files
committed
fix (PilotSync): Remove not only the MasterCS but also its aliases
1 parent a2fbd84 commit eeadb6c

File tree

1 file changed

+67
-6
lines changed

1 file changed

+67
-6
lines changed

src/DIRAC/WorkloadManagementSystem/Utilities/PilotCStoJSONSynchronizer.py

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
""" CStoJSONSynchronizer
2-
Module that keeps the pilot parameters file synchronized with the information
3-
in the Operations/Pilot section of the CS. If there are additions in the CS,
4-
these are incorporated to the file.
5-
The module uploads to a web server the latest version of the pilot scripts.
1+
"""CStoJSONSynchronizer
2+
Module that keeps the pilot parameters file synchronized with the information
3+
in the Operations/Pilot section of the CS. If there are additions in the CS,
4+
these are incorporated to the file.
5+
The module uploads to a web server the latest version of the pilot scripts.
66
"""
7+
78
import datetime
89
import glob
910
import os
@@ -19,6 +20,65 @@
1920
from DIRAC.ConfigurationSystem.Client.Helpers.Path import cfgPath
2021
from DIRAC.Core.Utilities.ReturnValues import DOKReturnType, DReturnType
2122

23+
import socket
24+
from urllib.parse import urlparse
25+
26+
27+
def exclude_master_cs_aliases(urls: list[str], master_cs_url: str) -> list[str]:
28+
"""
29+
Excludes URLs that are DNS aliases of the given MasterCS server URL.
30+
31+
This function resolves the IP addresses of the MasterCS server and each URL in the input list.
32+
It returns a new list containing only those URLs whose hostnames do not resolve to any of the
33+
MasterCS server's IP addresses, effectively excluding all DNS aliases of the MasterCS server.
34+
35+
Args:
36+
urls (list[str]): A list of URLs to filter. Each URL should be a string in a valid URL format.
37+
master_cs_url (str): The reference URL (e.g., MasterCS server URL) whose DNS aliases are to be excluded.
38+
39+
Returns:
40+
list[str]: A new list of URLs with all aliases of the MasterCS server removed.
41+
If the MasterCS hostname cannot be resolved, the original list is returned unchanged.
42+
43+
Example:
44+
>>> urls = [
45+
... 'dips://lbvobox303.cern.ch:9135/Configuration/Server',
46+
... 'dips://ccwlcglhcb02.in2p3.fr:9135/Configuration/Server',
47+
... 'dips://lbvobox302.cern.ch:9135/Configuration/Server',
48+
... ]
49+
>>> master_cs_url = "dips://mastercs.cern.ch:9135/Configuration/Server"
50+
>>> exclude_master_cs_aliases(urls, master_cs_url)
51+
['dips://ccwlcglhcb02.in2p3.fr:9135/Configuration/Server']
52+
53+
Notes:
54+
- If the MasterCS hostname cannot be resolved, the function returns the original list.
55+
- If a hostname in the input list cannot be resolved, it is included in the result.
56+
- The comparison is based on IP addresses, not hostnames.
57+
"""
58+
master_cs_hostname = urlparse(master_cs_url).hostname
59+
60+
# Resolve IP addresses for the MasterCS hostname
61+
try:
62+
master_cs_ips = set(socket.gethostbyname_ex(master_cs_hostname)[2])
63+
except socket.gaierror:
64+
return urls
65+
66+
# Function to get IPs for a hostname
67+
def get_ips(hostname):
68+
try:
69+
return set(socket.gethostbyname_ex(hostname)[2])
70+
except socket.gaierror:
71+
return set()
72+
73+
filtered_urls = []
74+
for url in urls:
75+
hostname = urlparse(url).hostname
76+
ips = get_ips(hostname)
77+
if not ips & master_cs_ips:
78+
filtered_urls.append(url)
79+
80+
return filtered_urls
81+
2282

2383
class PilotCStoJSONSynchronizer:
2484
"""
@@ -151,7 +211,8 @@ def getCSDict(self, includeMasterCS: bool = True) -> DReturnType[Any]:
151211
configurationServers = gConfig.getServersList()
152212
if not includeMasterCS:
153213
masterCS = gConfigurationData.getMasterServer()
154-
configurationServers = list(set(configurationServers) - {masterCS})
214+
configurationServers = exclude_master_cs_aliases(configurationServers, masterCS)
215+
155216
pilotDict["ConfigurationServers"] = configurationServers
156217

157218
self.log.debug("Got pilotDict", str(pilotDict))

0 commit comments

Comments
 (0)