← Back to team overview

nagios-charmers team mailing list archive

[Merge] ~aieri/hw-health-charm:oo-rewrite-prep1 into hw-health-charm:oo-rewrite-integration

 

Andrea Ieri has proposed merging ~aieri/hw-health-charm:oo-rewrite-prep1 into hw-health-charm:oo-rewrite-integration.

Commit message:
This is the first chunk of the superseded MR#364694

Requested reviews:
  Canonical IS Reviewers (canonical-is-reviewers)

For more details, see:
https://code.launchpad.net/~aieri/hw-health-charm/+git/hw-health-charm/+merge/364750
-- 
Your team Nagios Charm developers is subscribed to branch hw-health-charm:oo-rewrite-integration.
diff --git a/src/files/megaraid/check_megacli.py b/src/files/megacli/check_megacli.py
similarity index 100%
rename from src/files/megaraid/check_megacli.py
rename to src/files/megacli/check_megacli.py
diff --git a/src/files/megaraid/check_megacli.sh b/src/files/megacli/check_megacli.sh
similarity index 100%
rename from src/files/megaraid/check_megacli.sh
rename to src/files/megacli/check_megacli.sh
diff --git a/src/layer.yaml b/src/layer.yaml
index 054b43e..893978e 100644
--- a/src/layer.yaml
+++ b/src/layer.yaml
@@ -4,6 +4,7 @@ includes:
 - "layer:status"
 - "layer:nagios"
 - "layer:snap"
+- "interface:juju-info"
 - "interface:nrpe-external-master"
 options:
   status:
diff --git a/src/lib/utils/__init__.py b/src/lib/hwhealth/__init__.py
similarity index 100%
rename from src/lib/utils/__init__.py
rename to src/lib/hwhealth/__init__.py
diff --git a/src/lib/utils/hwdiscovery.py b/src/lib/hwhealth/hwdiscovery.py
similarity index 100%
rename from src/lib/utils/hwdiscovery.py
rename to src/lib/hwhealth/hwdiscovery.py
diff --git a/src/lib/utils/tooling.py b/src/lib/hwhealth/tooling.py
similarity index 100%
rename from src/lib/utils/tooling.py
rename to src/lib/hwhealth/tooling.py
diff --git a/src/reactive/hw_health.py b/src/reactive/hw_health.py
index d1a0fc6..20bc354 100644
--- a/src/reactive/hw_health.py
+++ b/src/reactive/hw_health.py
@@ -4,13 +4,14 @@ from charmhelpers.core import hookenv, host, unitdata
 from charms.layer import status
 from charms.reactive import (
     clear_flag,
+    hook,
     set_flag,
     when,
     when_none,
     when_not,
 )
-from utils.hwdiscovery import get_tools
-from utils.tooling import (
+from hwhealth.hwdiscovery import get_tools
+from hwhealth.tooling import (
     configure_nrpe_checks,
     install_resource,
     remove_nrpe_checks,
@@ -66,24 +67,27 @@ def install():
             status.blocked('Tools not found: {}'.format(', '.join(missing_tools)))
 
 
-@when('hw-health.installed')
-@when('nrpe-external-master.available')
+@hook('upgrade-charm')
+def upgrade():
+    clear_flag('hw-health.installed')
+    clear_flag('hw-health.unsupported')
+    clear_flag('hw-health.configured')
+    status.maintenance('Charm upgrade in progress')
+
+
+@hook('stop')
 def remove_checks(nrpe):
-    if hookenv.hook_name() == 'stop':
-        # Note(aluria): Remove nrpe check(s)
-        kv = unitdata.kv()
-        tools = kv.get('tools', set())
-        removed = remove_nrpe_checks(tools)
-        if removed:
-            nrpe.updated()
+    # Note(aluria): Remove nrpe check(s)
+    kv = unitdata.kv()
+    tools = kv.get('tools', set())
+    removed = remove_nrpe_checks(tools)
+    if removed:
+        nrpe.updated()
 
 
 @when('config.changed')
 def config_changed():
-    # clear_flag('hw-health.configured')
-    clear_flag('hw-health.installed')
-    clear_flag('hw-health.unsupported')
-    clear_flag('hw-health.nrpe')
+    clear_flag('hw-health.configured')
 
 
 @when('hw-health.installed')
@@ -94,7 +98,7 @@ def blocked_on_nrpe():
 
 @when('hw-health.installed')
 @when('nrpe-external-master.available')
-@when_not('hw-health.nrpe')
+@when_not('hw-health.configured')
 def configure_nrpe():
     if not os.path.exists('/var/lib/nagios'):
         status.waiting('Waiting for nrpe package installation')
@@ -108,6 +112,6 @@ def configure_nrpe():
     configured = configure_nrpe_checks(tools)
     if configured:
         status.active('ready')
-        set_flag('hw-health.nrpe')
+        set_flag('hw-health.configured')
     else:
         status.waiting('Missing tools to monitor hw health')
diff --git a/src/tests/download_nagios_plugin3.py b/src/tests/download_nagios_plugin3.py
index 0505ec8..173fa31 100755
--- a/src/tests/download_nagios_plugin3.py
+++ b/src/tests/download_nagios_plugin3.py
@@ -18,7 +18,7 @@ def content():
 
 
 def main():
-    for i in glob('.tox/py3/lib/python3*'):
+    for i in glob('.tox/unit/lib/python3*'):
         mod_path = os.path.join(i, MODULE_NAME)
         if os.path.isdir(i) and not os.path.exists(mod_path):
             open(mod_path, 'wb').write(content())
diff --git a/src/tests/unit/test_check_megacli.py b/src/tests/unit/test_check_megacli.py
index 3fc9b6b..d2e21c4 100644
--- a/src/tests/unit/test_check_megacli.py
+++ b/src/tests/unit/test_check_megacli.py
@@ -4,7 +4,7 @@ import sys
 import unittest
 import unittest.mock as mock
 
-sys.path.append('files/megaraid')
+sys.path.append('files/megacli')
 import check_megacli  # noqa: E402
 
 
diff --git a/src/tests/unit/test_hwdiscovery.py b/src/tests/unit/test_hwdiscovery.py
index 7cb516e..06b5f95 100644
--- a/src/tests/unit/test_hwdiscovery.py
+++ b/src/tests/unit/test_hwdiscovery.py
@@ -5,7 +5,7 @@ import sys
 import unittest
 import unittest.mock as mock
 
-sys.path.append('lib/utils')
+sys.path.append('lib/hwhealth')
 import hwdiscovery  # noqa: E402
 
 
diff --git a/src/tests/unit/test_tooling.py b/src/tests/unit/test_tooling.py
index 5236f6e..3421b7f 100644
--- a/src/tests/unit/test_tooling.py
+++ b/src/tests/unit/test_tooling.py
@@ -5,7 +5,7 @@ import unittest.mock as mock
 import zipfile
 
 
-sys.path.append('lib/utils')
+sys.path.append('lib/hwhealth')
 import tooling  # noqa: E402
 
 
diff --git a/src/tox.ini b/src/tox.ini
index 522cffd..04b6de8 100644
--- a/src/tox.ini
+++ b/src/tox.ini
@@ -4,7 +4,6 @@ skipsdist = true
 
 [testenv:unit]
 basepython=python3
-envdir={toxworkdir}/py3
 deps=
   charms.reactive
   nose

Follow ups