From 9b6ac0cf21330115eec01e504895562357dfe1a6 Mon Sep 17 00:00:00 2001 From: Jr Aquino Date: Thu, 14 Jul 2011 16:00:51 -0700 Subject: [PATCH] 34 Create FreeIPA CLI Plugin for the 389 Auto Membership plugin https://fedorahosted.org/freeipa/ticket/1272 Added new container in etc to hold the automembership configs. Modified constants to point to the new container Modified dsinstance to create the container Modified hostgroup.py to add the new commands Added xmlrpc test to verify functionality --- API.txt | 77 ++++++++ freeipa.spec.in | 2 +- install/share/Makefile.am | 1 + install/share/automembership.ldif | 26 +++ ipalib/constants.py | 1 + ipalib/plugins/hostgroup.py | 263 +++++++++++++++++++++++++- ipaserver/install/dsinstance.py | 4 + tests/test_xmlrpc/test_clarityrule_plugin.py | 109 +++++++++++ 8 files changed, 480 insertions(+), 3 deletions(-) create mode 100644 install/share/automembership.ldif create mode 100644 tests/test_xmlrpc/test_clarityrule_plugin.py diff --git a/API.txt b/API.txt index 44292a9..6cb773b 100644 --- a/API.txt +++ b/API.txt @@ -1525,6 +1525,83 @@ option: Str('version?', exclude='webui', flags=['no_option', 'no_output']) output: Output('summary', (, ), 'User-friendly description of action performed') output: Entry('result', , Gettext('A dictionary representing an LDAP entry', domain='ipa', localedir=None)) output: Output('value', , "The primary_key value of the entry, e.g. 'jdoe' for a user") +command: hostgroupclarity_add +args: 1,8,3 +arg: Str('cn', attribute=True, cli_name='hostgroupclarity_rule', label=Gettext('Hostgroup Clarity Rule', domain='ipa', localedir=None), multivalue=False, normalizer=, primary_key=True, required=True) +option: Str('description', attribute=True, cli_name='desc', label=Gettext('Description', domain='ipa', localedir=None), multivalue=False, required=False) +option: List('automemberinclusiveregex', attribute=True, cli_name='inclusive_hostname_regex', label=Gettext('Inclusive Regex', domain='ipa', localedir=None), multivalue=True, required=False) +option: List('automemberexclusiveregex', attribute=True, cli_name='exclusive_hostname_regex', label=Gettext('Exclusive Regex', domain='ipa', localedir=None), multivalue=True, required=False) +option: Str('addattr*', validate_add_attribute, cli_name='addattr', exclude='webui') +option: Str('setattr*', validate_set_attribute, cli_name='setattr', exclude='webui') +option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui', flags=['no_output']) +option: Flag('raw', autofill=True, cli_name='raw', default=False, exclude='webui', flags=['no_output']) +option: Str('version?', exclude='webui', flags=['no_option', 'no_output']) +output: Output('summary', (, ), 'User-friendly description of action performed') +output: Entry('result', , Gettext('A dictionary representing an LDAP entry', domain='ipa', localedir=None)) +output: Output('value', , "The primary_key value of the entry, e.g. 'jdoe' for a user") +command: hostgroupclarity_add_condition +args: 1,9,3 +arg: Str('cn', attribute=True, cli_name='hostgroupclarity_rule', label=Gettext('Hostgroup Clarity Rule', domain='ipa', localedir=None), multivalue=False, normalizer=, primary_key=True, query=True, required=True) +option: Str('description', attribute=True, autofill=False, cli_name='desc', label=Gettext('Description', domain='ipa', localedir=None), multivalue=False, required=False) +option: List('automemberinclusiveregex', attribute=True, autofill=False, cli_name='inclusive_hostname_regex', label=Gettext('Inclusive Regex', domain='ipa', localedir=None), multivalue=True, required=False) +option: List('automemberexclusiveregex', attribute=True, autofill=False, cli_name='exclusive_hostname_regex', label=Gettext('Exclusive Regex', domain='ipa', localedir=None), multivalue=True, required=False) +option: Str('addattr*', validate_add_attribute, cli_name='addattr', exclude='webui') +option: Str('setattr*', validate_set_attribute, cli_name='setattr', exclude='webui') +option: Flag('rights', autofill=True, default=False, label=Gettext('Rights', domain='ipa', localedir=None)) +option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui', flags=['no_output']) +option: Flag('raw', autofill=True, cli_name='raw', default=False, exclude='webui', flags=['no_output']) +option: Str('version?', exclude='webui', flags=['no_option', 'no_output']) +output: Output('summary', (, ), 'User-friendly description of action performed') +output: Entry('result', , Gettext('A dictionary representing an LDAP entry', domain='ipa', localedir=None)) +output: Output('value', , "The primary_key value of the entry, e.g. 'jdoe' for a user") +command: hostgroupclarity_del +args: 1,1,3 +arg: Str('cn', attribute=True, cli_name='hostgroupclarity_rule', label=Gettext('Hostgroup Clarity Rule', domain='ipa', localedir=None), multivalue=True, normalizer=, primary_key=True, query=True, required=True) +option: Flag('continue', autofill=True, cli_name='continue', default=False) +output: Output('summary', (, ), 'User-friendly description of action performed') +output: Output('result', , 'list of deletions that failed') +output: Output('value', , "The primary_key value of the entry, e.g. 'jdoe' for a user") +command: hostgroupclarity_find +args: 1,9,4 +arg: Str('criteria?', noextrawhitespace=False) +option: Str('cn', attribute=True, autofill=False, cli_name='hostgroupclarity_rule', label=Gettext('Hostgroup Clarity Rule', domain='ipa', localedir=None), multivalue=False, normalizer=, primary_key=True, query=True, required=False) +option: Str('description', attribute=True, autofill=False, cli_name='desc', label=Gettext('Description', domain='ipa', localedir=None), multivalue=False, query=True, required=False) +option: List('automemberinclusiveregex', attribute=True, autofill=False, cli_name='inclusive_hostname_regex', label=Gettext('Inclusive Regex', domain='ipa', localedir=None), multivalue=True, query=True, required=False) +option: List('automemberexclusiveregex', attribute=True, autofill=False, cli_name='exclusive_hostname_regex', label=Gettext('Exclusive Regex', domain='ipa', localedir=None), multivalue=True, query=True, required=False) +option: Int('timelimit?', autofill=False, flags=['no_display'], label=Gettext('Time Limit', domain='ipa', localedir=None), minvalue=0) +option: Int('sizelimit?', autofill=False, flags=['no_display'], label=Gettext('Size Limit', domain='ipa', localedir=None), minvalue=0) +option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui', flags=['no_output']) +option: Flag('raw', autofill=True, cli_name='raw', default=False, exclude='webui', flags=['no_output']) +option: Str('version?', exclude='webui', flags=['no_option', 'no_output']) +output: Output('summary', (, ), 'User-friendly description of action performed') +output: ListOfEntries('result', (, ), Gettext('A list of LDAP entries', domain='ipa', localedir=None)) +output: Output('count', , 'Number of entries returned') +output: Output('truncated', , 'True if not all results were returned') +command: hostgroupclarity_remove_condition +args: 1,9,3 +arg: Str('cn', attribute=True, cli_name='hostgroupclarity_rule', label=Gettext('Hostgroup Clarity Rule', domain='ipa', localedir=None), multivalue=False, normalizer=, primary_key=True, query=True, required=True) +option: Str('description', attribute=True, autofill=False, cli_name='desc', label=Gettext('Description', domain='ipa', localedir=None), multivalue=False, required=False) +option: List('automemberinclusiveregex', attribute=True, autofill=False, cli_name='inclusive_hostname_regex', label=Gettext('Inclusive Regex', domain='ipa', localedir=None), multivalue=True, required=False) +option: List('automemberexclusiveregex', attribute=True, autofill=False, cli_name='exclusive_hostname_regex', label=Gettext('Exclusive Regex', domain='ipa', localedir=None), multivalue=True, required=False) +option: Str('addattr*', validate_add_attribute, cli_name='addattr', exclude='webui') +option: Str('setattr*', validate_set_attribute, cli_name='setattr', exclude='webui') +option: Flag('rights', autofill=True, default=False, label=Gettext('Rights', domain='ipa', localedir=None)) +option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui', flags=['no_output']) +option: Flag('raw', autofill=True, cli_name='raw', default=False, exclude='webui', flags=['no_output']) +option: Str('version?', exclude='webui', flags=['no_option', 'no_output']) +output: Output('summary', (, ), 'User-friendly description of action performed') +output: Entry('result', , Gettext('A dictionary representing an LDAP entry', domain='ipa', localedir=None)) +output: Output('value', , "The primary_key value of the entry, e.g. 'jdoe' for a user") +command: hostgroupclarity_show +args: 1,4,3 +arg: Str('cn', attribute=True, cli_name='hostgroupclarity_rule', label=Gettext('Hostgroup Clarity Rule', domain='ipa', localedir=None), multivalue=False, normalizer=, primary_key=True, query=True, required=True) +option: Flag('rights', autofill=True, default=False, label=Gettext('Rights', domain='ipa', localedir=None)) +option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui', flags=['no_output']) +option: Flag('raw', autofill=True, cli_name='raw', default=False, exclude='webui', flags=['no_output']) +option: Str('version?', exclude='webui', flags=['no_option', 'no_output']) +output: Output('summary', (, ), 'User-friendly description of action performed') +output: Entry('result', , Gettext('A dictionary representing an LDAP entry', domain='ipa', localedir=None)) +output: Output('value', , "The primary_key value of the entry, e.g. 'jdoe' for a user") command: i18n_messages args: 0,0,1 output: Output('messages', , Gettext('Dict of I18N messages', domain='ipa', localedir=None)) diff --git a/freeipa.spec.in b/freeipa.spec.in index 276001a..eb5dee3 100644 --- a/freeipa.spec.in +++ b/freeipa.spec.in @@ -24,7 +24,7 @@ Source0: freeipa-%{version}.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) %if ! %{ONLY_CLIENT} -BuildRequires: 389-ds-base-devel >= 1.2.8 +BuildRequires: 389-ds-base-devel >= 1.2.9-0.2 BuildRequires: svrcore-devel BuildRequires: /usr/share/selinux/devel/Makefile BuildRequires: policycoreutils >= %{POLICYCOREUTILSVER} diff --git a/install/share/Makefile.am b/install/share/Makefile.am index c636109..94669eb 100644 --- a/install/share/Makefile.am +++ b/install/share/Makefile.am @@ -49,6 +49,7 @@ app_DATA = \ entryusn.ldif \ root-autobind.ldif \ sudobind.ldif \ + automembership.ldif \ $(NULL) EXTRA_DIST = \ diff --git a/install/share/automembership.ldif b/install/share/automembership.ldif new file mode 100644 index 0000000..f192fe6 --- /dev/null +++ b/install/share/automembership.ldif @@ -0,0 +1,26 @@ +dn: cn=Auto Membership Plugin,cn=plugins,cn=config +changetype: modify +add: nsslapd-pluginConfigArea +nsslapd-pluginConfigArea: cn=automembership,cn=etc,$SUFFIX + +dn: cn=automembership,cn=etc,$SUFFIX +changetype: add +objectClass: top +objectClass: nsContainer +cn: automembership + +dn: cn=Hostgroups,cn=automembership,cn=etc,$SUFFIX +changetype: add +objectclass: autoMemberDefinition +cn: Hostgroups +autoMemberScope: $SUFFIX +autoMemberFilter: objectclass=ipaHost +autoMemberGroupingAttr: member:dn + +dn: cn=Groups,cn=automembership,cn=etc,$SUFFIX +changetype: add +objectclass: autoMemberDefinition +cn: Groups +autoMemberScope: $SUFFIX +autoMemberFilter: objectclass=posixAccount +autoMemberGroupingAttr: member:dn \ No newline at end of file diff --git a/ipalib/constants.py b/ipalib/constants.py index 23e8025..444aeb4 100644 --- a/ipalib/constants.py +++ b/ipalib/constants.py @@ -112,6 +112,7 @@ DEFAULT_CONFIG = ( ('container_sudocmd', 'cn=sudocmds,cn=sudo'), ('container_sudocmdgroup', 'cn=sudocmdgroups,cn=sudo'), ('container_entitlements', 'cn=entitlements,cn=etc'), + ('container_automembership', 'cn=automembership,cn=etc'), # Ports, hosts, and URIs: # FIXME: let's renamed xmlrpc_uri to rpc_xml_uri diff --git a/ipalib/plugins/hostgroup.py b/ipalib/plugins/hostgroup.py index 11ed663..544a2db 100644 --- a/ipalib/plugins/hostgroup.py +++ b/ipalib/plugins/hostgroup.py @@ -1,8 +1,9 @@ # Authors: # Rob Crittenden # Pavel Zuna +# JR Aquino # -# Copyright (C) 2009 Red Hat +# Copyright (C) 2011 Red Hat # see file 'COPYING' for use and warranty information # # This program is free software; you can redistribute it and/or modify @@ -45,10 +46,40 @@ EXAMPLES: Delete a hostgroup: ipa hostgroup-del baltimore + +Bring clarity to a hostgroup with an Auto Membership Rule. + +By configuring inclusive or exclusive regex paterns, you can automatically + assign a new host into a hostgroup based upon its FQDN. + +EXAMPLES: + + Create the initial host group: + ipa hostgroup-add --desc="Web Servers" webservers + + Create the initial rule: + ipa hostgroupclarity-add --inclusive-hostname-regex=fqdn=^www[1-9]+\.example\.com webservers + + Add another condition to the rule: + ipa hostgroupclarity-add-condition --inclusive-hostname-regex=fqdn=^web[1-9+]\.example\.com webservers + + Remove a condition from the rule: + ipa hostgroupclarity-remove-condition --inclusive-hostname-regex=^www[1-9+]\.example\.com webservers + + Find all of the clarity rules: + ipa hostgroupclarity-find + + Display the clarity rule for a host group: + ipa hostgroupclarity-show webservers + + Delete a hostgroup's clarity rule: + ipa hostgroup-del webservers + """ from ipalib.plugins.baseldap import * -from ipalib import api, Int, _, ngettext +from ipalib import api, Str, Int, _, ngettext +from ipalib.dn import * class hostgroup(LDAPObject): @@ -155,3 +186,231 @@ class hostgroup_remove_member(LDAPRemoveMember): """ api.register(hostgroup_remove_member) + +class hostgroupclarity(LDAPObject): + + """ + Bring clarity to a hostgroup with an Auto Membership Rule. + """ + + container_dn = DN(('cn', 'hostgroups'), api.env.container_automembership) + container_dn = str(container_dn) + + object_name = 'auto_membership_rule' + object_name_plural = 'auto_membership_rules' + object_class = ['top', 'automemberregexrule'] + default_attributes = [ + 'automemberinclusiveregex', 'automemberexclusiveregex', + 'cn', 'automembertargetgroup', 'description' + ] + + label = _('Auto Membership Rule') + + takes_params = ( + Str('cn', + cli_name='hostgroupclarity_rule', + label=_('Hostgroup Clarity Rule'), + doc=_('Hostgroup Clarity Rule'), + normalizer=lambda value: value.lower(), + primary_key=True, + ), + Str('description?', + cli_name='desc', + label=_('Description'), + doc=_('A description of this auto membership rule'), + ), + List('automemberinclusiveregex?', + cli_name='inclusive_hostname_regex', + label=_('Inclusive Regex'), + doc=_('Inclusive Regex'), + multivalue=True + ), + List('automemberexclusiveregex?', + cli_name='exclusive_hostname_regex', + label=_('Exclusive Regex'), + doc=_('Exclusive Regex'), + multivalue=True + ), + + ) + +api.register(hostgroupclarity) + +def automembership_container_exists(ldap): + try: + ldap.get_entry(api.env.container_automembership, []) + except errors.NotFound: + return False + return True + +def group_dn(groupname, ldap): + base_dn = DN(('cn', groupname), api.env.container_hostgroup) + base_dn = str(base_dn) + + try: + (gdn, entry_attrs) = ldap.get_entry(base_dn, []) + except errors.NotFound: + raise errors.NotFound(reason=_('Hostgroup: %s not found!' % groupname)) + return gdn + +class hostgroupclarity_add(LDAPCreate): + """ + Add a clarity rule for a hostgroup + """ + + def pre_callback(self, ldap, dn, entry_attrs, *keys, **options): + if not automembership_container_exists(self.api.Backend.ldap2): + raise errors.NotFound(reason=_('Auto Membership is not configured')) + + entry_attrs['automembertargetgroup'] = group_dn( + entry_attrs['cn'], + self.api.Backend.ldap2) + + include_type = (u'automemberinclusiveregex', + u'automemberexclusiveregex') + attr = '' + if include_type[0] in options: + attr = include_type[0] + elif include_type[1] in options: + attr = include_type[1] + if attr: + entry_attrs[attr] = ['fqdn=' + condition for condition in entry_attrs[attr]] + + return dn + +api.register(hostgroupclarity_add) + + +class hostgroupclarity_add_condition(LDAPUpdate): + """ + Add conditions to a clarity rule for a hostgroup + """ + def execute(self, *keys, **options): + ldap = self.obj.backend + + if len(options) == 2: # 'all' and 'raw' are always sent + raise errors.EmptyModlist() + + dn = self.obj.get_dn(*keys, **options) + entry_attrs = self.args_options_2_entry(**options) + + include_type = (u'automemberinclusiveregex', + u'automemberexclusiveregex') + attr = '' + if include_type[0] in options: + attr = include_type[0] + elif include_type[1] in options: + attr = include_type[1] + entry_attrs[attr] = ['fqdn=' + condition for condition in entry_attrs[attr]] + + if attr: + try: + (dn, old_entry) = ldap.get_entry( + dn, [attr], normalize=self.obj.normalize_dn + ) + except errors.ExecutionError, e: + try: + (dn, old_entry) = self._call_exc_callbacks( + keys, options, e, ldap.get_entry, dn, [], + normalize=self.obj.normalize_dn + ) + except errors.NotFound: + self.obj.handle_not_found(*keys) + for a in old_entry: + if not isinstance(entry_attrs[a], (list, tuple)): + entry_attrs[a] = [entry_attrs[a]] + entry_attrs[a] = list(entry_attrs[a]) + old_entry[a] + + attrs_list = list( + set(self.obj.default_attributes + entry_attrs.keys()) + ) + ldap.update_entry(dn, entry_attrs, normalize=self.obj.normalize_dn) + + self.obj.convert_attribute_members(entry_attrs, *keys, **options) + if self.obj.primary_key and keys[-1] is not None: + return dict(result=entry_attrs, value=keys[-1]) + return dict(result=entry_attrs, value=u'') + +api.register(hostgroupclarity_add_condition) + + +class hostgroupclarity_remove_condition(LDAPUpdate): + """ + Remove conditions from a clarity rule for a hostgroup + """ + + def execute(self, *keys, **options): + ldap = self.obj.backend + + if len(options) == 2: # 'all' and 'raw' are always sent + raise errors.EmptyModlist() + + dn = self.obj.get_dn(*keys, **options) + + entry_attrs = self.args_options_2_entry(**options) + + include_type = (u'automemberinclusiveregex', + u'automemberexclusiveregex') + attr = '' + if include_type[0] in options: + attr = include_type[0] + elif include_type[1] in options: + attr = include_type[1] + if attr: + try: + entry_attrs[attr] = ['fqdn=' + condition for condition in entry_attrs[attr]] + (dn, old_entry) = ldap.get_entry( + dn, [attr], normalize=self.obj.normalize_dn + ) + except errors.ExecutionError, e: + try: + (dn, old_entry) = self._call_exc_callbacks( + keys, options, e, ldap.get_entry, dn, [], + normalize=self.obj.normalize_dn + ) + except errors.NotFound: + self.obj.handle_not_found(*keys) + for a in old_entry: + if not isinstance(entry_attrs[a], (list, tuple)): + old_entry[a].remove(entry_attrs[a]) + elif entry_attrs[a][0] in old_entry[a]: + old_entry[a].remove(entry_attrs[a][0]) + entry_attrs = old_entry + attrs_list = list( + set(self.obj.default_attributes + entry_attrs.keys()) + ) + ldap.update_entry(dn, entry_attrs, normalize=self.obj.normalize_dn) + + self.obj.convert_attribute_members(entry_attrs, *keys, **options) + if self.obj.primary_key and keys[-1] is not None: + return dict(result=entry_attrs, value=keys[-1]) + return dict(result=entry_attrs, value=u'') + +api.register(hostgroupclarity_remove_condition) + + +class hostgroupclarity_del(LDAPDelete): + """ + Delete clarity rule for a hostgroup + """ + +api.register(hostgroupclarity_del) + + +class hostgroupclarity_find(LDAPSearch): + """ + Search for clarity rules for hostgroups. + """ + msg_summary = ngettext( + '%(count)d rules matched', '%(count)d rules matched', 0 + ) + +api.register(hostgroupclarity_find) + + +class hostgroupclarity_show(LDAPRetrieve): + """ + Display information about a hostgroup's clarity rules. + """ + +api.register(hostgroupclarity_show) diff --git a/ipaserver/install/dsinstance.py b/ipaserver/install/dsinstance.py index 9033b7b..c900d40 100644 --- a/ipaserver/install/dsinstance.py +++ b/ipaserver/install/dsinstance.py @@ -255,6 +255,7 @@ class DsInstance(service.Service): self.step("configuring user private groups", self.__user_private_groups) self.step("configuring netgroups from hostgroups", self.__host_nis_groups) self.step("creating default Sudo bind user", self.__add_sudo_binduser) + self.step("creating default Auto Membership layout", self.__add_automembership_config) if hbac_allow: self.step("creating default HBAC rule allow_all", self.add_hbac) @@ -779,6 +780,9 @@ class DsInstance(service.Service): def __add_sudo_binduser(self): self._ldap_mod("sudobind.ldif", self.sub_dict) + def __add_automembership_config(self): + self._ldap_mod("automembership.ldif", self.sub_dict) + def replica_populate(self): self.ldap_connect() diff --git a/tests/test_xmlrpc/test_clarityrule_plugin.py b/tests/test_xmlrpc/test_clarityrule_plugin.py new file mode 100644 index 0000000..bbc3b26 --- /dev/null +++ b/tests/test_xmlrpc/test_clarityrule_plugin.py @@ -0,0 +1,109 @@ +# Authors: +# Jr Aquino +# +# Copyright (C) 2011 Red Hat +# see file 'COPYING' for use and warranty information +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +""" +Test the `ipalib/plugins/clarityrule.py` module. +""" + +from xmlrpc_test import XMLRPC_test, assert_attr_equal +from ipalib import api +from ipalib.dn import * +from ipalib import errors + +class test_clarityrule(XMLRPC_test): + """ + Test the `clarityrule` plugin. + """ + test_host = u'clarityrule._test_host' + test_hostgroup = u'clarityrule_test_hostgroup' + test_hostgroup_include_regex = u'^clarityrule.*' + + def test_0_add_hostgroup(self): + """ + Initialize data for the automembership plugin testing. + """ + self.failsafe_add(api.Object.hostgroup, + self.test_hostgroup, description=u'description' + ) + + def test_1_hostgroupclarity_add(self): + """ + Test adding hostgroup clarity rule using + `xmlrpc.hostgroupclarity_add`. + """ + ret = api.Command['hostgroupclarity_add']( + self.test_hostgroup + ) + entry = ret['result'] + target_hostgroup = DN(('cn', self.test_hostgroup), DN(api.env.container_hostgroup), DN(api.env.basedn)) + target_hostgroup = str(target_hostgroup) + assert_attr_equal(entry, 'automembertargetgroup', target_hostgroup) + + def test_2_hostgroupclarity_add(self): + """ + Test adding conditions to a hostgroup clarity rule using + `xmlrpc.hostgroupclarity_add_condition`. + """ + ret = api.Command['hostgroupclarity_add_condition']( + self.test_hostgroup, automemberinclusiveregex=self.test_hostgroup_include_regex + ) + entry = ret['result'] + target_hostgroup = DN(('cn', self.test_hostgroup), DN(api.env.container_hostgroup), DN(api.env.basedn)) + target_hostgroup = str(target_hostgroup) + assert_attr_equal(entry, 'automemberinclusiveregex', u'fqdn=^clarityrule.*') + + def test_3_add_host(self): + """ + Add the test host. + """ + ret = api.Command['host_add']( + self.test_host, force=True + ) + entry = ret['result'] + assert_attr_equal(entry, 'fqdn', self.test_host) + + def test_3_check_hostgroup_membership(self): + """ + Check hostgroup membership + """ + ret = api.Command['hostgroup_show']( + self.test_hostgroup + ) + entry = ret['result'] + print entry + assert_attr_equal(entry, 'member_host', self.test_host) + + def test_4_clarityrule_remove__conditions(self): + """ + Test removing conditions from a hostgroup clarty rule using + `xmlrpc.hostgroupclarity_remove_condition`. + """ + ret = api.Command['hostgroupclarity_remove_condition']( + self.test_hostgroup, automemberinclusiveregex=self.test_hostgroup_include_regex + ) + entry = ret['result'] + assert 'automembertargetgroup' not in entry + assert 'automemberinclusiveregex' in entry + + def test_5_clarityrule_clear_testing_data(self): + """ + Clear data for AutoMembership rule plugin testing. + """ + api.Command['hostgroupclarity_del'](self.test_hostgroup) + api.Command['host_del'](self.test_host) + api.Command['hostgroup_del'](self.test_hostgroup) -- 1.7.4.4