Merge lp:~sdn-charmers/charms/trusty/odl-controller/odl-cmds into lp:~sdn-charmers/charms/trusty/odl-controller/trunk

Proposed by Liam Young on 2015-06-16
Status: Merged
Merged at revision: 5
Proposed branch: lp:~sdn-charmers/charms/trusty/odl-controller/odl-cmds
Merge into: lp:~sdn-charmers/charms/trusty/odl-controller/trunk
Diff against target: 171 lines (+69/-11)
2 files modified
hooks/odl_controller_hooks.py (+28/-11)
hooks/odl_controller_utils.py (+41/-0)
To merge this branch: bzr merge lp:~sdn-charmers/charms/trusty/odl-controller/odl-cmds
Reviewer Review Type Date Requested Status
SDN Charmers 2015-06-16 Pending
Review via email: mp+262095@code.launchpad.net
To post a comment you must log in.
Liam Young (gnuoy) wrote :

The post install commands that were being run no longer work on more recent versions of ODL because the features being requested have been renamed or removed.

This mp removes any default commands. Instead, a charm joined via the controller-api relation can request features so be installed or log settings to be set by setting odl-cmds to a string representation of json.

eg

{
    'feature:install': ['cosc-cvpn-ovs-rest', 'odl-netconf-connector-all'],
    'log:set': {
        'TRACE': ['cosc-cvpn-ovs-rest', 'odl-netconf-connector-all'],
    }
}

The above would request the installation of cosc-cvpn-ovs-rest and odl-netconf-connector-all and set logging to trace for cosc-cvpn-ovs-rest and odl-netconf-connector-all

Liam Young (gnuoy) wrote :

The filter_installed function was added on the assumption that installing features was an expensive operation, it might not be so this may be overkill

Robert Ayres (robert-ayres) wrote :

Are you using an auto-formatter? Seems to be some formatting changes that aren't related to functionality.

Liam Young (gnuoy) wrote :

I fixed some flake8 complaints while I was at it

6. By Liam Young on 2015-06-16

Switch to double quotes for consistency

Jason Hobbs (jason-hobbs) wrote :

When using this, port 8080 on the controller isn't listening.

https://ask.opendaylight.org/question/919/resource-error-using-port-8080/

This makes it look like we need: odl-nsf-all and odl-adsal-compatibility installed for port 8080 to come up.

