Skip to content

Commit

Permalink
Upgrade container_inspector to latest version and add integration test
Browse files Browse the repository at this point in the history
…#132

Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Jun 7, 2021
1 parent 388894b commit 486831a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion etc/requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ redis==3.5.3
gunicorn==20.1.0

# Docker
container_inspector==21.5.25
container_inspector==21.6.4

# ScanCode-toolkit
scancode-toolkit[packages]==21.3.31
Expand Down
10 changes: 3 additions & 7 deletions scanpipe/pipes/rootfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,9 @@ def __attrs_post_init__(self, *args, **kwargs):
def from_project_codebase(cls, project):
"""
Yield RootFs objects collected from the project "codebase" directory.
Each directory in the input/ is considered as the root of a root filesystem.
"""
# for now we do a dumb thing:
# each directory in input is considered as the root of a rootfs

subdirs = [p for p in project.codebase_path.glob("*/") if p.is_dir()]
subdirs = [path for path in project.codebase_path.glob("*/") if path.is_dir()]
for subdir in subdirs:
rootfs_location = str(subdir.absolute())
yield RootFs(location=rootfs_location)
Expand Down Expand Up @@ -261,9 +259,7 @@ def get_resource_with_md5(project, status):
a non-empty size and md5.
"""
return (
project.codebaseresources.status(
status=status,
)
project.codebaseresources.status(status=status)
.exclude(md5__exact="")
.exclude(size__exact=0)
)
Expand Down
Binary file added scanpipe/tests/data/windows-container-rootfs.tar
Binary file not shown.
14 changes: 14 additions & 0 deletions scanpipe/tests/test_pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from django.test import TestCase
from django.test import TransactionTestCase

from commoncode.archive import extract_tar
from scancode.interrupt import TimeoutError as InterruptTimeoutError

from scanpipe.models import CodebaseResource
Expand Down Expand Up @@ -622,6 +623,19 @@ def test_scanpipe_pipes_docker_tag_whiteout_codebase_resources(self):
self.assertEqual("", resource1.status)
self.assertEqual("ignored-whiteout", resource2.status)

def test_scanpipe_pipes_rootfs_from_project_codebase_class_method(self):
p1 = Project.objects.create(name="Analysis")
root_filesystems = list(rootfs.RootFs.from_project_codebase(p1))
self.assertEqual([], root_filesystems)

input_location = str(self.data_location / "windows-container-rootfs.tar")
extract_tar(input_location, target_dir=p1.codebase_path)
root_filesystems = list(rootfs.RootFs.from_project_codebase(p1))
self.assertEqual(1, len(root_filesystems))
distro = root_filesystems[0].distro
self.assertEqual("windows", distro.os)
self.assertEqual("windows", distro.identifier)

def test_scanpipe_pipes_rootfs_tag_empty_codebase_resources(self):
p1 = Project.objects.create(name="Analysis")
resource1 = CodebaseResource.objects.create(project=p1, path="dir/")
Expand Down

0 comments on commit 486831a

Please sign in to comment.