summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Safranek <jsafrane@redhat.com>2013-01-16 15:10:59 +0100
committerJan Safranek <jsafrane@redhat.com>2013-01-16 15:10:59 +0100
commit5422c49f7f1d99263c5fa522774b6a5fd33bd528 (patch)
tree03872e7b5385dd08226f798ed66818f2b7baea2a
parentfcfb2aa6c76759f19e859b00dc2cbcd9f12bde2c (diff)
parent8bdd20cd739de9399cc71d8f82eff55dc4c6d346 (diff)
downloadopenlmi-providers-5422c49f7f1d99263c5fa522774b6a5fd33bd528.tar.gz
openlmi-providers-5422c49f7f1d99263c5fa522774b6a5fd33bd528.tar.xz
openlmi-providers-5422c49f7f1d99263c5fa522774b6a5fd33bd528.zip
Merge branch 'master' of ssh://git.fedorahosted.org/git/openlmi-providers
-rw-r--r--CMakeLists.txt1
-rw-r--r--mof/LMI_Hardware.mof35
-rw-r--r--nosetests.cfg1
-rwxr-xr-xopenlmi-register-pegasus2
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/account/test/TestAccount.py100
-rw-r--r--src/account/test/TestGroup.py72
-rw-r--r--src/account/test/TestMemberOfGroup.py84
-rw-r--r--src/account/test/TestService.py114
-rw-r--r--src/account/test/__init__.py0
-rw-r--r--src/account/test/common.py46
-rwxr-xr-xsrc/account/test/localtest.sh1
-rw-r--r--src/account/test/methods.py80
-rw-r--r--src/hardware/CMakeLists.txt29
-rw-r--r--src/hardware/LMI_PCIDeviceProvider.c371
15 files changed, 939 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e44fd76..bf94319 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,6 +16,7 @@ option(WITH-FAN "Build fan provider" ON)
option(WITH-POWER "Build power provider" ON)
option(WITH-SERVICE "Build service provider" ON)
option(WITH-ACCOUNT "Build account provider" ON)
+option(WITH-HARDWARE "Build hardware provider" ON)
# Set path to custom cmake modules
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
diff --git a/mof/LMI_Hardware.mof b/mof/LMI_Hardware.mof
new file mode 100644
index 0000000..87d5741
--- /dev/null
+++ b/mof/LMI_Hardware.mof
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2013 Red Hat, Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Tomas Smetana <tsmetana@redhat.com>
+ */
+
+[ Provider("cmpi:cmpiLMI_PCIDevice") ]
+class LMI_PCIDevice: CIM_PCIDevice
+{
+ [ Description("Name of the subsystem") ]
+ string SubsystemName;
+
+ [ Description("Name of the subsystem vendor") ]
+ string SubsystemVendorName;
+
+ [ Description("Name of the device") ]
+ string PCIDeviceName;
+
+ [ Description("Name of the vendor") ]
+ string VendorName;
+};
diff --git a/nosetests.cfg b/nosetests.cfg
index 2ba1566..0eded79 100644
--- a/nosetests.cfg
+++ b/nosetests.cfg
@@ -3,4 +3,5 @@
exe=1
where=.
where=src/software/test
+where=src/account/test
diff --git a/openlmi-register-pegasus b/openlmi-register-pegasus
index 260093f..73b7b0c 100755
--- a/openlmi-register-pegasus
+++ b/openlmi-register-pegasus
@@ -46,7 +46,7 @@ def define_module(location):
Version = "0.0.1";
InterfaceType = "CMPI";
InterfaceVersion = "2.0.0";
- ModuleGroupName = "lmi-providers";
+ ModuleGroupName = "%(location)s";
};
""" % { 'location': location }
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ff3bf58..6d41f49 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -24,3 +24,7 @@ endif (WITH-SERVICE)
if (WITH-ACCOUNT)
add_subdirectory(account)
endif (WITH-ACCOUNT)
+
+if (WITH-HARDWARE)
+ add_subdirectory(hardware)
+endif (WITH-HARDWARE)
diff --git a/src/account/test/TestAccount.py b/src/account/test/TestAccount.py
new file mode 100644
index 0000000..7157b52
--- /dev/null
+++ b/src/account/test/TestAccount.py
@@ -0,0 +1,100 @@
+# -*- encoding: utf-8 -*-
+# Copyright (C) 2012 Red Hat, Inc. All rights reserved.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Authors: Roman Rakus <rrakus@redhat.com
+#
+
+from common import AccountBase
+from methods import *
+import subprocess
+
+class TestAccount(AccountBase):
+ """
+ Class for testing LMI_Account class
+ """
+ def test_account_properties(self):
+ """
+ Test if there are key and main properties in LMI_Account
+ """
+ slct = "select * from LMI_Account"
+ instances = self.wbemconnection.ExecQuery('WQL', slct)
+ self.assertTrue(len(instances) > 0)
+ # check if it provides key properties
+ for attr in ["CreationClassName", "Name", "SystemCreationClassName",
+ "SystemName"]:
+ self.assertIsNotNone(instances[0][attr])
+
+ # check if it provides other properties, which should be set
+ for attr in ["host", "UserID", "UserPassword", "UserPasswordEncoding"]:
+ self.assertIsNotNone(instances[0][attr])
+
+ def test_create_account(self):
+ """
+ Test to create user account
+ """
+ # make sure the account will not exist
+ clean_account(self.user_name)
+ computer_system = self.wbemconnection.ExecQuery('WQL',
+ 'select * from Linux_ComputerSystem')[0]
+ lams = self.wbemconnection.ExecQuery('WQL',
+ 'select * from LMI_AccountManagementService')[0]
+ self.wbemconnection.InvokeMethod("CreateAccount", lams.path,
+ Name=self.user_name, System=computer_system.path)
+ # The user now should be created, check it
+ subprocess.check_call(["id", self.user_name])
+ # now delete that user
+ clean_account(self.user_name)
+
+ def test_delete_account(self):
+ """
+ Test to delete account
+ """
+ # make sure the account will exist
+ create_account(self.user_name)
+ i = self.wbemconnection.ExecQuery('WQL',
+ 'select * from LMI_Account where Name = "%s"' % self.user_name)[0]
+ self.wbemconnection.DeleteInstance(i.path)
+ # check if it was really deleted
+ c = subprocess.Popen(["id", self.user_name])
+ c.communicate()
+ self.assertEqual(c.returncode, 1)
+ clean_account(self.user_name)
+
+ def test_modify_account(self):
+ """
+ Test several modifications
+ """
+ create_account(self.user_name)
+ i = self.wbemconnection.ExecQuery('WQL',
+ 'select * from LMI_Account where Name = "%s"' % self.user_name)[0]
+ # gecos
+ print i["ElementName"]
+ i["ElementName"] = "GECOS"
+ print i["ElementName"]
+ self.wbemconnection.ModifyInstance(i)
+ self.assertEqual(field_in_passwd(self.user_name, 4), "GECOS")
+ # login shell
+ i["LoginShell"] = "/modified"
+ self.wbemconnection.ModifyInstance(i)
+ self.assertEqual(field_in_passwd(self.user_name, 6), "/modified")
+ # password
+ i["UserPassword"][0] = '$6$9Ky8vI6f$ipRcdc7rgMrtDh.sWOaRSoBck2cLz4eUom8Eze.NaY2DoMmNimuFBrXpJjlPCjMoeFTYC.FdZwj488JZcohyw1'
+ self.wbemconnection.ModifyInstance(i)
+ self.assertEqual(field_in_shadow(self.user_name, 1),
+ '$6$9Ky8vI6f$ipRcdc7rgMrtDh.sWOaRSoBck2cLz4eUom8Eze.NaY2DoMmNimuFBrXpJjlPCjMoeFTYC.FdZwj488JZcohyw1')
+ clean_account(self.user_name)
+
diff --git a/src/account/test/TestGroup.py b/src/account/test/TestGroup.py
new file mode 100644
index 0000000..2cf5228
--- /dev/null
+++ b/src/account/test/TestGroup.py
@@ -0,0 +1,72 @@
+# -*- encoding: utf-8 -*-
+# Copyright (C) 2012 Red Hat, Inc. All rights reserved.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Authors: Roman Rakus <rrakus@redhat.com
+#
+
+from common import AccountBase
+from methods import *
+
+class TestGroup(AccountBase):
+ """
+ Class for testing LMI_Group class
+ """
+ def test_group_properties(self):
+ """
+ Test if there are key and main properties in LMI_Group
+ """
+ slct = "select * from LMI_Group"
+ instances = self.wbemconnection.ExecQuery('WQL', slct)
+ self.assertTrue(len(instances) > 0)
+ # check if it provides key properties
+ for attr in ["CreationClassName", "Name"]:
+ self.assertIsNotNone(instances[0][attr])
+
+ # check if it provides other properties, which should be set
+ for attr in ["ElementName", "InstanceID"]:
+ self.assertIsNotNone(instances[0][attr])
+
+ def test_create_group(self):
+ """
+ Test to create group
+ """
+ # make sure the group will not exist
+ clean_group(self.group_name)
+ computer_system = self.wbemconnection.ExecQuery('WQL',
+ 'select * from Linux_ComputerSystem')[0]
+ lams = self.wbemconnection.ExecQuery('WQL',
+ 'select * from LMI_AccountManagementService')[0]
+ self.wbemconnection.InvokeMethod("CreateGroup", lams.path,
+ Name=self.group_name, System=computer_system.path)
+ # The group now should be created, check it
+ self.assertEqual(field_in_group(self.group_name, 0), self.group_name)
+ # now delete that group
+ clean_group(self.group_name)
+
+ def test_delete_group(self):
+ """
+ Test to delete group
+ """
+ # make sure the group will exist
+ create_group(self.group_name)
+ i = self.wbemconnection.ExecQuery('WQL',
+ 'select * from LMI_Group where Name = "%s"' % self.group_name)[0]
+ self.wbemconnection.DeleteInstance(i.path)
+ # check if it was really deleted
+ self.assertIsNone(field_in_group(self.group_name, 0))
+ clean_group(self.group_name)
+
diff --git a/src/account/test/TestMemberOfGroup.py b/src/account/test/TestMemberOfGroup.py
new file mode 100644
index 0000000..19071ef
--- /dev/null
+++ b/src/account/test/TestMemberOfGroup.py
@@ -0,0 +1,84 @@
+# -*- encoding: utf-8 -*-
+# Copyright (C) 2012 Red Hat, Inc. All rights reserved.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Authors: Roman Rakus <rrakus@redhat.com
+#
+
+from common import AccountBase
+from methods import *
+import pywbem
+
+class TestMemberOfGroup(AccountBase):
+ """
+ Class for testing LMI_MemberOfGroup class
+ """
+ def test_add_user_to_group(self):
+ """
+ Test to add user to group
+ """
+ create_account(self.user_name)
+ create_group(self.group_name)
+ user = self.wbemconnection.ExecQuery('WQL',
+ 'select * from LMI_Account where Name = "%s"' %self.user_name)[0]
+ group = self.wbemconnection.ExecQuery('WQL',
+ 'select * from LMI_Group where Name = "%s"' %self.group_name)[0]
+ tocreate = pywbem.CIMInstance('LMI_MemberOfGroup',
+ {'Collection' : group.path,
+ 'Member' : user.path})
+ self.wbemconnection.CreateInstance(tocreate)
+ clean_account(self.user_name)
+ clean_group(self.group_name)
+
+ def test_remove_user_from_group(self):
+ """
+ Test remove user from group
+ """
+ # make sure the account will exist
+ create_account(self.user_name)
+ i = self.wbemconnection.ExecQuery('WQL',
+ 'select * from LMI_Account where Name = "%s"' % self.user_name)[0]
+ self.wbemconnection.DeleteInstance(i.path)
+ # check if it was really deleted
+ c = subprocess.Popen(["id", self.user_name])
+ c.communicate()
+ self.assertEqual(c.returncode, 1)
+ clean_account(self.user_name)
+
+ def test_user_in_groups(self):
+ """
+ Test correct list of groups for user
+ """
+ create_account(self.user_name)
+ create_group(self.group_name)
+ add_user_to_group(self.user_name, self.group_name)
+ user = self.wbemconnection.ExecQuery('WQL',
+ 'select * from LMI_Account where Name = "%s"' %self.user_name)[0]
+ ident = self.wbemconnection.ExecQuery('WQL',
+ 'select * from LMI_Identity where InstanceID = "LMI:UID:%s"' % user["UserID"])[0]
+ insts = self.wbemconnection.Associators(ident.path, AssocClass = 'LMI_MemberOfGroup')
+ self.assertEqual(len(insts), 2)
+ found_user = False
+ found_group = False
+ for inst in insts:
+ if inst["Name"] == self.user_name:
+ found_user = True
+ elif inst["Name"] == self.group_name:
+ found_group = True
+ self.assertTrue(found_user)
+ self.assertTrue(found_group)
+ clean_account(self.user_name)
+ clean_group(self.group_name)
diff --git a/src/account/test/TestService.py b/src/account/test/TestService.py
new file mode 100644
index 0000000..08a47ee
--- /dev/null
+++ b/src/account/test/TestService.py
@@ -0,0 +1,114 @@
+# -*- encoding: utf-8 -*-
+# Copyright (C) 2012 Red Hat, Inc. All rights reserved.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Authors: Roman Rakus <rrakus@redhat.com
+#
+
+from common import AccountBase
+from methods import *
+import pywbem
+
+class TestService(AccountBase):
+ """
+ Class for testing LMI_AccountManagementService
+ """
+
+ def test_create_account(self):
+ """
+ Test create account parameters
+ """
+ # make sure the account will not exist
+ clean_account(self.user_name)
+ computer_system = self.wbemconnection.ExecQuery('WQL',
+ 'select * from Linux_ComputerSystem')[0]
+ lams = self.wbemconnection.ExecQuery('WQL',
+ 'select * from LMI_AccountManagementService')[0]
+
+ # create account and test all parameters
+ shell = "testshell"
+ system_account = True
+ dont_create_home = True
+ dont_create_group = True
+ gid = 0
+ gecos = "test create account gecos"
+ home_dir = "/test/home"
+ password = '$6$9Ky8vI6f$ipRcdc7rgMrtDh.sWOaRSoBck2cLz4eUom8Eze.NaY2DoMmNimuFBrXpJjlPCjMoeFTYC.FdZwj488JZcohyw1'
+ uid = 777
+ (rc, out) = self.wbemconnection.InvokeMethod("CreateAccount", lams.path,
+ Name = self.user_name,
+ System = computer_system.path,
+ Shell = shell,
+ SystemAccount = system_account,
+ DontCreateHome = dont_create_home,
+ DontCreateGroup = dont_create_group,
+ GID = pywbem.Uint32(gid),
+ GECOS = gecos,
+ HomeDirectory = home_dir,
+ Password = password,
+ UID = pywbem.Uint32(uid))
+
+ acc = out["Account"]
+ idents = out["Identities"]
+
+ # check return values
+ # account
+ self.assertEqual(rc, 0)
+ self.assertEqual(acc["Name"], self.user_name)
+ # identities
+ for identity in idents:
+ if identity["InstanceID"].find("UID") != -1:
+ # user identity
+ self.assertEqual(identity["InstanceID"], "LMI:UID:%d" %uid)
+ else:
+ # group identity
+ self.assertEqual(identity["InstanceID"], "LMI:GID:%d" %gid)
+
+ # check with system info
+ self.assertEqual(field_in_passwd(self.user_name, 2), str(uid))
+ self.assertEqual(field_in_passwd(self.user_name, 3), str(gid))
+ self.assertEqual(field_in_passwd(self.user_name, 4), gecos)
+ self.assertEqual(field_in_passwd(self.user_name, 5), home_dir)
+ self.assertEqual(field_in_passwd(self.user_name, 6), shell)
+ self.assertEqual(field_in_shadow(self.user_name, 1), password)
+ clean_account(self.user_name)
+
+ def test_create_group(self):
+ """
+ Test create group parameters
+ """
+ clean_group(self.group_name)
+ computer_system = self.wbemconnection.ExecQuery('WQL',
+ 'select * from Linux_ComputerSystem')[0]
+ lams = self.wbemconnection.ExecQuery('WQL',
+ 'select * from LMI_AccountManagementService')[0]
+ system_account = True
+ gid = 666
+ (rc, out) = self.wbemconnection.InvokeMethod("CreateGroup", lams.path,
+ Name=self.group_name,
+ System=computer_system.path,
+ SystemAccount=system_account,
+ GID=pywbem.Uint32(gid))
+
+ group = out["Group"]
+ idents = out["Identities"]
+ self.assertEqual(rc, 0)
+ self.assertEqual(group["Name"], self.group_name)
+ for identity in idents:
+ self.assertEqual(identity["InstanceID"], "LMI:GID:%d" %gid)
+
+ self.assertEqual(field_in_group(self.group_name, 2), str(gid))
+ clean_group(self.group_name)
diff --git a/src/account/test/__init__.py b/src/account/test/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/account/test/__init__.py
diff --git a/src/account/test/common.py b/src/account/test/common.py
new file mode 100644
index 0000000..2ffbbcf
--- /dev/null
+++ b/src/account/test/common.py
@@ -0,0 +1,46 @@
+# -*- encoding: utf-8 -*-
+# Copyright (C) 2012 Red Hat, Inc. All rights reserved.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Authors: Roman Rakus <rrakus@redhat.com
+#
+
+import pywbem
+import os
+import unittest
+
+"""
+Base class for all tests
+"""
+
+
+
+class AccountBase(unittest.TestCase):
+ """
+ Base class for all LMI Account tests
+ """
+ def setUp(self):
+ """
+ Connnect to server
+ """
+ self.url = os.environ.get("LMI_CIMOM_URL", "https://localhost:5989")
+ self.username = os.environ.get("LMI_CIMOM_USERNAME", "root")
+ self.password = os.environ.get("LMI_CIMOM_PASSWORD", "")
+ self.user_name = os.environ.get("LMI_ACCOUNT_USER")
+ self.group_name = os.environ.get("LMI_ACCOUNT_GROUP")
+ self.wbemconnection = pywbem.WBEMConnection(self.url,
+ (self.username, self.password))
+
diff --git a/src/account/test/localtest.sh b/src/account/test/localtest.sh
new file mode 100755
index 0000000..f8d1b59
--- /dev/null
+++ b/src/account/test/localtest.sh
@@ -0,0 +1 @@
+LMI_CIMOM_PASSWORD="test" LMI_CIMOM_USERNAME="pegasus" LMI_ACCOUNT_USER="account_test_user" LMI_ACCOUNT_GROUP="account_test_group" nosetests -v
diff --git a/src/account/test/methods.py b/src/account/test/methods.py
new file mode 100644
index 0000000..b40859f
--- /dev/null
+++ b/src/account/test/methods.py
@@ -0,0 +1,80 @@
+# -*- encoding: utf-8 -*-
+# Copyright (C) 2012 Red Hat, Inc. All rights reserved.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Authors: Roman Rakus <rrakus@redhat.com
+#
+
+import subprocess
+
+def field_in_passwd(username, number):
+ """
+ Return numberth field in /etc/passwd for given username
+ """
+ for line in open("/etc/passwd").readlines():
+ if line.startswith(username):
+ return line.split(":")[number].strip()
+
+def field_in_shadow(username, number):
+ """
+ Return numberth field in /etc/shadow for given username
+ """
+ for line in open("/etc/shadow").readlines():
+ if line.startswith(username):
+ return line.split(":")[number].strip()
+
+def field_in_group(groupname, number):
+ """
+ Return numberth field in /etc/group for given groupname
+ """
+ for line in open("/etc/group").readlines():
+ if line.startswith(groupname):
+ return line.split(":")[number].strip()
+
+def clean_account(user_name):
+ """
+ Force to delete testing account and remove home dir
+ """
+ subprocess.call(["userdel", "-fr", user_name])
+ # groups should be expicitely deleted
+ subprocess.call(["groupdel", user_name])
+ subprocess.call(["rm", "-fr", "/home/%s" %user_name])
+
+def add_user_to_group(user_name, group_name):
+ """
+ Will add user to group
+ """
+ subprocess.call(["usermod", "-a", "-G", group_name, user_name])
+
+def create_account(user_name):
+ """
+ Force to create account; run clean_account before creation
+ """
+ clean_account(user_name)
+ subprocess.call(["useradd", user_name])
+
+def clean_group(group_name):
+ """
+ Force to delete testing group
+ """
+ subprocess.call(["groupdel", group_name])
+
+def create_group(group_name):
+ """
+ Force to create group
+ """
+ clean_group(group_name)
+ subprocess.call(["groupadd", group_name])
diff --git a/src/hardware/CMakeLists.txt b/src/hardware/CMakeLists.txt
new file mode 100644
index 0000000..27e8df2
--- /dev/null
+++ b/src/hardware/CMakeLists.txt
@@ -0,0 +1,29 @@
+
+set(PROVIDER_NAME Hardware)
+set(LIBRARY_NAME cmpiLMI_${PROVIDER_NAME})
+set(MOF LMI_Hardware.mof)
+
+#set(provider_SRCS
+# util/serviceutil.c
+#)
+
+konkretcmpi_generate(${MOF}
+ CIM_PROVIDERS
+ CIM_HEADERS
+)
+
+add_library(${LIBRARY_NAME} SHARED
+ ${provider_SRCS}
+ ${CIM_PROVIDERS}
+ ${CIM_HEADERS}
+)
+
+pkg_check_modules(LIBPCI REQUIRED libpci)
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMPI_INCLUDE_DIR} ${LIBPCI_INCLUDE_DIR})
+target_link_libraries(${LIBRARY_NAME} openlmicommon ${KONKRETCMPI_LIBRARIES} ${LIBPCI_LIBRARIES})
+
+# Create registration file
+cim_registration(${PROVIDER_NAME} ${LIBRARY_NAME} ${MOF} share/openlmi-providers)
+
+install(TARGETS ${LIBRARY_NAME} DESTINATION lib${LIB_SUFFIX}/cmpi)
diff --git a/src/hardware/LMI_PCIDeviceProvider.c b/src/hardware/LMI_PCIDeviceProvider.c
new file mode 100644
index 0000000..e879484
--- /dev/null
+++ b/src/hardware/LMI_PCIDeviceProvider.c
@@ -0,0 +1,371 @@
+/*
+ * Copyright (C) 2013 Red Hat, Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Tomas Smetana <tsmetana@redhat.com>
+ *
+ */
+#include <konkret/konkret.h>
+#include <pci/pci.h>
+
+#include "globals.h"
+#include "LMI_PCIDevice.h"
+
+static const CMPIBroker* _cb = NULL;
+
+static void get_subid(struct pci_dev *d, u16 *subvp, u16 *subdp)
+{
+ u8 htype = pci_read_byte(d, PCI_HEADER_TYPE) & 0x7f;
+
+ if (htype == PCI_HEADER_TYPE_NORMAL) {
+ *subvp = pci_read_word(d, PCI_SUBSYSTEM_VENDOR_ID);
+ *subdp = pci_read_word(d, PCI_SUBSYSTEM_ID);
+ } else if (htype == PCI_HEADER_TYPE_CARDBUS) {
+ *subvp = pci_read_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
+ *subdp = pci_read_word(d, PCI_CB_SUBSYSTEM_ID);
+ } else
+ *subvp = *subdp = 0xffff;
+}
+
+static void LMI_PCIDeviceInitialize()
+{
+}
+
+static CMPIStatus LMI_PCIDeviceCleanup(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_PCIDeviceEnumInstanceNames(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ return KDefaultEnumerateInstanceNames(_cb, mi, cc, cr, cop);
+}
+
+#define NAME_BUF_SIZE 128
+#define PCI_DEVID_STR_SIZE 9
+static CMPIStatus LMI_PCIDeviceEnumInstances(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ struct pci_access *acc;
+ struct pci_dev *dev;
+ struct pci_cap *cap;
+ int i;
+ u16 subid, svid;
+ char vendor_buf[NAME_BUF_SIZE], *vendor_name;
+ char device_buf[NAME_BUF_SIZE], *device_name;
+ char subsys_buf[NAME_BUF_SIZE], *subsys_name;
+ char svendor_buf[NAME_BUF_SIZE], *svendor_name;
+ char device_id_str[PCI_DEVID_STR_SIZE];
+ LMI_PCIDevice lmi_dev;
+ const char *ns = KNameSpace(cop);
+
+ if (!(acc = pci_alloc()))
+ KReturn2(_cb, ERR_FAILED, "Error accessing the PCI bus");
+ pci_init(acc);
+ pci_scan_bus(acc);
+
+ for (dev = acc->devices; dev; dev = dev->next) {
+ pci_fill_info(dev,
+ PCI_FILL_IDENT
+ | PCI_FILL_IRQ
+ | PCI_FILL_BASES
+ | PCI_FILL_ROM_BASE
+ | PCI_FILL_CLASS
+ | PCI_FILL_CAPS);
+
+ vendor_name = pci_lookup_name(acc, vendor_buf, NAME_BUF_SIZE,
+ PCI_LOOKUP_VENDOR, dev->vendor_id);
+ device_name = pci_lookup_name(acc, device_buf, NAME_BUF_SIZE,
+ PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id);
+ get_subid(dev, &svid, &subid);
+ subsys_name = pci_lookup_name(acc, subsys_buf, NAME_BUF_SIZE,
+ PCI_LOOKUP_DEVICE | PCI_LOOKUP_SUBSYSTEM,
+ dev->vendor_id, dev->device_id, svid, subid);
+ svendor_name = pci_lookup_name(acc, svendor_buf, NAME_BUF_SIZE,
+ PCI_LOOKUP_VENDOR | PCI_LOOKUP_SUBSYSTEM, svid);
+
+ LMI_PCIDevice_Init(&lmi_dev, _cb, ns);
+ LMI_PCIDevice_Set_CreationClassName(&lmi_dev, "LMI_PCIDevice");
+ LMI_PCIDevice_Set_SystemCreationClassName(&lmi_dev,
+ get_system_creation_class_name());
+ LMI_PCIDevice_Set_SystemName(&lmi_dev, get_system_name());
+ snprintf((char *)&device_id_str, PCI_DEVID_STR_SIZE, "%d:%d.%d",
+ dev->bus, dev->dev, dev->func);
+ LMI_PCIDevice_Set_DeviceID(&lmi_dev, device_id_str);
+ LMI_PCIDevice_Set_BusNumber(&lmi_dev, dev->bus);
+ LMI_PCIDevice_Set_DeviceNumber(&lmi_dev, dev->dev);
+ LMI_PCIDevice_Set_FunctionNumber(&lmi_dev, dev->func);
+ LMI_PCIDevice_Set_VendorID(&lmi_dev, dev->vendor_id);
+ LMI_PCIDevice_Set_PCIDeviceID(&lmi_dev, dev->device_id);
+ LMI_PCIDevice_Set_PCIDeviceName(&lmi_dev, device_name);
+ LMI_PCIDevice_Set_SubsystemID(&lmi_dev, subid);
+ LMI_PCIDevice_Set_SubsystemVendorID(&lmi_dev, svid);
+ /* Throw away the lower 8 bits denoting the subclass */
+ LMI_PCIDevice_Set_ClassCode(&lmi_dev, ((dev->device_class) >> 8));
+ if (dev->rom_base_addr)
+ LMI_PCIDevice_Set_ExpansionROMBaseAddress(&lmi_dev,
+ dev->rom_base_addr);
+ if (vendor_name)
+ LMI_PCIDevice_Set_VendorName(&lmi_dev, vendor_name);
+ if (subsys_name)
+ LMI_PCIDevice_Set_SubsystemName(&lmi_dev, subsys_name);
+ if (svendor_name)
+ LMI_PCIDevice_Set_SubsystemVendorName(&lmi_dev, svendor_name);
+ for (i = 0; i < 6; i++)
+ if (dev->base_addr[i]) {
+#ifdef PCI_HAVE_64BIT_ADDRESS
+ LMI_PCIDevice_Set_BaseAddress64(&lmi_dev, i, dev->base_addr[i]);
+#else
+ LMI_PCIDevice_Set_BaseAddress(&lmi_dev, i, dev->base_addr[i]);
+#endif
+ }
+ for (cap = dev->first_cap, i = 0; cap; cap = cap->next, i++) {
+ LMI_PCIDevice_Set_Capabilities(&lmi_dev, i, cap->type);
+ }
+ KReturnInstance(cr, lmi_dev);
+ }
+
+ pci_cleanup(acc);
+
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_PCIDeviceGetInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ return KDefaultGetInstance(
+ _cb, mi, cc, cr, cop, properties);
+}
+
+static CMPIStatus LMI_PCIDeviceCreateInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_PCIDeviceModifyInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci,
+ const char** properties)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_PCIDeviceDeleteInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_PCIDeviceExecQuery(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* lang,
+ const char* query)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+CMInstanceMIStub(
+ LMI_PCIDevice,
+ LMI_PCIDevice,
+ _cb,
+ LMI_PCIDeviceInitialize())
+
+static CMPIStatus LMI_PCIDeviceMethodCleanup(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_PCIDeviceInvokeMethod(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* meth,
+ const CMPIArgs* in,
+ CMPIArgs* out)
+{
+ return LMI_PCIDevice_DispatchMethod(
+ _cb, mi, cc, cr, cop, meth, in, out);
+}
+
+CMMethodMIStub(
+ LMI_PCIDevice,
+ LMI_PCIDevice,
+ _cb,
+ LMI_PCIDeviceInitialize())
+
+KUint32 LMI_PCIDevice_RequestStateChange(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PCIDeviceRef* self,
+ const KUint16* RequestedState,
+ KRef* Job,
+ const KDateTime* TimeoutPeriod,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PCIDevice_SetPowerState(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PCIDeviceRef* self,
+ const KUint16* PowerState,
+ const KDateTime* Time,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PCIDevice_Reset(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PCIDeviceRef* self,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PCIDevice_EnableDevice(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PCIDeviceRef* self,
+ const KBoolean* Enabled,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PCIDevice_OnlineDevice(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PCIDeviceRef* self,
+ const KBoolean* Online,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PCIDevice_QuiesceDevice(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PCIDeviceRef* self,
+ const KBoolean* Quiesce,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PCIDevice_SaveProperties(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PCIDeviceRef* self,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PCIDevice_RestoreProperties(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PCIDeviceRef* self,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint8 LMI_PCIDevice_BISTExecution(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PCIDeviceRef* self,
+ CMPIStatus* status)
+{
+ KUint8 result = KUINT8_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KONKRET_REGISTRATION(
+ "root/cimv2",
+ "LMI_PCIDevice",
+ "LMI_PCIDevice",
+ "instance method")