-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import contextlib | ||
import os | ||
|
||
import pytest | ||
|
||
|
||
DOT_REGISTERED_PATH = "/etc/insights-client/.registered" | ||
DOT_UNREGISTERED_PATH = "/etc/insights-client/.unregistered" | ||
|
||
MOTD_PATH = "/etc/motd.d/insights-client" | ||
MOTD_SRC = "/etc/insights-client/insights-client.motd" | ||
|
||
|
||
pytestmark = pytest.mark.usefixtures("register_subman") | ||
|
||
|
||
@pytest.fixture | ||
def delete_special_files(): | ||
"""Clean special files before and after test. | ||
Since .registered and .unregistered files are usually ignored and | ||
do not affect the behavior of insights-client, the MOTD case is | ||
special and depends on them. | ||
To ensure the tests here are not affected by them, we remove them | ||
""" | ||
|
||
def delete_files(): | ||
with contextlib.suppress(FileNotFoundError): | ||
os.remove(DOT_REGISTERED_PATH) | ||
with contextlib.suppress(FileNotFoundError): | ||
os.remove(DOT_UNREGISTERED_PATH) | ||
with contextlib.suppress(FileNotFoundError): | ||
os.remove(MOTD_PATH) | ||
|
||
delete_files() | ||
yield | ||
delete_files() | ||
|
||
|
||
@pytest.mark.usefixtures("delete_special_files") | ||
def test_motd(insights_client): | ||
"""MOTD only exists on unregistered system without (.un)registered files.""" | ||
# If the system is not registered, the file should be present. | ||
insights_client.run("--status") | ||
assert os.path.exists(MOTD_PATH) | ||
|
||
# After registration, the file should not exist. | ||
insights_client.register() | ||
assert not os.path.exists(MOTD_PATH) | ||
|
||
# The system was unregistered. Because .unregistered file exists, | ||
# the file should not be present. | ||
insights_client.unregister() | ||
assert not os.path.exists(MOTD_PATH) | ||
|
||
|
||
@pytest.mark.usefixtures("delete_special_files") | ||
def test_motd_dev_null(insights_client): | ||
"""MOTD should not be touched if it is a /dev/null symlink.""" | ||
os.symlink(os.devnull, MOTD_PATH) | ||
|
||
insights_client.run("--status") | ||
assert os.path.samefile(os.devnull, MOTD_PATH) | ||
|
||
insights_client.register() | ||
assert os.path.samefile(os.devnull, MOTD_PATH) |