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", )
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"', )
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", )
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", )
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" )
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\"", )
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" )
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" )
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" )
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" )
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" )
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" )
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" )
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"' )
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")
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"' )
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", )
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", )
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")
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", )