def remove_role(lib_env, role_id, autodelete_users_groups=False): """ Remove role with specified id from CIB. Raises LibraryError on any failure. lib_env -- LibraryEnvironment role_id -- id of role which should be deleted autodelete_users_groups -- if True targets and groups which are empty after removal will be removed """ with cib_acl_section(lib_env) as acl_section: acl.remove_role(acl_section, role_id, autodelete_users_groups)
def test_autodelete(self): expected_xml = """ <cib> <configuration> <acls> <acl_group> <role id="some-role"/> </acl_group> </acls> </configuration> </cib> """ lib.remove_role(self.tree, "role-id", autodelete_users_groups=True) assert_xml_equal(expected_xml, etree.tostring(self.tree).decode())
def test_success(self): expected_xml = """ <cib> <configuration> <acls> <acl_target/> <acl_group> <role id="some-role"/> </acl_group> </acls> </configuration> </cib> """ lib.remove_role(self.tree, "role-id") assert_xml_equal(expected_xml, etree.tostring(self.tree).decode())
def remove_role(lib_env, role_id, autodelete_users_groups=False): """ Remove role with specified id from CIB. Raises LibraryError on any failure. lib_env -- LibraryEnvironment role_id -- id of role which should be deleted autodelete_users_groups -- if True targets and groups which are empty after removal will be removed """ cib = lib_env.get_cib(REQUIRED_CIB_VERSION) try: acl.remove_role(cib, role_id, autodelete_users_groups) except acl.AclRoleNotFound as e: raise LibraryError(acl.acl_error_to_report_item(e)) lib_env.push_cib(cib)
def test_id_not_exists(self): assert_raise_library_error( lambda: lib.remove_role(self.tree.find(".//acls"), "id-of-role"), ( severities.ERROR, report_codes.ID_NOT_FOUND, { "context_type": "acls", "context_id": "", "id": "id-of-role", }, ), )
def test_id_not_exists(self): self.assert_raises( lib.AclRoleNotFound, lambda: lib.remove_role(self.tree, "id-of-role"), {"role_id": "id-of-role"} )