apt: get settings from mirror + proxy
This commit is contained in:
parent
55b2d4cf86
commit
0c28c13887
|
@ -53,7 +53,7 @@ class MirrorModel(object):
|
|||
self.default_mirror = self.get_mirror()
|
||||
self.disable_components = set()
|
||||
|
||||
def get_config(self):
|
||||
def get_apt_config(self):
|
||||
config = copy.deepcopy(self.config)
|
||||
config['disable_components'] = list(self.disable_components)
|
||||
return config
|
||||
|
|
|
@ -32,13 +32,18 @@ class ProxyModel(object):
|
|||
def proxy_systemd_dropin(self):
|
||||
return dropin_template.format(proxy=self.proxy)
|
||||
|
||||
def get_apt_config(self):
|
||||
if self.proxy:
|
||||
return {
|
||||
'http_proxy': self.proxy,
|
||||
'https_proxy': self.proxy,
|
||||
}
|
||||
else:
|
||||
return {}
|
||||
|
||||
def render(self):
|
||||
if self.proxy:
|
||||
return {
|
||||
'apt': {
|
||||
'http_proxy': self.proxy,
|
||||
'https_proxy': self.proxy,
|
||||
},
|
||||
'proxy': {
|
||||
'http_proxy': self.proxy,
|
||||
'https_proxy': self.proxy,
|
||||
|
|
|
@ -44,11 +44,11 @@ class TestMirrorModel(unittest.TestCase):
|
|||
self.assertEqual(model.get_mirror(), "http://mymirror.invalid/")
|
||||
|
||||
def test_default_disable_components(self):
|
||||
config = MirrorModel().get_config()
|
||||
config = MirrorModel().get_apt_config()
|
||||
self.assertEqual([], config['disable_components'])
|
||||
|
||||
def test_set_disable_components(self):
|
||||
model = MirrorModel()
|
||||
model.disable_components = set(['universe'])
|
||||
config = model.get_config()
|
||||
config = model.get_apt_config()
|
||||
self.assertEqual(['universe'], config['disable_components'])
|
||||
|
|
|
@ -119,8 +119,6 @@ class TestSubiquityModel(unittest.TestCase):
|
|||
config = model.render()
|
||||
self.assertConfigHasVal(config, 'proxy.http_proxy', proxy_val)
|
||||
self.assertConfigHasVal(config, 'proxy.https_proxy', proxy_val)
|
||||
self.assertConfigHasVal(config, 'apt.http_proxy', proxy_val)
|
||||
self.assertConfigHasVal(config, 'apt.https_proxy', proxy_val)
|
||||
confs = self.writtenFilesMatchingContaining(
|
||||
config,
|
||||
'etc/systemd/system/snapd.service.d/*.conf',
|
||||
|
|
|
@ -18,6 +18,7 @@ import os
|
|||
import shutil
|
||||
import tempfile
|
||||
|
||||
from curtin.config import merge_config
|
||||
from curtin.util import write_file
|
||||
|
||||
import yaml
|
||||
|
@ -66,6 +67,12 @@ class AptConfigurer:
|
|||
options=f'lowerdir={source},upperdir={u},workdir={w}')
|
||||
return u
|
||||
|
||||
def apt_config(self):
|
||||
cfg = {}
|
||||
merge_config(cfg, self.app.base_model.mirror.get_apt_config())
|
||||
merge_config(cfg, self.app.base_model.proxy.get_apt_config())
|
||||
return {'apt': cfg}
|
||||
|
||||
async def configure(self, context):
|
||||
# Configure apt so that installs from the pool on the cdrom are
|
||||
# preferred during installation but not in the installed system.
|
||||
|
@ -103,15 +110,12 @@ class AptConfigurer:
|
|||
|
||||
config_upper = await self.setup_overlay(self.source, self.configured)
|
||||
|
||||
config = {
|
||||
'apt': self.app.base_model.mirror.get_config(),
|
||||
}
|
||||
config_location = os.path.join(
|
||||
self.app.root, 'var/log/installer/subiquity-curtin-apt.conf')
|
||||
|
||||
datestr = '# Autogenerated by Subiquity: {} UTC\n'.format(
|
||||
str(datetime.datetime.utcnow()))
|
||||
write_file(config_location, datestr + yaml.dump(config))
|
||||
write_file(config_location, datestr + yaml.dump(self.apt_config()))
|
||||
|
||||
self.app.note_data_for_apport("CurtinAptConfig", config_location)
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
# Copyright 2021 Canonical, Ltd.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from unittest.mock import Mock
|
||||
|
||||
from subiquitycore.tests import SubiTestCase
|
||||
from subiquitycore.tests.mocks import make_app
|
||||
from subiquity.server.apt import AptConfigurer
|
||||
from subiquity.models.mirror import MirrorModel, DEFAULT
|
||||
from subiquity.models.proxy import ProxyModel
|
||||
|
||||
|
||||
class TestAptConfigurer(SubiTestCase):
|
||||
def setUp(self):
|
||||
self.base_config = {'apt': DEFAULT}
|
||||
self.base_config['apt']['disable_components'] = []
|
||||
|
||||
self.model = Mock()
|
||||
self.model.mirror = MirrorModel()
|
||||
self.model.proxy = ProxyModel()
|
||||
self.app = make_app(self.model)
|
||||
self.configurer = AptConfigurer(self.app, '')
|
||||
|
||||
def test_apt_config_noproxy(self):
|
||||
expected = self.base_config
|
||||
self.assertEqual(expected, self.configurer.apt_config())
|
||||
|
||||
def test_apt_config_proxy(self):
|
||||
proxy = 'http://apt-cacher-ng:3142'
|
||||
self.model.proxy.proxy = proxy
|
||||
expected = self.base_config
|
||||
expected['apt']['http_proxy'] = proxy
|
||||
expected['apt']['https_proxy'] = proxy
|
||||
self.assertEqual(expected, self.configurer.apt_config())
|
Loading…
Reference in New Issue