def test_create_swap_space( self, mock_check_existing_swap_file, # pylint: disable=unused-argument mock_isfile, # pylint: disable=unused-argument mock_mkfile, # pylint: disable=unused-argument mock_run, mock_run_get_output): mount_point = '/mnt/resource' size_mb = 128 rdh = ResourceDiskHandler() def rgo_side_effect(*args, **kwargs): # pylint: disable=unused-argument if args[0] == 'swapon -s': return ( 0, 'Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n/mnt/resource/swapfile \tfile \t131068\t0\t-2\n' ) return DEFAULT def run_side_effect(*args, **kwargs): # pylint: disable=unused-argument # We have to change the default mock behavior to return a falsey value # (instead of the default truthy of the mock), because we are testing # really for the exit code of the the swapon command to return 0. if 'swapon' in args[0]: return 0 return None mock_run_get_output.side_effect = rgo_side_effect mock_run.side_effect = run_side_effect rdh.create_swap_space(mount_point=mount_point, size_mb=size_mb)
def test_mount_flags_many(self): partition = '/dev/sdb1' mountpoint = '/mnt/resource' options = 'noexec,noguid,nodev' expected = 'mount -t ext3 -o noexec,noguid,nodev /dev/sdb1 /mnt/resource' rdh = ResourceDiskHandler() mount_string = rdh.get_mount_string(options, partition, mountpoint) self.assertEqual(expected, mount_string)
def test_mount_flags_empty(self): partition = '/dev/sdb1' mountpoint = '/mnt/resource' options = None expected = 'mount -t ext3 /dev/sdb1 /mnt/resource' rdh = ResourceDiskHandler() mount_string = rdh.get_mount_string(options, partition, mountpoint) self.assertEqual(expected, mount_string)