Browse Source

Sync charm-helpers to ensure Rocky support

Change-Id: Ib1fb899fbbe89158b0b5309b7fa8cb78229c9e40
Chris MacNaughton 10 months ago
parent
commit
43d868dc21

+ 10
- 5
hooks/charmhelpers/contrib/charmsupport/nrpe.py View File

@@ -410,16 +410,21 @@ def add_init_service_checks(nrpe, services, unit_name, immediate_check=True):
410 410
                 os.chmod(checkpath, 0o644)
411 411
 
412 412
 
413
-def copy_nrpe_checks():
413
+def copy_nrpe_checks(nrpe_files_dir=None):
414 414
     """
415 415
     Copy the nrpe checks into place
416 416
 
417 417
     """
418 418
     NAGIOS_PLUGINS = '/usr/local/lib/nagios/plugins'
419
-    nrpe_files_dir = os.path.join(os.getenv('CHARM_DIR'), 'hooks',
420
-                                  'charmhelpers', 'contrib', 'openstack',
421
-                                  'files')
422
-
419
+    default_nrpe_files_dir = os.path.join(
420
+        os.getenv('CHARM_DIR'),
421
+        'hooks',
422
+        'charmhelpers',
423
+        'contrib',
424
+        'openstack',
425
+        'files')
426
+    if not nrpe_files_dir:
427
+        nrpe_files_dir = default_nrpe_files_dir
423 428
     if not os.path.exists(NAGIOS_PLUGINS):
424 429
         os.makedirs(NAGIOS_PLUGINS)
425 430
     for fname in glob.glob(os.path.join(nrpe_files_dir, "check_*")):

+ 14
- 0
hooks/charmhelpers/core/host.py View File

@@ -972,6 +972,20 @@ def is_container():
972 972
 
973 973
 
974 974
 def add_to_updatedb_prunepath(path, updatedb_path=UPDATEDB_PATH):
975
+    """Adds the specified path to the mlocate's udpatedb.conf PRUNEPATH list.
976
+
977
+    This method has no effect if the path specified by updatedb_path does not
978
+    exist or is not a file.
979
+
980
+    @param path: string the path to add to the updatedb.conf PRUNEPATHS value
981
+    @param updatedb_path: the path the updatedb.conf file
982
+    """
983
+    if not os.path.exists(updatedb_path) or os.path.isdir(updatedb_path):
984
+        # If the updatedb.conf file doesn't exist then don't attempt to update
985
+        # the file as the package providing mlocate may not be installed on
986
+        # the local system
987
+        return
988
+
975 989
     with open(updatedb_path, 'r+') as f_id:
976 990
         updatedb_text = f_id.read()
977 991
         output = updatedb(updatedb_text, path)

+ 1
- 1
hooks/charmhelpers/fetch/ubuntu.py View File

@@ -315,7 +315,7 @@ def import_key(key):
315 315
         cmd = ['apt-key', 'adv', '--keyserver',
316 316
                'hkp://keyserver.ubuntu.com:80', '--recv-keys', key]
317 317
         try:
318
-            subprocess.check_call(cmd)
318
+            _run_with_retries(cmd)
319 319
         except subprocess.CalledProcessError:
320 320
             error = "Error importing PGP key '{}'".format(key)
321 321
             log(error)

+ 14
- 0
tests/charmhelpers/core/host.py View File

@@ -972,6 +972,20 @@ def is_container():
972 972
 
973 973
 
974 974
 def add_to_updatedb_prunepath(path, updatedb_path=UPDATEDB_PATH):
975
+    """Adds the specified path to the mlocate's udpatedb.conf PRUNEPATH list.
976
+
977
+    This method has no effect if the path specified by updatedb_path does not
978
+    exist or is not a file.
979
+
980
+    @param path: string the path to add to the updatedb.conf PRUNEPATHS value
981
+    @param updatedb_path: the path the updatedb.conf file
982
+    """
983
+    if not os.path.exists(updatedb_path) or os.path.isdir(updatedb_path):
984
+        # If the updatedb.conf file doesn't exist then don't attempt to update
985
+        # the file as the package providing mlocate may not be installed on
986
+        # the local system
987
+        return
988
+
975 989
     with open(updatedb_path, 'r+') as f_id:
976 990
         updatedb_text = f_id.read()
977 991
         output = updatedb(updatedb_text, path)

Loading…
Cancel
Save