示例#1
0
    def setUp(self):
        """
        Initializer
        """
        self.setMessageLevel("normal")

        self.subdirs = ["two", "three" "one/four"]

        """
        Set up a ramdisk and use that random location as a root to test the
        filesystem functionality of what is being tested.
        """
        #Calculate size of ramdisk to make for this unit test.
        size_in_mb = 100
        self.mnt_pnt_requested = ""

        self.success = False
        self.mountPoint = False
        self.ramdiskDev = False
        self.mnt_pnt_requested = False

        # get a ramdisk of appropriate size, with a secure random mountpoint
        my_ramdisk = RamDisk(str(size_in_mb), self.mnt_pnt_requested, self.message_level)
        (self.success, self.mountPoint, self.ramdiskDev) = my_ramdisk.get_data()

        log_message("::::::::Ramdisk Mount Point: " + str(self.mountPoint), "debug", self.message_level)
        log_message("::::::::Ramdisk Device     : " + str(self.ramdiskDev), "debug", self.message_level)

        
        if not self.success:
            raise IOError
示例#2
0
    def setupRamdisk(self, size, mntpnt="", message_level="normal"):
        ramdisk = RamDisk(str(size), mntpnt, message_level)

        if not ramdisk.success:
            raise Exception("Ramdisk setup failed...")

        return ramdisk.getDevice()
示例#3
0
    def setupRamdisk(self, size, mntpnt="", message_level="normal"):
        ramdisk = RamDisk(str(size), mntpnt, message_level)

        if not ramdisk.success:
            raise Exception("Ramdisk setup failed...")

        return ramdisk.getDevice()
示例#4
0
文件: macbuild.py 项目: aes512/stonix
 def setupRamdisk(self, size=DEFAULT_RAMDISK_SIZE, mntpnt=""):
     # TODO: Add debug/verbose options
     message_level = "normal"
     ramdisk = RamDisk(str(size), mntpnt, message_level)
     
     if not ramdisk.success:
         raise Exception("Ramdisk setup failed...")
     
     return ramdisk.getDevice()
示例#5
0
    def setUpClass(self):
        """
        Initializer
        """
        # Start timer in miliseconds
        self.test_start_time = datetime.now()

        #self.message_level = "debug"
        self.message_level = "debug"

        self.libcPath = None  # initial initialization

        #####
        # If we don't have a supported platform, skip this test.
        if not sys.platform.startswith("darwin") and \
           not sys.platform.startswith("linux"):
            unittest.SkipTest("This is not valid on this OS")

        self.subdirs = ["two", "three" "one/four"]
        """
        Set up a ramdisk and use that random location as a root to test the
        filesystem functionality of what is being tested.
        """
        #Calculate size of ramdisk to make for this unit test.
        size_in_mb = 1800
        ramdisk_size = size = size_in_mb
        self.mnt_pnt_requested = ""

        self.logger = CyLogger()

        self.success = False
        self.mountPoint = False
        self.ramdiskDev = False
        self.mnt_pnt_requested = False

        # get a ramdisk of appropriate size, with a secure random mountpoint
        self.my_ramdisk = RamDisk(str(ramdisk_size), self.mnt_pnt_requested,
                                  self.message_level)
        (self.success, self.mountPoint,
         self.ramdiskDev) = self.my_ramdisk.getData()
        if self.success:
            self.logger.log(
                lp.INFO,
                "::::::::Ramdisk Mount Point: " + str(self.mountPoint))
            self.logger.log(
                lp.INFO,
                "::::::::Ramdisk Device     : " + str(self.ramdiskDev))

        else:
            raise IOError("Cannot get a ramdisk for some reason. . .")

        #####
        # Create a temp location on disk to run benchmark tests against
        self.fs_dir = tempfile.mkdtemp()
示例#6
0
    def setUpClass(self):
        """
        """
        self.getLibc()
        self.subdirs = ["two", "three" "one/four"]
        self.logger = CyLogger()
        self.logger.log(lp.CRITICAL,
                        "Logger initialized............................")
        """
        Set up a ramdisk and use that random location as a root to test the
        filesystem functionality of what is being tested.
        """
        #Calculate size of ramdisk to make for this unit test.
        size_in_mb = 1800
        ramdisk_size = size = size_in_mb
        self.mnt_pnt_requested = "testmntpnt"

        self.success = False
        self.mountPoint = ""
        self.ramdiskDev = False
        self.mnt_pnt_requested = False

        # get a ramdisk of appropriate size, with a secure random mountpoint
        self.my_ramdisk = RamDisk(str(ramdisk_size),
                                  self.mnt_pnt_requested,
                                  logger=self.logger)
        (self.success, self.mountPoint,
         self.ramdiskDev) = self.my_ramdisk.getData()
        self.logger.log(
            lp.WARNING,
            str(self.success) + " : " + str(self.mountPoint) + " : " +
            str(self.ramdiskDev))
        self.mount = self.mountPoint

        self.logger.log(lp.INFO,
                        "::::::::Ramdisk Mount Point: " + str(self.mountPoint))
        self.logger.log(lp.INFO,
                        "::::::::Ramdisk Device     : " + str(self.ramdiskDev))

        if not self.success:
            raise IOError("Cannot get a ramdisk for some reason. . .")

        #####
        # Create a temp location on disk to run benchmark tests against
        self.fs_dir = tempfile.mkdtemp()

        # Start timer in miliseconds
        self.test_start_time = datetime.now()

        self.setUpInstanceSpecifics()
