Skip to content

Commit 4b715ef

Browse files
fix: Fixed doc, and went back on the client selector
1 parent ff736bb commit 4b715ef

File tree

6 files changed

+51
-35
lines changed

6 files changed

+51
-35
lines changed

docs/source/DeveloperGuide/CodeTesting/index.rst

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,17 +352,13 @@ And you can also restart all services (it can take some time):
352352
353353
You can also test DiracX in integration tests. To do that, you have to provide in the `prepare-environment` command the following flag: `TEST_DIRACX=Yes`. It will run DiracX alongside DIRAC, and use the available and activated legacy adapted services.
354354

355-
To deactivate a service from being used with DiracX, you can set the `diracxClient` field to `None`:
355+
To deactivate a service from being used with DiracX, you can add it in `integration_tests.py` in the `DIRACX_DISABLED_SERVICES` list:
356356

357357
.. code-block:: python
358358
359-
class MyOldClient(Client):
360-
def __init__(self, **kwargs):
361-
super().__init__(**kwargs)
362-
self.setServer("...")
363-
364-
# Set to NULL to avoid using it in ClientSelector
365-
diracxClient = None
359+
DIRACX_DISABLED_SERVICES = [
360+
"WorkloadManagement/JobMonitoring",
361+
]
366362
367363
By setting `TEST_DIRACX=Yes` only, it will take the last version of DiracX by default. If you want to provide your own, you have to build your DiracX project, and provide the `dist` folder path when calling `prepare-client`. This path has to be absolute.
368364

integration_tests.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@
3939
"INSTALLATION_BRANCH": "",
4040
"DEBUG": "Yes",
4141
}
42-
# If TEST_DIRACX is set to yes, all variables in DIRACX_OPTIONS will also be set to "Yes"
43-
DIRACX_OPTIONS = ()
4442
DEFAULT_MODULES = {"DIRAC": Path(__file__).parent.absolute()}
43+
# All services that have a FutureClient, but we *explicitly* deactivate
44+
# (for example if we did not finish to develop it)
45+
DIRACX_DISABLED_SERVICES = [
46+
# "WorkloadManagement/JobMonitoring",
47+
]
4548

4649
# Static configuration
4750
DB_USER = "Dirac"
@@ -155,8 +158,9 @@ def list_commands(self, ctx):
155158
It will search for legacy adapted services (services with a future client activated)
156159
and do the necessary to make DIRAC work alongside DiracX.
157160
158-
To deactivate a legacy adapted service (to pass CI for example), you have to set in the old
159-
client the `diracxClient` field to "None". Else, set it to the right future client instance.
161+
To deactivate a legacy adapted service (to pass CI for example), you have to add it in
162+
the `DIRACX_DISABLED_SERVICES` list. If you don't, the program will set this service to be used
163+
with DiracX, and if it is badly adapted, errors will be raised.
160164
161165
> Note that you can provide a DiracX project (repository, branch) by building it and providing
162166
the dist folder to the prepare-environment command.
@@ -1184,10 +1188,16 @@ def _make_config(modules, flags, release_var, editable):
11841188
typer.secho(f"Required feature variable {key!r} is missing", err=True, fg=c.RED)
11851189
raise typer.Exit(code=1)
11861190

1187-
# If we test DiracX, enable all the options
1191+
# If we test DiracX, add specific config
11881192
if config["TEST_DIRACX"].lower() in ("yes", "true"):
1189-
for key in DIRACX_OPTIONS:
1190-
config[key] = "Yes"
1193+
if DIRACX_DISABLED_SERVICES:
1194+
# We link all disabled services
1195+
# config["DIRACX_DISABLED_SERVICES"] = "Service1 Service2 Service3 ..."
1196+
diracx_disabled_services = " ".join(DIRACX_DISABLED_SERVICES)
1197+
1198+
typer.secho(f"The following services won't be legacy adapted: {diracx_disabled_services}", fg="yellow")
1199+
1200+
config["DIRACX_DISABLED_SERVICES"] = diracx_disabled_services
11911201

11921202
config["TESTREPO"] = [f"/home/dirac/LocalRepo/TestCode/{name}" for name in modules]
11931203
config["ALTERNATIVE_MODULES"] = [f"/home/dirac/LocalRepo/ALTERNATIVE_MODULES/{name}" for name in modules]

