Skip to content

Commit a8948eb

Browse files
committed
fix: monitoring the installation takes a user
1 parent 35b9c17 commit a8948eb

File tree

3 files changed

+38
-31
lines changed

3 files changed

+38
-31
lines changed

src/DIRAC/Core/scripts/dirac_install_db.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"""
33
Create a new DB in the MySQL server
44
"""
5+
from DIRAC import exit as DIRACExit
6+
from DIRAC import gConfig, gLogger
57
from DIRAC.Core.Base.Script import Script
68

79

@@ -12,7 +14,8 @@ def main():
1214
_, args = Script.parseCommandLine()
1315

1416
# Script imports
15-
from DIRAC import gConfig
17+
from DIRAC.ConfigurationSystem.Client.Helpers.CSGlobals import useServerCertificate
18+
from DIRAC.Core.Security.ProxyInfo import getProxyInfo
1619
from DIRAC.FrameworkSystem.Client.ComponentInstaller import gComponentInstaller
1720
from DIRAC.FrameworkSystem.Utilities import MonitoringUtilities
1821

@@ -21,15 +24,31 @@ def main():
2124
for db in args:
2225
result = gComponentInstaller.installDatabase(db)
2326
if not result["OK"]:
24-
print(f"ERROR: failed to correctly install {db}", result["Message"])
25-
continue
27+
gLogger.error(f"ERROR: failed to correctly install {db}", result["Message"])
28+
DIRACExit(1)
2629
extension, system = result["Value"]
27-
gComponentInstaller.addDatabaseOptionsToCS(gConfig, system, db, overwrite=True)
30+
result = gComponentInstaller.addDatabaseOptionsToCS(gConfig, system, db, overwrite=True)
31+
if not result["OK"]:
32+
gLogger.error(f"ERROR: failed to add database options to CS: {result['Message']}")
33+
DIRACExit(1)
2834

2935
if db != "InstalledComponentsDB":
30-
result = MonitoringUtilities.monitorInstallation("DB", system, db)
36+
37+
# get the user that installed the DB
38+
if useServerCertificate():
39+
user = "DIRAC"
40+
else:
41+
result = getProxyInfo()
42+
if not result["OK"]:
43+
return result
44+
proxyInfo = result["Value"]
45+
if "username" in proxyInfo:
46+
user = proxyInfo["username"]
47+
48+
result = MonitoringUtilities.monitorInstallation("DB", system, db, user=user)
3149
if not result["OK"]:
32-
print(f"ERROR: failed to register installation in database: {result['Message']}")
50+
gLogger.error(f"ERROR: failed to register installation in database: {result['Message']}")
51+
DIRACExit(1)
3352

3453

3554
if __name__ == "__main__":

src/DIRAC/FrameworkSystem/Client/SystemAdministratorClientCLI.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import time
1212

