blob: 991455cedcb51fded2643b8a4ceb5ea9a6670130 [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
A R Karthickea8bfce2016-10-13 16:32:07 -070017import os,time
18from CordContainer import Container
A R Karthick76a497a2017-04-12 10:59:39 -070019from CordTestUtils import log_test
A R Karthickea8bfce2016-10-13 16:32:07 -070020
21class XosBase(object):
22 workspace = '/tmp/xos_scratch_workspace'
23 image = 'xosproject/xos'
24 tag = 'latest'
25
26 @classmethod
27 def clone(cls, update = False):
28 fetch_cmd = 'mkdir -p {} && cd {} && \
29 git clone http://gerrit.opencord.org/xos'.format(cls.workspace, cls.workspace)
30 fetch = True
31 if os.access(cls.workspace, os.F_OK):
32 fetch = update
33 if update is True:
34 os.system('rm -rf {}'.format(cls.workspace))
35 if fetch is True:
36 ##fetch the xos
37 os.system(fetch_cmd)
38
39 @classmethod
40 def build_images(cls):
41 images = ( ['xos', ('base', 'build',),],
42 ['postgresql', ('build',),],
43 ['synchronizer', ('build',),],
44 ['onboarding_synchronizer', ('build',),],
45 ['syndicate-ms', ('build',),],
46 )
47
48 for cnt, targets in images:
49 for target in targets:
50 xos_dir = 'cd {}/xos/containers/{} && make {}'.format(cls.workspace, cnt, target)
51 os.system(xos_dir)
52
53class XosServiceProfile(XosBase):
54
55 def __init__(self, profile = 'cord-pod', update = False):
56 self.workspace = XosBase.workspace
57 self.profile = profile
58 self.service_dir = '{}/service-profile'.format(self.workspace)
59 self.profile_dir = '{}/{}'.format(self.service_dir, profile)
60 XosBase.clone(update = update)
61 self.__clone(update = update)
62
63 def __clone(self, update = False):
64 fetch_cmd = 'cd {} && git clone http://gerrit.opencord.org/service-profile'.format(self.workspace)
65 fetch = True
66 if os.access(self.service_dir, os.F_OK):
67 fetch = update
68 if update is True:
69 os.system('rm -rf {}'.format(self.service_dir))
70 if fetch:
71 os.system(fetch_cmd)
72
73 def __ssh_key_check(self):
74 id_rsa = '{}/.ssh/id_rsa'.format(os.getenv('HOME'))
75 if not os.access(id_rsa, os.F_OK):
76 return False
77 return True
78
79 def __ssh_copy_keys(self, dest):
80 cmd = 'cp -v {}/.ssh/id_rsa* {}'.format(os.getenv('HOME'), dest)
81 return os.system(cmd)
82
83 def build_images(self, force = False):
84 if force is True or not Container.image_exists('{}:{}'.format(XosBase.image, XosBase.tag)):
85 XosBase.build_images()
86
87 def start_services(self):
88 if not self.__ssh_key_check():
A R Karthick76a497a2017-04-12 10:59:39 -070089 log_test.info('SSH keys need to be generated before building XOS service containers')
90 log_test.info('Use the following commands to generate ssh keys')
91 log_test.info('ssh-keygen -t rsa -q -N ""')
92 log_test.info('ssh-copy-id -i $HOME/.ssh/id_rsa ubuntu@localhost')
A R Karthickea8bfce2016-10-13 16:32:07 -070093 return False
94 if not os.access(self.profile_dir, os.F_OK):
A R Karthick76a497a2017-04-12 10:59:39 -070095 log_test.error('Profile directory %s does not exist' %self.profile_dir)
A R Karthickea8bfce2016-10-13 16:32:07 -070096 return False
97 self.build_images()
98 ##copy the keys to the profile dir
99 self.__ssh_copy_keys(self.profile_dir)
100 service_cmd = 'cd {} && make dirs download_services bootstrap onboarding'.format(self.profile_dir)
101 return os.system(service_cmd)
102
103 def stop_services(self, rm = False):
104 if os.access(self.profile_dir, os.F_OK):
105 cmds = ['cd {}'.format(self.profile_dir), 'make stop']
106 if rm is True:
107 cmds += ['make rm']
108 cmd = ' && '.join(cmds)
109 return os.system(cmd) == 0
110 return False