Skip to content

Commit

Permalink
Merge pull request #4 from RedHatSatellite/update100
Browse files Browse the repository at this point in the history
Update to 1.0.0
  • Loading branch information
evgeni authored Jun 22, 2020
2 parents bbf0623 + 34f098f commit 33cca9e
Show file tree
Hide file tree
Showing 231 changed files with 1,056 additions and 726 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,18 @@ jobs:
matrix:
python: ["2.7", "3.5", "3.6", "3.7"]
ansible:
- stable-2.7
- stable-2.8
- stable-2.9
- devel
exclude:
- python: "2.7"
ansible: "stable-2.7"
- python: "2.7"
ansible: "stable-2.8"
- python: "2.7"
ansible: "stable-2.9"
- python: "3.5"
ansible: "stable-2.7"
- python: "3.5"
ansible: "stable-2.8"
- python: "3.5"
ansible: "stable-2.9"
- python: "3.6"
ansible: "stable-2.7"
- python: "3.6"
ansible: "stable-2.8"
- python: "3.6"
Expand All @@ -46,6 +39,12 @@ jobs:
python-version: ${{ matrix.python }}
- name: Install Ansible
run: pip install git+https://github.com/ansible/ansible.git@${{ matrix.ansible }}#egg=ansible
- name: Set Environment to use mazer
run: |
echo "::set-env name=COLLECTION_COMMAND::mazer"
echo "::set-env name=COLLECTION_COMMAND_SUFFIX::"
pip install mazer
if: matrix.ansible == 'stable-2.8'
- name: Install dependencies
run: make test-setup
- name: fake redhat-uep.pem for redhat_manifest module
Expand Down
57 changes: 30 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ VERSION := $(shell python -c 'import yaml; print(yaml.safe_load(open("galaxy.yml
MANIFEST := build/collections/ansible_collections/$(NAMESPACE)/$(NAME)/MANIFEST.json

PLUGIN_TYPES := $(filter-out __%,$(notdir $(wildcard plugins/*)))
METADATA := galaxy.yml LICENSE README.md
METADATA := galaxy.yml LICENSE README.md meta/runtime.yml
$(foreach PLUGIN_TYPE,$(PLUGIN_TYPES),$(eval _$(PLUGIN_TYPE) := $(filter-out %__init__.py,$(wildcard plugins/$(PLUGIN_TYPE)/*.py))))
DEPENDENCIES := $(METADATA) $(foreach PLUGIN_TYPE,$(PLUGIN_TYPES),$(_$(PLUGIN_TYPE)))

PYTHON_VERSION = 3.7
COLLECTION_COMMAND ?= ansible-galaxy
SANITY_OPTS = --venv
TEST=
PYTEST=pytest -n 4 --boxed -v
Expand Down Expand Up @@ -41,26 +42,26 @@ sanity: $(MANIFEST)
# Fake a fresh git repo for ansible-test
cd $(<D) ; git init ; echo tests > .gitignore ; ansible-test sanity $(SANITY_OPTS) --python $(PYTHON_VERSION)

test: | tests/test_playbooks/vars/server.yml
test: $(MANIFEST) | tests/test_playbooks/vars/server.yml
$(PYTEST) $(TEST)

test-crud: | tests/test_playbooks/vars/server.yml
test-crud: $(MANIFEST) | tests/test_playbooks/vars/server.yml
$(PYTEST) 'tests/test_crud.py::test_crud'

test-check-mode: | tests/test_playbooks/vars/server.yml
test-check-mode: $(MANIFEST) | tests/test_playbooks/vars/server.yml
$(PYTEST) 'tests/test_crud.py::test_check_mode'

test-other:
$(PYTEST) -k 'not test_crud.py'

test_%: FORCE | tests/test_playbooks/vars/server.yml
test_%: FORCE $(MANIFEST) | tests/test_playbooks/vars/server.yml
pytest -v 'tests/test_crud.py::test_crud[$*]' 'tests/test_crud.py::test_check_mode[$*]'

record_%: FORCE
record_%: FORCE $(MANIFEST)
$(RM) tests/test_playbooks/fixtures/$*-*.yml
pytest -v 'tests/test_crud.py::test_crud[$*]' --record

clean_%: FORCE
clean_%: FORCE $(MANIFEST)
ansible-playbook --tags teardown,cleanup -i tests/inventory/hosts 'tests/test_playbooks/$*.yml'

setup: test-setup
Expand All @@ -74,33 +75,32 @@ tests/test_playbooks/vars/server.yml:
@echo "For recording, please adjust $@ to match your reference server."

dist-test: $(MANIFEST)
ANSIBLE_COLLECTIONS_PATHS=build/collections ansible -m $(NAMESPACE).$(NAME).foreman_organization -a "username=admin password=changeme server_url=https://foreman.example.test name=collectiontest" localhost | grep -q "Failed to connect to Foreman server"
ANSIBLE_COLLECTIONS_PATHS=build/collections ansible-doc $(NAMESPACE).$(NAME).foreman_organization | grep -q "Manage Foreman Organization"
ANSIBLE_COLLECTIONS_PATHS=build/collections ansible -m $(NAMESPACE).$(NAME).organization -a "username=admin password=changeme server_url=https://foreman.example.test name=collectiontest" localhost | grep -q "Failed to connect to Foreman server"
ANSIBLE_COLLECTIONS_PATHS=build/collections ansible-doc $(NAMESPACE).$(NAME).organization | grep -q "Manage Organization"

$(MANIFEST): $(NAMESPACE)-$(NAME)-$(VERSION).tar.gz
ifeq ($(COLLECTION_COMMAND),mazer)
# No idea, why this fails. But mazer is old and deprecated so unlikely to beeing fixed...
# mazer install --collections-path build/collections $<
-mkdir build/collections build/collections/ansible_collections build/collections/ansible_collections/$(NAMESPACE) build/collections/ansible_collections/$(NAMESPACE)/$(NAME)
tar xf $< -C build/collections/ansible_collections/$(NAMESPACE)/$(NAME)
else
ansible-galaxy collection install -p build/collections $< --force
endif

# fix the imports to use the collection namespace
build/src/plugins/modules/%.py: plugins/modules/%.py | build
sed -e '/ansible.module_utils.foreman_helper/ s/ansible.module_utils/ansible_collections.$(NAMESPACE).$(NAME).plugins.module_utils/g' \
-e '/extends_documentation_fragment/{:1 n; s/- foreman/- $(NAMESPACE).$(NAME).foreman/; t1}' $< > $@

build/src/plugins/inventory/%.py: plugins/inventory/%.py | build
sed -E -e '/NAME =/ s/foreman/$(NAMESPACE).$(NAME).foreman/' \
-e '/(plugin|choices):/ s/foreman/$(NAMESPACE).$(NAME).foreman/' $< > $@

build/src/plugins/callback/%.py: plugins/callback/%.py | build
sed -e '/CALLBACK_NAME =/ s/foreman/$(NAMESPACE).$(NAME).foreman/' \
-e '/callback:/ s/foreman/$(NAMESPACE).$(NAME).foreman/' $< > $@

build/src/%: % | build
build/src/%: % | build/src
cp $< $@

build:
-mkdir build build/src build/src/plugins $(addprefix build/src/plugins/,$(PLUGIN_TYPES))
build/src:
-mkdir build build/src build/src/meta build/src/plugins $(addprefix build/src/plugins/,$(PLUGIN_TYPES))

$(NAMESPACE)-$(NAME)-$(VERSION).tar.gz: $(addprefix build/src/,$(DEPENDENCIES)) | build
$(NAMESPACE)-$(NAME)-$(VERSION).tar.gz: $(addprefix build/src/,$(DEPENDENCIES)) | build/src
ifeq ($(COLLECTION_COMMAND),mazer)
mazer build --collection-path=build/src
cp build/src/releases/$@ .
else
ansible-galaxy collection build build/src --force
endif

dist: $(NAMESPACE)-$(NAME)-$(VERSION).tar.gz

Expand All @@ -109,9 +109,12 @@ clean:

doc-setup:
pip install -r docs/requirements.txt
doc:
doc: $(MANIFEST)
make -C docs html

branding:
sed -i 's/theforeman\.foreman/redhat.satellite/g' plugins/*/*.py tests/inventory/tests.foreman.yml tests/test_module_state.py tests/test_playbooks/*.yml

FORCE:

.PHONY: help dist lint sanity test test-crud test-check-mode test-other setup test-setup FORCE
9 changes: 1 addition & 8 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
[defaults]
library = plugins/modules
module_utils = plugins/module_utils
doc_fragment_plugins = plugins/doc_fragments
filter_plugins = plugins/filter
inventory_plugins = plugins/inventory
callback_plugins = plugins/callback
collections_paths = build/collections
inventory = tests/inventory/hosts
retry_files_enabled = False
stdout_callback = debug
stderr_callback = debug
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $(ANSIBLEGIT):

generate-docs: $(ANSIBLEGIT)
rm -rf ./modules/
bash -c "source $(ANSIBLEGIT)/hacking/env-setup && ANSIBLE_DOC_FRAGMENT_PLUGINS=../plugins/doc_fragments python3 $(ANSIBLEGIT)/hacking/build-ansible.py document-plugins --module-dir ../plugins/modules --template-dir ./_templates --template-dir $(ANSIBLEGIT)/docs/templates --type rst --output-dir ./modules/"
bash -c "source $(ANSIBLEGIT)/hacking/env-setup && ANSIBLE_COLLECTIONS_PATHS=../build/collections python3 $(ANSIBLEGIT)/hacking/build-ansible.py document-plugins --module-dir ../plugins/modules --template-dir ./_templates --template-dir $(ANSIBLEGIT)/docs/templates --type rst --output-dir ./modules/"

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
Expand Down
10 changes: 5 additions & 5 deletions docs/developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

First of all, please have a look at the [Ansible module development](https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html) guide and get familiar with the general Ansible module layout.

When looking at actual modules in this repository ([`foreman_domain`](../plugins/modules/foreman_domain.py) is a nice short example), you will notice a few differences to a "regular" Ansible module:
When looking at actual modules in this repository ([`domain`](../plugins/modules/domain.py) is a nice short example), you will notice a few differences to a "regular" Ansible module:

* Instead of `AnsibleModule`, we use `ForemanEntityAnsibleModule` (and a few others, see [`plugins/module_utils/foreman_helper.py`](../plugins/module_utils/foreman_helper.py)) which provides an abstraction layer for talking with the Foreman API
* Instead of Ansible's `argument_spec`, we provide an enhanced version called `foreman_spec`. It handles the translation from Ansible module arguments to Foreman API parameters, as nobody wants to write `organization_ids` in their playbook when they can write `organizations`
Expand Down Expand Up @@ -42,8 +42,8 @@ The rest of the module is usually very minimalistic:
if __name__ == '__main__':
main()
```
You can see a complete example of simple module in [`foreman_architecture`](../plugins/modules/foreman_architecture.py)
In some cases, you will have to handle some custom workflows/validations, you can see some examples in [`foreman_bookmark`](../plugins/modules/foreman_bookmark.py), [`foreman_compute_attribute`](../plugins/modules/foreman_compute_attribute.py), [`foreman_hostgroup`](../plugins/modules/foreman_hostgroup.py), [`foreman_provisioning_template`](../plugins/modules/foreman_provisioning_template.py)...
You can see a complete example of simple module in [`architecture`](../plugins/modules/architecture.py)
In some cases, you will have to handle some custom workflows/validations, you can see some examples in [`bookmark`](../plugins/modules/bookmark.py), [`compute_attribute`](../plugins/modules/compute_attribute.py), [`hostgroup`](../plugins/modules/hostgroup.py), [`provisioning_template`](../plugins/modules/provisioning_template.py)...

## Specification of the `foreman_spec`

Expand All @@ -57,7 +57,7 @@ This is usually combined with `flat_name=<entity>_id`. If no flat_name is provid
This is usually combined with `flat_name=<entity>_ids`. If no flat_name is provided, fallback to `singularize(<entity>)_ids` where entity is the foreman_spec key. eg `organizations=dict(type='entity_list')` => `flat_name=organization_ids`.
* `type='nested_list'` The referenced value is a list of Foreman entities that are not included in the main API call.
The module must handle the entities separately.
See domain parameters in [`foreman_domain`](../plugins/modules/foreman_domain.py) for an example.
See domain parameters in [`domain`](../plugins/modules/domain.py) for an example.
The sub entities must be described by `foreman_spec=<sub_entity>_spec`.
* `type='invisible'` The parameter is available to the API call, but it will be excluded from Ansible's `argument_spec`.
* `search_by='login'`: Used with `type='entity'` or `type='entity_list'`. Field used to search the sub entity. Defaults to value provided by `ENTITY_KEYS` or 'name' if no value found.
Expand Down Expand Up @@ -93,7 +93,7 @@ required_plugins=[
]
```

Or specific parameters, like the `discovery_proxy` parameter of `foreman_subnet` which needs the Discovery plugin:
Or specific parameters, like the `discovery_proxy` parameter of `subnet` which needs the Discovery plugin:
```python
required_plugins=[
('discovery', ['discovery_proxy']),
Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ authors:
- "metalcated <[email protected]>"
- "russianguppie <[email protected]>"
- "willtome <[email protected]>"
version: "0.8.1"
version: "1.0.0"
license:
- "GPL-3.0-or-later"
tags:
Expand Down
106 changes: 106 additions & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
plugin_routing:
modules:
foreman_architecture:
redirect: architecture
foreman_auth_source_ldap:
redirect: auth_source_ldap
foreman_bookmark:
redirect: bookmark
foreman_compute_attribute:
redirect: compute_attribute
foreman_compute_profile:
redirect: compute_profile
foreman_compute_resource:
redirect: compute_resource
foreman_config_group:
redirect: config_group
foreman_domain:
redirect: domain
foreman_environment:
redirect: puppet_environment
foreman_external_usergroup:
redirect: external_usergroup
foreman_global_parameter:
redirect: global_parameter
foreman_hostgroup:
redirect: hostgroup
foreman_host_power:
redirect: host_power
foreman_host:
redirect: host
foreman_image:
redirect: image
foreman_installation_medium:
redirect: installation_medium
foreman_job_template:
redirect: job_template
foreman_location:
redirect: location
foreman_model:
redirect: hardware_model
foreman_operatingsystem:
redirect: operatingsystem
foreman_organization:
redirect: organization
foreman_os_default_template:
redirect: os_default_template
foreman_provisioning_template:
redirect: provisioning_template
foreman_ptable:
redirect: partition_table
foreman_realm:
redirect: realm
foreman_role:
redirect: role
foreman_scap_content:
redirect: scap_content
foreman_scap_tailoring_file:
redirect: scap_tailoring_file
foreman_scc_account:
redirect: scc_account
foreman_scc_product:
redirect: scc_product
foreman_search_facts:
redirect: resource_info
foreman_setting:
redirect: setting
foreman_smart_class_parameter:
redirect: smart_class_parameter
foreman_snapshot:
redirect: snapshot
foreman_subnet:
redirect: subnet
foreman_templates_import:
redirect: templates_import
foreman_usergroup:
redirect: usergroup
foreman_user:
redirect: user
katello_activation_key:
redirect: activation_key
katello_content_credential:
redirect: content_credential
katello_content_view_filter:
redirect: content_view_filter
katello_content_view:
redirect: content_view
katello_content_view_version:
redirect: content_view_version
katello_host_collection:
redirect: host_collection
katello_lifecycle_environment:
redirect: lifecycle_environment
katello_manifest:
redirect: subscription_manifest
katello_product:
redirect: product
katello_repository:
redirect: repository
katello_repository_set:
redirect: repository_set
katello_sync_plan:
redirect: sync_plan
katello_sync:
redirect: repository_sync
katello_upload:
redirect: content_upload
4 changes: 2 additions & 2 deletions plugins/callback/foreman.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
__metaclass__ = type

DOCUMENTATION = '''
callback: foreman
callback: redhat.satellite.foreman
type: notification
short_description: Sends events to Foreman
description:
Expand Down Expand Up @@ -83,7 +83,7 @@
class CallbackModule(CallbackBase):
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'notification'
CALLBACK_NAME = 'foreman'
CALLBACK_NAME = 'redhat.satellite.foreman'
CALLBACK_NEEDS_WHITELIST = True

FOREMAN_HEADERS = {
Expand Down
Loading

0 comments on commit 33cca9e

Please sign in to comment.