Skip to content

Commit

Permalink
include deb822 sources when collecting source channels (LP: #2062561) (
Browse files Browse the repository at this point in the history
…#239)

* include deb822 sources when collecting source channels (LP: #2062561)

* skip test when dep does not support it
  • Loading branch information
Perfect5th committed Apr 22, 2024
1 parent fe29486 commit a9a22e5
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
18 changes: 16 additions & 2 deletions landscape/lib/apt/package/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,16 @@ def ensure_channels_reloaded(self):
return
self.reload_channels()

@property
def _sourceparts_directory(self):
return apt_pkg.config.find_dir("Dir::Etc::sourceparts")

def _get_internal_sources_list(self):
"""Return the path to the source.list file for the facade channels."""
sources_dir = apt_pkg.config.find_dir("Dir::Etc::sourceparts")
return os.path.join(sources_dir, "_landscape-internal-facade.list")
return os.path.join(
self._sourceparts_directory,
"_landscape-internal-facade.list",
)

def add_channel_apt_deb(
self,
Expand Down Expand Up @@ -358,6 +364,10 @@ def get_channels(self):
and type keys.
"""
sources_list = SourcesList()
if hasattr(sources_list, "deb822"):
sources_list.deb822 = True
sources_list.refresh()

return [
{
"baseurl": entry.uri,
Expand All @@ -372,6 +382,10 @@ def get_channels(self):
def reset_channels(self):
"""Remove all the configured channels."""
sources_list = SourcesList()
if hasattr(sources_list, "deb822"):
sources_list.deb822 = True
sources_list.refresh()

for entry in sources_list:
entry.set_enabled(False)
sources_list.save()
Expand Down
1 change: 1 addition & 0 deletions landscape/lib/apt/package/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class AptFacadeHelper:

def set_up(self, test_case):
test_case.apt_root = test_case.makeDir()
os.makedirs(os.path.join(test_case.apt_root, "etc/apt/preferences.d"))
self.dpkg_status = os.path.join(
test_case.apt_root,
"var",
Expand Down
39 changes: 39 additions & 0 deletions landscape/lib/apt/package/tests/test_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import weakref
from collections import namedtuple
from unittest import mock
from unittest import skipIf

import apt
import apt_pkg
Expand Down Expand Up @@ -595,6 +596,44 @@ def test_get_channels_with_disabled_channels(self):
self.facade.get_channels(),
)

@skipIf(not hasattr(SourcesList(), "deb822"), "aptsources version too old")
def test_get_channels_deb822(self):
"""`get_channels` includes *.source files with deb822 format."""
sourceparts_dir = self.facade._sourceparts_directory
sources_file_path = os.path.join(
sourceparts_dir,
"test_deb822.sources",
)

with open(sources_file_path, "w") as sources_file:
sources_file.write(
textwrap.dedent(
"""\
Types: deb
URIs: http://test.archive.ubuntu.com/ubuntu/
Suites: unicorn-test
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
""",
),
)

channels = self.facade.get_channels()

self.assertEqual(
[
{
"baseurl": "http://test.archive.ubuntu.com/ubuntu/",
"components": "main restricted universe multiverse",
"distribution": "unicorn-test",
"type": "deb",
},
],
channels,
)

os.remove(sources_file_path)

def test_reset_channels(self):
"""
C{reset_channels()} disables all the configured deb URLs.
Expand Down

0 comments on commit a9a22e5

Please sign in to comment.