summaryrefslogtreecommitdiffstats
path: root/src/logicalfile
diff options
context:
space:
mode:
authorJan Synacek <jsynacek@redhat.com>2013-09-12 14:05:25 +0200
committerJan Synacek <jsynacek@redhat.com>2013-09-16 10:07:03 +0200
commit1575c34d31247d66bb5a6c2286a966e5fdf65a2e (patch)
treee53d8d64ba5b6f2c0832aebbb8fbe60a779ce8bf /src/logicalfile
parentc0f9fc31d2cbcb2131f73009c892f99b6e7ee9b8 (diff)
downloadopenlmi-providers-1575c34d31247d66bb5a6c2286a966e5fdf65a2e.tar.gz
openlmi-providers-1575c34d31247d66bb5a6c2286a966e5fdf65a2e.tar.xz
openlmi-providers-1575c34d31247d66bb5a6c2286a966e5fdf65a2e.zip
logicalfile: ignore some key properties
CIM_LogicalFile and CIM_UnixFile have some key properties that are not needed when calling GetInstance(). On Linux systems, all is needed to get information about a file is its path. Type of the filesystem that the file resides on and the file type itself are not needed. In fact, it's not desirable to require those when querying remote systems. Ignore FSCreationClassName, FSName, LFCreationClassName and CreationClassName. This commit reverts most of the functionality of commit 5c3e1a6203e495bec37acd8c3731ca41377beb94.
Diffstat (limited to 'src/logicalfile')
-rw-r--r--src/logicalfile/LMI_DirectoryContainsFileProvider.c4
-rw-r--r--src/logicalfile/LMI_FileIdentityProvider.c14
-rw-r--r--src/logicalfile/LMI_RootDirectoryProvider.c2
-rw-r--r--src/logicalfile/LMI_UnixFileProvider.c15
-rw-r--r--src/logicalfile/file.c92
-rw-r--r--src/logicalfile/file.h21
-rw-r--r--src/logicalfile/test/test_basic.py78
7 files changed, 51 insertions, 175 deletions
diff --git a/src/logicalfile/LMI_DirectoryContainsFileProvider.c b/src/logicalfile/LMI_DirectoryContainsFileProvider.c
index 753cb00..427c2a6 100644
--- a/src/logicalfile/LMI_DirectoryContainsFileProvider.c
+++ b/src/logicalfile/LMI_DirectoryContainsFileProvider.c
@@ -151,7 +151,7 @@ static CMPIStatus associators(
int group = -1;
int rgroup = -1;
- st = lmi_check_required(_cb, cop, LOGICALFILE);
+ st = lmi_check_required(_cb, cop);
if (st.rc != CMPI_RC_OK) {
return st;
}
@@ -277,7 +277,7 @@ static CMPIStatus references(
group = 0;
}
}
- st = lmi_check_required(_cb, cop, LOGICALFILE);
+ st = lmi_check_required(_cb, cop);
if (st.rc != CMPI_RC_OK) {
return st;
}
diff --git a/src/logicalfile/LMI_FileIdentityProvider.c b/src/logicalfile/LMI_FileIdentityProvider.c
index 7ada787..7720a75 100644
--- a/src/logicalfile/LMI_FileIdentityProvider.c
+++ b/src/logicalfile/LMI_FileIdentityProvider.c
@@ -76,7 +76,7 @@ static CMPIStatus associators(
if (CMClassPathIsA(_cb, cop, LMI_UnixFile_ClassName, &st)) {
/* got UnixFile - SameElement */
- st = lmi_check_required(_cb, cop, UNIXFILE);
+ st = lmi_check_required(_cb, cop);
if (st.rc != CMPI_RC_OK) {
return st;
}
@@ -97,12 +97,6 @@ static CMPIStatus associators(
CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name");
}
- /* TODO is this error necessary? */
- if (strcmp(fileclass, ccname) != 0) {
- CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND,
- "LMCreationClassName is not correct");
- }
-
CIM_LogicalFileRef cim_lfr;
CIM_LogicalFileRef_Init(&cim_lfr, _cb, ns);
fill_logicalfile(CIM_LogicalFileRef, &cim_lfr, path, fsname, ccname);
@@ -110,7 +104,7 @@ static CMPIStatus associators(
CMSetClassName(o, fileclass);
} else {
/* got LogicalFile - SystemElement */
- st = lmi_check_required(_cb, cop, LOGICALFILE);
+ st = lmi_check_required(_cb, cop);
if (st.rc != CMPI_RC_OK) {
return st;
}
@@ -186,7 +180,7 @@ static CMPIStatus references(
/* got UnixFile - SameElement */
LMI_FileIdentity_SetObjectPath_SameElement(&lmi_fi, cop);
- st = lmi_check_required(_cb, cop, UNIXFILE);
+ st = lmi_check_required(_cb, cop);
if (st.rc != CMPI_RC_OK) {
return st;
}
@@ -220,7 +214,7 @@ static CMPIStatus references(
/* got LogicalFile - SystemElement */
LMI_FileIdentity_SetObjectPath_SystemElement(&lmi_fi, cop);
- st = lmi_check_required(_cb, cop, LOGICALFILE);
+ st = lmi_check_required(_cb, cop);
if (st.rc != CMPI_RC_OK) {
return st;
}
diff --git a/src/logicalfile/LMI_RootDirectoryProvider.c b/src/logicalfile/LMI_RootDirectoryProvider.c
index 2be709f..0c3b23e 100644
--- a/src/logicalfile/LMI_RootDirectoryProvider.c
+++ b/src/logicalfile/LMI_RootDirectoryProvider.c
@@ -169,7 +169,7 @@ static CMPIStatus references(
if (strcmp(path, "/") != 0) {
CMReturn(CMPI_RC_OK);
}
- st = lmi_check_required(_cb, cop, LOGICALFILE);
+ st = lmi_check_required(_cb, cop);
if (st.rc != CMPI_RC_OK) {
return st;
}
diff --git a/src/logicalfile/LMI_UnixFileProvider.c b/src/logicalfile/LMI_UnixFileProvider.c
index 5da5bb0..6b3a45e 100644
--- a/src/logicalfile/LMI_UnixFileProvider.c
+++ b/src/logicalfile/LMI_UnixFileProvider.c
@@ -118,7 +118,7 @@ static CMPIStatus LMI_UnixFileGetInstance(
char aux[BUFLEN];
const char *path;
- st = lmi_check_required(_cb, cop, UNIXFILE);
+ st = lmi_check_required(_cb, cop);
if (st.rc != CMPI_RC_OK) {
return st;
}
@@ -130,6 +130,16 @@ static CMPIStatus LMI_UnixFileGetInstance(
snprintf(aux, BUFLEN, "Can't stat file: %s", path);
CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, aux);
}
+ /* set ignored stuff */
+ LMI_UnixFile_Set_FSCreationClassName(&lmi_file, FSCREATIONCLASSNAME);
+ char *fsname;
+ get_fsname_from_stat(&sb, &fsname);
+ LMI_UnixFile_Set_FSName(&lmi_file, fsname);
+ free(fsname);
+ get_class_from_stat(&sb, aux);
+ LMI_UnixFile_Set_LFCreationClassName(&lmi_file, aux);
+
+ /* set unix-specific stuff */
LMI_UnixFile_Set_Name(&lmi_file, path);
sprintf(aux, "%u", sb.st_uid);
LMI_UnixFile_Set_UserID(&lmi_file, aux);
@@ -248,3 +258,6 @@ KONKRET_REGISTRATION(
"LMI_UnixFile",
"instance method")
/* vi: set et: */
+/* Local Variables: */
+/* indent-tabs-mode: nil */
+/* End: */
diff --git a/src/logicalfile/file.c b/src/logicalfile/file.c
index ca0d9f4..e768ea0 100644
--- a/src/logicalfile/file.c
+++ b/src/logicalfile/file.c
@@ -21,111 +21,29 @@
CMPIStatus lmi_check_required(
const CMPIBroker *b,
- const CMPIObjectPath *o,
- const enum RequiredNames rn)
+ const CMPIObjectPath *o)
{
const char *prop;
const char *errmsg = NULL;
- char *path = NULL;
/* check computer system creation class name */
if (CMIsNullValue(CMGetKey(o, "CSCreationClassName", NULL))) {
- errmsg = "CSCreationClassName is empty";
- goto done;
+ CMReturnWithChars(b, CMPI_RC_ERR_FAILED, "CSCreationClassName is empty");
}
prop = get_string_property_from_op(o, "CSCreationClassName");
if (strcmp(prop, lmi_get_system_creation_class_name()) != 0) {
- errmsg = "Wrong CSCreationClassName";
- goto done;
+ CMReturnWithChars(b, CMPI_RC_ERR_FAILED, "Wrong CSCreationClassName");
}
/* check fqdn */
if (CMIsNullValue(CMGetKey(o, "CSName", NULL))) {
- errmsg = "CSName is empty";
- goto done;
+ CMReturnWithChars(b, CMPI_RC_ERR_FAILED, "CSName is empty");
}
prop = get_string_property_from_op(o, "CSName");
if (strcmp(prop, lmi_get_system_name()) != 0) {
- errmsg = "Wrong CSName";
- goto done;
+ CMReturnWithChars(b, CMPI_RC_ERR_FAILED, "Wrong CSName");
}
- if (rn == UNIXFILE) {
- /* check creation class name */
- char fileclass[BUFLEN];
- if (CMIsNullValue(CMGetKey(o, "LFCreationClassName", NULL))) {
- errmsg = "LFCreationClassName is empty";
- goto done;
- }
- prop = get_string_property_from_op(o, "LFCreationClassName");
- if (get_class_from_path(get_string_property_from_op(o, "LFName"), fileclass) != 0) {
- errmsg = "Can't get class from path";
- goto done;
- }
- if (strcmp(prop, fileclass) != 0) {
- errmsg = "LFCreationClassName doesn't match the file's type";
- goto done;
- }
- if (CMIsNullValue(CMGetKey(o, "LFName", NULL))) {
- errmsg = "LFName is empty";
- goto done;
- }
- if (get_fsname_from_path(get_string_property_from_op(o, "LFName"), &path) < 0) {
- errmsg = "Can't get FSName from path";
- goto done;
- }
- } else if (rn == LOGICALFILE) {
- /* check creation class name */
- if (CMIsNullValue(CMGetKey(o, "CreationClassName", NULL))) {
- errmsg = "CreationClassName is empty";
- goto done;
- }
- prop = get_string_property_from_op(o, "CreationClassName");
- if (!CMClassPathIsA(b, o, prop, NULL)) {
- errmsg = "CreationClassName and the class name don't match";
- goto done;
- }
- if (CMIsNullValue(CMGetKey(o, "Name", NULL))) {
- errmsg = "Name is empty";
- goto done;
- }
- if (get_fsname_from_path(get_string_property_from_op(o, "Name"), &path) < 0) {
- errmsg = "Can't get FSName from path";
- goto done;
- }
- } else {
- /* not possible! */
- assert(0);
- }
-
- /* check fs creation class name and fsname */
- if (CMIsNullValue(CMGetKey(o, "FSCreationClassName", NULL))) {
- errmsg = "FSCreationClassName is empty";
- goto done;
- }
- prop = get_string_property_from_op(o, "FSCreationClassName");
- if (strcmp(prop, FSCREATIONCLASSNAME) != 0) {
- errmsg = "Wrong FSCreationClassName";
- goto done;
- }
-
- if (CMIsNullValue(CMGetKey(o, "FSName", NULL))) {
- errmsg = "FSName is empty";
- goto done;
- }
- prop = get_string_property_from_op(o, "FSName");
- if (strcmp(prop, path) != 0) {
- errmsg = "Wrong FSName";
- goto done;
- }
-
-done:
- if (path) {
- free(path);
- }
- if (errmsg) {
- CMReturnWithChars(b, CMPI_RC_ERR_FAILED, errmsg);
- }
CMReturn(CMPI_RC_OK);
}
diff --git a/src/logicalfile/file.h b/src/logicalfile/file.h
index b7ecb53..938673c 100644
--- a/src/logicalfile/file.h
+++ b/src/logicalfile/file.h
@@ -74,12 +74,23 @@
#define fill_basic(cmpitype, path, stattype, error) \
struct stat sb; \
char errmsg[BUFLEN]; \
+ char aux[BUFLEN]; \
\
if (lstat((path), &sb) < 0 || !(sb.st_mode & S_IFMT & (stattype))) { \
snprintf(errmsg, BUFLEN, error, (path)); \
CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, errmsg); \
} \
\
+ get_class_from_stat(&sb, aux); \
+ LMI_##cmpitype##_Set_CreationClassName(&lmi_file, aux); \
+ LMI_##cmpitype##_Set_FSCreationClassName(&lmi_file, FSCREATIONCLASSNAME); \
+ char *fsname; \
+ if (get_fsname_from_stat(&sb, &fsname) < 0) { \
+ CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name"); \
+ } else { \
+ LMI_##cmpitype##_Set_FSName(&lmi_file, fsname); \
+ free(fsname); \
+ } \
LMI_##cmpitype##_Set_Readable(&lmi_file, sb_isreadable(sb)); \
LMI_##cmpitype##_Set_Writeable(&lmi_file, sb_iswriteable(sb)); \
LMI_##cmpitype##_Set_Executable(&lmi_file, sb_isexecutable(sb)); \
@@ -92,7 +103,7 @@
CMPIStatus st; \
\
LMI_##cmpitype##_InitFromObjectPath(&lmi_file, _cb, cop); \
- st = lmi_check_required(_cb, cop, LOGICALFILE); \
+ st = lmi_check_required(_cb, cop); \
if (st.rc != CMPI_RC_OK) { \
return st; \
} \
@@ -116,12 +127,7 @@
CMRelease(o); \
}
-enum RequiredNames {
- LOGICALFILE,
- UNIXFILE,
-};
-
-CMPIStatus lmi_check_required(const CMPIBroker *, const CMPIObjectPath *, const enum RequiredNames);
+CMPIStatus lmi_check_required(const CMPIBroker *, const CMPIObjectPath *);
void get_class_from_stat(const struct stat *, char *);
int get_class_from_path(const char *, char *);
int get_fsname_from_stat(const struct stat *, char **);
@@ -134,4 +140,5 @@ void _dump_objectpath(const CMPIObjectPath *);
/* vi: set et: */
/* Local Variables: */
/* indent-tabs-mode: nil */
+/* c-backslash-max-column: 78 */
/* End: */
diff --git a/src/logicalfile/test/test_basic.py b/src/logicalfile/test/test_basic.py
index fbcf6d5..4c210f9 100644
--- a/src/logicalfile/test/test_basic.py
+++ b/src/logicalfile/test/test_basic.py
@@ -428,73 +428,17 @@ class TestLogicalFile(LogicalFileTestBase):
prefix = ''
clsname = 'LMI_DataFile'
cop = pywbem.CIMInstanceName(classname=clsname,
- namespace='root/cimv2',
- keybindings={})
-
- prop = 'CSCreationClassName'
- self.assertRaisesRegexp(pywbem.CIMError,
- '%s is empty' % prop,
- self.wbemconnection.GetInstance,
- cop)
- cop.keybindings[prop] = 'BadClass'
- self.assertRaisesRegexp(pywbem.CIMError,
- 'Wrong %s' % prop,
- self.wbemconnection.GetInstance,
- cop)
- cop.keybindings[prop] = self.SYSTEM_CLASS_NAME
-
- prop = 'CSName'
- self.assertRaisesRegexp(pywbem.CIMError,
- '%s is empty' % prop,
- self.wbemconnection.GetInstance,
- cop)
- cop.keybindings[prop] = 'BadClass'
- self.assertRaisesRegexp(pywbem.CIMError,
- 'Wrong %s' % prop,
- self.wbemconnection.GetInstance,
- cop)
- cop.keybindings[prop] = self.SYSTEM_NAME
-
- prop = prefix + 'CreationClassName'
- self.assertRaisesRegexp(pywbem.CIMError,
- '%s is empty' % prop,
- self.wbemconnection.GetInstance,
- cop)
- cop.keybindings[prop] = testfile['class']
- prop = prefix + 'Name'
- cop.keybindings[prop] = self.files['dir']['path']
- if is_unixfile:
- self.assertRaisesRegexp(pywbem.CIMError,
- 'LFCreationClassName doesn\'t match',
- self.wbemconnection.GetInstance,
- cop)
- cop.keybindings[prop] = testfile['path']
-
- prop = 'FSCreationClassName'
- self.assertRaisesRegexp(pywbem.CIMError,
- '%s is empty' % prop,
- self.wbemconnection.GetInstance,
- cop)
- cop.keybindings[prop] = 'BadFS'
- self.assertRaisesRegexp(pywbem.CIMError,
- 'Wrong %s' % prop,
- self.wbemconnection.GetInstance,
- cop)
- cop.keybindings[prop] = 'LMI_LocalFileSystem'
-
- prop = 'FSName'
- self.assertRaisesRegexp(pywbem.CIMError,
- '%s is empty' % prop,
- self.wbemconnection.GetInstance,
- cop)
- cop.keybindings[prop] = 'BadFSName'
- self.assertRaisesRegexp(pywbem.CIMError,
- 'Wrong %s' % prop,
- self.wbemconnection.GetInstance,
- cop)
- cop.keybindings[prop] = self.fsname
-
- # finally, test GetInstance on the correct object path
+ namespace='root/cimv2',
+ keybindings={
+ 'CSCreationClassName':self.SYSTEM_CLASS_NAME,
+ 'CSName':self.SYSTEM_NAME,
+ 'FSCreationClassName':'LMI_LocalFileSystem',
+ 'FSName':self.fsname,
+ })
+
+ cop.keybindings[prefix+'CreationClassName'] = testfile['class']
+ cop.keybindings[prefix+'Name'] = testfile['path']
+
try:
self.wbemconnection.GetInstance(cop)
except pywbem.CIMError as pe: