summaryrefslogtreecommitdiffstats
path: root/src/account
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@redhat.com>2013-12-16 14:24:22 +0100
committerTomas Bzatek <tbzatek@redhat.com>2014-01-03 13:34:47 +0100
commit55c5277e039a34294d1969d0ac5da867e3cb2d87 (patch)
treedc68b92be018c241d63a978705730799199dfcec /src/account
parent6c56489a82e34a07089da832fb6e71ff69262177 (diff)
downloadopenlmi-providers-55c5277e039a34294d1969d0ac5da867e3cb2d87.tar.gz
openlmi-providers-55c5277e039a34294d1969d0ac5da867e3cb2d87.tar.xz
openlmi-providers-55c5277e039a34294d1969d0ac5da867e3cb2d87.zip
account: Port tests to lmishell base
Diffstat (limited to 'src/account')
-rw-r--r--src/account/test/TestAccount.py64
-rw-r--r--src/account/test/TestGroup.py42
-rw-r--r--src/account/test/TestIndications.py8
-rw-r--r--src/account/test/TestMemberOfGroup.py52
-rw-r--r--src/account/test/TestService.py64
-rw-r--r--src/account/test/common.py8
6 files changed, 126 insertions, 112 deletions
diff --git a/src/account/test/TestAccount.py b/src/account/test/TestAccount.py
index a66ef45..ecf8930 100644
--- a/src/account/test/TestAccount.py
+++ b/src/account/test/TestAccount.py
@@ -20,27 +20,33 @@
from common import AccountBase
from methods import *
+from lmi.shell import LMIInstance
import subprocess
class TestAccount(AccountBase):
"""
Class for testing LMI_Account class
"""
+
+ CLASS_NAME = "LMI_Account"
+
+ def tearDown(self):
+ clean_account(self.user_name)
+
def test_account_properties(self):
"""
Account: 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)
+ inst = self.cim_class.first_instance()
+ self.assertIsInstance(inst, LMIInstance)
# check if it provides key properties
- for attr in ["CreationClassName", "Name", "SystemCreationClassName",
- "SystemName"]:
- self.assertIsNotNone(instances[0][attr])
+ for attr in ['CreationClassName', 'Name', 'SystemCreationClassName',
+ 'SystemName']:
+ self.assertIsNotNone(inst.properties_dict()[attr])
# check if it provides other properties, which should be set
- for attr in ["host", "UserID", "UserPassword", "UserPasswordEncoding"]:
- self.assertIsNotNone(instances[0][attr])
+ for attr in ['host', 'UserID', 'UserPassword', 'UserPasswordEncoding']:
+ self.assertIsNotNone(inst.properties_dict()[attr])
def test_create_account(self):
"""
@@ -48,16 +54,13 @@ class TestAccount(AccountBase):
"""
# make sure the account will not exist
clean_account(self.user_name)
- computer_system = self.wbemconnection.ExecQuery('WQL',
- 'select * from %s' % self.system_cs_name)[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)
+ lams = self.ns.LMI_AccountManagementService.first_instance()
+ self.assertIsInstance(lams, LMIInstance)
+ (retval, rparam, errorstr) = lams.CreateAccount({'Name': self.user_name,
+ 'System': self.system_iname})
+ self.assertEqual(retval, 0)
# The user now should be created, check it
self.assertTrue(user_exists(self.user_name))
- # now delete that user
- clean_account(self.user_name)
def test_delete_account(self):
"""
@@ -65,32 +68,33 @@ class TestAccount(AccountBase):
"""
# 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)
+ inst = self.cim_class.first_instance({"Name": self.user_name})
+ self.assertIsInstance(inst, LMIInstance)
+ r = inst.delete()
+ self.assertTrue(r)
# check if it was really deleted
self.assertFalse(user_exists(self.user_name))
- clean_account(self.user_name)
def test_modify_account(self):
"""
Account: Test several modifications
"""
create_account(self.user_name)
- i = self.wbemconnection.ExecQuery('WQL',
- 'select * from LMI_Account where Name = "%s"' % self.user_name)[0]
+ inst = self.cim_class.first_instance({"Name": self.user_name})
+ self.assertIsInstance(inst, LMIInstance)
# gecos
- i["ElementName"] = "GECOS"
- self.wbemconnection.ModifyInstance(i)
+ inst.ElementName = "GECOS"
+ (retval, rparam, errorstr) = inst.push()
+ self.assertEqual(retval, 0)
self.assertEqual(field_in_passwd(self.user_name, 4), "GECOS")
# login shell
- i["LoginShell"] = "/modified"
- self.wbemconnection.ModifyInstance(i)
+ inst.LoginShell = "/modified"
+ (retval, rparam, errorstr) = inst.push()
+ self.assertEqual(retval, 0)
self.assertEqual(field_in_passwd(self.user_name, 6), "/modified")
# password
- i["UserPassword"][0] = '$6$9Ky8vI6f$ipRcdc7rgMrtDh.sWOaRSoBck2cLz4eUom8Eze.NaY2DoMmNimuFBrXpJjlPCjMoeFTYC.FdZwj488JZcohyw1'
- self.wbemconnection.ModifyInstance(i)
+ inst.UserPassword = ['$6$9Ky8vI6f$ipRcdc7rgMrtDh.sWOaRSoBck2cLz4eUom8Eze.NaY2DoMmNimuFBrXpJjlPCjMoeFTYC.FdZwj488JZcohyw1']
+ (retval, rparam, errorstr) = inst.push()
+ self.assertEqual(retval, 0)
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
index d0bec65..4734a88 100644
--- a/src/account/test/TestGroup.py
+++ b/src/account/test/TestGroup.py
@@ -20,25 +20,31 @@
from common import AccountBase
from methods import *
+from lmi.shell import LMIInstance
class TestGroup(AccountBase):
"""
Class for testing LMI_Group class
"""
+
+ CLASS_NAME = "LMI_Group"
+
+ def tearDown(self):
+ clean_group(self.group_name)
+
def test_group_properties(self):
"""
Account: 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)
+ inst = self.cim_class.first_instance()
+ self.assertIsInstance(inst, LMIInstance)
# check if it provides key properties
- for attr in ["CreationClassName", "Name"]:
- self.assertIsNotNone(instances[0][attr])
+ for attr in ['CreationClassName', 'Name']:
+ self.assertIsNotNone(inst.properties_dict()[attr])
# check if it provides other properties, which should be set
- for attr in ["ElementName", "InstanceID"]:
- self.assertIsNotNone(instances[0][attr])
+ for attr in ['ElementName', 'InstanceID']:
+ self.assertIsNotNone(inst.properties_dict()[attr])
def test_create_group(self):
"""
@@ -46,16 +52,13 @@ class TestGroup(AccountBase):
"""
# make sure the group will not exist
clean_group(self.group_name)
- computer_system = self.wbemconnection.ExecQuery('WQL',
- 'select * from %s' % self.system_cs_name)[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)
+ lams = self.ns.LMI_AccountManagementService.first_instance()
+ self.assertIsInstance(lams, LMIInstance)
+ (retval, rparam, errorstr) = lams.CreateGroup({'Name': self.group_name,
+ 'System': self.system_iname})
+ self.assertEqual(retval, 0)
# 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):
"""
@@ -63,10 +66,9 @@ class TestGroup(AccountBase):
"""
# 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)
+ inst = self.cim_class.first_instance({"Name": self.group_name})
+ self.assertIsInstance(inst, LMIInstance)
+ r = inst.delete()
+ self.assertTrue(r)
# 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/TestIndications.py b/src/account/test/TestIndications.py
index 45962ca..a3f3820 100644
--- a/src/account/test/TestIndications.py
+++ b/src/account/test/TestIndications.py
@@ -18,8 +18,8 @@
#
from common import AccountBase
-import time
from methods import *
+import time
class TestIndications(AccountBase):
"""
@@ -34,7 +34,7 @@ class TestIndications(AccountBase):
filter_name = "test_good_filter_%d" % (time.time() * 1000000)
sub = self.subscribe(filter_name, "select * from LMI_AccountInstanceCreationIndication where SourceInstance isa LMI_Account")
self.assertIsNotNone(sub)
- self.unsubscribe(filter_name);
+ self.unsubscribe(sub);
def test_check_bad_filter(self):
"""
@@ -55,6 +55,7 @@ class TestIndications(AccountBase):
self.assertIn("SourceInstance", indication.keys())
self.assertTrue(indication["SourceInstance"] is not None)
self.assertEqual(indication["SourceInstance"]["Name"], self.group_name)
+ self.unsubscribe(sub);
def test_group_creation_indication(self):
"""
@@ -70,6 +71,7 @@ class TestIndications(AccountBase):
self.assertTrue(indication["SourceInstance"] is not None)
self.assertEqual(indication["SourceInstance"]["Name"], self.group_name)
clean_group(self.group_name)
+ self.unsubscribe(sub);
def test_account_deletion_indication(self):
"""
@@ -84,6 +86,7 @@ class TestIndications(AccountBase):
self.assertIn("SourceInstance", indication.keys())
self.assertTrue(indication["SourceInstance"] is not None)
self.assertEqual(indication["SourceInstance"]["Name"], self.user_name)
+ self.unsubscribe(sub);
def test_account_creation_indication(self):
"""
@@ -99,4 +102,5 @@ class TestIndications(AccountBase):
self.assertTrue(indication["SourceInstance"] is not None)
self.assertEqual(indication["SourceInstance"]["Name"], self.user_name)
clean_account(self.user_name)
+ self.unsubscribe(sub);
diff --git a/src/account/test/TestMemberOfGroup.py b/src/account/test/TestMemberOfGroup.py
index 211244e..d44ca5a 100644
--- a/src/account/test/TestMemberOfGroup.py
+++ b/src/account/test/TestMemberOfGroup.py
@@ -20,28 +20,34 @@
from common import AccountBase
from methods import *
-import pywbem
+from lmi.shell import LMIInstance
+from lmi.shell import LMIInstanceName
class TestMemberOfGroup(AccountBase):
"""
Class for testing LMI_MemberOfGroup class
"""
+
+ def tearDown(self):
+ clean_account(self.user_name)
+ clean_group(self.group_name)
+
def test_add_user_to_group(self):
"""
Account: 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)
+ user = self.ns.LMI_Account.first_instance({"Name": self.user_name})
+ group = self.ns.LMI_Group.first_instance_name({"Name": self.group_name})
+ self.assertIsInstance(user, LMIInstance)
+ self.assertIsInstance(group, LMIInstanceName)
+ identity = user.first_associator_name(ResultClass = 'LMI_Identity')
+ self.assertIsInstance(identity, LMIInstanceName)
+ tocreate = self.ns.LMI_MemberOfGroup.create_instance(
+ { 'Collection' : group,
+ 'Member' : identity })
+ self.assertIsInstance(tocreate, LMIInstance)
def test_remove_user_from_group(self):
"""
@@ -49,12 +55,12 @@ class TestMemberOfGroup(AccountBase):
"""
# 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)
+ inst = self.ns.LMI_Account.first_instance({"Name": self.user_name})
+ self.assertIsInstance(inst, LMIInstance)
+ r = inst.delete()
+ self.assertTrue(r)
# check if it was really deleted
self.assertFalse(user_exists(self.user_name))
- clean_account(self.user_name)
def test_user_in_groups(self):
"""
@@ -63,20 +69,18 @@ class TestMemberOfGroup(AccountBase):
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')
+ user = self.ns.LMI_Account.first_instance({"Name": self.user_name})
+ self.assertIsInstance(user, LMIInstance)
+ ident = self.ns.LMI_Identity.first_instance({"InstanceID": "LMI:UID:%s" % user.UserID})
+ self.assertIsInstance(ident, LMIInstance)
+ insts = ident.associators(AssocClass = 'LMI_MemberOfGroup')
self.assertEqual(len(insts), 2)
found_user = False
found_group = False
for inst in insts:
- if inst["Name"] == self.user_name:
+ if inst.Name == self.user_name:
found_user = True
- elif inst["Name"] == self.group_name:
+ 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
index 08c7cc1..e27f7b6 100644
--- a/src/account/test/TestService.py
+++ b/src/account/test/TestService.py
@@ -20,23 +20,24 @@
from common import AccountBase
from methods import *
-import pywbem
+from lmi.shell import LMIInstance
+from lmi.shell import LMIInstanceName
class TestService(AccountBase):
"""
Class for testing LMI_AccountManagementService
"""
+ CLASS_NAME = "LMI_AccountManagementService"
+
def test_create_account(self):
"""
Account: Test create account parameters
"""
# make sure the account will not exist
clean_account(self.user_name)
- computer_system = self.wbemconnection.ExecQuery('WQL',
- 'select * from %s' % self.system_cs_name)[0]
- lams = self.wbemconnection.ExecQuery('WQL',
- 'select * from LMI_AccountManagementService')[0]
+ lams = self.cim_class.first_instance()
+ self.assertIsInstance(lams, LMIInstance)
# create account and test all parameters
shell = "testshell"
@@ -48,34 +49,33 @@ class TestService(AccountBase):
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))
-
+ (rc, out, errorstr) = lams.CreateAccount({
+ 'Name': self.user_name,
+ 'System': self.system_iname,
+ 'Shell': shell,
+ 'SystemAccount': system_account,
+ 'DontCreateHome': dont_create_home,
+ 'DontCreateGroup': dont_create_group,
+ 'GID': gid,
+ 'GECOS': gecos,
+ 'HomeDirectory': home_dir,
+ 'Password': password,
+ 'UID': uid})
acc = out["Account"]
idents = out["Identities"]
# check return values
# account
self.assertEqual(rc, 0)
- self.assertEqual(acc["Name"], self.user_name)
+ self.assertEqual(acc.Name, self.user_name)
# identities
for identity in idents:
- if identity["InstanceID"].find("UID") != -1:
+ if identity.InstanceID.find("UID") != -1:
# user identity
- self.assertEqual(identity["InstanceID"], "LMI:UID:%d" %uid)
+ self.assertEqual(identity.InstanceID, "LMI:UID:%d" %uid)
else:
# group identity
- self.assertEqual(identity["InstanceID"], "LMI:GID:%d" %gid)
+ self.assertEqual(identity.InstanceID, "LMI:GID:%d" %gid)
# check with system info
self.assertEqual(field_in_passwd(self.user_name, 2), str(uid))
@@ -91,24 +91,22 @@ class TestService(AccountBase):
Account: Test create group parameters
"""
clean_group(self.group_name)
- computer_system = self.wbemconnection.ExecQuery('WQL',
- 'select * from %s' % self.system_cs_name)[0]
- lams = self.wbemconnection.ExecQuery('WQL',
- 'select * from LMI_AccountManagementService')[0]
+ lams = self.cim_class.first_instance()
+ self.assertIsInstance(lams, LMIInstance)
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))
+ (rc, out, errorstr) = lams.CreateGroup({
+ 'Name': self.group_name,
+ 'System': self.system_iname,
+ 'SystemAccount': system_account,
+ 'GID': gid})
group = out["Group"]
idents = out["Identities"]
self.assertEqual(rc, 0)
- self.assertEqual(group["Name"], self.group_name)
+ self.assertEqual(group.Name, self.group_name)
for identity in idents:
- self.assertEqual(identity["InstanceID"], "LMI:GID:%d" %gid)
+ 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/common.py b/src/account/test/common.py
index 30bce96..8bb18e2 100644
--- a/src/account/test/common.py
+++ b/src/account/test/common.py
@@ -23,16 +23,18 @@ Base class and utilities for all OpenLMI Account tests.
import os
-from lmi.test import cimbase
+from lmi.test import lmibase
+import lmi.shell
-class AccountBase(cimbase.CIMTestCase):
+class AccountBase(lmibase.LmiTestCase):
"""
Base class for all LMI Account tests.
"""
@classmethod
def setUpClass(cls):
- cimbase.CIMTestCase.setUpClass.im_func(cls)
+ lmibase.LmiTestCase.setUpClass.im_func(cls)
+ lmi.shell.LMIUtil.lmi_set_use_exceptions(True)
cls.user_name = os.environ.get("LMI_ACCOUNT_USER")
cls.group_name = os.environ.get("LMI_ACCOUNT_GROUP")