|
From: <ba...@us...> - 2007-12-31 23:22:13
|
Revision: 532
http://omc.svn.sourceforge.net/omc/?rev=532&view=rev
Author: bartw
Date: 2007-12-31 15:22:18 -0800 (Mon, 31 Dec 2007)
Log Message:
-----------
changed CL options. added tests for LogicalFile
Modified Paths:
--------------
test/trunk/omcbase_test.py
Modified: test/trunk/omcbase_test.py
===================================================================
--- test/trunk/omcbase_test.py 2007-12-27 04:28:09 UTC (rev 531)
+++ test/trunk/omcbase_test.py 2007-12-31 23:22:18 UTC (rev 532)
@@ -5,7 +5,10 @@
import pywbem
import os
import commands
+import shutil
+from stat import *
+from tempfile import mkdtemp
from lib import ProviderSanityTest as PST
from time import sleep
from socket import getfqdn
@@ -24,13 +27,10 @@
self.__dict__ = WBEMConn._shared_state
if options:
- proto = 'http'
- if options.secure:
- proto = 'https'
- url = '%s://%s' % (proto, options.host)
- self.conn = pywbem.WBEMConnection(
- url,
- (options.user, options.password),
+ creds = None
+ if options.user is not None:
+ creds = (options.user, options.password)
+ self.conn = pywbem.WBEMConnection(options.url, creds,
default_namespace = options.namespace)
@@ -92,9 +92,11 @@
self._conn = WBEMConn().conn
self._verbose = _globalVerbose
self._dbgPrint()
+ self._tmpdir = mkdtemp()
def tearDown(self):
unittest.TestCase.tearDown(self)
+ shutil.rmtree(self._tmpdir, ignore_errors=True)
def _omc_initdservice_test(self):
svcs = []
@@ -334,16 +336,105 @@
def test_logical_file(self):
'''OMC_LogicalFile'''
- try:
- #TODO Traverse a folder on filesystem and retrieve all of the
- #LinuxDataFiles
- #Get through GetInstance using keybindings since they are
- #non-enumerable
- #self._conn.GetInstance("OMC_LinuxdataFile")
- pass
- except pywbem.CIMError, arg:
- raise
+ inames = self._conn.EnumerateInstanceNames('OMC_LinuxDirectory')
+ inames.sort()
+ names = [x['Name'] for x in inames]
+ gnames = os.listdir('/')
+ isdir = lambda x: S_ISDIR(os.stat(x).st_mode)
+ gnames = ['/'+x for x in gnames]
+ gnames = [x for x in gnames if isdir(x)]
+ gnames.append('/')
+ gnames.sort()
+ self.assertEqual(gnames, names)
+
+ for sock in ['/var/run/tog-pegasus/cimxml.socket',
+ '/tmp/OW@LCL@APIIPC_72859_Xq47Bf_P9r761-5_J-7_Q']:
+ if os.path.exists(sock):
+ iname = pywbem.CIMInstanceName('OMC_LinuxSocketFile',
+ keybindings={'Name':sock})
+ sockinst = self._conn.GetInstance(iname)
+ self.assertEqual(sockinst.classname.lower(),
+ 'omc_linuxsocketfile')
+ self.assertEqual(sockinst['ElementName'],
+ os.path.basename(sock))
+ self.assertEqual(sockinst['CSName'], getfqdn())
+ # TODO check more stuff.
+ break
+ else:
+ self.fail('Failed to find a socket file to test.')
+
+ os.mkdir(self._tmpdir + '/dir')
+ fo = open(self._tmpdir + '/file', 'w')
+ fo.write('1234')
+ fo.close()
+ os.symlink('file', self._tmpdir + '/symlink')
+ iname = pywbem.CIMInstanceName('OMC_LinuxDirectory',
+ keybindings={'Name':self._tmpdir})
+ ccontents = self._conn.Associators(iname,
+ AssocClass='OMC_LinuxDirectoryContainsFile',
+ Role='GroupComponent',
+ ResultRole='PartComponent')
+ self.assertEqual(len(ccontents), 3)
+ ccontents = dict([(os.path.basename(x['Name']), x) for x in ccontents])
+ self.assertEqual(ccontents['file']['FileSize'], 4)
+ self.assertEqual(ccontents['file'].classname.lower(),
+ 'omc_linuxdatafile')
+ self.assertEqual(ccontents['dir'].classname.lower(),
+ 'omc_linuxdirectory')
+ self.assertEqual(ccontents['symlink'].classname.lower(),
+ 'omc_linuxsymboliclink')
+ self.assertEqual(ccontents['symlink']['TargetFile'], 'file')
+
+ parent = self._conn.Associators(ccontents['file'].path,
+ AssocClass='OMC_LinuxDirectoryContainsFile',
+ Role='PartComponent',
+ ResultRole='GroupComponent')
+ self.assertEquals(len(parent), 1)
+ parent = parent[0]
+ self.assertEquals(parent['Name'], self._tmpdir)
+ self.assertEquals(parent.classname.lower(), 'omc_linuxdirectory')
+
+ iname = pywbem.CIMInstanceName('OMC_LinuxDeviceFile',
+ keybindings={'Name':'/dev/null'})
+ null = self._conn.GetInstance(iname, LocalOnly=False)
+ self.assertEquals(null.classname.lower(), 'omc_linuxdevicefile')
+ self.assertEquals(null['DeviceId'], '259') # same on every system?
+ self.assertEquals(null['DeviceMajor'], '1')
+ self.assertEquals(null['DeviceMinor'], '3')
+ self.assertEquals(null['DeviceFileType'], 3)
+
+ os.chmod(self._tmpdir + '/file', 0700)
+
+ iname = pywbem.CIMInstanceName('OMC_LinuxFile',
+ keybindings={'LFName':self._tmpdir + '/file'})
+ lf = self._conn.GetInstance(iname, LocalOnly=False)
+ self.assertTrue(lf['UserReadable'])
+ self.assertTrue(lf['UserWritable'])
+ self.assertTrue(lf['UserExecutable'])
+ self.assertFalse(lf['WorldReadable'])
+ self.assertFalse(lf['WorldWritable'])
+ self.assertFalse(lf['WorldExecutable'])
+ self.assertFalse(lf['GroupReadable'])
+ self.assertFalse(lf['GroupWritable'])
+ self.assertFalse(lf['GroupExecutable'])
+
+ lf['GroupReadable'] = True
+ lf['GroupWritable'] = True
+ lf['GroupExecutable'] = True
+
+ self._conn.ModifyInstance(lf)
+ lf2 = self._conn.GetInstance(iname, LocalOnly=False)
+
+ self.assertEquals(lf, lf2)
+
+ st = os.stat(self._tmpdir + '/file')
+ self.assertTrue(st.st_mode & S_IRGRP)
+ self.assertTrue(st.st_mode & S_IWGRP)
+ self.assertTrue(st.st_mode & S_IXGRP)
+
+ # TODO test chmod/chown/delete
+
def test_operating_system(self):
'''OMC_OperatingSystem'''
if self._isSupportedAssn('OMC_OperatingSystem',
@@ -631,15 +722,13 @@
dest='dbglevel',
help='Indicate the level of debugging statements to display (default=2)',
default=2)
- parser.add_option('', '--host', default='localhost',
- help='Specify the hosting machine of the CIMOM (default=localhost)')
- parser.add_option('-s', '--secure', action='store_true', default=False,
- help='Use the HTTPS protocol. Default is HTTP')
+ parser.add_option('-u', '--url', default='https://localhost',
+ help='Specify the URL to the CIMOM')
parser.add_option('-n', '--namespace', default='root/cimv2',
help='Specify the namespace the test runs against (default=root/cimv2)')
- parser.add_option('', '--user', default='',
+ parser.add_option('', '--user', default=None,
help='Specify the user name used when connection to the CIMOM')
- parser.add_option('', '--password', default='',
+ parser.add_option('', '--password', default=None,
help='Specify the password for the user')
parser.add_option('--verbose', '', action='store_true', default=False,
help='Show verbose output')
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|