1313
from DIRAC import gConfig, gLogger
14-
from DIRAC.ConfigurationSystem.Client.Helpers import CSGlobals
1514
from DIRAC.Core.Base.CLI import CLI, colorize
1615
from DIRAC.Core.Security.ProxyInfo import getProxyInfo
1716
from DIRAC.Core.Utilities import List
@@ -623,6 +622,11 @@ def do_install(self, args):
623622
install agent <system> <agent> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ...
624623
install executor <system> <executor> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ...
625624
"""
625+
result = getProxyInfo()
626+
if not result["OK"]:
627+
self._errMsg(result["Message"])
628+
user = result["Value"]["username"]
629+
626630
argss = args.split()
627631
hostSetup = extension = None
628632
if not argss:
@@ -673,7 +677,7 @@ def do_install(self, args):
673677

674678
if database != "InstalledComponentsDB":
675679
result = MonitoringUtilities.monitorInstallation(
676-
"DB", system.replace("System", ""), database, cpu=cpu, hostname=hostname
680+
"DB", system.replace("System", ""), database, cpu=cpu, hostname=hostname, user=user
677681
)
678682
if not result["OK"]:
679683
self._errMsg(result["Message"])
@@ -786,14 +790,14 @@ def do_install(self, args):
786790
return
787791

788792
result = MonitoringUtilities.monitorInstallation(
789-
"DB", system, "InstalledComponentsDB", cpu=cpu, hostname=hostname
793+
"DB", system, "InstalledComponentsDB", cpu=cpu, hostname=hostname, user=user
790794
)
791795
if not result["OK"]:
792796
self._errMsg(f"Error registering installation into database: {result['Message']}")
793797
return
794798

795799
result = MonitoringUtilities.monitorInstallation(
796-
option, system, component, module, cpu=cpu, hostname=hostname
800+
option, system, component, module, cpu=cpu, hostname=hostname, user=user
797801
)
798802
if not result["OK"]:
799803
self._errMsg(f"Error registering installation into database: {result['Message']}")
@@ -820,6 +824,7 @@ def do_uninstall(self, args):
820824
result = getProxyInfo()
821825
if not result["OK"]:
822826
self._errMsg(result["Message"])
827+
user = result["Value"]["username"]
823828

824829
option = argss[0]
825830
if option == "db":
@@ -842,7 +847,7 @@ def do_uninstall(self, args):
842847
self._errMsg(result["Message"])
843848
return
844849
system = result["Value"][component]["System"]
845-
result = MonitoringUtilities.monitorUninstallation(system, component, hostname=hostname, cpu=cpu)
850+
result = MonitoringUtilities.monitorUninstallation(system, component, hostname=hostname, cpu=cpu, user=user)
846851
if not result["OK"]:
847852
self._errMsg(result["Message"])
848853
return
@@ -937,7 +942,7 @@ def do_uninstall(self, args):
937942
else:
938943
cpu = result["Value"]["CPUModel"]
939944
hostname = self.host
940-
result = MonitoringUtilities.monitorUninstallation(system, component, hostname=hostname, cpu=cpu)
945+
result = MonitoringUtilities.monitorUninstallation(system, component, hostname=hostname, cpu=cpu, user=user)
941946
if not result["OK"]:
942947
return result
943948

src/DIRAC/FrameworkSystem/Utilities/MonitoringUtilities.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66

77
from DIRAC import S_OK
88
from DIRAC.FrameworkSystem.Client.ComponentMonitoringClient import ComponentMonitoringClient
9-
from DIRAC.Core.Security.ProxyInfo import getProxyInfo
109

1110

12-
def monitorInstallation(componentType, system, component, module=None, cpu=None, hostname=None):
11+
def monitorInstallation(componentType, system, component, module=None, cpu=None, hostname=None, user=None):
1312
"""
1413
Register the installation of a component in the InstalledComponentsDB
1514
"""
@@ -19,14 +18,6 @@ def monitorInstallation(componentType, system, component, module=None, cpu=None,
1918
module = component
2019

2120
# Retrieve user installing the component
22-
user = None
23-
result = getProxyInfo()
24-
if result["OK"]:
25-
proxyInfo = result["Value"]
26-
if "username" in proxyInfo:
27-
user = proxyInfo["username"]
28-
else:
29-
return result
3021
if not user:
3122
user = "unknown"
3223

@@ -61,21 +52,13 @@ def monitorInstallation(componentType, system, component, module=None, cpu=None,
6152
return result
6253

6354

64-
def monitorUninstallation(system, component, cpu=None, hostname=None):
55+
def monitorUninstallation(system, component, cpu=None, hostname=None, user=None):
6556
"""
6657
Register the uninstallation of a component in the InstalledComponentsDB
6758
"""
6859
monitoringClient = ComponentMonitoringClient()
6960

7061
# Retrieve user uninstalling the component
71-
user = None
72-
result = getProxyInfo()
73-
if result["OK"]:
74-
proxyInfo = result["Value"]
75-
if "username" in proxyInfo:
76-
user = proxyInfo["username"]
77-
else:
78-
return result
7962
if not user:
8063
user = "unknown"
8164

0 commit comments

Comments
 (0)