From 13c1c17394263a2a7230d5c0a671e1cf1656f2b4 Mon Sep 17 00:00:00 2001 From: Mike Sul Date: Wed, 22 May 2019 17:02:24 +0300 Subject: OTA-2541: Use local.conf's variables to configure Primary with Secondary(ies) and vice versa Signed-off-by: Mike Sul Signed-off-by: Patrick Vacek --- recipes-sota/aktualizr/aktualizr_git.bb | 8 --- recipes-test/demo-config/files/30-fake_pacman.toml | 2 + .../demo-config/files/30-secondary_config.toml | 2 + .../demo-config/files/35-network_config.toml | 4 ++ recipes-test/demo-config/files/45-id_config.toml | 3 + .../demo-config/files/ip_secondary_config.json | 7 +++ recipes-test/demo-config/primary-config.bb | 68 ++++++++++++++++++++++ recipes-test/demo-config/secondary-config.bb | 41 +++++++++++++ recipes-test/demo-config/shared-conf.inc | 5 ++ .../files/30-fake_pacman.toml | 2 - .../files/35-network_config.toml | 4 -- .../demo-secondary-config/files/45-id_config.toml | 3 - .../demo-secondary-config/secondary-config.bb | 43 -------------- recipes-test/images/primary-image.bb | 3 +- 14 files changed, 134 insertions(+), 61 deletions(-) create mode 100644 recipes-test/demo-config/files/30-fake_pacman.toml create mode 100644 recipes-test/demo-config/files/30-secondary_config.toml create mode 100644 recipes-test/demo-config/files/35-network_config.toml create mode 100644 recipes-test/demo-config/files/45-id_config.toml create mode 100644 recipes-test/demo-config/files/ip_secondary_config.json create mode 100644 recipes-test/demo-config/primary-config.bb create mode 100644 recipes-test/demo-config/secondary-config.bb create mode 100644 recipes-test/demo-config/shared-conf.inc delete mode 100644 recipes-test/demo-secondary-config/files/30-fake_pacman.toml delete mode 100644 recipes-test/demo-secondary-config/files/35-network_config.toml delete mode 100644 recipes-test/demo-secondary-config/files/45-id_config.toml delete mode 100644 recipes-test/demo-secondary-config/secondary-config.bb diff --git a/recipes-sota/aktualizr/aktualizr_git.bb b/recipes-sota/aktualizr/aktualizr_git.bb index 1574879..c1e0134 100755 --- a/recipes-sota/aktualizr/aktualizr_git.bb +++ b/recipes-sota/aktualizr/aktualizr_git.bb @@ -117,14 +117,6 @@ do_install_append () { fi fi - if [ -n "${SOTA_SECONDARY_NETWORK_CONFIG}" ]; then - if [ -f "${SOTA_SECONDARY_NETWORK_CONFIG}" ]; then - install -m 0644 ${SOTA_SECONDARY_NETWORK_CONFIG} ${D}/${libdir}/sota/conf.d/35-secondary-network-config.toml - else - bbwarn "SOTA_SECONDARY_NETWORK_CONFIG is set to a non-existent file (${SOTA_SECONDARY_NETWORK_CONFIG})" - fi - fi - install -m 0755 -d ${D}${systemd_unitdir}/system aktualizr_service=${@bb.utils.contains('SOTA_CLIENT_FEATURES', 'serialcan', '${WORKDIR}/aktualizr-serialcan.service', '${WORKDIR}/aktualizr.service', d)} install -m 0644 ${aktualizr_service} ${D}${systemd_unitdir}/system/aktualizr.service diff --git a/recipes-test/demo-config/files/30-fake_pacman.toml b/recipes-test/demo-config/files/30-fake_pacman.toml new file mode 100644 index 0000000..3fb5cf2 --- /dev/null +++ b/recipes-test/demo-config/files/30-fake_pacman.toml @@ -0,0 +1,2 @@ +[pacman] +type = "fake" diff --git a/recipes-test/demo-config/files/30-secondary_config.toml b/recipes-test/demo-config/files/30-secondary_config.toml new file mode 100644 index 0000000..7714240 --- /dev/null +++ b/recipes-test/demo-config/files/30-secondary_config.toml @@ -0,0 +1,2 @@ +[uptane] +secondary_config_file = "@CFG_FILEPATH@" diff --git a/recipes-test/demo-config/files/35-network_config.toml b/recipes-test/demo-config/files/35-network_config.toml new file mode 100644 index 0000000..db7a1bb --- /dev/null +++ b/recipes-test/demo-config/files/35-network_config.toml @@ -0,0 +1,4 @@ +[network] +port = @PORT@ +primary_ip = @PRIMARY_IP@ +primary_port = @PRIMARY_PORT@ diff --git a/recipes-test/demo-config/files/45-id_config.toml b/recipes-test/demo-config/files/45-id_config.toml new file mode 100644 index 0000000..6cbd77f --- /dev/null +++ b/recipes-test/demo-config/files/45-id_config.toml @@ -0,0 +1,3 @@ +[uptane] +ecu_serial = @SERIAL@ +ecu_hardware_id = @HWID@ diff --git a/recipes-test/demo-config/files/ip_secondary_config.json b/recipes-test/demo-config/files/ip_secondary_config.json new file mode 100644 index 0000000..690cf2e --- /dev/null +++ b/recipes-test/demo-config/files/ip_secondary_config.json @@ -0,0 +1,7 @@ +{ + "IP": { + "secondaries_wait_port": @PORT@, + "secondaries_wait_timeout": @TIMEOUT@, + "secondaries": @ADDR_ARRAY@ + } +} diff --git a/recipes-test/demo-config/primary-config.bb b/recipes-test/demo-config/primary-config.bb new file mode 100644 index 0000000..0cd9180 --- /dev/null +++ b/recipes-test/demo-config/primary-config.bb @@ -0,0 +1,68 @@ +DESCRIPTION = "Sample configuration for an Uptane Primary to support IP/Posix Secondary" +LICENSE = "MPL-2.0" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MPL-2.0;md5=815ca599c9df247a0c7f619bab123dad" + +require shared-conf.inc + +PRIMARY_SECONDARIES ?= "${SECONDARY_IP}:${SECONDARY_PORT}" + +SRC_URI = "\ + file://30-secondary_config.toml \ + file://ip_secondary_config.json \ + " + +def get_secondary_addrs(d): + import json + + secondaries = d.getVar('PRIMARY_SECONDARIES') + sec_array = [] + for secondary in secondaries.split(): + sec_array.append({"addr": secondary}) + + return json.dumps(sec_array) + +do_install () { + + if [ ! -n "${SOTA_SECONDARY_CONFIG}" ]; then + bbwarn "SOTA_SECONDARY_CONFIG hasn't been specified in the local config, generate a default one" + + IP_SECONDARY_CONFIG_FILE=${WORKDIR}/ip_secondary_config.json + IP_SECONDARY_ADDRS='${@get_secondary_addrs(d)}' + else + bbwarn "SOTA_SECONDARY_CONFIG has been specified in the local config: ${SOTA_SECONDARY_CONFIG}" + + IP_SECONDARY_CONFIG_FILE=${SOTA_SECONDARY_CONFIG} + fi + + if [ ! -f $IP_SECONDARY_CONFIG_FILE ]; then + bbfatal "Secondary config file does not exist: $IP_SECONDARY_CONFIG_FILE" + fi + + SECONDARY_CONFIG_DEST_DIR="${D}${sysconfdir}/sota/ecus" + SECONDARY_CONFIG_DEST_FILEPATH=$SECONDARY_CONFIG_DEST_DIR/$(basename -- $IP_SECONDARY_CONFIG_FILE) + SECONDARY_CONFIG_FILEPATH_ON_IMAGE="${sysconfdir}/sota/ecus/$(basename -- $IP_SECONDARY_CONFIG_FILE)" + + # install the secondary configuration file (json) + install -m 0700 -d $SECONDARY_CONFIG_DEST_DIR + install -m 0644 $IP_SECONDARY_CONFIG_FILE $SECONDARY_CONFIG_DEST_DIR + + # if SOTA_SECONDARY_CONFIG/secondary config file is not defined in the local conf + # then a default template is used and filled with corresponding configuration variable values + if [ ! -n "${SOTA_SECONDARY_CONFIG}" ]; then + sed -i -e "s|@PORT@|${PRIMARY_PORT}|g" \ + -e "s|@TIMEOUT@|${PRIMARY_WAIT_TIMEOUT}|g" \ + -e "s|@ADDR_ARRAY@|$IP_SECONDARY_ADDRS|g" $SECONDARY_CONFIG_DEST_FILEPATH + fi + + # install aktualizr config file (toml) that points to the secondary config file, so aktualizr is aware about it + install -m 0700 -d ${D}${libdir}/sota/conf.d + install -m 0644 ${WORKDIR}/30-secondary_config.toml ${D}${libdir}/sota/conf.d + sed -i "s|@CFG_FILEPATH@|$SECONDARY_CONFIG_FILEPATH_ON_IMAGE|g" ${D}${libdir}/sota/conf.d/30-secondary_config.toml +} + +FILES_${PN} = " \ + ${libdir}/sota/conf.d/* \ + ${sysconfdir}/sota/ecus/* \ + " + +# vim:set ts=4 sw=4 sts=4 expandtab: diff --git a/recipes-test/demo-config/secondary-config.bb b/recipes-test/demo-config/secondary-config.bb new file mode 100644 index 0000000..5b213d1 --- /dev/null +++ b/recipes-test/demo-config/secondary-config.bb @@ -0,0 +1,41 @@ +DESCRIPTION = "Sample configuration for an Uptane Secondary" +LICENSE = "MPL-2.0" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MPL-2.0;md5=815ca599c9df247a0c7f619bab123dad" + +require shared-conf.inc + +SECONDARY_SERIAL_ID ?= "" +SOTA_HARDWARE_ID ?= "${MACHINE}-sndry" +SECONDARY_HARDWARE_ID ?= "${SOTA_HARDWARE_ID}" + +SRC_URI = "\ + file://30-fake_pacman.toml \ + file://35-network_config.toml \ + file://45-id_config.toml \ + " + +do_install () { + install -m 0700 -d ${D}${libdir}/sota/conf.d + install -m 0644 ${WORKDIR}/30-fake_pacman.toml ${D}/${libdir}/sota/conf.d/30-fake_pacman.toml + + install -m 0644 ${WORKDIR}/35-network_config.toml ${D}/${libdir}/sota/conf.d/35-network_config.toml + sed -i -e 's|@PORT@|${SECONDARY_PORT}|g' \ + -e 's|@PRIMARY_IP@|${PRIMARY_IP}|g' \ + -e 's|@PRIMARY_PORT@|${PRIMARY_PORT}|g' \ + ${D}/${libdir}/sota/conf.d/35-network_config.toml + + install -m 0644 ${WORKDIR}/45-id_config.toml ${D}/${libdir}/sota/conf.d/45-id_config.toml + sed -i -e 's|@SERIAL@|${SECONDARY_SERIAL_ID}|g' \ + -e 's|@HWID@|${SECONDARY_HARDWARE_ID}|g' \ + ${D}/${libdir}/sota/conf.d/45-id_config.toml + +} + +FILES_${PN} = " \ + ${libdir}/sota/conf.d \ + ${libdir}/sota/conf.d/30-fake_pacman.toml \ + ${libdir}/sota/conf.d/35-network_config.toml \ + ${libdir}/sota/conf.d/45-id_config.toml \ + " + +# vim:set ts=4 sw=4 sts=4 expandtab: diff --git a/recipes-test/demo-config/shared-conf.inc b/recipes-test/demo-config/shared-conf.inc new file mode 100644 index 0000000..ce2bb44 --- /dev/null +++ b/recipes-test/demo-config/shared-conf.inc @@ -0,0 +1,5 @@ +SECONDARY_IP ?= "10.0.3.2" +SECONDARY_PORT ?= "9050" +PRIMARY_IP ?= "10.0.3.1" +PRIMARY_PORT ?= "9040" +PRIMARY_WAIT_TIMEOUT ?= "120" diff --git a/recipes-test/demo-secondary-config/files/30-fake_pacman.toml b/recipes-test/demo-secondary-config/files/30-fake_pacman.toml deleted file mode 100644 index 3fb5cf2..0000000 --- a/recipes-test/demo-secondary-config/files/30-fake_pacman.toml +++ /dev/null @@ -1,2 +0,0 @@ -[pacman] -type = "fake" diff --git a/recipes-test/demo-secondary-config/files/35-network_config.toml b/recipes-test/demo-secondary-config/files/35-network_config.toml deleted file mode 100644 index db7a1bb..0000000 --- a/recipes-test/demo-secondary-config/files/35-network_config.toml +++ /dev/null @@ -1,4 +0,0 @@ -[network] -port = @PORT@ -primary_ip = @PRIMARY_IP@ -primary_port = @PRIMARY_PORT@ diff --git a/recipes-test/demo-secondary-config/files/45-id_config.toml b/recipes-test/demo-secondary-config/files/45-id_config.toml deleted file mode 100644 index 6cbd77f..0000000 --- a/recipes-test/demo-secondary-config/files/45-id_config.toml +++ /dev/null @@ -1,3 +0,0 @@ -[uptane] -ecu_serial = @SERIAL@ -ecu_hardware_id = @HWID@ diff --git a/recipes-test/demo-secondary-config/secondary-config.bb b/recipes-test/demo-secondary-config/secondary-config.bb deleted file mode 100644 index 25972d4..0000000 --- a/recipes-test/demo-secondary-config/secondary-config.bb +++ /dev/null @@ -1,43 +0,0 @@ -DESCRIPTION = "Sample configuration for an Uptane Secondary" -LICENSE = "MPL-2.0" -LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MPL-2.0;md5=815ca599c9df247a0c7f619bab123dad" - -SECONDARY_SERIAL_ID ?= "" -SOTA_HARDWARE_ID ?= "${MACHINE}-sndry" -SECONDARY_HARDWARE_ID ?= "${SOTA_HARDWARE_ID}" - -SECONDARY_PORT ?= "9050" -PRIMARY_IP ?= "10.0.3.1" -PRIMARY_PORT ?= "9040" - -SRC_URI = "\ - file://30-fake_pacman.toml \ - file://35-network_config.toml \ - file://45-id_config.toml \ - " - -do_install () { - install -m 0700 -d ${D}${libdir}/sota/conf.d - install -m 0644 ${WORKDIR}/30-fake_pacman.toml ${D}/${libdir}/sota/conf.d/30-fake_pacman.toml - - install -m 0644 ${WORKDIR}/35-network_config.toml ${D}/${libdir}/sota/conf.d/35-network_config.toml - sed -i -e 's|@PORT@|${SECONDARY_PORT}|g' \ - -e 's|@PRIMARY_IP@|${PRIMARY_IP}|g' \ - -e 's|@PRIMARY_PORT@|${PRIMARY_PORT}|g' \ - ${D}/${libdir}/sota/conf.d/35-network_config.toml - - install -m 0644 ${WORKDIR}/45-id_config.toml ${D}/${libdir}/sota/conf.d/45-id_config.toml - sed -i -e 's|@SERIAL@|${SECONDARY_SERIAL_ID}|g' \ - -e 's|@HWID@|${SECONDARY_HARDWARE_ID}|g' \ - ${D}/${libdir}/sota/conf.d/45-id_config.toml - -} - -FILES_${PN} = " \ - ${libdir}/sota/conf.d \ - ${libdir}/sota/conf.d/30-fake_pacman.toml \ - ${libdir}/sota/conf.d/35-network_config.toml \ - ${libdir}/sota/conf.d/45-id_config.toml \ - " - -# vim:set ts=4 sw=4 sts=4 expandtab: diff --git a/recipes-test/images/primary-image.bb b/recipes-test/images/primary-image.bb index 935f7ac..ba1dc1f 100644 --- a/recipes-test/images/primary-image.bb +++ b/recipes-test/images/primary-image.bb @@ -9,7 +9,8 @@ IMAGE_INSTALL_remove = " \ " IMAGE_INSTALL_append = " \ - primary-network-config \ + primary-network-config \ + primary-config \ " # vim:set ts=4 sw=4 sts=4 expandtab: -- cgit v1.2.3-54-g00ecf