]> git.ipfire.org Git - thirdparty/pdns.git/blob - tasks.py
Merge pull request #13465 from franklouwers/master
[thirdparty/pdns.git] / tasks.py
1 from invoke import task
2 from invoke.exceptions import Failure, UnexpectedExit
3
4 import os
5 import sys
6 import time
7
8 auth_backend_ip_addr = os.getenv('AUTH_BACKEND_IP_ADDR', '127.0.0.1')
9
10 clang_version = os.getenv('CLANG_VERSION', '13')
11 quiche_version = '0.18.0'
12 quiche_hash = 'eb242a14c4d801a90b57b6021dd29f7a62099f3a4d7a7ba889e105f8328e6c1f'
13
14 all_build_deps = [
15 'ccache',
16 'libboost-all-dev',
17 'libluajit-5.1-dev',
18 'libsodium-dev',
19 'libssl-dev', # This will install libssl 1.1 on Debian 11 and libssl3 on Debian 12
20 'libsystemd-dev',
21 'libtool',
22 'make',
23 'pkg-config',
24 'python3-venv',
25 'systemd',
26 ]
27 git_build_deps = [
28 'autoconf',
29 'automake',
30 'bison',
31 'bzip2',
32 'curl',
33 'flex',
34 'git',
35 'ragel'
36 ]
37 auth_build_deps = [ # FIXME: perhaps we should be stealing these from the debian (Ubuntu) control file
38 'default-libmysqlclient-dev',
39 'libcdb-dev',
40 'libcurl4-openssl-dev',
41 'libgeoip-dev',
42 'libkrb5-dev',
43 'libldap2-dev',
44 'liblmdb-dev',
45 'libmaxminddb-dev',
46 'libp11-kit-dev',
47 'libpq-dev',
48 'libsqlite3-dev',
49 'libyaml-cpp-dev',
50 'libzmq3-dev',
51 'ruby-bundler',
52 'ruby-dev',
53 'sqlite3',
54 'unixodbc-dev',
55 'cmake',
56 ]
57 rec_build_deps = [
58 'libcap-dev',
59 'libfstrm-dev',
60 'libsnmp-dev',
61 ]
62 rec_bulk_deps = [
63 'curl',
64 'libboost-all-dev',
65 'libcap2',
66 'libfstrm0',
67 'libluajit-5.1-2',
68 '"libsnmp[1-9]+"',
69 'libsodium23',
70 'libsystemd0',
71 'moreutils',
72 'pdns-tools',
73 'unzip',
74 ]
75 dnsdist_build_deps = [
76 'libcap-dev',
77 'libcdb-dev',
78 'libedit-dev',
79 'libfstrm-dev',
80 'libgnutls28-dev',
81 'libh2o-evloop-dev',
82 'liblmdb-dev',
83 'libnghttp2-dev',
84 'libre2-dev',
85 'libsnmp-dev',
86 ]
87 auth_test_deps = [ # FIXME: we should be generating some of these from shlibdeps in build
88 'authbind',
89 'bc',
90 'bind9utils',
91 'curl',
92 'default-jre-headless',
93 'dnsutils',
94 'faketime',
95 'gawk',
96 'krb5-user',
97 'ldnsutils',
98 '"libboost-serialization1.7[1-9]+"',
99 'libcdb1',
100 'libcurl4',
101 'libgeoip1',
102 'libkrb5-3',
103 '"libldap-2.[1-9]+"',
104 'liblmdb0',
105 'libluajit-5.1-2',
106 'libmaxminddb0',
107 'libnet-dns-perl',
108 'libp11-kit0',
109 'libpq5',
110 'libsodium23',
111 'libsqlite3-dev',
112 'libsystemd0',
113 '"libyaml-cpp0.[1-9]+"',
114 'libzmq3-dev',
115 'lmdb-utils',
116 'prometheus',
117 'ruby-bundler',
118 'ruby-dev',
119 'socat',
120 'softhsm2',
121 'unbound-host',
122 'unixodbc',
123 'wget',
124 ]
125 doc_deps = [
126 'autoconf',
127 'automake',
128 'bison',
129 'curl',
130 'flex',
131 'g++',
132 'git',
133 'latexmk',
134 'libboost-all-dev',
135 'libedit-dev',
136 'libluajit-5.1-dev',
137 'libssl-dev',
138 'make',
139 'pkg-config',
140 'python3-venv',
141 'ragel',
142 'rsync',
143 ]
144 doc_deps_pdf = [
145 'texlive-binaries',
146 'texlive-formats-extra',
147 'texlive-latex-extra',
148 ]
149
150 @task
151 def apt_fresh(c):
152 c.sudo('apt-get update')
153 c.sudo('apt-get -y --allow-downgrades dist-upgrade')
154
155 @task
156 def install_clang(c):
157 """
158 install clang and llvm
159 """
160 c.sudo(f'apt-get -y --no-install-recommends install clang-{clang_version} llvm-{clang_version}')
161
162 @task
163 def install_clang_tidy_tools(c):
164 c.sudo(f'apt-get -y --no-install-recommends install clang-tidy-{clang_version} clang-tools-{clang_version} bear python3-yaml')
165
166 @task
167 def install_clang_runtime(c):
168 # this gives us the symbolizer, for symbols in asan/ubsan traces
169 c.sudo(f'apt-get -y --no-install-recommends install clang-{clang_version}')
170
171 @task
172 def ci_install_rust(c, repo):
173 c.sudo(f'{repo}/builder-support/helpers/install_rust.sh')
174
175 def install_libdecaf(c, product):
176 c.run('git clone https://git.code.sf.net/p/ed448goldilocks/code /tmp/libdecaf')
177 with c.cd('/tmp/libdecaf'):
178 c.run('git checkout 41f349')
179 c.run(f'CC={get_c_compiler()} CXX={get_cxx_compiler()} '
180 'cmake -B build '
181 '-DCMAKE_INSTALL_PREFIX=/usr/local '
182 '-DCMAKE_INSTALL_LIBDIR=lib '
183 '-DENABLE_STATIC=OFF '
184 '-DENABLE_TESTS=OFF '
185 '-DCMAKE_C_FLAGS="-Wno-sizeof-array-div -Wno-array-parameter" .')
186 c.run('make -C build')
187 c.run('sudo make -C build install')
188 c.sudo(f'mkdir -p /opt/{product}/libdecaf')
189 c.sudo(f'cp /usr/local/lib/libdecaf.so* /opt/{product}/libdecaf/.')
190
191 @task
192 def install_doc_deps(c):
193 c.sudo('apt-get install -y ' + ' '.join(doc_deps))
194
195 @task
196 def install_doc_deps_pdf(c):
197 c.sudo('apt-get install -y ' + ' '.join(doc_deps_pdf))
198
199 @task
200 def install_auth_build_deps(c):
201 c.sudo('apt-get install -y --no-install-recommends ' + ' '.join(all_build_deps + git_build_deps + auth_build_deps))
202 if os.getenv('DECAF_SUPPORT', 'no') == 'yes':
203 install_libdecaf(c, 'pdns-auth')
204
205 def is_coverage_enabled():
206 sanitizers = os.getenv('SANITIZERS')
207 if sanitizers:
208 sanitizers = sanitizers.split('+')
209 if 'tsan' in sanitizers:
210 return False
211 return os.getenv('COVERAGE') == 'yes'
212
213 def get_coverage():
214 return '--enable-coverage=clang' if is_coverage_enabled() else ''
215
216 @task
217 def install_coverage_deps(c):
218 if is_coverage_enabled():
219 c.sudo(f'apt-get install -y --no-install-recommends llvm-{clang_version}')
220
221 @task
222 def generate_coverage_info(c, binary, outputDir):
223 if is_coverage_enabled():
224 version = os.getenv('BUILDER_VERSION')
225 c.run(f'llvm-profdata-{clang_version} merge -sparse -o {outputDir}/temp.profdata /tmp/code-*.profraw')
226 c.run(f'llvm-cov-{clang_version} export --format=lcov --ignore-filename-regex=\'^/usr/\' -instr-profile={outputDir}/temp.profdata -object {binary} > {outputDir}/coverage.lcov')
227 c.run(f'{outputDir}/.github/scripts/normalize_paths_in_coverage.py {outputDir} {version} {outputDir}/coverage.lcov {outputDir}/normalized_coverage.lcov')
228 c.run(f'mv {outputDir}/normalized_coverage.lcov {outputDir}/coverage.lcov')
229
230 def setup_authbind(c):
231 c.sudo('touch /etc/authbind/byport/53')
232 c.sudo('chmod 755 /etc/authbind/byport/53')
233
234 auth_backend_test_deps = dict(
235 gsqlite3=['sqlite3'],
236 gmysql=['default-libmysqlclient-dev'],
237 gpgsql=['libpq-dev'],
238 lmdb=[],
239 remote=[],
240 bind=[],
241 geoip=[],
242 lua2=[],
243 tinydns=[],
244 authpy=[],
245 godbc_sqlite3=['libsqliteodbc'],
246 godbc_mssql=['freetds-bin','tdsodbc'],
247 ldap=[],
248 geoip_mmdb=[]
249 )
250
251 @task(help={'backend': 'Backend to install test deps for, e.g. gsqlite3; can be repeated'}, iterable=['backend'], optional=['backend'])
252 def install_auth_test_deps(c, backend): # FIXME: rename this, we do way more than apt-get
253 extra=[]
254 for b in backend:
255 extra.extend(auth_backend_test_deps[b])
256 c.sudo('DEBIAN_FRONTEND=noninteractive apt-get -y install ' + ' '.join(extra+auth_test_deps))
257
258 c.run('chmod +x /opt/pdns-auth/bin/* /opt/pdns-auth/sbin/*')
259 # c.run('''if [ ! -e $HOME/bin/jdnssec-verifyzone ]; then
260 # wget https://github.com/dblacka/jdnssec-tools/releases/download/0.14/jdnssec-tools-0.14.tar.gz
261 # tar xfz jdnssec-tools-0.14.tar.gz -C $HOME
262 # rm jdnssec-tools-0.14.tar.gz
263 # fi
264 # echo 'export PATH=$HOME/jdnssec-tools-0.14/bin:$PATH' >> $BASH_ENV''') # FIXME: why did this fail with no error?
265 c.run('touch regression-tests/tests/verify-dnssec-zone/allow-missing regression-tests.nobackend/rectify-axfr/allow-missing') # FIXME: can this go?
266 # FIXME we may want to start a background recursor here to make ALIAS tests more robust
267 setup_authbind(c)
268
269 if os.getenv('DECAF_SUPPORT', 'no') == 'yes':
270 # Copy libdecaf out
271 c.sudo('mkdir -p /usr/local/lib')
272 c.sudo('cp /opt/pdns-auth/libdecaf/libdecaf.so* /usr/local/lib/.')
273
274 @task
275 def install_rec_bulk_deps(c): # FIXME: rename this, we do way more than apt-get
276 c.sudo('apt-get --no-install-recommends -y install ' + ' '.join(rec_bulk_deps))
277 c.run('chmod +x /opt/pdns-recursor/bin/* /opt/pdns-recursor/sbin/*')
278
279 @task
280 def install_rec_test_deps(c): # FIXME: rename this, we do way more than apt-get
281 c.sudo('apt-get --no-install-recommends install -y ' + ' '.join(rec_bulk_deps) + ' \
282 pdns-server pdns-backend-bind daemontools \
283 jq libfaketime lua-posix lua-socket bc authbind \
284 python3-venv python3-dev default-libmysqlclient-dev libpq-dev \
285 protobuf-compiler snmpd prometheus')
286
287 c.run('chmod +x /opt/pdns-recursor/bin/* /opt/pdns-recursor/sbin/*')
288
289 setup_authbind(c)
290
291 c.run('sed "s/agentxperms 0700 0755 recursor/agentxperms 0777 0755/g" regression-tests.recursor-dnssec/snmpd.conf | sudo tee /etc/snmp/snmpd.conf')
292 c.sudo('/etc/init.d/snmpd restart')
293 time.sleep(5)
294 c.sudo('chmod 755 /var/agentx')
295
296 @task
297 def install_dnsdist_test_deps(c): # FIXME: rename this, we do way more than apt-get
298 c.sudo('apt-get install -y \
299 libluajit-5.1-2 \
300 libboost-all-dev \
301 libcap2 \
302 libcdb1 \
303 libcurl4-openssl-dev \
304 libfstrm0 \
305 libgnutls30 \
306 libh2o-evloop0.13 \
307 liblmdb0 \
308 libnghttp2-14 \
309 "libre2-[1-9]+" \
310 libssl-dev \
311 libsystemd0 \
312 libsodium23 \
313 lua-socket \
314 patch \
315 protobuf-compiler \
316 python3-venv snmpd prometheus')
317 c.run('sed "s/agentxperms 0700 0755 dnsdist/agentxperms 0777 0755/g" regression-tests.dnsdist/snmpd.conf | sudo tee /etc/snmp/snmpd.conf')
318 c.sudo('/etc/init.d/snmpd restart')
319 time.sleep(5)
320 c.sudo('chmod 755 /var/agentx')
321
322 @task
323 def install_rec_build_deps(c):
324 c.sudo('apt-get install -y --no-install-recommends ' + ' '.join(all_build_deps + git_build_deps + rec_build_deps))
325
326 @task
327 def install_dnsdist_build_deps(c):
328 c.sudo('apt-get install -y --no-install-recommends ' + ' '.join(all_build_deps + git_build_deps + dnsdist_build_deps))
329
330 @task
331 def ci_autoconf(c):
332 c.run('autoreconf -vfi')
333
334 @task
335 def ci_docs_rec_generate(c):
336 c.run('python3 generate.py')
337
338 @task
339 def ci_docs_build(c):
340 c.run('make -f Makefile.sphinx -C docs html')
341
342 @task
343 def ci_docs_build_pdf(c):
344 c.run('make -f Makefile.sphinx -C docs latexpdf')
345
346 @task
347 def ci_docs_upload_master(c, docs_host, pdf, username, product, directory=""):
348 rsync_cmd = " ".join([
349 "rsync",
350 "--checksum",
351 "--recursive",
352 "--verbose",
353 "--no-p",
354 "--chmod=g=rwX",
355 "--exclude '*~'",
356 ])
357 c.run(f"{rsync_cmd} --delete ./docs/_build/{product}-html-docs/ {username}@{docs_host}:{directory}")
358 c.run(f"{rsync_cmd} ./docs/_build/{product}-html-docs.tar.bz2 {username}@{docs_host}:{directory}/html-docs.tar.bz2")
359 c.run(f"{rsync_cmd} ./docs/_build/latex/{pdf} {username}@{docs_host}:{directory}")
360
361 @task
362 def ci_docs_add_ssh(c, ssh_key, host_key):
363 c.run('mkdir -m 700 -p ~/.ssh')
364 c.run(f'echo "{ssh_key}" > ~/.ssh/id_ed25519')
365 c.run('chmod 600 ~/.ssh/id_ed25519')
366 c.run(f'echo "{host_key}" > ~/.ssh/known_hosts')
367
368
369 def get_sanitizers():
370 sanitizers = os.getenv('SANITIZERS', '')
371 if sanitizers != '':
372 sanitizers = sanitizers.split('+')
373 sanitizers = ['--enable-' + sanitizer for sanitizer in sanitizers]
374 sanitizers = ' '.join(sanitizers)
375 return sanitizers
376
377 def get_unit_tests(auth=False):
378 if os.getenv('UNIT_TESTS') != 'yes':
379 return ''
380 return '--enable-unit-tests --enable-backend-unit-tests' if auth else '--enable-unit-tests'
381
382 def get_build_concurrency(default=8):
383 return os.getenv('CONCURRENCY', default)
384
385 def get_fuzzing_targets():
386 return '--enable-fuzz-targets' if os.getenv('FUZZING_TARGETS') == 'yes' else ''
387
388 def is_compiler_clang():
389 compiler = os.getenv('COMPILER', 'clang')
390 return compiler == 'clang'
391
392 def get_c_compiler():
393 return f'clang-{clang_version}' if is_compiler_clang() else 'gcc'
394
395 def get_cxx_compiler():
396 return f'clang++-{clang_version}' if is_compiler_clang() else 'g++'
397
398 def get_optimizations():
399 optimizations = os.getenv('OPTIMIZATIONS', 'yes')
400 return '-O1' if optimizations == 'yes' else '-O0'
401
402 def get_cflags():
403 return " ".join([
404 get_optimizations(),
405 "-Werror=vla",
406 "-Werror=shadow",
407 "-Wformat=2",
408 "-Werror=format-security",
409 "-Werror=string-plus-int" if is_compiler_clang() else '',
410 ])
411
412
413 def get_cxxflags():
414 return " ".join([
415 get_cflags(),
416 "-Wp,-D_GLIBCXX_ASSERTIONS",
417 ])
418
419
420 def get_base_configure_cmd(additional_c_flags='', additional_cxx_flags='', enable_systemd=True, enable_sodium=True):
421 cflags = " ".join([get_cflags(), additional_c_flags])
422 cxxflags = " ".join([get_cxxflags(), additional_cxx_flags])
423 return " ".join([
424 f'CFLAGS="{cflags}"',
425 f'CXXFLAGS="{cxxflags}"',
426 './configure',
427 f"CC='{get_c_compiler()}'",
428 f"CXX='{get_cxx_compiler()}'",
429 "--enable-option-checking=fatal",
430 "--enable-systemd" if enable_systemd else '',
431 "--with-libsodium" if enable_sodium else '',
432 "--enable-fortify-source=auto",
433 "--enable-auto-var-init=pattern",
434 get_coverage(),
435 get_sanitizers()
436 ])
437
438
439 @task
440 def ci_auth_configure(c):
441 unittests = get_unit_tests(True)
442 fuzz_targets = get_fuzzing_targets()
443 modules = " ".join([
444 "bind",
445 "geoip",
446 "gmysql",
447 "godbc",
448 "gpgsql",
449 "gsqlite3",
450 "ldap",
451 "lmdb",
452 "lua2",
453 "pipe",
454 "remote",
455 "tinydns",
456 ])
457 configure_cmd = " ".join([
458 get_base_configure_cmd(),
459 "LDFLAGS='-L/usr/local/lib -Wl,-rpath,/usr/local/lib'",
460 f"--with-modules='{modules}'",
461 "--enable-tools",
462 "--enable-dns-over-tls",
463 "--enable-experimental-pkcs11",
464 "--enable-experimental-gss-tsig",
465 "--enable-remotebackend-zeromq",
466 "--with-lmdb=/usr",
467 "--with-libdecaf" if os.getenv('DECAF_SUPPORT', 'no') == 'yes' else '',
468 "--prefix=/opt/pdns-auth",
469 "--enable-ixfrdist",
470 unittests,
471 fuzz_targets
472 ])
473 res = c.run(configure_cmd, warn=True)
474 if res.exited != 0:
475 c.run('cat config.log')
476 raise UnexpectedExit(res)
477
478
479 @task
480 def ci_rec_configure(c):
481 unittests = get_unit_tests()
482
483 configure_cmd = " ".join([
484 get_base_configure_cmd(),
485 "--enable-nod",
486 "--prefix=/opt/pdns-recursor",
487 "--with-lua=luajit",
488 "--with-libcap",
489 "--with-net-snmp",
490 "--enable-dns-over-tls",
491 unittests,
492 ])
493 res = c.run(configure_cmd, warn=True)
494 if res.exited != 0:
495 c.run('cat config.log')
496 raise UnexpectedExit(res)
497
498
499 @task
500 def ci_dnsdist_configure(c, features):
501 additional_flags = ''
502 if features == 'full':
503 features_set = '--enable-dnstap \
504 --enable-dnscrypt \
505 --enable-dns-over-tls \
506 --enable-dns-over-https \
507 --enable-dns-over-quic \
508 --enable-dns-over-http3 \
509 --enable-systemd \
510 --prefix=/opt/dnsdist \
511 --with-gnutls \
512 --with-h2o \
513 --with-libsodium \
514 --with-lua=luajit \
515 --with-libcap \
516 --with-net-snmp \
517 --with-nghttp2 \
518 --with-re2'
519 else:
520 features_set = '--disable-dnstap \
521 --disable-dnscrypt \
522 --disable-ipcipher \
523 --disable-systemd \
524 --without-cdb \
525 --without-ebpf \
526 --without-gnutls \
527 --without-h2o \
528 --without-libedit \
529 --without-libsodium \
530 --without-lmdb \
531 --without-net-snmp \
532 --without-nghttp2 \
533 --without-re2'
534 additional_flags = '-DDISABLE_COMPLETION \
535 -DDISABLE_DELAY_PIPE \
536 -DDISABLE_DYNBLOCKS \
537 -DDISABLE_PROMETHEUS \
538 -DDISABLE_PROTOBUF \
539 -DDISABLE_BUILTIN_HTML \
540 -DDISABLE_CARBON \
541 -DDISABLE_SECPOLL \
542 -DDISABLE_DEPRECATED_DYNBLOCK \
543 -DDISABLE_LUA_WEB_HANDLERS \
544 -DDISABLE_NON_FFI_DQ_BINDINGS \
545 -DDISABLE_POLICIES_BINDINGS \
546 -DDISABLE_PACKETCACHE_BINDINGS \
547 -DDISABLE_DOWNSTREAM_BINDINGS \
548 -DDISABLE_COMBO_ADDR_BINDINGS \
549 -DDISABLE_CLIENT_STATE_BINDINGS \
550 -DDISABLE_QPS_LIMITER_BINDINGS \
551 -DDISABLE_SUFFIX_MATCH_BINDINGS \
552 -DDISABLE_NETMASK_BINDINGS \
553 -DDISABLE_DNSNAME_BINDINGS \
554 -DDISABLE_DNSHEADER_BINDINGS \
555 -DDISABLE_RECVMMSG \
556 -DDISABLE_WEB_CACHE_MANAGEMENT \
557 -DDISABLE_WEB_CONFIG \
558 -DDISABLE_RULES_ALTERING_QUERIES \
559 -DDISABLE_ECS_ACTIONS \
560 -DDISABLE_TOP_N_BINDINGS \
561 -DDISABLE_OCSP_STAPLING \
562 -DDISABLE_HASHED_CREDENTIALS \
563 -DDISABLE_FALSE_SHARING_PADDING \
564 -DDISABLE_NPN'
565 unittests = get_unit_tests()
566 fuzztargets = get_fuzzing_targets()
567 tools = f'''AR=llvm-ar-{clang_version} RANLIB=llvm-ranlib-{clang_version}''' if is_compiler_clang() else ''
568 configure_cmd = " ".join([
569 tools,
570 get_base_configure_cmd(additional_c_flags='', additional_cxx_flags=additional_flags, enable_systemd=False, enable_sodium=False),
571 features_set,
572 unittests,
573 fuzztargets,
574 ' --enable-lto=thin',
575 '--prefix=/opt/dnsdist'
576 ])
577
578 res = c.run(configure_cmd, warn=True)
579 if res.exited != 0:
580 c.run('cat config.log')
581 raise UnexpectedExit(res)
582
583 @task
584 def ci_auth_make(c):
585 c.run(f'make -j{get_build_concurrency()} -k V=1')
586
587 @task
588 def ci_auth_make_bear(c):
589 c.run(f'bear --append -- make -j{get_build_concurrency()} -k V=1')
590
591 @task
592 def ci_rec_make(c):
593 c.run(f'make -j{get_build_concurrency()} -k V=1')
594
595 @task
596 def ci_rec_make_bear(c):
597 # Assumed to be running under ./pdns/recursordist/
598 c.run(f'bear --append -- make -j{get_build_concurrency()} -k V=1')
599
600 @task
601 def ci_dnsdist_make(c):
602 c.run(f'make -j{get_build_concurrency(4)} -k V=1')
603
604 @task
605 def ci_dnsdist_make_bear(c):
606 # Assumed to be running under ./pdns/dnsdistdist/
607 c.run(f'bear --append -- make -j{get_build_concurrency(4)} -k V=1')
608
609 @task
610 def ci_auth_install_remotebackend_test_deps(c):
611 with c.cd('modules/remotebackend'):
612 # c.run('bundle config set path vendor/bundle')
613 c.run('sudo ruby -S bundle install')
614 c.sudo('apt-get install -y socat')
615
616 @task
617 def ci_auth_run_unit_tests(c):
618 res = c.run('make check', warn=True)
619 if res.exited != 0:
620 c.run('cat pdns/test-suite.log', warn=True)
621 c.run('cat modules/remotebackend/test-suite.log', warn=True)
622 raise UnexpectedExit(res)
623
624 @task
625 def ci_rec_run_unit_tests(c):
626 res = c.run('make check', warn=True)
627 if res.exited != 0:
628 c.run('cat test-suite.log')
629 raise UnexpectedExit(res)
630
631 @task
632 def ci_dnsdist_run_unit_tests(c):
633 res = c.run('make check', warn=True)
634 if res.exited != 0:
635 c.run('cat test-suite.log')
636 raise UnexpectedExit(res)
637
638 @task
639 def ci_make_distdir(c):
640 res = c.run('make distdir')
641
642 @task
643 def ci_make_install(c):
644 res = c.run('make install') # FIXME: this builds auth docs - again
645
646 @task
647 def add_auth_repo(c, dist_name, dist_release_name, pdns_repo_version):
648 c.sudo('apt-get install -y curl gnupg2')
649 if pdns_repo_version == 'master':
650 c.sudo('curl -s -o /etc/apt/trusted.gpg.d/pdns-repo.asc https://repo.powerdns.com/CBC8B383-pub.asc')
651 else:
652 c.sudo('curl -s -o /etc/apt/trusted.gpg.d/pdns-repo.asc https://repo.powerdns.com/FD380FBB-pub.asc')
653 c.run(f"echo 'deb [arch=amd64] http://repo.powerdns.com/{dist_name} {dist_release_name}-auth-{pdns_repo_version} main' | sudo tee /etc/apt/sources.list.d/pdns.list")
654 c.run("echo 'Package: pdns-*' | sudo tee /etc/apt/preferences.d/pdns")
655 c.run("echo 'Pin: origin repo.powerdns.com' | sudo tee -a /etc/apt/preferences.d/pdns")
656 c.run("echo 'Pin-Priority: 600' | sudo tee -a /etc/apt/preferences.d/pdns")
657 c.sudo('apt-get update')
658
659 @task
660 def test_api(c, product, backend=''):
661 if product == 'recursor':
662 with c.cd('regression-tests.api'):
663 c.run(f'PDNSRECURSOR=/opt/pdns-recursor/sbin/pdns_recursor ./runtests recursor {backend}')
664 elif product == 'auth':
665 with c.cd('regression-tests.api'):
666 c.run(f'PDNSSERVER=/opt/pdns-auth/sbin/pdns_server PDNSUTIL=/opt/pdns-auth/bin/pdnsutil SDIG=/opt/pdns-auth/bin/sdig MYSQL_HOST={auth_backend_ip_addr} PGHOST={auth_backend_ip_addr} PGPORT=5432 ./runtests authoritative {backend}')
667 else:
668 raise Failure('unknown product')
669
670 backend_regress_tests = dict(
671 bind = [
672 'bind-both',
673 'bind-dnssec-both',
674 'bind-dnssec-nsec3-both',
675 'bind-dnssec-nsec3-optout-both',
676 'bind-dnssec-nsec3-narrow',
677 'bind-dnssec-pkcs11'
678 ],
679 geoip = [
680 'geoip',
681 'geoip-nsec3-narrow'
682 ],
683 lua2 = ['lua2', 'lua2-dnssec'],
684 tinydns = ['tinydns'],
685 remote = [
686 'remotebackend-pipe',
687 'remotebackend-unix',
688 'remotebackend-http',
689 'remotebackend-zeromq',
690 'remotebackend-pipe-dnssec',
691 'remotebackend-unix-dnssec',
692 'remotebackend-http-dnssec',
693 'remotebackend-zeromq-dnssec'
694 ],
695 lmdb = [
696 'lmdb-nodnssec-both',
697 'lmdb-both',
698 'lmdb-nsec3-both',
699 'lmdb-nsec3-optout-both',
700 'lmdb-nsec3-narrow'
701 ],
702 gmysql = [
703 'gmysql',
704 'gmysql-nodnssec-both',
705 'gmysql-nsec3-both',
706 'gmysql-nsec3-optout-both',
707 'gmysql-nsec3-narrow',
708 'gmysql_sp-both'
709 ],
710 gpgsql = [
711 'gpgsql',
712 'gpgsql-nodnssec-both',
713 'gpgsql-nsec3-both',
714 'gpgsql-nsec3-optout-both',
715 'gpgsql-nsec3-narrow',
716 'gpgsql_sp-both'
717 ],
718 gsqlite3 = [
719 'gsqlite3',
720 'gsqlite3-nodnssec-both',
721 'gsqlite3-nsec3-both',
722 'gsqlite3-nsec3-optout-both',
723 'gsqlite3-nsec3-narrow'
724 ],
725 godbc_sqlite3 = ['godbc_sqlite3-nodnssec'],
726 godbc_mssql = [
727 'godbc_mssql',
728 'godbc_mssql-nodnssec',
729 'godbc_mssql-nsec3',
730 'godbc_mssql-nsec3-optout',
731 'godbc_mssql-nsec3-narrow'
732 ],
733 ldap = [
734 'ldap-tree',
735 'ldap-simple',
736 'ldap-strict'
737 ],
738 geoip_mmdb = ['geoip'],
739 )
740
741 godbc_mssql_credentials = {"username": "sa", "password": "SAsa12%%-not-a-secret-password"}
742
743 godbc_config = f'''
744 [pdns-mssql-docker]
745 Driver=FreeTDS
746 Trace=No
747 Server={auth_backend_ip_addr}
748 Port=1433
749 Database=pdns
750 TDS_Version=7.1
751
752 [pdns-mssql-docker-nodb]
753 Driver=FreeTDS
754 Trace=No
755 Server={auth_backend_ip_addr}
756 Port=1433
757 TDS_Version=7.1
758
759 [pdns-sqlite3-1]
760 Driver = SQLite3
761 Database = pdns.sqlite3
762
763 [pdns-sqlite3-2]
764 Driver = SQLite3
765 Database = pdns.sqlite32
766 '''
767
768 def setup_godbc_mssql(c):
769 with open(os.path.expanduser("~/.odbc.ini"), "a") as f:
770 f.write(godbc_config)
771 c.sudo('sh -c \'echo "Threading=1" | cat /usr/share/tdsodbc/odbcinst.ini - | tee -a /etc/odbcinst.ini\'')
772 c.sudo('sed -i "s/libtdsodbc.so/\/usr\/lib\/x86_64-linux-gnu\/odbc\/libtdsodbc.so/g" /etc/odbcinst.ini')
773 c.run(f'echo "create database pdns" | isql -v pdns-mssql-docker-nodb {godbc_mssql_credentials["username"]} {godbc_mssql_credentials["password"]}')
774 # FIXME: Skip 8bit-txt-unescaped test
775 c.run('touch ${PWD}/regression-tests/tests/8bit-txt-unescaped/skip')
776
777 def setup_godbc_sqlite3(c):
778 with open(os.path.expanduser("~/.odbc.ini"), "a") as f:
779 f.write(godbc_config)
780 c.sudo('sed -i "s/libsqlite3odbc.so/\/usr\/lib\/x86_64-linux-gnu\/odbc\/libsqlite3odbc.so/g" /etc/odbcinst.ini')
781
782 def setup_ldap_client(c):
783 c.sudo('DEBIAN_FRONTEND=noninteractive apt-get install -y ldap-utils')
784 c.sudo(f'sh -c \'echo "{auth_backend_ip_addr} ldapserver" | tee -a /etc/hosts\'')
785
786 def setup_softhsm(c):
787 # Modify the location of the softhsm tokens and configuration directory.
788 # Enables token generation by non-root users (runner)
789 c.run('mkdir -p /opt/pdns-auth/softhsm/tokens')
790 c.run('echo "directories.tokendir = /opt/pdns-auth/softhsm/tokens" > /opt/pdns-auth/softhsm/softhsm2.conf')
791
792 @task
793 def test_auth_backend(c, backend):
794 pdns_auth_env_vars = f'PDNS=/opt/pdns-auth/sbin/pdns_server PDNS2=/opt/pdns-auth/sbin/pdns_server SDIG=/opt/pdns-auth/bin/sdig NOTIFY=/opt/pdns-auth/bin/pdns_notify NSEC3DIG=/opt/pdns-auth/bin/nsec3dig SAXFR=/opt/pdns-auth/bin/saxfr ZONE2SQL=/opt/pdns-auth/bin/zone2sql ZONE2LDAP=/opt/pdns-auth/bin/zone2ldap ZONE2JSON=/opt/pdns-auth/bin/zone2json PDNSUTIL=/opt/pdns-auth/bin/pdnsutil PDNSCONTROL=/opt/pdns-auth/bin/pdns_control PDNSSERVER=/opt/pdns-auth/sbin/pdns_server SDIG=/opt/pdns-auth/bin/sdig GMYSQLHOST={auth_backend_ip_addr} GMYSQL2HOST={auth_backend_ip_addr} MYSQL_HOST={auth_backend_ip_addr} PGHOST={auth_backend_ip_addr} PGPORT=5432'
795
796 if backend == 'remote':
797 ci_auth_install_remotebackend_test_deps(c)
798
799 if backend == 'authpy':
800 c.sudo(f'sh -c \'echo "{auth_backend_ip_addr} kerberos-server" | tee -a /etc/hosts\'')
801 with c.cd('regression-tests.auth-py'):
802 c.run(f'{pdns_auth_env_vars} WITHKERBEROS=YES ./runtests')
803 return
804
805 if backend == 'bind':
806 setup_softhsm(c)
807 with c.cd('regression-tests'):
808 for variant in backend_regress_tests[backend]:
809 c.run(f'{pdns_auth_env_vars} SOFTHSM2_CONF=/opt/pdns-auth/softhsm/softhsm2.conf ./start-test-stop 5300 {variant}')
810 return
811
812 if backend == 'godbc_sqlite3':
813 setup_godbc_sqlite3(c)
814 with c.cd('regression-tests'):
815 for variant in backend_regress_tests[backend]:
816 c.run(f'{pdns_auth_env_vars} GODBC_SQLITE3_DSN=pdns-sqlite3-1 ./start-test-stop 5300 {variant}')
817 return
818
819 if backend == 'godbc_mssql':
820 setup_godbc_mssql(c)
821 with c.cd('regression-tests'):
822 for variant in backend_regress_tests[backend]:
823 c.run(f'{pdns_auth_env_vars} GODBC_MSSQL_PASSWORD={godbc_mssql_credentials["password"]} GODBC_MSSQL_USERNAME={godbc_mssql_credentials["username"]} GODBC_MSSQL_DSN=pdns-mssql-docker GODBC_MSSQL2_PASSWORD={godbc_mssql_credentials["password"]} GODBC_MSSQL2_USERNAME={godbc_mssql_credentials["username"]} GODBC_MSSQL2_DSN=pdns-mssql-docker ./start-test-stop 5300 {variant}')
824 return
825
826 if backend == 'ldap':
827 setup_ldap_client(c)
828
829 if backend == 'geoip_mmdb':
830 with c.cd('regression-tests'):
831 for variant in backend_regress_tests[backend]:
832 c.run(f'{pdns_auth_env_vars} geoipdatabase=../modules/geoipbackend/regression-tests/GeoLiteCity.mmdb ./start-test-stop 5300 {variant}')
833 return
834
835 with c.cd('regression-tests'):
836 if backend == 'lua2':
837 c.run('touch trustedkeys') # avoid silly error during cleanup
838 for variant in backend_regress_tests[backend]:
839 c.run(f'{pdns_auth_env_vars} ./start-test-stop 5300 {variant}')
840
841 if backend == 'gsqlite3':
842 if os.getenv('SKIP_IPV6_TESTS'):
843 pdns_auth_env_vars += ' context=noipv6'
844 with c.cd('regression-tests.nobackend'):
845 c.run(f'{pdns_auth_env_vars} ./runtests')
846 c.run('/opt/pdns-auth/bin/pdnsutil test-algorithms')
847 return
848
849 @task
850 def test_ixfrdist(c):
851 with c.cd('regression-tests.ixfrdist'):
852 c.run('IXFRDISTBIN=/opt/pdns-auth/bin/ixfrdist ./runtests')
853
854 @task
855 def test_dnsdist(c):
856 c.run('chmod +x /opt/dnsdist/bin/*')
857 c.run('ls -ald /var /var/agentx /var/agentx/master')
858 c.run('ls -al /var/agentx/master')
859 with c.cd('regression-tests.dnsdist'):
860 c.run('DNSDISTBIN=/opt/dnsdist/bin/dnsdist LD_LIBRARY_PATH=/opt/dnsdist/lib/ ./runtests')
861
862 @task
863 def test_regression_recursor(c):
864 c.run('/opt/pdns-recursor/sbin/pdns_recursor --version')
865 c.run('PDNSRECURSOR=/opt/pdns-recursor/sbin/pdns_recursor RECCONTROL=/opt/pdns-recursor/bin/rec_control ./build-scripts/test-recursor')
866
867 @task
868 def test_bulk_recursor(c, threads, mthreads, shards):
869 # We run an extremely small version of the bulk test, as GH does not seem to be able to handle the UDP load
870 with c.cd('regression-tests'):
871 c.run('curl -LO http://s3-us-west-1.amazonaws.com/umbrella-static/top-1m.csv.zip')
872 c.run('unzip top-1m.csv.zip -d .')
873 c.run('chmod +x /opt/pdns-recursor/bin/* /opt/pdns-recursor/sbin/*')
874 c.run(f'DNSBULKTEST=/usr/bin/dnsbulktest RECURSOR=/opt/pdns-recursor/sbin/pdns_recursor RECCONTROL=/opt/pdns-recursor/bin/rec_control THRESHOLD=95 TRACE=no ./recursor-test 5300 100 {threads} {mthreads} {shards}')
875
876 @task
877 def install_swagger_tools(c):
878 c.run('npm install -g api-spec-converter')
879
880 @task
881 def swagger_syntax_check(c):
882 c.run('api-spec-converter docs/http-api/swagger/authoritative-api-swagger.yaml -f swagger_2 -t openapi_3 -s json -c')
883
884 @task
885 def install_coverity_tools(c, project):
886 token = os.getenv('COVERITY_TOKEN')
887 c.run(f'curl -s https://scan.coverity.com/download/linux64 --data "token={token}&project={project}" | gunzip | sudo tar xvf /dev/stdin --strip-components=1 --no-same-owner -C /usr/local', hide=True)
888
889 @task
890 def coverity_clang_configure(c):
891 c.sudo(f'/usr/local/bin/cov-configure --template --comptype clangcc --compiler clang++-{clang_version}')
892
893 @task
894 def coverity_make(c):
895 c.run('/usr/local/bin/cov-build --dir cov-int make -j8 -k')
896
897 @task
898 def coverity_tarball(c, tarball):
899 c.run(f'tar caf {tarball} cov-int')
900
901 @task
902 def coverity_upload(c, email, project, tarball):
903 token = os.getenv('COVERITY_TOKEN')
904 c.run(f'curl --form token={token} \
905 --form email="{email}" \
906 --form file=@{tarball} \
907 --form version="$(./builder-support/gen-version)" \
908 --form description="master build" \
909 https://scan.coverity.com/builds?project={project}', hide=True)
910
911 @task
912 def ci_build_and_install_quiche(c):
913 # we have to pass -L because GitHub will do a redirect, sadly
914 c.run(f'curl -L -o quiche-{quiche_version}.tar.gz https://github.com/cloudflare/quiche/archive/{quiche_version}.tar.gz')
915 # Line below should echo two spaces between digest and name
916 c.run(f'echo {quiche_hash}" "quiche-{quiche_version}.tar.gz | sha256sum -c -')
917 c.run(f'tar xf quiche-{quiche_version}.tar.gz')
918 with c.cd(f'quiche-{quiche_version}'):
919 c.run('cargo build --release --no-default-features --features ffi,boringssl-boring-crate --package quiche')
920 # cannot use c.sudo() inside a cd() context, see https://github.com/pyinvoke/invoke/issues/687
921 c.run('sudo install -Dm644 quiche/include/quiche.h /usr/include')
922 c.run('sudo install -Dm644 target/release/libquiche.so /usr/lib')
923 c.run('install -D target/release/libquiche.so /opt/dnsdist/lib/libquiche.so')
924 c.run(f"""sudo install -Dm644 /dev/stdin /usr/lib/pkgconfig/quiche.pc <<PC
925 # quiche
926 Name: quiche
927 Description: quiche library
928 URL: https://github.com/cloudflare/quiche
929 Version: {quiche_version}
930 Libs: -lquiche
931 PC""")
932
933 # this is run always
934 def setup():
935 if '/usr/lib/ccache' not in os.environ['PATH']:
936 os.environ['PATH']='/usr/lib/ccache:'+os.environ['PATH']
937
938 setup()