move storage probing from model to controller

This commit is contained in:
Michael Hudson-Doyle 2019-04-29 14:16:40 +12:00
parent 89415fd810
commit 4be9b41a0f
4 changed files with 19 additions and 14 deletions

View File

@ -17,6 +17,8 @@ import logging
import os
import platform
from probert.storage import StorageInfo
from subiquitycore.controller import BaseController
from subiquity.models.filesystem import (
@ -48,7 +50,13 @@ class FilesystemController(BaseController):
self.answers.setdefault('guided', False)
self.answers.setdefault('guided-index', 0)
self.answers.setdefault('manual', [])
self.model.probe() # probe before we complete
def start(self):
probed_data = self.prober.get_storage()["blockdev"]
storage = {}
for path, data in probed_data.items():
storage[path] = StorageInfo({path: data})
self.model.load_probe_data(storage)
def default(self):
self.ui.set_body(GuidedFilesystemView(self))

View File

@ -867,8 +867,7 @@ class FilesystemModel(object):
fs_by_name[fs.label] = fs
fs_by_name['fat32'] = FS('fat32', True)
def __init__(self, prober):
self.prober = prober
def __init__(self):
self._disk_info = []
self.reset()
@ -975,25 +974,23 @@ class FilesystemModel(object):
mounted_disks.add('/dev/' + paths[0].split('/')[3])
return mounted_disks
def probe(self):
storage = self.prober.get_storage()["blockdev"]
def load_probe_data(self, storage):
currently_mounted = self._get_system_mounted_disks()
for path, data in storage.items():
for path, info in storage.items():
log.debug("fs probe %s", path)
if path in currently_mounted:
continue
if data['DEVTYPE'] == 'disk':
if data["DEVPATH"].startswith('/devices/virtual'):
if info.type == 'disk':
if info.is_virtual:
continue
if data["MAJOR"] in ("2", "11"): # serial and cd devices
if info.raw["MAJOR"] in ("2", "11"): # serial and cd devices
continue
if data['attrs'].get('ro') == "1":
if info.raw['attrs'].get('ro') == "1":
continue
if "ID_CDROM" in data:
if "ID_CDROM" in info.raw:
continue
# log.debug('disk={}\n{}'.format(
# path, json.dumps(data, indent=4, sort_keys=True)))
info = self.prober.get_storage_info(path)
if info.size < self.lower_size_limit:
continue
self._disk_info.append(info)

View File

@ -74,7 +74,7 @@ class SubiquityModel:
target=self.target,
sources=common['opts'].sources)
self.network = NetworkModel(support_wlan=False)
self.filesystem = FilesystemModel(common['prober'])
self.filesystem = FilesystemModel()
self.identity = IdentityModel()
self.proxy = ProxyModel()
self.mirror = MirrorModel()

View File

@ -21,7 +21,7 @@ FakeStorageInfo.__new__.__defaults__ = (None,) * len(FakeStorageInfo._fields)
def make_model_and_disk():
model = FilesystemModel(prober=None)
model = FilesystemModel()
model._disk_info.append(FakeStorageInfo(
name='disk-name', size=100*(2**30), free=50*(2**30)))
model.reset()