diff --git a/hooks/odl_controller_hooks.py b/hooks/odl_controller_hooks.py index fa3ea10..3170f1a 100755 --- a/hooks/odl_controller_hooks.py +++ b/hooks/odl_controller_hooks.py @@ -41,7 +41,7 @@ from charmhelpers.fetch import ( configure_sources, apt_install, install_remote) from odl_controller_utils import write_mvn_config, process_odl_cmds -from odl_controller_utils import PROFILES +from odl_controller_utils import PROFILES, assess_status PACKAGES = ["default-jre-headless", "python-jinja2"] KARAF_PACKAGE = "opendaylight-karaf" @@ -117,6 +117,7 @@ def main(): hooks.execute(sys.argv) except UnregisteredHookError as e: log("Unknown hook {} - skipping.".format(e)) + assess_status() @hooks.hook("ovsdb-manager-relation-joined") diff --git a/hooks/odl_controller_utils.py b/hooks/odl_controller_utils.py index 7dda86f..3a3011a 100644 --- a/hooks/odl_controller_utils.py +++ b/hooks/odl_controller_utils.py @@ -17,8 +17,9 @@ from os import environ import urlparse from charmhelpers.core.templating import render -from charmhelpers.core.hookenv import config +from charmhelpers.core.hookenv import config, status_set from charmhelpers.core.decorators import retry_on_exception +from charmhelpers.core.host import service_running PROFILES = { @@ -170,3 +171,11 @@ def process_odl_cmds(odl_cmds): for log_level in logging.keys(): for target in logging[log_level]: run_odl(["log:set", log_level, target]) + + +def assess_status(): + '''Assess unit status and inform juju using status-set''' + if service_running('odl-controller'): + status_set('active', 'Unit is ready') + else: + status_set('blocked', 'ODL controller not running') diff --git a/unit_tests/test_odl_controller_utils.py b/unit_tests/test_odl_controller_utils.py index d18a9e6..0218a5a 100644 --- a/unit_tests/test_odl_controller_utils.py +++ b/unit_tests/test_odl_controller_utils.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from mock import patch, call +from mock import patch, call, ANY from test_utils import CharmTestCase import odl_controller_utils as utils @@ -105,3 +105,16 @@ class ODLControllerUtilsTests(CharmTestCase): call(["feature:install", "odl-l2switch-all"]), call(['log:set', 'TRACE', 'cosc-cvpn-ovs-rest']) ]) + + @patch.object(utils, 'service_running') + @patch.object(utils, 'status_set') + def test_assess_status(self, status_set, service_running): + service_running.return_value = False + utils.assess_status() + service_running.assert_called_with('odl-controller') + status_set.assert_called_with('blocked', ANY) + + service_running.return_value = True + utils.assess_status() + service_running.assert_called_with('odl-controller') + status_set.assert_called_with('active', ANY)