diff options
author | Jan Synacek <jsynacek@redhat.com> | 2013-07-16 15:39:56 +0200 |
---|---|---|
committer | Jan Synacek <jsynacek@redhat.com> | 2013-07-17 09:19:40 +0200 |
commit | 5c3e1a6203e495bec37acd8c3731ca41377beb94 (patch) | |
tree | 733f0da458265d866c968ea4f646f33e3a81a08d /src | |
parent | 607c7feaa11f124b835860a36f9a6f40871ac939 (diff) | |
download | openlmi-providers-5c3e1a6203e495bec37acd8c3731ca41377beb94.tar.gz openlmi-providers-5c3e1a6203e495bec37acd8c3731ca41377beb94.tar.xz openlmi-providers-5c3e1a6203e495bec37acd8c3731ca41377beb94.zip |
LogicalFile: add property checks
Diffstat (limited to 'src')
-rw-r--r-- | src/logicalfile/file.c | 141 | ||||
-rw-r--r-- | src/logicalfile/file.h | 1 | ||||
-rw-r--r-- | src/logicalfile/test/test_base.py | 9 | ||||
-rw-r--r-- | src/logicalfile/test/test_basic.py | 10 |
4 files changed, 119 insertions, 42 deletions
diff --git a/src/logicalfile/file.c b/src/logicalfile/file.c index 64b7d52..e3be07f 100644 --- a/src/logicalfile/file.c +++ b/src/logicalfile/file.c @@ -19,52 +19,112 @@ */ #include "file.h" -static const char *LOGICALFILE_REQUIRED_NAMES[] = { - "CSCreationClassName", - "CSName", - "CreationClassName", - "FSCreationClassName", - "FSName", - "Name", - NULL -}; - -static const char *UNIXFILE_REQUIRED_NAMES[] = { - "CSCreationClassName", - "CSName", - "LFCreationClassName", - "FSCreationClassName", - "FSName", - "LFName", - NULL -}; - CMPIStatus lmi_check_required( const CMPIBroker *b, const CMPIObjectPath *o, const enum RequiredNames rn) { - const char **names; - - switch (rn) { - case LOGICALFILE: - names = LOGICALFILE_REQUIRED_NAMES; - break; - case UNIXFILE: - names = UNIXFILE_REQUIRED_NAMES; - break; - default: + 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; + } + prop = get_string_property_from_op(o, "CSCreationClassName"); + if (strcmp(prop, lmi_get_system_creation_class_name())) { + errmsg = "Wrong CSCreationClassName"; + goto done; + } + + /* check fqdn */ + if (CMIsNullValue(CMGetKey(o, "CSName", NULL))) { + errmsg = "CSName is empty"; + goto done; + } + prop = get_string_property_from_op(o, "CSName"); + if (strcmp(prop, lmi_get_system_name())) { + errmsg = "Wrong CSName"; + goto done; + } + + 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)) { + 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); - break; } - for (int i = 0; names[i]; i++) { - if (CMIsNullValue(CMGetKey(o, names[i], NULL))) { - char errmsg[BUFLEN]; - snprintf(errmsg, BUFLEN, "No '%s' specified", names[i]); - CMReturnWithChars(b, CMPI_RC_ERR_FAILED, errmsg); - } + /* 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)) { + 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)) { + errmsg = "Wrong FSName"; + goto done; + } + +done: + if (path) { + free(path); + } + if (errmsg) { + CMReturnWithChars(b, CMPI_RC_ERR_FAILED, errmsg); } CMReturn(CMPI_RC_OK); } @@ -137,6 +197,13 @@ int get_fsname_from_path(const char *path, char **fsname) return rc; } +const char *get_string_property_from_op(const CMPIObjectPath *o, const char *prop) +{ + CMPIData d; + d = CMGetKey(o, prop, NULL); + return KChars(d.value.string); +} + void _dump_objectpath(const CMPIObjectPath *o) { printf("OP: %s\n", CMGetCharsPtr(o->ft->toString(o, NULL), NULL)); diff --git a/src/logicalfile/file.h b/src/logicalfile/file.h index df906c2..b7f8c50 100644 --- a/src/logicalfile/file.h +++ b/src/logicalfile/file.h @@ -105,6 +105,7 @@ 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 **); int get_fsname_from_path(const char *, char **); +const char *get_string_property_from_op(const CMPIObjectPath *, const char *); void _dump_objectpath(const CMPIObjectPath *); diff --git a/src/logicalfile/test/test_base.py b/src/logicalfile/test/test_base.py index 6d2f2a1..5c71196 100644 --- a/src/logicalfile/test/test_base.py +++ b/src/logicalfile/test/test_base.py @@ -21,6 +21,7 @@ import os import socket import unittest import subprocess +import pyudev class LogicalFileTestBase(unittest.TestCase): """ @@ -43,6 +44,14 @@ class LogicalFileTestBase(unittest.TestCase): if rc != 0: cls.selinux_enabled = False except: cls.selinux_enabled = False + ctx = pyudev.Context() + sb = os.stat(os.path.realpath(cls.testdir + "/..")) + device = pyudev.Device.from_device_number(ctx, "block", sb.st_dev) + dev_name = device.get("ID_FS_UUID_ENC") + if not dev_name: + cls.fsname = "DEVICE=" + device.get("DEVNAME") + else: + cls.fsname = "UUID=" + dev_name def setUp(self): pass diff --git a/src/logicalfile/test/test_basic.py b/src/logicalfile/test/test_basic.py index f14de6e..4cc201b 100644 --- a/src/logicalfile/test/test_basic.py +++ b/src/logicalfile/test/test_basic.py @@ -71,7 +71,7 @@ class TestLogicalFile(LogicalFileTestBase): 'CSCreationClassName':self.SYSTEM_CLASS_NAME, 'CSName':self.SYSTEM_NAME, 'FSCreationClassName':'LMI_LocalFileSystem', - 'FSName':'NotImportant', + 'FSName':self.fsname, 'CreationClassName':'LMI_UnixDirectory', 'Name':self.testdir }) @@ -152,7 +152,7 @@ class TestLogicalFile(LogicalFileTestBase): 'CSCreationClassName':self.SYSTEM_CLASS_NAME, 'CSName':self.SYSTEM_NAME, 'FSCreationClassName':'LMI_LocalFileSystem', - 'FSName':'NotImportant', + 'FSName':self.fsname, 'CreationClassName':f['class'], 'Name':f['path'] }) @@ -179,7 +179,7 @@ class TestLogicalFile(LogicalFileTestBase): 'CSCreationClassName':self.SYSTEM_CLASS_NAME, 'CSName':self.SYSTEM_NAME, 'FSCreationClassName':'LMI_LocalFileSystem', - 'FSName':'NotImportant', + 'FSName':self.fsname, 'CreationClassName':f['class'], 'Name':f['path'] }) @@ -218,7 +218,7 @@ class TestLogicalFile(LogicalFileTestBase): 'CSCreationClassName':self.SYSTEM_CLASS_NAME, 'CSName':self.SYSTEM_NAME, 'FSCreationClassName':'LMI_LocalFileSystem', - 'FSName':'NotImportant', + 'FSName':self.fsname, 'LFCreationClassName':f['class'], 'LFName':f['path'] }) @@ -249,7 +249,7 @@ class TestLogicalFile(LogicalFileTestBase): 'CSCreationClassName':self.SYSTEM_CLASS_NAME, 'CSName':self.SYSTEM_NAME, 'FSCreationClassName':'LMI_LocalFileSystem', - 'FSName':'NotImportant', + 'FSName':self.fsname, 'LFCreationClassName':f['class'], 'LFName':f['path'] }) |