示例#7
0
    def setUpClass(self):
        """
        Initializer
        """
        # Start timer in miliseconds
        self.test_start_time = datetime.now()

        #self.message_level = "debug"
        self.message_level = "debug"

        self.libcPath = None # initial initialization

        self.subdirs = ["two", "three" "one/four"]

        """
        Set up a ramdisk and use that random location as a root to test the
        filesystem functionality of what is being tested.
        """
        #Calculate size of ramdisk to make for this unit test.
        size_in_mb = 1800
        ramdisk_size = size = size_in_mb
        self.mnt_pnt_requested = ""

        self.logger = CyLogger()

        self.success = False
        self.mountPoint = False
        self.ramdiskDev = False
        self.mnt_pnt_requested = False

        # get a ramdisk of appropriate size, with a secure random mountpoint
        self.my_ramdisk = RamDisk(str(ramdisk_size),
                                  self.mnt_pnt_requested,
                                  self.message_level)
        (self.success, self.mountPoint, self.ramdiskDev) = self.my_ramdisk.getData()
        if self.success:
            self.logger.log(lp.INFO, "::::::::Ramdisk Mount Point: " + str(self.mountPoint))
            self.logger.log(lp.INFO, "::::::::Ramdisk Device     : " + str(self.ramdiskDev))

        else:
            raise IOError("Cannot get a ramdisk for some reason. . .")

        #####
        # Create a temp location on disk to run benchmark tests against
        self.fs_dir = tempfile.mkdtemp()
示例#8
0
    def getRamdisk(self, size=0, mountpoint="", ramdiskType=""):
        """
        Getter for the ramdisk instance.
        
        @var: ramdisks - a list of ramdisks this factory has created
        
        @param: size - size of the ramdisk to create. If zero, it looks for 
        @author: Roy Nielsen
        """
        if not ramdiskType in self.validRamdiskTypes:
            raise BadRamdiskTypeException("Not a valid ramdisk type")

        if size and mountpoint and ramdiskType:
            #####
            # Determine OS and ramdisk type, create ramdisk accordingly
            if self.myosfamily == "darwin":
                #####
                # Found MacOS
                from macRamdisk import RamDisk
                self.activeRamdisk = RamDisk(size, mountpoint, self.logger)

            elif self.myosfamily == "linux" and ramdiskType == "loop":
                #####
                # Found Linux with a loopback ramdisk request
                from linuxLoopRamdisk import RamDisk
                self.activeRamdisk = RamDisk(mountpoint, self.logger)

            elif self.myosfamily == "linux" and ramdiskType == "tmpfs":
                #####
                # Found Linux with a tmpfs ramdisk request.
                from linuxTmpfsRamdisk import RamDisk
                self.activeRamdisk = RamDisk(size, mountpoint, self.logger)

            else:
                #####
                # Bad method input parameters...
                self.activeRamdisk = None

            #####
            # Append the newly assigned self.activeRamdisk to the self.ramdisks
            # list
            self.ramdisks.append(self.activeRamdisk)

        elif not size and mountpoint:
            #####
            # Look for the ramdisk with "mountpoint" and return that instance.
            for ramdisk in self.ramdisks:
                if re.match("^%s$" % mountpoint, ramdisk.getMountPoint()):
                    self.activeRamdisk = ramdisk
                    break

        return self.activeRamdisk
示例#9
0
class RamDiskFactory(object):
    """
    Retrieve and OS specific ramdisk, and provide an interface to manage it.

    Keeps a reference to a list of ramdisks.  When calling getRamdisk(new), if
    "new" is true, the method will add the ramdisk to the list of ramdisks.

    @parameter message_level: Level of logging a person wishes to log at.
                              see logMessage in the log_message module.

    @method: getRamdisk: Will return either a new ramdisk, or make the
                         self.activeRamdisk the ramdisk with the name of the
                         passed in mountpoint (if found).  Otherwise, the
                         self.activeRamdisk is initialized to None.

    @method getModuleVersion: gets the version of this module.

    @method unmountActiveRamdisk: Unmounts the active ramdisk.

    @method unmountRamdisk: Unmounts the mountpoint that is passed in.

    @author: Roy Nielsen
    """
    def __init__(self, logger=None):
        """
        Identify OS and instantiate an instance of a ramdisk
        """
        self.module_version = '20160224.203258.288119'

        self.size = 0
        self.mountpoint = None
        self.ramdiskType = None
        if not logger:
            self.logger = CyLogger()
        else:
            self.logger = logger
        self.activeRamdisk = None
        self.ramdisks = []
        self.validRamdiskTypes = ["loop", "tmpfs"]
        self.validOSFamilies = ["macos", "linux"]

        self.myosfamily = getOsFamily()

        if not self.myosfamily in self.validOSFamilies:
            raise OSNotValidForRamdiskHelper("Needs to be MacOS or Linux...")

    ############################################################################

    def getRamdisk(self, size=0, mountpoint="", ramdiskType=""):
        """
        Getter for the ramdisk instance.
        
        @var: ramdisks - a list of ramdisks this factory has created
        
        @param: size - size of the ramdisk to create. If zero, it looks for 
        @author: Roy Nielsen
        """
        if not ramdiskType in self.validRamdiskTypes:
            raise BadRamdiskTypeException("Not a valid ramdisk type")

        if size and mountpoint and ramdiskType:
            #####
            # Determine OS and ramdisk type, create ramdisk accordingly
            if self.myosfamily == "darwin":
                #####
                # Found MacOS
                from macRamdisk import RamDisk
                self.activeRamdisk = RamDisk(size, mountpoint, self.logger)

            elif self.myosfamily == "linux" and ramdiskType == "loop":
                #####
                # Found Linux with a loopback ramdisk request
                from linuxLoopRamdisk import RamDisk
                self.activeRamdisk = RamDisk(mountpoint, self.logger)

            elif self.myosfamily == "linux" and ramdiskType == "tmpfs":
                #####
                # Found Linux with a tmpfs ramdisk request.
                from linuxTmpfsRamdisk import RamDisk
                self.activeRamdisk = RamDisk(size, mountpoint, self.logger)

            else:
                #####
                # Bad method input parameters...
                self.activeRamdisk = None

            #####
            # Append the newly assigned self.activeRamdisk to the self.ramdisks
            # list
            self.ramdisks.append(self.activeRamdisk)

        elif not size and mountpoint:
            #####
            # Look for the ramdisk with "mountpoint" and return that instance.
            for ramdisk in self.ramdisks:
                if re.match("^%s$" % mountpoint, ramdisk.getMountPoint()):
                    self.activeRamdisk = ramdisk
                    break

        return self.activeRamdisk

    ############################################################################

    def getModuleVersion(self):
        """
        Getter for the version of this  module.

        @author: Roy Nielsen
        """
        return self.module_version

    ############################################################################

    def unmountActiveRamdisk(self):
        """
        Eject the currently active ramdisk in the Factory.

        @return: success - successful = True, unsuccessful = False

        @author: Roy Nielsen
        """
        success = False

        success = self.activeRamdisk.unmount(self.logger)

        return success

    ############################################################################

    def unmountRamdisk(self, mountpoint=""):
        """
        Eject the ramdisk in the list with the passed in mountpoint.

        @param mountpoint: the mountpoint to eject.

        @return: True if successful, False if not successful

        @author: Roy Nielsen
        """
        success = False
        if mountpoint:
            for ramdisk in self.ramdisks:
                if re.match("^%s$" % mountpoint, ramdisk.getMountPoint()):
                    self.activeRamdisk = ramdisk
                    success = self.unmountActiveRamdisk()
                    break

        return success
示例#10
0
    size = int(opts.size)  # in Megabytes
else:
    size = str(512)

if opts.mntpnt:
    mntpnt = opts.mntpnt
else:
    mntpnt = "uniontest"

if not os.path.exists(mntpnt):
    os.makedirs(mntpnt)

logger = CyLogger(level=level)
logger.initializeLogs()

ramdisk = RamDisk(size=size, logger=logger)
ramdisk.logData()
ramdisk.printData()

ramdisk.unionOver(mntpnt)

ramdisk.printData()

if not ramdisk.success:
    raise Exception("Ramdisk setup failed..")

print((ramdisk.getDevice()))

# print "\n\n"
# print ramdisk.get_data()
示例#11
0
                  help="Size of ramdisk you want to create in 512byte blocks")
parser.add_option("-m", "--mount-point", dest="mntpnt",
                  default="", 
                  help="Name of the mountpoint you want to mount to")
parser.add_option("-d", "--debug", action="store_true", dest="debug", 
                  default=0, help="Print debug messages")
parser.add_option("-v", "--verbose", action="store_true", 
                  dest="verbose", default=0, 
                  help="Print status messages")

(opts, args) = parser.parse_args()

if opts.verbose != 0:
    message_level = "verbose"
elif opts.debug != 0:
    message_level = "debug"
else:
    message_level="normal"

if opts.size:
    size = int(opts.size) * 2 * 1024
mntpnt = opts.mntpnt

ramdisk = RamDisk(str(size), mntpnt, message_level)

if not ramdisk.success:
    raise Exception("Ramdisk setup failed..")

print ramdisk.getDevice()

示例#12
0
    size = int(opts.size) # in Megabytes
else:
    size = str(512)

if opts.mntpnt:
    mntpnt = opts.mntpnt
else:
    mntpnt = "uniontest"

if not os.path.exists(mntpnt):
    os.makedirs(mntpnt)

logger = CyLogger(level=level)
logger.initializeLogs()

ramdisk = RamDisk(size=size, logger=logger)
ramdisk.logData()
ramdisk.printData()

ramdisk.unionOver(mntpnt)

ramdisk.printData()

if not ramdisk.success:
    raise Exception("Ramdisk setup failed..")

print ramdisk.getDevice()



# print "\n\n"
示例#13
0
                  default=0, help="Print debug messages")
parser.add_option("-v", "--verbose", action="store_true",
                  dest="verbose", default=0,
                  help="Print status messages")

(opts, args) = parser.parse_args()

if opts.verbose != 0:
    level = Logger(level=lp.INFO)
elif opts.debug != 0:
    level = Logger(level=lp.DEBUG)
else:
    level=lp.WARNING

if opts.size:
    size = int(opts.size)  # in Megabytes
mntpnt = opts.mntpnt

logger = CyLogger()
logger.initializeLogs()

ramdisk = RamDisk(str(size), mntpnt, logger)
ramdisk.logData()
ramdisk.printData()

if not ramdisk.success:
    raise Exception("Ramdisk setup failed..")

print((ramdisk.getDevice()))

示例#14
0
class test_ramdisk(GenericRamdiskTest):
    """
    """

    @classmethod
    def setUpClass(self):
        """
        Initializer
        """
        # Start timer in miliseconds
        self.test_start_time = datetime.now()

        #self.message_level = "debug"
        self.message_level = "debug"

        self.libcPath = None # initial initialization

        self.subdirs = ["two", "three" "one/four"]

        """
        Set up a ramdisk and use that random location as a root to test the
        filesystem functionality of what is being tested.
        """
        #Calculate size of ramdisk to make for this unit test.
        size_in_mb = 1800
        ramdisk_size = size = size_in_mb
        self.mnt_pnt_requested = ""

        self.logger = CyLogger()

        self.success = False
        self.mountPoint = False
        self.ramdiskDev = False
        self.mnt_pnt_requested = False

        # get a ramdisk of appropriate size, with a secure random mountpoint
        self.my_ramdisk = RamDisk(str(ramdisk_size),
                                  self.mnt_pnt_requested,
                                  self.message_level)
        (self.success, self.mountPoint, self.ramdiskDev) = self.my_ramdisk.getData()
        if self.success:
            self.logger.log(lp.INFO, "::::::::Ramdisk Mount Point: " + str(self.mountPoint))
            self.logger.log(lp.INFO, "::::::::Ramdisk Device     : " + str(self.ramdiskDev))

        else:
            raise IOError("Cannot get a ramdisk for some reason. . .")

        #####
        # Create a temp location on disk to run benchmark tests against
        self.fs_dir = tempfile.mkdtemp()

    def setUp(self):
        """
        This method runs before each test run.

        @author: Roy Nielsen
        """
        self.libcPath = None # initial initialization
        #####
        # setting up to call ctypes to do a filesystem sync
        if sys.platform.startswith("darwin"):
            #####
            # For Mac
            self.libc = C.CDLL("/usr/lib/libc.dylib")
        elif sys.platform.startswith("linux"):
            #####
            # For Linux
            self.findLinuxLibC()
            self.libc = C.CDLL(self.libcPath)
        else:
            self.libc = self._pass()


###############################################################################
##### Helper Methods


###############################################################################
##### Method Tests

    ##################################

    def test_init(self):
        """
        """
        pass

    ##################################

    def test_get_data(self):
        """
        """
        pass

    ##################################

    def test_getRandomizedMountpoint(self):
        """
        """
        pass

    ##################################

    def test_create(self):
        """
        """
        pass

    ##################################

    def test_mount(self):
        """
        """
        pass

    ##################################

    def test_attach(self):
        """
        """
        pass

    ##################################

    def test_remove_journal(self):
        """
        """
        pass

    ##################################

    def test_unmount(self):
        """
        """
        pass

    ##################################

    def test_eject(self):
        """
        """
        pass

    ##################################

    def test_format(self):
        """
        """
        pass

    ##################################

    def test_partition(self):
        """
        """
        pass

    ##################################

    def test_isMemoryAvailable(self):
        """
        """
        pass

    ##################################

    def test_runcmd(self):
        """
        """
        pass

    ##################################

    def test_getDevice(self):
        """
        """
        pass

    ##################################

    def test_setDevice(self):
        """
        """
        pass

    ##################################

    def test_getVersion(self):
        """
        """
        pass

    ##################################

    def test_detach(self):
        """
        """
        pass

###############################################################################
##### Functional Tests

    ##################################

    def test_files_n_dirs(self):
        """
        Should work when files exist in ramdisk.
        """
        # Do file setup for this test
        for subdir in self.subdirs:
            dirpath = self.mountPoint + "/" + subdir
            self.logger.log(lp.DEBUG, "DIRPATH: : " + str(dirpath))
            self.mkdirs(dirpath)
            self.touch(dirpath + "/" + "test")

        # Do the tests
        for subdir in self.subdirs:
            # CANNOT use os.path.join this way.  os.path.join cannot deal with
            # absolute directories.  May work with mounting ramdisk in local
            # relative directories.
            self.assertTrue(os.path.exists(self.mountPoint + "/" + subdir + "/" +  "test"))

    ##################################

    def test_four_file_sizes(self):
        """
        Test file creation of various sizes, ramdisk vs. filesystem
        """
        #####
        # Clean up the ramdisk
        self.my_ramdisk._format()
        #####
        # 100Mb file size
        oneHundred = 100
        #####
        # 100Mb file size
        twoHundred = 200
        #####
        # 500Mb file size
        fiveHundred = 500
        #####
        # 1Gb file size
        oneGig = 1000

        my_fs_array = [oneHundred, twoHundred, fiveHundred, oneGig]
        time.sleep(1)
        for file_size in my_fs_array:
            self.logger.log(lp.DEBUG, "testfile size: " + str(file_size))
            #####
            # Create filesystem file and capture the time it takes...
            fs_time = self.mkfile(os.path.join(self.fs_dir, "testfile"), file_size)
            self.logger.log(lp.DEBUG, "fs_time: " + str(fs_time))
            time.sleep(1)

            #####
            # get the time it takes to create the file in ramdisk...
            ram_time = self.mkfile(os.path.join(self.mountPoint, "testfile"), file_size)
            self.logger.log(lp.DEBUG, "ram_time: " + str(ram_time))
            time.sleep(1)

            speed = fs_time - ram_time
            self.logger.log(lp.DEBUG, "ramdisk: " + str(speed) + " faster...")

            self.assertTrue((fs_time - ram_time).days>-1)


    def test_many_small_files_creation(self):
        """
        """
        #####
        # Clean up the ramdisk
        self.my_ramdisk._format()
        #####
        #
        ramdisk_starttime = datetime.now()
        for i in range(1000):
            self.mkfile(os.path.join(self.mountPoint, "testfile" + str(i)), 1)
        ramdisk_endtime = datetime.now()

        rtime = ramdisk_endtime - ramdisk_starttime

        fs_starttime = datetime.now()
        for i in range(1000):
            self.mkfile(os.path.join(self.fs_dir, "testfile" + str(i)), 1)
        fsdisk_endtime = datetime.now()

        fstime = fsdisk_endtime - fs_starttime

        self.assertTrue((fstime - rtime).days > -11)

###############################################################################
##### unittest Tear down
    @classmethod
    def tearDownClass(self):
        """
        disconnect ramdisk
        """
        if self.my_ramdisk.unmount():
            self.logger.log(lp.INFO, r"Successfully detached disk: " + \
                       str(self.my_ramdisk.mntPoint).strip())
        else:
            self.logger.log(lp.WARNING, r"Couldn't detach disk: " + \
                       str(self.my_ramdisk.myRamdiskDev).strip() + \
                       " : mntpnt: " + str(self.my_ramdisk.mntPoint))
            raise Exception(r"Cannot eject disk: " + \
                            str(self.my_ramdisk.myRamdiskDev).strip() + \
                            " : mntpnt: " + str(self.my_ramdisk.mntPoint))
        #####
        # capture end time
        test_end_time = datetime.now()

        #####
        # Calculate and log how long it took...
        test_time = (test_end_time - self.test_start_time)

        self.logger.log(lp.INFO, self.__module__ + " took " + str(test_time) + \
                  " time to complete...")
示例#15
0
class test_ramdisk(GenericRamdiskTest):
    ''' '''

    @classmethod
    def setUpClass(self):
        '''Initializer'''
        # Start timer in miliseconds
        self.test_start_time = datetime.now()

        #self.message_level = "debug"
        self.message_level = "debug"

        self.libcPath = None # initial initialization

        self.subdirs = ["two", "three" "one/four"]

        """
        Set up a ramdisk and use that random location as a root to test the
        filesystem functionality of what is being tested.
        """
        #Calculate size of ramdisk to make for this unit test.
        size_in_mb = 1800
        ramdisk_size = size = size_in_mb
        self.mnt_pnt_requested = ""

        self.logger = CyLogger()

        self.success = False
        self.mountPoint = False
        self.ramdiskDev = False
        self.mnt_pnt_requested = False

        # get a ramdisk of appropriate size, with a secure random mountpoint
        self.my_ramdisk = RamDisk(str(ramdisk_size),
                                  self.mnt_pnt_requested,
                                  self.message_level)
        (self.success, self.mountPoint, self.ramdiskDev) = self.my_ramdisk.getData()
        if self.success:
            self.logger.log(lp.INFO, "::::::::Ramdisk Mount Point: " + str(self.mountPoint))
            self.logger.log(lp.INFO, "::::::::Ramdisk Device     : " + str(self.ramdiskDev))

        else:
            raise IOError("Cannot get a ramdisk for some reason. . .")

        #####
        # Create a temp location on disk to run benchmark tests against
        self.fs_dir = tempfile.mkdtemp()

    def setUp(self):
        '''This method runs before each test run.
        
        @author: Roy Nielsen


        '''
        self.libcPath = None # initial initialization
        #####
        # setting up to call ctypes to do a filesystem sync
        if sys.platform.startswith("darwin"):
            #####
            # For Mac
            self.libc = C.CDLL("/usr/lib/libc.dylib")
        elif sys.platform.startswith("linux"):
            #####
            # For Linux
            self.findLinuxLibC()
            self.libc = C.CDLL(self.libcPath)
        else:
            self.libc = self._pass()


###############################################################################
##### Helper Methods


###############################################################################
##### Method Tests

    ##################################

    def test_init(self):
        ''' '''
        pass

    ##################################

    def test_get_data(self):
        ''' '''
        pass

    ##################################

    def test_getRandomizedMountpoint(self):
        ''' '''
        pass

    ##################################

    def test_create(self):
        ''' '''
        pass

    ##################################

    def test_mount(self):
        ''' '''
        pass

    ##################################

    def test_attach(self):
        ''' '''
        pass

    ##################################

    def test_remove_journal(self):
        ''' '''
        pass

    ##################################

    def test_unmount(self):
        ''' '''
        pass

    ##################################

    def test_eject(self):
        ''' '''
        pass

    ##################################

    def test_format(self):
        ''' '''
        pass

    ##################################

    def test_partition(self):
        ''' '''
        pass

    ##################################

    def test_isMemoryAvailable(self):
        ''' '''
        pass

    ##################################

    def test_runcmd(self):
        ''' '''
        pass

    ##################################

    def test_getDevice(self):
        ''' '''
        pass

    ##################################

    def test_setDevice(self):
        ''' '''
        pass

    ##################################

    def test_getVersion(self):
        ''' '''
        pass

    ##################################

    def test_detach(self):
        ''' '''
        pass

###############################################################################
##### Functional Tests

    ##################################

    def test_files_n_dirs(self):
        '''Should work when files exist in ramdisk.'''
        # Do file setup for this test
        for subdir in self.subdirs:
            dirpath = self.mountPoint + "/" + subdir
            self.logger.log(lp.DEBUG, "DIRPATH: : " + str(dirpath))
            self.mkdirs(dirpath)
            self.touch(dirpath + "/" + "test")

        # Do the tests
        for subdir in self.subdirs:
            # CANNOT use os.path.join this way.  os.path.join cannot deal with
            # absolute directories.  May work with mounting ramdisk in local
            # relative directories.
            self.assertTrue(os.path.exists(self.mountPoint + "/" + subdir + "/" +  "test"))

    ##################################

    def test_four_file_sizes(self):
        '''Test file creation of various sizes, ramdisk vs. filesystem'''
        #####
        # Clean up the ramdisk
        self.my_ramdisk._format()
        #####
        # 100Mb file size
        oneHundred = 100
        #####
        # 100Mb file size
        twoHundred = 200
        #####
        # 500Mb file size
        fiveHundred = 500
        #####
        # 1Gb file size
        oneGig = 1000

        my_fs_array = [oneHundred, twoHundred, fiveHundred, oneGig]
        time.sleep(1)
        for file_size in my_fs_array:
            self.logger.log(lp.DEBUG, "testfile size: " + str(file_size))
            #####
            # Create filesystem file and capture the time it takes...
            fs_time = self.mkfile(os.path.join(self.fs_dir, "testfile"), file_size)
            self.logger.log(lp.DEBUG, "fs_time: " + str(fs_time))
            time.sleep(1)

            #####
            # get the time it takes to create the file in ramdisk...
            ram_time = self.mkfile(os.path.join(self.mountPoint, "testfile"), file_size)
            self.logger.log(lp.DEBUG, "ram_time: " + str(ram_time))
            time.sleep(1)

            speed = fs_time - ram_time
            self.logger.log(lp.DEBUG, "ramdisk: " + str(speed) + " faster...")

            self.assertTrue((fs_time - ram_time).days>-1)


    def test_many_small_files_creation(self):
        ''' '''
        #####
        # Clean up the ramdisk
        self.my_ramdisk._format()
        #####
        #
        ramdisk_starttime = datetime.now()
        for i in range(1000):
            self.mkfile(os.path.join(self.mountPoint, "testfile" + str(i)), 1)
        ramdisk_endtime = datetime.now()

        rtime = ramdisk_endtime - ramdisk_starttime

        fs_starttime = datetime.now()
        for i in range(1000):
            self.mkfile(os.path.join(self.fs_dir, "testfile" + str(i)), 1)
        fsdisk_endtime = datetime.now()

        fstime = fsdisk_endtime - fs_starttime

        self.assertTrue((fstime - rtime).days > -11)

###############################################################################
##### unittest Tear down
    @classmethod
    def tearDownClass(self):
        '''disconnect ramdisk'''
        if self.my_ramdisk.unmount():
            self.logger.log(lp.INFO, r"Successfully detached disk: " + \
                       str(self.my_ramdisk.mntPoint).strip())
        else:
            self.logger.log(lp.WARNING, r"Couldn't detach disk: " + \
                       str(self.my_ramdisk.myRamdiskDev).strip() + \
                       " : mntpnt: " + str(self.my_ramdisk.mntPoint))
            raise Exception(r"Cannot eject disk: " + \
                            str(self.my_ramdisk.myRamdiskDev).strip() + \
                            " : mntpnt: " + str(self.my_ramdisk.mntPoint))
        #####
        # capture end time
        test_end_time = datetime.now()

        #####
        # Calculate and log how long it took...
        test_time = (test_end_time - self.test_start_time)

        self.logger.log(lp.INFO, self.__module__ + " took " + str(test_time) + \
                  " time to complete...")
示例#16
0
                  default="", 
                  help="Name of the mountpoint you want to mount to")
parser.add_option("-d", "--debug", action="store_true", dest="debug", 
                  default=0, help="Print debug messages")
parser.add_option("-v", "--verbose", action="store_true", 
                  dest="verbose", default=0, 
                  help="Print status messages")

(opts, args) = parser.parse_args()

if opts.verbose != 0:
    message_level = "verbose"
elif opts.debug != 0:
    message_level = "debug"
else:
    message_level="normal"

if opts.size:
    size = int(opts.size) * 2 * 1024
mntpnt = opts.mntpnt

ramdisk = RamDisk(str(size), mntpnt, message_level)

if not ramdisk.success:
    raise Exception("Ramdisk setup failed..")

print ramdisk.getDevice()

print "\n\n"
print ramdisk.get_data()
示例#17
0
class GenericRamdiskTest(unittest.TestCase, GenericTestUtilities):
    """
    Holds helper methods.  DO NOT create an init

    Inspiration for using classmethod:
    http://simeonfranklin.com/testing2.pdf

    @author: Roy Nielsen
    """
    @classmethod
    def setUpClass(self):
        """
        """
        #self.getLibc()
        self.subdirs = ["two", "three" "one/four"]
        self.logger = CyLogger()
        self.logger.log(lp.CRITICAL, "Logger initialized............................")

        """
        Set up a ramdisk and use that random location as a root to test the
        filesystem functionality of what is being tested.
        """
        #Calculate size of ramdisk to make for this unit test.
        size_in_mb = 1800
        ramdisk_size = size = size_in_mb
        self.mnt_pnt_requested = ""

        self.success = False
        self.mountPoint = False
        self.ramdiskDev = False
        self.mnt_pnt_requested = False

        # get a ramdisk of appropriate size, with a secure random mountpoint
        self.my_ramdisk = RamDisk(size=str(ramdisk_size), logger=self.logger)
        (self.success, self.mountPoint, self.ramdiskDev) = self.my_ramdisk.getData()

        self.mount = self.mountPoint

        self.logger.log(lp.INFO, "::::::::Ramdisk Mount Point: " + str(self.mountPoint))
        self.logger.log(lp.INFO, "::::::::Ramdisk Device     : " + str(self.ramdiskDev))

        if not self.success:
            raise IOError("Cannot get a ramdisk for some reason. . .")

        #####
        # Create a temp location on disk to run benchmark tests against
        self.fs_dir = tempfile.mkdtemp()

        # Start timer in miliseconds
        self.test_start_time = datetime.now()

        self.setUpInstanceSpecifics()

    @classmethod
    def setUpInstanceSpecifics(self):
        """
        Call the child class setUpClass initializer, if possible..

        Here to be over-ridden by a child class.

        @author: Roy Nielsen
        """
        pass

    ################################################
    ##### Helper Methods

    def _unloadRamdisk(self):
        """
        """
        if self.my_ramdisk.unmount():
            self.logger.log(lp.INFO, r"Successfully detached disk: " + \
                       str(self.my_ramdisk.mntPoint).strip())
        else:
            self.logger.log(lp.WARNING, r"Couldn't detach disk: " + \
                       str(self.my_ramdisk.myRamdiskDev).strip() + \
                       " : mntpnt: " + str(self.my_ramdisk.mntPoint))
            raise Exception(r"Cannot eject disk: " + \
                            str(self.my_ramdisk.myRamdiskDev).strip() + \
                            " : mntpnt: " + str(self.my_ramdisk.mntPoint))

###############################################################################
##### Functional Tests

    ##################################

    def test_files_n_dirs(self):
        """
        Should work when files exist in ramdisk.
        """
        # Do file setup for this test
        for subdir in self.subdirs:
            dirpath = self.mountPoint + "/" + subdir
            self.logger.log(lp.DEBUG, "DIRPATH: : " + str(dirpath))
            self.mkdirs(dirpath)
            self.touch(dirpath + "/" + "test")

        # Do the tests
        for subdir in self.subdirs:
            # CANNOT use os.path.join this way.  os.path.join cannot deal with
            # absolute directories.  May work with mounting ramdisk in local
            # relative directories.
            self.assertTrue(os.path.exists(self.mountPoint + "/" + subdir + "/" +  "test"), "Problem with ramdisk...")

    ##################################

    def test_four_file_sizes(self):
        """
        Test file creation of various sizes, ramdisk vs. filesystem
        """
        #####
        # Clean up the ramdisk
        self.my_ramdisk._format()
        #####
        # 100Mb file size
        oneHundred = 100
        #####
        # 100Mb file size
        twoHundred = 200
        #####
        # 500Mb file size
        fiveHundred = 500
        #####
        # 1Gb file size
        oneGig = 1000

        my_fs_array = [oneHundred, twoHundred, fiveHundred, oneGig]

        for file_size in my_fs_array:
            self.logger.log(lp.INFO, "testfile size: " + str(file_size))
            #####
            # Create filesystem file and capture the time it takes...
            fs_time = self.mkfile(os.path.join(self.fs_dir, "testfile"), file_size)
            self.logger.log(lp.INFO, "fs_time: " + str(fs_time))

            #####
            # get the time it takes to create the file in ramdisk...
            ram_time = self.mkfile(os.path.join(self.mountPoint, "testfile"), file_size)
            self.logger.log(lp.INFO, "ram_time: " + str(ram_time))

            speed = fs_time - ram_time
            self.logger.log(lp.INFO, "ramdisk: " + str(speed) + " faster...")

            self.assertTrue((fs_time - ram_time).days > -1, "Problem with ramdisk...")

    ##################################

    def test_many_small_files_creation(self):
        """
        """
        #####
        # Clean up the ramdisk
        self.my_ramdisk._format()
        #####
        #
        ramdisk_starttime = datetime.now()
        for i in range(1000):
            self.mkfile(os.path.join(self.mountPoint, "testfile" + str(i)), 1)
        ramdisk_endtime = datetime.now()

        rtime = ramdisk_endtime - ramdisk_starttime

        fs_starttime = datetime.now()
        for i in range(1000):
            self.mkfile(os.path.join(self.fs_dir, "testfile" + str(i)), 1)
        fsdisk_endtime = datetime.now()

        fstime = fsdisk_endtime - fs_starttime

        self.assertTrue((fstime - rtime).days > -1, "Problem with ramdisk...")

    ##################################

    @classmethod
    def tearDownInstanceSpecifics(self):
        """
        Skeleton method in case a child class wants/needs to override it.

        @author: Roy Nielsen
        """
        pass

    @classmethod
    def tearDownClass(self):
        """
        """
        self.tearDownInstanceSpecifics()
        if unmount(self.mount):
            self.logger.log(lp.INFO, r"Successfully detached disk: " + \
                       str(self.my_ramdisk.mntPoint).strip())
        else:
            self.logger.log(lp.WARNING, r"Couldn't detach disk: " + \
                       str(self.my_ramdisk.myRamdiskDev).strip() + \
                       " : mntpnt: " + str(self.my_ramdisk.mntPoint))
            raise Exception(r"Cannot eject disk: " + \
                            str(self.my_ramdisk.myRamdiskDev).strip() + \
                            " : mntpnt: " + str(self.my_ramdisk.mntPoint))
        #####
        # capture end time
        test_end_time = datetime.now()

        #####
        # Calculate and log how long it took...
        test_time = (test_end_time - self.test_start_time)

        self.logger.log(lp.INFO, self.__module__ + " took " + str(test_time) + \
                  " time to complete...")
示例#18
0
                  default=0, help="Print debug messages")
parser.add_option("-v", "--verbose", action="store_true",
                  dest="verbose", default=0,
                  help="Print status messages")

(opts, args) = parser.parse_args()

if opts.verbose != 0:
    level = Logger(level=lp.INFO)
elif opts.debug != 0:
    level = Logger(level=lp.DEBUG)
else:
    level=lp.WARNING

if opts.size:
    size = int(opts.size)  # in Megabytes
mntpnt = opts.mntpnt

logger = CyLogger()
logger.initializeLogs()

ramdisk = RamDisk(str(size), mntpnt, logger)
ramdisk.logData()
ramdisk.printData()

if not ramdisk.success:
    raise Exception("Ramdisk setup failed..")

print ramdisk.getDevice()

示例#19
0
class GenericRamdiskTest(unittest.TestCase, GenericTestUtilities):
    """
    Holds helper methods.  DO NOT create an init

    Inspiration for using classmethod:
    http://simeonfranklin.com/testing2.pdf

    @author: Roy Nielsen
    """
    @classmethod
    def setUpClass(self):
        """
        """
        self.getLibc()
        self.subdirs = ["two", "three" "one/four"]
        self.logger = CyLogger()
        self.logger.log(lp.CRITICAL,
                        "Logger initialized............................")
        """
        Set up a ramdisk and use that random location as a root to test the
        filesystem functionality of what is being tested.
        """
        #Calculate size of ramdisk to make for this unit test.
        size_in_mb = 1800
        ramdisk_size = size = size_in_mb
        self.mnt_pnt_requested = "testmntpnt"

        self.success = False
        self.mountPoint = ""
        self.ramdiskDev = False
        self.mnt_pnt_requested = False

        # get a ramdisk of appropriate size, with a secure random mountpoint
        self.my_ramdisk = RamDisk(str(ramdisk_size),
                                  self.mnt_pnt_requested,
                                  logger=self.logger)
        (self.success, self.mountPoint,
         self.ramdiskDev) = self.my_ramdisk.getData()
        self.logger.log(
            lp.WARNING,
            str(self.success) + " : " + str(self.mountPoint) + " : " +
            str(self.ramdiskDev))
        self.mount = self.mountPoint

        self.logger.log(lp.INFO,
                        "::::::::Ramdisk Mount Point: " + str(self.mountPoint))
        self.logger.log(lp.INFO,
                        "::::::::Ramdisk Device     : " + str(self.ramdiskDev))

        if not self.success:
            raise IOError("Cannot get a ramdisk for some reason. . .")

        #####
        # Create a temp location on disk to run benchmark tests against
        self.fs_dir = tempfile.mkdtemp()

        # Start timer in miliseconds
        self.test_start_time = datetime.now()

        self.setUpInstanceSpecifics()

    @classmethod
    def setUpInstanceSpecifics(self):
        """
        Call the child class setUpClass initializer, if possible..

        Here to be over-ridden by a child class.

        @author: Roy Nielsen
        """
        pass

    ################################################
    ##### Helper Methods

    def _unloadRamdisk(self):
        """
        """
        if self.my_ramdisk.umount():
            self.logger.log(lp.INFO, r"Successfully detached disk: " + \
                       str(self.my_ramdisk.mntPoint).strip())
        else:
            self.logger.log(lp.WARNING, r"Couldn't detach disk: " + \
                       str(self.my_ramdisk.myRamdiskDev).strip() + \
                       " : mntpnt: " + str(self.my_ramdisk.mntPoint))
            raise Exception(r"Cannot eject disk: " + \
                            str(self.my_ramdisk.myRamdiskDev).strip() + \
                            " : mntpnt: " + str(self.my_ramdisk.mntPoint))

###############################################################################
##### Functional Tests

##################################

    def test_files_n_dirs(self):
        """
        Should work when files exist in ramdisk.
        """
        # Do file setup for this test
        for subdir in self.subdirs:
            dirpath = self.mountPoint + "/" + subdir
            self.logger.log(lp.DEBUG, "DIRPATH: : " + str(dirpath))
            self.mkdirs(dirpath)
            self.touch(dirpath + "/" + "test")

        # Do the tests
        for subdir in self.subdirs:
            # CANNOT use os.path.join this way.  os.path.join cannot deal with
            # absolute directories.  May work with mounting ramdisk in local
            # relative directories.
            self.assertTrue(
                os.path.exists(self.mountPoint + "/" + subdir + "/" + "test"),
                "Problem with ramdisk...")

    ##################################

    def test_four_file_sizes(self):
        """
        Test file creation of various sizes, ramdisk vs. filesystem
        """
        #####
        # Clean up the ramdisk
        self.my_ramdisk._format()
        #####
        # 100Mb file size
        oneHundred = 100
        #####
        # 500Mb file size
        fiveHundred = 500
        #####
        # 800Mb file size
        eightHundred = 800
        #####
        # 1Gb file size
        oneGig = 1000

        my_fs_array = [oneHundred, fiveHundred, eightHundred, oneGig]

        for file_size in my_fs_array:
            self.logger.log(lp.INFO, "testfile size: " + str(file_size))
            #####
            # Create filesystem file and capture the time it takes...
            fs_time = self.mkfile(os.path.join(self.fs_dir, "testfile"),
                                  file_size)
            self.logger.log(lp.INFO, "fs_time: " + str(fs_time))

            #####
            # get the time it takes to create the file in ramdisk...
            ram_time = self.mkfile(os.path.join(self.mountPoint, "testfile"),
                                   file_size)
            self.logger.log(lp.INFO, "ram_time: " + str(ram_time))

            speed = fs_time - ram_time
            self.logger.log(lp.INFO, "ramdisk: " + str(speed) + " faster...")

            assert_message = "Problem with " + str(file_size) + "mb ramdisk..."
            self.logger.log(lp.DEBUG, assert_message)
            self.logger.log(
                lp.INFO,
                "Smaller file sizes will fail this test on systems with SSD's..."
            )

            self.assertTrue((fs_time - ram_time).days > -1, assert_message)

    ##################################

    def test_many_small_files_creation(self):
        """
        """
        #####
        # Clean up the ramdisk
        self.my_ramdisk._format()
        #####
        #
        ramdisk_starttime = datetime.now()
        for i in range(1000):
            self.mkfile(os.path.join(self.mountPoint, "testfile" + str(i)), 1)
        ramdisk_endtime = datetime.now()

        rtime = ramdisk_endtime - ramdisk_starttime

        fs_starttime = datetime.now()
        for i in range(1000):
            self.mkfile(os.path.join(self.fs_dir, "testfile" + str(i)), 1)
        fsdisk_endtime = datetime.now()

        fstime = fsdisk_endtime - fs_starttime

        self.assertTrue((fstime - rtime).days > -1, "Problem with ramdisk...")

    ##################################

    @classmethod
    def tearDownInstanceSpecifics(self):
        """
        Skeleton method in case a child class wants/needs to override it.

        @author: Roy Nielsen
        """
        pass

    @classmethod
    def tearDownClass(self):
        """
        """
        self.tearDownInstanceSpecifics()
        try:
            umount(self.mount)
            self.logger.log(lp.INFO, r"Successfully detached disk: " + \
                       str(self.my_ramdisk.mntPoint).strip())
        except Exception:
            message = r"Couldn't detach disk: " + \
                       str(self.my_ramdisk.myRamdiskDev).strip() + \
                       " : mntpnt: " + str(self.my_ramdisk.mntPoint)
            ex_message = message + "\n" + traceback.format_exc()
            raise Exception(ex_message)

        #####
        # capture end time
        test_end_time = datetime.now()

        #####
        # Calculate and log how long it took...
        test_time = (test_end_time - self.test_start_time)

        self.logger.log(lp.INFO, self.__module__ + " took " + str(test_time) + \
                  " time to complete...")