Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions tests/test_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ class TestRules(unittest.TestCase):
def setUp(self):
Applications._apps = ApplicationsCollection()
self.tracer = Tracer(PackageManagerMock(), Rules, Applications, memory=dump_memory_mock)
self.tracer.timestamp = 5555 # Sure, it should be a UNIX timestamp value
Applications._append_application({"name": "kernel", "ignore": True})
Application.processes_factory = ProcessesMock

@patch('tracer.resources.applications.System.init_system', return_value="dummy")
def test_trace_affected(self, init_system):
@patch('tracer.resources.applications.System.boot_time', return_value=5555)
def test_trace_affected(self, boot_time, init_system):
affected = self.tracer.trace_affected()
self.assertSetEqual(set(affected), set([Applications.find("baz"), Applications.find("qux")]))
self.assertIsInstance(affected, ApplicationsCollection)

def test_trace_application(self):
@patch('tracer.resources.applications.System.boot_time', return_value=5555)
def test_trace_application(self, boot_time):
affected = self.tracer.trace_application(Applications.find("baz"), AffectedProcessMock)
self.assertIsInstance(affected, AffectedProcessesCollection)
self.assertEqual(len(affected), 1)
Expand Down
1 change: 1 addition & 0 deletions tracer/resources/args_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
parser.add_argument('-t', '--timestamp',
nargs=1,
default=[None],
type=float,
dest='timestamp',
help='since when the updates should be'
)
Expand Down
10 changes: 9 additions & 1 deletion tracer/resources/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,19 @@ def _modified_packages(self):
if self.specified_packages and self.now:
return PackagesCollection(self.specified_packages)

timestamp = self.timestamp if self.timestamp else System.boot_time()
timestamp = self._timestamp()
packages = self._PACKAGE_MANAGER.packages_newer_than(timestamp)
packages = packages.intersection(self.specified_packages)
return packages

def _timestamp(self):
boot = System.boot_time()
if not self.timestamp:
return boot
if self.timestamp < boot:
return boot
return self.timestamp

def trace_affected(self, user=None):
"""
Returns collection of applications which uses some files that have been modified
Expand Down