From 26dc8f1e535402affb64f7dd11459e0228a9c318 Mon Sep 17 00:00:00 2001 From: Rafael Guterres Jeffman <rjeffman@redhat.com> Date: Fri, 3 Sep 2021 13:28:43 -0300 Subject: [PATCH] ipaserver: Allow execution of plugin in client host. Update server README file and add tests for executing plugin with `ipaapi_context` set to `client`. A new test playbook can be found at: tests/server/test_server_client_context.yml The new test file can be executed in a FreeIPA client host that is not a server. In this case, it should be defined in the `ipaclients` group, in the inventory file. --- README-server.md | 1 + tests/server/test_server.yml | 17 +++++++++- tests/server/test_server_client_context.yml | 37 +++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/server/test_server_client_context.yml diff --git a/README-server.md b/README-server.md index b899cdac..66e62bb5 100644 --- a/README-server.md +++ b/README-server.md @@ -230,6 +230,7 @@ Variable | Description | Required -------- | ----------- | -------- `ipaadmin_principal` | The admin principal is a string and defaults to `admin` | no `ipaadmin_password` | The admin password is a string and is required if there is no admin ticket available on the node | no +`ipaapi_context` | The context in which the module will execute. Executing in a server context is preferred. If not provided context will be determined by the execution environment. Valid values are `server` and `client`. | no `name` \| `cn` | The list of server name strings. | yes `location` \| `ipalocation_location` | The server location string. Only in state: present. "" for location reset. | no `service_weight` \| `ipaserviceweight` | Weight for server services. Type Values 0 to 65535, -1 for weight reset. Only in state: present. (int) | no diff --git a/tests/server/test_server.yml b/tests/server/test_server.yml index b7f0193a..0f97b2ac 100644 --- a/tests/server/test_server.yml +++ b/tests/server/test_server.yml @@ -1,6 +1,6 @@ --- - name: Test server - hosts: ipaserver + hosts: "{{ ipa_test_host | default('ipaserver') }}" become: true gather_facts: yes @@ -30,18 +30,21 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without location ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" location: "" - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without service weight ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" service_weight: -1 - name: Ensure location "mylocation" is absent ipalocation: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: mylocation state: absent @@ -50,6 +53,7 @@ - name: Ensure location "mylocation" is present ipalocation: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: mylocation register: result failed_when: not result.changed or result.failed @@ -59,6 +63,7 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" is present ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" register: result failed_when: result.changed or result.failed @@ -66,6 +71,7 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" with location "mylocation" ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" location: "mylocation" register: result @@ -74,6 +80,7 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" with location "mylocation" again ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" location: "mylocation" register: result @@ -82,6 +89,7 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without location ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" location: "" register: result @@ -90,6 +98,7 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without location again ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" location: "" register: result @@ -98,6 +107,7 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" with service weight 1 ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" service_weight: 1 register: result @@ -106,6 +116,7 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" with service weight 1 again ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" service_weight: 1 register: result @@ -114,6 +125,7 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without service weight ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" service_weight: -1 register: result @@ -122,6 +134,7 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without service weight again ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" service_weight: -1 register: result @@ -134,6 +147,7 @@ - name: Ensure server "{{ 'absent.' + ipaserver_domain }}" is absent ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ 'absent.' + ipaserver_domain }}" state: absent register: result @@ -148,6 +162,7 @@ - name: Ensure location "mylocation" is absent ipalocation: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: mylocation state: absent register: result diff --git a/tests/server/test_server_client_context.yml b/tests/server/test_server_client_context.yml new file mode 100644 index 00000000..d1f31090 --- /dev/null +++ b/tests/server/test_server_client_context.yml @@ -0,0 +1,37 @@ +--- +- name: Test server + hosts: ipaclients, ipaserver + become: no + gather_facts: no + + tasks: + - name: Include FreeIPA facts. + include_tasks: ../env_freeipa_facts.yml + + # Test will only be executed if host is not a server. + - name: Execute with server context in the client. + ipaserver: + ipaadmin_password: SomeADMINpassword + ipaapi_context: server + name: ThisShouldNotWork + register: result + failed_when: not (result.failed and result.msg is regex("No module named '*ipaserver'*")) + when: ipa_host_is_client + +# Import basic module tests, and execute with ipa_context set to 'client'. +# If ipaclients is set, it will be executed using the client, if not, +# ipaserver will be used. +# +# With this setup, tests can be executed against an IPA client, against +# an IPA server using "client" context, and ensure that tests are executed +# in upstream CI. + +- name: Test server using client context, in client host. + import_playbook: test_server.yml + when: groups['ipaclients'] + vars: + ipa_test_host: ipaclients + +- name: Test server using client context, in server host. + import_playbook: test_server.yml + when: groups['ipaclients'] is not defined or not groups['ipaclients'] -- GitLab