mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-10-25 22:50:12 -05:00
ipatests: add missing automember-cli tests
Revisit the bash tests and port the valid tests to upstream. Related: https://pagure.io/freeipa/issue/9332 Signed-off-by: mbhalodi <mbhalodi@redhat.com> Reviewed-By: Florence Blanc-Renaud <flo@redhat.com> Reviewed-By: Rob Crittenden <rcritten@redhat.com> Reviewed-By: Michal Polovka <mpolovka@redhat.com>
This commit is contained in:
1 parent
5a0eed0b1a
commit
4119e4e799
2 files changed
+352
-18
No files matched your search
@@ -194,7 +194,7 @@ def automember_hostgroup4(request, hostgroup4):
|
||||
|
||||
|
||||
@pytest.mark.tier1
|
||||
class TestNonexistentAutomember(XMLRPC_test):
|
||||
class TestAutomemberAddNegative(XMLRPC_test):
|
||||
def test_create_with_nonexistent_group(self, automember_group, group1):
|
||||
""" Try to add a rule with non-existent group """
|
||||
group1.ensure_missing()
|
||||
@@ -203,14 +203,6 @@ class TestNonexistentAutomember(XMLRPC_test):
|
||||
reason=u'group "%s" not found' % group1.cn)):
|
||||
command()
|
||||
|
||||
def test_delete_with_nonexistent_group(self, automember_group, group1):
|
||||
""" Try to delete a rule with non-existent group """
|
||||
group1.ensure_missing()
|
||||
command = automember_group.make_delete_command()
|
||||
with raises_exact(errors.NotFound(
|
||||
reason=u'%s: Automember rule not found' % group1.cn)):
|
||||
command()
|
||||
|
||||
def test_create_with_nonexistent_hostgroup(self, automember_hostgroup,
|
||||
hostgroup1):
|
||||
""" Try to add a rule with non-existent group """
|
||||
@@ -220,13 +212,114 @@ class TestNonexistentAutomember(XMLRPC_test):
|
||||
reason=u'hostgroup "%s" not found' % hostgroup1.cn)):
|
||||
command()
|
||||
|
||||
def test_delete_with_nonexistent_hostgroup(self, automember_hostgroup,
|
||||
hostgroup1):
|
||||
""" Try to delete a rule with non-existent group """
|
||||
hostgroup1.ensure_missing()
|
||||
command = automember_hostgroup.make_delete_command()
|
||||
with raises_exact(errors.NotFound(
|
||||
reason=u'%s: Automember rule not found' % hostgroup1.cn)):
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp", [
|
||||
"automember_group",
|
||||
"automember_hostgroup"
|
||||
])
|
||||
def test_delete_with_nonexistent_automember(self, automember_grp,
|
||||
request):
|
||||
""" Try to delete a rule a non-existent rule"""
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
automember_grp.ensure_missing()
|
||||
command = automember_grp.make_delete_command()
|
||||
with pytest.raises(errors.NotFound,
|
||||
match=r'%s: Automember rule not found'
|
||||
% automember_grp.cn):
|
||||
command()
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp, grp", [
|
||||
("automember_group", "group1"),
|
||||
("automember_hostgroup", "hostgroup1")
|
||||
])
|
||||
def test_create_with_existent_group(self, automember_grp, grp, request):
|
||||
""" Try to add a rule that already exists """
|
||||
grp = request.getfixturevalue(grp)
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
grp.ensure_exists()
|
||||
automember_grp.ensure_exists()
|
||||
command = automember_grp.make_create_command()
|
||||
with pytest.raises(errors.DuplicateEntry,
|
||||
match=r'Automember rule with name "%s" '
|
||||
r'already exists' % grp.cn):
|
||||
command()
|
||||
|
||||
|
||||
class TestAutomemberFindNegative(XMLRPC_test):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp", [
|
||||
"automember_group",
|
||||
"automember_hostgroup"
|
||||
])
|
||||
def test_find_with_nonexistent_automember(self, automember_grp,
|
||||
request):
|
||||
""" Try to find a rule a non-existent rule """
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
automember_grp.ensure_missing()
|
||||
command = automember_grp.make_find_command()
|
||||
result = command()
|
||||
assert_deepequal(dict(
|
||||
count=0,
|
||||
truncated=False,
|
||||
summary=u'0 rules matched',
|
||||
result=[],
|
||||
), result)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp, grp", [
|
||||
("automember_group", "group1"),
|
||||
("automember_hostgroup", "hostgroup1")
|
||||
])
|
||||
def test_find_with_invalidtype(self, automember_grp, grp, request):
|
||||
""" Try to find rule with invalid type """
|
||||
grp = request.getfixturevalue(grp)
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
grp.ensure_exists()
|
||||
automember_grp.ensure_exists()
|
||||
command = automember_grp.make_command('automember_find', grp.name,
|
||||
type='badtype')
|
||||
with pytest.raises(errors.ValidationError,
|
||||
match=r'invalid \'type\': must be one '
|
||||
r'of \'group\', \'hostgroup\''):
|
||||
command()
|
||||
|
||||
|
||||
class TestAutomemberShowNegative(XMLRPC_test):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp", [
|
||||
"automember_group",
|
||||
"automember_hostgroup"
|
||||
])
|
||||
def test_show_with_nonexistent_automember(self, automember_grp,
|
||||
request):
|
||||
""" Try to show a non-existent rule """
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
automember_grp.ensure_missing()
|
||||
command = automember_grp.make_retrieve_command()
|
||||
with pytest.raises(errors.NotFound,
|
||||
match=r'%s: Automember rule not found'
|
||||
% automember_grp.cn):
|
||||
command()
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp, grp", [
|
||||
("automember_group", "group1"),
|
||||
("automember_hostgroup", "hostgroup1")
|
||||
])
|
||||
def test_show_with_invalidtype_group(self, automember_grp, grp, request):
|
||||
""" Try to show a rule with invalid type """
|
||||
grp = request.getfixturevalue(grp)
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
grp.ensure_exists()
|
||||
automember_grp.ensure_exists()
|
||||
command = automember_grp.make_command('automember_show', grp.name,
|
||||
type='badtype')
|
||||
with pytest.raises(errors.ValidationError,
|
||||
match=r'invalid \'type\': must be one '
|
||||
r'of \'group\', \'hostgroup\''):
|
||||
command()
|
||||
|
||||
|
||||
@@ -380,7 +473,6 @@ class TestAutomemberRebuildHostMembership(XMLRPC_test):
|
||||
hostgroup1.remove_member(dict(host=host1.fqdn))
|
||||
assert "extra keys = ['member_host']" in str(error.value)
|
||||
|
||||
|
||||
def test_rebuild_membership_for_host(self, host1, automember_hostgroup,
|
||||
hostgroup1):
|
||||
""" Rebuild automember membership for one host, both synchronously and
|
||||
@@ -406,6 +498,79 @@ class TestAutomemberRebuildHostMembership(XMLRPC_test):
|
||||
automember_hostgroup.delete()
|
||||
|
||||
|
||||
class TestAutomemberModifyNegative(XMLRPC_test):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp, grp", [
|
||||
("automember_group", "group1"),
|
||||
("automember_hostgroup", "hostgroup1")
|
||||
])
|
||||
def test_modify_with_same_value(self, automember_grp, grp, request):
|
||||
""" Try to modify an existing rule with the same value """
|
||||
grp = request.getfixturevalue(grp)
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
grp.ensure_exists()
|
||||
automember_grp.ensure_exists()
|
||||
command = automember_grp.make_update_command(updates=dict(
|
||||
description='%s' % automember_grp.description))
|
||||
with pytest.raises(errors.EmptyModlist,
|
||||
match=r"no modifications to be performed"):
|
||||
command()
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp", [
|
||||
"automember_group",
|
||||
"automember_hostgroup"
|
||||
])
|
||||
def test_modify_with_nonexistent_automember(self, automember_grp,
|
||||
request):
|
||||
""" Try to modify a non-existent rule """
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
automember_grp.ensure_missing()
|
||||
command = automember_grp.make_update_command(updates=dict(
|
||||
description='WEB_SERVERS'))
|
||||
with pytest.raises(errors.NotFound,
|
||||
match=r'%s: Automember rule not found' %
|
||||
automember_grp.cn):
|
||||
command()
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp, grp", [
|
||||
("automember_group", "group1"),
|
||||
("automember_hostgroup", "hostgroup1")
|
||||
])
|
||||
def test_modify_with_invalidtype_group(self, automember_grp, grp, request):
|
||||
""" Try to modify rule with invalid type """
|
||||
grp = request.getfixturevalue(grp)
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
grp.ensure_exists()
|
||||
automember_grp.ensure_exists()
|
||||
command = automember_grp.make_command('automember_mod', grp.name,
|
||||
type='badtype',
|
||||
description='WEB_SERVERS')
|
||||
with pytest.raises(errors.ValidationError,
|
||||
match=r'invalid \'type\': must be one '
|
||||
r'of \'group\', \'hostgroup\''):
|
||||
command()
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp, grp", [
|
||||
("automember_group", "group1"),
|
||||
("automember_hostgroup", "hostgroup1")
|
||||
])
|
||||
def test_modify_with_group_badattr(self, automember_grp, grp, request):
|
||||
"Try to modify rule with invalid attribute"
|
||||
grp = request.getfixturevalue(grp)
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
grp.ensure_exists()
|
||||
automember_grp.ensure_exists()
|
||||
command = automember_grp.make_update_command(updates=dict(
|
||||
badattr='WEB_SERVERS'))
|
||||
with raises_exact(errors.OptionError(
|
||||
('Unknown option: %(option)s'), option='badattr')):
|
||||
command()
|
||||
|
||||
|
||||
@pytest.mark.tier1
|
||||
class TestAutomemberRebuildGroupMembership(XMLRPC_test):
|
||||
def test_create_deps_for_rebuilding_groups(self, group1, manager1, user1,
|
||||
@@ -461,7 +626,6 @@ class TestAutomemberRebuildGroupMembership(XMLRPC_test):
|
||||
group1.remove_member(dict(user=user1.name))
|
||||
assert "extra keys = ['member_user']" in str(error.value)
|
||||
|
||||
|
||||
def test_rebuild_membership_for_user(self, user1, automember_group,
|
||||
group1):
|
||||
""" Rebuild automember membership for one user, both synchronously and
|
||||
@@ -528,6 +692,165 @@ class TestAutomemberRebuildMembershipIncorrectly(XMLRPC_test):
|
||||
command()
|
||||
|
||||
|
||||
class TestAutomemberAddConditionNegative(XMLRPC_test):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp", [
|
||||
"automember_group",
|
||||
"automember_hostgroup"
|
||||
])
|
||||
def test_create_inclusive_with_nonexistent_automember(
|
||||
self, automember_grp, request):
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
automember_grp.ensure_missing()
|
||||
command = automember_grp.make_add_condition_command(
|
||||
key=u'manager', type=automember_grp.membertype,
|
||||
automemberinclusiveregex="eng[0-9]+.example.com")
|
||||
with pytest.raises(errors.NotFound,
|
||||
match=r'Auto member rule: %s not found'
|
||||
% automember_grp.cn):
|
||||
command()
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp", [
|
||||
"automember_group",
|
||||
"automember_hostgroup"
|
||||
])
|
||||
def test_create_exclusive_with_nonexistent_automember(
|
||||
self, automember_grp, request):
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
automember_grp.ensure_missing()
|
||||
command = automember_grp.make_add_condition_command(
|
||||
key=u'manager', type=automember_grp.membertype,
|
||||
automemberexclusiveregex="qa[0-9]+.example.com")
|
||||
with pytest.raises(errors.NotFound,
|
||||
match=r'Auto member rule: %s not found'
|
||||
% automember_grp.cn):
|
||||
command()
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp, grp", [
|
||||
("automember_group", "group1"),
|
||||
("automember_hostgroup", "hostgroup1")
|
||||
])
|
||||
def test_create_inclusive_with_existent_automember(
|
||||
self, automember_grp, grp, request):
|
||||
grp = request.getfixturevalue(grp)
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
grp.ensure_exists()
|
||||
automember_grp.ensure_exists()
|
||||
automember_grp.add_condition(key=u'manager',
|
||||
type=automember_grp.membertype,
|
||||
inclusiveregex=[group_include_regex])
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp, grp", [
|
||||
("automember_group", "group1"),
|
||||
("automember_hostgroup", "hostgroup1")
|
||||
])
|
||||
def test_create_exclusive_with_existent_automember(
|
||||
self, automember_grp, grp, request):
|
||||
grp = request.getfixturevalue(grp)
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
grp.ensure_exists()
|
||||
automember_grp.ensure_exists()
|
||||
automember_grp.add_condition_exclusive(
|
||||
key=u'manager', type=automember_grp.membertype,
|
||||
exclusiveregex=[u'mjohn'])
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp, grp", [
|
||||
("automember_group", "group1"),
|
||||
("automember_hostgroup", "hostgroup1")
|
||||
])
|
||||
def test_create_inclusive_with_group_invalidtype(self, automember_grp,
|
||||
grp, request):
|
||||
grp = request.getfixturevalue(grp)
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
grp.ensure_exists()
|
||||
automember_grp.ensure_exists()
|
||||
command = automember_grp.make_add_condition_command(
|
||||
key=u'manager', type='badtype',
|
||||
automemberinclusiveregex=[u'mjohn'])
|
||||
with pytest.raises(errors.ValidationError,
|
||||
match=r'invalid \'type\': must be one '
|
||||
r'of \'group\', \'hostgroup\''):
|
||||
command()
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp, grp", [
|
||||
("automember_group", "group1"),
|
||||
("automember_hostgroup", "hostgroup1")
|
||||
])
|
||||
def test_create_exclusive_with_group_invalidtype(self, automember_grp,
|
||||
grp, request):
|
||||
grp = request.getfixturevalue(grp)
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
grp.ensure_exists()
|
||||
automember_grp.ensure_exists()
|
||||
command = automember_grp.make_add_condition_command(
|
||||
key=u'fqdn', type='badtype',
|
||||
automemberexclusiveregex="eng[0-9]+.example.com")
|
||||
with pytest.raises(errors.ValidationError,
|
||||
match=r'invalid \'type\': must be one '
|
||||
r'of \'group\', \'hostgroup\''):
|
||||
command()
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp, grp", [
|
||||
("automember_group", "group1"),
|
||||
("automember_hostgroup", "hostgroup1")
|
||||
])
|
||||
def test_create_inclusive_with_group_invalidkey(self, automember_grp,
|
||||
grp, request):
|
||||
grp = request.getfixturevalue(grp)
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
grp.ensure_exists()
|
||||
automember_grp.ensure_exists()
|
||||
command = automember_grp.make_add_condition_command(
|
||||
key='badkey', type=automember_grp.membertype,
|
||||
automemberinclusiveregex=[group_include_regex])
|
||||
with pytest.raises(errors.NotFound,
|
||||
match=r'badkey is not a valid attribute.'):
|
||||
command()
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp, grp", [
|
||||
("automember_group", "group1"),
|
||||
("automember_hostgroup", "hostgroup1")
|
||||
])
|
||||
def test_create_exclusive_with_group_invalidkey(self, automember_grp,
|
||||
grp, request):
|
||||
grp = request.getfixturevalue(grp)
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
grp.ensure_exists()
|
||||
automember_grp.ensure_exists()
|
||||
command = automember_grp.make_add_condition_command(
|
||||
key='badkey', type=automember_grp.membertype,
|
||||
automemberexclusiveregex=[group_include_regex])
|
||||
with pytest.raises(errors.NotFound,
|
||||
match=r'badkey is not a valid attribute.'):
|
||||
command()
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"automember_grp, grp", [
|
||||
("automember_group", "group1"),
|
||||
("automember_hostgroup", "hostgroup1")
|
||||
])
|
||||
def test_create_inclusive_with_group_badregextype(
|
||||
self, automember_grp, grp, request):
|
||||
grp = request.getfixturevalue(grp)
|
||||
automember_grp = request.getfixturevalue(automember_grp)
|
||||
grp.ensure_exists()
|
||||
automember_grp.ensure_exists()
|
||||
command = automember_grp.make_add_condition_command(
|
||||
key='manager', type=automember_grp.membertype,
|
||||
badregextype_regex=[group_include_regex])
|
||||
with raises_exact(errors.OptionError(
|
||||
('Unknown option: %(option)s'), option='badregextype_regex')):
|
||||
command()
|
||||
|
||||
|
||||
@pytest.mark.tier1
|
||||
class TestMultipleAutomemberConditions(XMLRPC_test):
|
||||
def test_create_deps_for_multiple_conditions(
|
||||
|
||||
@@ -189,6 +189,17 @@ class AutomemberTracker(Tracker):
|
||||
result = command()
|
||||
self.check_add_condition(result)
|
||||
|
||||
def add_condition_exclusive(self, key, type, exclusiveregex):
|
||||
""" Add a condition with given exclusive regex and check for result.
|
||||
Only one condition can be added. For more specific uses please
|
||||
use make_add_condition_command instead. """
|
||||
command = self.make_add_condition_command(
|
||||
key=key, type=type, automemberexclusiveregex=exclusiveregex)
|
||||
self.attrs['automemberexclusiveregex'] = [u'%s=%s' %
|
||||
(key, exclusiveregex[0])]
|
||||
result = command()
|
||||
self.check_add_condition(result)
|
||||
|
||||
def rebuild(self, no_wait=False):
|
||||
""" Rebuild automember conditions and check for result """
|
||||
command = self.make_rebuild_command(type=self.membertype,
|
||||
|
||||
Reference in new issue
Block a user