|
|
b677e7 |
From 430445a936cdb4c32c55affdfdd94b7eb910d5e6 Mon Sep 17 00:00:00 2001
|
|
|
b677e7 |
From: David Tardon <dtardon@redhat.com>
|
|
|
b677e7 |
Date: Wed, 31 Mar 2021 10:38:00 +0200
|
|
|
b677e7 |
Subject: [PATCH] test-install-root: add test for unknown WantedBy= target
|
|
|
b677e7 |
|
|
|
b677e7 |
(cherry picked from commit 8adbad370f522831dd9246fe272caf37ce748d4a)
|
|
|
b677e7 |
|
|
|
b677e7 |
Related: #1835351
|
|
|
b677e7 |
---
|
|
|
b677e7 |
src/test/test-install-root.c | 26 ++++++++++++++++++++++++++
|
|
|
b677e7 |
1 file changed, 26 insertions(+)
|
|
|
b677e7 |
|
|
|
b677e7 |
diff --git a/src/test/test-install-root.c b/src/test/test-install-root.c
|
|
|
b677e7 |
index f8b41b04db..73e1e0ae03 100644
|
|
|
b677e7 |
--- a/src/test/test-install-root.c
|
|
|
b677e7 |
+++ b/src/test/test-install-root.c
|
|
|
b677e7 |
@@ -20,6 +20,7 @@ static void test_basic_mask_and_enable(const char *root) {
|
|
|
b677e7 |
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", NULL) == -ENOENT);
|
|
|
b677e7 |
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", NULL) == -ENOENT);
|
|
|
b677e7 |
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", NULL) == -ENOENT);
|
|
|
b677e7 |
+ assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "f.service", NULL) == -ENOENT);
|
|
|
b677e7 |
|
|
|
b677e7 |
p = strjoina(root, "/usr/lib/systemd/system/a.service");
|
|
|
b677e7 |
assert_se(write_string_file(p,
|
|
|
b677e7 |
@@ -147,6 +148,31 @@ static void test_basic_mask_and_enable(const char *root) {
|
|
|
b677e7 |
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
|
|
|
b677e7 |
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
|
|
|
b677e7 |
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
|
|
|
b677e7 |
+
|
|
|
b677e7 |
+ /* Test enabling with unknown dependency target */
|
|
|
b677e7 |
+
|
|
|
b677e7 |
+ p = strjoina(root, "/usr/lib/systemd/system/f.service");
|
|
|
b677e7 |
+ assert_se(write_string_file(p,
|
|
|
b677e7 |
+ "[Install]\n"
|
|
|
b677e7 |
+ "WantedBy=x.target\n", WRITE_STRING_FILE_CREATE) >= 0);
|
|
|
b677e7 |
+
|
|
|
b677e7 |
+ assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "f.service", NULL) >= 0);
|
|
|
b677e7 |
+ assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "f.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
|
|
|
b677e7 |
+
|
|
|
b677e7 |
+ assert_se(unit_file_enable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("f.service"), &changes, &n_changes) == 1);
|
|
|
b677e7 |
+ assert_se(n_changes == 2);
|
|
|
b677e7 |
+ assert_se(changes[0].type == UNIT_FILE_SYMLINK);
|
|
|
b677e7 |
+ assert_se(streq(changes[0].source, "/usr/lib/systemd/system/f.service"));
|
|
|
b677e7 |
+ p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/x.target.wants/f.service");
|
|
|
b677e7 |
+ assert_se(streq(changes[0].path, p));
|
|
|
b677e7 |
+ assert_se(changes[1].type == UNIT_FILE_DESTINATION_NOT_PRESENT);
|
|
|
b677e7 |
+ p = strjoina(root, "/usr/lib/systemd/system/f.service");
|
|
|
b677e7 |
+ assert_se(streq(changes[1].source, p));
|
|
|
b677e7 |
+ assert_se(streq(changes[1].path, "x.target"));
|
|
|
b677e7 |
+ unit_file_changes_free(changes, n_changes);
|
|
|
b677e7 |
+ changes = NULL; n_changes = 0;
|
|
|
b677e7 |
+
|
|
|
b677e7 |
+ assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "f.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
|
|
|
b677e7 |
}
|
|
|
b677e7 |
|
|
|
b677e7 |
static void test_linked_units(const char *root) {
|