blob: d4ce7832f34a8090fb525a2d2b08889da79c7095 [file] [log] [blame]
A R Karthickea8bfce2016-10-13 16:32:07 -07001import os,time
2from CordContainer import Container
A R Karthick76a497a2017-04-12 10:59:39 -07003from CordTestUtils import log_test
A R Karthickea8bfce2016-10-13 16:32:07 -07004
5class XosBase(object):
6 workspace = '/tmp/xos_scratch_workspace'
7 image = 'xosproject/xos'
8 tag = 'latest'
9
10 @classmethod
11 def clone(cls, update = False):
12 fetch_cmd = 'mkdir -p {} && cd {} && \
13 git clone http://gerrit.opencord.org/xos'.format(cls.workspace, cls.workspace)
14 fetch = True
15 if os.access(cls.workspace, os.F_OK):
16 fetch = update
17 if update is True:
18 os.system('rm -rf {}'.format(cls.workspace))
19 if fetch is True:
20 ##fetch the xos
21 os.system(fetch_cmd)
22
23 @classmethod
24 def build_images(cls):
25 images = ( ['xos', ('base', 'build',),],
26 ['postgresql', ('build',),],
27 ['synchronizer', ('build',),],
28 ['onboarding_synchronizer', ('build',),],
29 ['syndicate-ms', ('build',),],
30 )
31
32 for cnt, targets in images:
33 for target in targets:
34 xos_dir = 'cd {}/xos/containers/{} && make {}'.format(cls.workspace, cnt, target)
35 os.system(xos_dir)
36
37class XosServiceProfile(XosBase):
38
39 def __init__(self, profile = 'cord-pod', update = False):
40 self.workspace = XosBase.workspace
41 self.profile = profile
42 self.service_dir = '{}/service-profile'.format(self.workspace)
43 self.profile_dir = '{}/{}'.format(self.service_dir, profile)
44 XosBase.clone(update = update)
45 self.__clone(update = update)
46
47 def __clone(self, update = False):
48 fetch_cmd = 'cd {} && git clone http://gerrit.opencord.org/service-profile'.format(self.workspace)
49 fetch = True
50 if os.access(self.service_dir, os.F_OK):
51 fetch = update
52 if update is True:
53 os.system('rm -rf {}'.format(self.service_dir))
54 if fetch:
55 os.system(fetch_cmd)
56
57 def __ssh_key_check(self):
58 id_rsa = '{}/.ssh/id_rsa'.format(os.getenv('HOME'))
59 if not os.access(id_rsa, os.F_OK):
60 return False
61 return True
62
63 def __ssh_copy_keys(self, dest):
64 cmd = 'cp -v {}/.ssh/id_rsa* {}'.format(os.getenv('HOME'), dest)
65 return os.system(cmd)
66
67 def build_images(self, force = False):
68 if force is True or not Container.image_exists('{}:{}'.format(XosBase.image, XosBase.tag)):
69 XosBase.build_images()
70
71 def start_services(self):
72 if not self.__ssh_key_check():
A R Karthick76a497a2017-04-12 10:59:39 -070073 log_test.info('SSH keys need to be generated before building XOS service containers')
74 log_test.info('Use the following commands to generate ssh keys')
75 log_test.info('ssh-keygen -t rsa -q -N ""')
76 log_test.info('ssh-copy-id -i $HOME/.ssh/id_rsa ubuntu@localhost')
A R Karthickea8bfce2016-10-13 16:32:07 -070077 return False
78 if not os.access(self.profile_dir, os.F_OK):
A R Karthick76a497a2017-04-12 10:59:39 -070079 log_test.error('Profile directory %s does not exist' %self.profile_dir)
A R Karthickea8bfce2016-10-13 16:32:07 -070080 return False
81 self.build_images()
82 ##copy the keys to the profile dir
83 self.__ssh_copy_keys(self.profile_dir)
84 service_cmd = 'cd {} && make dirs download_services bootstrap onboarding'.format(self.profile_dir)
85 return os.system(service_cmd)
86
87 def stop_services(self, rm = False):
88 if os.access(self.profile_dir, os.F_OK):
89 cmds = ['cd {}'.format(self.profile_dir), 'make stop']
90 if rm is True:
91 cmds += ['make rm']
92 cmd = ' && '.join(cmds)
93 return os.system(cmd) == 0
94 return False