~curtin-dev/curtin/bionic

« back to all changes in this revision

Viewing changes to curtin/block/__init__.py

  • Committer: Scott Moser
  • Date: 2017-08-03 19:51:16 UTC
  • mfrom: (1.1.50)
  • Revision ID: smoser@ubuntu.com-20170803195116-0xc6onji18peerm5
* New upstream snapshot.
  - tests: Add CiTestCase common parent for all curtin tests.
  - vmtests: Remove force flag for centos curthooks
  - tools/jenkins-runner: improve tgtd cleanup logic
  - tests: Drop EOL Wily Vivid and Yakkety tests.
  - Disable yum plugins when installing packages, update ca-certs for https
  - Rename centos_network_curthooks -> centos_apply_network_config.
  - tests: in centos_defaults use write_files for grub serial.
  - write_files: write files after extract, change write_files signature.
  - pass network configuration through to target for ubuntu and centos
  - tests: disable yakkety tests.
  - tools/launch: automatically pass on proxy settings to curtin
  - Add top level 'proxy' to config, deprecate top level http_proxy.
  - tools/curtainer: fix to enable deb-src for -proposed.
  - Use unshare to put chroot commands in own pid namespace.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import errno
20
20
import itertools
21
21
import os
22
 
import shlex
23
22
import stat
24
23
import sys
25
24
import tempfile
204
203
        return [path_to_kname(device)]
205
204
 
206
205
 
207
 
def _shlex_split(str_in):
208
 
    # shlex.split takes a string
209
 
    # but in python2 if input here is a unicode, encode it to a string.
210
 
    # http://stackoverflow.com/questions/2365411/
211
 
    #     python-convert-unicode-to-ascii-without-errors
212
 
    if sys.version_info.major == 2:
213
 
        try:
214
 
            if isinstance(str_in, unicode):
215
 
                str_in = str_in.encode('utf-8')
216
 
        except NameError:
217
 
            pass
218
 
 
219
 
        return shlex.split(str_in)
220
 
    else:
221
 
        return shlex.split(str_in)
222
 
 
223
 
 
224
206
def _lsblock_pairs_to_dict(lines):
225
207
    """
226
208
    parse lsblock output and convert to dict
227
209
    """
228
210
    ret = {}
229
211
    for line in lines.splitlines():
230
 
        toks = _shlex_split(line)
 
212
        toks = util.shlex_split(line)
231
213
        cur = {}
232
214
        for tok in toks:
233
215
            k, v = tok.split("=", 1)
468
450
    for line in out.splitlines():
469
451
        curdev, curdata = line.split(":", 1)
470
452
        data[curdev] = dict(tok.split('=', 1)
471
 
                            for tok in _shlex_split(curdata))
 
453
                            for tok in util.shlex_split(curdata))
472
454
    return data
473
455
 
474
456
 
978
960
    else:
979
961
        raise ValueError("wipe mode %s not supported" % mode)
980
962
 
 
963
 
 
964
def storage_config_required_packages(storage_config, mapping):
 
965
    """Read storage configuration dictionary and determine
 
966
       which packages are required for the supplied configuration
 
967
       to function.  Return a list of packaged to install.
 
968
    """
 
969
 
 
970
    if not storage_config or not isinstance(storage_config, dict):
 
971
        raise ValueError('Invalid storage configuration.  '
 
972
                         'Must be a dict:\n %s' % storage_config)
 
973
 
 
974
    if not mapping or not isinstance(mapping, dict):
 
975
        raise ValueError('Invalid storage mapping.  Must be a dict')
 
976
 
 
977
    if 'storage' in storage_config:
 
978
        storage_config = storage_config.get('storage')
 
979
 
 
980
    needed_packages = []
 
981
 
 
982
    # get reqs by device operation type
 
983
    dev_configs = set(operation['type']
 
984
                      for operation in storage_config['config'])
 
985
 
 
986
    for dev_type in dev_configs:
 
987
        if dev_type in mapping:
 
988
            needed_packages.extend(mapping[dev_type])
 
989
 
 
990
    # for any format operations, check the fstype and
 
991
    # determine if we need any mkfs tools as well.
 
992
    format_configs = set([operation['fstype']
 
993
                         for operation in storage_config['config']
 
994
                         if operation['type'] == 'format'])
 
995
    for format_type in format_configs:
 
996
        if format_type in mapping:
 
997
            needed_packages.extend(mapping[format_type])
 
998
 
 
999
    return needed_packages
 
1000
 
 
1001
 
 
1002
def detect_required_packages_mapping():
 
1003
    """Return a dictionary providing a versioned configuration which maps
 
1004
       storage configuration elements to the packages which are required
 
1005
       for functionality.
 
1006
 
 
1007
       The mapping key is either a config type value, or an fstype value.
 
1008
 
 
1009
    """
 
1010
    version = 1
 
1011
    mapping = {
 
1012
        version: {
 
1013
            'handler': storage_config_required_packages,
 
1014
            'mapping': {
 
1015
                'bcache': ['bcache-tools'],
 
1016
                'btrfs': ['btrfs-tools'],
 
1017
                'ext2': ['e2fsprogs'],
 
1018
                'ext3': ['e2fsprogs'],
 
1019
                'ext4': ['e2fsprogs'],
 
1020
                'lvm_partition': ['lvm2'],
 
1021
                'lvm_volgroup': ['lvm2'],
 
1022
                'raid': ['mdadm'],
 
1023
                'xfs': ['xfsprogs']
 
1024
            },
 
1025
        },
 
1026
    }
 
1027
    return mapping
 
1028
 
 
1029
 
981
1030
# vi: ts=4 expandtab syntax=python