예제 #1
0
 def test_zfs_command_property_value(self):
     """
     Test if zfs_command builds the correct string
     """
     with patch.object(zfs, "_zfs_cmd",
                       MagicMock(return_value="/sbin/zfs")):
         with patch.object(zfs, "_zpool_cmd",
                           MagicMock(return_value="/sbin/zpool")):
             with patch.object(zfs, "property_data_zfs",
                               MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(
                         zfs,
                         "property_data_zpool",
                         MagicMock(return_value=self.pmap_zpool),
                 ):
                     my_flags = [
                         "-r",  # recursive
                     ]
                     self.assertEqual(
                         zfs.zfs_command(
                             "set",
                             flags=my_flags,
                             property_name="quota",
                             property_value="5G",
                             target="mypool",
                         ),
                         "/sbin/zfs set -r quota=5368709120 mypool",
                     )
예제 #2
0
 def test_zfs_command_target_with_space(self):
     """
     Test if zfs_command builds the correct string
     """
     with patch.object(zfs, "_zfs_cmd",
                       MagicMock(return_value="/sbin/zfs")):
         with patch.object(zfs, "_zpool_cmd",
                           MagicMock(return_value="/sbin/zpool")):
             with patch.object(zfs, "property_data_zfs",
                               MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(
                         zfs,
                         "property_data_zpool",
                         MagicMock(return_value=self.pmap_zpool),
                 ):
                     my_flags = [
                         "-r",  # recursive
                     ]
                     my_opts = {
                         "-t": "snap",  # only list snapshots
                     }
                     self.assertEqual(
                         zfs.zfs_command("list",
                                         flags=my_flags,
                                         opts=my_opts,
                                         target="my pool"),
                         '/sbin/zfs list -r -t snap "my pool"',
                     )
예제 #3
0
 def test_zfs_command_multi_property_value(self):
     """
     Test if zfs_command builds the correct string
     """
     with patch.object(zfs, "_zfs_cmd",
                       MagicMock(return_value="/sbin/zfs")):
         with patch.object(zfs, "_zpool_cmd",
                           MagicMock(return_value="/sbin/zpool")):
             with patch.object(zfs, "property_data_zfs",
                               MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(
                         zfs,
                         "property_data_zpool",
                         MagicMock(return_value=self.pmap_zpool),
                 ):
                     property_name = ["quota", "readonly"]
                     property_value = ["5G", "no"]
                     self.assertEqual(
                         zfs.zfs_command(
                             "set",
                             property_name=property_name,
                             property_value=property_value,
                             target="mypool",
                         ),
                         "/sbin/zfs set quota=5368709120 readonly=off mypool",
                     )
예제 #4
0
 def test_zfs_command_fs_props(self):
     """
     Test if zfs_command builds the correct string
     """
     with patch.object(zfs, "_zfs_cmd",
                       MagicMock(return_value="/sbin/zfs")):
         with patch.object(zfs, "_zpool_cmd",
                           MagicMock(return_value="/sbin/zpool")):
             with patch.object(zfs, "property_data_zfs",
                               MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(
                         zfs,
                         "property_data_zpool",
                         MagicMock(return_value=self.pmap_zpool),
                 ):
                     my_flags = [
                         "-p",  # create parent
                     ]
                     my_props = {
                         "quota": "1G",
                         "compression": "lz4",
                     }
                     self.assertEqual(
                         zfs.zfs_command(
                             "create",
                             flags=my_flags,
                             filesystem_properties=my_props,
                             target="mypool/dataset",
                         ),
                         "/sbin/zfs create -p -o compression=lz4 -o quota=1073741824"
                         " mypool/dataset",
                     )
예제 #5
0
 def test_zfs_command_fs_props(self):
     '''
     Test if zfs_command builds the correct string
     '''
     with patch.object(zfs, '_zfs_cmd',
                       MagicMock(return_value='/sbin/zfs')):
         with patch.object(zfs, '_zpool_cmd',
                           MagicMock(return_value='/sbin/zpool')):
             with patch.object(zfs, 'property_data_zfs',
                               MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(zfs, 'property_data_zpool',
                                   MagicMock(return_value=self.pmap_zpool)):
                     my_flags = [
                         '-p',  # create parent
                     ]
                     my_props = {
                         'quota': '1G',
                         'compression': 'lz4',
                     }
                     self.assertEqual(
                         zfs.zfs_command('create',
                                         flags=my_flags,
                                         filesystem_properties=my_props,
                                         target='mypool/dataset'),
                         "/sbin/zfs create -p -o compression=lz4 -o quota=1073741824 mypool/dataset"
                     )
예제 #6
0
 def test_zfs_command_fs_props_with_space(self):
     """
     Test if zfs_command builds the correct string
     """
     with patch.object(zfs, "_zfs_cmd",
                       MagicMock(return_value="/sbin/zfs")):
         with patch.object(zfs, "_zpool_cmd",
                           MagicMock(return_value="/sbin/zpool")):
             with patch.object(zfs, "property_data_zfs",
                               MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(
                         zfs,
                         "property_data_zpool",
                         MagicMock(return_value=self.pmap_zpool),
                 ):
                     my_props = {
                         "quota": "4.2M",
                         "compression": "lz4",
                     }
                     self.assertEqual(
                         zfs.zfs_command(
                             "create",
                             filesystem_properties=my_props,
                             target="my pool/jorge's dataset",
                         ),
                         '/sbin/zfs create -o compression=lz4 -o quota=4404019 "my'
                         " pool/jorge's dataset\"",
                     )
예제 #7
0
파일: test_zfs.py 프로젝트: yutiansut/salt
 def test_zfs_command_property(self):
     '''
     Test if zfs_command builds the correct string
     '''
     with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
         with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
             with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=self.pmap_zpool)):
                     self.assertEqual(
                         zfs.zfs_command('get', property_name='quota', target='mypool'),
                         "/sbin/zfs get quota mypool"
                     )
예제 #8
0
파일: test_zfs.py 프로젝트: yutiansut/salt
 def test_zfs_command_simple(self):
     '''
     Test if zfs_command builds the correct string
     '''
     with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
         with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
             with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=self.pmap_zpool)):
                     self.assertEqual(
                         zfs.zfs_command('list'),
                         "/sbin/zfs list"
                     )
예제 #9
0
파일: test_zfs.py 프로젝트: yutiansut/salt
 def test_zfs_command_none_target(self):
     '''
     Test if zfs_command builds the correct string with a target of None
     '''
     with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
         with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
             with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=self.pmap_zpool)):
                     self.assertEqual(
                         zfs.zfs_command('list', target=[None, 'mypool', None]),
                         "/sbin/zfs list mypool"
                     )
