package.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  4. import argparse
  5. import logging
  6. import os
  7. import pexpect
  8. import shutil
  9. import signal
  10. import subprocess
  11. import sys
  12. import tempfile
  13. import textwrap
  14. import time
  15. import traceback
  16. from xmlrpc import client as xmlrpclib
  17. from glob import glob
  18. #----------------------------------------------------------
  19. # Utils
  20. #----------------------------------------------------------
  21. ROOTDIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
  22. TSTAMP = time.strftime("%Y%m%d", time.gmtime())
  23. TSEC = time.strftime("%H%M%S", time.gmtime())
  24. # Get some variables from release.py
  25. version = ...
  26. version_info = ...
  27. nt_service_name = ...
  28. exec(open(os.path.join(ROOTDIR, 'odoo', 'release.py'), 'rb').read())
  29. VERSION = version.split('-')[0].replace('saas~', '')
  30. GPGPASSPHRASE = os.getenv('GPGPASSPHRASE')
  31. GPGID = os.getenv('GPGID')
  32. DOCKERVERSION = VERSION.replace('+', '')
  33. INSTALL_TIMEOUT = 600
  34. DOCKERUSER = """
  35. RUN mkdir /var/lib/odoo && \
  36. groupadd -g %(group_id)s odoo && \
  37. useradd -u %(user_id)s -g odoo odoo -d /var/lib/odoo && \
  38. mkdir /data && \
  39. chown odoo:odoo /var/lib/odoo /data
  40. USER odoo
  41. """ % {'group_id': os.getgid(), 'user_id': os.getuid()}
  42. class OdooTestTimeoutError(Exception):
  43. pass
  44. class OdooTestError(Exception):
  45. pass
  46. def run_cmd(cmd, chdir=None, timeout=None):
  47. logging.info("Running command %s", cmd)
  48. return subprocess.run(cmd, cwd=chdir, timeout=timeout)
  49. def _rpc_count_modules(addr='http://127.0.0.1', port=8069, dbname='mycompany'):
  50. time.sleep(5)
  51. uid = xmlrpclib.ServerProxy('%s:%s/xmlrpc/2/common' % (addr, port)).authenticate(
  52. dbname, 'admin', 'admin', {}
  53. )
  54. modules = xmlrpclib.ServerProxy('%s:%s/xmlrpc/2/object' % (addr, port)).execute(
  55. dbname, uid, 'admin', 'ir.module.module', 'search', [('state', '=', 'installed')]
  56. )
  57. if len(modules) > 1:
  58. time.sleep(1)
  59. toinstallmodules = xmlrpclib.ServerProxy('%s:%s/xmlrpc/2/object' % (addr, port)).execute(
  60. dbname, uid, 'admin', 'ir.module.module', 'search', [('state', '=', 'to install')]
  61. )
  62. if toinstallmodules:
  63. logging.error("Package test: FAILED. Not able to install dependencies of base.")
  64. raise OdooTestError("Installation of package failed")
  65. else:
  66. logging.info("Package test: successfuly installed %s modules" % len(modules))
  67. else:
  68. logging.error("Package test: FAILED. Not able to install base.")
  69. raise OdooTestError("Package test: FAILED. Not able to install base.")
  70. def publish(args, pub_type, extensions):
  71. """Publish builded package (move builded files and generate a symlink to the latests)
  72. :args: parsed program args
  73. :pub_type: one of [deb, rpm, src, exe]
  74. :extensions: list of extensions to publish
  75. :returns: published files
  76. """
  77. def _publish(release):
  78. build_path = os.path.join(args.build_dir, release)
  79. filename = release.split(os.path.sep)[-1]
  80. release_dir = os.path.join(args.pub, pub_type)
  81. release_path = os.path.join(release_dir, filename)
  82. os.renames(build_path, release_path)
  83. # Latest/symlink handler
  84. release_abspath = os.path.abspath(release_path)
  85. latest_abspath = release_abspath.replace(TSTAMP, 'latest')
  86. if os.path.islink(latest_abspath):
  87. os.unlink(latest_abspath)
  88. os.symlink(release_abspath, latest_abspath)
  89. return release_path
  90. published = []
  91. for extension in extensions:
  92. release = glob("%s/odoo_*.%s" % (args.build_dir, extension))
  93. if release:
  94. published.append(_publish(release[0]))
  95. return published
  96. # ---------------------------------------------------------
  97. # Generates Packages, Sources and Release files of debian package
  98. # ---------------------------------------------------------
  99. def gen_deb_package(args, published_files):
  100. # Executes command to produce file_name in path, and moves it to args.pub/deb
  101. def _gen_file(args, command, file_name, path):
  102. cur_tmp_file_path = os.path.join(path, file_name)
  103. with open(cur_tmp_file_path, 'w') as out:
  104. subprocess.call(command, stdout=out, cwd=path)
  105. shutil.copy(cur_tmp_file_path, os.path.join(args.pub, 'deb', file_name))
  106. # Copy files to a temp directory (required because the working directory must contain only the
  107. # files of the last release)
  108. temp_path = tempfile.mkdtemp(suffix='debPackages')
  109. for pub_file_path in published_files:
  110. shutil.copy(pub_file_path, temp_path)
  111. commands = [
  112. (['dpkg-scanpackages', '--multiversion', '.'], "Packages"), # Generate Packages file
  113. (['dpkg-scansources', '.'], "Sources"), # Generate Sources file
  114. (['apt-ftparchive', 'release', '.'], "Release") # Generate Release file
  115. ]
  116. # Generate files
  117. for command in commands:
  118. _gen_file(args, command[0], command[-1], temp_path)
  119. # Remove temp directory
  120. shutil.rmtree(temp_path)
  121. if args.sign:
  122. # Generate Release.gpg (= signed Release)
  123. # Options -abs: -a (Create ASCII armored output), -b (Make a detach signature), -s (Make a signature)
  124. subprocess.call(['gpg', '--default-key', GPGID, '--passphrase', GPGPASSPHRASE, '--yes', '-abs', '--no-tty', '-o', 'Release.gpg', 'Release'], cwd=os.path.join(args.pub, 'deb'))
  125. # ---------------------------------------------------------
  126. # Generates an RPM repo
  127. # ---------------------------------------------------------
  128. def rpm_sign(args, file_name):
  129. """Genereate a rpm repo in publish directory"""
  130. # Sign the RPM
  131. rpmsign = pexpect.spawn('/bin/bash', ['-c', 'rpm --resign %s' % file_name], cwd=os.path.join(args.pub, 'rpm'))
  132. rpmsign.expect_exact('Enter passphrase: ')
  133. rpmsign.send(GPGPASSPHRASE + '\r\n')
  134. rpmsign.expect(pexpect.EOF)
  135. def _prepare_build_dir(args, win32=False, move_addons=True):
  136. """Copy files to the build directory"""
  137. logging.info('Preparing build dir "%s"', args.build_dir)
  138. cmd = ['rsync', '-a', '--delete', '--exclude', '.git', '--exclude', '*.pyc', '--exclude', '*.pyo']
  139. if win32 is False:
  140. cmd += ['--exclude', 'setup/win32']
  141. run_cmd(cmd + ['%s/' % args.odoo_dir, args.build_dir])
  142. if not move_addons:
  143. return
  144. for addon_path in glob(os.path.join(args.build_dir, 'addons/*')):
  145. if args.blacklist is None or os.path.basename(addon_path) not in args.blacklist:
  146. try:
  147. shutil.move(addon_path, os.path.join(args.build_dir, 'odoo/addons'))
  148. except shutil.Error as e:
  149. logging.warning("Warning '%s' while moving addon '%s", e, addon_path)
  150. if addon_path.startswith(args.build_dir) and os.path.isdir(addon_path):
  151. logging.info("Removing '{}'".format(addon_path))
  152. try:
  153. shutil.rmtree(addon_path)
  154. except shutil.Error as rm_error:
  155. logging.warning("Cannot remove '{}': {}".format(addon_path, rm_error))
  156. # Docker stuffs
  157. class Docker():
  158. """Base Docker class. Must be inherited by specific Docker builder class"""
  159. arch = None
  160. def __init__(self, args):
  161. """
  162. :param args: argparse parsed arguments
  163. """
  164. self.args = args
  165. self.tag = 'odoo-%s-%s-nightly-tests' % (DOCKERVERSION, self.arch)
  166. self.container_name = None
  167. self.exposed_port = None
  168. dockerfiles = {
  169. 'tgz': os.path.join(args.build_dir, 'setup/package.dfsrc'),
  170. 'deb': os.path.join(args.build_dir, 'setup/package.dfdebian'),
  171. 'rpm': os.path.join(args.build_dir, 'setup/package.dffedora'),
  172. }
  173. self.dockerfile = dockerfiles[self.arch]
  174. self.test_log_file = '/data/src/test-%s.log' % self.arch
  175. self.build_image()
  176. def build_image(self):
  177. """Build the dockerimage by copying Dockerfile into build_dir/docker"""
  178. docker_dir = os.path.join(self.args.build_dir, 'docker')
  179. docker_file_path = os.path.join(docker_dir, 'Dockerfile')
  180. os.mkdir(docker_dir)
  181. shutil.copy(self.dockerfile, docker_file_path)
  182. with open(docker_file_path, 'a') as dockerfile:
  183. dockerfile.write(DOCKERUSER)
  184. shutil.copy(os.path.join(self.args.build_dir, 'requirements.txt'), docker_dir)
  185. run_cmd(["docker", "build", "--rm=True", "-t", self.tag, "."], chdir=docker_dir, timeout=1200).check_returncode()
  186. shutil.rmtree(docker_dir)
  187. def run(self, cmd, build_dir, container_name, user='odoo', exposed_port=None, detach=False, timeout=None):
  188. self.container_name = container_name
  189. docker_cmd = [
  190. "docker",
  191. "run",
  192. "--user=%s" % user,
  193. "--name=%s" % container_name,
  194. "--rm",
  195. "--volume=%s:/data/src" % build_dir
  196. ]
  197. if exposed_port:
  198. docker_cmd.extend(['-p', '127.0.0.1:%s:%s' % (exposed_port, exposed_port)])
  199. self.exposed_port = exposed_port
  200. if detach:
  201. docker_cmd.append('-d')
  202. # preserve logs in case of detached docker container
  203. cmd = '(%s) > %s 2>&1' % (cmd, self.test_log_file)
  204. docker_cmd.extend([
  205. self.tag,
  206. "/bin/bash",
  207. "-c",
  208. "cd /data/src && %s" % cmd
  209. ])
  210. run_cmd(docker_cmd, timeout=timeout).check_returncode()
  211. def is_running(self):
  212. dinspect = subprocess.run(['docker', 'container', 'inspect', self.container_name], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
  213. return True if dinspect.returncode == 0 else False
  214. def stop(self):
  215. run_cmd(["docker", "stop", self.container_name]).check_returncode()
  216. def test_odoo(self):
  217. logging.info('Starting to test Odoo install test')
  218. start_time = time.time()
  219. while self.is_running() and (time.time() - start_time) < INSTALL_TIMEOUT:
  220. time.sleep(5)
  221. if os.path.exists(os.path.join(args.build_dir, 'odoo.pid')):
  222. try:
  223. _rpc_count_modules(port=self.exposed_port)
  224. finally:
  225. self.stop()
  226. return
  227. if self.is_running():
  228. self.stop()
  229. raise OdooTestTimeoutError('Odoo pid file never appeared after %s sec' % INSTALL_TIMEOUT)
  230. raise OdooTestError('Error while installing/starting Odoo after %s sec.\nSee testlogs.txt in build dir' % int(time.time() - start_time))
  231. def build(self):
  232. """To be overriden by specific builder"""
  233. pass
  234. def start_test(self):
  235. """To be overriden by specific builder"""
  236. pass
  237. class DockerTgz(Docker):
  238. """Docker class to build python src package"""
  239. arch = 'tgz'
  240. def build(self):
  241. logging.info('Start building python tgz package')
  242. self.run('python3 setup.py sdist --quiet --formats=gztar,zip', self.args.build_dir, 'odoo-src-build-%s' % TSTAMP)
  243. os.rename(glob('%s/dist/odoo-*.tar.gz' % self.args.build_dir)[0], '%s/odoo_%s.%s.tar.gz' % (self.args.build_dir, VERSION, TSTAMP))
  244. os.rename(glob('%s/dist/odoo-*.zip' % self.args.build_dir)[0], '%s/odoo_%s.%s.zip' % (self.args.build_dir, VERSION, TSTAMP))
  245. logging.info('Finished building python tgz package')
  246. def start_test(self):
  247. if not self.args.test:
  248. return
  249. logging.info('Start testing python tgz package')
  250. cmds = [
  251. 'service postgresql start',
  252. 'pip3 install /data/src/odoo_%s.%s.tar.gz' % (VERSION, TSTAMP),
  253. 'su postgres -s /bin/bash -c "createuser -s odoo"',
  254. 'su postgres -s /bin/bash -c "createdb mycompany"',
  255. 'su odoo -s /bin/bash -c "odoo -d mycompany -i base --stop-after-init"',
  256. 'su odoo -s /bin/bash -c "odoo -d mycompany --pidfile=/data/src/odoo.pid"',
  257. ]
  258. self.run(' && '.join(cmds), self.args.build_dir, 'odoo-src-test-%s' % TSTAMP, user='root', detach=True, exposed_port=8069, timeout=300)
  259. self.test_odoo()
  260. logging.info('Finished testing tgz package')
  261. class DockerDeb(Docker):
  262. """Docker class to build debian package"""
  263. arch = 'deb'
  264. def build(self):
  265. logging.info('Start building debian package')
  266. # Append timestamp to version for the .dsc to refer the right .tar.gz
  267. cmds = ["sed -i '1s/^.*$/odoo (%s.%s) stable; urgency=low/' debian/changelog" % (VERSION, TSTAMP)]
  268. cmds.append('dpkg-buildpackage -rfakeroot -uc -us -tc')
  269. # As the packages are built in the parent of the buildir, we move them back to build_dir
  270. cmds.append('mv ../odoo_* ./')
  271. self.run(' && '.join(cmds), self.args.build_dir, 'odoo-deb-build-%s' % TSTAMP)
  272. logging.info('Finished building debian package')
  273. def start_test(self):
  274. if not self.args.test:
  275. return
  276. logging.info('Start testing debian package')
  277. cmds = [
  278. 'service postgresql start',
  279. 'su postgres -s /bin/bash -c "createdb mycompany"',
  280. '/usr/bin/apt-get update -y',
  281. '/usr/bin/dpkg -i /data/src/odoo_%s.%s_all.deb ; /usr/bin/apt-get install -f -y' % (VERSION, TSTAMP),
  282. 'su odoo -s /bin/bash -c "odoo -d mycompany -i base --stop-after-init"',
  283. 'su odoo -s /bin/bash -c "odoo -d mycompany --pidfile=/data/src/odoo.pid"',
  284. ]
  285. self.run(' && '.join(cmds), self.args.build_dir, 'odoo-deb-test-%s' % TSTAMP, user='root', detach=True, exposed_port=8069, timeout=300)
  286. self.test_odoo()
  287. logging.info('Finished testing debian package')
  288. class DockerRpm(Docker):
  289. """Docker class to build rpm package"""
  290. arch = 'rpm'
  291. def build(self):
  292. logging.info('Start building fedora rpm package')
  293. rpmbuild_dir = '/var/lib/odoo/rpmbuild'
  294. cmds = [
  295. 'cd /data/src',
  296. 'mkdir -p dist',
  297. 'rpmdev-setuptree -d',
  298. f'cp -a /data/src/setup/rpm/odoo.spec {rpmbuild_dir}/SPECS/',
  299. f'tar --transform "s/^\\./odoo-{VERSION}/" -c -z -f {rpmbuild_dir}/SOURCES/odoo-{VERSION}.tar.gz .',
  300. f'rpmbuild -bb --define="%version {VERSION}" /data/src/setup/rpm/odoo.spec',
  301. f'mv {rpmbuild_dir}/RPMS/noarch/odoo*.rpm /data/src/dist/'
  302. ]
  303. self.run(' && '.join(cmds), self.args.build_dir, f'odoo-rpm-build-{TSTAMP}')
  304. os.rename(glob('%s/dist/odoo-*.noarch.rpm' % self.args.build_dir)[0], '%s/odoo_%s.%s.rpm' % (self.args.build_dir, VERSION, TSTAMP))
  305. logging.info('Finished building fedora rpm package')
  306. def start_test(self):
  307. if not self.args.test:
  308. return
  309. logging.info('Start testing rpm package')
  310. cmds = [
  311. 'su postgres -c "/usr/bin/pg_ctl -D /var/lib/postgres/data start"',
  312. 'sleep 5',
  313. 'su postgres -c "createdb mycompany"',
  314. 'dnf install -d 0 -e 0 /data/src/odoo_%s.%s.rpm -y' % (VERSION, TSTAMP),
  315. 'su odoo -s /bin/bash -c "odoo -c /etc/odoo/odoo.conf -d mycompany -i base --stop-after-init"',
  316. 'su odoo -s /bin/bash -c "odoo -c /etc/odoo/odoo.conf -d mycompany --pidfile=/data/src/odoo.pid"',
  317. ]
  318. self.run(' && '.join(cmds), args.build_dir, 'odoo-rpm-test-%s' % TSTAMP, user='root', detach=True, exposed_port=8069, timeout=300)
  319. self.test_odoo()
  320. logging.info('Finished testing rpm package')
  321. def gen_rpm_repo(self, args, rpm_filepath):
  322. pub_repodata_path = os.path.join(args.pub, 'rpm', 'repodata')
  323. # Removes the old repodata
  324. if os.path.isdir(pub_repodata_path):
  325. shutil.rmtree(pub_repodata_path)
  326. # Copy files to a temp directory (required because the working directory must contain only the
  327. # files of the last release)
  328. temp_path = tempfile.mkdtemp(suffix='rpmPackages')
  329. shutil.copy(rpm_filepath, temp_path)
  330. logging.info('Start creating rpm repo')
  331. self.run('createrepo /data/src/', temp_path, 'odoo-rpm-createrepo-%s' % TSTAMP)
  332. shutil.copytree(os.path.join(temp_path, "repodata"), pub_repodata_path)
  333. # Remove temp directory
  334. shutil.rmtree(temp_path)
  335. # KVM stuffs
  336. class KVM(object):
  337. def __init__(self, args):
  338. self.args = args
  339. self.image = args.vm_winxp_image
  340. self.ssh_key = args.vm_winxp_ssh_key
  341. self.login = args.vm_winxp_login
  342. def timeout(self, signum, frame):
  343. logging.warning("vm timeout kill (pid: {})".format(self.kvm_proc.pid))
  344. self.kvm_proc.terminate()
  345. def start(self):
  346. kvm_cmd = [
  347. "kvm",
  348. "-cpu", "Skylake-Client,hypervisor=on,hle=off,rtm=off",
  349. "-smp", "2,sockets=2,cores=1,threads=1",
  350. "-net", "nic,model=e1000e,macaddr=52:54:00:d3:38:5e",
  351. "-net", "user,hostfwd=tcp:127.0.0.1:10022-:22,hostfwd=tcp:127.0.0.1:18069-:8069,hostfwd=tcp:127.0.0.1:15432-:5432",
  352. "-m", "2048",
  353. "-drive", f"if=virtio,file={self.image},snapshot=on",
  354. "-nographic",
  355. "-serial", "none",
  356. ]
  357. logging.info("Starting kvm: {}".format(" ".join(kvm_cmd)))
  358. self.kvm_proc = subprocess.Popen(kvm_cmd)
  359. try:
  360. self.wait_ssh(30) # give some time to the VM to start, otherwise the SSH server may not be ready
  361. signal.alarm(2400)
  362. signal.signal(signal.SIGALRM, self.timeout)
  363. self.run()
  364. finally:
  365. signal.signal(signal.SIGALRM, signal.SIG_DFL)
  366. self.kvm_proc.terminate()
  367. time.sleep(10)
  368. def ssh(self, cmd):
  369. run_cmd([
  370. 'ssh',
  371. '-o', 'UserKnownHostsFile=/dev/null',
  372. '-o', 'StrictHostKeyChecking=no',
  373. '-o', 'BatchMode=yes',
  374. '-o', 'ConnectTimeout=10',
  375. '-p', '10022',
  376. '-i', self.ssh_key,
  377. '%s@127.0.0.1' % self.login,
  378. cmd
  379. ]).check_returncode()
  380. def rsync(self, rsync_args, options=['--delete', '--exclude', '.git', '--exclude', '.tx', '--exclude', '__pycache__']):
  381. cmd = [
  382. 'rsync',
  383. '-a',
  384. '-e', 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 10022 -i %s' % self.ssh_key
  385. ]
  386. cmd.extend(options)
  387. cmd.extend(rsync_args)
  388. run_cmd(cmd).check_returncode()
  389. def wait_ssh(self, n):
  390. for i in range(n):
  391. try:
  392. self.ssh('exit')
  393. return
  394. except subprocess.CalledProcessError:
  395. time.sleep(10)
  396. raise Exception('Unable to conncect to the VM')
  397. def run(self):
  398. pass
  399. class KVMWinBuildExe(KVM):
  400. def run(self):
  401. logging.info('Start building Windows package')
  402. with open(os.path.join(self.args.build_dir, 'setup/win32/Makefile.version'), 'w', encoding='utf-8') as f:
  403. win_version = VERSION.replace('~', '_').replace('+', '')
  404. f.write(textwrap.dedent(f"""
  405. VERSION={win_version}.{TSTAMP}
  406. MAJORVERSION={version_info[0]}
  407. MINORVERSION={version_info[1]}
  408. """))
  409. with open(os.path.join(self.args.build_dir, 'setup/win32/Makefile.python'), 'w', encoding='utf-8') as f:
  410. f.write("PYTHON_VERSION=%s\n" % self.args.vm_winxp_python_version)
  411. with open(os.path.join(self.args.build_dir, 'setup/win32/Makefile.servicename'), 'w', encoding='utf-8') as f:
  412. f.write("SERVICENAME=%s\n" % nt_service_name)
  413. remote_build_dir = '/cygdrive/c/odoobuild/server/'
  414. self.ssh("mkdir -p build")
  415. logging.info("Syncing Odoo files to virtual machine...")
  416. self.rsync(['%s/' % self.args.build_dir, '%s@127.0.0.1:%s' % (self.login, remote_build_dir)])
  417. self.ssh("cd {}setup/win32;time make allinone;".format(remote_build_dir))
  418. self.rsync(['%s@127.0.0.1:%ssetup/win32/release/' % (self.login, remote_build_dir), '%s/' % self.args.build_dir])
  419. logging.info('Finished building Windows package')
  420. class KVMWinTestExe(KVM):
  421. def run(self):
  422. logging.info('Start testing Windows package')
  423. setup_path = glob("%s/odoo_setup_*.exe" % self.args.build_dir)[0]
  424. setupfile = setup_path.split('/')[-1]
  425. setupversion = setupfile.split('odoo_setup_')[1].split('.exe')[0]
  426. self.rsync(['%s' % setup_path, '%s@127.0.0.1:' % self.login])
  427. self.ssh("TEMP=/tmp ./%s /S" % setupfile)
  428. self.ssh('PGPASSWORD=openpgpwd /cygdrive/c/"Program Files"/"Odoo %s"/PostgreSQL/bin/createdb.exe -e -U openpg mycompany' % setupversion)
  429. self.ssh('netsh advfirewall set publicprofile state off')
  430. self.ssh('/cygdrive/c/"Program Files"/"Odoo {sv}"/python/python.exe \'c:\\Program Files\\Odoo {sv}\\server\\odoo-bin\' -d mycompany -i base --stop-after-init'.format(sv=setupversion))
  431. _rpc_count_modules(port=18069)
  432. logging.info('Finished testing Windows package')
  433. def build_exe(args):
  434. KVMWinBuildExe(args).start()
  435. def test_exe(args):
  436. if args.test:
  437. KVMWinTestExe(args).start()
  438. def parse_args():
  439. ap = argparse.ArgumentParser()
  440. build_dir = "%s-%s-%s" % (ROOTDIR, TSEC, TSTAMP)
  441. log_levels = {"debug": logging.DEBUG, "info": logging.INFO, "warning": logging.WARN, "error": logging.ERROR, "critical": logging.CRITICAL}
  442. ap.add_argument("-b", "--build-dir", default=build_dir, help="build directory (%(default)s)", metavar="DIR")
  443. ap.add_argument("-p", "--pub", default=None, help="pub directory %(default)s", metavar="DIR")
  444. ap.add_argument("--logging", action="store", choices=list(log_levels.keys()), default="info", help="Logging level")
  445. ap.add_argument("--build-deb", action="store_true")
  446. ap.add_argument("--build-rpm", action="store_true")
  447. ap.add_argument("--build-tgz", action="store_true")
  448. ap.add_argument("--build-win", action="store_true")
  449. # Windows VM
  450. ap.add_argument("--vm-winxp-image", default='/home/odoo/vm/win1036/win10_winpy36.qcow2', help="%(default)s")
  451. ap.add_argument("--vm-winxp-ssh-key", default='/home/odoo/vm/win1036/id_rsa', help="%(default)s")
  452. ap.add_argument("--vm-winxp-login", default='Naresh', help="Windows login %(default)s")
  453. ap.add_argument("--vm-winxp-python-version", default='3.7.7', help="Windows Python version installed in the VM (default: %(default)s)")
  454. ap.add_argument("-t", "--test", action="store_true", default=False, help="Test built packages")
  455. ap.add_argument("-s", "--sign", action="store_true", default=False, help="Sign Debian package / generate Rpm repo")
  456. ap.add_argument("--no-remove", action="store_true", help="don't remove build dir")
  457. ap.add_argument("--blacklist", nargs="*", help="Modules to blacklist in package")
  458. parsed_args = ap.parse_args()
  459. logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', datefmt='%Y-%m-%d %I:%M:%S', level=log_levels[parsed_args.logging])
  460. parsed_args.odoo_dir = ROOTDIR
  461. return parsed_args
  462. def main(args):
  463. try:
  464. if args.build_tgz:
  465. _prepare_build_dir(args)
  466. docker_tgz = DockerTgz(args)
  467. docker_tgz.build()
  468. try:
  469. docker_tgz.start_test()
  470. published_files = publish(args, 'tgz', ['tar.gz', 'zip'])
  471. except Exception as e:
  472. logging.error("Won't publish the tgz release.\n Exception: %s" % str(e))
  473. if args.build_rpm:
  474. _prepare_build_dir(args)
  475. docker_rpm = DockerRpm(args)
  476. docker_rpm.build()
  477. try:
  478. docker_rpm.start_test()
  479. published_files = publish(args, 'rpm', ['rpm'])
  480. if args.sign:
  481. logging.info('Signing rpm package')
  482. rpm_sign(args, published_files[0])
  483. logging.info('Generate rpm repo')
  484. docker_rpm.gen_rpm_repo(args, published_files[0])
  485. except Exception as e:
  486. logging.error("Won't publish the rpm release.\n Exception: %s" % str(e))
  487. if args.build_deb:
  488. _prepare_build_dir(args, move_addons=False)
  489. docker_deb = DockerDeb(args)
  490. docker_deb.build()
  491. try:
  492. docker_deb.start_test()
  493. published_files = publish(args, 'deb', ['deb', 'dsc', 'changes', 'tar.xz'])
  494. gen_deb_package(args, published_files)
  495. except Exception as e:
  496. logging.error("Won't publish the deb release.\n Exception: %s" % str(e))
  497. if args.build_win:
  498. _prepare_build_dir(args, win32=True)
  499. build_exe(args)
  500. try:
  501. test_exe(args)
  502. published_files = publish(args, 'windows', ['exe'])
  503. except Exception as e:
  504. logging.error("Won't publish the exe release.\n Exception: %s" % str(e))
  505. except Exception as e:
  506. logging.error('Something bad happened ! : {}'.format(e))
  507. traceback.print_exc()
  508. finally:
  509. if args.no_remove:
  510. logging.info('Build dir "{}" not removed'.format(args.build_dir))
  511. else:
  512. if os.path.exists(args.build_dir):
  513. shutil.rmtree(args.build_dir)
  514. logging.info('Build dir %s removed' % args.build_dir)
  515. if __name__ == '__main__':
  516. args = parse_args()
  517. if os.path.exists(args.build_dir):
  518. logging.error('Build dir "%s" already exists.', args.build_dir)
  519. sys.exit(1)
  520. main(args)