Пример #1
0
    def test_zpool_create_pool_iterable(self):
        """ zpool_create accepts vdev iterables besides list """
        zpool_props = {'version': 250, 'ashift': 9}
        zfs.zpool_create('mypool', ('/dev/virtio-disk1', '/dev/virtio-disk2'),
                         pool_properties=zpool_props)
        merge_config(zfs.ZPOOL_DEFAULT_PROPERTIES.copy(), zpool_props)
        params = ["%s=%s" % (k, v) for k, v in zpool_props.items()]
        args, _ = self.mock_subp.call_args
        self.assertTrue(set(params).issubset(set(args[0])))

        args, _ = self.mock_subp.call_args
        self.assertIn("/dev/virtio-disk1", args[0])
        self.assertIn("/dev/virtio-disk2", args[0])
Пример #2
0
 def test_zpool_create_use_passed_properties(self):
     """ zpool_create uses provided properties """
     zpool_props = {'prop1': 'val1'}
     zfs_props = {'fsprop1': 'val2'}
     zfs.zpool_create('mypool', ['/dev/disk/by-id/virtio-abcfoo1'],
                      pool_properties=zpool_props, zfs_properties=zfs_props)
     all_props = {}
     merge_config(all_props, zfs.ZPOOL_DEFAULT_PROPERTIES.copy())
     merge_config(all_props, zfs.ZFS_DEFAULT_PROPERTIES.copy())
     merge_config(all_props, zpool_props.copy())
     params = ["%s=%s" % (k, v) for k, v in all_props.items()]
     args, _ = self.mock_subp.call_args
     self.assertTrue(set(params).issubset(set(args[0])))
Пример #3
0
    def test_zpool_create_raises_value_errors(self):
        """ zfs.zpool_create raises ValueError/TypeError for invalid inputs """

        # poolname
        for val in [None, '', {'a': 1}]:
            with self.assertRaises(ValueError):
                zfs.zpool_create(val, [])

        # vdevs
        for val in [None, '', {'a': 1}, 'mydev']:
            with self.assertRaises(TypeError):
                # All the assert methods (except assertRaises(),
                # assertRaisesRegexp()) accept a msg argument that,
                # if specified, is used as the error message on failure
                print('vdev value: %s' % val)
                zfs.zpool_create('mypool', val)
Пример #4
0
 def test_zpool_create_zfsroot(self):
     """ zpool_create sets up root command correctly """
     pool = 'rpool'
     mountpoint = '/'
     altroot = '/var/tmp/mytarget'
     vdev = '/dev/disk/by-id/virtio-abcfoo1'
     zfs.zpool_create('rpool', [vdev], mountpoint=mountpoint,
                      altroot=altroot)
     # the dictionary ordering is not guaranteed which means the
     # pairs of parameters may shift; this does not harm the function
     # of the call, but is harder to test; instead we will compare
     # the arg list sorted
     args, kwargs = self.mock_subp.call_args
     print(args[0])
     print(kwargs)
     expected_args = (
         ['zpool', 'create', '-o', 'ashift=12', '-o', 'version=28',
          '-O', 'normalization=formD', '-O', 'canmount=off',
          '-O', 'atime=off', '-O', 'mountpoint=%s' % mountpoint,
          '-R', altroot, pool, vdev])
     expected_kwargs = {'capture': True}
     self.assertEqual(sorted(expected_args), sorted(args[0]))
     self.assertEqual(expected_kwargs, kwargs)