forked from akarol/cloudqe-aeolus
-
Notifications
You must be signed in to change notification settings - Fork 2
/
aeolus-helper
executable file
·175 lines (146 loc) · 6.05 KB
/
aeolus-helper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/python -tt
#
# Script to build and install aeolus modules from source control or yum repo
#
# Copyright (C) 2011 Red Hat
# James Laska <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import os
import sys
import optparse
import logging
import yum
try:
import aeoluslib
from aeoluslib.cli import *
from aeoluslib.logger import setup_logging
except ImportError:
print "Unable to import aeoluslib. Is aeoluslib in PYTHONPATH?"
sys.exit(1)
def yum_var_subst(buf):
'''Convenience method to substitute instances of $releasever and $basearch
from yum's point of view.
ex: yum_var_subst('/tmp/$basearch/$releasever') -> '/tmp/x86_64/16'
'''
yb = yum.YumBase()
yb.conf
for varname in ['releasever', 'basearch']:
buf = buf.replace('$'+varname, yb.yumvar[varname])
return buf
def is_requested(module, requested):
# Was module (or all) requested?
if module in requested or 'all' in requested:
return True
return False
def main(opts, requested_modules):
# FIXME - detect whether running in SELinux enforcing
# FIXME - remind about firewall changes?
command = requested_modules[0]
requested_modules = requested_modules[1:]
# If directed, enable custom repofiles
if opts.repofile:
aeoluslib.add_custom_repos(opts.repofile)
# Instruct aeoluslib to not cleanup temporary files after completion
if opts.no_clean:
aeoluslib.cleanup = False
# Define a basedir for all git operations
if opts.source == 'git' and opts.basedir:
aeoluslib.workdir = opts.basedir
# Install some packages needed to interact with SCM and create packages
if command == 'build' and opts.source == 'git':
pre_reqs = ['git', 'make', 'gcc', 'rpm-build',
'rubygem-rake', # needed by several projects for Rakefile support
'rubygem-rspec', # needed by aeolus-configure
'gettext-devel', # needed by iwhd
'gperf', # needed by iwhd
'gcc-c++', # needed by iwhd
'libtool', # needed by libdeltacloud
'tito', # needed by candlepin
]
try:
aeoluslib.yum_install_if_needed(pre_reqs)
except Exception, e:
logging.error("Error: Unable to detect (or install) " \
+ "pre-requisites: %s\n%s" % (' '.join(pre_reqs), e))
sys.exit(1)
# Force specific module install/setup order
priority_modules = ['aeolus-conductor', 'aeolus-configure']
supported_modules = get_supported_modules()
# Remove duplicates - doesn't catch ValueError
[supported_modules.remove(m) for m in priority_modules]
# Install requested modules
for module in priority_modules + supported_modules:
if is_requested(module, requested_modules):
cls_obj = find_module(module)
if cls_obj is None:
logging.error("Unable to find aeoluslib module for %s" % module)
sys.exit(1)
# Instantiate the module
cls_inst = cls_obj()
# build =======================================
if command == 'build':
if opts.source == 'git':
cls_inst.build_from_scm()
else:
logging.error("No support for building from --source=yum")
sys.exit(1)
# install =====================================
elif command == 'install':
if opts.source == 'yum':
cls_inst.install()
elif opts.source == 'git':
cls_inst.install_from_scm(opts.rpmforce)
# Activate and start the system service (if applicable)
if module in ['aeolus-conductor', 'imagefactory', 'iwhd']:
cls_inst.chkconfig('on')
cls_inst.svc_restart()
# Run custom setup
try:
cls_inst.setup()
except NotImplementedError:
logging.warn("No custom setup defined for %s" % module)
pass
# list-requires ===============================
elif command == 'list-requires':
print '\n'.join(cls_inst.list_requires())
# list-buildrequires ==========================
elif command == 'list-buildrequires':
print '\n'.join(cls_inst.list_buildreqs())
# install-requires ============================
elif command == 'install-requires':
cls_inst.install_requires()
# install-buildrequires =======================
elif command == 'install-buildrequires':
cls_inst.install_buildreqs()
# unittest ====================================
elif command == 'unittest':
cls_inst.unittest()
# ls-remote ===================================
elif command == 'ls-remote':
githash = cls_inst.get_remote_hash('master')
print "%s (master) - %s" % (cls_inst.name, githash)
if __name__ == "__main__":
# Process arguments
(opts, requested_modules) = parse_args()
# Setup logging
setup_logging(opts.debug, opts.logfile)
try:
main(opts, requested_modules)
except KeyError:
print "Exiting upon user request"
sys.exit(1)
finally:
aeoluslib.remove_custom_repos(opts.repofile)