Is there a corresponding branch for neutron-api to issue that that odl-cmds?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/odl_controller_hooks.py'
2--- hooks/odl_controller_hooks.py 2015-03-16 19:56:22 +0000
3+++ hooks/odl_controller_hooks.py 2015-06-16 16:35:08 +0000
4@@ -1,5 +1,6 @@
5 #!/usr/bin/env python
6
7+import json
8 import os
9 import re
10 import shutil
11@@ -12,35 +13,51 @@
12 UnregisteredHookError,
13 config,
14 log,
15- relation_set
16+ relation_get,
17+ relation_ids,
18+ relation_set,
19+ related_units,
20 )
21
22 from charmhelpers.core.host import (
23 adduser,
24 mkdir,
25 restart_on_change,
26- service_restart,
27 service_start
28 )
29
30 from charmhelpers.fetch import apt_install, install_remote
31
32-from odl_controller_utils import write_mvn_config
33+from odl_controller_utils import write_mvn_config, process_odl_cmds
34
35-PACKAGES = [ "default-jre-headless", "python-jinja2" ]
36+PACKAGES = ["default-jre-headless", "python-jinja2"]
37
38 hooks = Hooks()
39 config = config()
40
41+
42 @hooks.hook("config-changed")
43 @restart_on_change({"/home/opendaylight/.m2/settings.xml": ["odl-controller"]})
44 def config_changed():
45 write_mvn_config()
46
47+
48 @hooks.hook("controller-api-relation-joined")
49 def controller_api_joined():
50 relation_set(port=8080, username="admin", password="admin")
51
52+
53+@hooks.hook("controller-api-relation-changed")
54+def controller_api_changed():
55+ for rid in relation_ids("controller-api"):
56+ for unit in related_units(rid):
57+ odl_cmds_json = relation_get(rid=rid, unit=unit,
58+ attribute="odl-cmds")
59+ if odl_cmds_json:
60+ odl_cmds = json.loads(odl_cmds_json)
61+ process_odl_cmds(odl_cmds)
62+
63+
64 @hooks.hook()
65 def install():
66 # install dependencies
67@@ -54,18 +71,16 @@
68 os.symlink(name, "/opt/opendaylight-karaf")
69 shutil.copy("files/odl-controller.conf", "/etc/init")
70 adduser("opendaylight", system_user=True)
71- mkdir("/home/opendaylight", owner="opendaylight", group="opendaylight", perms=0755)
72+ mkdir("/home/opendaylight", owner="opendaylight", group="opendaylight",
73+ perms=0755)
74 check_call(["chown", "-R", "opendaylight:opendaylight", "/opt/" + name])
75- mkdir("/var/log/opendaylight", owner="opendaylight", group="opendaylight", perms=0755)
76+ mkdir("/var/log/opendaylight", owner="opendaylight", group="opendaylight",
77+ perms=0755)
78
79 # install features
80 write_mvn_config()
81 service_start("odl-controller")
82- check_call(["/opt/opendaylight-karaf/bin/client", "-r", "61",
83- "feature:install", "odl-base-all", "odl-aaa-authn",
84- "odl-restconf", "odl-nsf-all", "odl-adsal-northbound",
85- "odl-mdsal-apidocs", "odl-ovsdb-openstack",
86- "odl-ovsdb-northbound", "odl-dlux-core"])
87+
88
89 def main():
90 try:
91@@ -73,10 +88,12 @@
92 except UnregisteredHookError as e:
93 log("Unknown hook {} - skipping.".format(e))
94
95+
96 @hooks.hook("ovsdb-manager-relation-joined")
97 def ovsdb_manager_joined():
98 relation_set(port=6640, protocol="tcp")
99
100+
101 @hooks.hook("upgrade-charm")
102 def upgrade_charm():
103 pass
104
105=== modified file 'hooks/odl_controller_utils.py'
106--- hooks/odl_controller_utils.py 2015-02-19 22:08:13 +0000
107+++ hooks/odl_controller_utils.py 2015-06-16 16:35:08 +0000
108@@ -1,14 +1,17 @@
109+import subprocess
110 from os import environ
111 import urlparse
112
113 from charmhelpers.core.templating import render
114
115+
116 def mvn_ctx():
117 ctx = {}
118 ctx.update(mvn_proxy_ctx("http"))
119 ctx.update(mvn_proxy_ctx("https"))
120 return ctx
121
122+
123 def mvn_proxy_ctx(protocol):
124 ctx = {}
125 key = protocol + "_proxy"
126@@ -32,7 +35,45 @@
127 ctx[protocol + "_noproxy"] = no_proxy
128 return ctx
129
130+
131 def write_mvn_config():
132 ctx = mvn_ctx()
133 render("settings.xml", "/home/opendaylight/.m2/settings.xml", ctx,
134 "opendaylight", "opendaylight", 0400)
135+
136+
137+def run_odl(cmds, host="localhost", port=8101, retries=20):
138+ run_cmd = ["/opt/opendaylight-karaf/bin/client", "-r", str(retries),
139+ "-h", host, "-a", str(port)]
140+ run_cmd.extend(cmds)
141+ output = subprocess.check_output(run_cmd)
142+ return output
143+
144+
145+def installed_features():
146+ installed = []
147+ out = run_odl(["feature:list"])
148+ for line in out.split("\n"):
149+ columns = line.split("|")
150+ if len(columns) > 2:
151+ install_flag = columns[2].replace(" ", "")
152+ if install_flag == "x":
153+ installed.append(columns[0].replace(" ", ""))
154+ return installed
155+
156+
157+def filter_installed(features):
158+ installed = installed_features()
159+ whitelist = [feature for feature in features if feature not in installed]
160+ return whitelist
161+
162+
163+def process_odl_cmds(odl_cmds):
164+ features = filter_installed(odl_cmds.get("feature:install", []))
165+ if features:
166+ run_odl(["feature:install"] + features)
167+ logging = odl_cmds.get("log:set")
168+ if logging:
169+ for log_level in logging.keys():
170+ for target in logging[log_level]:
171+ run_odl(["log:set", log_level, target])

Subscribers

People subscribed via source and target branches

to all changes: