Exemplo n.º 1
0
class test_libHelperFunctions(unittest.TestCase):
    """ 
    """
    @classmethod
    def setUpClass(self):
        """ 
        """
        self.logger = CyLogger(debug_mode=True)
        self.logger.initializeLogs()
        self.logger.log(lp.DEBUG, "Test " + self.__name__ + " initialized...")

    @classmethod
    def tearDownClass(self):
        """ 
        """
        pass

    def test_FoundException(self):
        """ 
        """
        pass

    def test_get_os_vers(self):
        """ 
        """
        pass

    def test_get_os_minor_vers(self):
        """ 
        """
        pass
Exemplo n.º 2
0
class SedFile4VersionStamp(object):
    def __init__(self, files=[], logger=False):
        if not logger:
            self.logger = CyLogger()
            self.logger.initializeLogs()
        else:
            self.logger = logger
        self.acquireStamp()
        self.module_version = '20160224.032043.009191'
        if files:
            for myfile in files:
                self.sedFileWithDateTimeStamp(myfile)

    def acquireStamp(self):
        """
        Get the UTC time and format a time stamp string for the version.

        @author: Roy Nielsen
        """
        format = ""
        datestamp = datetime.utcnow()
        
        self.stamp = datestamp.strftime("%Y%m%d.%H%M%S.%f")
        self.logger.log(lp.DEBUG, "Stamp: " + str(self.stamp))

    def sedFileWithDateTimeStamp(self, file2change=""):
        """
        Find "^(\s+module_version\s*=\s*)\S*" or
             "^(\s+self.module_version\s*=\s*)\S*"
        and replace with x.group(1) + "'" +  acquireStamp() + "'"

        @author: Roy Nielsen
        """
        self.logger.log(lp.INFO, "********** Entered sed method...**************")
        startString = ""
        found = False
        if file2change:
            fp = open(file2change, "r")
            lines = fp.readlines()
            fp.close()
            fp = open(file2change, "w")
            for line in lines:
                check1 = re.match("^(\s+module_version\s*=\s*)\S*", line)
                check2 = re.match("^(\s+self\.module_version\s*=\s*)\S*", line)
                if check1:
                    self.logger.log(lp.DEBUG, "Found first check..")
                    startString = check1.group(1)
                    fp.write(re.sub("^\s+module_version\s*=\s*\S*", \
                                    startString + "'" + \
                                    self.stamp + "'", line))
                elif check2:
                    self.logger.log(lp.DEBUG, "Found second check...")
                    startString = check2.group(1)
                    fp.write(re.sub("^\s+self\.module_version\s*=\s*\S*", \
                                    startString + "'" + \
                                    self.stamp + "'", line))
                else:
                    fp.write(line)
            fp.close()
Exemplo n.º 3
0
if opts.size:
    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()

Exemplo n.º 4
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()))

Exemplo n.º 5
0
class SedFile4VersionStamp(object):
    def __init__(self, files=[], logger=False):
        if not logger:
            self.logger = CyLogger()
            self.logger.initializeLogs()
        else:
            self.logger = logger
        self.acquireStamp()
        self.module_version = '20160224.032043.009191'
        if files:
            for myfile in files:
                self.sedFileWithDateTimeStamp(myfile)

    def acquireStamp(self):
        '''Get the UTC time and format a time stamp string for the version.
        
        @author: Roy Nielsen


        '''
        format = ""
        datestamp = datetime.utcnow()

        self.stamp = datestamp.strftime("%Y%m%d.%H%M%S.%f")
        self.logger.log(lp.DEBUG, "Stamp: " + str(self.stamp))

    def sedFileWithDateTimeStamp(self, file2change=""):
        '''Find "^(\s+module_version\s*=\s*)\S*" or
             "^(\s+self.module_version\s*=\s*)\S*"
        and replace with x.group(1) + "'" +  acquireStamp() + "'"
        
        @author: Roy Nielsen

        :param file2change:  (Default value = "")

        '''
        self.logger.log(lp.INFO,
                        "********** Entered sed method...**************")
        startString = ""
        found = False
        if file2change:
            fp = open(file2change, "r")
            lines = fp.readlines()
            fp.close()
            fp = open(file2change, "w")
            for line in lines:
                check1 = re.match("^(\s+module_version\s*=\s*)\S*", line)
                check2 = re.match("^(\s+self\.module_version\s*=\s*)\S*", line)
                if check1:
                    self.logger.log(lp.DEBUG, "Found first check..")
                    startString = check1.group(1)
                    fp.write(re.sub("^\s+module_version\s*=\s*\S*", \
                                    startString + "'" + \
                                    self.stamp + "'", line))
                elif check2:
                    self.logger.log(lp.DEBUG, "Found second check...")
                    startString = check2.group(1)
                    fp.write(re.sub("^\s+self\.module_version\s*=\s*\S*", \
                                    startString + "'" + \
                                    self.stamp + "'", line))
                else:
                    fp.write(line)
            fp.close()
Exemplo n.º 6
0
    #####
    # ... processing modules ...
    if options.all:
        modules = None
    elif options.modules:
        modules = options.modules
    else:
        modules = None

    #####
    # ... processing logging options...
    verbose = options.verbose
    debug = options.debug
    logger = CyLogger(debug_mode=options.debug, verbose_mode=options.verbose)
    logger.initializeLogs(filename="ramdiskTestLog")

    logger.log(lp.DEBUG, "Modules: " + str(modules))

    #####
    # ... processing test prefixes
    if options.prefix:
        prefix = options.prefix
    else:
        prefix = ["test_", "Test_"]


    bars = BuildAndRunSuite(logger)
    bars.setPrefix(prefix)
    bars.run_suite(modules)
Exemplo n.º 7
0
    # Options processing

    #####
    # ... processing modules ...
    if options.all:
        modules = None
    elif options.modules:
        modules = options.modules
    else:
        modules = None

    #####
    # ... processing logging options...
    verbose = options.verbose
    debug = options.debug
    logger = CyLogger(debug_mode=options.debug, verbose_mode=options.verbose)
    logger.initializeLogs(syslog=options.skip_syslog)

    logger.log(lp.DEBUG, "Modules: " + str(modules))

    #####
    # ... processing test prefixes
    if options.prefix:
        prefix = options.prefix
    else:
        prefix = ["test_"]


    bars = BuildAndRunSuite(logger)
    bars.run_suite(modules)
Exemplo n.º 8
0
class test_run_commands(unittest.TestCase):
    """
    """
    @classmethod
    def setUpClass(self):
        """
        """
        #####
        # Set up logging
        self.logger = CyLogger(debug_mode=True)
        self.logger.initializeLogs()
        self.rw = RunWith(self.logger)
        #####
        # Start timer in miliseconds
        self.test_start_time = datetime.now()

    @classmethod
    def tearDownClass(self):
        """
        """
        pass

    def test_RunCommunicateWithBlankCommand(self):
        self.rw.__init__(self.logger)
        self.assertRaises(SetCommandTypeError, self.rw.setCommand, "")
        self.assertRaises(SetCommandTypeError, self.rw.setCommand, [])
        self.assertRaises(SetCommandTypeError, self.rw.setCommand, None)
        self.assertRaises(SetCommandTypeError, self.rw.setCommand, True)
        self.assertRaises(SetCommandTypeError, self.rw.setCommand, {})

    def test_setCommand(self):
        self.rw.__init__(self.logger)
        command = ['/bin/ls', 1, '.']
        self.assertRaises(SetCommandTypeError, self.rw.setCommand, [command])

    def test_communicate(self):
        """
        """
        self.rw.__init__(self.logger)
        self.logger.log(lp.DEBUG,
                        "=============== Starting test_communicate...")

        self.rw.setCommand('/bin/ls /var/spool', myshell=True)
        _, _, retval = self.rw.communicate(silent=False)
        self.assertEquals(
            retval, 0, "Valid [] command execution failed: " +
            '/bin/ls /var/spool --- retval: ' + str(retval))
        self.rw.setCommand(['/bin/ls', '-l', '/usr/local'])
        _, _, retval = self.rw.communicate(silent=False)
        self.assertEquals(
            retval, 0, "Valid [] command execution failed: " +
            '/bin/ls /var/spool --- retval: ' + str(retval))

        self.logger.log(lp.DEBUG, "=============== Ending test_communicate...")

    def test_wait(self):
        """
        """
        self.rw.__init__(self.logger)
        self.logger.log(lp.DEBUG, "=============== Starting test_wait...")

        self.rw.setCommand('/bin/ls /var/spool')
        _, _, retval = self.rw.communicate(silent=False)
        self.assertEquals(
            retval, 0, "Valid [] command execution failed: " +
            '/bin/ls /var/spool --- retval: ' + str(retval))

        self.rw.setCommand(['/bin/ls', '-l', '/usr/local'])
        _, _, retval = self.rw.communicate(silent=False)
        self.assertEquals(
            retval, 0, "Valid [] command execution failed: " +
            '/bin/ls /var/spool --- retval: ' + str(retval))

        self.rw.setCommand(['/bin/ls', '/1', '/'])
        _, _, retcode = self.rw.wait()
        self.logger.log(lp.WARNING, "retcode: " + str(retcode))
        if sys.platform == 'darwin':
            self.assertEquals(retcode, 1, "Returncode Test failed...")
        else:
            self.assertEquals(retcode, 2, "Returncode Test failed...")

    def test_waitNpassThruStdout(self):
        """
        """
        self.rw.__init__(self.logger)
        self.rw.setCommand(['/bin/ls', '-l', '/usr/local'])
        _, _, retval = self.rw.waitNpassThruStdout()
        self.assertEquals(
            retval, 0, "Valid [] command execution failed: " +
            '/bin/ls /var/spool --- retval: ' + str(retval))

        self.rw.setCommand(['/bin/ls', '/1', '/'])
        _, _, retval = self.rw.waitNpassThruStdout()
        if sys.platform == 'darwin':
            self.assertEquals(retval, 1, "Returncode Test failed...")
        else:
            self.assertEquals(retval, 2, "Returncode Test failed...")

    def test_timeout(self):
        """
        """
        self.rw.__init__(self.logger)
        if os.path.exists("/sbin/ping"):
            ping = "/sbin/ping"
        elif os.path.exists('/bin/ping'):
            ping = "/bin/ping"

        self.rw.setCommand([ping, '8.8.8.8'])

        startTime = time.time()
        self.rw.timeout(3)
        elapsed = (time.time() - startTime)

        self.assertTrue(elapsed < 4,
                        "Elapsed time is greater than it should be...")

    def test_runAs(self):
        """
        """
        pass

    def test_liftDown(self):
        """
        """
        pass

    def test_runAsWithSudo(self):
        """
        """
        pass

    def test_runWithSudo(self):
        """
        """
        pass

    def test_getecho(self):
        """
        """
        pass

    def test_waitnoecho(self):
        """
        """
        pass

    def test_RunThread(self):
        """
        """
        pass

    def test_runMyThreadCommand(self):
        """
        """
        pass