Matteo Scandolo | 48d3d2d | 2017-08-08 13:05:27 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 17 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 18 | # Copyright 2016-present Ciena Corporation |
| 19 | # |
| 20 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 21 | # you may not use this file except in compliance with the License. |
| 22 | # You may obtain a copy of the License at |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 23 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 24 | # http://www.apache.org/licenses/LICENSE-2.0 |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 25 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 26 | # Unless required by applicable law or agreed to in writing, software |
| 27 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 28 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 29 | # See the License for the specific language governing permissions and |
| 30 | # limitations under the License. |
| 31 | # |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 32 | import os,time |
| 33 | import io |
| 34 | import json |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 35 | import yaml |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 36 | import errno |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 37 | import copy |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 38 | from pyroute2 import IPRoute |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 39 | from pyroute2.netlink import NetlinkError |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 40 | from itertools import chain |
| 41 | from nsenter import Namespace |
A R Karthick | 6f2ac6f | 2017-07-26 12:55:24 -0700 | [diff] [blame] | 42 | try: |
| 43 | from docker import APIClient as Client |
| 44 | except: |
| 45 | from docker import Client |
A R Karthick | 85eb186 | 2017-01-23 16:10:57 -0800 | [diff] [blame] | 46 | from docker import utils as dockerutils |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 47 | import shutil |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 48 | from OnosCtrl import OnosCtrl |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 49 | from OnosLog import OnosLog |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 50 | from onosclidriver import OnosCliDriver |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 51 | from threadPool import ThreadPool |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 52 | from threading import Lock |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 53 | |
| 54 | class docker_netns(object): |
| 55 | |
| 56 | dckr = Client() |
| 57 | def __init__(self, name): |
| 58 | pid = int(self.dckr.inspect_container(name)['State']['Pid']) |
| 59 | if pid == 0: |
| 60 | raise Exception('no container named {0}'.format(name)) |
| 61 | self.pid = pid |
| 62 | |
| 63 | def __enter__(self): |
| 64 | pid = self.pid |
| 65 | if not os.path.exists('/var/run/netns'): |
| 66 | os.mkdir('/var/run/netns') |
| 67 | os.symlink('/proc/{0}/ns/net'.format(pid), '/var/run/netns/{0}'.format(pid)) |
| 68 | return str(pid) |
| 69 | |
| 70 | def __exit__(self, type, value, traceback): |
| 71 | pid = self.pid |
| 72 | os.unlink('/var/run/netns/{0}'.format(pid)) |
| 73 | |
| 74 | flatten = lambda l: chain.from_iterable(l) |
| 75 | |
| 76 | class Container(object): |
| 77 | dckr = Client() |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 78 | IMAGE_PREFIX = '' ##for saving global prefix for all test classes |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 79 | CONFIG_LOCK = Lock() |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 80 | |
| 81 | def __init__(self, name, image, prefix='', tag = 'candidate', command = 'bash', quagga_config = None): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 82 | self.name = name |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 83 | self.prefix = prefix |
| 84 | if prefix: |
| 85 | self.prefix += '/' |
| 86 | image = '{}{}'.format(self.prefix, image) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 87 | self.image = image |
| 88 | self.tag = tag |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 89 | if tag: |
| 90 | self.image_name = image + ':' + tag |
| 91 | else: |
| 92 | self.image_name = image |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 93 | self.id = None |
| 94 | self.command = command |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 95 | self.quagga_config = quagga_config |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 96 | |
| 97 | @classmethod |
| 98 | def build_image(cls, dockerfile, tag, force=True, nocache=False): |
| 99 | f = io.BytesIO(dockerfile.encode('utf-8')) |
| 100 | if force or not cls.image_exists(tag): |
| 101 | print('Build {0}...'.format(tag)) |
| 102 | for line in cls.dckr.build(fileobj=f, rm=True, tag=tag, decode=True, nocache=nocache): |
| 103 | if 'stream' in line: |
| 104 | print(line['stream'].strip()) |
| 105 | |
| 106 | @classmethod |
| 107 | def image_exists(cls, name): |
A R Karthick | e07fc3a | 2017-02-27 10:49:29 -0800 | [diff] [blame] | 108 | #return name in [ctn['RepoTags'][0] for ctn in cls.dckr.images()] |
| 109 | return name in list( flatten(ctn['RepoTags'] if ctn['RepoTags'] else '' for ctn in cls.dckr.images()) ) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 110 | |
| 111 | @classmethod |
| 112 | def create_host_config(cls, port_list = None, host_guest_map = None, privileged = False): |
| 113 | port_bindings = None |
| 114 | binds = None |
| 115 | if port_list: |
| 116 | port_bindings = {} |
| 117 | for p in port_list: |
A R Karthick | 184945a | 2017-07-25 17:23:57 -0700 | [diff] [blame] | 118 | if type(p) is tuple: |
| 119 | port_bindings[str(p[0])] = str(p[1]) |
| 120 | else: |
| 121 | port_bindings[str(p)] = str(p) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 122 | |
| 123 | if host_guest_map: |
| 124 | binds = [] |
| 125 | for h, g in host_guest_map: |
| 126 | binds.append('{0}:{1}'.format(h, g)) |
| 127 | |
| 128 | return cls.dckr.create_host_config(binds = binds, port_bindings = port_bindings, privileged = privileged) |
| 129 | |
| 130 | @classmethod |
A R Karthick | 85eb186 | 2017-01-23 16:10:57 -0800 | [diff] [blame] | 131 | def connect_to_network(cls, name, network): |
| 132 | try: |
| 133 | cls.dckr.connect_container_to_network(name, network) |
| 134 | return True |
| 135 | except: |
| 136 | return False |
| 137 | |
| 138 | @classmethod |
| 139 | def create_network(cls, network, subnet = None, gateway = None): |
| 140 | ipam_config = None |
| 141 | if subnet is not None and gateway is not None: |
| 142 | ipam_pool = dockerutils.create_ipam_pool(subnet = subnet, gateway = gateway) |
| 143 | ipam_config = dockerutils.create_ipam_config(pool_configs = [ipam_pool]) |
| 144 | cls.dckr.create_network(network, driver='bridge', ipam = ipam_config) |
| 145 | |
| 146 | @classmethod |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 147 | def cleanup(cls, image): |
A R Karthick | 09b1f4e | 2016-05-12 14:31:50 -0700 | [diff] [blame] | 148 | cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers(all=True)) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 149 | for cnt in cnt_list: |
| 150 | print('Cleaning container %s' %cnt['Id']) |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 151 | if cnt.has_key('State') and cnt['State'] == 'running': |
A R Karthick | 09b1f4e | 2016-05-12 14:31:50 -0700 | [diff] [blame] | 152 | cls.dckr.kill(cnt['Id']) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 153 | cls.dckr.remove_container(cnt['Id'], force=True) |
| 154 | |
| 155 | @classmethod |
| 156 | def remove_container(cls, name, force=True): |
| 157 | try: |
| 158 | cls.dckr.remove_container(name, force = force) |
| 159 | except: pass |
| 160 | |
| 161 | def exists(self): |
| 162 | return '/{0}'.format(self.name) in list(flatten(n['Names'] for n in self.dckr.containers())) |
| 163 | |
| 164 | def img_exists(self): |
A R Karthick | e07fc3a | 2017-02-27 10:49:29 -0800 | [diff] [blame] | 165 | #return self.image_name in [ctn['RepoTags'][0] if ctn['RepoTags'] else '' for ctn in self.dckr.images()] |
| 166 | return self.image_name in list( flatten(ctn['RepoTags'] if ctn['RepoTags'] else '' for ctn in self.dckr.images()) ) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 167 | |
A R Karthick | 7584457 | 2017-01-23 16:57:44 -0800 | [diff] [blame] | 168 | def ip(self, network = None): |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 169 | cnt_list = filter(lambda c: c['Names'][0] == '/{}'.format(self.name), self.dckr.containers()) |
| 170 | #if not cnt_list: |
| 171 | # cnt_list = filter(lambda c: c['Image'] == self.image_name, self.dckr.containers()) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 172 | cnt_settings = cnt_list.pop() |
A R Karthick | 7584457 | 2017-01-23 16:57:44 -0800 | [diff] [blame] | 173 | if network is not None and cnt_settings['NetworkSettings']['Networks'].has_key(network): |
| 174 | return cnt_settings['NetworkSettings']['Networks'][network]['IPAddress'] |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 175 | return cnt_settings['NetworkSettings']['Networks']['bridge']['IPAddress'] |
| 176 | |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 177 | @classmethod |
| 178 | def ips(cls, image_name): |
| 179 | cnt_list = filter(lambda c: c['Image'] == image_name, cls.dckr.containers()) |
| 180 | ips = [ cnt['NetworkSettings']['Networks']['bridge']['IPAddress'] for cnt in cnt_list ] |
| 181 | return ips |
| 182 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 183 | def kill(self, remove = True): |
| 184 | self.dckr.kill(self.name) |
| 185 | self.dckr.remove_container(self.name, force=True) |
| 186 | |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 187 | def start(self, rm = True, ports = None, volumes = None, host_config = None, |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 188 | environment = None, tty = False, stdin_open = True): |
| 189 | |
| 190 | if rm and self.exists(): |
| 191 | print('Removing container:', self.name) |
| 192 | self.dckr.remove_container(self.name, force=True) |
| 193 | |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 194 | ctn = self.dckr.create_container(image=self.image_name, ports = ports, command=self.command, |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 195 | detach=True, name=self.name, |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 196 | environment = environment, |
| 197 | volumes = volumes, |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 198 | host_config = host_config, stdin_open=stdin_open, tty = tty) |
| 199 | self.dckr.start(container=self.name) |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 200 | if self.quagga_config: |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 201 | self.connect_to_br() |
| 202 | self.id = ctn['Id'] |
| 203 | return ctn |
| 204 | |
Thangavelu K S | ef6f0a5 | 2016-12-14 19:57:05 +0000 | [diff] [blame] | 205 | @classmethod |
| 206 | def pause_container(cls, image, delay): |
| 207 | cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers(all=True)) |
| 208 | for cnt in cnt_list: |
| 209 | print('Pause the container %s' %cnt['Id']) |
| 210 | if cnt.has_key('State') and cnt['State'] == 'running': |
| 211 | cls.dckr.pause(cnt['Id']) |
| 212 | if delay != 0: |
| 213 | time.sleep(delay) |
| 214 | for cnt in cnt_list: |
| 215 | print('Unpause the container %s' %cnt['Id']) |
| 216 | cls.dckr.unpause(cnt['Id']) |
| 217 | else: |
| 218 | print('Infinity time pause the container %s' %cnt['Id']) |
| 219 | return 'success' |
| 220 | |
A R Karthick | 5241473 | 2017-01-31 09:59:47 -0800 | [diff] [blame] | 221 | def connect_to_br(self, index = 0): |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 222 | self.CONFIG_LOCK.acquire() |
| 223 | try: |
| 224 | with docker_netns(self.name) as pid: |
| 225 | for quagga_config in self.quagga_config: |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 226 | ip = IPRoute() |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 227 | br = ip.link_lookup(ifname=quagga_config['bridge']) |
| 228 | if len(br) == 0: |
| 229 | try: |
| 230 | ip.link_create(ifname=quagga_config['bridge'], kind='bridge') |
| 231 | except NetlinkError as e: |
| 232 | err, _ = e.args |
| 233 | if err == errno.EEXIST: |
| 234 | pass |
| 235 | else: |
| 236 | raise NetlinkError(*e.args) |
| 237 | br = ip.link_lookup(ifname=quagga_config['bridge']) |
| 238 | br = br[0] |
| 239 | ip.link('set', index=br, state='up') |
A R Karthick | 5241473 | 2017-01-31 09:59:47 -0800 | [diff] [blame] | 240 | ifname = '{0}-{1}'.format(self.name[:12], index) |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 241 | ifs = ip.link_lookup(ifname=ifname) |
| 242 | if len(ifs) > 0: |
| 243 | ip.link_remove(ifs[0]) |
| 244 | peer_ifname = '{0}-{1}'.format(pid, index) |
| 245 | ip.link_create(ifname=ifname, kind='veth', peer=peer_ifname) |
| 246 | host = ip.link_lookup(ifname=ifname)[0] |
| 247 | ip.link('set', index=host, master=br) |
| 248 | ip.link('set', index=host, state='up') |
| 249 | guest = ip.link_lookup(ifname=peer_ifname)[0] |
| 250 | ip.link('set', index=guest, net_ns_fd=pid) |
| 251 | with Namespace(pid, 'net'): |
| 252 | ip = IPRoute() |
| 253 | ip.link('set', index=guest, ifname='eth{}'.format(index+1)) |
| 254 | ip.addr('add', index=guest, address=quagga_config['ip'], mask=quagga_config['mask']) |
| 255 | ip.link('set', index=guest, state='up') |
| 256 | index += 1 |
| 257 | finally: |
| 258 | self.CONFIG_LOCK.release() |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 259 | |
Thangavelu K S | ef6f0a5 | 2016-12-14 19:57:05 +0000 | [diff] [blame] | 260 | def execute(self, cmd, tty = True, stream = False, shell = False, detach = True): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 261 | res = 0 |
| 262 | if type(cmd) == str: |
| 263 | cmds = (cmd,) |
| 264 | else: |
| 265 | cmds = cmd |
| 266 | if shell: |
| 267 | for c in cmds: |
| 268 | res += os.system('docker exec {0} {1}'.format(self.name, c)) |
| 269 | return res |
| 270 | for c in cmds: |
| 271 | i = self.dckr.exec_create(container=self.name, cmd=c, tty = tty, privileged = True) |
A R Karthick | d6dd9b2 | 2017-02-24 15:17:22 -0800 | [diff] [blame] | 272 | s = self.dckr.exec_start(i['Id'], stream = stream, detach=detach, socket=True) |
| 273 | try: |
| 274 | s.close() |
| 275 | except: pass |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 276 | result = self.dckr.exec_inspect(i['Id']) |
| 277 | res += 0 if result['ExitCode'] == None else result['ExitCode'] |
| 278 | return res |
| 279 | |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 280 | def restart(self, timeout =10): |
| 281 | return self.dckr.restart(self.name, timeout) |
| 282 | |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 283 | def get_mem(jvm_heap_size = None, instances = 1): |
A R Karthick | 1f90820 | 2016-11-16 17:32:20 -0800 | [diff] [blame] | 284 | if instances <= 0: |
| 285 | instances = 1 |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 286 | heap_size = jvm_heap_size |
| 287 | heap_size_i = 0 |
| 288 | #sanitize the heap size config |
| 289 | if heap_size is not None: |
| 290 | if not heap_size.isdigit(): |
| 291 | try: |
| 292 | heap_size_i = int(heap_size[:-1]) |
| 293 | suffix = heap_size[-1] |
| 294 | if suffix == 'M': |
| 295 | heap_size_i /= 1024 #convert to gigs |
A.R Karthick | 9904482 | 2017-02-09 14:04:20 -0800 | [diff] [blame] | 296 | #allow to specific minimum heap size |
| 297 | if heap_size_i == 0: |
| 298 | return heap_size |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 299 | except: |
| 300 | ##invalid suffix length probably. Fall back to default |
| 301 | heap_size = None |
| 302 | else: |
| 303 | heap_size_i = int(heap_size) |
| 304 | |
Chetan Gaonker | 462d9fa | 2016-05-03 16:39:10 -0700 | [diff] [blame] | 305 | with open('/proc/meminfo', 'r') as fd: |
| 306 | meminfo = fd.readlines() |
| 307 | mem = 0 |
| 308 | for m in meminfo: |
| 309 | if m.startswith('MemTotal:') or m.startswith('SwapTotal:'): |
| 310 | mem += int(m.split(':')[1].strip().split()[0]) |
| 311 | |
A R Karthick | 1f90820 | 2016-11-16 17:32:20 -0800 | [diff] [blame] | 312 | mem = max(mem/1024/1024/2/instances, 1) |
Chetan Gaonker | 6d0a7b0 | 2016-05-03 16:57:28 -0700 | [diff] [blame] | 313 | mem = min(mem, 16) |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 314 | |
| 315 | if heap_size_i: |
| 316 | #we take the minimum of the provided heap size and max allowed heap size |
| 317 | heap_size_i = min(heap_size_i, mem) |
| 318 | else: |
| 319 | heap_size_i = mem |
| 320 | |
| 321 | return '{}G'.format(heap_size_i) |
Chetan Gaonker | 462d9fa | 2016-05-03 16:39:10 -0700 | [diff] [blame] | 322 | |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 323 | class OnosCord(Container): |
| 324 | """Use this when running the cord tester agent on the onos compute node""" |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 325 | onos_config_dir_guest = '/root/onos/config' |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 326 | synchronizer_map = { 'vtn' : { 'install': |
| 327 | ('http://mavenrepo:8080/repository/org/opencord/cord-config/1.2-SNAPSHOT/cord-config-1.2-SNAPSHOT.oar', |
| 328 | 'http://mavenrepo:8080/repository/org/opencord/vtn/1.2-SNAPSHOT/vtn-1.2-SNAPSHOT.oar',), |
| 329 | 'activate': |
| 330 | ('org.onosproject.ovsdb-base', 'org.onosproject.drivers.ovsdb', |
| 331 | 'org.onosproject.dhcp', 'org.onosproject.optical-model', |
| 332 | 'org.onosproject.openflow-base', 'org.onosproject.proxyarp', |
| 333 | 'org.onosproject.hostprovider'), |
| 334 | }, |
| 335 | 'fabric' : { 'activate': |
| 336 | ('org.onosproject.hostprovider', 'org.onosproject.optical-model', |
| 337 | 'org.onosproject.openflow-base', 'org.onosproject.vrouter', |
| 338 | 'org.onosproject.netcfghostprovider', 'org.onosproject.netcfglinksprovider', |
| 339 | 'org.onosproject.segmentrouting', 'org.onosproject.proxyarp'), |
| 340 | } |
| 341 | } |
| 342 | tester_apps = ('http://mavenrepo:8080/repository/org/opencord/aaa/1.2-SNAPSHOT/aaa-1.2-SNAPSHOT.oar', |
| 343 | 'http://mavenrepo:8080/repository/org/opencord/igmp/1.2-SNAPSHOT/igmp-1.2-SNAPSHOT.oar',) |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 344 | |
A.R Karthick | ddf1277 | 2017-05-17 13:49:47 -0700 | [diff] [blame] | 345 | old_service_profile = '/opt/cord/orchestration/service-profile/cord-pod' |
A R Karthick | 49529c5 | 2017-05-19 09:43:01 -0700 | [diff] [blame] | 346 | cord_profile = '/opt/cord_profile' |
A.R Karthick | ddf1277 | 2017-05-17 13:49:47 -0700 | [diff] [blame] | 347 | |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 348 | def __init__(self, onos_ip, conf, service_profile, synchronizer, start = True, boot_delay = 5): |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 349 | if not os.access(conf, os.F_OK): |
| 350 | raise Exception('ONOS cord configuration location %s is invalid' %conf) |
A.R Karthick | ddf1277 | 2017-05-17 13:49:47 -0700 | [diff] [blame] | 351 | self.old_cord = False |
| 352 | if os.access(self.old_service_profile, os.F_OK): |
| 353 | self.old_cord = True |
A R Karthick | bd9b8a3 | 2016-07-21 09:56:45 -0700 | [diff] [blame] | 354 | self.onos_ip = onos_ip |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 355 | self.onos_cord_dir = conf |
A R Karthick | bd9b8a3 | 2016-07-21 09:56:45 -0700 | [diff] [blame] | 356 | self.boot_delay = boot_delay |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 357 | self.synchronizer = synchronizer |
| 358 | self.service_profile = service_profile |
| 359 | self.docker_yaml = os.path.join(conf, 'docker-compose.yml') |
| 360 | self.docker_yaml_saved = os.path.join(conf, 'docker-compose.yml.saved') |
| 361 | self.onos_config_dir = os.path.join(conf, 'config') |
| 362 | self.onos_cfg_save_loc = os.path.join(conf, 'network-cfg.json.saved') |
| 363 | instance_active = False |
| 364 | #if we have a wrapper onos instance already active, back out |
| 365 | if os.access(self.onos_config_dir, os.F_OK) or os.access(self.docker_yaml_saved, os.F_OK): |
| 366 | instance_active = True |
| 367 | else: |
| 368 | if start is True: |
| 369 | os.mkdir(self.onos_config_dir) |
| 370 | shutil.copy(self.docker_yaml, self.docker_yaml_saved) |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 371 | |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 372 | self.start_wrapper = instance_active is False and start is True |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 373 | ##update the docker yaml with the config volume |
| 374 | with open(self.docker_yaml, 'r') as f: |
| 375 | yaml_config = yaml.load(f) |
| 376 | image = yaml_config['services'].keys()[0] |
A R Karthick | 8983cb0 | 2017-06-09 11:32:53 -0700 | [diff] [blame] | 377 | cord_conf_dir_basename = os.path.basename(self.onos_cord_dir.replace('-', '').replace('_', '')) |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 378 | xos_onos_name = '{}_{}_1'.format(cord_conf_dir_basename, image) |
A R Karthick | 5778a79 | 2017-01-31 13:47:16 -0800 | [diff] [blame] | 379 | if not yaml_config['services'][image].has_key('volumes'): |
| 380 | yaml_config['services'][image]['volumes'] = [] |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 381 | volumes = yaml_config['services'][image]['volumes'] |
| 382 | config_volumes = filter(lambda e: e.find(self.onos_config_dir_guest) >= 0, volumes) |
| 383 | if not config_volumes: |
| 384 | config_volume = '{}:{}'.format(self.onos_config_dir, self.onos_config_dir_guest) |
| 385 | volumes.append(config_volume) |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 386 | if self.start_wrapper: |
| 387 | docker_yaml_changed = '{}-changed'.format(self.docker_yaml) |
| 388 | with open(docker_yaml_changed, 'w') as wf: |
| 389 | yaml.dump(yaml_config, wf) |
| 390 | os.rename(docker_yaml_changed, self.docker_yaml) |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 391 | self.volumes = volumes |
| 392 | |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 393 | ##Create an container instance of xos onos |
A R Karthick | 5241473 | 2017-01-31 09:59:47 -0800 | [diff] [blame] | 394 | super(OnosCord, self).__init__(xos_onos_name, image, tag = '', quagga_config = Onos.QUAGGA_CONFIG) |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 395 | self.last_cfg = None |
| 396 | if self.start_wrapper: |
| 397 | #fetch the current config of onos cord instance and save it |
| 398 | try: |
| 399 | self.last_cfg = OnosCtrl.get_config(controller = onos_ip) |
| 400 | json_data = json.dumps(self.last_cfg, indent=4) |
| 401 | with open(self.onos_cfg_save_loc, 'w') as f: |
| 402 | f.write(json_data) |
| 403 | except: |
| 404 | pass |
| 405 | #start the container back with the shared onos config volume |
| 406 | self.start() |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 407 | |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 408 | def cliEnter(self): |
| 409 | retries = 0 |
| 410 | while retries < 30: |
| 411 | cli = OnosCliDriver(controller = self.onos_ip, connect = True) |
| 412 | if cli.handle: |
| 413 | return cli |
| 414 | else: |
| 415 | retries += 1 |
A R Karthick | 72fcbc5 | 2017-03-06 12:35:17 -0800 | [diff] [blame] | 416 | time.sleep(3) |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 417 | |
| 418 | return None |
| 419 | |
| 420 | def cliExit(self, cli): |
| 421 | if cli: |
| 422 | cli.disconnect() |
| 423 | |
A.R Karthick | ddf1277 | 2017-05-17 13:49:47 -0700 | [diff] [blame] | 424 | def synchronize_fabric(self, cfg = None): |
| 425 | if self.old_cord is True: |
| 426 | cmds = [ 'cd {} && make {}'.format(self.old_service_profile, self.synchronizer), |
| 427 | 'sleep 30' |
| 428 | ] |
| 429 | for cmd in cmds: |
| 430 | try: |
| 431 | os.system(cmd) |
| 432 | except: |
| 433 | pass |
| 434 | |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 435 | def synchronize_vtn(self, cfg = None): |
A.R Karthick | ddf1277 | 2017-05-17 13:49:47 -0700 | [diff] [blame] | 436 | if self.old_cord is True: |
| 437 | cmds = [ 'cd {} && make {}'.format(self.old_service_profile, self.synchronizer), |
| 438 | 'sleep 30' |
| 439 | ] |
| 440 | for cmd in cmds: |
| 441 | try: |
| 442 | os.system(cmd) |
| 443 | except: |
| 444 | pass |
| 445 | return |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 446 | if cfg is None: |
| 447 | return |
| 448 | if not cfg.has_key('apps'): |
| 449 | return |
| 450 | if not cfg['apps'].has_key('org.opencord.vtn'): |
| 451 | return |
| 452 | vtn_neutron_cfg = cfg['apps']['org.opencord.vtn']['cordvtn']['openstack'] |
| 453 | password = vtn_neutron_cfg['password'] |
| 454 | endpoint = vtn_neutron_cfg['endpoint'] |
| 455 | user = vtn_neutron_cfg['user'] |
| 456 | tenant = vtn_neutron_cfg['tenant'] |
| 457 | vtn_host = cfg['apps']['org.opencord.vtn']['cordvtn']['nodes'][0]['hostname'] |
| 458 | cli = self.cliEnter() |
| 459 | if cli is None: |
| 460 | return |
| 461 | cli.cordVtnSyncNeutronStates(endpoint, password, tenant = tenant, user = user) |
| 462 | time.sleep(2) |
| 463 | cli.cordVtnNodeInit(vtn_host) |
| 464 | self.cliExit(cli) |
| 465 | |
| 466 | def synchronize(self, cfg_unlink = False): |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 467 | |
| 468 | if not self.synchronizer_map.has_key(self.synchronizer): |
| 469 | return |
| 470 | |
| 471 | install_list = () |
| 472 | if self.synchronizer_map[self.synchronizer].has_key('install'): |
| 473 | install_list = self.synchronizer_map[self.synchronizer]['install'] |
| 474 | |
| 475 | activate_list = () |
| 476 | if self.synchronizer_map[self.synchronizer].has_key('activate'): |
| 477 | activate_list = self.synchronizer_map[self.synchronizer]['activate'] |
| 478 | |
| 479 | for app_url in install_list: |
| 480 | print('Installing app from url: %s' %app_url) |
| 481 | OnosCtrl.install_app_from_url(None, None, app_url = app_url, onos_ip = self.onos_ip) |
| 482 | |
| 483 | for app in activate_list: |
| 484 | print('Activating app %s' %app) |
| 485 | OnosCtrl(app, controller = self.onos_ip).activate() |
| 486 | time.sleep(2) |
| 487 | |
| 488 | for app_url in self.tester_apps: |
| 489 | print('Installing tester app from url: %s' %app_url) |
| 490 | OnosCtrl.install_app_from_url(None, None, app_url = app_url, onos_ip = self.onos_ip) |
| 491 | |
A R Karthick | 72fcbc5 | 2017-03-06 12:35:17 -0800 | [diff] [blame] | 492 | cfg = None |
| 493 | #restore the saved config after applications are activated |
| 494 | if os.access(self.onos_cfg_save_loc, os.F_OK): |
| 495 | with open(self.onos_cfg_save_loc, 'r') as f: |
| 496 | cfg = json.load(f) |
| 497 | try: |
| 498 | OnosCtrl.config(cfg, controller = self.onos_ip) |
| 499 | if cfg_unlink is True: |
| 500 | os.unlink(self.onos_cfg_save_loc) |
| 501 | except: |
| 502 | pass |
| 503 | |
| 504 | if hasattr(self, 'synchronize_{}'.format(self.synchronizer)): |
| 505 | getattr(self, 'synchronize_{}'.format(self.synchronizer))(cfg = cfg) |
| 506 | |
| 507 | #now restart the xos synchronizer container |
A R Karthick | 49529c5 | 2017-05-19 09:43:01 -0700 | [diff] [blame] | 508 | cmd = None |
| 509 | if os.access('{}/onboarding-docker-compose/docker-compose.yml'.format(self.cord_profile), os.F_OK): |
| 510 | cmd = 'cd {}/onboarding-docker-compose && \ |
| 511 | docker-compose -p {} restart xos_synchronizer_{}'.format(self.cord_profile, |
| 512 | self.service_profile, |
| 513 | self.synchronizer) |
| 514 | else: |
| 515 | if os.access('{}/docker-compose.yml'.format(self.cord_profile), os.F_OK): |
| 516 | cmd = 'cd {} && \ |
| 517 | docker-compose -p {} restart {}-synchronizer'.format(self.cord_profile, |
| 518 | self.service_profile, |
| 519 | self.synchronizer) |
| 520 | if cmd is not None: |
| 521 | try: |
| 522 | print(cmd) |
| 523 | os.system(cmd) |
| 524 | except: |
| 525 | pass |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 526 | |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 527 | def start(self, restart = False, network_cfg = None): |
A R Karthick | 928ad62 | 2017-01-30 12:18:32 -0800 | [diff] [blame] | 528 | if network_cfg is not None: |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 529 | json_data = json.dumps(network_cfg, indent=4) |
| 530 | with open('{}/network-cfg.json'.format(self.onos_config_dir), 'w') as f: |
| 531 | f.write(json_data) |
A R Karthick | 5241473 | 2017-01-31 09:59:47 -0800 | [diff] [blame] | 532 | |
| 533 | #we avoid using docker-compose restart for now. |
| 534 | #since we don't want to retain the metadata across restarts |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 535 | #stop and start and synchronize the services before installing tester cord apps |
| 536 | cmds = [ 'cd {} && docker-compose down'.format(self.onos_cord_dir), |
| 537 | 'cd {} && docker-compose up -d'.format(self.onos_cord_dir), |
A R Karthick | bc89437 | 2017-05-12 16:34:08 -0700 | [diff] [blame] | 538 | 'sleep 150', |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 539 | ] |
| 540 | for cmd in cmds: |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 541 | try: |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 542 | print(cmd) |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 543 | os.system(cmd) |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 544 | except:pass |
A R Karthick | 5241473 | 2017-01-31 09:59:47 -0800 | [diff] [blame] | 545 | |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 546 | self.synchronize() |
A R Karthick | 5241473 | 2017-01-31 09:59:47 -0800 | [diff] [blame] | 547 | ##we could also connect container to default docker network but disabled for now |
| 548 | #Container.connect_to_network(self.name, 'bridge') |
A R Karthick | 5241473 | 2017-01-31 09:59:47 -0800 | [diff] [blame] | 549 | #connect container to the quagga bridge |
| 550 | self.connect_to_br(index = 0) |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 551 | print('Waiting %d seconds for ONOS instance to start' %self.boot_delay) |
A R Karthick | bd9b8a3 | 2016-07-21 09:56:45 -0700 | [diff] [blame] | 552 | time.sleep(self.boot_delay) |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 553 | |
| 554 | def build_image(self): |
| 555 | build_cmd = 'cd {} && docker-compose build'.format(self.onos_cord_dir) |
| 556 | os.system(build_cmd) |
| 557 | |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 558 | def restore(self, force = False): |
| 559 | restore = self.start_wrapper is True or force is True |
| 560 | if not restore: |
A.R Karthick | 263d3fc | 2017-01-27 12:52:53 -0800 | [diff] [blame] | 561 | return |
A R Karthick | 394976f | 2017-01-31 14:25:16 -0800 | [diff] [blame] | 562 | #nothing to restore |
| 563 | if not os.access(self.docker_yaml_saved, os.F_OK): |
| 564 | return |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 565 | |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 566 | #restore the config files back. The synchronizer restore should bring the last config back |
| 567 | cmds = ['cd {} && docker-compose down'.format(self.onos_cord_dir), |
| 568 | 'rm -rf {}'.format(self.onos_config_dir), |
| 569 | 'mv {} {}'.format(self.docker_yaml_saved, self.docker_yaml), |
| 570 | 'cd {} && docker-compose up -d'.format(self.onos_cord_dir), |
A R Karthick | bc89437 | 2017-05-12 16:34:08 -0700 | [diff] [blame] | 571 | 'sleep 150', |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 572 | ] |
| 573 | for cmd in cmds: |
A.R Karthick | b17e202 | 2017-01-27 11:29:26 -0800 | [diff] [blame] | 574 | try: |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 575 | print(cmd) |
| 576 | os.system(cmd) |
A.R Karthick | b17e202 | 2017-01-27 11:29:26 -0800 | [diff] [blame] | 577 | except: pass |
| 578 | |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 579 | self.synchronize(cfg_unlink = True) |
A.R Karthick | b17e202 | 2017-01-27 11:29:26 -0800 | [diff] [blame] | 580 | |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 581 | class OnosCordStopWrapper(Container): |
| 582 | onos_cord_dir = os.path.join(os.getenv('HOME'), 'cord-tester-cord') |
| 583 | docker_yaml = os.path.join(onos_cord_dir, 'docker-compose.yml') |
| 584 | |
| 585 | def __init__(self): |
| 586 | if os.access(self.docker_yaml, os.F_OK): |
| 587 | with open(self.docker_yaml, 'r') as f: |
| 588 | yaml_config = yaml.load(f) |
| 589 | image = yaml_config['services'].keys()[0] |
| 590 | name = 'cordtestercord_{}_1'.format(image) |
| 591 | super(OnosCordStopWrapper, self).__init__(name, image, tag = '') |
| 592 | if self.exists(): |
| 593 | print('Killing container %s' %self.name) |
| 594 | self.kill() |
| 595 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 596 | class Onos(Container): |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 597 | QUAGGA_CONFIG = [ { 'bridge' : 'quagga-br', 'ip': '10.10.0.4', 'mask' : 16 }, ] |
A R Karthick | a2492c1 | 2016-12-16 10:31:51 -0800 | [diff] [blame] | 598 | MAX_INSTANCES = 3 |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 599 | JVM_HEAP_SIZE = None |
Chetan Gaonker | 462d9fa | 2016-05-03 16:39:10 -0700 | [diff] [blame] | 600 | SYSTEM_MEMORY = (get_mem(),) * 2 |
A R Karthick | a2492c1 | 2016-12-16 10:31:51 -0800 | [diff] [blame] | 601 | INSTANCE_MEMORY = (get_mem(instances=MAX_INSTANCES),) * 2 |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 602 | JAVA_OPTS_FORMAT = '-Xms{} -Xmx{} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode' |
| 603 | JAVA_OPTS_DEFAULT = JAVA_OPTS_FORMAT.format(*SYSTEM_MEMORY) #-XX:+PrintGCDetails -XX:+PrintGCTimeStamps' |
| 604 | JAVA_OPTS_CLUSTER_DEFAULT = JAVA_OPTS_FORMAT.format(*INSTANCE_MEMORY) |
| 605 | env = { 'ONOS_APPS' : 'drivers,openflow,proxyarp,vrouter', 'JAVA_OPTS' : JAVA_OPTS_DEFAULT } |
A R Karthick | 6e70e14 | 2017-07-28 15:25:38 -0700 | [diff] [blame] | 606 | onos_cord_apps = ( ['cord-config', '1.2-SNAPSHOT', 'org.opencord.config'], |
| 607 | ['aaa', '1.2-SNAPSHOT', 'org.opencord.aaa'], |
| 608 | ['igmp', '1.2-SNAPSHOT', 'org.opencord.igmp'], |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 609 | ) |
A R Karthick | b608d40 | 2017-06-02 11:48:41 -0700 | [diff] [blame] | 610 | cord_apps_version_updated = False |
A R Karthick | 184945a | 2017-07-25 17:23:57 -0700 | [diff] [blame] | 611 | expose_port = False |
| 612 | expose_ports = [ 8181, 8101, 9876, 6653, 6633, 2000, 2620, 5005 ] |
| 613 | ports = [] |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 614 | setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup') |
| 615 | host_config_dir = os.path.join(setup_dir, 'onos-config') |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 616 | guest_config_dir = '/root/onos/config' |
A.R Karthick | dda2206 | 2017-02-09 14:39:20 -0800 | [diff] [blame] | 617 | guest_data_dir = '/root/onos/apache-karaf-3.0.8/data' |
| 618 | guest_log_file = '/root/onos/apache-karaf-3.0.8/data/log/karaf.log' |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 619 | onos_gen_partitions = os.path.join(setup_dir, 'onos-gen-partitions') |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 620 | onos_form_cluster = os.path.join(setup_dir, 'onos-form-cluster') |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 621 | cord_apps_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'apps') |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 622 | host_guest_map = ( (host_config_dir, guest_config_dir), ) |
A R Karthick | d52ca8a | 2017-07-24 17:38:55 -0700 | [diff] [blame] | 623 | ssl_key = None |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 624 | cluster_cfg = os.path.join(host_config_dir, 'cluster.json') |
| 625 | cluster_mode = False |
| 626 | cluster_instances = [] |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 627 | NAME = 'cord-onos' |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 628 | ##the ip of ONOS in default cluster.json in setup/onos-config |
| 629 | CLUSTER_CFG_IP = '172.17.0.2' |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 630 | IMAGE = 'onosproject/onos' |
| 631 | TAG = 'latest' |
| 632 | PREFIX = '' |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 633 | |
| 634 | @classmethod |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 635 | def generate_cluster_cfg(cls, ip): |
| 636 | if type(ip) in [ list, tuple ]: |
| 637 | ips = ' '.join(ip) |
| 638 | else: |
| 639 | ips = ip |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 640 | try: |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 641 | cmd = '{} {} {}'.format(cls.onos_gen_partitions, cls.cluster_cfg, ips) |
| 642 | os.system(cmd) |
| 643 | except: pass |
| 644 | |
| 645 | @classmethod |
| 646 | def form_cluster(cls, ips): |
| 647 | nodes = ' '.join(ips) |
| 648 | try: |
| 649 | cmd = '{} {}'.format(cls.onos_form_cluster, nodes) |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 650 | os.system(cmd) |
| 651 | except: pass |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 652 | |
A R Karthick | 9d48c65 | 2016-09-15 09:16:36 -0700 | [diff] [blame] | 653 | @classmethod |
| 654 | def cleanup_runtime(cls): |
| 655 | '''Cleanup ONOS runtime generated files''' |
| 656 | files = ( Onos.cluster_cfg, os.path.join(Onos.host_config_dir, 'network-cfg.json') ) |
| 657 | for f in files: |
| 658 | if os.access(f, os.F_OK): |
| 659 | try: |
| 660 | os.unlink(f) |
| 661 | except: pass |
| 662 | |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 663 | @classmethod |
| 664 | def get_data_map(cls, host_volume, guest_volume_dir): |
| 665 | host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume)) |
| 666 | if not os.path.exists(host_volume_dir): |
| 667 | os.mkdir(host_volume_dir) |
| 668 | return ( (host_volume_dir, guest_volume_dir), ) |
| 669 | |
| 670 | @classmethod |
| 671 | def remove_data_map(cls, host_volume, guest_volume_dir): |
| 672 | host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume)) |
| 673 | if os.path.exists(host_volume_dir): |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 674 | shutil.rmtree(host_volume_dir) |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 675 | |
A R Karthick | 973010f | 2017-02-06 16:41:51 -0800 | [diff] [blame] | 676 | @classmethod |
| 677 | def update_data_dir(cls, karaf): |
| 678 | Onos.guest_data_dir = '/root/onos/apache-karaf-{}/data'.format(karaf) |
| 679 | Onos.guest_log_file = '/root/onos/apache-karaf-{}/data/log/karaf.log'.format(karaf) |
| 680 | |
A R Karthick | d52ca8a | 2017-07-24 17:38:55 -0700 | [diff] [blame] | 681 | @classmethod |
| 682 | def update_ssl_key(cls, key): |
| 683 | if os.access(key, os.F_OK): |
| 684 | try: |
| 685 | shutil.copy(key, cls.host_config_dir) |
| 686 | cls.ssl_key = os.path.join(cls.host_config_dir, os.path.basename(key)) |
| 687 | except:pass |
| 688 | |
A R Karthick | 184945a | 2017-07-25 17:23:57 -0700 | [diff] [blame] | 689 | @classmethod |
| 690 | def set_expose_port(cls, flag): |
| 691 | cls.expose_port = flag |
| 692 | |
| 693 | def get_port_map(self, instance=0): |
| 694 | if self.expose_port is False: |
| 695 | return self.ports |
| 696 | return map(lambda p: (p, p + instance), self.expose_ports) |
| 697 | |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 698 | def remove_data_volume(self): |
| 699 | if self.data_map is not None: |
| 700 | self.remove_data_map(*self.data_map) |
| 701 | |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 702 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG, |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 703 | boot_delay = 20, restart = False, network_cfg = None, |
A R Karthick | 85eb186 | 2017-01-23 16:10:57 -0800 | [diff] [blame] | 704 | cluster = False, data_volume = None, async = False, quagga_config = None, |
A R Karthick | 184945a | 2017-07-25 17:23:57 -0700 | [diff] [blame] | 705 | network = None, instance = 0): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 706 | if restart is True: |
| 707 | ##Find the right image to restart |
| 708 | running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers()) |
| 709 | if running_image: |
| 710 | image_name = running_image[0]['Image'] |
| 711 | try: |
| 712 | image = image_name.split(':')[0] |
| 713 | tag = image_name.split(':')[1] |
| 714 | except: pass |
| 715 | |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 716 | if quagga_config is None: |
| 717 | quagga_config = Onos.QUAGGA_CONFIG |
| 718 | super(Onos, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = quagga_config) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 719 | self.boot_delay = boot_delay |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 720 | self.data_map = None |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 721 | instance_memory = (get_mem(jvm_heap_size = Onos.JVM_HEAP_SIZE, instances = Onos.MAX_INSTANCES),) * 2 |
| 722 | self.env['JAVA_OPTS'] = self.JAVA_OPTS_FORMAT.format(*instance_memory) |
A R Karthick | 184945a | 2017-07-25 17:23:57 -0700 | [diff] [blame] | 723 | self.ports = self.get_port_map(instance = instance) |
A R Karthick | d52ca8a | 2017-07-24 17:38:55 -0700 | [diff] [blame] | 724 | if self.ssl_key: |
| 725 | key_files = ( os.path.join(self.guest_config_dir, os.path.basename(self.ssl_key)), ) * 2 |
| 726 | self.env['JAVA_OPTS'] += ' -DenableOFTLS=true -Djavax.net.ssl.keyStore={} -Djavax.net.ssl.keyStorePassword=222222 -Djavax.net.ssl.trustStore={} -Djavax.net.ssl.trustStorePassword=222222'.format(*key_files) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 727 | if cluster is True: |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 728 | if data_volume is not None: |
| 729 | self.data_map = self.get_data_map(data_volume, self.guest_data_dir) |
| 730 | self.host_guest_map = self.host_guest_map + self.data_map |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 731 | if os.access(self.cluster_cfg, os.F_OK): |
| 732 | try: |
| 733 | os.unlink(self.cluster_cfg) |
| 734 | except: pass |
| 735 | |
| 736 | self.host_config = self.create_host_config(port_list = self.ports, |
| 737 | host_guest_map = self.host_guest_map) |
| 738 | self.volumes = [] |
| 739 | for _,g in self.host_guest_map: |
| 740 | self.volumes.append(g) |
| 741 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 742 | if restart is True and self.exists(): |
| 743 | self.kill() |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 744 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 745 | if not self.exists(): |
| 746 | self.remove_container(name, force=True) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 747 | host_config = self.create_host_config(port_list = self.ports, |
| 748 | host_guest_map = self.host_guest_map) |
| 749 | volumes = [] |
| 750 | for _,g in self.host_guest_map: |
| 751 | volumes.append(g) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 752 | if network_cfg is not None: |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 753 | json_data = json.dumps(network_cfg, indent=4) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 754 | with open('{}/network-cfg.json'.format(self.host_config_dir), 'w') as f: |
| 755 | f.write(json_data) |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 756 | if cluster is False or async is False: |
| 757 | print('Starting ONOS container %s' %self.name) |
| 758 | self.start(ports = self.ports, environment = self.env, |
| 759 | host_config = self.host_config, volumes = self.volumes, tty = True) |
| 760 | if not restart: |
| 761 | ##wait a bit before fetching IP to regenerate cluster cfg |
| 762 | time.sleep(5) |
| 763 | ip = self.ip() |
| 764 | ##Just a quick hack/check to ensure we don't regenerate in the common case. |
| 765 | ##As ONOS is usually the first test container that is started |
| 766 | if cluster is False: |
| 767 | if ip != self.CLUSTER_CFG_IP or not os.access(self.cluster_cfg, os.F_OK): |
| 768 | print('Regenerating ONOS cluster cfg for ip %s' %ip) |
| 769 | self.generate_cluster_cfg(ip) |
| 770 | self.kill() |
| 771 | self.remove_container(self.name, force=True) |
| 772 | print('Restarting ONOS container %s' %self.name) |
| 773 | self.start(ports = self.ports, environment = self.env, |
| 774 | host_config = self.host_config, volumes = self.volumes, tty = True) |
| 775 | print('Waiting for ONOS to boot') |
| 776 | time.sleep(boot_delay) |
| 777 | self.wait_for_onos_start(self.ip()) |
| 778 | self.running = True |
| 779 | else: |
| 780 | self.running = False |
| 781 | else: |
| 782 | self.running = True |
| 783 | if self.running: |
| 784 | self.ipaddr = self.ip() |
| 785 | if cluster is False: |
| 786 | self.install_cord_apps(self.ipaddr) |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 787 | |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 788 | @classmethod |
| 789 | def get_quagga_config(cls, instance = 0): |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 790 | quagga_config = copy.deepcopy(cls.QUAGGA_CONFIG) |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 791 | if instance == 0: |
| 792 | return quagga_config |
| 793 | ip = quagga_config[0]['ip'] |
| 794 | octets = ip.split('.') |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 795 | octets[3] = str((int(octets[3]) + instance) & 255) |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 796 | ip = '.'.join(octets) |
| 797 | quagga_config[0]['ip'] = ip |
| 798 | return quagga_config |
| 799 | |
| 800 | @classmethod |
| 801 | def start_cluster_async(cls, onos_instances): |
| 802 | instances = filter(lambda o: o.running == False, onos_instances) |
| 803 | if not instances: |
| 804 | return |
| 805 | tpool = ThreadPool(len(instances), queue_size = 1, wait_timeout = 1) |
| 806 | for onos in instances: |
| 807 | tpool.addTask(onos.start_async) |
| 808 | tpool.cleanUpThreads() |
| 809 | |
| 810 | def start_async(self): |
| 811 | print('Starting ONOS container %s' %self.name) |
| 812 | self.start(ports = self.ports, environment = self.env, |
| 813 | host_config = self.host_config, volumes = self.volumes, tty = True) |
| 814 | time.sleep(3) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 815 | self.ipaddr = self.ip() |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 816 | print('Waiting for ONOS container %s to start' %self.name) |
| 817 | self.wait_for_onos_start(self.ipaddr) |
| 818 | self.running = True |
| 819 | print('ONOS container %s started' %self.name) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 820 | |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 821 | @classmethod |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 822 | def wait_for_onos_start(cls, ip, tries = 30): |
A R Karthick | 973010f | 2017-02-06 16:41:51 -0800 | [diff] [blame] | 823 | onos_log = OnosLog(host = ip, log_file = Onos.guest_log_file) |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 824 | num_tries = 0 |
| 825 | started = None |
| 826 | while not started and num_tries < tries: |
| 827 | time.sleep(3) |
| 828 | started = onos_log.search_log_pattern('ApplicationManager .* Started') |
| 829 | num_tries += 1 |
| 830 | |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 831 | if not started: |
| 832 | print('ONOS did not start') |
| 833 | else: |
| 834 | print('ONOS started') |
| 835 | return started |
| 836 | |
| 837 | @classmethod |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 838 | def setup_cluster_deprecated(cls, onos_instances, image_name = None): |
| 839 | if not onos_instances or len(onos_instances) < 2: |
| 840 | return |
| 841 | ips = [] |
| 842 | if image_name is not None: |
| 843 | ips = Container.ips(image_name) |
| 844 | else: |
| 845 | for onos in onos_instances: |
| 846 | ips.append(onos.ipaddr) |
| 847 | Onos.cluster_instances = onos_instances |
| 848 | Onos.cluster_mode = True |
| 849 | ##regenerate the cluster json with the 3 instance ips before restarting them back |
| 850 | print('Generating cluster cfg for ONOS instances with ips %s' %ips) |
| 851 | Onos.generate_cluster_cfg(ips) |
| 852 | for onos in onos_instances: |
| 853 | onos.kill() |
| 854 | onos.remove_container(onos.name, force=True) |
| 855 | print('Restarting ONOS container %s for forming cluster' %onos.name) |
| 856 | onos.start(ports = onos.ports, environment = onos.env, |
| 857 | host_config = onos.host_config, volumes = onos.volumes, tty = True) |
| 858 | print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name)) |
| 859 | time.sleep(onos.boot_delay) |
| 860 | onos.ipaddr = onos.ip() |
| 861 | onos.install_cord_apps(onos.ipaddr) |
| 862 | |
| 863 | @classmethod |
| 864 | def setup_cluster(cls, onos_instances, image_name = None): |
| 865 | if not onos_instances or len(onos_instances) < 2: |
| 866 | return |
| 867 | ips = [] |
| 868 | if image_name is not None: |
| 869 | ips = Container.ips(image_name) |
| 870 | else: |
| 871 | for onos in onos_instances: |
| 872 | ips.append(onos.ipaddr) |
| 873 | Onos.cluster_instances = onos_instances |
| 874 | Onos.cluster_mode = True |
| 875 | ##regenerate the cluster json with the 3 instance ips before restarting them back |
| 876 | print('Forming cluster for ONOS instances with ips %s' %ips) |
| 877 | Onos.form_cluster(ips) |
| 878 | ##wait for the cluster to be formed |
| 879 | print('Waiting for the cluster to be formed') |
| 880 | time.sleep(60) |
| 881 | for onos in onos_instances: |
| 882 | onos.install_cord_apps(onos.ipaddr) |
| 883 | |
| 884 | @classmethod |
A R Karthick | e2c24bd | 2016-10-07 14:51:38 -0700 | [diff] [blame] | 885 | def add_cluster(cls, count = 1, network_cfg = None): |
| 886 | if not cls.cluster_instances or Onos.cluster_mode is False: |
| 887 | return |
| 888 | for i in range(count): |
A R Karthick | 184945a | 2017-07-25 17:23:57 -0700 | [diff] [blame] | 889 | instance = len(cls.cluster_instances) |
| 890 | name = '{}-{}'.format(Onos.NAME, instance+1) |
A R Karthick | e2c24bd | 2016-10-07 14:51:38 -0700 | [diff] [blame] | 891 | onos = cls(name = name, image = Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX, |
A R Karthick | 184945a | 2017-07-25 17:23:57 -0700 | [diff] [blame] | 892 | cluster = True, network_cfg = network_cfg, instance = instance) |
A R Karthick | e2c24bd | 2016-10-07 14:51:38 -0700 | [diff] [blame] | 893 | cls.cluster_instances.append(onos) |
| 894 | |
| 895 | cls.setup_cluster(cls.cluster_instances) |
| 896 | |
| 897 | @classmethod |
A.R Karthick | 2560f04 | 2016-11-30 14:38:52 -0800 | [diff] [blame] | 898 | def restart_cluster(cls, network_cfg = None, timeout = 10, setup = False): |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 899 | if cls.cluster_mode is False: |
| 900 | return |
| 901 | if not cls.cluster_instances: |
| 902 | return |
| 903 | |
| 904 | if network_cfg is not None: |
| 905 | json_data = json.dumps(network_cfg, indent=4) |
| 906 | with open('{}/network-cfg.json'.format(cls.host_config_dir), 'w') as f: |
| 907 | f.write(json_data) |
| 908 | |
A.R Karthick | 2560f04 | 2016-11-30 14:38:52 -0800 | [diff] [blame] | 909 | cls.cleanup_cluster() |
| 910 | if timeout > 0: |
| 911 | time.sleep(timeout) |
| 912 | |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 913 | #start the instances asynchronously |
| 914 | cls.start_cluster_async(cls.cluster_instances) |
| 915 | time.sleep(5) |
A.R Karthick | 2560f04 | 2016-11-30 14:38:52 -0800 | [diff] [blame] | 916 | ##form the cluster as appropriate |
| 917 | if setup is True: |
| 918 | cls.setup_cluster(cls.cluster_instances) |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 919 | else: |
| 920 | for onos in cls.cluster_instances: |
| 921 | onos.install_cord_apps(onos.ipaddr) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 922 | |
| 923 | @classmethod |
| 924 | def cluster_ips(cls): |
| 925 | if cls.cluster_mode is False: |
| 926 | return [] |
| 927 | if not cls.cluster_instances: |
| 928 | return [] |
| 929 | ips = [ onos.ipaddr for onos in cls.cluster_instances ] |
| 930 | return ips |
| 931 | |
| 932 | @classmethod |
| 933 | def cleanup_cluster(cls): |
| 934 | if cls.cluster_mode is False: |
| 935 | return |
| 936 | if not cls.cluster_instances: |
| 937 | return |
| 938 | for onos in cls.cluster_instances: |
| 939 | if onos.exists(): |
| 940 | onos.kill() |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 941 | onos.running = False |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 942 | onos.remove_container(onos.name, force=True) |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 943 | |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 944 | @classmethod |
A R Karthick | de6b9dc | 2016-11-29 17:46:16 -0800 | [diff] [blame] | 945 | def restart_node(cls, node = None, network_cfg = None, timeout = 10): |
A R Karthick | 889d965 | 2016-10-03 14:13:45 -0700 | [diff] [blame] | 946 | if node is None: |
| 947 | cls(restart = True, network_cfg = network_cfg, image = cls.IMAGE, tag = cls.TAG) |
| 948 | else: |
| 949 | #Restarts a node in the cluster |
| 950 | valid_node = filter(lambda onos: node in [ onos.ipaddr, onos.name ], cls.cluster_instances) |
| 951 | if valid_node: |
| 952 | onos = valid_node.pop() |
| 953 | if onos.exists(): |
| 954 | onos.kill() |
| 955 | onos.remove_container(onos.name, force=True) |
A R Karthick | de6b9dc | 2016-11-29 17:46:16 -0800 | [diff] [blame] | 956 | if timeout > 0: |
| 957 | time.sleep(timeout) |
A R Karthick | 889d965 | 2016-10-03 14:13:45 -0700 | [diff] [blame] | 958 | print('Restarting ONOS container %s' %onos.name) |
| 959 | onos.start(ports = onos.ports, environment = onos.env, |
| 960 | host_config = onos.host_config, volumes = onos.volumes, tty = True) |
A R Karthick | 889d965 | 2016-10-03 14:13:45 -0700 | [diff] [blame] | 961 | onos.ipaddr = onos.ip() |
A.R Karthick | 2560f04 | 2016-11-30 14:38:52 -0800 | [diff] [blame] | 962 | onos.wait_for_onos_start(onos.ipaddr) |
| 963 | onos.install_cord_apps(onos.ipaddr) |
A R Karthick | 889d965 | 2016-10-03 14:13:45 -0700 | [diff] [blame] | 964 | |
| 965 | @classmethod |
A R Karthick | b608d40 | 2017-06-02 11:48:41 -0700 | [diff] [blame] | 966 | def cliEnter(cls, onos_ip = None): |
| 967 | retries = 0 |
| 968 | while retries < 10: |
| 969 | cli = OnosCliDriver(controller = onos_ip, connect = True) |
| 970 | if cli.handle: |
| 971 | return cli |
| 972 | else: |
| 973 | retries += 1 |
| 974 | time.sleep(3) |
| 975 | |
| 976 | return None |
| 977 | |
| 978 | @classmethod |
| 979 | def cliExit(cls, cli): |
| 980 | if cli: |
| 981 | cli.disconnect() |
| 982 | |
| 983 | @classmethod |
| 984 | def getVersion(cls, onos_ip = None): |
| 985 | cli = cls.cliEnter(onos_ip = onos_ip) |
| 986 | try: |
| 987 | summary = json.loads(cli.summary(jsonFormat = True)) |
| 988 | except: |
| 989 | cls.cliExit(cli) |
| 990 | return '1.8.0' |
| 991 | cls.cliExit(cli) |
| 992 | return summary['version'] |
| 993 | |
| 994 | @classmethod |
| 995 | def update_cord_apps_version(cls, onos_ip = None): |
| 996 | if cls.cord_apps_version_updated == True: |
| 997 | return |
| 998 | version = cls.getVersion(onos_ip = onos_ip) |
| 999 | major = int(version.split('.')[0]) |
| 1000 | minor = int(version.split('.')[1]) |
A R Karthick | 5b8310e | 2017-09-01 13:55:15 -0700 | [diff] [blame] | 1001 | try: |
| 1002 | patch = int(version.split('.')[2]) |
| 1003 | except: |
| 1004 | patch = 0 |
A R Karthick | b608d40 | 2017-06-02 11:48:41 -0700 | [diff] [blame] | 1005 | app_version = '1.2-SNAPSHOT' |
| 1006 | if major > 1: |
| 1007 | app_version = '2.0-SNAPSHOT' |
A R Karthick | 5b8310e | 2017-09-01 13:55:15 -0700 | [diff] [blame] | 1008 | elif major == 1 and minor >= 10: |
A R Karthick | b608d40 | 2017-06-02 11:48:41 -0700 | [diff] [blame] | 1009 | app_version = '2.0-SNAPSHOT' |
A R Karthick | 5b8310e | 2017-09-01 13:55:15 -0700 | [diff] [blame] | 1010 | if patch < 3: |
| 1011 | app_version = '1.2-SNAPSHOT' |
A R Karthick | b608d40 | 2017-06-02 11:48:41 -0700 | [diff] [blame] | 1012 | for apps in cls.onos_cord_apps: |
| 1013 | apps[1] = app_version |
| 1014 | cls.cord_apps_version_updated = True |
| 1015 | |
| 1016 | @classmethod |
A R Karthick | eaf1c4e | 2016-07-19 12:22:35 -0700 | [diff] [blame] | 1017 | def install_cord_apps(cls, onos_ip = None): |
A R Karthick | b608d40 | 2017-06-02 11:48:41 -0700 | [diff] [blame] | 1018 | cls.update_cord_apps_version(onos_ip = onos_ip) |
A R Karthick | 6e70e14 | 2017-07-28 15:25:38 -0700 | [diff] [blame] | 1019 | for app, version,_ in cls.onos_cord_apps: |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 1020 | app_file = '{}/{}-{}.oar'.format(cls.cord_apps_dir, app, version) |
A R Karthick | eaf1c4e | 2016-07-19 12:22:35 -0700 | [diff] [blame] | 1021 | ok, code = OnosCtrl.install_app(app_file, onos_ip = onos_ip) |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 1022 | ##app already installed (conflicts) |
| 1023 | if code in [ 409 ]: |
| 1024 | ok = True |
| 1025 | print('ONOS app %s, version %s %s' %(app, version, 'installed' if ok else 'failed to install')) |
| 1026 | time.sleep(2) |
| 1027 | |
A R Karthick | 6e70e14 | 2017-07-28 15:25:38 -0700 | [diff] [blame] | 1028 | @classmethod |
| 1029 | def activate_apps(cls, apps, onos_ip = None, deactivate = False): |
| 1030 | for app in apps: |
| 1031 | if deactivate is True: |
| 1032 | OnosCtrl(app, controller = onos_ip).deactivate() |
| 1033 | time.sleep(2) |
| 1034 | OnosCtrl(app, controller = onos_ip).activate() |
| 1035 | |
| 1036 | time.sleep(5) |
| 1037 | |
| 1038 | @classmethod |
| 1039 | def activate_cord_apps(cls, onos_ip = None, deactivate = True): |
| 1040 | cord_apps = map(lambda a: a[2], cls.onos_cord_apps) |
| 1041 | cls.activate_apps(cord_apps, onos_ip = onos_ip, deactivate = deactivate) |
| 1042 | |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 1043 | class OnosStopWrapper(Container): |
| 1044 | def __init__(self, name): |
| 1045 | super(OnosStopWrapper, self).__init__(name, Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX) |
| 1046 | if self.exists(): |
| 1047 | self.kill() |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 1048 | self.running = False |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 1049 | else: |
| 1050 | if Onos.cluster_mode is True: |
| 1051 | valid_node = filter(lambda onos: name in [ onos.ipaddr, onos.name ], Onos.cluster_instances) |
| 1052 | if valid_node: |
| 1053 | onos = valid_node.pop() |
| 1054 | if onos.exists(): |
| 1055 | onos.kill() |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 1056 | onos.running = False |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 1057 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 1058 | class Radius(Container): |
| 1059 | ports = [ 1812, 1813 ] |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 1060 | env = {'TIMEZONE':'America/Los_Angeles', |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 1061 | 'DEBUG': 'true', 'cert_password':'whatever', 'primary_shared_secret':'radius_password' |
| 1062 | } |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 1063 | host_db_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/db') |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 1064 | guest_db_dir = os.path.join(os.path.sep, 'opt', 'db') |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 1065 | host_config_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/freeradius') |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 1066 | guest_config_dir = os.path.join(os.path.sep, 'etc', 'freeradius') |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 1067 | start_command = os.path.join(guest_config_dir, 'start-radius.py') |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 1068 | host_guest_map = ( (host_db_dir, guest_db_dir), |
| 1069 | (host_config_dir, guest_config_dir) |
| 1070 | ) |
A R Karthick | f7a613b | 2017-02-24 09:36:44 -0800 | [diff] [blame] | 1071 | IMAGE = 'cordtest/radius' |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 1072 | NAME = 'cord-radius' |
| 1073 | |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 1074 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate', |
A R Karthick | 85eb186 | 2017-01-23 16:10:57 -0800 | [diff] [blame] | 1075 | boot_delay = 10, restart = False, update = False, network = None): |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 1076 | super(Radius, self).__init__(name, image, prefix = prefix, tag = tag, command = self.start_command) |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 1077 | if update is True or not self.img_exists(): |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 1078 | self.build_image(self.image_name) |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 1079 | if restart is True and self.exists(): |
| 1080 | self.kill() |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 1081 | if not self.exists(): |
| 1082 | self.remove_container(name, force=True) |
| 1083 | host_config = self.create_host_config(port_list = self.ports, |
| 1084 | host_guest_map = self.host_guest_map) |
| 1085 | volumes = [] |
| 1086 | for _,g in self.host_guest_map: |
| 1087 | volumes.append(g) |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 1088 | self.start(ports = self.ports, environment = self.env, |
| 1089 | volumes = volumes, |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 1090 | host_config = host_config, tty = True) |
A R Karthick | 85eb186 | 2017-01-23 16:10:57 -0800 | [diff] [blame] | 1091 | if network is not None: |
| 1092 | Container.connect_to_network(self.name, network) |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 1093 | time.sleep(boot_delay) |
| 1094 | |
| 1095 | @classmethod |
| 1096 | def build_image(cls, image): |
| 1097 | print('Building Radius image %s' %image) |
| 1098 | dockerfile = ''' |
| 1099 | FROM hbouvier/docker-radius |
| 1100 | MAINTAINER chetan@ciena.com |
| 1101 | LABEL RUN docker pull hbouvier/docker-radius |
| 1102 | LABEL RUN docker run -it --name cord-radius hbouvier/docker-radius |
A R Karthick | c762df4 | 2016-05-25 10:09:21 -0700 | [diff] [blame] | 1103 | RUN apt-get update && \ |
| 1104 | apt-get -y install python python-pexpect strace |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 1105 | WORKDIR /root |
| 1106 | CMD ["/etc/freeradius/start-radius.py"] |
| 1107 | ''' |
| 1108 | super(Radius, cls).build_image(dockerfile, image) |
| 1109 | print('Done building image %s' %image) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 1110 | |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 1111 | class Quagga(Container): |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 1112 | QUAGGA_CONFIG = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 }, |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 1113 | { 'bridge' : 'quagga-br', 'ip': '192.168.10.3', 'mask': 16 }, |
| 1114 | ) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 1115 | ports = [ 179, 2601, 2602, 2603, 2604, 2605, 2606 ] |
| 1116 | host_quagga_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/quagga-config') |
| 1117 | guest_quagga_config = '/root/config' |
| 1118 | quagga_config_file = os.path.join(guest_quagga_config, 'testrib.conf') |
| 1119 | host_guest_map = ( (host_quagga_config, guest_quagga_config), ) |
A R Karthick | f7a613b | 2017-02-24 09:36:44 -0800 | [diff] [blame] | 1120 | IMAGE = 'cordtest/quagga' |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 1121 | NAME = 'cord-quagga' |
| 1122 | |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 1123 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate', |
A R Karthick | 85eb186 | 2017-01-23 16:10:57 -0800 | [diff] [blame] | 1124 | boot_delay = 15, restart = False, config_file = quagga_config_file, update = False, |
| 1125 | network = None): |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 1126 | super(Quagga, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.QUAGGA_CONFIG) |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 1127 | if update is True or not self.img_exists(): |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 1128 | self.build_image(self.image_name) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 1129 | if restart is True and self.exists(): |
| 1130 | self.kill() |
| 1131 | if not self.exists(): |
| 1132 | self.remove_container(name, force=True) |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 1133 | host_config = self.create_host_config(port_list = self.ports, |
| 1134 | host_guest_map = self.host_guest_map, |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 1135 | privileged = True) |
| 1136 | volumes = [] |
| 1137 | for _,g in self.host_guest_map: |
| 1138 | volumes.append(g) |
| 1139 | self.start(ports = self.ports, |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 1140 | host_config = host_config, |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 1141 | volumes = volumes, tty = True) |
A R Karthick | 85eb186 | 2017-01-23 16:10:57 -0800 | [diff] [blame] | 1142 | if network is not None: |
| 1143 | Container.connect_to_network(self.name, network) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 1144 | print('Starting Quagga on container %s' %self.name) |
| 1145 | self.execute('{0}/start.sh {1}'.format(self.guest_quagga_config, config_file)) |
| 1146 | time.sleep(boot_delay) |
| 1147 | |
| 1148 | @classmethod |
| 1149 | def build_image(cls, image): |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 1150 | onos_quagga_ip = Onos.QUAGGA_CONFIG[0]['ip'] |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 1151 | print('Building Quagga image %s' %image) |
| 1152 | dockerfile = ''' |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 1153 | FROM ubuntu:14.04 |
| 1154 | MAINTAINER chetan@ciena.com |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 1155 | WORKDIR /root |
| 1156 | RUN useradd -M quagga |
| 1157 | RUN mkdir /var/log/quagga && chown quagga:quagga /var/log/quagga |
| 1158 | RUN mkdir /var/run/quagga && chown quagga:quagga /var/run/quagga |
A R Karthick | 973ea69 | 2016-10-17 12:23:02 -0700 | [diff] [blame] | 1159 | RUN apt-get update && apt-get install -qy git autoconf libtool gawk make telnet libreadline6-dev pkg-config protobuf-c-compiler |
ChetanGaonker | b5b46c6 | 2016-08-16 12:02:53 -0700 | [diff] [blame] | 1160 | RUN git clone git://git.savannah.nongnu.org/quagga.git quagga && \ |
A R Karthick | 8f69c2c | 2016-10-21 11:43:26 -0700 | [diff] [blame] | 1161 | (cd quagga && git checkout quagga-1.0.20160315 && ./bootstrap.sh && \ |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 1162 | sed -i -r 's,htonl.*?\(INADDR_LOOPBACK\),inet_addr\("{0}"\),g' zebra/zebra_fpm.c && \ |
| 1163 | ./configure --enable-fpm --disable-doc --localstatedir=/var/run/quagga && make && make install) |
| 1164 | RUN ldconfig |
| 1165 | '''.format(onos_quagga_ip) |
| 1166 | super(Quagga, cls).build_image(dockerfile, image) |
| 1167 | print('Done building image %s' %image) |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 1168 | |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 1169 | class QuaggaStopWrapper(Container): |
| 1170 | def __init__(self, name = Quagga.NAME, image = Quagga.IMAGE, tag = 'candidate'): |
| 1171 | super(QuaggaStopWrapper, self).__init__(name, image, prefix = Container.IMAGE_PREFIX, tag = tag) |
| 1172 | if self.exists(): |
| 1173 | self.kill() |
| 1174 | |
| 1175 | |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 1176 | def reinitContainerClients(): |
| 1177 | docker_netns.dckr = Client() |
| 1178 | Container.dckr = Client() |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1179 | |
| 1180 | class Xos(Container): |
| 1181 | setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup') |
| 1182 | TAG = 'latest' |
| 1183 | PREFIX = '' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1184 | host_guest_map = None |
| 1185 | env = None |
| 1186 | ports = None |
| 1187 | volumes = None |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1188 | |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1189 | @classmethod |
| 1190 | def get_cmd(cls, img_name): |
| 1191 | cmd = cls.dckr.inspect_image(img_name)['Config']['Cmd'] |
| 1192 | return ' '.join(cmd) |
| 1193 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1194 | def __init__(self, name, image, prefix = PREFIX, tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1195 | boot_delay = 20, restart = False, network_cfg = None, update = False): |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1196 | if restart is True: |
| 1197 | ##Find the right image to restart |
| 1198 | running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers()) |
| 1199 | if running_image: |
| 1200 | image_name = running_image[0]['Image'] |
| 1201 | try: |
| 1202 | image = image_name.split(':')[0] |
| 1203 | tag = image_name.split(':')[1] |
| 1204 | except: pass |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1205 | super(Xos, self).__init__(name, image, prefix = prefix, tag = tag) |
| 1206 | if update is True or not self.img_exists(): |
| 1207 | self.build_image(self.image_name) |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1208 | self.command = self.get_cmd(self.image_name).strip() or None |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1209 | if restart is True and self.exists(): |
| 1210 | self.kill() |
| 1211 | if not self.exists(): |
| 1212 | self.remove_container(name, force=True) |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1213 | host_config = self.create_host_config(port_list = self.ports, |
| 1214 | host_guest_map = self.host_guest_map, |
| 1215 | privileged = True) |
| 1216 | print('Starting XOS container %s' %self.name) |
| 1217 | self.start(ports = self.ports, environment = self.env, host_config = host_config, |
| 1218 | volumes = self.volumes, tty = True) |
| 1219 | print('Waiting %d seconds for XOS Base Container to boot' %(boot_delay)) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1220 | time.sleep(boot_delay) |
| 1221 | |
| 1222 | @classmethod |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1223 | def build_image(cls, image, dockerfile_path, image_target = 'build'): |
| 1224 | cmd = 'cd {} && make {}'.format(dockerfile_path, image_target) |
| 1225 | print('Building XOS %s' %image) |
| 1226 | res = os.system(cmd) |
| 1227 | print('Done building image %s. Image build %s' %(image, 'successful' if res == 0 else 'failed')) |
| 1228 | return res |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1229 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1230 | class XosServer(Xos): |
| 1231 | ports = [8000,9998,9999] |
| 1232 | NAME = 'xos-server' |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1233 | IMAGE = 'xosproject/xos' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1234 | BASE_IMAGE = 'xosproject/xos-base' |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1235 | TAG = 'latest' |
| 1236 | PREFIX = '' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1237 | dockerfile_path = os.path.join(Xos.setup_dir, 'xos') |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1238 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1239 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1240 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1241 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1242 | |
| 1243 | @classmethod |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1244 | def build_image(cls, image = IMAGE): |
| 1245 | ##build the base image and then build the server image |
| 1246 | Xos.build_image(cls.BASE_IMAGE, cls.dockerfile_path, image_target = 'base') |
| 1247 | Xos.build_image(image, cls.dockerfile_path) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1248 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1249 | class XosSynchronizerOpenstack(Xos): |
| 1250 | ports = [2375,] |
| 1251 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer') |
| 1252 | NAME = 'xos-synchronizer' |
| 1253 | IMAGE = 'xosproject/xos-synchronizer-openstack' |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1254 | TAG = 'latest' |
| 1255 | PREFIX = '' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1256 | host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1257 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1258 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1259 | tag = TAG, boot_delay = 20, restart = False, network_cfg = None, update = False): |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1260 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1261 | |
| 1262 | @classmethod |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1263 | def build_image(cls, image = IMAGE): |
| 1264 | XosServer.build_image() |
| 1265 | Xos.build_image(image, cls.dockerfile_path) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1266 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1267 | class XosSynchronizerOnboarding(Xos): |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1268 | NAME = 'xos-synchronizer-onboarding' |
| 1269 | IMAGE = 'xosproject/xos-synchronizer-onboarding' |
| 1270 | TAG = 'latest' |
| 1271 | PREFIX = '' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1272 | dockerfile_path = os.path.join(Xos.setup_dir, 'onboarding_synchronizer') |
| 1273 | host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1274 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1275 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1276 | tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False): |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1277 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1278 | |
| 1279 | @classmethod |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1280 | def build_image(cls, image = IMAGE): |
| 1281 | XosSynchronizerOpenstack.build_image() |
| 1282 | Xos.build_image(image, cls.dockerfile_path) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1283 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1284 | class XosSynchronizerOpenvpn(Xos): |
| 1285 | NAME = 'xos-synchronizer-openvpn' |
| 1286 | IMAGE = 'xosproject/xos-openvpn' |
| 1287 | TAG = 'latest' |
| 1288 | PREFIX = '' |
| 1289 | dockerfile_path = os.path.join(Xos.setup_dir, 'openvpn') |
| 1290 | host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1291 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1292 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1293 | tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False): |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1294 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1295 | |
| 1296 | @classmethod |
| 1297 | def build_image(cls, image = IMAGE): |
| 1298 | XosSynchronizerOpenstack.build_image() |
| 1299 | Xos.build_image(image, cls.dockerfile_path) |
| 1300 | |
| 1301 | class XosPostgresql(Xos): |
| 1302 | ports = [5432,] |
| 1303 | NAME = 'xos-db-postgres' |
| 1304 | IMAGE = 'xosproject/xos-postgres' |
| 1305 | TAG = 'latest' |
| 1306 | PREFIX = '' |
| 1307 | volumes = ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"] |
| 1308 | dockerfile_path = os.path.join(Xos.setup_dir, 'postgresql') |
| 1309 | |
| 1310 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1311 | tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False): |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1312 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1313 | |
| 1314 | @classmethod |
| 1315 | def build_image(cls, image = IMAGE): |
| 1316 | Xos.build_image(image, cls.dockerfile_path) |
| 1317 | |
| 1318 | class XosSyndicateMs(Xos): |
| 1319 | ports = [8080,] |
| 1320 | env = None |
| 1321 | NAME = 'xos-syndicate-ms' |
| 1322 | IMAGE = 'xosproject/syndicate-ms' |
| 1323 | TAG = 'latest' |
| 1324 | PREFIX = '' |
| 1325 | dockerfile_path = os.path.join(Xos.setup_dir, 'syndicate-ms') |
| 1326 | |
| 1327 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1328 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1329 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1330 | |
| 1331 | @classmethod |
| 1332 | def build_image(cls, image = IMAGE): |
| 1333 | Xos.build_image(image, cls.dockerfile_path) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1334 | |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1335 | class XosSyncVtn(Xos): |
| 1336 | ports = [8080,] |
| 1337 | env = None |
| 1338 | NAME = 'xos-synchronizer-vtn' |
| 1339 | IMAGE = 'xosproject/xos-synchronizer-vtn' |
| 1340 | TAG = 'latest' |
| 1341 | PREFIX = '' |
| 1342 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtn') |
| 1343 | |
| 1344 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1345 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1346 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1347 | |
| 1348 | @classmethod |
| 1349 | def build_image(cls, image = IMAGE): |
| 1350 | Xos.build_image(image, cls.dockerfile_path) |
| 1351 | |
| 1352 | class XosSyncVtr(Xos): |
| 1353 | ports = [8080,] |
| 1354 | env = None |
| 1355 | NAME = 'xos-synchronizer-vtr' |
| 1356 | IMAGE = 'xosproject/xos-synchronizer-vtr' |
| 1357 | TAG = 'latest' |
| 1358 | PREFIX = '' |
| 1359 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtr') |
| 1360 | |
| 1361 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1362 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1363 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1364 | |
| 1365 | @classmethod |
| 1366 | def build_image(cls, image = IMAGE): |
| 1367 | Xos.build_image(image, cls.dockerfile_path) |
| 1368 | |
| 1369 | class XosSyncVsg(Xos): |
| 1370 | ports = [8080,] |
| 1371 | env = None |
| 1372 | NAME = 'xos-synchronizer-vsg' |
| 1373 | IMAGE = 'xosproject/xos-synchronizer-vsg' |
| 1374 | TAG = 'latest' |
| 1375 | PREFIX = '' |
| 1376 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vsg') |
| 1377 | |
| 1378 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1379 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1380 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1381 | |
| 1382 | @classmethod |
| 1383 | def build_image(cls, image = IMAGE): |
| 1384 | Xos.build_image(image, cls.dockerfile_path) |
| 1385 | |
| 1386 | |
| 1387 | class XosSyncOnos(Xos): |
| 1388 | ports = [8080,] |
| 1389 | env = None |
| 1390 | NAME = 'xos-synchronizer-onos' |
| 1391 | IMAGE = 'xosproject/xos-synchronizer-onos' |
| 1392 | TAG = 'latest' |
| 1393 | PREFIX = '' |
| 1394 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-onos') |
| 1395 | |
| 1396 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1397 | boot_delay = 30, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1398 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1399 | |
| 1400 | @classmethod |
| 1401 | def build_image(cls, image = IMAGE): |
| 1402 | Xos.build_image(image, cls.dockerfile_path) |
| 1403 | |
| 1404 | class XosSyncFabric(Xos): |
| 1405 | ports = [8080,] |
| 1406 | env = None |
| 1407 | NAME = 'xos-synchronizer-fabric' |
| 1408 | IMAGE = 'xosproject/xos-synchronizer-fabric' |
| 1409 | TAG = 'latest' |
| 1410 | PREFIX = '' |
| 1411 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-fabric') |
| 1412 | |
| 1413 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1414 | boot_delay = 30, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1415 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1416 | |
| 1417 | @classmethod |
| 1418 | def build_image(cls, image = IMAGE): |
| 1419 | Xos.build_image(image, cls.dockerfile_path) |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 1420 | |
| 1421 | if __name__ == '__main__': |
| 1422 | onos = Onos(boot_delay = 10, restart = True) |