예제 #10
0
파일: test_zfs.py 프로젝트: yutiansut/salt
 def test_zfs_command_multi_property_value(self):
     '''
     Test if zfs_command builds the correct string
     '''
     with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
         with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
             with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=self.pmap_zpool)):
                     property_name = ['quota', 'readonly']
                     property_value = ['5G', 'no']
                     self.assertEqual(
                         zfs.zfs_command('set', property_name=property_name, property_value=property_value, target='mypool'),
                         "/sbin/zfs set quota=5368709120 readonly=off mypool"
                     )
예제 #11
0
파일: test_zfs.py 프로젝트: yutiansut/salt
 def test_zfs_command_flag(self):
     '''
     Test if zfs_command builds the correct string
     '''
     with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
         with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
             with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=self.pmap_zpool)):
                     my_flags = [
                         '-r',  # recursive
                     ]
                     self.assertEqual(
                         zfs.zfs_command('list', flags=my_flags),
                         "/sbin/zfs list -r"
                     )
예제 #12
0
파일: test_zfs.py 프로젝트: yutiansut/salt
 def test_zfs_command_opt(self):
     '''
     Test if zfs_command builds the correct string
     '''
     with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
         with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
             with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=self.pmap_zpool)):
                     my_opts = {
                         '-t': 'snap',  # only list snapshots
                     }
                     self.assertEqual(
                         zfs.zfs_command('list', opts=my_opts),
                         "/sbin/zfs list -t snap"
                     )
예제 #13
0
파일: test_zfs.py 프로젝트: yutiansut/salt
 def test_zfs_command_property_value(self):
     '''
     Test if zfs_command builds the correct string
     '''
     with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
         with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
             with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=self.pmap_zpool)):
                     my_flags = [
                         '-r',  # recursive
                     ]
                     self.assertEqual(
                         zfs.zfs_command('set', flags=my_flags, property_name='quota', property_value='5G', target='mypool'),
                         "/sbin/zfs set -r quota=5368709120 mypool"
                     )
