From de2b0f06546666aacf9dd2fce94e0134768c6a3b Mon Sep 17 00:00:00 2001 From: Phil Wise Date: Tue, 27 Mar 2018 14:06:38 +0200 Subject: Add SOTA client feature to enable secondary network Also add a test for the 'primary-image' --- lib/oeqa/selftest/cases/updater.py | 41 ++++++++++++++++++++++ recipes-sota/aktualizr/aktualizr-auto-prov.bb | 4 ++- recipes-sota/aktualizr/aktualizr_git.bb | 3 +- .../files/27-dhcp-client-external.network | 6 ++++ .../secondary-network-config.bb | 6 +++- recipes-test/images/secondary-image.bb | 2 ++ 6 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 recipes-test/demo-network-config/files/27-dhcp-client-external.network diff --git a/lib/oeqa/selftest/cases/updater.py b/lib/oeqa/selftest/cases/updater.py index 06884e5..e459ffb 100644 --- a/lib/oeqa/selftest/cases/updater.py +++ b/lib/oeqa/selftest/cases/updater.py @@ -548,6 +548,47 @@ class SecondaryTests(OESelftestTestCase): stdout, stderr, retcode = self.qemu_command('echo test | nc localhost 9030') self.assertEqual(retcode, 0, "Unable to connect to secondary") + +class PrimaryTests(OESelftestTestCase): + @classmethod + def setUpClass(cls): + super(PrimaryTests, cls).setUpClass() + logger = logging.getLogger("selftest") + logger.info('Running bitbake to build primary-image') + bitbake('primary-image') + + 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 like. + 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 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_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()) + def qemu_launch(efi=False, machine=None, imagename=None): logger = logging.getLogger("selftest") logger.info('Running bitbake to build core-image-minimal') diff --git a/recipes-sota/aktualizr/aktualizr-auto-prov.bb b/recipes-sota/aktualizr/aktualizr-auto-prov.bb index 2190512..07e5bb8 100644 --- a/recipes-sota/aktualizr/aktualizr-auto-prov.bb +++ b/recipes-sota/aktualizr/aktualizr-auto-prov.bb @@ -35,7 +35,9 @@ do_install() { install -d ${D}${libdir}/sota install -d ${D}${localstatedir}/sota if [ -n "${SOTA_PACKED_CREDENTIALS}" ]; then - install -m 0644 ${STAGING_DIR_NATIVE}${libdir}/sota/sota_autoprov.toml ${D}${libdir}/sota/sota.toml + aktualizr_toml=${@bb.utils.contains('SOTA_CLIENT_FEATURES', 'secondary-network', 'sota_autoprov_primary.toml', 'sota_autoprov.toml', d)} + + install -m 0644 ${STAGING_DIR_NATIVE}${libdir}/sota/${aktualizr_toml} ${D}${libdir}/sota/sota.toml # deploy SOTA credentials if [ -e ${SOTA_PACKED_CREDENTIALS} ]; then diff --git a/recipes-sota/aktualizr/aktualizr_git.bb b/recipes-sota/aktualizr/aktualizr_git.bb index 79a89ef..ba0a261 100644 --- a/recipes-sota/aktualizr/aktualizr_git.bb +++ b/recipes-sota/aktualizr/aktualizr_git.bb @@ -22,7 +22,7 @@ SRC_URI = " \ file://aktualizr-secondary.socket \ file://aktualizr-serialcan.service \ " -SRCREV = "7d1d71a28a9ff0b14240b98600de3d541835b278" +SRCREV = "3fc94e7ed20a486da0067f01906250e9d4868931" BRANCH ?= "master" S = "${WORKDIR}/git" @@ -59,6 +59,7 @@ do_install_append_class-target () { do_install_append_class-native () { install -d ${D}${libdir}/sota install -m 0644 ${S}/config/sota_autoprov.toml ${D}/${libdir}/sota/sota_autoprov.toml + install -m 0644 ${S}/config/sota_autoprov_primary.toml ${D}/${libdir}/sota/sota_autoprov_primary.toml install -m 0644 ${S}/config/sota_hsm_prov.toml ${D}/${libdir}/sota/sota_hsm_prov.toml install -m 0644 ${S}/config/sota_implicit_prov.toml ${D}/${libdir}/sota/sota_implicit_prov.toml install -m 0644 ${S}/config/sota_implicit_prov_ca.toml ${D}/${libdir}/sota/sota_implicit_prov_ca.toml diff --git a/recipes-test/demo-network-config/files/27-dhcp-client-external.network b/recipes-test/demo-network-config/files/27-dhcp-client-external.network new file mode 100644 index 0000000..ba49593 --- /dev/null +++ b/recipes-test/demo-network-config/files/27-dhcp-client-external.network @@ -0,0 +1,6 @@ +[Match] +Name=enp0s3 + +[Network] +Description=External network for secondary +DHCP=yes diff --git a/recipes-test/demo-network-config/secondary-network-config.bb b/recipes-test/demo-network-config/secondary-network-config.bb index 492d3ca..9091c65 100644 --- a/recipes-test/demo-network-config/secondary-network-config.bb +++ b/recipes-test/demo-network-config/secondary-network-config.bb @@ -3,7 +3,10 @@ LICENSE = "CLOSED" inherit allarch -SRC_URI = "file://26-dhcp-client.network" +SRC_URI = "\ + file://26-dhcp-client.network \ + file://27-dhcp-client-external.network \ + " FILES_${PN} = "/usr/lib/systemd/network" @@ -13,4 +16,5 @@ 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/ } diff --git a/recipes-test/images/secondary-image.bb b/recipes-test/images/secondary-image.bb index c1ce57a..02153d0 100644 --- a/recipes-test/images/secondary-image.bb +++ b/recipes-test/images/secondary-image.bb @@ -13,6 +13,8 @@ IMAGE_INSTALL_remove = " \ aktualizr-ca-implicit-prov \ aktualizr-hsm-prov \ aktualizr-implicit-prov \ + connman \ + connman-client \ " IMAGE_INSTALL_append = " \ -- cgit v1.2.3-54-g00ecf From edae332ab5b66d0caf5b68926b23554aa5493040 Mon Sep 17 00:00:00 2001 From: Phil Wise Date: Tue, 27 Mar 2018 14:08:24 +0200 Subject: Restrict secondary network to localhost --- scripts/qemucommand.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qemucommand.py b/scripts/qemucommand.py index e209a07..4918314 100644 --- a/scripts/qemucommand.py +++ b/scripts/qemucommand.py @@ -108,7 +108,7 @@ class QemuCommand(object): if self.secondary_network: cmdline += [ '-net', 'nic,vlan=1,macaddr='+random_mac(), - '-net', 'socket,vlan=1,mcast=230.0.0.1:1234', + '-net', 'socket,vlan=1,mcast=230.0.0.1:1234,localaddr=127.0.0.1', ] if self.gui: cmdline += ["-serial", "stdio"] -- cgit v1.2.3-54-g00ecf