From 1d05d369f2820e836e7f65aa45cf0775e6a875f0 Mon Sep 17 00:00:00 2001 From: Mike Sul Date: Wed, 15 May 2019 11:17:41 +0300 Subject: OTA-2541: Network configuration on IP/Posix Secondary Signed-off-by: Mike Sul --- recipes-sota/aktualizr/aktualizr_git.bb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/recipes-sota/aktualizr/aktualizr_git.bb b/recipes-sota/aktualizr/aktualizr_git.bb index 903f2de..db8cf38 100755 --- a/recipes-sota/aktualizr/aktualizr_git.bb +++ b/recipes-sota/aktualizr/aktualizr_git.bb @@ -119,6 +119,14 @@ 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 -- cgit v1.2.3-54-g00ecf From ee23fa2bcae2fd793d62a531cb5ae0c9272d8a97 Mon Sep 17 00:00:00 2001 From: Mike Sul Date: Thu, 16 May 2019 22:47:12 +0300 Subject: OTA-2541: Static IP address on Primary's and Secondary's internal NIC Signed-off-by: Mike Sul --- .../files/26-static-client.network | 7 +++++++ .../demo-network-config/primary-network-config.bb | 13 ++++++++++--- .../demo-network-config/secondary-network-config.bb | 13 ++++++++++--- .../demo-network-config/static-network-config.inc | 16 ++++++++++++++++ .../demo-secondary-config/files/30-fake_pacman.toml | 2 ++ .../demo-secondary-config/secondary-config.bb | 20 ++++++++++++++++++++ recipes-test/images/primary-image.bb | 1 + recipes-test/images/secondary-image.bb | 1 + scripts/qemucommand.py | 4 ++-- 9 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 recipes-test/demo-network-config/files/26-static-client.network create mode 100644 recipes-test/demo-network-config/static-network-config.inc create mode 100644 recipes-test/demo-secondary-config/files/30-fake_pacman.toml create mode 100644 recipes-test/demo-secondary-config/secondary-config.bb diff --git a/recipes-test/demo-network-config/files/26-static-client.network b/recipes-test/demo-network-config/files/26-static-client.network new file mode 100644 index 0000000..19a6b83 --- /dev/null +++ b/recipes-test/demo-network-config/files/26-static-client.network @@ -0,0 +1,7 @@ +[Match] +Name=@IFNAME@ + +[Network] +Description=Private internal network between aktualizr Primary and Secondary nodes +Address=@ADDR@ +DHCP=no diff --git a/recipes-test/demo-network-config/primary-network-config.bb b/recipes-test/demo-network-config/primary-network-config.bb index 78678a2..ce19f07 100644 --- a/recipes-test/demo-network-config/primary-network-config.bb +++ b/recipes-test/demo-network-config/primary-network-config.bb @@ -3,8 +3,9 @@ LICENSE = "CLOSED" inherit allarch -SRC_URI = "file://25-dhcp-server.network" - +SRC_URI = "\ + file://27-dhcp-client-external.network \ + " FILES_${PN} = "/usr/lib/systemd/network" @@ -12,5 +13,11 @@ PR = "1" do_install() { install -d ${D}/usr/lib/systemd/network - install -m 0644 ${WORKDIR}/25-dhcp-server.network ${D}/usr/lib/systemd/network/ + install -m 0644 ${WORKDIR}/27-dhcp-client-external.network ${D}/usr/lib/systemd/network/ } + +SECONDARY_NETWORK_IP_ADDR ?= "10.0.3.1" + +require static-network-config.inc + +# vim:set ts=4 sw=4 sts=4 expandtab: diff --git a/recipes-test/demo-network-config/secondary-network-config.bb b/recipes-test/demo-network-config/secondary-network-config.bb index 9091c65..6473e05 100644 --- a/recipes-test/demo-network-config/secondary-network-config.bb +++ b/recipes-test/demo-network-config/secondary-network-config.bb @@ -3,18 +3,25 @@ LICENSE = "CLOSED" inherit allarch +# TODO: It configures the 'user' interface in NAT mode and provides an access to public Inet via it +# which is not desired for Secondary. It cannot be just removed since we get SSH access to Secondary +# VM via this interface. So, the task is to configure the interface in such way that it does provide access +# via SSH from a host machine and forbids an access to Inet SRC_URI = "\ - file://26-dhcp-client.network \ file://27-dhcp-client-external.network \ " - FILES_${PN} = "/usr/lib/systemd/network" PR = "1" do_install() { install -d ${D}/usr/lib/systemd/network - install -m 0644 ${WORKDIR}/26-dhcp-client.network ${D}/usr/lib/systemd/network/ install -m 0644 ${WORKDIR}/27-dhcp-client-external.network ${D}/usr/lib/systemd/network/ } + +SECONDARY_NETWORK_IP_ADDR ?= "10.0.3.2" + +require static-network-config.inc + +# vim:set ts=4 sw=4 sts=4 expandtab: diff --git a/recipes-test/demo-network-config/static-network-config.inc b/recipes-test/demo-network-config/static-network-config.inc new file mode 100644 index 0000000..27d2a20 --- /dev/null +++ b/recipes-test/demo-network-config/static-network-config.inc @@ -0,0 +1,16 @@ +SRC_URI_append = "\ + file://26-static-client.network \ + " + +SECONDARY_NETWORK_INTERFACE_NAME ?= "enp0s5" + +do_install_append() { + install -d ${D}/usr/lib/systemd/network + install -m 0644 ${WORKDIR}/26-static-client.network ${D}/usr/lib/systemd/network/ + sed -i -e 's|@ADDR@|${SECONDARY_NETWORK_IP_ADDR}|g' \ + -e 's|@IFNAME@|${SECONDARY_NETWORK_INTERFACE_NAME}|g' \ + ${D}/usr/lib/systemd/network/26-static-client.network + +} + +# vim:set ts=4 sw=4 sts=4 expandtab: diff --git a/recipes-test/demo-secondary-config/files/30-fake_pacman.toml b/recipes-test/demo-secondary-config/files/30-fake_pacman.toml new file mode 100644 index 0000000..3fb5cf2 --- /dev/null +++ b/recipes-test/demo-secondary-config/files/30-fake_pacman.toml @@ -0,0 +1,2 @@ +[pacman] +type = "fake" diff --git a/recipes-test/demo-secondary-config/secondary-config.bb b/recipes-test/demo-secondary-config/secondary-config.bb new file mode 100644 index 0000000..3187ff0 --- /dev/null +++ b/recipes-test/demo-secondary-config/secondary-config.bb @@ -0,0 +1,20 @@ +DESCRIPTION = "Sample configuration for an Uptane Secondary" +LICENSE = "CLOSED" + +inherit allarch + +SRC_URI = "\ + file://30-fake_pacman.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 +} + +FILES_${PN} = " \ + ${libdir}/sota/conf.d \ + ${libdir}/sota/conf.d/30-fake_pacman.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 6d2df94..ac14233 100644 --- a/recipes-test/images/primary-image.bb +++ b/recipes-test/images/primary-image.bb @@ -5,6 +5,7 @@ SUMMARY = "A minimal Uptane Primary image running aktualizr, for testing with a LICENSE = "MIT" IMAGE_INSTALL_remove = " \ + virtual/network-configuration \ " IMAGE_INSTALL_append = " \ diff --git a/recipes-test/images/secondary-image.bb b/recipes-test/images/secondary-image.bb index 61df85b..46be3d1 100644 --- a/recipes-test/images/secondary-image.bb +++ b/recipes-test/images/secondary-image.bb @@ -21,6 +21,7 @@ IMAGE_INSTALL_remove = " \ IMAGE_INSTALL_append = " \ aktualizr-secondary \ secondary-network-config \ + secondary-config \ " # vim:set ts=4 sw=4 sts=4 expandtab: diff --git a/scripts/qemucommand.py b/scripts/qemucommand.py index cafab6d..1049d7c 100644 --- a/scripts/qemucommand.py +++ b/scripts/qemucommand.py @@ -109,8 +109,8 @@ class QemuCommand(object): cmdline += ['-net', 'dump,file=' + self.pcap] if self.secondary_network: cmdline += [ - '-net', 'nic,vlan=1,macaddr='+random_mac(), - '-net', 'socket,vlan=1,mcast=230.0.0.1:1234,localaddr=127.0.0.1', + '-netdev', 'socket,id=vlan1,mcast=230.0.0.1:1234,localaddr=127.0.0.1', + '-device', 'e1000,netdev=vlan1,mac='+random_mac(), ] if self.gui: cmdline += ["-serial", "stdio"] -- cgit v1.2.3-54-g00ecf From 753f664541c84f1977f370690e38d9130bf9e2f1 Mon Sep 17 00:00:00 2001 From: Mike Sul Date: Fri, 17 May 2019 10:58:30 +0300 Subject: OTA-2541: Remove Secondary's socket service. Use a regular systemd service to start Seconadry daemon Signed-off-by: Mike Sul --- recipes-sota/aktualizr/aktualizr_git.bb | 5 +---- recipes-sota/aktualizr/files/aktualizr-secondary.service | 6 +++++- recipes-sota/aktualizr/files/aktualizr-secondary.socket | 6 ------ 3 files changed, 6 insertions(+), 11 deletions(-) delete mode 100644 recipes-sota/aktualizr/files/aktualizr-secondary.socket diff --git a/recipes-sota/aktualizr/aktualizr_git.bb b/recipes-sota/aktualizr/aktualizr_git.bb index db8cf38..d61b597 100755 --- a/recipes-sota/aktualizr/aktualizr_git.bb +++ b/recipes-sota/aktualizr/aktualizr_git.bb @@ -22,7 +22,6 @@ SRC_URI = " \ file://run-ptest \ file://aktualizr.service \ file://aktualizr-secondary.service \ - file://aktualizr-secondary.socket \ file://aktualizr-serialcan.service \ file://10-resource-control.conf \ ${@ d.expand("https://ats-tuf-cli-releases.s3-eu-central-1.amazonaws.com/cli-${GARAGE_SIGN_PV}.tgz;unpack=0") if d.getVar('GARAGE_SIGN_AUTOVERSION') != '1' else ''} \ @@ -45,7 +44,7 @@ PTEST_ENABLED = "0" SYSTEMD_PACKAGES = "${PN} ${PN}-secondary" SYSTEMD_SERVICE_${PN} = "aktualizr.service" -SYSTEMD_SERVICE_${PN}-secondary = "aktualizr-secondary.socket" +SYSTEMD_SERVICE_${PN}-secondary = "aktualizr-secondary.service" EXTRA_OECMAKE = "-DCMAKE_BUILD_TYPE=Release -DAKTUALIZR_VERSION=${PV} ${@bb.utils.contains('PTEST_ENABLED', '1', '-DTESTSUITE_VALGRIND=on', '', d)}" @@ -100,7 +99,6 @@ do_install_append () { install -m 0644 ${S}/config/sota_secondary.toml ${D}/${libdir}/sota/sota_secondary.toml install -m 0644 ${S}/config/sota_uboot_env.toml ${D}/${libdir}/sota/sota_uboot_env.toml install -d ${D}${systemd_unitdir}/system - install -m 0644 ${WORKDIR}/aktualizr-secondary.socket ${D}${systemd_unitdir}/system/aktualizr-secondary.socket install -m 0644 ${WORKDIR}/aktualizr-secondary.service ${D}${systemd_unitdir}/system/aktualizr-secondary.service install -m 0700 -d ${D}${libdir}/sota/conf.d install -m 0700 -d ${D}${sysconfdir}/sota/conf.d @@ -184,7 +182,6 @@ FILES_${PN}-examples = " \ FILES_${PN}-secondary = " \ ${bindir}/aktualizr-secondary \ ${libdir}/sota/sota_secondary.toml \ - ${systemd_unitdir}/system/aktualizr-secondary.socket \ ${systemd_unitdir}/system/aktualizr-secondary.service \ " diff --git a/recipes-sota/aktualizr/files/aktualizr-secondary.service b/recipes-sota/aktualizr/files/aktualizr-secondary.service index 9628ee3..b577ae8 100644 --- a/recipes-sota/aktualizr/files/aktualizr-secondary.service +++ b/recipes-sota/aktualizr/files/aktualizr-secondary.service @@ -1,8 +1,12 @@ [Unit] Description=Aktualizr SOTA Client (UPTANE Secondary) +After=network.target [Service] RestartSec=10 Restart=always -ExecStart=/usr/bin/aktualizr-secondary --config /usr/lib/sota/sota_secondary.toml +ExecStart=/usr/bin/aktualizr-secondary + +[Install] +WantedBy=multi-user.target diff --git a/recipes-sota/aktualizr/files/aktualizr-secondary.socket b/recipes-sota/aktualizr/files/aktualizr-secondary.socket deleted file mode 100644 index da0ee44..0000000 --- a/recipes-sota/aktualizr/files/aktualizr-secondary.socket +++ /dev/null @@ -1,6 +0,0 @@ -[Socket] -ListenStream=9030 -ListenDatagram=9031 - -[Install] -WantedBy=sockets.target \ No newline at end of file -- cgit v1.2.3-54-g00ecf From d0b6547fde5038cb7ab9837681ea370af24de855 Mon Sep 17 00:00:00 2001 From: Mike Sul Date: Tue, 21 May 2019 08:04:44 +0300 Subject: OTA-2541: Add suffix '-sndry' to a default HW_ID for Secondary. Ability to define IP and Port in local.conf Signed-off-by: Mike Sul --- .../demo-network-config/primary-network-config.bb | 3 ++- .../secondary-network-config.bb | 3 ++- .../demo-network-config/static-network-config.inc | 6 ++--- .../files/35-network_config.toml | 4 ++++ .../demo-secondary-config/files/45-id_config.toml | 3 +++ .../demo-secondary-config/secondary-config.bb | 26 ++++++++++++++++++++-- recipes-test/images/secondary-image.bb | 2 ++ 7 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 recipes-test/demo-secondary-config/files/35-network_config.toml create mode 100644 recipes-test/demo-secondary-config/files/45-id_config.toml diff --git a/recipes-test/demo-network-config/primary-network-config.bb b/recipes-test/demo-network-config/primary-network-config.bb index ce19f07..9725898 100644 --- a/recipes-test/demo-network-config/primary-network-config.bb +++ b/recipes-test/demo-network-config/primary-network-config.bb @@ -16,7 +16,8 @@ do_install() { install -m 0644 ${WORKDIR}/27-dhcp-client-external.network ${D}/usr/lib/systemd/network/ } -SECONDARY_NETWORK_IP_ADDR ?= "10.0.3.1" +PRIMARY_IP ?= "10.0.3.1" +IP_ADDR = "${PRIMARY_IP}" require static-network-config.inc diff --git a/recipes-test/demo-network-config/secondary-network-config.bb b/recipes-test/demo-network-config/secondary-network-config.bb index 6473e05..e33229d 100644 --- a/recipes-test/demo-network-config/secondary-network-config.bb +++ b/recipes-test/demo-network-config/secondary-network-config.bb @@ -20,7 +20,8 @@ do_install() { install -m 0644 ${WORKDIR}/27-dhcp-client-external.network ${D}/usr/lib/systemd/network/ } -SECONDARY_NETWORK_IP_ADDR ?= "10.0.3.2" +SECONDARY_IP ?= "10.0.3.2" +IP_ADDR = "${SECONDARY_IP}" require static-network-config.inc diff --git a/recipes-test/demo-network-config/static-network-config.inc b/recipes-test/demo-network-config/static-network-config.inc index 27d2a20..e64675e 100644 --- a/recipes-test/demo-network-config/static-network-config.inc +++ b/recipes-test/demo-network-config/static-network-config.inc @@ -2,13 +2,13 @@ SRC_URI_append = "\ file://26-static-client.network \ " -SECONDARY_NETWORK_INTERFACE_NAME ?= "enp0s5" +SECONDARY_INTERFACE ?= "enp0s5" do_install_append() { install -d ${D}/usr/lib/systemd/network install -m 0644 ${WORKDIR}/26-static-client.network ${D}/usr/lib/systemd/network/ - sed -i -e 's|@ADDR@|${SECONDARY_NETWORK_IP_ADDR}|g' \ - -e 's|@IFNAME@|${SECONDARY_NETWORK_INTERFACE_NAME}|g' \ + sed -i -e 's|@ADDR@|${IP_ADDR}|g' \ + -e 's|@IFNAME@|${SECONDARY_INTERFACE}|g' \ ${D}/usr/lib/systemd/network/26-static-client.network } diff --git a/recipes-test/demo-secondary-config/files/35-network_config.toml b/recipes-test/demo-secondary-config/files/35-network_config.toml new file mode 100644 index 0000000..db7a1bb --- /dev/null +++ b/recipes-test/demo-secondary-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-secondary-config/files/45-id_config.toml b/recipes-test/demo-secondary-config/files/45-id_config.toml new file mode 100644 index 0000000..6cbd77f --- /dev/null +++ b/recipes-test/demo-secondary-config/files/45-id_config.toml @@ -0,0 +1,3 @@ +[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 index 3187ff0..b05ab8e 100644 --- a/recipes-test/demo-secondary-config/secondary-config.bb +++ b/recipes-test/demo-secondary-config/secondary-config.bb @@ -1,20 +1,42 @@ DESCRIPTION = "Sample configuration for an Uptane Secondary" LICENSE = "CLOSED" -inherit allarch +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 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/secondary-image.bb b/recipes-test/images/secondary-image.bb index 46be3d1..a688bbd 100644 --- a/recipes-test/images/secondary-image.bb +++ b/recipes-test/images/secondary-image.bb @@ -4,6 +4,8 @@ SUMMARY = "A minimal Uptane Secondary image running aktualizr-secondary" LICENSE = "MIT" +SECONDARY_SERIAL_ID ?= "" +SOTA_HARDWARE_ID ?= "${MACHINE}-sndry" # Remove default aktualizr primary, and the provisioning configuration (which # RDEPENDS on aktualizr) -- cgit v1.2.3-54-g00ecf From f14d0017d221f93b51d57484619aff28cb23f9bd Mon Sep 17 00:00:00 2001 From: Mike Sul Date: Tue, 21 May 2019 19:03:36 +0300 Subject: OTA-2541: Use MPL-2.0 license for recipes-test's recipes Signed-off-by: Mike Sul --- recipes-test/big-update/big-update_1.0.bb | 2 +- recipes-test/big-update/big-update_2.0.bb | 2 +- recipes-test/demo-network-config/primary-network-config.bb | 3 ++- recipes-test/demo-network-config/secondary-network-config.bb | 3 ++- recipes-test/demo-secondary-config/secondary-config.bb | 3 ++- recipes-test/images/primary-image.bb | 2 +- recipes-test/images/secondary-image.bb | 2 +- 7 files changed, 10 insertions(+), 7 deletions(-) diff --git a/recipes-test/big-update/big-update_1.0.bb b/recipes-test/big-update/big-update_1.0.bb index 68b9746..3b1d652 100644 --- a/recipes-test/big-update/big-update_1.0.bb +++ b/recipes-test/big-update/big-update_1.0.bb @@ -1,5 +1,5 @@ DESCRIPTION = "Example Package with 10MB of random, seeded content" -LICENSE = "CLOSED" +LICENSE = "MPL-2.0" SRC_URI = "file://rand_file.py" diff --git a/recipes-test/big-update/big-update_2.0.bb b/recipes-test/big-update/big-update_2.0.bb index 20c8138..7cb6e94 100644 --- a/recipes-test/big-update/big-update_2.0.bb +++ b/recipes-test/big-update/big-update_2.0.bb @@ -1,5 +1,5 @@ DESCRIPTION = "Example Package with 12MB of random, seeded content" -LICENSE = "CLOSED" +LICENSE = "MPL-2.0" SRC_URI = "file://rand_file.py" diff --git a/recipes-test/demo-network-config/primary-network-config.bb b/recipes-test/demo-network-config/primary-network-config.bb index 9725898..c7daa15 100644 --- a/recipes-test/demo-network-config/primary-network-config.bb +++ b/recipes-test/demo-network-config/primary-network-config.bb @@ -1,5 +1,6 @@ DESCRIPTION = "Sample network configuration for an Uptane Primary" -LICENSE = "CLOSED" +LICENSE = "MPL-2.0" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MPL-2.0;md5=815ca599c9df247a0c7f619bab123dad" inherit allarch diff --git a/recipes-test/demo-network-config/secondary-network-config.bb b/recipes-test/demo-network-config/secondary-network-config.bb index e33229d..c70d88a 100644 --- a/recipes-test/demo-network-config/secondary-network-config.bb +++ b/recipes-test/demo-network-config/secondary-network-config.bb @@ -1,5 +1,6 @@ DESCRIPTION = "Sample network configuration for an Uptane Secondary" -LICENSE = "CLOSED" +LICENSE = "MPL-2.0" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MPL-2.0;md5=815ca599c9df247a0c7f619bab123dad" inherit allarch diff --git a/recipes-test/demo-secondary-config/secondary-config.bb b/recipes-test/demo-secondary-config/secondary-config.bb index b05ab8e..25972d4 100644 --- a/recipes-test/demo-secondary-config/secondary-config.bb +++ b/recipes-test/demo-secondary-config/secondary-config.bb @@ -1,5 +1,6 @@ DESCRIPTION = "Sample configuration for an Uptane Secondary" -LICENSE = "CLOSED" +LICENSE = "MPL-2.0" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MPL-2.0;md5=815ca599c9df247a0c7f619bab123dad" SECONDARY_SERIAL_ID ?= "" SOTA_HARDWARE_ID ?= "${MACHINE}-sndry" diff --git a/recipes-test/images/primary-image.bb b/recipes-test/images/primary-image.bb index ac14233..935f7ac 100644 --- a/recipes-test/images/primary-image.bb +++ b/recipes-test/images/primary-image.bb @@ -2,7 +2,7 @@ include recipes-core/images/core-image-minimal.bb SUMMARY = "A minimal Uptane Primary image running aktualizr, for testing with a Linux secondary" -LICENSE = "MIT" +LICENSE = "MPL-2.0" IMAGE_INSTALL_remove = " \ virtual/network-configuration \ diff --git a/recipes-test/images/secondary-image.bb b/recipes-test/images/secondary-image.bb index a688bbd..4cae874 100644 --- a/recipes-test/images/secondary-image.bb +++ b/recipes-test/images/secondary-image.bb @@ -2,7 +2,7 @@ include recipes-core/images/core-image-minimal.bb SUMMARY = "A minimal Uptane Secondary image running aktualizr-secondary" -LICENSE = "MIT" +LICENSE = "MPL-2.0" SECONDARY_SERIAL_ID ?= "" SOTA_HARDWARE_ID ?= "${MACHINE}-sndry" -- cgit v1.2.3-54-g00ecf From 0b89fa5f5505891d8b358f8ef829b0200d238705 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 --- 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 d61b597..f4c9946 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 From 5929016fad098a83286b4849f4ff96d3f5f26361 Mon Sep 17 00:00:00 2001 From: Mike Sul Date: Thu, 23 May 2019 15:38:42 +0300 Subject: OTA-2541: IP Secondary tests (oe-selftest) Signed-off-by: Mike Sul --- lib/oeqa/selftest/cases/testutils.py | 53 +++++---- lib/oeqa/selftest/cases/updater_qemux86_64.py | 151 ++++++++++++++++++-------- 2 files changed, 138 insertions(+), 66 deletions(-) diff --git a/lib/oeqa/selftest/cases/testutils.py b/lib/oeqa/selftest/cases/testutils.py index 2ad99ad..f8b1904 100644 --- a/lib/oeqa/selftest/cases/testutils.py +++ b/lib/oeqa/selftest/cases/testutils.py @@ -7,49 +7,57 @@ from time import sleep from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars from qemucommand import QemuCommand +logger = logging.getLogger("selftest") -def qemu_launch(efi=False, machine=None, imagename=None): - logger = logging.getLogger("selftest") - if imagename is None: - imagename = 'core-image-minimal' - logger.info('Running bitbake to build {}'.format(imagename)) - bitbake(imagename) + +def qemu_launch(efi=False, machine=None, imagename='core-image-minimal', **kwargs): + qemu_bake_image(imagename) + return qemu_boot_image(efi=efi, machine=machine, imagename=imagename, **kwargs) + + +def qemu_terminate(s): + try: + s.terminate() + s.wait(timeout=10) + except KeyboardInterrupt: + pass + + +def qemu_boot_image(imagename, **kwargs): # Create empty object. args = type('', (), {})() args.imagename = imagename - args.mac = None + args.mac = kwargs.get('mac', None) # Could use DEPLOY_DIR_IMAGE here but it's already in the machine # subdirectory. args.dir = 'tmp/deploy/images' - args.efi = efi - args.machine = machine + args.efi = kwargs.get('efi', False) + args.machine = kwargs.get('machine', None) qemu_use_kvm = get_bb_var("QEMU_USE_KVM") if qemu_use_kvm and \ - (qemu_use_kvm == 'True' and 'x86' in machine or + (qemu_use_kvm == 'True' and 'x86' in args.machine or get_bb_var('MACHINE') in qemu_use_kvm.split()): args.kvm = True else: args.kvm = None # Autodetect - args.no_gui = True - args.gdb = False - args.pcap = None - args.overlay = None - args.dry_run = False - args.secondary_network = False + args.no_gui = kwargs.get('no_gui', True) + args.gdb = kwargs.get('gdb', False) + args.pcap = kwargs.get('pcap', None) + args.overlay = kwargs.get('overlay', None) + args.dry_run = kwargs.get('dry_run', False) + args.secondary_network = kwargs.get('secondary_network', False) qemu = QemuCommand(args) cmdline = qemu.command_line() print('Booting image with run-qemu-ota...') s = subprocess.Popen(cmdline) - sleep(10) + sleep(kwargs.get('wait_for_boot_time', 10)) return qemu, s -def qemu_terminate(s): - try: - s.terminate() - except KeyboardInterrupt: - pass +def qemu_bake_image(imagename): + logger.info('Running bitbake to build {}'.format(imagename)) + bitbake(imagename) def qemu_send_command(port, command, timeout=60): @@ -122,7 +130,6 @@ def verifyProvisioned(testInst, machine): m = p.search(stdout.decode()) testInst.assertTrue(m, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) testInst.assertGreater(m.lastindex, 0, 'Device ID could not be read: ' + stderr.decode() + stdout.decode()) - logger = logging.getLogger("selftest") logger.info('Device successfully provisioned with ID: ' + m.group(1)) # vim:set ts=4 sw=4 sts=4 expandtab: diff --git a/lib/oeqa/selftest/cases/updater_qemux86_64.py b/lib/oeqa/selftest/cases/updater_qemux86_64.py index 9f32bcf..f951bc7 100644 --- a/lib/oeqa/selftest/cases/updater_qemux86_64.py +++ b/lib/oeqa/selftest/cases/updater_qemux86_64.py @@ -4,11 +4,12 @@ import logging import re import unittest from time import sleep +from uuid import uuid4 from oeqa.selftest.case import OESelftestTestCase from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars from testutils import qemu_launch, qemu_send_command, qemu_terminate, \ - akt_native_run, verifyNotProvisioned, verifyProvisioned + akt_native_run, verifyNotProvisioned, verifyProvisioned, qemu_bake_image, qemu_boot_image class GeneralTests(OESelftestTestCase): @@ -309,7 +310,91 @@ class HsmTests(OESelftestTestCase): verifyProvisioned(self, machine) -class SecondaryTests(OESelftestTestCase): +class IpSecondaryTests(OESelftestTestCase): + + class Image: + def __init__(self, imagename, binaryname, machine='qemux86-64', bake=True, **kwargs): + self.machine = machine + self.imagename = imagename + self.boot_kwargs = kwargs + self.binaryname = binaryname + self.stdout = '' + self.stderr = '' + self.retcode = 0 + if bake: + self.bake() + + def bake(self): + self.configure() + qemu_bake_image(self.imagename) + + def send_command(self, cmd): + stdout, stderr, retcode = qemu_send_command(self.qemu.ssh_port, cmd, timeout=60) + return str(stdout), str(stderr), retcode + + def __enter__(self): + self.qemu, self.process = qemu_boot_image(machine=self.machine, imagename=self.imagename, + wait_for_boot_time=1, **self.boot_kwargs) + # wait until the VM is booted and is SSHable + self.wait_till_sshable() + + def __exit__(self, exc_type, exc_val, exc_tb): + qemu_terminate(self.process) + + def wait_till_sshable(self): + # qemu_send_command tries to ssh into the qemu VM and blocks until it gets there or timeout happens + # so it helps us to block q control flow until the VM is booted and a target binary/daemon is running there + self.stdout, self.stderr, self.retcode = self.send_command(self.binaryname + ' --help') + + def was_successfully_booted(self): + return self.retcode == 0 + + class Secondary(Image): + def __init__(self, test_ctx): + self._test_ctx = test_ctx + self.sndry_serial = str(uuid4()) + self.sndry_hw_id = 'qemux86-64-oeselftest-sndry' + self.id = (self.sndry_hw_id, self.sndry_serial) + super(IpSecondaryTests.Secondary, self).__init__('secondary-image', 'aktualizr-secondary', + secondary_network=True) + + def configure(self): + self._test_ctx.append_config('SECONDARY_SERIAL_ID = "{}"'.format(self.sndry_serial)) + self._test_ctx.append_config('SECONDARY_HARDWARE_ID = "{}"'.format(self.sndry_hw_id)) + + class Primary(Image): + def __init__(self, test_ctx): + self._test_ctx = test_ctx + super(IpSecondaryTests.Primary, self).__init__('primary-image', 'aktualizr', secondary_network=True) + + def configure(self): + self._test_ctx.append_config('MACHINE = "qemux86-64"') + self._test_ctx.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "') + + def is_ecu_registered(self, ecu_id): + max_number_of_tries = 20 + try_counter = 0 + + # aktualizr-info is not always able to load ECU serials from DB + # so, let's run it a few times until it actually succeeds + while try_counter < max_number_of_tries: + device_status = self.get_info() + try_counter += 1 + if device_status.find("load ECU serials") == -1: + break + sleep(1) + + if not ((device_status.find(ecu_id[0]) != -1) and (device_status.find(ecu_id[1]) != -1)): + return False + not_registered_field = "Removed or not registered ecus:" + not_reg_start = device_status.find(not_registered_field) + return not_reg_start == -1 or (device_status.find(ecu_id[1], not_reg_start) == -1) + + def get_info(self): + stdout, stderr, retcode = self.send_command('aktualizr-info') + self._test_ctx.assertEqual(retcode, 0, 'Unable to run aktualizr-info: {}'.format(stderr)) + return stdout + def setUpLocal(self): layer = "meta-updater-qemux86-64" result = runCmd('bitbake-layers show-layers') @@ -323,57 +408,37 @@ class SecondaryTests(OESelftestTestCase): runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu) else: self.meta_qemu = None - self.append_config('MACHINE = "qemux86-64"') - self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "') - self.qemu, self.s = qemu_launch(machine='qemux86-64', imagename='secondary-image') + + self.primary = IpSecondaryTests.Primary(self) + self.secondary = IpSecondaryTests.Secondary(self) def tearDownLocal(self): - qemu_terminate(self.s) if self.meta_qemu: runCmd('bitbake-layers remove-layer "%s"' % self.meta_qemu, ignore_status=True) - def qemu_command(self, command): - return qemu_send_command(self.qemu.ssh_port, command) + def test_ip_secondary_registration_if_secondary_starts_first(self): + with self.secondary: + self.assertTrue(self.secondary.was_successfully_booted(), + 'The secondary failed to boot: {}'.format(self.secondary.stderr)) - def test_secondary_present(self): - print('Checking aktualizr-secondary is present') - stdout, stderr, retcode = self.qemu_command('aktualizr-secondary --help') - self.assertEqual(retcode, 0, "Unable to run aktualizr-secondary --help") - self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) + with self.primary: + self.assertTrue(self.primary.was_successfully_booted(), + 'The primary failed to boot: {}'.format(self.primary.stderr)) + self.assertTrue(self.primary.is_ecu_registered(self.secondary.id), + "The secondary wasn't registered at the primary: {}".format(self.primary.get_info())) -class PrimaryTests(OESelftestTestCase): - def setUpLocal(self): - layer = "meta-updater-qemux86-64" - result = runCmd('bitbake-layers show-layers') - if re.search(layer, result.output) is None: - # Assume the directory layout for finding other layers. We could also - # make assumptions by using 'show-layers', but either way, if the - # layers we need aren't where we expect them, we are out of luck. - path = os.path.abspath(os.path.dirname(__file__)) - metadir = path + "/../../../../../" - self.meta_qemu = metadir + layer - runCmd('bitbake-layers add-layer "%s"' % self.meta_qemu) - else: - self.meta_qemu = None - self.append_config('MACHINE = "qemux86-64"') - self.append_config('SOTA_CLIENT_PROV = " aktualizr-auto-prov "') - self.append_config('SOTA_CLIENT_FEATURES = "secondary-network"') - self.qemu, self.s = qemu_launch(machine='qemux86-64', imagename='primary-image') + def test_ip_secondary_registration_if_primary_starts_first(self): + with self.primary: + self.assertTrue(self.primary.was_successfully_booted(), + 'The primary failed to boot: {}'.format(self.primary.stderr)) - def tearDownLocal(self): - qemu_terminate(self.s) - if self.meta_qemu: - runCmd('bitbake-layers remove-layer "%s"' % self.meta_qemu, ignore_status=True) + with self.secondary: + self.assertTrue(self.secondary.was_successfully_booted(), + 'The secondary failed to boot: {}'.format(self.secondary.stderr)) - def qemu_command(self, command): - return qemu_send_command(self.qemu.ssh_port, command) - - def test_aktualizr_present(self): - print('Checking aktualizr is present') - stdout, stderr, retcode = self.qemu_command('aktualizr --help') - self.assertEqual(retcode, 0, "Unable to run aktualizr --help") - self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) + self.assertTrue(self.primary.is_ecu_registered(self.secondary.id), + "The secondary wasn't registered at the primary: {}".format(self.primary.get_info())) class ResourceControlTests(OESelftestTestCase): -- cgit v1.2.3-54-g00ecf From 8e9bbe95badbc889f3cd69caff8a223f65e6042d Mon Sep 17 00:00:00 2001 From: Mike Sul Date: Mon, 27 May 2019 10:38:48 +0300 Subject: OTA-2541: Switch to Aktualizr's version that supports IP Secondaries preconfig and its tests Signed-off-by: Mike Sul --- recipes-sota/aktualizr/aktualizr_git.bb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes-sota/aktualizr/aktualizr_git.bb b/recipes-sota/aktualizr/aktualizr_git.bb index f4c9946..a97939e 100755 --- a/recipes-sota/aktualizr/aktualizr_git.bb +++ b/recipes-sota/aktualizr/aktualizr_git.bb @@ -31,7 +31,7 @@ SRC_URI = " \ SRC_URI[md5sum] = "c5e9968dfe78a7264ab9a8338c11725d" SRC_URI[sha256sum] = "3a19258d7a1825a308aca0da82f7a337985bec05e8951355c4c95f0fcf2444f4" -SRCREV = "c50feb37034eceb1254429d3e3ed38e5b8a0dc60" +SRCREV = "8c523efc4c1f1e6d9dfd41b7e23a202ade4d9ff7" BRANCH ?= "master" S = "${WORKDIR}/git" -- cgit v1.2.3-54-g00ecf