Add basic juju status support
Add a basic assess_status helper to evaluate the current state of the unit; this is currently just a check to ensure that the odl-controller service is running. Closes-Bug: 1632032 Change-Id: I008cdf0da04f2ad68291a53ae6a8cb7334979cf6
This commit is contained in:
parent
9d8e489229
commit
608be92d73
|
@ -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")
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue