Bug 62344 - tests depend on /etc/machine-id
Summary: tests depend on /etc/machine-id
Status: RESOLVED WONTFIX
Alias: None
Product: systemd
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: Other All
: medium minor
Assignee: systemd-bugs
QA Contact: systemd-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-14 16:34 UTC by Martin Pitt
Modified: 2013-03-15 11:33 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Martin Pitt 2013-03-14 16:34:45 UTC
"make check" has 6 failures for me:

FAIL: test-unit-name
FAIL: test-unit-file
FAIL: test-id128
FAIL: test-journal
FAIL: test-journal-stream
FAIL: test-journal-verify

Turns out that these rely on an existing /etc/machine-id. Once I create one, all tests succeed.

Depending on the outside environment is rather bad for unit tests, as this breaks operation in continuous integration servers, ephemeral chroots, etc. If these tests need a machine ID, could they use one generated in a temporary location?
Comment 1 Martin Pitt 2013-03-14 16:47:59 UTC
Note that this particularly hits us during package builds. These happen in minimal chroots which don't have any particular system setup, but we would still like to run the tests during package build to ensure they keep working on all architectures.
Comment 2 Kay Sievers 2013-03-14 16:52:06 UTC
Hmm, if you run in a chroot, why not just add the missing file there?
Comment 3 Martin Pitt 2013-03-14 16:55:24 UTC
Would it be acceptable to do something like this, and set it in the tests?

-        fd = open("/etc/machine-id", O_RDONLY|O_CLOEXEC|O_NOCTTY);
+        machine_id_path = getenv("SYSTEMD_MACHINE_ID_PATH");
+        if (machine_id_path == NULL)
+                machine_id_path = "/etc/machine-id";
+        fd = open(machine_id_path, O_RDONLY|O_CLOEXEC|O_NOCTTY);

Security wise it should not matter much, as you can also use LD_PRELOAD to divert the path.
Comment 4 Martin Pitt 2013-03-14 16:55:40 UTC
(In reply to comment #2)
> Hmm, if you run in a chroot, why not just add the missing file there?

Package builds can't do that, they don't run as root.
Comment 5 Lennart Poettering 2013-03-15 00:17:59 UTC
May I suggest to just add this to Ubuntu? It would really be a useful feature anyway...

I mean, this is not really the most exotic thing, you could just link the dbus machine id to /etc/machine-id...

The other option is simply not to run the tests on Ubuntu?

We actually try to gently push people into just adopting /etc/machine-id, because it is so useful and we want to allow code to simply rely on it, and so I am not really interested in adding code that allows people to maintain fallback logic...
Comment 6 Martin Pitt 2013-03-15 06:25:44 UTC
(In reply to comment #5)
> May I suggest to just add this to Ubuntu?

Sure, I can do that. I just thought I at least propose it before assuming it wasn't useful for anyone else.

> I mean, this is not really the most exotic thing, you could just link the
> dbus machine id to /etc/machine-id...

Yeah, I guess we can do that, if the D-BUS id is a sanctioned source for libsystemd-id128.

Thanks!
Comment 7 Kay Sievers 2013-03-15 11:33:30 UTC
/etc/machine-id and the D-Bus machine-id are identical, yes. Systemd
just moved it to /etc as a common interface, not a D-Bus private
setting.

All *should* work fine, if the D-Bus own one is removed today:
  http://cgit.freedesktop.org/dbus/dbus/commit/?id=66e52541d5bdd4927a5c702963749760643313f4

Future versions of D-Bus, including the ongoing kdbus work will not use the
old location anymore, but require /etc/machine-id.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.