예제 #14
0
파일: test_zfs.py 프로젝트: yutiansut/salt
 def test_zfs_command_fs_props_with_space(self):
     '''
     Test if zfs_command builds the correct string
     '''
     with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
         with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
             with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=self.pmap_zpool)):
                     my_props = {
                         'quota': '4.2M',
                         'compression': 'lz4',
                     }
                     self.assertEqual(
                         zfs.zfs_command('create', filesystem_properties=my_props, target="my pool/jorge's dataset"),
                         '/sbin/zfs create -o compression=lz4 -o quota=4404019 "my pool/jorge\'s dataset"'
                     )
예제 #15
0
 def test_zfs_command_simple(self):
     """
     Test if zfs_command builds the correct string
     """
     with patch.object(zfs, "_zfs_cmd",
                       MagicMock(return_value="/sbin/zfs")):
         with patch.object(zfs, "_zpool_cmd",
                           MagicMock(return_value="/sbin/zpool")):
             with patch.object(zfs, "property_data_zfs",
                               MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(
                         zfs,
                         "property_data_zpool",
                         MagicMock(return_value=self.pmap_zpool),
                 ):
                     self.assertEqual(zfs.zfs_command("list"),
                                      "/sbin/zfs list")
예제 #16
0
파일: test_zfs.py 프로젝트: yutiansut/salt
 def test_zfs_command_target_with_space(self):
     '''
     Test if zfs_command builds the correct string
     '''
     with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
         with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
             with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=self.pmap_zpool)):
                     my_flags = [
                         '-r',  # recursive
                     ]
                     my_opts = {
                         '-t': 'snap',  # only list snapshots
                     }
                     self.assertEqual(
                         zfs.zfs_command('list', flags=my_flags, opts=my_opts, target='my pool'),
                         '/sbin/zfs list -r -t snap "my pool"'
                     )
예제 #17
0
 def test_zfs_command_none_target(self):
     """
     Test if zfs_command builds the correct string with a target of None
     """
     with patch.object(zfs, "_zfs_cmd",
                       MagicMock(return_value="/sbin/zfs")):
         with patch.object(zfs, "_zpool_cmd",
                           MagicMock(return_value="/sbin/zpool")):
             with patch.object(zfs, "property_data_zfs",
                               MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(
                         zfs,
                         "property_data_zpool",
                         MagicMock(return_value=self.pmap_zpool),
                 ):
                     self.assertEqual(
                         zfs.zfs_command("list",
                                         target=[None, "mypool", None]),
                         "/sbin/zfs list mypool",
                     )
예제 #18
0
 def test_zfs_command_property(self):
     """
     Test if zfs_command builds the correct string
     """
     with patch.object(zfs, "_zfs_cmd",
                       MagicMock(return_value="/sbin/zfs")):
         with patch.object(zfs, "_zpool_cmd",
                           MagicMock(return_value="/sbin/zpool")):
             with patch.object(zfs, "property_data_zfs",
                               MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(
                         zfs,
                         "property_data_zpool",
                         MagicMock(return_value=self.pmap_zpool),
                 ):
                     self.assertEqual(
                         zfs.zfs_command("get",
                                         property_name="quota",
                                         target="mypool"),
                         "/sbin/zfs get quota mypool",
                     )
예제 #19
0
 def test_zfs_command_flag(self):
     """
     Test if zfs_command builds the correct string
     """
     with patch.object(zfs, "_zfs_cmd",
                       MagicMock(return_value="/sbin/zfs")):
         with patch.object(zfs, "_zpool_cmd",
                           MagicMock(return_value="/sbin/zpool")):
             with patch.object(zfs, "property_data_zfs",
                               MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(
                         zfs,
                         "property_data_zpool",
                         MagicMock(return_value=self.pmap_zpool),
                 ):
                     my_flags = [
                         "-r",  # recursive
                     ]
                     self.assertEqual(
                         zfs.zfs_command("list", flags=my_flags),
                         "/sbin/zfs list -r")
예제 #20
0
 def test_zfs_command_opt(self):
     """
     Test if zfs_command builds the correct string
     """
     with patch.object(zfs, "_zfs_cmd",
                       MagicMock(return_value="/sbin/zfs")):
         with patch.object(zfs, "_zpool_cmd",
                           MagicMock(return_value="/sbin/zpool")):
             with patch.object(zfs, "property_data_zfs",
                               MagicMock(return_value=self.pmap_zfs)):
                 with patch.object(
                         zfs,
                         "property_data_zpool",
                         MagicMock(return_value=self.pmap_zpool),
                 ):
                     my_opts = {
                         "-t": "snap",  # only list snapshots
                     }
                     self.assertEqual(
                         zfs.zfs_command("list", opts=my_opts),
                         "/sbin/zfs list -t snap",
                     )