blob: 24aa6b538e4e0d39796d0045942c0a82a5b335ea [file] [log] [blame]
A R Karthick41adfce2016-06-10 09:51:25 -07001#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07002# 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 Karthick41adfce2016-06-10 09:51:25 -07007#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07008# http://www.apache.org/licenses/LICENSE-2.0
A R Karthick41adfce2016-06-10 09:51:25 -07009#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070010# 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 Gaonker3533faa2016-04-25 17:50:14 -070016import os,time
17import io
18import json
A R Karthickd44cea12016-07-20 12:16:41 -070019import yaml
A.R Karthickc4e474d2016-12-12 15:24:57 -080020import errno
Chetan Gaonker3533faa2016-04-25 17:50:14 -070021from pyroute2 import IPRoute
A.R Karthickc4e474d2016-12-12 15:24:57 -080022from pyroute2.netlink import NetlinkError
Chetan Gaonker3533faa2016-04-25 17:50:14 -070023from itertools import chain
24from nsenter import Namespace
25from docker import Client
A R Karthickec2db322016-11-17 15:06:01 -080026from shutil import rmtree
A.R Karthick95d044e2016-06-10 18:44:36 -070027from OnosCtrl import OnosCtrl
A R Karthick19aaf5c2016-11-09 17:47:57 -080028from OnosLog import OnosLog
A.R Karthickc4e474d2016-12-12 15:24:57 -080029from threadPool import ThreadPool
Chetan Gaonker3533faa2016-04-25 17:50:14 -070030
31class docker_netns(object):
32
33 dckr = Client()
34 def __init__(self, name):
35 pid = int(self.dckr.inspect_container(name)['State']['Pid'])
36 if pid == 0:
37 raise Exception('no container named {0}'.format(name))
38 self.pid = pid
39
40 def __enter__(self):
41 pid = self.pid
42 if not os.path.exists('/var/run/netns'):
43 os.mkdir('/var/run/netns')
44 os.symlink('/proc/{0}/ns/net'.format(pid), '/var/run/netns/{0}'.format(pid))
45 return str(pid)
46
47 def __exit__(self, type, value, traceback):
48 pid = self.pid
49 os.unlink('/var/run/netns/{0}'.format(pid))
50
51flatten = lambda l: chain.from_iterable(l)
52
53class Container(object):
54 dckr = Client()
A R Karthick07608ef2016-08-23 16:51:19 -070055 IMAGE_PREFIX = '' ##for saving global prefix for all test classes
56
57 def __init__(self, name, image, prefix='', tag = 'candidate', command = 'bash', quagga_config = None):
Chetan Gaonker3533faa2016-04-25 17:50:14 -070058 self.name = name
A R Karthick07608ef2016-08-23 16:51:19 -070059 self.prefix = prefix
60 if prefix:
61 self.prefix += '/'
62 image = '{}{}'.format(self.prefix, image)
Chetan Gaonker3533faa2016-04-25 17:50:14 -070063 self.image = image
64 self.tag = tag
A R Karthickd44cea12016-07-20 12:16:41 -070065 if tag:
66 self.image_name = image + ':' + tag
67 else:
68 self.image_name = image
Chetan Gaonker3533faa2016-04-25 17:50:14 -070069 self.id = None
70 self.command = command
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -070071 self.quagga_config = quagga_config
Chetan Gaonker3533faa2016-04-25 17:50:14 -070072
73 @classmethod
74 def build_image(cls, dockerfile, tag, force=True, nocache=False):
75 f = io.BytesIO(dockerfile.encode('utf-8'))
76 if force or not cls.image_exists(tag):
77 print('Build {0}...'.format(tag))
78 for line in cls.dckr.build(fileobj=f, rm=True, tag=tag, decode=True, nocache=nocache):
79 if 'stream' in line:
80 print(line['stream'].strip())
81
82 @classmethod
83 def image_exists(cls, name):
84 return name in [ctn['RepoTags'][0] for ctn in cls.dckr.images()]
85
86 @classmethod
87 def create_host_config(cls, port_list = None, host_guest_map = None, privileged = False):
88 port_bindings = None
89 binds = None
90 if port_list:
91 port_bindings = {}
92 for p in port_list:
93 port_bindings[str(p)] = str(p)
94
95 if host_guest_map:
96 binds = []
97 for h, g in host_guest_map:
98 binds.append('{0}:{1}'.format(h, g))
99
100 return cls.dckr.create_host_config(binds = binds, port_bindings = port_bindings, privileged = privileged)
101
102 @classmethod
103 def cleanup(cls, image):
A R Karthick09b1f4e2016-05-12 14:31:50 -0700104 cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers(all=True))
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700105 for cnt in cnt_list:
106 print('Cleaning container %s' %cnt['Id'])
A.R Karthick95d044e2016-06-10 18:44:36 -0700107 if cnt.has_key('State') and cnt['State'] == 'running':
A R Karthick09b1f4e2016-05-12 14:31:50 -0700108 cls.dckr.kill(cnt['Id'])
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700109 cls.dckr.remove_container(cnt['Id'], force=True)
110
111 @classmethod
112 def remove_container(cls, name, force=True):
113 try:
114 cls.dckr.remove_container(name, force = force)
115 except: pass
116
117 def exists(self):
118 return '/{0}'.format(self.name) in list(flatten(n['Names'] for n in self.dckr.containers()))
119
120 def img_exists(self):
A R Karthick6d98a592016-08-24 15:16:46 -0700121 return self.image_name in [ctn['RepoTags'][0] if ctn['RepoTags'] else '' for ctn in self.dckr.images()]
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700122
123 def ip(self):
A R Karthick2b93d6a2016-09-06 15:19:09 -0700124 cnt_list = filter(lambda c: c['Names'][0] == '/{}'.format(self.name), self.dckr.containers())
125 #if not cnt_list:
126 # cnt_list = filter(lambda c: c['Image'] == self.image_name, self.dckr.containers())
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700127 cnt_settings = cnt_list.pop()
128 return cnt_settings['NetworkSettings']['Networks']['bridge']['IPAddress']
129
A R Karthick2b93d6a2016-09-06 15:19:09 -0700130 @classmethod
131 def ips(cls, image_name):
132 cnt_list = filter(lambda c: c['Image'] == image_name, cls.dckr.containers())
133 ips = [ cnt['NetworkSettings']['Networks']['bridge']['IPAddress'] for cnt in cnt_list ]
134 return ips
135
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700136 def kill(self, remove = True):
137 self.dckr.kill(self.name)
138 self.dckr.remove_container(self.name, force=True)
139
A R Karthick41adfce2016-06-10 09:51:25 -0700140 def start(self, rm = True, ports = None, volumes = None, host_config = None,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700141 environment = None, tty = False, stdin_open = True):
142
143 if rm and self.exists():
144 print('Removing container:', self.name)
145 self.dckr.remove_container(self.name, force=True)
146
A R Karthick41adfce2016-06-10 09:51:25 -0700147 ctn = self.dckr.create_container(image=self.image_name, ports = ports, command=self.command,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700148 detach=True, name=self.name,
A R Karthick41adfce2016-06-10 09:51:25 -0700149 environment = environment,
150 volumes = volumes,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700151 host_config = host_config, stdin_open=stdin_open, tty = tty)
152 self.dckr.start(container=self.name)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700153 if self.quagga_config:
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700154 self.connect_to_br()
155 self.id = ctn['Id']
156 return ctn
157
158 def connect_to_br(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700159 index = 0
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700160 with docker_netns(self.name) as pid:
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700161 for quagga_config in self.quagga_config:
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700162 ip = IPRoute()
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700163 br = ip.link_lookup(ifname=quagga_config['bridge'])
164 if len(br) == 0:
A.R Karthickc4e474d2016-12-12 15:24:57 -0800165 try:
166 ip.link_create(ifname=quagga_config['bridge'], kind='bridge')
167 except NetlinkError as e:
168 err, _ = e.args
169 if err == errno.EEXIST:
170 pass
171 else:
172 raise NetlinkError(*e.args)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700173 br = ip.link_lookup(ifname=quagga_config['bridge'])
174 br = br[0]
175 ip.link('set', index=br, state='up')
176 ifname = '{0}-{1}'.format(self.name, index)
177 ifs = ip.link_lookup(ifname=ifname)
178 if len(ifs) > 0:
179 ip.link_remove(ifs[0])
180 peer_ifname = '{0}-{1}'.format(pid, index)
Chetan Gaonker5a0fda32016-05-10 14:09:07 -0700181 ip.link_create(ifname=ifname, kind='veth', peer=peer_ifname)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700182 host = ip.link_lookup(ifname=ifname)[0]
183 ip.link('set', index=host, master=br)
184 ip.link('set', index=host, state='up')
185 guest = ip.link_lookup(ifname=peer_ifname)[0]
186 ip.link('set', index=guest, net_ns_fd=pid)
187 with Namespace(pid, 'net'):
188 ip = IPRoute()
189 ip.link('set', index=guest, ifname='eth{}'.format(index+1))
190 ip.addr('add', index=guest, address=quagga_config['ip'], mask=quagga_config['mask'])
191 ip.link('set', index=guest, state='up')
192 index += 1
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700193
A.R Karthicke4631062016-11-03 14:28:19 -0700194 def execute(self, cmd, tty = True, stream = False, shell = False):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700195 res = 0
196 if type(cmd) == str:
197 cmds = (cmd,)
198 else:
199 cmds = cmd
200 if shell:
201 for c in cmds:
202 res += os.system('docker exec {0} {1}'.format(self.name, c))
203 return res
204 for c in cmds:
205 i = self.dckr.exec_create(container=self.name, cmd=c, tty = tty, privileged = True)
206 self.dckr.exec_start(i['Id'], stream = stream, detach=True)
207 result = self.dckr.exec_inspect(i['Id'])
208 res += 0 if result['ExitCode'] == None else result['ExitCode']
209 return res
210
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700211 def restart(self, timeout =10):
212 return self.dckr.restart(self.name, timeout)
213
A R Karthick1f908202016-11-16 17:32:20 -0800214def get_mem(instances = 1):
215 if instances <= 0:
216 instances = 1
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700217 with open('/proc/meminfo', 'r') as fd:
218 meminfo = fd.readlines()
219 mem = 0
220 for m in meminfo:
221 if m.startswith('MemTotal:') or m.startswith('SwapTotal:'):
222 mem += int(m.split(':')[1].strip().split()[0])
223
A R Karthick1f908202016-11-16 17:32:20 -0800224 mem = max(mem/1024/1024/2/instances, 1)
Chetan Gaonker6d0a7b02016-05-03 16:57:28 -0700225 mem = min(mem, 16)
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700226 return str(mem) + 'G'
227
A R Karthickd44cea12016-07-20 12:16:41 -0700228class OnosCord(Container):
229 """Use this when running the cord tester agent on the onos compute node"""
230 onos_cord_dir = os.path.join(os.getenv('HOME'), 'cord-tester-cord')
231 onos_config_dir_guest = '/root/onos/config'
232 onos_config_dir = os.path.join(onos_cord_dir, 'config')
233 docker_yaml = os.path.join(onos_cord_dir, 'docker-compose.yml')
234
A R Karthickbd9b8a32016-07-21 09:56:45 -0700235 def __init__(self, onos_ip, conf, boot_delay = 60):
236 self.onos_ip = onos_ip
A R Karthickd44cea12016-07-20 12:16:41 -0700237 self.cord_conf_dir = conf
A R Karthickbd9b8a32016-07-21 09:56:45 -0700238 self.boot_delay = boot_delay
A R Karthickd44cea12016-07-20 12:16:41 -0700239 if os.access(self.cord_conf_dir, os.F_OK) and not os.access(self.onos_cord_dir, os.F_OK):
240 os.mkdir(self.onos_cord_dir)
241 os.mkdir(self.onos_config_dir)
242 ##copy the config file from cord-tester-config
243 cmd = 'cp {}/* {}'.format(self.cord_conf_dir, self.onos_cord_dir)
244 os.system(cmd)
245
246 ##update the docker yaml with the config volume
247 with open(self.docker_yaml, 'r') as f:
248 yaml_config = yaml.load(f)
249 image = yaml_config['services'].keys()[0]
250 name = 'cordtestercord_{}_1'.format(image)
251 volumes = yaml_config['services'][image]['volumes']
252 config_volumes = filter(lambda e: e.find(self.onos_config_dir_guest) >= 0, volumes)
253 if not config_volumes:
254 config_volume = '{}:{}'.format(self.onos_config_dir, self.onos_config_dir_guest)
255 volumes.append(config_volume)
256 docker_yaml_changed = '{}-changed'.format(self.docker_yaml)
257 with open(docker_yaml_changed, 'w') as wf:
258 yaml.dump(yaml_config, wf)
259
260 os.rename(docker_yaml_changed, self.docker_yaml)
261 self.volumes = volumes
262
263 super(OnosCord, self).__init__(name, image, tag = '')
264 cord_conf_dir_basename = os.path.basename(self.cord_conf_dir.replace('-', ''))
265 self.xos_onos_name = '{}_{}_1'.format(cord_conf_dir_basename, image)
266 ##Create an container instance of xos onos
267 self.xos_onos = Container(self.xos_onos_name, image, tag = '')
268
269 def start(self, restart = False, network_cfg = None):
270 if restart is True:
271 if self.exists():
272 ##Kill the existing instance
273 print('Killing container %s' %self.name)
274 self.kill()
275 if self.xos_onos.exists():
276 print('Killing container %s' %self.xos_onos.name)
277 self.xos_onos.kill()
278
279 if network_cfg is not None:
280 json_data = json.dumps(network_cfg, indent=4)
281 with open('{}/network-cfg.json'.format(self.onos_config_dir), 'w') as f:
282 f.write(json_data)
283
284 #start the container using docker-compose
285 cmd = 'cd {} && docker-compose up -d'.format(self.onos_cord_dir)
286 os.system(cmd)
A R Karthickbd9b8a32016-07-21 09:56:45 -0700287 #Delay to make sure ONOS fully boots
288 time.sleep(self.boot_delay)
289 Onos.install_cord_apps(onos_ip = self.onos_ip)
A R Karthickd44cea12016-07-20 12:16:41 -0700290
291 def build_image(self):
292 build_cmd = 'cd {} && docker-compose build'.format(self.onos_cord_dir)
293 os.system(build_cmd)
294
A.R Karthick1700e0e2016-10-06 18:16:57 -0700295class OnosCordStopWrapper(Container):
296 onos_cord_dir = os.path.join(os.getenv('HOME'), 'cord-tester-cord')
297 docker_yaml = os.path.join(onos_cord_dir, 'docker-compose.yml')
298
299 def __init__(self):
300 if os.access(self.docker_yaml, os.F_OK):
301 with open(self.docker_yaml, 'r') as f:
302 yaml_config = yaml.load(f)
303 image = yaml_config['services'].keys()[0]
304 name = 'cordtestercord_{}_1'.format(image)
305 super(OnosCordStopWrapper, self).__init__(name, image, tag = '')
306 if self.exists():
307 print('Killing container %s' %self.name)
308 self.kill()
309
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700310class Onos(Container):
311
A.R Karthickc4e474d2016-12-12 15:24:57 -0800312 quagga_config = [ { 'bridge' : 'quagga-br', 'ip': '10.10.0.4', 'mask' : 16 }, ]
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700313 SYSTEM_MEMORY = (get_mem(),) * 2
A R Karthick1f908202016-11-16 17:32:20 -0800314 INSTANCE_MEMORY = (get_mem(instances=3),) * 2
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700315 JAVA_OPTS = '-Xms{} -Xmx{} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode'.format(*SYSTEM_MEMORY)#-XX:+PrintGCDetails -XX:+PrintGCTimeStamps'
A R Karthick1f908202016-11-16 17:32:20 -0800316 JAVA_OPTS_CLUSTER = '-Xms{} -Xmx{} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode'.format(*INSTANCE_MEMORY)
A.R Karthick95d044e2016-06-10 18:44:36 -0700317 env = { 'ONOS_APPS' : 'drivers,openflow,proxyarp,vrouter', 'JAVA_OPTS' : JAVA_OPTS }
A.R Karthickdfeadb02016-11-30 17:55:51 -0800318 onos_cord_apps = ( ('cord-config', '1.1-SNAPSHOT'),
319 ('aaa', '1.1-SNAPSHOT'),
320 ('igmp', '1.1-SNAPSHOT'),
321 #('vtn', '1.1-SNAPSHOT'),
A.R Karthick95d044e2016-06-10 18:44:36 -0700322 )
A.R Karthickc4e474d2016-12-12 15:24:57 -0800323 ports = [] #[ 8181, 8101, 9876, 6653, 6633, 2000, 2620 ]
A R Karthickf2f4ca62016-08-17 10:34:08 -0700324 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
325 host_config_dir = os.path.join(setup_dir, 'onos-config')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700326 guest_config_dir = '/root/onos/config'
A R Karthickec2db322016-11-17 15:06:01 -0800327 guest_data_dir = '/root/onos/apache-karaf-3.0.5/data'
A R Karthickf2f4ca62016-08-17 10:34:08 -0700328 onos_gen_partitions = os.path.join(setup_dir, 'onos-gen-partitions')
A R Karthick2b93d6a2016-09-06 15:19:09 -0700329 onos_form_cluster = os.path.join(setup_dir, 'onos-form-cluster')
A.R Karthick95d044e2016-06-10 18:44:36 -0700330 cord_apps_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'apps')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700331 host_guest_map = ( (host_config_dir, guest_config_dir), )
A R Karthick2b93d6a2016-09-06 15:19:09 -0700332 cluster_cfg = os.path.join(host_config_dir, 'cluster.json')
333 cluster_mode = False
334 cluster_instances = []
Chetan Gaonker503032a2016-05-12 12:06:29 -0700335 NAME = 'cord-onos'
A R Karthickf2f4ca62016-08-17 10:34:08 -0700336 ##the ip of ONOS in default cluster.json in setup/onos-config
337 CLUSTER_CFG_IP = '172.17.0.2'
A R Karthick07608ef2016-08-23 16:51:19 -0700338 IMAGE = 'onosproject/onos'
339 TAG = 'latest'
340 PREFIX = ''
A R Karthickf2f4ca62016-08-17 10:34:08 -0700341
342 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700343 def generate_cluster_cfg(cls, ip):
344 if type(ip) in [ list, tuple ]:
345 ips = ' '.join(ip)
346 else:
347 ips = ip
A R Karthickf2f4ca62016-08-17 10:34:08 -0700348 try:
A R Karthick2b93d6a2016-09-06 15:19:09 -0700349 cmd = '{} {} {}'.format(cls.onos_gen_partitions, cls.cluster_cfg, ips)
350 os.system(cmd)
351 except: pass
352
353 @classmethod
354 def form_cluster(cls, ips):
355 nodes = ' '.join(ips)
356 try:
357 cmd = '{} {}'.format(cls.onos_form_cluster, nodes)
A R Karthickf2f4ca62016-08-17 10:34:08 -0700358 os.system(cmd)
359 except: pass
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700360
A R Karthick9d48c652016-09-15 09:16:36 -0700361 @classmethod
362 def cleanup_runtime(cls):
363 '''Cleanup ONOS runtime generated files'''
364 files = ( Onos.cluster_cfg, os.path.join(Onos.host_config_dir, 'network-cfg.json') )
365 for f in files:
366 if os.access(f, os.F_OK):
367 try:
368 os.unlink(f)
369 except: pass
370
A R Karthickec2db322016-11-17 15:06:01 -0800371 @classmethod
372 def get_data_map(cls, host_volume, guest_volume_dir):
373 host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume))
374 if not os.path.exists(host_volume_dir):
375 os.mkdir(host_volume_dir)
376 return ( (host_volume_dir, guest_volume_dir), )
377
378 @classmethod
379 def remove_data_map(cls, host_volume, guest_volume_dir):
380 host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume))
381 if os.path.exists(host_volume_dir):
382 rmtree(host_volume_dir)
383
384 def remove_data_volume(self):
385 if self.data_map is not None:
386 self.remove_data_map(*self.data_map)
387
A.R Karthick1700e0e2016-10-06 18:16:57 -0700388 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
A R Karthickec2db322016-11-17 15:06:01 -0800389 boot_delay = 20, restart = False, network_cfg = None,
A.R Karthickc4e474d2016-12-12 15:24:57 -0800390 cluster = False, data_volume = None, async = False, quagga_config = None):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700391 if restart is True:
392 ##Find the right image to restart
393 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
394 if running_image:
395 image_name = running_image[0]['Image']
396 try:
397 image = image_name.split(':')[0]
398 tag = image_name.split(':')[1]
399 except: pass
400
A.R Karthickc4e474d2016-12-12 15:24:57 -0800401 if quagga_config is not None:
402 self.quagga_config = quagga_config
A R Karthick07608ef2016-08-23 16:51:19 -0700403 super(Onos, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.quagga_config)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700404 self.boot_delay = boot_delay
A R Karthickec2db322016-11-17 15:06:01 -0800405 self.data_map = None
A R Karthick2b93d6a2016-09-06 15:19:09 -0700406 if cluster is True:
407 self.ports = []
A R Karthick1f908202016-11-16 17:32:20 -0800408 self.env['JAVA_OPTS'] = self.JAVA_OPTS_CLUSTER
A R Karthickec2db322016-11-17 15:06:01 -0800409 if data_volume is not None:
410 self.data_map = self.get_data_map(data_volume, self.guest_data_dir)
411 self.host_guest_map = self.host_guest_map + self.data_map
A R Karthick2b93d6a2016-09-06 15:19:09 -0700412 if os.access(self.cluster_cfg, os.F_OK):
413 try:
414 os.unlink(self.cluster_cfg)
415 except: pass
416
417 self.host_config = self.create_host_config(port_list = self.ports,
418 host_guest_map = self.host_guest_map)
419 self.volumes = []
420 for _,g in self.host_guest_map:
421 self.volumes.append(g)
422
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700423 if restart is True and self.exists():
424 self.kill()
A R Karthick2b93d6a2016-09-06 15:19:09 -0700425
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700426 if not self.exists():
427 self.remove_container(name, force=True)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700428 host_config = self.create_host_config(port_list = self.ports,
429 host_guest_map = self.host_guest_map)
430 volumes = []
431 for _,g in self.host_guest_map:
432 volumes.append(g)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700433 if network_cfg is not None:
A R Karthick81acbff2016-06-17 14:45:16 -0700434 json_data = json.dumps(network_cfg, indent=4)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700435 with open('{}/network-cfg.json'.format(self.host_config_dir), 'w') as f:
436 f.write(json_data)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800437 if cluster is False or async is False:
438 print('Starting ONOS container %s' %self.name)
439 self.start(ports = self.ports, environment = self.env,
440 host_config = self.host_config, volumes = self.volumes, tty = True)
441 if not restart:
442 ##wait a bit before fetching IP to regenerate cluster cfg
443 time.sleep(5)
444 ip = self.ip()
445 ##Just a quick hack/check to ensure we don't regenerate in the common case.
446 ##As ONOS is usually the first test container that is started
447 if cluster is False:
448 if ip != self.CLUSTER_CFG_IP or not os.access(self.cluster_cfg, os.F_OK):
449 print('Regenerating ONOS cluster cfg for ip %s' %ip)
450 self.generate_cluster_cfg(ip)
451 self.kill()
452 self.remove_container(self.name, force=True)
453 print('Restarting ONOS container %s' %self.name)
454 self.start(ports = self.ports, environment = self.env,
455 host_config = self.host_config, volumes = self.volumes, tty = True)
456 print('Waiting for ONOS to boot')
457 time.sleep(boot_delay)
458 self.wait_for_onos_start(self.ip())
459 self.running = True
460 else:
461 self.running = False
462 else:
463 self.running = True
464 if self.running:
465 self.ipaddr = self.ip()
466 if cluster is False:
467 self.install_cord_apps(self.ipaddr)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800468
A.R Karthickc4e474d2016-12-12 15:24:57 -0800469 @classmethod
470 def get_quagga_config(cls, instance = 0):
471 quagga_config = cls.quagga_config[:]
472 if instance == 0:
473 return quagga_config
474 ip = quagga_config[0]['ip']
475 octets = ip.split('.')
476 octets[3] = str((int(octets[3]) + 1) & 255)
477 ip = '.'.join(octets)
478 quagga_config[0]['ip'] = ip
479 return quagga_config
480
481 @classmethod
482 def start_cluster_async(cls, onos_instances):
483 instances = filter(lambda o: o.running == False, onos_instances)
484 if not instances:
485 return
486 tpool = ThreadPool(len(instances), queue_size = 1, wait_timeout = 1)
487 for onos in instances:
488 tpool.addTask(onos.start_async)
489 tpool.cleanUpThreads()
490
491 def start_async(self):
492 print('Starting ONOS container %s' %self.name)
493 self.start(ports = self.ports, environment = self.env,
494 host_config = self.host_config, volumes = self.volumes, tty = True)
495 time.sleep(3)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700496 self.ipaddr = self.ip()
A.R Karthickc4e474d2016-12-12 15:24:57 -0800497 print('Waiting for ONOS container %s to start' %self.name)
498 self.wait_for_onos_start(self.ipaddr)
499 self.running = True
500 print('ONOS container %s started' %self.name)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700501
A R Karthick2b93d6a2016-09-06 15:19:09 -0700502 @classmethod
A R Karthick19aaf5c2016-11-09 17:47:57 -0800503 def wait_for_onos_start(cls, ip, tries = 30):
504 onos_log = OnosLog(host = ip)
505 num_tries = 0
506 started = None
507 while not started and num_tries < tries:
508 time.sleep(3)
509 started = onos_log.search_log_pattern('ApplicationManager .* Started')
510 num_tries += 1
511
A R Karthick19aaf5c2016-11-09 17:47:57 -0800512 if not started:
513 print('ONOS did not start')
514 else:
515 print('ONOS started')
516 return started
517
518 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700519 def setup_cluster_deprecated(cls, onos_instances, image_name = None):
520 if not onos_instances or len(onos_instances) < 2:
521 return
522 ips = []
523 if image_name is not None:
524 ips = Container.ips(image_name)
525 else:
526 for onos in onos_instances:
527 ips.append(onos.ipaddr)
528 Onos.cluster_instances = onos_instances
529 Onos.cluster_mode = True
530 ##regenerate the cluster json with the 3 instance ips before restarting them back
531 print('Generating cluster cfg for ONOS instances with ips %s' %ips)
532 Onos.generate_cluster_cfg(ips)
533 for onos in onos_instances:
534 onos.kill()
535 onos.remove_container(onos.name, force=True)
536 print('Restarting ONOS container %s for forming cluster' %onos.name)
537 onos.start(ports = onos.ports, environment = onos.env,
538 host_config = onos.host_config, volumes = onos.volumes, tty = True)
539 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
540 time.sleep(onos.boot_delay)
541 onos.ipaddr = onos.ip()
542 onos.install_cord_apps(onos.ipaddr)
543
544 @classmethod
545 def setup_cluster(cls, onos_instances, image_name = None):
546 if not onos_instances or len(onos_instances) < 2:
547 return
548 ips = []
549 if image_name is not None:
550 ips = Container.ips(image_name)
551 else:
552 for onos in onos_instances:
553 ips.append(onos.ipaddr)
554 Onos.cluster_instances = onos_instances
555 Onos.cluster_mode = True
556 ##regenerate the cluster json with the 3 instance ips before restarting them back
557 print('Forming cluster for ONOS instances with ips %s' %ips)
558 Onos.form_cluster(ips)
559 ##wait for the cluster to be formed
560 print('Waiting for the cluster to be formed')
561 time.sleep(60)
562 for onos in onos_instances:
563 onos.install_cord_apps(onos.ipaddr)
564
565 @classmethod
A R Karthicke2c24bd2016-10-07 14:51:38 -0700566 def add_cluster(cls, count = 1, network_cfg = None):
567 if not cls.cluster_instances or Onos.cluster_mode is False:
568 return
569 for i in range(count):
570 name = '{}-{}'.format(Onos.NAME, len(cls.cluster_instances)+1)
571 onos = cls(name = name, image = Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX,
572 cluster = True, network_cfg = network_cfg)
573 cls.cluster_instances.append(onos)
574
575 cls.setup_cluster(cls.cluster_instances)
576
577 @classmethod
A.R Karthick2560f042016-11-30 14:38:52 -0800578 def restart_cluster(cls, network_cfg = None, timeout = 10, setup = False):
A R Karthick2b93d6a2016-09-06 15:19:09 -0700579 if cls.cluster_mode is False:
580 return
581 if not cls.cluster_instances:
582 return
583
584 if network_cfg is not None:
585 json_data = json.dumps(network_cfg, indent=4)
586 with open('{}/network-cfg.json'.format(cls.host_config_dir), 'w') as f:
587 f.write(json_data)
588
A.R Karthick2560f042016-11-30 14:38:52 -0800589 cls.cleanup_cluster()
590 if timeout > 0:
591 time.sleep(timeout)
592
A R Karthick2b93d6a2016-09-06 15:19:09 -0700593 for onos in cls.cluster_instances:
A R Karthick2b93d6a2016-09-06 15:19:09 -0700594 print('Restarting ONOS container %s' %onos.name)
595 onos.start(ports = onos.ports, environment = onos.env,
596 host_config = onos.host_config, volumes = onos.volumes, tty = True)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700597 onos.ipaddr = onos.ip()
A.R Karthick2560f042016-11-30 14:38:52 -0800598 onos.wait_for_onos_start(onos.ipaddr)
599 onos.install_cord_apps(onos.ipaddr)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700600
A.R Karthick2560f042016-11-30 14:38:52 -0800601 ##form the cluster as appropriate
602 if setup is True:
603 cls.setup_cluster(cls.cluster_instances)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700604
605 @classmethod
606 def cluster_ips(cls):
607 if cls.cluster_mode is False:
608 return []
609 if not cls.cluster_instances:
610 return []
611 ips = [ onos.ipaddr for onos in cls.cluster_instances ]
612 return ips
613
614 @classmethod
615 def cleanup_cluster(cls):
616 if cls.cluster_mode is False:
617 return
618 if not cls.cluster_instances:
619 return
620 for onos in cls.cluster_instances:
621 if onos.exists():
622 onos.kill()
623 onos.remove_container(onos.name, force=True)
A R Karthickd44cea12016-07-20 12:16:41 -0700624
A.R Karthick95d044e2016-06-10 18:44:36 -0700625 @classmethod
A R Karthickde6b9dc2016-11-29 17:46:16 -0800626 def restart_node(cls, node = None, network_cfg = None, timeout = 10):
A R Karthick889d9652016-10-03 14:13:45 -0700627 if node is None:
628 cls(restart = True, network_cfg = network_cfg, image = cls.IMAGE, tag = cls.TAG)
629 else:
630 #Restarts a node in the cluster
631 valid_node = filter(lambda onos: node in [ onos.ipaddr, onos.name ], cls.cluster_instances)
632 if valid_node:
633 onos = valid_node.pop()
634 if onos.exists():
635 onos.kill()
636 onos.remove_container(onos.name, force=True)
A R Karthickde6b9dc2016-11-29 17:46:16 -0800637 if timeout > 0:
638 time.sleep(timeout)
A R Karthick889d9652016-10-03 14:13:45 -0700639 print('Restarting ONOS container %s' %onos.name)
640 onos.start(ports = onos.ports, environment = onos.env,
641 host_config = onos.host_config, volumes = onos.volumes, tty = True)
A R Karthick889d9652016-10-03 14:13:45 -0700642 onos.ipaddr = onos.ip()
A.R Karthick2560f042016-11-30 14:38:52 -0800643 onos.wait_for_onos_start(onos.ipaddr)
644 onos.install_cord_apps(onos.ipaddr)
A R Karthick889d9652016-10-03 14:13:45 -0700645
646 @classmethod
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700647 def install_cord_apps(cls, onos_ip = None):
A.R Karthick95d044e2016-06-10 18:44:36 -0700648 for app, version in cls.onos_cord_apps:
649 app_file = '{}/{}-{}.oar'.format(cls.cord_apps_dir, app, version)
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700650 ok, code = OnosCtrl.install_app(app_file, onos_ip = onos_ip)
A.R Karthick95d044e2016-06-10 18:44:36 -0700651 ##app already installed (conflicts)
652 if code in [ 409 ]:
653 ok = True
654 print('ONOS app %s, version %s %s' %(app, version, 'installed' if ok else 'failed to install'))
655 time.sleep(2)
656
A.R Karthick1700e0e2016-10-06 18:16:57 -0700657class OnosStopWrapper(Container):
658 def __init__(self, name):
659 super(OnosStopWrapper, self).__init__(name, Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX)
660 if self.exists():
661 self.kill()
662 else:
663 if Onos.cluster_mode is True:
664 valid_node = filter(lambda onos: name in [ onos.ipaddr, onos.name ], Onos.cluster_instances)
665 if valid_node:
666 onos = valid_node.pop()
667 if onos.exists():
668 onos.kill()
669
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700670class Radius(Container):
671 ports = [ 1812, 1813 ]
A R Karthick41adfce2016-06-10 09:51:25 -0700672 env = {'TIMEZONE':'America/Los_Angeles',
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700673 'DEBUG': 'true', 'cert_password':'whatever', 'primary_shared_secret':'radius_password'
674 }
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700675 host_db_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/db')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700676 guest_db_dir = os.path.join(os.path.sep, 'opt', 'db')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700677 host_config_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/freeradius')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700678 guest_config_dir = os.path.join(os.path.sep, 'etc', 'freeradius')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700679 start_command = os.path.join(guest_config_dir, 'start-radius.py')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700680 host_guest_map = ( (host_db_dir, guest_db_dir),
681 (host_config_dir, guest_config_dir)
682 )
Chetan Gaonker503032a2016-05-12 12:06:29 -0700683 IMAGE = 'cord-test/radius'
684 NAME = 'cord-radius'
685
A R Karthick07608ef2016-08-23 16:51:19 -0700686 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
Chetan Gaonker503032a2016-05-12 12:06:29 -0700687 boot_delay = 10, restart = False, update = False):
A R Karthick07608ef2016-08-23 16:51:19 -0700688 super(Radius, self).__init__(name, image, prefix = prefix, tag = tag, command = self.start_command)
Chetan Gaonker503032a2016-05-12 12:06:29 -0700689 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -0700690 self.build_image(self.image_name)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700691 if restart is True and self.exists():
692 self.kill()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700693 if not self.exists():
694 self.remove_container(name, force=True)
695 host_config = self.create_host_config(port_list = self.ports,
696 host_guest_map = self.host_guest_map)
697 volumes = []
698 for _,g in self.host_guest_map:
699 volumes.append(g)
A R Karthick41adfce2016-06-10 09:51:25 -0700700 self.start(ports = self.ports, environment = self.env,
701 volumes = volumes,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700702 host_config = host_config, tty = True)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700703 time.sleep(boot_delay)
704
705 @classmethod
706 def build_image(cls, image):
707 print('Building Radius image %s' %image)
708 dockerfile = '''
709FROM hbouvier/docker-radius
710MAINTAINER chetan@ciena.com
711LABEL RUN docker pull hbouvier/docker-radius
712LABEL RUN docker run -it --name cord-radius hbouvier/docker-radius
A R Karthickc762df42016-05-25 10:09:21 -0700713RUN apt-get update && \
714 apt-get -y install python python-pexpect strace
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700715WORKDIR /root
716CMD ["/etc/freeradius/start-radius.py"]
717'''
718 super(Radius, cls).build_image(dockerfile, image)
719 print('Done building image %s' %image)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700720
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700721class Quagga(Container):
A R Karthick41adfce2016-06-10 09:51:25 -0700722 quagga_config = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 },
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700723 { 'bridge' : 'quagga-br', 'ip': '192.168.10.3', 'mask': 16 },
724 )
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700725 ports = [ 179, 2601, 2602, 2603, 2604, 2605, 2606 ]
726 host_quagga_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/quagga-config')
727 guest_quagga_config = '/root/config'
728 quagga_config_file = os.path.join(guest_quagga_config, 'testrib.conf')
729 host_guest_map = ( (host_quagga_config, guest_quagga_config), )
Chetan Gaonker503032a2016-05-12 12:06:29 -0700730 IMAGE = 'cord-test/quagga'
731 NAME = 'cord-quagga'
732
A R Karthick07608ef2016-08-23 16:51:19 -0700733 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
Chetan Gaonker503032a2016-05-12 12:06:29 -0700734 boot_delay = 15, restart = False, config_file = quagga_config_file, update = False):
A R Karthick07608ef2016-08-23 16:51:19 -0700735 super(Quagga, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.quagga_config)
Chetan Gaonker503032a2016-05-12 12:06:29 -0700736 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -0700737 self.build_image(self.image_name)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700738 if restart is True and self.exists():
739 self.kill()
740 if not self.exists():
741 self.remove_container(name, force=True)
A R Karthick41adfce2016-06-10 09:51:25 -0700742 host_config = self.create_host_config(port_list = self.ports,
743 host_guest_map = self.host_guest_map,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700744 privileged = True)
745 volumes = []
746 for _,g in self.host_guest_map:
747 volumes.append(g)
748 self.start(ports = self.ports,
A R Karthick41adfce2016-06-10 09:51:25 -0700749 host_config = host_config,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700750 volumes = volumes, tty = True)
751 print('Starting Quagga on container %s' %self.name)
752 self.execute('{0}/start.sh {1}'.format(self.guest_quagga_config, config_file))
753 time.sleep(boot_delay)
754
755 @classmethod
756 def build_image(cls, image):
Chetan Gaonker2a6601b2016-05-02 17:28:26 -0700757 onos_quagga_ip = Onos.quagga_config[0]['ip']
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700758 print('Building Quagga image %s' %image)
759 dockerfile = '''
A R Karthick41adfce2016-06-10 09:51:25 -0700760FROM ubuntu:14.04
761MAINTAINER chetan@ciena.com
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700762WORKDIR /root
763RUN useradd -M quagga
764RUN mkdir /var/log/quagga && chown quagga:quagga /var/log/quagga
765RUN mkdir /var/run/quagga && chown quagga:quagga /var/run/quagga
A R Karthick973ea692016-10-17 12:23:02 -0700766RUN apt-get update && apt-get install -qy git autoconf libtool gawk make telnet libreadline6-dev pkg-config protobuf-c-compiler
ChetanGaonkerb5b46c62016-08-16 12:02:53 -0700767RUN git clone git://git.savannah.nongnu.org/quagga.git quagga && \
A R Karthick8f69c2c2016-10-21 11:43:26 -0700768(cd quagga && git checkout quagga-1.0.20160315 && ./bootstrap.sh && \
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700769sed -i -r 's,htonl.*?\(INADDR_LOOPBACK\),inet_addr\("{0}"\),g' zebra/zebra_fpm.c && \
770./configure --enable-fpm --disable-doc --localstatedir=/var/run/quagga && make && make install)
771RUN ldconfig
772'''.format(onos_quagga_ip)
773 super(Quagga, cls).build_image(dockerfile, image)
774 print('Done building image %s' %image)
A R Karthick81acbff2016-06-17 14:45:16 -0700775
A.R Karthick1700e0e2016-10-06 18:16:57 -0700776class QuaggaStopWrapper(Container):
777 def __init__(self, name = Quagga.NAME, image = Quagga.IMAGE, tag = 'candidate'):
778 super(QuaggaStopWrapper, self).__init__(name, image, prefix = Container.IMAGE_PREFIX, tag = tag)
779 if self.exists():
780 self.kill()
781
782
A R Karthick81acbff2016-06-17 14:45:16 -0700783def reinitContainerClients():
784 docker_netns.dckr = Client()
785 Container.dckr = Client()
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700786
787class Xos(Container):
788 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
789 TAG = 'latest'
790 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700791 host_guest_map = None
792 env = None
793 ports = None
794 volumes = None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700795
A R Karthick6e80afd2016-10-10 16:03:12 -0700796 @classmethod
797 def get_cmd(cls, img_name):
798 cmd = cls.dckr.inspect_image(img_name)['Config']['Cmd']
799 return ' '.join(cmd)
800
A R Karthicke3bde962016-09-27 15:06:35 -0700801 def __init__(self, name, image, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700802 boot_delay = 20, restart = False, network_cfg = None, update = False):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700803 if restart is True:
804 ##Find the right image to restart
805 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
806 if running_image:
807 image_name = running_image[0]['Image']
808 try:
809 image = image_name.split(':')[0]
810 tag = image_name.split(':')[1]
811 except: pass
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700812 super(Xos, self).__init__(name, image, prefix = prefix, tag = tag)
813 if update is True or not self.img_exists():
814 self.build_image(self.image_name)
A R Karthick6e80afd2016-10-10 16:03:12 -0700815 self.command = self.get_cmd(self.image_name).strip() or None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700816 if restart is True and self.exists():
817 self.kill()
818 if not self.exists():
819 self.remove_container(name, force=True)
A R Karthicke3bde962016-09-27 15:06:35 -0700820 host_config = self.create_host_config(port_list = self.ports,
821 host_guest_map = self.host_guest_map,
822 privileged = True)
823 print('Starting XOS container %s' %self.name)
824 self.start(ports = self.ports, environment = self.env, host_config = host_config,
825 volumes = self.volumes, tty = True)
826 print('Waiting %d seconds for XOS Base Container to boot' %(boot_delay))
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700827 time.sleep(boot_delay)
828
829 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700830 def build_image(cls, image, dockerfile_path, image_target = 'build'):
831 cmd = 'cd {} && make {}'.format(dockerfile_path, image_target)
832 print('Building XOS %s' %image)
833 res = os.system(cmd)
834 print('Done building image %s. Image build %s' %(image, 'successful' if res == 0 else 'failed'))
835 return res
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700836
A R Karthicke3bde962016-09-27 15:06:35 -0700837class XosServer(Xos):
838 ports = [8000,9998,9999]
839 NAME = 'xos-server'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700840 IMAGE = 'xosproject/xos'
A R Karthicke3bde962016-09-27 15:06:35 -0700841 BASE_IMAGE = 'xosproject/xos-base'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700842 TAG = 'latest'
843 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700844 dockerfile_path = os.path.join(Xos.setup_dir, 'xos')
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700845
A R Karthicke3bde962016-09-27 15:06:35 -0700846 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700847 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700848 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700849
850 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700851 def build_image(cls, image = IMAGE):
852 ##build the base image and then build the server image
853 Xos.build_image(cls.BASE_IMAGE, cls.dockerfile_path, image_target = 'base')
854 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700855
A R Karthicke3bde962016-09-27 15:06:35 -0700856class XosSynchronizerOpenstack(Xos):
857 ports = [2375,]
858 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer')
859 NAME = 'xos-synchronizer'
860 IMAGE = 'xosproject/xos-synchronizer-openstack'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700861 TAG = 'latest'
862 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700863 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700864
A R Karthicke3bde962016-09-27 15:06:35 -0700865 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700866 tag = TAG, boot_delay = 20, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700867 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700868
869 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700870 def build_image(cls, image = IMAGE):
871 XosServer.build_image()
872 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700873
A R Karthicke3bde962016-09-27 15:06:35 -0700874class XosSynchronizerOnboarding(Xos):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700875 NAME = 'xos-synchronizer-onboarding'
876 IMAGE = 'xosproject/xos-synchronizer-onboarding'
877 TAG = 'latest'
878 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700879 dockerfile_path = os.path.join(Xos.setup_dir, 'onboarding_synchronizer')
880 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700881
A R Karthicke3bde962016-09-27 15:06:35 -0700882 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700883 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700884 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700885
886 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700887 def build_image(cls, image = IMAGE):
888 XosSynchronizerOpenstack.build_image()
889 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700890
A R Karthicke3bde962016-09-27 15:06:35 -0700891class XosSynchronizerOpenvpn(Xos):
892 NAME = 'xos-synchronizer-openvpn'
893 IMAGE = 'xosproject/xos-openvpn'
894 TAG = 'latest'
895 PREFIX = ''
896 dockerfile_path = os.path.join(Xos.setup_dir, 'openvpn')
897 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700898
A R Karthicke3bde962016-09-27 15:06:35 -0700899 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700900 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700901 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
902
903 @classmethod
904 def build_image(cls, image = IMAGE):
905 XosSynchronizerOpenstack.build_image()
906 Xos.build_image(image, cls.dockerfile_path)
907
908class XosPostgresql(Xos):
909 ports = [5432,]
910 NAME = 'xos-db-postgres'
911 IMAGE = 'xosproject/xos-postgres'
912 TAG = 'latest'
913 PREFIX = ''
914 volumes = ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
915 dockerfile_path = os.path.join(Xos.setup_dir, 'postgresql')
916
917 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700918 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700919 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
920
921 @classmethod
922 def build_image(cls, image = IMAGE):
923 Xos.build_image(image, cls.dockerfile_path)
924
925class XosSyndicateMs(Xos):
926 ports = [8080,]
927 env = None
928 NAME = 'xos-syndicate-ms'
929 IMAGE = 'xosproject/syndicate-ms'
930 TAG = 'latest'
931 PREFIX = ''
932 dockerfile_path = os.path.join(Xos.setup_dir, 'syndicate-ms')
933
934 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700935 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700936 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
937
938 @classmethod
939 def build_image(cls, image = IMAGE):
940 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700941
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700942class XosSyncVtn(Xos):
943 ports = [8080,]
944 env = None
945 NAME = 'xos-synchronizer-vtn'
946 IMAGE = 'xosproject/xos-synchronizer-vtn'
947 TAG = 'latest'
948 PREFIX = ''
949 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtn')
950
951 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700952 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700953 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
954
955 @classmethod
956 def build_image(cls, image = IMAGE):
957 Xos.build_image(image, cls.dockerfile_path)
958
959class XosSyncVtr(Xos):
960 ports = [8080,]
961 env = None
962 NAME = 'xos-synchronizer-vtr'
963 IMAGE = 'xosproject/xos-synchronizer-vtr'
964 TAG = 'latest'
965 PREFIX = ''
966 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtr')
967
968 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700969 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700970 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
971
972 @classmethod
973 def build_image(cls, image = IMAGE):
974 Xos.build_image(image, cls.dockerfile_path)
975
976class XosSyncVsg(Xos):
977 ports = [8080,]
978 env = None
979 NAME = 'xos-synchronizer-vsg'
980 IMAGE = 'xosproject/xos-synchronizer-vsg'
981 TAG = 'latest'
982 PREFIX = ''
983 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vsg')
984
985 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700986 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700987 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
988
989 @classmethod
990 def build_image(cls, image = IMAGE):
991 Xos.build_image(image, cls.dockerfile_path)
992
993
994class XosSyncOnos(Xos):
995 ports = [8080,]
996 env = None
997 NAME = 'xos-synchronizer-onos'
998 IMAGE = 'xosproject/xos-synchronizer-onos'
999 TAG = 'latest'
1000 PREFIX = ''
1001 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-onos')
1002
1003 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001004 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001005 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1006
1007 @classmethod
1008 def build_image(cls, image = IMAGE):
1009 Xos.build_image(image, cls.dockerfile_path)
1010
1011class XosSyncFabric(Xos):
1012 ports = [8080,]
1013 env = None
1014 NAME = 'xos-synchronizer-fabric'
1015 IMAGE = 'xosproject/xos-synchronizer-fabric'
1016 TAG = 'latest'
1017 PREFIX = ''
1018 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-fabric')
1019
1020 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001021 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001022 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1023
1024 @classmethod
1025 def build_image(cls, image = IMAGE):
1026 Xos.build_image(image, cls.dockerfile_path)
A R Karthick19aaf5c2016-11-09 17:47:57 -08001027
1028if __name__ == '__main__':
1029 onos = Onos(boot_delay = 10, restart = True)