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