-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
598 lines (532 loc) · 24.1 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.19)
project(velia LANGUAGES CXX)
cmake_policy(SET CMP0109 NEW)
# Build options
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS_DEBUG "-Werror ${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Woverloaded-virtual -Wimplicit-fallthrough ${CMAKE_CXX_FLAGS}")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "-Wsuggest-override ${CMAKE_CXX_FLAGS}")
endif()
if(CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+" AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
set(STD_FILESYSTEM_LIBRARY c++fs)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.1)
set(STD_FILESYSTEM_LIBRARY stdc++fs)
endif()
add_custom_target(velia-version-cmake-ide
cmake/ProjectGitVersion.cmake
cmake/ProjectGitVersionRunner.cmake
)
include(cmake/ProjectGitVersion.cmake)
prepare_git_version(VELIA_VERSION "1")
find_package(Doxygen)
option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${DOXYGEN_FOUND})
find_package(date REQUIRED) # FIXME: Remove when we have STL with __cpp_lib_chrono >= 201907 (gcc 14)
find_package(Boost REQUIRED)
find_package(spdlog REQUIRED)
find_package(sdbus-c++ "1.0.0" REQUIRED)
find_package(PkgConfig)
find_package(fmt "9.0.0" REQUIRED)
find_package(nlohmann_json REQUIRED)
pkg_check_modules(DOCOPT REQUIRED IMPORTED_TARGET docopt)
pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET libsystemd)
if(${SYSTEMD_VERSION} VERSION_EQUAL 245)
message(FATAL_ERROR "Systemd 245 has a bug affecting DBus method calls using sdbus-c++. Please see https://github.com/Kistler-Group/sdbus-cpp/issues/106.")
endif()
#TODO: Check patch 20333 active
pkg_check_modules(SYSREPO REQUIRED IMPORTED_TARGET sysrepo sysrepo-cpp>=3)
pkg_check_modules(LIBYANG REQUIRED IMPORTED_TARGET libyang libyang-cpp>=3)
pkg_check_modules(LIBNL REQUIRED IMPORTED_TARGET libnl-route-3.0)
include(GNUInstallDirs)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
set(YANG_SRCS
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
yang/[email protected]
)
set(YANG_SUBMODULES
yang/[email protected]
)
# temporary until our CI switches to fmt>=9
add_compile_definitions(FMT_DEPRECATED_OSTREAM)
# Targets
# - utils
add_library(velia-utils STATIC
src/utils/alarms.cpp
src/utils/alarms.h
src/utils/benchmark.cpp
src/utils/benchmark.h
src/utils/exceptions.cpp
src/utils/exceptions.h
src/utils/exec.cpp
src/utils/exec.h
src/utils/io.cpp
src/utils/io.h
src/utils/journal.cpp
src/utils/journal.h
src/utils/libyang.cpp
src/utils/libyang.h
src/utils/log.h
src/utils/log.cpp
src/utils/log-fwd.h
src/utils/log-init.cpp
src/utils/log-init.h
src/utils/sysrepo.cpp
src/utils/sysrepo.h
src/utils/waitUntilSignalled.cpp
src/utils/waitUntilSignalled.h
)
target_link_libraries(velia-utils PUBLIC spdlog::spdlog PRIVATE PkgConfig::SYSTEMD PkgConfig::LIBYANG PkgConfig::SYSREPO fmt::fmt PkgConfig::DOCOPT)
# - health
add_library(velia-health STATIC
src/health/outputs/AlarmsOutputs.cpp
src/health/outputs/AlarmsOutputs.h
src/health/outputs/LedSysfsDriver.cpp
src/health/outputs/callables.cpp
src/health/State.cpp
src/health/SystemdUnits.cpp
src/health/SystemdUnits.h
)
target_link_libraries(velia-health
PUBLIC
velia-utils
Boost::boost
SDBusCpp::sdbus-c++
${STD_FILESYSTEM_LIBRARY}
PRIVATE
PkgConfig::LIBYANG
)
# - ietf-hardware
add_library(velia-ietf-hardware STATIC
src/ietf-hardware/sysfs/EMMC.cpp
src/ietf-hardware/sysfs/EMMC.h
src/ietf-hardware/sysfs/HWMon.cpp
src/ietf-hardware/sysfs/HWMon.h
src/ietf-hardware/sysfs/IpmiFruEEPROM.cpp
src/ietf-hardware/sysfs/IpmiFruEEPROM.h
src/ietf-hardware/IETFHardware.cpp
src/ietf-hardware/IETFHardware.h
src/ietf-hardware/FspYh.cpp
src/ietf-hardware/FspYh.h
src/ietf-hardware/thresholds.h
src/ietf-hardware/thresholds.cpp
src/ietf-hardware/thresholds_fwd.h
)
target_link_libraries(velia-ietf-hardware
PUBLIC
velia-utils
${STD_FILESYSTEM_LIBRARY}
Boost::boost
PRIVATE
PkgConfig::LIBYANG
date::date
)
add_library(velia-ietf-hardware-sysrepo STATIC
src/ietf-hardware/sysrepo/Sysrepo.cpp
src/ietf-hardware/sysrepo/Sysrepo.h
)
target_link_libraries(velia-ietf-hardware-sysrepo
PUBLIC
velia-utils
PkgConfig::SYSREPO
PkgConfig::LIBYANG
)
set(NOBODY_UID 65534 CACHE STRING "UID which refers to 'nobody'. Used for dropping root privileges.")
set(NOBODY_GID 65534 CACHE STRING "GID which refers to 'nobody'. Used for dropping root privileges.")
if(NOT NFT_EXECUTABLE)
find_program(NFT_EXECUTABLE nft)
endif()
if(NOT SSH_KEYGEN_EXECUTABLE)
find_program(SSH_KEYGEN_EXECUTABLE ssh-keygen)
endif()
if(NOT CHPASSWD_EXECUTABLE)
find_program(CHPASSWD_EXECUTABLE chpasswd)
endif()
if(NOT SYSTEMCTL_EXECUTABLE)
find_program(SYSTEMCTL_EXECUTABLE systemctl)
endif()
if(NOT NETWORKCTL_EXECUTABLE)
find_program(NETWORKCTL_EXECUTABLE networkctl)
endif()
if(NOT HOSTNAMECTL_EXECUTABLE)
find_program(HOSTNAMECTL_EXECUTABLE hostnamectl)
endif()
set(VELIA_AUTHORIZED_KEYS_FORMAT "{HOME}/.ssh/authorized_keys" CACHE STRING "pattern for determining path to users' SSH authorized_keys file. Must at least one of '{USER}' or '{HOME}' which will get replaced by the name of the user and the home directory of the user respectively.")
if(NOT VELIA_AUTHORIZED_KEYS_FORMAT)
message(FATAL_ERROR "VELIA_AUTHORIZED_KEYS_FORMAT not set.")
endif()
if(NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{USER}" AND NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{HOME}")
message(FATAL_ERROR "Wrong format string given for VELIA_AUTHORIZED_KEYS_FORMAT: at least one of {USER} or {HOME} expected.")
endif()
set(VELIA_REAL_ETC_PASSWD "/etc/passwd" CACHE STRING "Path to passwd file")
if(NOT VELIA_REAL_ETC_PASSWD)
message(FATAL_ERROR "VELIA_REAL_ETC_PASSWD not set")
endif()
set(VELIA_REAL_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to shadow file")
if(NOT VELIA_REAL_ETC_SHADOW)
message(FATAL_ERROR "VELIA_REAL_ETC_SHADOW not set")
endif()
set(VELIA_BACKUP_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to where /etc/shadow gets copied to upon each change")
if(NOT VELIA_BACKUP_ETC_SHADOW)
message(FATAL_ERROR "VELIA_BACKUP_ETC_SHADOW not set")
endif()
set(VELIA_BACKUP_ETC_HOSTNAME "/etc/hostname" CACHE STRING "Path to hostname file")
if(NOT VELIA_BACKUP_ETC_HOSTNAME )
message(FATAL_ERROR "VELIA_BACKUP_ETC_HOSTNAME not set")
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/system/system_vars.h.in ${CMAKE_CURRENT_BINARY_DIR}/system_vars.h @ONLY)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
# - ietf-system
add_library(velia-system STATIC
src/system/RAUC.cpp
src/system/RAUC.h
src/system/Firmware.cpp
src/system/Firmware.h
src/system/IETFSystem.cpp
src/system/IETFSystem.h
src/system/Authentication.cpp
src/system/Authentication.h
src/system/Rtnetlink.cpp
src/system/Rtnetlink.h
src/system/IETFInterfaces.cpp
src/system/IETFInterfaces.h
src/system/IETFInterfacesConfig.cpp
src/system/IETFInterfacesConfig.h
src/system/JournalUpload.cpp
src/system/JournalUpload.h
src/system/LED.cpp
src/system/LED.h
src/system/LLDP.cpp
src/system/LLDP.h
src/system/LLDPCallback.cpp
src/system/LLDPCallback.h
)
target_link_libraries(velia-system
PUBLIC
velia-utils
PkgConfig::SYSREPO
PkgConfig::LIBYANG
PkgConfig::LIBNL
SDBusCpp::sdbus-c++
nlohmann_json::nlohmann_json
PRIVATE
date::date-tz
)
# - firewall
add_library(velia-firewall STATIC
src/firewall/Firewall.cpp
)
target_link_libraries(velia-firewall
PUBLIC
velia-utils
PkgConfig::SYSREPO
PRIVATE
PkgConfig::LIBYANG
)
# - daemons
add_executable(veliad-health
src/main-health.cpp
src/health/Factory.cpp
src/health/Factory.h
)
target_link_libraries(veliad-health
PUBLIC
velia-health
PkgConfig::DOCOPT
)
add_dependencies(veliad-health target-VELIA_VERSION)
target_include_directories(veliad-health PUBLIC ${CMAKE_BINARY_DIR})
add_executable(veliad-system
src/main-system.cpp
)
target_link_libraries(veliad-system
PUBLIC
velia-system
PkgConfig::DOCOPT
)
add_dependencies(veliad-system target-VELIA_VERSION)
target_include_directories(veliad-system PUBLIC ${CMAKE_BINARY_DIR})
add_executable(veliad-firewall
src/main-firewall.cpp
)
target_link_libraries(veliad-firewall
PUBLIC
velia-firewall
velia-utils
PkgConfig::DOCOPT
)
add_dependencies(veliad-firewall target-VELIA_VERSION)
target_include_directories(veliad-firewall PUBLIC ${CMAKE_BINARY_DIR})
add_executable(veliad-hardware
src/main-hardware.cpp
src/ietf-hardware/Factory.cpp
src/ietf-hardware/Factory.h
)
target_link_libraries(veliad-hardware
PUBLIC
velia-ietf-hardware
velia-ietf-hardware-sysrepo
PkgConfig::DOCOPT
)
add_dependencies(veliad-hardware target-VELIA_VERSION)
target_include_directories(veliad-hardware PUBLIC ${CMAKE_BINARY_DIR})
add_executable(velia-ipmi-fru-eeprom
src/main-ipmi-fru-eeprom.cpp
)
add_dependencies(velia-ipmi-fru-eeprom target-VELIA_VERSION)
target_link_libraries(velia-ipmi-fru-eeprom
PUBLIC
velia-ietf-hardware
PkgConfig::DOCOPT
fmt::fmt
)
add_dependencies(veliad-hardware target-VELIA_VERSION)
target_include_directories(veliad-hardware PUBLIC ${CMAKE_BINARY_DIR})
# Testing
include(CTest)
if(BUILD_TESTING)
find_package(trompeloeil 45 REQUIRED)
find_package(doctest 2.4.11 REQUIRED)
include(cmake/SysrepoTest.cmake)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/configure.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/tests/configure.cmake.h)
add_library(DoctestIntegration STATIC
tests/doctest_integration.cpp
tests/trompeloeil_doctest.h
tests/wait-a-bit-longer.cpp
)
target_link_libraries(DoctestIntegration doctest::doctest spdlog::spdlog)
target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/)
target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
add_library(SysrepoTesting STATIC
tests/mock/ietf_hardware.h
tests/mock/system.h
tests/sysrepo-helpers/common.cpp
tests/sysrepo-helpers/common.h
tests/sysrepo-helpers/datastore.cpp
tests/sysrepo-helpers/datastore.h
tests/sysrepo-helpers/notifications.cpp
tests/sysrepo-helpers/notifications.h
tests/sysrepo-helpers/rpc.cpp
tests/sysrepo-helpers/rpc.h
tests/sysrepo-helpers/alarms.cpp
tests/sysrepo-helpers/alarms.h
)
target_link_libraries(SysrepoTesting DoctestIntegration PkgConfig::SYSREPO)
add_library(DbusTesting STATIC
tests/dbus-helpers/dbus_rauc_server.cpp
tests/dbus-helpers/dbus_rauc_server.h
tests/dbus-helpers/dbus_resolve1_server.cpp
tests/dbus-helpers/dbus_resolve1_server.h
tests/dbus-helpers/dbus_semaphore_server.cpp
tests/dbus-helpers/dbus_semaphore_server.h
tests/dbus-helpers/dbus_systemd_server.cpp
tests/dbus-helpers/dbus_systemd_server.h
)
target_link_libraries(DbusTesting
PUBLIC
velia-utils
SDBusCpp::sdbus-c++
)
add_library(FsTestUtils STATIC
tests/fs-helpers/FileInjector.cpp
tests/fs-helpers/FileInjector.h
tests/fs-helpers/utils.cpp
tests/fs-helpers/utils.h
)
target_link_libraries(FsTestUtils
PUBLIC
${STD_FILESYSTEM_LIBRARY}
)
find_program(IPROUTE2_EXECUTABLE ip REQUIRED)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/test_vars.h.in ${CMAKE_CURRENT_BINARY_DIR}/test_vars.h @ONLY)
function(velia_test)
cmake_parse_arguments(TEST "" "NAME" "" ${ARGN})
sysrepo_test(NAME ${TEST_NAME} ${TEST_UNPARSED_ARGUMENTS})
target_link_libraries(test-${TEST_NAME} DoctestIntegration SysrepoTesting)
endfunction()
find_program(YANGLINT_PATH yanglint)
if (NOT YANGLINT_PATH)
message(FATAL_ERROR "Cannot find libyang's yanglint")
endif()
foreach(yang_file ${YANG_SRCS})
add_test(NAME yang-tree:${yang_file} COMMAND ${YANGLINT_PATH} -f tree ${CMAKE_CURRENT_SOURCE_DIR}/${yang_file})
endforeach()
velia_test(NAME system_rauc LIBRARIES velia-system DbusTesting RESOURCE_LOCK dbus-rauc)
velia_test(NAME system_lldp LIBRARIES velia-system DbusTesting)
velia_test(NAME hardware_thresholds LIBRARIES velia-ietf-hardware)
velia_test(NAME hardware_eeprom LIBRARIES velia-ietf-hardware)
velia_test(NAME hardware_emmc LIBRARIES velia-ietf-hardware FsTestUtils)
velia_test(NAME hardware_hwmon LIBRARIES velia-ietf-hardware FsTestUtils)
velia_test(NAME hardware_fspyh LIBRARIES velia-ietf-hardware FsTestUtils)
velia_test(NAME hardware_ietf-hardware LIBRARIES velia-ietf-hardware)
set(fixture_sysrepo-czechlight-lldp --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/[email protected])
velia_test(NAME sysrepo_system-lldp LIBRARIES velia-system DbusTesting FIXTURE fixture_sysrepo-czechlight-lldp)
set(fixture_sysrepo-ietf-system --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/[email protected])
velia_test(NAME sysrepo_system-ietfsystem LIBRARIES velia-system DbusTesting FIXTURE fixture_sysrepo-ietf-system)
set(fixture_sysrepo-czechlight-system --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/[email protected] --init-data ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-authentication.json)
velia_test(NAME sysrepo_system-firmware LIBRARIES velia-system DbusTesting FIXTURE fixture_sysrepo-czechlight-system RESOURCE_LOCK dbus-rauc)
velia_test(NAME sysrepo_authentication LIBRARIES velia-system FsTestUtils date::date-tz FIXTURE fixture_sysrepo-czechlight-system)
velia_test(NAME sysrepo_system-leds LIBRARIES velia-system FsTestUtils FIXTURE fixture_sysrepo-czechlight-system)
velia_test(NAME sysrepo_system-journalupload LIBRARIES velia-system FIXTURE fixture_sysrepo-czechlight-system)
set(fixture_sysrepo-czechlight-network
--install ${CMAKE_CURRENT_SOURCE_DIR}/yang/[email protected]
--install ${CMAKE_CURRENT_SOURCE_DIR}/yang/[email protected]
--install ${CMAKE_CURRENT_SOURCE_DIR}/yang/[email protected]
--install ${CMAKE_CURRENT_SOURCE_DIR}/yang/[email protected]
--install ${CMAKE_CURRENT_SOURCE_DIR}/yang/[email protected]
--install ${CMAKE_CURRENT_SOURCE_DIR}/yang/[email protected]
--install ${CMAKE_CURRENT_SOURCE_DIR}/yang/[email protected])
velia_test(NAME sysrepo_interfaces-systemd-networkd LIBRARIES velia-system FIXTURE fixture_sysrepo-czechlight-network)
find_program(UNSHARE_EXECUTABLE unshare REQUIRED)
find_program(MOUNT_EXECUTABLE mount REQUIRED)
pkg_get_variable(SR_GROUP sysrepo SR_GROUP)
if (SR_GROUP)
set(UNSHARE_MAP_GROUP_ARG "--map-group=${SR_GROUP}")
else()
set(UNSHARE_MAP_GROUP_ARG "")
endif()
velia_test(NAME sysrepo_interfaces-libnl LIBRARIES velia-system FIXTURE fixture_sysrepo-czechlight-network
COMMAND ${UNSHARE_EXECUTABLE} --net --mount --map-root-user ${UNSHARE_MAP_GROUP_ARG} sh -c "set -ex $<SEMICOLON> ${MOUNT_EXECUTABLE} -t sysfs none /sys $<SEMICOLON> $<TARGET_FILE:test-sysrepo_interfaces-libnl>")
set(fixture_sysrepo-ietf-hardware
--install ${CMAKE_CURRENT_SOURCE_DIR}/yang/[email protected]
--install ${CMAKE_CURRENT_SOURCE_DIR}/yang/[email protected]
--enable-feature hardware-sensor
--enable-feature hardware-state
--install ${CMAKE_CURRENT_SOURCE_DIR}/yang/[email protected]
--enable-feature alarm-shelving
--enable-feature alarm-summary
--install ${CMAKE_CURRENT_SOURCE_DIR}/yang/[email protected]
--install ${CMAKE_CURRENT_SOURCE_DIR}/tests/yang/[email protected])
velia_test(NAME sysrepo_ietf-hardware LIBRARIES velia-ietf-hardware velia-ietf-hardware-sysrepo FsTestUtils FIXTURE fixture_sysrepo-ietf-hardware)
# ctest dance for sysrepo_two-daemons: compile daemon, create a fixture for test, add the test into the fixture
add_executable(test-sysrepo_test_merge-daemon ${CMAKE_SOURCE_DIR}/tests/sysrepo_two-daemons_daemon.cpp)
target_link_libraries(test-sysrepo_test_merge-daemon PkgConfig::SYSREPO PkgConfig::LIBYANG)
velia_test(NAME sysrepo_two-daemons LIBRARIES velia-ietf-hardware-sysrepo FIXTURE fixture_sysrepo-ietf-hardware)
add_test(NAME sysrepo_test_merge-start COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_two-daemons_control.sh start)
add_test(NAME sysrepo_test_merge-stop COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_two-daemons_control.sh stop)
set_tests_properties(sysrepo_test_merge-start PROPERTIES FIXTURES_SETUP sysrepo:two-daemons)
set_tests_properties(sysrepo_test_merge-stop PROPERTIES FIXTURES_CLEANUP sysrepo:two-daemons)
get_property(TWO_DAEMONS_ENV TEST test-sysrepo_two-daemons PROPERTY ENVIRONMENT)
set_property(TEST sysrepo_test_merge-start sysrepo_test_merge-stop PROPERTY ENVIRONMENT ${TWO_DAEMONS_ENV})
set_property(TEST test-sysrepo_two-daemons APPEND PROPERTY FIXTURES_REQUIRED sysrepo:two-daemons)
# ensure we run two-daemons merge test and ietf-hardware test sequentially and don't cleanup before everything ends
set_tests_properties(sysrepo_test_merge-start PROPERTIES DEPENDS test-sysrepo_ietf-hardware)
set_tests_properties(sysrepo:clean:sysrepo_two-daemons PROPERTIES DEPENDS sysrepo_test_merge-stop)
set(fixture_sysrepo-firewall
# Installing czechlight-firewall automatically installs ietf-access-control-list as implemented (not just
# imported) but I still need to install it myself to enable the features.
--install ${CMAKE_CURRENT_SOURCE_DIR}/yang/[email protected]
--enable-feature match-on-eth
--enable-feature eth
--enable-feature match-on-ipv4
--enable-feature ipv4
--enable-feature match-on-ipv6
--enable-feature ipv6
--enable-feature mixed-eth-ipv4-ipv6
--install ${CMAKE_CURRENT_SOURCE_DIR}/yang/[email protected]
)
velia_test(NAME sysrepo-firewall LIBRARIES velia-firewall FIXTURE fixture_sysrepo-firewall)
set(fixture_sysrepo-alarms
--install ${CMAKE_CURRENT_SOURCE_DIR}/yang/[email protected]
--enable-feature alarm-shelving
--enable-feature alarm-summary
--install ${CMAKE_CURRENT_SOURCE_DIR}/yang/[email protected]
--install ${CMAKE_CURRENT_SOURCE_DIR}/tests/yang/[email protected]
)
velia_test(NAME health_systemd-units LIBRARIES velia-health DbusTesting FIXTURE fixture_sysrepo-alarms)
velia_test(NAME sysrepo_health-led-alarms LIBRARIES velia-health DbusTesting FIXTURE fixture_sysrepo-alarms)
find_program(SYSREPO_IETF_ALARMSD_EXECUTABLE sysrepo-ietf-alarmsd)
if(SYSREPO_IETF_ALARMSD_EXECUTABLE)
velia_test(NAME sysrepo_ietf-alarms LIBRARIES velia-health DbusTesting FIXTURE fixture_sysrepo-alarms)
add_test(NAME sysrepo_ietf-alarms-start COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_sysrepo-ietf-alarms_control.sh start ${SYSREPO_IETF_ALARMSD_EXECUTABLE} ${CMAKE_BINARY_DIR}/sysrepo-ietf-alarmsd.log)
add_test(NAME sysrepo_ietf-alarms-stop COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_sysrepo-ietf-alarms_control.sh stop)
get_property(IETF_ALARMS_ENV TEST test-sysrepo_ietf-alarms PROPERTY ENVIRONMENT)
set_property(TEST sysrepo_ietf-alarms-start sysrepo_ietf-alarms-stop PROPERTY ENVIRONMENT ${IETF_ALARMS_ENV})
set_tests_properties(sysrepo_ietf-alarms-start PROPERTIES FIXTURES_SETUP sysrepo-ietf-alarmsd)
set_tests_properties(sysrepo_ietf-alarms-stop PROPERTIES FIXTURES_CLEANUP sysrepo-ietf-alarmsd)
set_property(TEST test-sysrepo_ietf-alarms APPEND PROPERTY FIXTURES_REQUIRED sysrepo-ietf-alarmsd)
set_tests_properties(sysrepo_ietf-alarms-start PROPERTIES DEPENDS sysrepo:prep:sysrepo_ietf-alarms)
set_tests_properties(sysrepo:clean:sysrepo_ietf-alarms PROPERTIES DEPENDS sysrepo_ietf-alarms-stop)
endif()
endif()
if(WITH_DOCS)
set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
configure_file(${doxyfile_in} ${doxyfile} @ONLY)
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM
SOURCES ${doxyfile_in}
)
endif()
set(YANG_DIR ${CMAKE_INSTALL_PREFIX}/share/yang/modules/velia)
install(FILES ${YANG_SRCS} ${YANG_SUBMODULES} DESTINATION ${YANG_DIR})
set(YANG_DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/yang/static-data/velia)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-authentication.json DESTINATION ${YANG_DATA_DIR})
install(TARGETS
veliad-health
veliad-system
veliad-hardware
veliad-firewall
velia-ipmi-fru-eeprom
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})
set(JQ_SRCS)
function(add_jq_utility NAME)
set(JQ_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cli/${NAME}.jq)
set(JQ_WRAPPER ${CMAKE_CURRENT_SOURCE_DIR}/cli/${NAME}.in)
list(APPEND JQ_SRCS ${JQ_FILE} ${JQ_WRAPPER})
configure_file(${JQ_WRAPPER} ${CMAKE_CURRENT_BINARY_DIR}/${NAME} @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${NAME}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})
install(FILES ${JQ_FILE} DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBEXECDIR}/velia)
endfunction()
add_custom_target(jq_utils SOURCES ${JQ_SRCS})
find_program(JQ_EXECUTABLE jq)
function(add_jq_test UTILITY_NAME TESTCASE_NAME)
set(test_name jq-${UTILITY_NAME}-${TESTCASE_NAME})
if(JQ_EXECUTABLE STREQUAL "JQ_EXECUTABLE-NOTFOUND")
message(WARNING "Cannot find the `jq` program, skipping test \"${test_name}\"")
return()
endif()
set(test_input_prefix ${CMAKE_CURRENT_SOURCE_DIR}/tests/jq/${UTILITY_NAME}/${TESTCASE_NAME})
if(EXISTS ${test_input_prefix}.config.json)
set(jq_extra_config "--argjson config \"$(< ${test_input_prefix}.config.json)\"")
else()
set(jq_extra_config "")
endif()
add_test(NAME ${test_name}
COMMAND sh -c
"${JQ_EXECUTABLE} -f ${CMAKE_CURRENT_SOURCE_DIR}/cli/${UTILITY_NAME}.jq ${jq_extra_config} \
< ${test_input_prefix}.json \
| diff -u ${test_input_prefix}.expected -")
endfunction()
add_jq_utility(velia-list-alarms)
add_jq_test(velia-list-alarms EDFA-LINE-SDN-ID210512)
add_jq_test(velia-list-alarms active-since)
add_jq_test(velia-list-alarms cleared-before)
add_jq_utility(velia-list-hardware)
add_jq_test(velia-list-hardware EDFA-LINE-SDN-ID210512)