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 |
| 26 | from docker import Client |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 27 | from shutil import rmtree |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 28 | from OnosCtrl import OnosCtrl |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 29 | from OnosLog import OnosLog |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 30 | from threadPool import ThreadPool |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 31 | from threading import Lock |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 32 | |
| 33 | class docker_netns(object): |
| 34 | |
| 35 | dckr = Client() |
| 36 | def __init__(self, name): |
| 37 | pid = int(self.dckr.inspect_container(name)['State']['Pid']) |
| 38 | if pid == 0: |
| 39 | raise Exception('no container named {0}'.format(name)) |
| 40 | self.pid = pid |
| 41 | |
| 42 | def __enter__(self): |
| 43 | pid = self.pid |
| 44 | if not os.path.exists('/var/run/netns'): |
| 45 | os.mkdir('/var/run/netns') |
| 46 | os.symlink('/proc/{0}/ns/net'.format(pid), '/var/run/netns/{0}'.format(pid)) |
| 47 | return str(pid) |
| 48 | |
| 49 | def __exit__(self, type, value, traceback): |
| 50 | pid = self.pid |
| 51 | os.unlink('/var/run/netns/{0}'.format(pid)) |
| 52 | |
| 53 | flatten = lambda l: chain.from_iterable(l) |
| 54 | |
| 55 | class Container(object): |
| 56 | dckr = Client() |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 57 | IMAGE_PREFIX = '' ##for saving global prefix for all test classes |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 58 | CONFIG_LOCK = Lock() |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 59 | |
| 60 | 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] | 61 | self.name = name |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 62 | self.prefix = prefix |
| 63 | if prefix: |
| 64 | self.prefix += '/' |
| 65 | image = '{}{}'.format(self.prefix, image) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 66 | self.image = image |
| 67 | self.tag = tag |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 68 | if tag: |
| 69 | self.image_name = image + ':' + tag |
| 70 | else: |
| 71 | self.image_name = image |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 72 | self.id = None |
| 73 | self.command = command |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 74 | self.quagga_config = quagga_config |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 75 | |
| 76 | @classmethod |
| 77 | def build_image(cls, dockerfile, tag, force=True, nocache=False): |
| 78 | f = io.BytesIO(dockerfile.encode('utf-8')) |
| 79 | if force or not cls.image_exists(tag): |
| 80 | print('Build {0}...'.format(tag)) |
| 81 | for line in cls.dckr.build(fileobj=f, rm=True, tag=tag, decode=True, nocache=nocache): |
| 82 | if 'stream' in line: |
| 83 | print(line['stream'].strip()) |
| 84 | |
| 85 | @classmethod |
| 86 | def image_exists(cls, name): |
| 87 | return name in [ctn['RepoTags'][0] for ctn in cls.dckr.images()] |
| 88 | |
| 89 | @classmethod |
| 90 | def create_host_config(cls, port_list = None, host_guest_map = None, privileged = False): |
| 91 | port_bindings = None |
| 92 | binds = None |
| 93 | if port_list: |
| 94 | port_bindings = {} |
| 95 | for p in port_list: |
| 96 | port_bindings[str(p)] = str(p) |
| 97 | |
| 98 | if host_guest_map: |
| 99 | binds = [] |
| 100 | for h, g in host_guest_map: |
| 101 | binds.append('{0}:{1}'.format(h, g)) |
| 102 | |
| 103 | return cls.dckr.create_host_config(binds = binds, port_bindings = port_bindings, privileged = privileged) |
| 104 | |
| 105 | @classmethod |
| 106 | def cleanup(cls, image): |
A R Karthick | 09b1f4e | 2016-05-12 14:31:50 -0700 | [diff] [blame] | 107 | 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] | 108 | for cnt in cnt_list: |
| 109 | print('Cleaning container %s' %cnt['Id']) |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 110 | if cnt.has_key('State') and cnt['State'] == 'running': |
A R Karthick | 09b1f4e | 2016-05-12 14:31:50 -0700 | [diff] [blame] | 111 | cls.dckr.kill(cnt['Id']) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 112 | cls.dckr.remove_container(cnt['Id'], force=True) |
| 113 | |
| 114 | @classmethod |
| 115 | def remove_container(cls, name, force=True): |
| 116 | try: |
| 117 | cls.dckr.remove_container(name, force = force) |
| 118 | except: pass |
| 119 | |
| 120 | def exists(self): |
| 121 | return '/{0}'.format(self.name) in list(flatten(n['Names'] for n in self.dckr.containers())) |
| 122 | |
| 123 | def img_exists(self): |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 124 | return self.image_name in [ctn['RepoTags'][0] if ctn['RepoTags'] else '' for ctn in self.dckr.images()] |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 125 | |
| 126 | def ip(self): |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 127 | cnt_list = filter(lambda c: c['Names'][0] == '/{}'.format(self.name), self.dckr.containers()) |
| 128 | #if not cnt_list: |
| 129 | # 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] | 130 | cnt_settings = cnt_list.pop() |
| 131 | return cnt_settings['NetworkSettings']['Networks']['bridge']['IPAddress'] |
| 132 | |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 133 | @classmethod |
| 134 | def ips(cls, image_name): |
| 135 | cnt_list = filter(lambda c: c['Image'] == image_name, cls.dckr.containers()) |
| 136 | ips = [ cnt['NetworkSettings']['Networks']['bridge']['IPAddress'] for cnt in cnt_list ] |
| 137 | return ips |
| 138 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 139 | def kill(self, remove = True): |
| 140 | self.dckr.kill(self.name) |
| 141 | self.dckr.remove_container(self.name, force=True) |
| 142 | |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 143 | def start(self, rm = True, ports = None, volumes = None, host_config = None, |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 144 | environment = None, tty = False, stdin_open = True): |
| 145 | |
| 146 | if rm and self.exists(): |
| 147 | print('Removing container:', self.name) |
| 148 | self.dckr.remove_container(self.name, force=True) |
| 149 | |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 150 | 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] | 151 | detach=True, name=self.name, |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 152 | environment = environment, |
| 153 | volumes = volumes, |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 154 | host_config = host_config, stdin_open=stdin_open, tty = tty) |
| 155 | self.dckr.start(container=self.name) |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 156 | if self.quagga_config: |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 157 | self.connect_to_br() |
| 158 | self.id = ctn['Id'] |
| 159 | return ctn |
| 160 | |
Thangavelu K S | ef6f0a5 | 2016-12-14 19:57:05 +0000 | [diff] [blame] | 161 | @classmethod |
| 162 | def pause_container(cls, image, delay): |
| 163 | cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers(all=True)) |
| 164 | for cnt in cnt_list: |
| 165 | print('Pause the container %s' %cnt['Id']) |
| 166 | if cnt.has_key('State') and cnt['State'] == 'running': |
| 167 | cls.dckr.pause(cnt['Id']) |
| 168 | if delay != 0: |
| 169 | time.sleep(delay) |
| 170 | for cnt in cnt_list: |
| 171 | print('Unpause the container %s' %cnt['Id']) |
| 172 | cls.dckr.unpause(cnt['Id']) |
| 173 | else: |
| 174 | print('Infinity time pause the container %s' %cnt['Id']) |
| 175 | return 'success' |
| 176 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 177 | def connect_to_br(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 178 | index = 0 |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 179 | self.CONFIG_LOCK.acquire() |
| 180 | try: |
| 181 | with docker_netns(self.name) as pid: |
| 182 | for quagga_config in self.quagga_config: |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 183 | ip = IPRoute() |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 184 | br = ip.link_lookup(ifname=quagga_config['bridge']) |
| 185 | if len(br) == 0: |
| 186 | try: |
| 187 | ip.link_create(ifname=quagga_config['bridge'], kind='bridge') |
| 188 | except NetlinkError as e: |
| 189 | err, _ = e.args |
| 190 | if err == errno.EEXIST: |
| 191 | pass |
| 192 | else: |
| 193 | raise NetlinkError(*e.args) |
| 194 | br = ip.link_lookup(ifname=quagga_config['bridge']) |
| 195 | br = br[0] |
| 196 | ip.link('set', index=br, state='up') |
| 197 | ifname = '{0}-{1}'.format(self.name, index) |
| 198 | ifs = ip.link_lookup(ifname=ifname) |
| 199 | if len(ifs) > 0: |
| 200 | ip.link_remove(ifs[0]) |
| 201 | peer_ifname = '{0}-{1}'.format(pid, index) |
| 202 | ip.link_create(ifname=ifname, kind='veth', peer=peer_ifname) |
| 203 | host = ip.link_lookup(ifname=ifname)[0] |
| 204 | ip.link('set', index=host, master=br) |
| 205 | ip.link('set', index=host, state='up') |
| 206 | guest = ip.link_lookup(ifname=peer_ifname)[0] |
| 207 | ip.link('set', index=guest, net_ns_fd=pid) |
| 208 | with Namespace(pid, 'net'): |
| 209 | ip = IPRoute() |
| 210 | ip.link('set', index=guest, ifname='eth{}'.format(index+1)) |
| 211 | ip.addr('add', index=guest, address=quagga_config['ip'], mask=quagga_config['mask']) |
| 212 | ip.link('set', index=guest, state='up') |
| 213 | index += 1 |
| 214 | finally: |
| 215 | self.CONFIG_LOCK.release() |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 216 | |
Thangavelu K S | ef6f0a5 | 2016-12-14 19:57:05 +0000 | [diff] [blame] | 217 | def execute(self, cmd, tty = True, stream = False, shell = False, detach = True): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 218 | res = 0 |
| 219 | if type(cmd) == str: |
| 220 | cmds = (cmd,) |
| 221 | else: |
| 222 | cmds = cmd |
| 223 | if shell: |
| 224 | for c in cmds: |
| 225 | res += os.system('docker exec {0} {1}'.format(self.name, c)) |
| 226 | return res |
| 227 | for c in cmds: |
| 228 | i = self.dckr.exec_create(container=self.name, cmd=c, tty = tty, privileged = True) |
Thangavelu K S | ef6f0a5 | 2016-12-14 19:57:05 +0000 | [diff] [blame] | 229 | self.dckr.exec_start(i['Id'], stream = stream, detach=detach) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 230 | result = self.dckr.exec_inspect(i['Id']) |
| 231 | res += 0 if result['ExitCode'] == None else result['ExitCode'] |
| 232 | return res |
| 233 | |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 234 | def restart(self, timeout =10): |
| 235 | return self.dckr.restart(self.name, timeout) |
| 236 | |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 237 | def get_mem(jvm_heap_size = None, instances = 1): |
A R Karthick | 1f90820 | 2016-11-16 17:32:20 -0800 | [diff] [blame] | 238 | if instances <= 0: |
| 239 | instances = 1 |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 240 | heap_size = jvm_heap_size |
| 241 | heap_size_i = 0 |
| 242 | #sanitize the heap size config |
| 243 | if heap_size is not None: |
| 244 | if not heap_size.isdigit(): |
| 245 | try: |
| 246 | heap_size_i = int(heap_size[:-1]) |
| 247 | suffix = heap_size[-1] |
| 248 | if suffix == 'M': |
| 249 | heap_size_i /= 1024 #convert to gigs |
| 250 | except: |
| 251 | ##invalid suffix length probably. Fall back to default |
| 252 | heap_size = None |
| 253 | else: |
| 254 | heap_size_i = int(heap_size) |
| 255 | |
Chetan Gaonker | 462d9fa | 2016-05-03 16:39:10 -0700 | [diff] [blame] | 256 | with open('/proc/meminfo', 'r') as fd: |
| 257 | meminfo = fd.readlines() |
| 258 | mem = 0 |
| 259 | for m in meminfo: |
| 260 | if m.startswith('MemTotal:') or m.startswith('SwapTotal:'): |
| 261 | mem += int(m.split(':')[1].strip().split()[0]) |
| 262 | |
A R Karthick | 1f90820 | 2016-11-16 17:32:20 -0800 | [diff] [blame] | 263 | mem = max(mem/1024/1024/2/instances, 1) |
Chetan Gaonker | 6d0a7b0 | 2016-05-03 16:57:28 -0700 | [diff] [blame] | 264 | mem = min(mem, 16) |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 265 | |
| 266 | if heap_size_i: |
| 267 | #we take the minimum of the provided heap size and max allowed heap size |
| 268 | heap_size_i = min(heap_size_i, mem) |
| 269 | else: |
| 270 | heap_size_i = mem |
| 271 | |
| 272 | return '{}G'.format(heap_size_i) |
Chetan Gaonker | 462d9fa | 2016-05-03 16:39:10 -0700 | [diff] [blame] | 273 | |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 274 | class OnosCord(Container): |
| 275 | """Use this when running the cord tester agent on the onos compute node""" |
| 276 | onos_cord_dir = os.path.join(os.getenv('HOME'), 'cord-tester-cord') |
| 277 | onos_config_dir_guest = '/root/onos/config' |
| 278 | onos_config_dir = os.path.join(onos_cord_dir, 'config') |
| 279 | docker_yaml = os.path.join(onos_cord_dir, 'docker-compose.yml') |
| 280 | |
A R Karthick | bd9b8a3 | 2016-07-21 09:56:45 -0700 | [diff] [blame] | 281 | def __init__(self, onos_ip, conf, boot_delay = 60): |
| 282 | self.onos_ip = onos_ip |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 283 | self.cord_conf_dir = conf |
A R Karthick | bd9b8a3 | 2016-07-21 09:56:45 -0700 | [diff] [blame] | 284 | self.boot_delay = boot_delay |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 285 | if os.access(self.cord_conf_dir, os.F_OK) and not os.access(self.onos_cord_dir, os.F_OK): |
| 286 | os.mkdir(self.onos_cord_dir) |
| 287 | os.mkdir(self.onos_config_dir) |
| 288 | ##copy the config file from cord-tester-config |
| 289 | cmd = 'cp {}/* {}'.format(self.cord_conf_dir, self.onos_cord_dir) |
| 290 | os.system(cmd) |
| 291 | |
| 292 | ##update the docker yaml with the config volume |
| 293 | with open(self.docker_yaml, 'r') as f: |
| 294 | yaml_config = yaml.load(f) |
| 295 | image = yaml_config['services'].keys()[0] |
| 296 | name = 'cordtestercord_{}_1'.format(image) |
| 297 | volumes = yaml_config['services'][image]['volumes'] |
| 298 | config_volumes = filter(lambda e: e.find(self.onos_config_dir_guest) >= 0, volumes) |
| 299 | if not config_volumes: |
| 300 | config_volume = '{}:{}'.format(self.onos_config_dir, self.onos_config_dir_guest) |
| 301 | volumes.append(config_volume) |
| 302 | docker_yaml_changed = '{}-changed'.format(self.docker_yaml) |
| 303 | with open(docker_yaml_changed, 'w') as wf: |
| 304 | yaml.dump(yaml_config, wf) |
| 305 | |
| 306 | os.rename(docker_yaml_changed, self.docker_yaml) |
| 307 | self.volumes = volumes |
| 308 | |
| 309 | super(OnosCord, self).__init__(name, image, tag = '') |
| 310 | cord_conf_dir_basename = os.path.basename(self.cord_conf_dir.replace('-', '')) |
| 311 | self.xos_onos_name = '{}_{}_1'.format(cord_conf_dir_basename, image) |
| 312 | ##Create an container instance of xos onos |
| 313 | self.xos_onos = Container(self.xos_onos_name, image, tag = '') |
| 314 | |
| 315 | def start(self, restart = False, network_cfg = None): |
| 316 | if restart is True: |
| 317 | if self.exists(): |
| 318 | ##Kill the existing instance |
| 319 | print('Killing container %s' %self.name) |
| 320 | self.kill() |
| 321 | if self.xos_onos.exists(): |
| 322 | print('Killing container %s' %self.xos_onos.name) |
| 323 | self.xos_onos.kill() |
| 324 | |
| 325 | if network_cfg is not None: |
| 326 | json_data = json.dumps(network_cfg, indent=4) |
| 327 | with open('{}/network-cfg.json'.format(self.onos_config_dir), 'w') as f: |
| 328 | f.write(json_data) |
| 329 | |
| 330 | #start the container using docker-compose |
| 331 | cmd = 'cd {} && docker-compose up -d'.format(self.onos_cord_dir) |
| 332 | os.system(cmd) |
A R Karthick | bd9b8a3 | 2016-07-21 09:56:45 -0700 | [diff] [blame] | 333 | #Delay to make sure ONOS fully boots |
| 334 | time.sleep(self.boot_delay) |
| 335 | Onos.install_cord_apps(onos_ip = self.onos_ip) |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 336 | |
| 337 | def build_image(self): |
| 338 | build_cmd = 'cd {} && docker-compose build'.format(self.onos_cord_dir) |
| 339 | os.system(build_cmd) |
| 340 | |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 341 | class OnosCordStopWrapper(Container): |
| 342 | onos_cord_dir = os.path.join(os.getenv('HOME'), 'cord-tester-cord') |
| 343 | docker_yaml = os.path.join(onos_cord_dir, 'docker-compose.yml') |
| 344 | |
| 345 | def __init__(self): |
| 346 | if os.access(self.docker_yaml, os.F_OK): |
| 347 | with open(self.docker_yaml, 'r') as f: |
| 348 | yaml_config = yaml.load(f) |
| 349 | image = yaml_config['services'].keys()[0] |
| 350 | name = 'cordtestercord_{}_1'.format(image) |
| 351 | super(OnosCordStopWrapper, self).__init__(name, image, tag = '') |
| 352 | if self.exists(): |
| 353 | print('Killing container %s' %self.name) |
| 354 | self.kill() |
| 355 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 356 | class Onos(Container): |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 357 | 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] | 358 | MAX_INSTANCES = 3 |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 359 | JVM_HEAP_SIZE = None |
Chetan Gaonker | 462d9fa | 2016-05-03 16:39:10 -0700 | [diff] [blame] | 360 | SYSTEM_MEMORY = (get_mem(),) * 2 |
A R Karthick | a2492c1 | 2016-12-16 10:31:51 -0800 | [diff] [blame] | 361 | INSTANCE_MEMORY = (get_mem(instances=MAX_INSTANCES),) * 2 |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 362 | JAVA_OPTS_FORMAT = '-Xms{} -Xmx{} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode' |
| 363 | JAVA_OPTS_DEFAULT = JAVA_OPTS_FORMAT.format(*SYSTEM_MEMORY) #-XX:+PrintGCDetails -XX:+PrintGCTimeStamps' |
| 364 | JAVA_OPTS_CLUSTER_DEFAULT = JAVA_OPTS_FORMAT.format(*INSTANCE_MEMORY) |
| 365 | env = { 'ONOS_APPS' : 'drivers,openflow,proxyarp,vrouter', 'JAVA_OPTS' : JAVA_OPTS_DEFAULT } |
A.R Karthick | dfeadb0 | 2016-11-30 17:55:51 -0800 | [diff] [blame] | 366 | onos_cord_apps = ( ('cord-config', '1.1-SNAPSHOT'), |
| 367 | ('aaa', '1.1-SNAPSHOT'), |
| 368 | ('igmp', '1.1-SNAPSHOT'), |
| 369 | #('vtn', '1.1-SNAPSHOT'), |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 370 | ) |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 371 | ports = [] #[ 8181, 8101, 9876, 6653, 6633, 2000, 2620 ] |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 372 | setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup') |
| 373 | host_config_dir = os.path.join(setup_dir, 'onos-config') |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 374 | guest_config_dir = '/root/onos/config' |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 375 | guest_data_dir = '/root/onos/apache-karaf-3.0.5/data' |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 376 | onos_gen_partitions = os.path.join(setup_dir, 'onos-gen-partitions') |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 377 | onos_form_cluster = os.path.join(setup_dir, 'onos-form-cluster') |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 378 | 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] | 379 | host_guest_map = ( (host_config_dir, guest_config_dir), ) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 380 | cluster_cfg = os.path.join(host_config_dir, 'cluster.json') |
| 381 | cluster_mode = False |
| 382 | cluster_instances = [] |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 383 | NAME = 'cord-onos' |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 384 | ##the ip of ONOS in default cluster.json in setup/onos-config |
| 385 | CLUSTER_CFG_IP = '172.17.0.2' |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 386 | IMAGE = 'onosproject/onos' |
| 387 | TAG = 'latest' |
| 388 | PREFIX = '' |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 389 | |
| 390 | @classmethod |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 391 | def generate_cluster_cfg(cls, ip): |
| 392 | if type(ip) in [ list, tuple ]: |
| 393 | ips = ' '.join(ip) |
| 394 | else: |
| 395 | ips = ip |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 396 | try: |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 397 | cmd = '{} {} {}'.format(cls.onos_gen_partitions, cls.cluster_cfg, ips) |
| 398 | os.system(cmd) |
| 399 | except: pass |
| 400 | |
| 401 | @classmethod |
| 402 | def form_cluster(cls, ips): |
| 403 | nodes = ' '.join(ips) |
| 404 | try: |
| 405 | cmd = '{} {}'.format(cls.onos_form_cluster, nodes) |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 406 | os.system(cmd) |
| 407 | except: pass |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 408 | |
A R Karthick | 9d48c65 | 2016-09-15 09:16:36 -0700 | [diff] [blame] | 409 | @classmethod |
| 410 | def cleanup_runtime(cls): |
| 411 | '''Cleanup ONOS runtime generated files''' |
| 412 | files = ( Onos.cluster_cfg, os.path.join(Onos.host_config_dir, 'network-cfg.json') ) |
| 413 | for f in files: |
| 414 | if os.access(f, os.F_OK): |
| 415 | try: |
| 416 | os.unlink(f) |
| 417 | except: pass |
| 418 | |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 419 | @classmethod |
| 420 | def get_data_map(cls, host_volume, guest_volume_dir): |
| 421 | host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume)) |
| 422 | if not os.path.exists(host_volume_dir): |
| 423 | os.mkdir(host_volume_dir) |
| 424 | return ( (host_volume_dir, guest_volume_dir), ) |
| 425 | |
| 426 | @classmethod |
| 427 | def remove_data_map(cls, host_volume, guest_volume_dir): |
| 428 | host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume)) |
| 429 | if os.path.exists(host_volume_dir): |
| 430 | rmtree(host_volume_dir) |
| 431 | |
| 432 | def remove_data_volume(self): |
| 433 | if self.data_map is not None: |
| 434 | self.remove_data_map(*self.data_map) |
| 435 | |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 436 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG, |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 437 | boot_delay = 20, restart = False, network_cfg = None, |
A R Karthick | a2492c1 | 2016-12-16 10:31:51 -0800 | [diff] [blame] | 438 | cluster = False, data_volume = None, async = False, quagga_config = None): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 439 | if restart is True: |
| 440 | ##Find the right image to restart |
| 441 | running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers()) |
| 442 | if running_image: |
| 443 | image_name = running_image[0]['Image'] |
| 444 | try: |
| 445 | image = image_name.split(':')[0] |
| 446 | tag = image_name.split(':')[1] |
| 447 | except: pass |
| 448 | |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 449 | if quagga_config is None: |
| 450 | quagga_config = Onos.QUAGGA_CONFIG |
| 451 | 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] | 452 | self.boot_delay = boot_delay |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 453 | self.data_map = None |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 454 | instance_memory = (get_mem(jvm_heap_size = Onos.JVM_HEAP_SIZE, instances = Onos.MAX_INSTANCES),) * 2 |
| 455 | self.env['JAVA_OPTS'] = self.JAVA_OPTS_FORMAT.format(*instance_memory) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 456 | if cluster is True: |
| 457 | self.ports = [] |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 458 | if data_volume is not None: |
| 459 | self.data_map = self.get_data_map(data_volume, self.guest_data_dir) |
| 460 | self.host_guest_map = self.host_guest_map + self.data_map |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 461 | if os.access(self.cluster_cfg, os.F_OK): |
| 462 | try: |
| 463 | os.unlink(self.cluster_cfg) |
| 464 | except: pass |
| 465 | |
| 466 | self.host_config = self.create_host_config(port_list = self.ports, |
| 467 | host_guest_map = self.host_guest_map) |
| 468 | self.volumes = [] |
| 469 | for _,g in self.host_guest_map: |
| 470 | self.volumes.append(g) |
| 471 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 472 | if restart is True and self.exists(): |
| 473 | self.kill() |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 474 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 475 | if not self.exists(): |
| 476 | self.remove_container(name, force=True) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 477 | host_config = self.create_host_config(port_list = self.ports, |
| 478 | host_guest_map = self.host_guest_map) |
| 479 | volumes = [] |
| 480 | for _,g in self.host_guest_map: |
| 481 | volumes.append(g) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 482 | if network_cfg is not None: |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 483 | json_data = json.dumps(network_cfg, indent=4) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 484 | with open('{}/network-cfg.json'.format(self.host_config_dir), 'w') as f: |
| 485 | f.write(json_data) |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 486 | if cluster is False or async is False: |
| 487 | print('Starting ONOS container %s' %self.name) |
| 488 | self.start(ports = self.ports, environment = self.env, |
| 489 | host_config = self.host_config, volumes = self.volumes, tty = True) |
| 490 | if not restart: |
| 491 | ##wait a bit before fetching IP to regenerate cluster cfg |
| 492 | time.sleep(5) |
| 493 | ip = self.ip() |
| 494 | ##Just a quick hack/check to ensure we don't regenerate in the common case. |
| 495 | ##As ONOS is usually the first test container that is started |
| 496 | if cluster is False: |
| 497 | if ip != self.CLUSTER_CFG_IP or not os.access(self.cluster_cfg, os.F_OK): |
| 498 | print('Regenerating ONOS cluster cfg for ip %s' %ip) |
| 499 | self.generate_cluster_cfg(ip) |
| 500 | self.kill() |
| 501 | self.remove_container(self.name, force=True) |
| 502 | print('Restarting ONOS container %s' %self.name) |
| 503 | self.start(ports = self.ports, environment = self.env, |
| 504 | host_config = self.host_config, volumes = self.volumes, tty = True) |
| 505 | print('Waiting for ONOS to boot') |
| 506 | time.sleep(boot_delay) |
| 507 | self.wait_for_onos_start(self.ip()) |
| 508 | self.running = True |
| 509 | else: |
| 510 | self.running = False |
| 511 | else: |
| 512 | self.running = True |
| 513 | if self.running: |
| 514 | self.ipaddr = self.ip() |
| 515 | if cluster is False: |
| 516 | self.install_cord_apps(self.ipaddr) |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 517 | |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 518 | @classmethod |
| 519 | def get_quagga_config(cls, instance = 0): |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 520 | quagga_config = copy.deepcopy(cls.QUAGGA_CONFIG) |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 521 | if instance == 0: |
| 522 | return quagga_config |
| 523 | ip = quagga_config[0]['ip'] |
| 524 | octets = ip.split('.') |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 525 | octets[3] = str((int(octets[3]) + instance) & 255) |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 526 | ip = '.'.join(octets) |
| 527 | quagga_config[0]['ip'] = ip |
| 528 | return quagga_config |
| 529 | |
| 530 | @classmethod |
| 531 | def start_cluster_async(cls, onos_instances): |
| 532 | instances = filter(lambda o: o.running == False, onos_instances) |
| 533 | if not instances: |
| 534 | return |
| 535 | tpool = ThreadPool(len(instances), queue_size = 1, wait_timeout = 1) |
| 536 | for onos in instances: |
| 537 | tpool.addTask(onos.start_async) |
| 538 | tpool.cleanUpThreads() |
| 539 | |
| 540 | def start_async(self): |
| 541 | print('Starting ONOS container %s' %self.name) |
| 542 | self.start(ports = self.ports, environment = self.env, |
| 543 | host_config = self.host_config, volumes = self.volumes, tty = True) |
| 544 | time.sleep(3) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 545 | self.ipaddr = self.ip() |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 546 | print('Waiting for ONOS container %s to start' %self.name) |
| 547 | self.wait_for_onos_start(self.ipaddr) |
| 548 | self.running = True |
| 549 | print('ONOS container %s started' %self.name) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 550 | |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 551 | @classmethod |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 552 | def wait_for_onos_start(cls, ip, tries = 30): |
| 553 | onos_log = OnosLog(host = ip) |
| 554 | num_tries = 0 |
| 555 | started = None |
| 556 | while not started and num_tries < tries: |
| 557 | time.sleep(3) |
| 558 | started = onos_log.search_log_pattern('ApplicationManager .* Started') |
| 559 | num_tries += 1 |
| 560 | |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 561 | if not started: |
| 562 | print('ONOS did not start') |
| 563 | else: |
| 564 | print('ONOS started') |
| 565 | return started |
| 566 | |
| 567 | @classmethod |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 568 | def setup_cluster_deprecated(cls, onos_instances, image_name = None): |
| 569 | if not onos_instances or len(onos_instances) < 2: |
| 570 | return |
| 571 | ips = [] |
| 572 | if image_name is not None: |
| 573 | ips = Container.ips(image_name) |
| 574 | else: |
| 575 | for onos in onos_instances: |
| 576 | ips.append(onos.ipaddr) |
| 577 | Onos.cluster_instances = onos_instances |
| 578 | Onos.cluster_mode = True |
| 579 | ##regenerate the cluster json with the 3 instance ips before restarting them back |
| 580 | print('Generating cluster cfg for ONOS instances with ips %s' %ips) |
| 581 | Onos.generate_cluster_cfg(ips) |
| 582 | for onos in onos_instances: |
| 583 | onos.kill() |
| 584 | onos.remove_container(onos.name, force=True) |
| 585 | print('Restarting ONOS container %s for forming cluster' %onos.name) |
| 586 | onos.start(ports = onos.ports, environment = onos.env, |
| 587 | host_config = onos.host_config, volumes = onos.volumes, tty = True) |
| 588 | print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name)) |
| 589 | time.sleep(onos.boot_delay) |
| 590 | onos.ipaddr = onos.ip() |
| 591 | onos.install_cord_apps(onos.ipaddr) |
| 592 | |
| 593 | @classmethod |
| 594 | def setup_cluster(cls, onos_instances, image_name = None): |
| 595 | if not onos_instances or len(onos_instances) < 2: |
| 596 | return |
| 597 | ips = [] |
| 598 | if image_name is not None: |
| 599 | ips = Container.ips(image_name) |
| 600 | else: |
| 601 | for onos in onos_instances: |
| 602 | ips.append(onos.ipaddr) |
| 603 | Onos.cluster_instances = onos_instances |
| 604 | Onos.cluster_mode = True |
| 605 | ##regenerate the cluster json with the 3 instance ips before restarting them back |
| 606 | print('Forming cluster for ONOS instances with ips %s' %ips) |
| 607 | Onos.form_cluster(ips) |
| 608 | ##wait for the cluster to be formed |
| 609 | print('Waiting for the cluster to be formed') |
| 610 | time.sleep(60) |
| 611 | for onos in onos_instances: |
| 612 | onos.install_cord_apps(onos.ipaddr) |
| 613 | |
| 614 | @classmethod |
A R Karthick | e2c24bd | 2016-10-07 14:51:38 -0700 | [diff] [blame] | 615 | def add_cluster(cls, count = 1, network_cfg = None): |
| 616 | if not cls.cluster_instances or Onos.cluster_mode is False: |
| 617 | return |
| 618 | for i in range(count): |
| 619 | name = '{}-{}'.format(Onos.NAME, len(cls.cluster_instances)+1) |
| 620 | onos = cls(name = name, image = Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX, |
| 621 | cluster = True, network_cfg = network_cfg) |
| 622 | cls.cluster_instances.append(onos) |
| 623 | |
| 624 | cls.setup_cluster(cls.cluster_instances) |
| 625 | |
| 626 | @classmethod |
A.R Karthick | 2560f04 | 2016-11-30 14:38:52 -0800 | [diff] [blame] | 627 | def restart_cluster(cls, network_cfg = None, timeout = 10, setup = False): |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 628 | if cls.cluster_mode is False: |
| 629 | return |
| 630 | if not cls.cluster_instances: |
| 631 | return |
| 632 | |
| 633 | if network_cfg is not None: |
| 634 | json_data = json.dumps(network_cfg, indent=4) |
| 635 | with open('{}/network-cfg.json'.format(cls.host_config_dir), 'w') as f: |
| 636 | f.write(json_data) |
| 637 | |
A.R Karthick | 2560f04 | 2016-11-30 14:38:52 -0800 | [diff] [blame] | 638 | cls.cleanup_cluster() |
| 639 | if timeout > 0: |
| 640 | time.sleep(timeout) |
| 641 | |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 642 | #start the instances asynchronously |
| 643 | cls.start_cluster_async(cls.cluster_instances) |
| 644 | time.sleep(5) |
A.R Karthick | 2560f04 | 2016-11-30 14:38:52 -0800 | [diff] [blame] | 645 | ##form the cluster as appropriate |
| 646 | if setup is True: |
| 647 | cls.setup_cluster(cls.cluster_instances) |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 648 | else: |
| 649 | for onos in cls.cluster_instances: |
| 650 | onos.install_cord_apps(onos.ipaddr) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 651 | |
| 652 | @classmethod |
| 653 | def cluster_ips(cls): |
| 654 | if cls.cluster_mode is False: |
| 655 | return [] |
| 656 | if not cls.cluster_instances: |
| 657 | return [] |
| 658 | ips = [ onos.ipaddr for onos in cls.cluster_instances ] |
| 659 | return ips |
| 660 | |
| 661 | @classmethod |
| 662 | def cleanup_cluster(cls): |
| 663 | if cls.cluster_mode is False: |
| 664 | return |
| 665 | if not cls.cluster_instances: |
| 666 | return |
| 667 | for onos in cls.cluster_instances: |
| 668 | if onos.exists(): |
| 669 | onos.kill() |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 670 | onos.running = False |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 671 | onos.remove_container(onos.name, force=True) |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 672 | |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 673 | @classmethod |
A R Karthick | de6b9dc | 2016-11-29 17:46:16 -0800 | [diff] [blame] | 674 | def restart_node(cls, node = None, network_cfg = None, timeout = 10): |
A R Karthick | 889d965 | 2016-10-03 14:13:45 -0700 | [diff] [blame] | 675 | if node is None: |
| 676 | cls(restart = True, network_cfg = network_cfg, image = cls.IMAGE, tag = cls.TAG) |
| 677 | else: |
| 678 | #Restarts a node in the cluster |
| 679 | valid_node = filter(lambda onos: node in [ onos.ipaddr, onos.name ], cls.cluster_instances) |
| 680 | if valid_node: |
| 681 | onos = valid_node.pop() |
| 682 | if onos.exists(): |
| 683 | onos.kill() |
| 684 | onos.remove_container(onos.name, force=True) |
A R Karthick | de6b9dc | 2016-11-29 17:46:16 -0800 | [diff] [blame] | 685 | if timeout > 0: |
| 686 | time.sleep(timeout) |
A R Karthick | 889d965 | 2016-10-03 14:13:45 -0700 | [diff] [blame] | 687 | print('Restarting ONOS container %s' %onos.name) |
| 688 | onos.start(ports = onos.ports, environment = onos.env, |
| 689 | host_config = onos.host_config, volumes = onos.volumes, tty = True) |
A R Karthick | 889d965 | 2016-10-03 14:13:45 -0700 | [diff] [blame] | 690 | onos.ipaddr = onos.ip() |
A.R Karthick | 2560f04 | 2016-11-30 14:38:52 -0800 | [diff] [blame] | 691 | onos.wait_for_onos_start(onos.ipaddr) |
| 692 | onos.install_cord_apps(onos.ipaddr) |
A R Karthick | 889d965 | 2016-10-03 14:13:45 -0700 | [diff] [blame] | 693 | |
| 694 | @classmethod |
A R Karthick | eaf1c4e | 2016-07-19 12:22:35 -0700 | [diff] [blame] | 695 | def install_cord_apps(cls, onos_ip = None): |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 696 | for app, version in cls.onos_cord_apps: |
| 697 | app_file = '{}/{}-{}.oar'.format(cls.cord_apps_dir, app, version) |
A R Karthick | eaf1c4e | 2016-07-19 12:22:35 -0700 | [diff] [blame] | 698 | ok, code = OnosCtrl.install_app(app_file, onos_ip = onos_ip) |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 699 | ##app already installed (conflicts) |
| 700 | if code in [ 409 ]: |
| 701 | ok = True |
| 702 | print('ONOS app %s, version %s %s' %(app, version, 'installed' if ok else 'failed to install')) |
| 703 | time.sleep(2) |
| 704 | |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 705 | class OnosStopWrapper(Container): |
| 706 | def __init__(self, name): |
| 707 | super(OnosStopWrapper, self).__init__(name, Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX) |
| 708 | if self.exists(): |
| 709 | self.kill() |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 710 | self.running = False |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 711 | else: |
| 712 | if Onos.cluster_mode is True: |
| 713 | valid_node = filter(lambda onos: name in [ onos.ipaddr, onos.name ], Onos.cluster_instances) |
| 714 | if valid_node: |
| 715 | onos = valid_node.pop() |
| 716 | if onos.exists(): |
| 717 | onos.kill() |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 718 | onos.running = False |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 719 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 720 | class Radius(Container): |
| 721 | ports = [ 1812, 1813 ] |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 722 | env = {'TIMEZONE':'America/Los_Angeles', |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 723 | 'DEBUG': 'true', 'cert_password':'whatever', 'primary_shared_secret':'radius_password' |
| 724 | } |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 725 | 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] | 726 | guest_db_dir = os.path.join(os.path.sep, 'opt', 'db') |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 727 | 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] | 728 | guest_config_dir = os.path.join(os.path.sep, 'etc', 'freeradius') |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 729 | start_command = os.path.join(guest_config_dir, 'start-radius.py') |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 730 | host_guest_map = ( (host_db_dir, guest_db_dir), |
| 731 | (host_config_dir, guest_config_dir) |
| 732 | ) |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 733 | IMAGE = 'cord-test/radius' |
| 734 | NAME = 'cord-radius' |
| 735 | |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 736 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate', |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 737 | boot_delay = 10, restart = False, update = False): |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 738 | 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] | 739 | if update is True or not self.img_exists(): |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 740 | self.build_image(self.image_name) |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 741 | if restart is True and self.exists(): |
| 742 | self.kill() |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 743 | if not self.exists(): |
| 744 | self.remove_container(name, force=True) |
| 745 | host_config = self.create_host_config(port_list = self.ports, |
| 746 | host_guest_map = self.host_guest_map) |
| 747 | volumes = [] |
| 748 | for _,g in self.host_guest_map: |
| 749 | volumes.append(g) |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 750 | self.start(ports = self.ports, environment = self.env, |
| 751 | volumes = volumes, |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 752 | host_config = host_config, tty = True) |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 753 | time.sleep(boot_delay) |
| 754 | |
| 755 | @classmethod |
| 756 | def build_image(cls, image): |
| 757 | print('Building Radius image %s' %image) |
| 758 | dockerfile = ''' |
| 759 | FROM hbouvier/docker-radius |
| 760 | MAINTAINER chetan@ciena.com |
| 761 | LABEL RUN docker pull hbouvier/docker-radius |
| 762 | LABEL RUN docker run -it --name cord-radius hbouvier/docker-radius |
A R Karthick | c762df4 | 2016-05-25 10:09:21 -0700 | [diff] [blame] | 763 | RUN apt-get update && \ |
| 764 | apt-get -y install python python-pexpect strace |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 765 | WORKDIR /root |
| 766 | CMD ["/etc/freeradius/start-radius.py"] |
| 767 | ''' |
| 768 | super(Radius, cls).build_image(dockerfile, image) |
| 769 | print('Done building image %s' %image) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 770 | |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 771 | class Quagga(Container): |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 772 | QUAGGA_CONFIG = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 }, |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 773 | { 'bridge' : 'quagga-br', 'ip': '192.168.10.3', 'mask': 16 }, |
| 774 | ) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 775 | ports = [ 179, 2601, 2602, 2603, 2604, 2605, 2606 ] |
| 776 | host_quagga_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/quagga-config') |
| 777 | guest_quagga_config = '/root/config' |
| 778 | quagga_config_file = os.path.join(guest_quagga_config, 'testrib.conf') |
| 779 | host_guest_map = ( (host_quagga_config, guest_quagga_config), ) |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 780 | IMAGE = 'cord-test/quagga' |
| 781 | NAME = 'cord-quagga' |
| 782 | |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 783 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate', |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 784 | boot_delay = 15, restart = False, config_file = quagga_config_file, update = False): |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 785 | 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] | 786 | if update is True or not self.img_exists(): |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 787 | self.build_image(self.image_name) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 788 | if restart is True and self.exists(): |
| 789 | self.kill() |
| 790 | if not self.exists(): |
| 791 | self.remove_container(name, force=True) |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 792 | host_config = self.create_host_config(port_list = self.ports, |
| 793 | host_guest_map = self.host_guest_map, |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 794 | privileged = True) |
| 795 | volumes = [] |
| 796 | for _,g in self.host_guest_map: |
| 797 | volumes.append(g) |
| 798 | self.start(ports = self.ports, |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 799 | host_config = host_config, |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 800 | volumes = volumes, tty = True) |
| 801 | print('Starting Quagga on container %s' %self.name) |
| 802 | self.execute('{0}/start.sh {1}'.format(self.guest_quagga_config, config_file)) |
| 803 | time.sleep(boot_delay) |
| 804 | |
| 805 | @classmethod |
| 806 | def build_image(cls, image): |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 807 | onos_quagga_ip = Onos.QUAGGA_CONFIG[0]['ip'] |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 808 | print('Building Quagga image %s' %image) |
| 809 | dockerfile = ''' |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 810 | FROM ubuntu:14.04 |
| 811 | MAINTAINER chetan@ciena.com |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 812 | WORKDIR /root |
| 813 | RUN useradd -M quagga |
| 814 | RUN mkdir /var/log/quagga && chown quagga:quagga /var/log/quagga |
| 815 | RUN mkdir /var/run/quagga && chown quagga:quagga /var/run/quagga |
A R Karthick | 973ea69 | 2016-10-17 12:23:02 -0700 | [diff] [blame] | 816 | 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] | 817 | RUN git clone git://git.savannah.nongnu.org/quagga.git quagga && \ |
A R Karthick | 8f69c2c | 2016-10-21 11:43:26 -0700 | [diff] [blame] | 818 | (cd quagga && git checkout quagga-1.0.20160315 && ./bootstrap.sh && \ |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 819 | sed -i -r 's,htonl.*?\(INADDR_LOOPBACK\),inet_addr\("{0}"\),g' zebra/zebra_fpm.c && \ |
| 820 | ./configure --enable-fpm --disable-doc --localstatedir=/var/run/quagga && make && make install) |
| 821 | RUN ldconfig |
| 822 | '''.format(onos_quagga_ip) |
| 823 | super(Quagga, cls).build_image(dockerfile, image) |
| 824 | print('Done building image %s' %image) |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 825 | |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 826 | class QuaggaStopWrapper(Container): |
| 827 | def __init__(self, name = Quagga.NAME, image = Quagga.IMAGE, tag = 'candidate'): |
| 828 | super(QuaggaStopWrapper, self).__init__(name, image, prefix = Container.IMAGE_PREFIX, tag = tag) |
| 829 | if self.exists(): |
| 830 | self.kill() |
| 831 | |
| 832 | |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 833 | def reinitContainerClients(): |
| 834 | docker_netns.dckr = Client() |
| 835 | Container.dckr = Client() |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 836 | |
| 837 | class Xos(Container): |
| 838 | setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup') |
| 839 | TAG = 'latest' |
| 840 | PREFIX = '' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 841 | host_guest_map = None |
| 842 | env = None |
| 843 | ports = None |
| 844 | volumes = None |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 845 | |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 846 | @classmethod |
| 847 | def get_cmd(cls, img_name): |
| 848 | cmd = cls.dckr.inspect_image(img_name)['Config']['Cmd'] |
| 849 | return ' '.join(cmd) |
| 850 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 851 | def __init__(self, name, image, prefix = PREFIX, tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 852 | boot_delay = 20, restart = False, network_cfg = None, update = False): |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 853 | if restart is True: |
| 854 | ##Find the right image to restart |
| 855 | running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers()) |
| 856 | if running_image: |
| 857 | image_name = running_image[0]['Image'] |
| 858 | try: |
| 859 | image = image_name.split(':')[0] |
| 860 | tag = image_name.split(':')[1] |
| 861 | except: pass |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 862 | super(Xos, self).__init__(name, image, prefix = prefix, tag = tag) |
| 863 | if update is True or not self.img_exists(): |
| 864 | self.build_image(self.image_name) |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 865 | self.command = self.get_cmd(self.image_name).strip() or None |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 866 | if restart is True and self.exists(): |
| 867 | self.kill() |
| 868 | if not self.exists(): |
| 869 | self.remove_container(name, force=True) |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 870 | host_config = self.create_host_config(port_list = self.ports, |
| 871 | host_guest_map = self.host_guest_map, |
| 872 | privileged = True) |
| 873 | print('Starting XOS container %s' %self.name) |
| 874 | self.start(ports = self.ports, environment = self.env, host_config = host_config, |
| 875 | volumes = self.volumes, tty = True) |
| 876 | print('Waiting %d seconds for XOS Base Container to boot' %(boot_delay)) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 877 | time.sleep(boot_delay) |
| 878 | |
| 879 | @classmethod |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 880 | def build_image(cls, image, dockerfile_path, image_target = 'build'): |
| 881 | cmd = 'cd {} && make {}'.format(dockerfile_path, image_target) |
| 882 | print('Building XOS %s' %image) |
| 883 | res = os.system(cmd) |
| 884 | print('Done building image %s. Image build %s' %(image, 'successful' if res == 0 else 'failed')) |
| 885 | return res |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 886 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 887 | class XosServer(Xos): |
| 888 | ports = [8000,9998,9999] |
| 889 | NAME = 'xos-server' |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 890 | IMAGE = 'xosproject/xos' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 891 | BASE_IMAGE = 'xosproject/xos-base' |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 892 | TAG = 'latest' |
| 893 | PREFIX = '' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 894 | dockerfile_path = os.path.join(Xos.setup_dir, 'xos') |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 895 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 896 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 897 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 898 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 899 | |
| 900 | @classmethod |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 901 | def build_image(cls, image = IMAGE): |
| 902 | ##build the base image and then build the server image |
| 903 | Xos.build_image(cls.BASE_IMAGE, cls.dockerfile_path, image_target = 'base') |
| 904 | Xos.build_image(image, cls.dockerfile_path) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 905 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 906 | class XosSynchronizerOpenstack(Xos): |
| 907 | ports = [2375,] |
| 908 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer') |
| 909 | NAME = 'xos-synchronizer' |
| 910 | IMAGE = 'xosproject/xos-synchronizer-openstack' |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 911 | TAG = 'latest' |
| 912 | PREFIX = '' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 913 | host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 914 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 915 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 916 | 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] | 917 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 918 | |
| 919 | @classmethod |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 920 | def build_image(cls, image = IMAGE): |
| 921 | XosServer.build_image() |
| 922 | Xos.build_image(image, cls.dockerfile_path) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 923 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 924 | class XosSynchronizerOnboarding(Xos): |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 925 | NAME = 'xos-synchronizer-onboarding' |
| 926 | IMAGE = 'xosproject/xos-synchronizer-onboarding' |
| 927 | TAG = 'latest' |
| 928 | PREFIX = '' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 929 | dockerfile_path = os.path.join(Xos.setup_dir, 'onboarding_synchronizer') |
| 930 | host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 931 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 932 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 933 | 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] | 934 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 935 | |
| 936 | @classmethod |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 937 | def build_image(cls, image = IMAGE): |
| 938 | XosSynchronizerOpenstack.build_image() |
| 939 | Xos.build_image(image, cls.dockerfile_path) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 940 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 941 | class XosSynchronizerOpenvpn(Xos): |
| 942 | NAME = 'xos-synchronizer-openvpn' |
| 943 | IMAGE = 'xosproject/xos-openvpn' |
| 944 | TAG = 'latest' |
| 945 | PREFIX = '' |
| 946 | dockerfile_path = os.path.join(Xos.setup_dir, 'openvpn') |
| 947 | host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 948 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 949 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 950 | 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] | 951 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 952 | |
| 953 | @classmethod |
| 954 | def build_image(cls, image = IMAGE): |
| 955 | XosSynchronizerOpenstack.build_image() |
| 956 | Xos.build_image(image, cls.dockerfile_path) |
| 957 | |
| 958 | class XosPostgresql(Xos): |
| 959 | ports = [5432,] |
| 960 | NAME = 'xos-db-postgres' |
| 961 | IMAGE = 'xosproject/xos-postgres' |
| 962 | TAG = 'latest' |
| 963 | PREFIX = '' |
| 964 | volumes = ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"] |
| 965 | dockerfile_path = os.path.join(Xos.setup_dir, 'postgresql') |
| 966 | |
| 967 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 968 | 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] | 969 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 970 | |
| 971 | @classmethod |
| 972 | def build_image(cls, image = IMAGE): |
| 973 | Xos.build_image(image, cls.dockerfile_path) |
| 974 | |
| 975 | class XosSyndicateMs(Xos): |
| 976 | ports = [8080,] |
| 977 | env = None |
| 978 | NAME = 'xos-syndicate-ms' |
| 979 | IMAGE = 'xosproject/syndicate-ms' |
| 980 | TAG = 'latest' |
| 981 | PREFIX = '' |
| 982 | dockerfile_path = os.path.join(Xos.setup_dir, 'syndicate-ms') |
| 983 | |
| 984 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 985 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 986 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 987 | |
| 988 | @classmethod |
| 989 | def build_image(cls, image = IMAGE): |
| 990 | Xos.build_image(image, cls.dockerfile_path) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 991 | |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 992 | class XosSyncVtn(Xos): |
| 993 | ports = [8080,] |
| 994 | env = None |
| 995 | NAME = 'xos-synchronizer-vtn' |
| 996 | IMAGE = 'xosproject/xos-synchronizer-vtn' |
| 997 | TAG = 'latest' |
| 998 | PREFIX = '' |
| 999 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtn') |
| 1000 | |
| 1001 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1002 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1003 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1004 | |
| 1005 | @classmethod |
| 1006 | def build_image(cls, image = IMAGE): |
| 1007 | Xos.build_image(image, cls.dockerfile_path) |
| 1008 | |
| 1009 | class XosSyncVtr(Xos): |
| 1010 | ports = [8080,] |
| 1011 | env = None |
| 1012 | NAME = 'xos-synchronizer-vtr' |
| 1013 | IMAGE = 'xosproject/xos-synchronizer-vtr' |
| 1014 | TAG = 'latest' |
| 1015 | PREFIX = '' |
| 1016 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtr') |
| 1017 | |
| 1018 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1019 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1020 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1021 | |
| 1022 | @classmethod |
| 1023 | def build_image(cls, image = IMAGE): |
| 1024 | Xos.build_image(image, cls.dockerfile_path) |
| 1025 | |
| 1026 | class XosSyncVsg(Xos): |
| 1027 | ports = [8080,] |
| 1028 | env = None |
| 1029 | NAME = 'xos-synchronizer-vsg' |
| 1030 | IMAGE = 'xosproject/xos-synchronizer-vsg' |
| 1031 | TAG = 'latest' |
| 1032 | PREFIX = '' |
| 1033 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vsg') |
| 1034 | |
| 1035 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1036 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1037 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1038 | |
| 1039 | @classmethod |
| 1040 | def build_image(cls, image = IMAGE): |
| 1041 | Xos.build_image(image, cls.dockerfile_path) |
| 1042 | |
| 1043 | |
| 1044 | class XosSyncOnos(Xos): |
| 1045 | ports = [8080,] |
| 1046 | env = None |
| 1047 | NAME = 'xos-synchronizer-onos' |
| 1048 | IMAGE = 'xosproject/xos-synchronizer-onos' |
| 1049 | TAG = 'latest' |
| 1050 | PREFIX = '' |
| 1051 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-onos') |
| 1052 | |
| 1053 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1054 | boot_delay = 30, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1055 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1056 | |
| 1057 | @classmethod |
| 1058 | def build_image(cls, image = IMAGE): |
| 1059 | Xos.build_image(image, cls.dockerfile_path) |
| 1060 | |
| 1061 | class XosSyncFabric(Xos): |
| 1062 | ports = [8080,] |
| 1063 | env = None |
| 1064 | NAME = 'xos-synchronizer-fabric' |
| 1065 | IMAGE = 'xosproject/xos-synchronizer-fabric' |
| 1066 | TAG = 'latest' |
| 1067 | PREFIX = '' |
| 1068 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-fabric') |
| 1069 | |
| 1070 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1071 | boot_delay = 30, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1072 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1073 | |
| 1074 | @classmethod |
| 1075 | def build_image(cls, image = IMAGE): |
| 1076 | Xos.build_image(image, cls.dockerfile_path) |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 1077 | |
| 1078 | if __name__ == '__main__': |
| 1079 | onos = Onos(boot_delay = 10, restart = True) |