mirror of
https://github.com/ansible/awx.git
synced 2026-02-03 02:28:12 -03:30
In essence, this configures Python to turn any warnings emitted in
runtime into errors[[1]]. This is the best practice that allows
reacting to future deprecation announcements that are coming from the
dependencies (direct, or transitive, or even CPython itself)[[2]].
The typical workflow looks like this:
1. If a dependency is updated an a warning is hit in tests, the
deprecated thing should be replaced with newer APIs.
2. If a dependency is transitive or we have no control over it
otherwise, the specific warning and a regex matching its message,
plus the module reference (where possible) can be added to the
list of temporary ignores in `pytest.ini`.
3. The list of temporary ignores should be reevaluated periodically,
including when dependency re-pinning in lockfile is happening.
[1]: https://docs.python.org/3/using/cmdline.html#cmdoption-W
[2]: https://pytest-with-eric.com/configuration/pytest-ignore-warnings/
72 lines
2.7 KiB
Python
72 lines
2.7 KiB
Python
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
import pytest
|
|
|
|
from awx.main.models import InstanceGroup, Instance
|
|
|
|
|
|
@pytest.mark.filterwarnings(
|
|
# FIXME: Figure out where it is emited and what causes it.
|
|
# FIXME: The suppression should be made more specific or the cause fixed.
|
|
# Ref: https://github.com/ansible/awx/pull/15620
|
|
"ignore::RuntimeWarning",
|
|
)
|
|
@pytest.mark.django_db
|
|
def test_instance_group_create(run_module, admin_user):
|
|
result = run_module(
|
|
'instance_group', {'name': 'foo-group', 'policy_instance_percentage': 34, 'policy_instance_minimum': 12, 'state': 'present'}, admin_user
|
|
)
|
|
assert not result.get('failed', False), result
|
|
assert result['changed']
|
|
|
|
ig = InstanceGroup.objects.get(name='foo-group')
|
|
assert ig.policy_instance_percentage == 34
|
|
assert ig.policy_instance_minimum == 12
|
|
|
|
# Create a new instance in the DB
|
|
new_instance = Instance.objects.create(hostname='foo.example.com')
|
|
|
|
# Set the new instance group only to the one instnace
|
|
result = run_module('instance_group', {'name': 'foo-group', 'instances': [new_instance.hostname], 'state': 'present'}, admin_user)
|
|
assert not result.get('failed', False), result
|
|
assert result['changed']
|
|
|
|
ig = InstanceGroup.objects.get(name='foo-group')
|
|
all_instance_names = []
|
|
for instance in ig.instances.all():
|
|
all_instance_names.append(instance.hostname)
|
|
|
|
assert new_instance.hostname in all_instance_names, 'Failed to add instance to group'
|
|
assert len(all_instance_names) == 1, 'Too many instances in group {0}'.format(','.join(all_instance_names))
|
|
|
|
|
|
@pytest.mark.filterwarnings(
|
|
# FIXME: Figure out where it is emited and what causes it.
|
|
# FIXME: The suppression should be made more specific or the cause fixed.
|
|
# Ref: https://github.com/ansible/awx/pull/15620
|
|
"ignore::RuntimeWarning",
|
|
)
|
|
@pytest.mark.django_db
|
|
def test_container_group_create(run_module, admin_user, kube_credential):
|
|
pod_spec = "{ 'Nothing': True }"
|
|
|
|
result = run_module('instance_group', {'name': 'foo-c-group', 'credential': kube_credential.id, 'is_container_group': True, 'state': 'present'}, admin_user)
|
|
assert not result.get('failed', False), result['msg']
|
|
assert result['changed']
|
|
|
|
ig = InstanceGroup.objects.get(name='foo-c-group')
|
|
assert ig.pod_spec_override == ''
|
|
|
|
result = run_module(
|
|
'instance_group',
|
|
{'name': 'foo-c-group', 'credential': kube_credential.id, 'is_container_group': True, 'pod_spec_override': pod_spec, 'state': 'present'},
|
|
admin_user,
|
|
)
|
|
assert not result.get('failed', False), result['msg']
|
|
assert result['changed']
|
|
|
|
ig = InstanceGroup.objects.get(name='foo-c-group')
|
|
assert ig.pod_spec_override == pod_spec
|