less hardcoding of /target
This commit is contained in:
parent
ad17c530b0
commit
56c637fed7
|
@ -31,8 +31,6 @@ from subiquity.ui.views.installprogress import ProgressView
|
|||
|
||||
log = logging.getLogger("subiquitycore.controller.installprogress")
|
||||
|
||||
TARGET = '/target'
|
||||
|
||||
|
||||
class InstallState:
|
||||
NOT_STARTED = 0
|
||||
|
@ -161,8 +159,7 @@ class InstallProgressController(BaseController):
|
|||
|
||||
ident = self._event_syslog_identifier
|
||||
self._write_config(config_location,
|
||||
self.base_model.render(target=TARGET,
|
||||
syslog_identifier=ident))
|
||||
self.base_model.render(syslog_identifier=ident))
|
||||
|
||||
return curtin_cmd
|
||||
|
||||
|
@ -228,20 +225,16 @@ class InstallProgressController(BaseController):
|
|||
self.reboot()
|
||||
|
||||
def configure_cloud_init(self):
|
||||
if self.opts.dry_run:
|
||||
target = '.subiquity'
|
||||
else:
|
||||
target = TARGET
|
||||
self.base_model.configure_cloud_init(target)
|
||||
self.base_model.configure_cloud_init()
|
||||
|
||||
def copy_logs_to_target(self):
|
||||
if self.opts.dry_run:
|
||||
return
|
||||
utils.run_command(['cp', '-aT', '/var/log/installer',
|
||||
'/target/var/log/installer'])
|
||||
target_logs = os.path.join(self.base_model.target, 'var/log/installer')
|
||||
utils.run_command(['cp', '-aT', '/var/log/installer', target_logs])
|
||||
try:
|
||||
with open('/target/var/log/installer/installer-journal.txt',
|
||||
'w') as output:
|
||||
with open(os.path.join(target_logs,
|
||||
'installer-journal.txt'), 'w') as output:
|
||||
utils.run_command(
|
||||
['journalctl'],
|
||||
stdout=output, stderr=subprocess.STDOUT)
|
||||
|
|
|
@ -42,20 +42,11 @@ def setup_yaml():
|
|||
setup_yaml()
|
||||
|
||||
|
||||
def get_all_groups(dry_run):
|
||||
command = ['chroot', '/target', 'getent', 'group']
|
||||
if dry_run:
|
||||
del command[:2]
|
||||
cp = run_command(command, check=True)
|
||||
groups = set()
|
||||
for line in cp.stdout.splitlines():
|
||||
groups.add(line.split(':')[0])
|
||||
return groups
|
||||
|
||||
|
||||
class SubiquityModel:
|
||||
"""The overall model for subiquity."""
|
||||
|
||||
target = '/target'
|
||||
|
||||
def __init__(self, common):
|
||||
root = '/'
|
||||
self.opts = common['opts']
|
||||
|
@ -71,6 +62,16 @@ class SubiquityModel:
|
|||
self.mirror = MirrorModel()
|
||||
self.snaplist = SnapListModel()
|
||||
|
||||
def get_target_groups(self):
|
||||
command = ['chroot', self.target, 'getent', 'group']
|
||||
if self.opts.dry_run:
|
||||
del command[:2]
|
||||
cp = run_command(command, check=True)
|
||||
groups = set()
|
||||
for line in cp.stdout.splitlines():
|
||||
groups.add(line.split(':')[0])
|
||||
return groups
|
||||
|
||||
def _cloud_init_config(self):
|
||||
user = self.identity.user
|
||||
users_and_groups_path = (
|
||||
|
@ -81,8 +82,8 @@ class SubiquityModel:
|
|||
else:
|
||||
groups = ['admin']
|
||||
groups.append('sudo')
|
||||
all_groups = get_all_groups(self.opts.dry_run)
|
||||
groups = [group for group in groups if group in all_groups]
|
||||
groups = [group for group in groups
|
||||
if group in self.get_target_groups()]
|
||||
user_info = {
|
||||
'name': user.username,
|
||||
'gecos': user.realname,
|
||||
|
@ -129,14 +130,14 @@ class SubiquityModel:
|
|||
('etc/cloud/ds-identify.cfg', 'policy: enabled\n'),
|
||||
]
|
||||
|
||||
def configure_cloud_init(self, target):
|
||||
def configure_cloud_init(self):
|
||||
for path, content in self._cloud_init_files():
|
||||
path = os.path.join(target, path)
|
||||
path = os.path.join(self.target, path)
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
with open(path, 'w') as fp:
|
||||
fp.write(content)
|
||||
|
||||
def render(self, target, syslog_identifier):
|
||||
def render(self, syslog_identifier):
|
||||
config = {
|
||||
'apt': {
|
||||
'http_proxy': self.proxy.proxy,
|
||||
|
@ -147,7 +148,7 @@ class SubiquityModel:
|
|||
},
|
||||
|
||||
'install': {
|
||||
'target': target,
|
||||
'target': self.target,
|
||||
'unmount': 'disabled',
|
||||
'save_install_config':
|
||||
'/var/log/installer/curtin-install-cfg.yaml',
|
||||
|
|
Loading…
Reference in New Issue