-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add coverage for improved countme system age
Adapt the countme feature to the libdnf fix for issue #1611, namely: - Turn the main scenario into a scenario outline to capture the various machine-id(5) configurations (see the table). - Add an upgrade scenario (from F39 to F40) that verifies that system age is now independent of $releasever on systems with a machine-id file. - Use NO_FAKE_STAT=1 in faketime invocations so that filesystem timestamps are *not* reported relative to the target time (this would break our custom machine-id timestamps we set here), see faketime(1) for details. - Add a new MachineId class to encapsulate the machine-id file, similar to OSRelease. - Mark the touched scenarios as destructive (due to them overriding the machine-id file).
- Loading branch information
Showing
4 changed files
with
136 additions
and
28 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
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
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,63 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import absolute_import | ||
from __future__ import print_function | ||
|
||
from behave import fixture | ||
from datetime import datetime | ||
import os | ||
|
||
|
||
class MachineId(object): | ||
"""Represents the machine-id(5) file.""" | ||
def __init__(self, path): | ||
self._path = path | ||
self._backup = path + '.bak' | ||
if os.path.exists(path): | ||
os.rename(path, self._backup) | ||
|
||
def _set_mtime(self, value): | ||
"""Set the given mtime on this file.""" | ||
times = None | ||
if value is not None and value != 'today': | ||
ts = int(datetime.strptime(value, '%b %d, %Y').timestamp()) | ||
times = (ts, ts) | ||
os.utime(self._path, times=times) | ||
|
||
def initialize(self, mtime): | ||
"""Initialize the file and set the given mtime.""" | ||
with open(self._path, 'w') as f: | ||
f.write('dummy\n') | ||
self._set_mtime(mtime) | ||
|
||
def uninitialize(self, mtime): | ||
"""Uninitialize the file and set the given mtime.""" | ||
with open(self._path, 'w') as f: | ||
f.write('uninitialized\n') | ||
self._set_mtime(mtime) | ||
|
||
def empty(self): | ||
"""Empty the file.""" | ||
open(self._path, 'w').close() | ||
|
||
def delete(self): | ||
"""Delete the file.""" | ||
if os.path.exists(self._path): | ||
os.remove(self._path) | ||
|
||
def __del__(self): | ||
"""Restore the backup.""" | ||
if os.path.exists(self._backup): | ||
os.rename(self._backup, self._path) | ||
|
||
|
||
@fixture | ||
def machineid_fixture(context): | ||
try: | ||
if not hasattr(context, "machineid"): | ||
path = os.path.realpath('/etc/machine-id') | ||
context.scenario.machineid = MachineId(path) | ||
|
||
yield context.scenario.machineid | ||
finally: | ||
del context.scenario.machineid |
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