forked from crocs-muni/rtt-deployment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy_backend.py
executable file
·627 lines (550 loc) · 31.1 KB
/
deploy_backend.py
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
#! /usr/bin/python3
import configparser
import json
import sys
import hashlib
import argparse
import traceback
from os.path import join
from common.rtt_deploy_utils import *
from common.rtt_constants import *
################################
# Global variables declaration #
################################
from common.rtt_utils import try_remove
def main():
parser = argparse.ArgumentParser(description='Worker deployment')
parser.add_argument('--metacentrum', dest='metacentrum', action='store_const', const=True, default=False,
help='Metacetrum deployment')
parser.add_argument('--docker', dest='docker', action='store_const', const=True, default=False,
help='Docker deployment')
parser.add_argument('--db-passwd', dest='db_passwd',
help='DB password to use, if given, skips DB registration')
parser.add_argument('--ssh-passphrase', dest='ssh_passphrase',
help='SSH passphrase to use to protect the private key')
parser.add_argument('--ssh-priv', dest='ssh_priv',
help='SSH private key to use instead of generated one, has to have .pub counterpart')
parser.add_argument('--no-db-reg', dest='no_db_reg', action='store_const', const=True, default=False,
help='Skip MySQL user registration')
parser.add_argument('--no-ssh-reg', dest='no_ssh_reg', action='store_const', const=True, default=False,
help='Skip SSH key registration at storage server')
parser.add_argument('--no-email', dest='no_email', action='store_const', const=True, default=False,
help='Skip email registration')
parser.add_argument('--no-cron', dest='no_cron', action='store_const', const=True, default=False,
help='Skip cron setup')
parser.add_argument('--sys-python', dest='sys_python', action='store_const', const=True, default=False,
help='Use system python')
parser.add_argument('--ph4-rtt', dest='ph4_rtt', action='store_const', const=True, default=False,
help='Use Ph4r05 fork of RTT - required for metacentrum')
parser.add_argument('--pub-storage', dest='public_storage', action='store_const', const=True, default=False,
help='Use public storage address')
parser.add_argument('--local-db', dest='local_db', action='store_const', const=True, default=False,
help='DB server is on the same machine')
parser.add_argument('--mysql-pass', dest='mysql_pass', action='store_const', const=True, default=False,
help='DB password to use')
parser.add_argument('--mysql-pass-file', dest='mysql_pass_file', action='store_const', const=True, default=False,
help='DB password file to use')
parser.add_argument('--deb9', dest='deb9', type=int, default=0,
help='Compile for debian 9')
parser.add_argument('--deb10', dest='deb10', type=int, default=0,
help='Compile for debian 10')
parser.add_argument('--deb11', dest='deb11', type=int, default=0,
help='Compile for debian 11')
parser.add_argument('--deb', dest='deb', type=int, default=1,
help='Compile for Debian, autodetect')
parser.add_argument('--build-only-rtt', dest='build_only_rtt', type=int, default=0,
help='Compile RTT only')
parser.add_argument('--build-only-cryptostreams', dest='build_only_cryptostreams', type=int, default=0,
help='Compile cryptostreams only')
parser.add_argument('--build-only-batteries', dest='build_only_batteries', type=int, default=0,
help='Compile batteries only')
parser.add_argument('-j', dest='buildj', type=int, default=2,
help='Parallel compilation')
parser.add_argument('--config', dest='config', default='deployment_settings.ini',
help='Path to deployment_settings.ini')
parser.add_argument('backend_id', default=None,
help='Backend ID to deploy')
args = parser.parse_args()
deploy_cfg_file = args.config
wbare = not args.metacentrum
if args.metacentrum or args.docker:
args.ph4_rtt = True
args.public_storage = True
if args.deb:
deb_ver = get_debian_version()
if not deb_ver:
raise ValueError('Debian version auto-detection failed, try using --debXX to specify the version')
if deb_ver == 9:
args.deb9 = 1
elif deb_ver == 10:
args.deb10 = 1
elif deb_ver == 11:
args.deb11 = 1
else:
raise ValueError('Unsupported Debian version: %s' % (deb_ver,))
# Get path to main config from console
if not args.backend_id:
print("\nUsage: ./deploy_backend.py <backend-id>\n")
print("<backend-id> must be entered according to config with deployment settings.\n"
" Configuration file \"{}\" must\n"
" contain one and only one section named\n"
" \"Backend-<backend-id>\"\n".format(deploy_cfg_file))
sys.exit(1)
deploy_cfg = configparser.ConfigParser()
try:
current_dir = os.path.abspath(os.path.curdir)
deploy_cfg.read(deploy_cfg_file)
if len(deploy_cfg.sections()) == 0:
raise FileNotFoundError("can't read: {}".format(deploy_cfg_file))
backend_sec = "Backend-" + args.backend_id
Backend.address = get_no_empty(deploy_cfg, backend_sec, "IPv4-Address")
Backend.rtt_files_dir = get_no_empty(deploy_cfg, backend_sec, "RTT-Files-dir")
Backend.exec_max_tests = get_no_empty(deploy_cfg, backend_sec, "Maximum-parallel-tests")
Backend.exec_test_timeout = get_no_empty(deploy_cfg, backend_sec, "Maximum-seconds-per-test")
Backend.backend_id = deploy_cfg.get(backend_sec, "backend-id", fallback=None)
Backend.backend_name = deploy_cfg.get(backend_sec, "backend-name", fallback=backend_sec)
Backend.backend_loc = deploy_cfg.get(backend_sec, "backend-loc", fallback='')
Backend.backend_longterm = deploy_cfg.get(backend_sec, "backend-longterm", fallback=1)
Backend.backend_aux = deploy_cfg.get(backend_sec, "backend-aux", fallback='{}')
Backend.log_dir = deploy_cfg.get(backend_sec, "log-dir", fallback=None)
if not Backend.backend_id:
Backend.backend_id = hashlib.md5(str(time.time()).encode('utf8')).hexdigest()
Database.address = get_no_empty(deploy_cfg, "Database", "IPv4-Address")
Database.mysql_port = get_no_empty(deploy_cfg, "Database", "MySQL-port")
Database.ssh_port = get_no_empty(deploy_cfg, "Database", "SSH-Port")
Database.ssh_root_user = get_no_empty(deploy_cfg, "Database", "SSH-Root-User")
Storage.address_private = get_no_empty(deploy_cfg, "Storage", "IPv4-Address")
Storage.address_public = deploy_cfg.get("Storage", "IPv4-Address-Public") or Storage.address_private
Storage.address = Storage.address_public if args.public_storage else Storage.address_private
Storage.ssh_root_user = get_no_empty(deploy_cfg, "Storage", "SSH-Root-User")
Storage.acc_chroot = get_no_empty(deploy_cfg, "Storage", "Storage-Chroot")
Storage.storage_user = get_no_empty(deploy_cfg, "Storage", "Storage-User")
Storage.ssh_port = get_no_empty(deploy_cfg, "Storage", "SSH-port")
except Exception as e:
print_error("Configuration file: {}".format(e))
sys.exit(1)
# Sanity checks
try:
check_paths_abs({
Backend.rtt_files_dir
})
check_paths_rel({
Backend.COMMON_FILES_DIR,
Backend.CACHE_DATA_DIR,
Backend.CACHE_CONFIG_DIR,
Backend.CREDENTIALS_DIR,
Backend.RTT_EXECUTION_DIR,
Backend.RANDOMNESS_TESTING_TOOLKIT_SRC_DIR,
Backend.RTT_STATISTICAL_BATTERIES_SRC_DIR,
})
check_files_exists({
CommonConst.BACKEND_CLEAN_CACHE_SCRIPT,
CommonConst.BACKEND_RUN_JOBS_SCRIPT
})
except AssertionError as e:
print_error("Invalid configuration. {}".format(e))
sys.exit(1)
os.makedirs(Backend.rtt_files_dir, 0o771, True)
# Defined absolute paths to directories and files
Backend.rand_test_tool_src_dir = \
join(Backend.rtt_files_dir, Backend.RANDOMNESS_TESTING_TOOLKIT_SRC_DIR)
Backend.rand_test_tool_dl_zip = \
join(Backend.rtt_files_dir, Backend.RANDOMNESS_TESTING_TOOLKIT_GIT_NAME + ".zip")
Backend.stat_batt_src_dir = \
join(Backend.rtt_files_dir, Backend.RTT_STATISTICAL_BATTERIES_SRC_DIR)
Backend.stat_batt_dl_zip = \
join(Backend.rtt_files_dir, Backend.RTT_STATISTICAL_BATTERIES_GIT_NAME + ".zip")
Backend.common_files_dir = \
join(Backend.rtt_files_dir, Backend.COMMON_FILES_DIR)
Backend.cache_conf_dir = \
join(Backend.rtt_files_dir, Backend.CACHE_CONFIG_DIR)
Backend.cache_data_dir = \
join(Backend.rtt_files_dir, Backend.CACHE_DATA_DIR)
Backend.credentials_dir = \
join(Backend.rtt_files_dir, Backend.CREDENTIALS_DIR)
Backend.rtt_exec_dir = \
join(Backend.rtt_files_dir, Backend.RTT_EXECUTION_DIR)
Backend.rtt_exec_nist_exp_dir = \
join(Backend.rtt_exec_dir, Backend.NIST_STS_EXPERIMENTS_DIR)
Backend.rtt_exec_nist_temp_dir = \
join(Backend.rtt_exec_dir, Backend.NIST_STS_TEMPLATES_DIR)
Backend.ssh_store_pkey = \
join(Backend.credentials_dir, Backend.SSH_CREDENTIALS_KEY)
Backend.ssh_store_pubkey = \
join(Backend.credentials_dir, Backend.SSH_CREDENTIALS_KEY + ".pub")
Backend.run_jobs_path = \
join(Backend.rtt_files_dir, Backend.RUN_JOBS_SCRIPT)
Backend.clean_cache_path = \
join(Backend.rtt_files_dir, Backend.CLEAN_CACHE_SCRIPT)
Backend.rtt_binary_path = \
join(Backend.rtt_exec_dir, os.path.basename(Backend.RTT_BINARY_PATH))
Backend.cryptostreams_binary_dir = Backend.rtt_exec_dir
Backend.mysql_cred_ini_path = \
join(Backend.credentials_dir, Backend.MYSQL_CREDENTIALS_FILE_INI)
Backend.mysql_cred_json_path = \
join(Backend.credentials_dir, Backend.MYSQL_CREDENTIALS_FILE_JSON)
Backend.ssh_cred_ini_path = \
join(Backend.credentials_dir, Backend.SSH_CREDENTIALS_FILE)
Backend.config_ini_path = \
join(Backend.rtt_files_dir, Backend.BACKEND_CONFIG_FILE)
wgrp = Backend.RTT_ADMIN_GROUP
try:
# Install essential packages
install_debian_pkgs(["acl", "sudo", "wget", "unzip", "rsync", "git", "curl", "openssh-client"])
# Adding rtt-admin group that is intended to manage
# directories and files related to rtt without root access
exec_sys_call_check("groupadd {}".format(Backend.RTT_ADMIN_GROUP), acc_codes=[0, 9])
# Remove directories that was created previously
if os.path.exists(Backend.rtt_files_dir):
shutil.rmtree(Backend.rtt_files_dir)
# Create and copy needed files into rtt-files
create_dir(Backend.rtt_files_dir, 0o2770, grp=wgrp)
# Set ACL on top directory - ensures all new files will have correct permissions
exec_sys_call_check("setfacl -R -d -m g::rwx {}".format(Backend.rtt_files_dir))
exec_sys_call_check("setfacl -R -d -m o::--- {}".format(Backend.rtt_files_dir))
create_dir(Backend.cache_conf_dir, 0o2770, grp=wgrp)
create_dir(Backend.cache_data_dir, 0o2770, grp=wgrp)
create_dir(Backend.credentials_dir, 0o2770, grp=wgrp)
create_dir(Backend.rtt_exec_dir, 0o2770, grp=wgrp)
shutil.copy(CommonConst.BACKEND_CLEAN_CACHE_SCRIPT, Backend.clean_cache_path)
chmod_chown(Backend.clean_cache_path, 0o770, grp=wgrp)
shutil.copy(CommonConst.BACKEND_RUN_JOBS_SCRIPT, Backend.run_jobs_path)
chmod_chown(Backend.run_jobs_path, 0o770, grp=wgrp)
if os.path.exists(Backend.common_files_dir):
shutil.rmtree(Backend.common_files_dir)
shutil.copytree(CommonConst.COMMON_FILES_DIR, Backend.common_files_dir)
recursive_chmod_chown(Backend.common_files_dir, mod_f=0o660, mod_d=0o2770, grp=wgrp)
# Install packages
install_debian_pkg("mailutils")
if not args.no_email:
install_debian_pkg("postfix")
install_debian_pkgs(["libmysqlcppconn-dev"])
if args.deb10 or args.deb11:
install_debian_pkgs(["libunbound-dev", "libunistring-dev"])
if args.deb9:
install_debian_pkgs(["libffi-dev"])
install_debian_pkg_at_least_one(["default-libmysqlclient-dev", "libmysqlclient-dev"])
python3, pip3 = setup_python3(use_system=args.sys_python, buildj=args.buildj)
install_python_pkg("pip", no_cache=False, pip3=pip3)
install_python_pkgs([
"paramiko", "cryptography",
"mysqlclient", "sarge", "requests", "shellescape", "coloredlogs", "filelock",
"jsonpath-ng", "sshtunnel", "randomgen", "numpy", "booltest", "booltest-rtt", "rtt-data-gen",
], pip3=pip3)
# Get current versions of needed tools from git
# Statistical batteries
if os.path.exists(Backend.stat_batt_src_dir):
shutil.rmtree(Backend.stat_batt_src_dir)
exec_sys_call_check("wget {} -O {}".format(Backend.RTT_STATISTICAL_BATTERIES_ZIP_URL,
Backend.stat_batt_dl_zip))
exec_sys_call_check("unzip {} -d {}".format(Backend.stat_batt_dl_zip,
Backend.rtt_files_dir))
os.remove(Backend.stat_batt_dl_zip)
os.rename(join(Backend.rtt_files_dir, Backend.RTT_STATISTICAL_BATTERIES_GIT_NAME),
Backend.stat_batt_src_dir)
# Randomness testing toolkit
if os.path.exists(Backend.rand_test_tool_src_dir):
shutil.rmtree(Backend.rand_test_tool_src_dir)
if args.ph4_rtt:
exec_sys_call_check("git clone --recursive https://github.com/ph4r05/randomness-testing-toolkit.git %s"
% Backend.rand_test_tool_src_dir)
else:
exec_sys_call_check("wget {} -O {}".format(Backend.RANDOMNESS_TESTING_TOOLKIT_ZIP_URL,
Backend.rand_test_tool_dl_zip))
exec_sys_call_check("unzip {} -d {}".format(Backend.rand_test_tool_dl_zip,
Backend.rtt_files_dir))
os.remove(Backend.rand_test_tool_dl_zip)
os.rename(join(Backend.rtt_files_dir, Backend.RANDOMNESS_TESTING_TOOLKIT_GIT_NAME),
Backend.rand_test_tool_src_dir)
# Change into directory rtt-src and rtt-stat-batt-src and call make and ./INSTALL respectively.
# Build statistical batteries
os.chdir(Backend.stat_batt_src_dir)
build_only_used = args.build_only_rtt or args.build_only_cryptostreams or args.build_only_batteries
build_batteries = not args.build_only_rtt and not args.build_only_cryptostreams
build_rtt = not args.build_only_cryptostreams and not args.build_only_batteries
build_cs = not args.build_only_rtt and not args.build_only_batteries
if build_batteries:
install_debian_pkgs(["libgsl0-dev", "build-essential", "autotools-dev", "automake", "autoconf", "libtool"])
build_static_dieharder(Backend.stat_batt_src_dir, buildj=args.buildj, deb11=args.deb11)
exec_sys_call_check("chmod +x INSTALL")
exec_sys_call_check("./INSTALL", env=get_make_env(buildj=args.buildj))
recursive_chmod_chown(Backend.stat_batt_src_dir, mod_f=0o660, mod_d=0o2770, grp=wgrp)
chmod_chown(Backend.DIEHARDER_BINARY_PATH, 0o770)
chmod_chown(Backend.NIST_STS_BINARY_PATH, 0o770)
chmod_chown(Backend.TESTU01_BINARY_PATH, 0o770)
os.chdir(Backend.stat_batt_src_dir)
# Build randomness testing toolkit
os.chdir(Backend.rand_test_tool_src_dir)
rtt_env = None
if args.ph4_rtt:
# p11 libs required by gnutls, required by libmaria
p11libs = None
try:
p11libs = build_p11_lib(buildj=args.buildj) if args.deb10 or args.deb11 else None
except Exception as e:
logger.warning("P11 build failed, using dynamic: %s" % (e,), exc_info=e)
lib_data = copy_rtt_libs(Backend.rand_test_tool_src_dir)
rtt_env = get_rtt_build_env(Backend.rand_test_tool_src_dir, lib_data, args.deb10, args.deb11, p11libs)
os.chdir(Backend.rand_test_tool_src_dir)
try:
if build_rtt:
exec_sys_call_check("make -j%s" % (args.buildj,), env=rtt_env, acc_codes=[0, 1, 2])
except Exception as e:
if args.ph4_rtt:
logger.warning("Could not build RTT statically, trying dynamic build")
print("[ERROR] Could not build RTT statically, trying dynamic build")
if build_rtt:
exec_sys_call_check("make -j%s" % (args.buildj,), acc_codes=[0, 1, 2])
else:
raise e
recursive_chmod_chown(Backend.rand_test_tool_src_dir, mod_f=0o660, mod_d=0o2770, grp=wgrp)
chmod_chown(Backend.RTT_BINARY_PATH, 0o770)
# Build cryptostreams
cstreams = None
if build_cs:
cstreams = cryptostreams_complete_deploy(ph4=args.ph4_rtt,
res_bin_dir=Backend.cryptostreams_binary_dir,
src_dir=Backend.rtt_files_dir,
buildj=args.buildj)
# Build finished, go into original directory
os.chdir(current_dir)
if build_only_used:
logger.info("Using --build-only-x, terminating call")
return
# Link RTT binary into execution directory
os.symlink(join(Backend.rand_test_tool_src_dir, Backend.RTT_BINARY_PATH),
Backend.rtt_binary_path)
# Copy needed directories and files into execution directory
shutil.copytree(join(Backend.stat_batt_src_dir, Backend.NIST_STS_TEMPLATES_DIR),
join(Backend.rtt_exec_dir,
os.path.basename(Backend.NIST_STS_TEMPLATES_DIR)))
shutil.copytree(join(Backend.stat_batt_src_dir, Backend.NIST_STS_EXPERIMENTS_DIR),
join(Backend.rtt_exec_dir,
os.path.basename(Backend.NIST_STS_EXPERIMENTS_DIR)))
# Booltest-rtt, rtt-data-gen
try:
booltest_rtt_binary = subprocess.check_output(['which', 'booltest_rtt']).decode('utf8').strip()
except Exception as e:
booltest_rtt_binary = ""
try:
rtt_data_gen_binary = subprocess.check_output(['which', 'rtt-data-gen']).decode('utf8').strip()
except Exception as e:
rtt_data_gen_binary = ""
if booltest_rtt_binary and os.path.exists(booltest_rtt_binary):
_spath = os.path.join(Backend.rtt_exec_dir, 'booltest_rtt')
try_remove(_spath)
os.symlink(booltest_rtt_binary, _spath)
if rtt_data_gen_binary and os.path.exists(rtt_data_gen_binary):
_spath = os.path.join(Backend.rtt_exec_dir, 'rtt-data-gen')
try_remove(_spath)
os.symlink(rtt_data_gen_binary, _spath)
rtt_settings = {
"toolkit-settings": {
"logger": {
"dir-prefix": join(Backend.rtt_files_dir, Backend.EXEC_LOGS_TOP_DIR),
"run-log-dir": Backend.EXEC_LOGS_RUN_LOG_DIR,
"dieharder-dir": Backend.EXEC_LOGS_DIEHARDER_DIR,
"nist-sts-dir": Backend.EXEC_LOGS_NIST_STS_DIR,
"tu01-smallcrush-dir": Backend.EXEC_LOGS_SMALLCRUSH_DIR,
"tu01-crush-dir": Backend.EXEC_LOGS_CRUSH_DIR,
"tu01-bigcrush-dir": Backend.EXEC_LOGS_BIGCRUSH_DIR,
"tu01-rabbit-dir": Backend.EXEC_LOGS_RABBIT_DIR,
"tu01-alphabit-dir": Backend.EXEC_LOGS_ALPHABIT_DIR,
"tu01-blockalphabit-dir": Backend.EXEC_LOGS_BLOCKALPHABIT_DIR
},
"result-storage": {
"file": {
"main-file": join(Backend.rtt_files_dir, Backend.EXEC_REPS_MAIN_FILE),
"dir-prefix": join(Backend.rtt_files_dir, Backend.EXEC_REPS_TOP_DIR),
"dieharder-dir": Backend.EXEC_REPS_DIEHARDER_DIR,
"nist-sts-dir": Backend.EXEC_REPS_NIST_STS_DIR,
"tu01-smallcrush-dir": Backend.EXEC_REPS_SMALLCRUSH_DIR,
"tu01-crush-dir": Backend.EXEC_REPS_CRUSH_DIR,
"tu01-bigcrush-dir": Backend.EXEC_REPS_BIGCRUSH_DIR,
"tu01-rabbit-dir": Backend.EXEC_REPS_RABBIT_DIR,
"tu01-alphabit-dir": Backend.EXEC_REPS_ALPHABIT_DIR,
"tu01-blockalphabit-dir": Backend.EXEC_REPS_ALPHABIT_DIR
},
"mysql-db": {
"address": Database.address,
"port": Database.mysql_port,
"name": Database.MYSQL_DB_NAME,
"credentials-file": Backend.mysql_cred_json_path
}
},
"binaries": {
"nist-sts": join(Backend.stat_batt_src_dir, Backend.NIST_STS_BINARY_PATH),
"dieharder": join(Backend.stat_batt_src_dir, Backend.DIEHARDER_BINARY_PATH),
"testu01": join(Backend.stat_batt_src_dir, Backend.TESTU01_BINARY_PATH),
"cryptostreams": cstreams[0],
},
"miscellaneous": {
"nist-sts": {
"main-result-dir": join(Backend.rtt_exec_dir, Backend.NIST_MAIN_RESULT_DIR)
}
},
"execution": {
"max-parallel-tests": int(Backend.exec_max_tests),
"test-timeout-seconds": int(Backend.exec_test_timeout)
},
"booltest": {
"default-cli": "--no-summary --json-out --log-prints --top 128 --no-comb-and --only-top-comb --only-top-deg --no-term-map --topterm-heap --topterm-heap-k 256 --best-x-combs 512",
"strategies": [
{
"name": "v1",
"cli": "",
"variations": [
{
"bl": [128, 256, 384, 512],
"deg": [1, 2, 3],
"cdeg": [1, 2, 3],
"exclusions": []
}
]
},
{
"name": "halving",
"cli": "--halving",
"variations": [
{
"bl": [128, 256, 384, 512],
"deg": [1, 2, 3],
"cdeg": [1, 2, 3],
"exclusions": []
}
]
}
]
}
}
}
with open(join(Backend.rtt_exec_dir, Backend.RTT_SETTINGS_JSON), "w") as f:
json.dump(rtt_settings, f, indent=4)
# Get email configuration
# Add configuration to file
# inet_interface = loopback-only
# inet_protocol = ipv4
if not args.no_email:
with open(Backend.POSTFIX_CFG_PATH) as mail_cfg:
for line in mail_cfg.readlines():
if line.startswith(Backend.POSTFIX_HOST_OPT):
Backend.sender_email = line.split(sep=" = ")[1]
if not args.no_email and Backend.sender_email is None:
print_error("can't find option {} in file {}"
.format(Backend.POSTFIX_CFG_PATH, Backend.POSTFIX_HOST_OPT))
sys.exit(1)
Backend.sender_email = ("root@" + Backend.sender_email) if not args.no_email else '[email protected]'
# Create backend configuration file
backend_ini_cfg = configparser.ConfigParser()
backend_ini_cfg.add_section("MySQL-Database")
backend_ini_cfg.set("MySQL-Database", "Address", Database.address)
backend_ini_cfg.set("MySQL-Database", "Port", Database.mysql_port)
backend_ini_cfg.set("MySQL-Database", "Name", Database.MYSQL_DB_NAME)
backend_ini_cfg.set("MySQL-Database", "Credentials-file",
Backend.mysql_cred_ini_path)
backend_ini_cfg.add_section("Local-cache")
backend_ini_cfg.set("Local-cache", "Data-directory", Backend.cache_data_dir)
backend_ini_cfg.set("Local-cache", "Config-directory", Backend.cache_conf_dir)
backend_ini_cfg.add_section("Backend")
backend_ini_cfg.set("Backend", "Sender-email", Backend.sender_email)
backend_ini_cfg.set("Backend", "Maximum-seconds-per-test", Backend.exec_test_timeout)
backend_ini_cfg.set("Backend", "Maximum-parallel-tests", Backend.exec_max_tests)
backend_ini_cfg.set("Backend", "backend-id", Backend.backend_id)
backend_ini_cfg.set("Backend", "backend-name", Backend.backend_name)
backend_ini_cfg.set("Backend", "backend-loc", Backend.backend_loc)
backend_ini_cfg.set("Backend", "backend-longterm", Backend.backend_longterm)
backend_ini_cfg.set("Backend", "backend-aux", Backend.backend_aux)
if Backend.log_dir:
backend_ini_cfg.set("Backend", "log-dir", Backend.log_dir)
backend_ini_cfg.add_section("Storage")
backend_ini_cfg.set("Storage", "Address", Storage.address)
backend_ini_cfg.set("Storage", "Port", Storage.ssh_port)
backend_ini_cfg.set("Storage", "Data-directory",
join(Storage.CHROOT_HOME_DIR, Storage.CHROOT_DATA_DIR))
backend_ini_cfg.set("Storage", "Config-directory",
join(Storage.CHROOT_HOME_DIR, Storage.CHROOT_CONF_DIR))
backend_ini_cfg.set("Storage", "Credentials-file", Backend.ssh_cred_ini_path)
backend_ini_cfg.add_section("RTT-Binary")
backend_ini_cfg.set("RTT-Binary", "Binary-path",
Backend.rtt_binary_path)
backend_ini_cfg.set("RTT-Binary", "booltest-rtt-path", booltest_rtt_binary) # TODO: auto-detect
backend_ini_cfg.set("RTT-Binary", "rtt-data-gen-path", rtt_data_gen_binary) # TODO: auto-detect
with open(Backend.config_ini_path, "w") as f:
backend_ini_cfg.write(f)
from common.rtt_registration import register_db_user
from common.rtt_registration import add_authorized_key_to_server
from common.rtt_registration import get_db_reg_command
# Register machine to database
db_pwd = args.db_passwd if args.db_passwd else get_rnd_pwd()
write_db_credentials(Backend.MYSQL_BACKEND_USER, db_pwd, Backend.mysql_cred_ini_path)
write_db_credentials_json(Backend.MYSQL_BACKEND_USER, db_pwd, Backend.mysql_cred_json_path)
post_install_info = []
db_addr_from = Backend.address if wbare else '%'
if not args.no_db_reg:
db_def_passwd = get_mysql_password_args(args)
register_db_user(Database.ssh_root_user, Database.address, Database.ssh_port,
Backend.MYSQL_BACKEND_USER, db_pwd, db_addr_from,
Database.MYSQL_ROOT_USERNAME, Database.MYSQL_DB_NAME,
priv_select=True, priv_insert=True, priv_update=True, priv_create=True,
db_def_passwd=db_def_passwd, db_no_pass=args.local_db)
else:
sql = get_db_reg_command(username=Database.MYSQL_ROOT_USERNAME, password=None,
db_name=Database.MYSQL_DB_NAME, reg_name=Backend.MYSQL_BACKEND_USER,
reg_address=db_addr_from, reg_pwd=db_pwd,
priv_select=True, priv_insert=True, priv_update=True, priv_create=True,
db_host=Database.address, db_port=Database.ssh_port)
post_install_info.append('* DB user not registered to the DB server. Make sure the following user:password has access: ')
post_install_info.append(sql + '\n')
# Register machine to storage
key_pwd = args.ssh_passphrase if args.ssh_passphrase else get_rnd_pwd()
if args.ssh_priv:
shutil.copy(args.ssh_priv, Backend.ssh_store_pkey)
shutil.copy(args.ssh_priv + '.pub', Backend.ssh_store_pubkey)
else:
exec_sys_call_check("ssh-keygen -q -b 2048 -t rsa -N {} -f {}"
.format(key_pwd, Backend.ssh_store_pkey))
chmod_chown(Backend.ssh_store_pkey, 0o600, grp=wgrp)
chmod_chown(Backend.ssh_store_pubkey, 0o660, grp=wgrp)
with open(Backend.ssh_store_pubkey) as f:
pub_key = f.read().rstrip()
write_ssh_credentials(Storage.storage_user, key_pwd, Backend.ssh_store_pkey, Backend.ssh_cred_ini_path)
authorized_keys_path = "{}{}".format(Storage.acc_chroot, join(Storage.CHROOT_HOME_DIR, Storage.SSH_DIR, Storage.AUTH_KEYS_FILE))
if args.no_ssh_reg:
post_install_info.append('* Register the following key on the storage server at %s' % (authorized_keys_path,))
post_install_info.append('%s' % (pub_key,))
post_install_info.append('')
else:
add_authorized_key_to_server(Storage.ssh_root_user, Storage.address, Storage.ssh_port,
pub_key, authorized_keys_path)
# Add cron jobs for cache cleaning and job running script
if not args.no_cron:
install_debian_pkg("cron")
add_cron_job(Backend.clean_cache_path, Backend.config_ini_path,
join(Backend.rtt_files_dir, Backend.CLEAN_CACHE_LOG),
python3=python3)
add_cron_job(Backend.run_jobs_path, Backend.config_ini_path,
join(Backend.rtt_files_dir, Backend.RUN_JOBS_LOG),
python3=python3)
exec_sys_call_check("service cron restart")
if not args.docker:
service_enable("cron.service")
try:
adj_workers = '/root/adjust_workers.py'
os.chdir(current_dir)
shutil.copy('files/adjust_workers.py', adj_workers)
chmod_chown(adj_workers, 0o770, grp=wgrp)
except Exception as e:
logger.error("Could not install adjust_workers: %s" % (e,))
if post_install_info:
print('='*80)
for x in post_install_info:
print(x)
except BaseException as e:
print_error("{}. Fix error and run the script again.".format(e))
traceback.print_exc()
return 2
if __name__ == "__main__":
print_start("deploy_backend")
r = main() or 0
print_end()
sys.exit(r)