less hardcoding of /target

This commit is contained in:
Michael Hudson-Doyle 2018-06-15 08:35:20 +12:00
parent ad17c530b0
commit 56c637fed7
2 changed files with 24 additions and 30 deletions

View File

@ -31,8 +31,6 @@ from subiquity.ui.views.installprogress import ProgressView
log = logging.getLogger("subiquitycore.controller.installprogress") log = logging.getLogger("subiquitycore.controller.installprogress")
TARGET = '/target'
class InstallState: class InstallState:
NOT_STARTED = 0 NOT_STARTED = 0
@ -161,8 +159,7 @@ class InstallProgressController(BaseController):
ident = self._event_syslog_identifier ident = self._event_syslog_identifier
self._write_config(config_location, self._write_config(config_location,
self.base_model.render(target=TARGET, self.base_model.render(syslog_identifier=ident))
syslog_identifier=ident))
return curtin_cmd return curtin_cmd
@ -228,20 +225,16 @@ class InstallProgressController(BaseController):
self.reboot() self.reboot()
def configure_cloud_init(self): def configure_cloud_init(self):
if self.opts.dry_run: self.base_model.configure_cloud_init()
target = '.subiquity'
else:
target = TARGET
self.base_model.configure_cloud_init(target)
def copy_logs_to_target(self): def copy_logs_to_target(self):
if self.opts.dry_run: if self.opts.dry_run:
return return
utils.run_command(['cp', '-aT', '/var/log/installer', target_logs = os.path.join(self.base_model.target, 'var/log/installer')
'/target/var/log/installer']) utils.run_command(['cp', '-aT', '/var/log/installer', target_logs])
try: try:
with open('/target/var/log/installer/installer-journal.txt', with open(os.path.join(target_logs,
'w') as output: 'installer-journal.txt'), 'w') as output:
utils.run_command( utils.run_command(
['journalctl'], ['journalctl'],
stdout=output, stderr=subprocess.STDOUT) stdout=output, stderr=subprocess.STDOUT)

View File

@ -42,20 +42,11 @@ def setup_yaml():
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: class SubiquityModel:
"""The overall model for subiquity.""" """The overall model for subiquity."""
target = '/target'
def __init__(self, common): def __init__(self, common):
root = '/' root = '/'
self.opts = common['opts'] self.opts = common['opts']
@ -71,6 +62,16 @@ class SubiquityModel:
self.mirror = MirrorModel() self.mirror = MirrorModel()
self.snaplist = SnapListModel() 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): def _cloud_init_config(self):
user = self.identity.user user = self.identity.user
users_and_groups_path = ( users_and_groups_path = (
@ -81,8 +82,8 @@ class SubiquityModel:
else: else:
groups = ['admin'] groups = ['admin']
groups.append('sudo') groups.append('sudo')
all_groups = get_all_groups(self.opts.dry_run) groups = [group for group in groups
groups = [group for group in groups if group in all_groups] if group in self.get_target_groups()]
user_info = { user_info = {
'name': user.username, 'name': user.username,
'gecos': user.realname, 'gecos': user.realname,
@ -129,14 +130,14 @@ class SubiquityModel:
('etc/cloud/ds-identify.cfg', 'policy: enabled\n'), ('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(): 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) os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, 'w') as fp: with open(path, 'w') as fp:
fp.write(content) fp.write(content)
def render(self, target, syslog_identifier): def render(self, syslog_identifier):
config = { config = {
'apt': { 'apt': {
'http_proxy': self.proxy.proxy, 'http_proxy': self.proxy.proxy,
@ -147,7 +148,7 @@ class SubiquityModel:
}, },
'install': { 'install': {
'target': target, 'target': self.target,
'unmount': 'disabled', 'unmount': 'disabled',
'save_install_config': 'save_install_config':
'/var/log/installer/curtin-install-cfg.yaml', '/var/log/installer/curtin-install-cfg.yaml',