src/DIRAC/Core/Tornado/Client/ClientSelector.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,28 @@ def ClientSelector(disetClient, *args, **kwargs): # We use same interface as RP
6565
# If we are not already given a URL, resolve it
6666
if serviceName.startswith(("http", "dip")):
6767
completeUrl = serviceName
68+
elif useLegacyAdapter(serviceName):
69+
sLog.debug(f"Using legacy adapter for service {serviceName}")
70+
if diracxClient is None:
71+
raise NotImplementedError(
72+
"DiracX is enabled but no diracxClient is provided, do you need to update your client?"
73+
)
74+
return diracxClient()
6875
else:
69-
isServiceLegacyAdapted = useLegacyAdapter(serviceName)
70-
if isServiceLegacyAdapted and diracxClient is not None:
71-
sLog.debug(f"Using legacy adapter for service {serviceName}")
72-
return diracxClient()
73-
else:
74-
if isServiceLegacyAdapted:
75-
# Only warn to deactivate it without making the code crash.
76-
sLog.warn(
77-
f"FutureClient for {serviceName} is provided but not activated, do you need to update your client?"
78-
)
79-
8076
completeUrl = getServiceURL(serviceName)
8177
sLog.debug(f"URL resolved: {completeUrl}")
8278

8379
if completeUrl.startswith("http"):
8480
sLog.debug(f"Using HTTPS for service {serviceName}")
85-
return tornadoClient(*args, **kwargs)
81+
rpc = tornadoClient(*args, **kwargs)
82+
else:
83+
rpc = disetClient(*args, **kwargs)
8684
except Exception as e: # pylint: disable=broad-except
8785
# If anything went wrong in the resolution, we return default RPCClient
8886
# So the behaviour is exactly the same as before implementation of Tornado
8987
sLog.warn("Could not select DISET or Tornado client", f"{repr(e)}")
90-
sLog.exception()
91-
return disetClient(*args, **kwargs)
88+
rpc = disetClient(*args, **kwargs)
89+
return rpc
9290

9391

9492
# Client to use for RPC selection

src/DIRAC/WorkloadManagementSystem/Client/JobMonitoringClient.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414

1515
@createClient("WorkloadManagement/JobMonitoring")
1616
class JobMonitoringClient(Client):
17+
diracxClient = None
18+
1719
def __init__(self, **kwargs):
1820
super().__init__(**kwargs)
1921
self.setServer("WorkloadManagement/JobMonitoring")
2022

21-
# Set to NULL to avoid using it in ClientSelector
22-
diracxClient = None
23-
2423
@ignoreEncodeWarning
2524
def getJobsStatus(self, jobIDs):
2625
res = self._getRPC().getJobsStatus(jobIDs)

tests/CI/docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ services:
278278
- DIRACX_SERVICE_AUTH_STATE_KEY=uSNPPtZ1EbC5np13zOwmWJ84Duix753Hejzk/u/MQE4=
279279
# Obtained with echo 'InsecureChangeMe' | base64 -d | openssl sha256
280280
- DIRACX_LEGACY_EXCHANGE_HASHED_API_KEY=07cddf6948d316ac9d186544dc3120c4c6697d8f994619665985c0a5bf76265a
281-
- DIRACX_SERVICE_JOBS_ENABLED=true
282281
- 'DIRACX_OS_DB_JOBPARAMETERSDB={"hosts": "elastic:changeme@opensearch:9200", "use_ssl": false, "verify_certs": false}'
283282
- DIRACX_SANDBOX_STORE_BUCKET_NAME=sandboxes
284283
- DIRACX_SANDBOX_STORE_AUTO_CREATE_BUCKET=true

tests/Jenkins/dirac_ci.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,23 @@ installSite() {
168168
# Only if we have TEST_DIRACX we can have a legacy_adapted service, or it will crash
169169
# "Missing mandatory /DiracX/URL configuration"
170170
# Call findFutureServices and read services into an array
171-
mapfile -t futureServices < <(python -m DIRAC.Core.Utilities.Extensions findFutureServices | sed 's/System / /g' | sed 's/Handler//g' | sed 's/Client//g' | sed 's/ /\//g')
172171

173-
# If there are any services, add them to the args
172+
# Prepare grep pattern to exclude disabled services
173+
disabledPattern=$(printf "%s\n" $DIRACX_DISABLED_SERVICES | sed 's/^/^/; s/$/$/' | paste -sd'|' -)
174+
175+
# Load and filter future services using grep -vF
176+
mapfile -t futureServices < <(
177+
python -m DIRAC.Core.Utilities.Extensions findFutureServices |
178+
sed 's/System / /g' |
179+
sed 's/Handler//g' |
180+
sed 's/Client//g' |
181+
sed 's/ /\//g' |
182+
grep -Ev "${disabledPattern}"
183+
)
184+
185+
echo "Legacy adapted services after filtering: $(IFS=' '; echo "${futureServices[*]}")"
186+
187+
# If there are any remaining services, add them to args
174188
if [[ ${#futureServices[@]} -gt 0 ]]; then
175189
diracxSetupArgs+=(--legacy-adapted-services "${futureServices[@]}")
176190
fi

0 commit comments

Comments
 (0)