mirror of
https://github.com/ansible/awx.git
synced 2026-03-23 03:45:01 -02:30
Apply new rules from black update (#16232)
This commit is contained in:
@@ -10,7 +10,6 @@ from awx.main.dispatch.publish import task as old_task
|
||||
|
||||
from ansible_base.lib.utils.db import advisory_lock
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
||||
@@ -59,8 +59,7 @@ def app_post_migration(sender, app_config, **kwargs):
|
||||
elif tblname == 'main_systemjobevent':
|
||||
unique_columns = "system_job_id integer NOT NULL"
|
||||
|
||||
cur.execute(
|
||||
f"""CREATE TABLE _unpartitioned_{tblname} (
|
||||
cur.execute(f"""CREATE TABLE _unpartitioned_{tblname} (
|
||||
id bigint NOT NULL,
|
||||
created timestamp with time zone NOT NULL,
|
||||
modified timestamp with time zone NOT NULL,
|
||||
@@ -72,8 +71,7 @@ def app_post_migration(sender, app_config, **kwargs):
|
||||
uuid character varying(1024) NOT NULL,
|
||||
verbosity integer NOT NULL,
|
||||
{unique_columns});
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
|
||||
if settings.DATABASES['default']['ENGINE'] == 'django.db.backends.sqlite3':
|
||||
|
||||
@@ -66,7 +66,7 @@ def test_database_counts(organization_factory, job_template_factory, workflow_jo
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_inventory_counts(organization_factory, inventory_factory):
|
||||
(inv1, inv2, inv3) = [inventory_factory(f"inv-{i}") for i in range(3)]
|
||||
inv1, inv2, inv3 = [inventory_factory(f"inv-{i}") for i in range(3)]
|
||||
|
||||
s1 = inv1.inventory_sources.create(name="src1", source="ec2")
|
||||
s2 = inv1.inventory_sources.create(name="src2", source="file")
|
||||
|
||||
@@ -3,7 +3,6 @@ import pytest
|
||||
|
||||
from awx.api.versioning import reverse
|
||||
|
||||
|
||||
"""
|
||||
def run_test_ad_hoc_command(self, **kwargs):
|
||||
# Post to list to start a new ad hoc command.
|
||||
|
||||
@@ -11,7 +11,6 @@ from django.http import HttpResponse
|
||||
|
||||
from rest_framework import status
|
||||
|
||||
|
||||
INSTANCE_KWARGS = dict(hostname='example-host', cpu=6, node_type='execution', memory=36000000000, cpu_capacity=6, mem_capacity=42)
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ from awx.api.versioning import reverse
|
||||
from awx.main.models import JobTemplate, Schedule
|
||||
from awx.main.utils.encryption import decrypt_value, get_encryption_key
|
||||
|
||||
|
||||
RRULE_EXAMPLE = 'DTSTART:20151117T050000Z RRULE:FREQ=DAILY;INTERVAL=1;COUNT=1'
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ from awx.main.models import UnifiedJob, ProjectUpdate, InventoryUpdate
|
||||
from awx.main.tests.URI import URI
|
||||
from awx.main.constants import ACTIVE_STATES
|
||||
|
||||
|
||||
TEST_STATES = list(ACTIVE_STATES)
|
||||
TEST_STATES.remove('new')
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ from django.test.utils import override_settings
|
||||
from awx.main.models import User
|
||||
from awx.api.versioning import reverse
|
||||
|
||||
|
||||
#
|
||||
# user creation
|
||||
#
|
||||
|
||||
@@ -18,7 +18,6 @@ from awx.main.management.commands import inventory_import
|
||||
from awx.main.models import Inventory, Host, Group, InventorySource
|
||||
from awx.main.utils.mem_inventory import MemGroup
|
||||
|
||||
|
||||
TEST_INVENTORY_CONTENT = {
|
||||
"_meta": {"hostvars": {}},
|
||||
"all": {"children": ["others", "servers", "ungrouped"], "vars": {"vara": "A"}},
|
||||
|
||||
@@ -12,7 +12,6 @@ from awx.conf.models import Setting
|
||||
from awx.main.management.commands import regenerate_secret_key
|
||||
from awx.main.utils.encryption import encrypt_field, decrypt_field, encrypt_value
|
||||
|
||||
|
||||
PREFIX = '$encrypted$UTF8$AESCBC$'
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ from awx.main.dispatch.publish import task
|
||||
from awx.main.dispatch.worker import BaseWorker, TaskWorker
|
||||
from awx.main.dispatch.periodic import Scheduler
|
||||
|
||||
|
||||
'''
|
||||
Prevent logger.<warn, debug, error> calls from triggering database operations
|
||||
'''
|
||||
|
||||
@@ -64,7 +64,7 @@ def test_env_matches_requirements_txt():
|
||||
if skip_line(x):
|
||||
continue
|
||||
x = x.lower()
|
||||
(pkg_name, pkg_version) = x.split('==')
|
||||
pkg_name, pkg_version = x.split('==')
|
||||
reqs_actual.append([pkg_name, pkg_version])
|
||||
|
||||
reqs_expected = []
|
||||
@@ -80,7 +80,7 @@ def test_env_matches_requirements_txt():
|
||||
Special case pkg_name[pkg_subname]==version
|
||||
For this case, we strip out [pkg_subname]
|
||||
'''
|
||||
(pkg_name, pkg_version) = line.split('==')
|
||||
pkg_name, pkg_version = line.split('==')
|
||||
pkg_name = re.sub(r'\[.*\]', '', pkg_name)
|
||||
reqs_expected.append([pkg_name, pkg_version])
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ from awx.main.tests import data
|
||||
from awx.main.models import Project, JobTemplate, Organization, Inventory
|
||||
from awx.main.tasks.system import clear_setting_cache
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ from awx.main.models.organization import Organization
|
||||
from awx.main.models.inventory import Inventory, InventorySource
|
||||
from awx.main.tests.live.tests.conftest import wait_for_job
|
||||
|
||||
|
||||
NAME_PREFIX = "test-ivu"
|
||||
GIT_REPO_FOLDER = "inventory_vars"
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class TestSubListCreateAttachDetachAPIView:
|
||||
mock_request = mocker.MagicMock(data=dict(id=1))
|
||||
serializer = SubListCreateAttachDetachAPIView()
|
||||
|
||||
(sub_id, res) = serializer.attach_validate(mock_request)
|
||||
sub_id, res = serializer.attach_validate(mock_request)
|
||||
|
||||
assert sub_id == 1
|
||||
assert res is None
|
||||
@@ -59,12 +59,12 @@ class TestSubListCreateAttachDetachAPIView:
|
||||
mock_request = mocker.MagicMock(data=dict(id='foobar'))
|
||||
serializer = SubListCreateAttachDetachAPIView()
|
||||
|
||||
(sub_id, res) = serializer.attach_validate(mock_request)
|
||||
sub_id, res = serializer.attach_validate(mock_request)
|
||||
|
||||
assert type(res) is Response
|
||||
|
||||
def test_attach_create_and_associate(self, mocker, get_object_or_400, parent_relationship_factory):
|
||||
(serializer, mock_parent_relationship) = parent_relationship_factory(SubListCreateAttachDetachAPIView, 'wife')
|
||||
serializer, mock_parent_relationship = parent_relationship_factory(SubListCreateAttachDetachAPIView, 'wife')
|
||||
create_return_value = mocker.MagicMock(status_code=status.HTTP_201_CREATED)
|
||||
serializer.create = mocker.Mock(return_value=create_return_value)
|
||||
|
||||
@@ -75,7 +75,7 @@ class TestSubListCreateAttachDetachAPIView:
|
||||
mock_parent_relationship.wife.add.assert_called_with(get_object_or_400.return_value)
|
||||
|
||||
def test_attach_associate_only(self, mocker, get_object_or_400, parent_relationship_factory):
|
||||
(serializer, mock_parent_relationship) = parent_relationship_factory(SubListCreateAttachDetachAPIView, 'wife')
|
||||
serializer, mock_parent_relationship = parent_relationship_factory(SubListCreateAttachDetachAPIView, 'wife')
|
||||
serializer.create = mocker.Mock(return_value=mocker.MagicMock())
|
||||
|
||||
mock_request = mocker.MagicMock(data=dict(id=1))
|
||||
@@ -88,7 +88,7 @@ class TestSubListCreateAttachDetachAPIView:
|
||||
mock_request = mocker.MagicMock(data=dict(id=1))
|
||||
serializer = SubListCreateAttachDetachAPIView()
|
||||
|
||||
(sub_id, res) = serializer.unattach_validate(mock_request)
|
||||
sub_id, res = serializer.unattach_validate(mock_request)
|
||||
|
||||
assert sub_id == 1
|
||||
assert res is None
|
||||
@@ -97,7 +97,7 @@ class TestSubListCreateAttachDetachAPIView:
|
||||
mock_request = mocker.MagicMock(data=dict(id='foobar'))
|
||||
serializer = SubListCreateAttachDetachAPIView()
|
||||
|
||||
(sub_id, res) = serializer.unattach_validate(mock_request)
|
||||
sub_id, res = serializer.unattach_validate(mock_request)
|
||||
|
||||
assert type(res) is Response
|
||||
|
||||
@@ -105,13 +105,13 @@ class TestSubListCreateAttachDetachAPIView:
|
||||
mock_request = mocker.MagicMock(data=dict())
|
||||
serializer = SubListCreateAttachDetachAPIView()
|
||||
|
||||
(sub_id, res) = serializer.unattach_validate(mock_request)
|
||||
sub_id, res = serializer.unattach_validate(mock_request)
|
||||
|
||||
assert sub_id is None
|
||||
assert type(res) is Response
|
||||
|
||||
def test_unattach_by_id_ok(self, mocker, parent_relationship_factory, get_object_or_400):
|
||||
(serializer, mock_parent_relationship) = parent_relationship_factory(SubListCreateAttachDetachAPIView, 'wife')
|
||||
serializer, mock_parent_relationship = parent_relationship_factory(SubListCreateAttachDetachAPIView, 'wife')
|
||||
mock_request = mocker.MagicMock()
|
||||
mock_sub = mocker.MagicMock(name="object to unattach")
|
||||
get_object_or_400.return_value = mock_sub
|
||||
|
||||
@@ -11,7 +11,6 @@ from awx.main.models import (
|
||||
WorkflowJobNode,
|
||||
)
|
||||
|
||||
|
||||
mock_query_set = mock.MagicMock()
|
||||
|
||||
mock_objects = mock.MagicMock(filter=mock.MagicMock(return_value=mock_query_set))
|
||||
|
||||
@@ -39,6 +39,6 @@ def simple_cycle_1(node_generator):
|
||||
|
||||
|
||||
def test_has_cycle(simple_cycle_1):
|
||||
(g, nodes) = simple_cycle_1
|
||||
g, nodes = simple_cycle_1
|
||||
|
||||
assert g.has_cycle() is True
|
||||
|
||||
@@ -86,13 +86,13 @@ class TestWorkflowDAG:
|
||||
return (g, wf_root_nodes, wf_leaf_nodes)
|
||||
|
||||
def test_get_root_nodes(self, workflow_dag_root_children):
|
||||
(g, wf_root_nodes, ignore) = workflow_dag_root_children
|
||||
g, wf_root_nodes, ignore = workflow_dag_root_children
|
||||
assert set([n.id for n in wf_root_nodes]) == set([n['node_object'].id for n in g.get_root_nodes()])
|
||||
|
||||
|
||||
class TestDNR:
|
||||
def test_mark_dnr_nodes(self, workflow_dag_1):
|
||||
(g, nodes) = workflow_dag_1
|
||||
g, nodes = workflow_dag_1
|
||||
|
||||
r'''
|
||||
0
|
||||
@@ -166,7 +166,7 @@ class TestAllWorkflowNodes:
|
||||
return (g, nodes)
|
||||
|
||||
def test_simple_all_convergence(self, simple_all_convergence):
|
||||
(g, nodes) = simple_all_convergence
|
||||
g, nodes = simple_all_convergence
|
||||
dnr_nodes = g.mark_dnr_nodes()
|
||||
assert 0 == len(dnr_nodes), "no nodes should be marked DNR"
|
||||
|
||||
@@ -197,7 +197,7 @@ class TestAllWorkflowNodes:
|
||||
return (g, nodes)
|
||||
|
||||
def test_all_converge_edge_case_1(self, workflow_all_converge_1):
|
||||
(g, nodes) = workflow_all_converge_1
|
||||
g, nodes = workflow_all_converge_1
|
||||
dnr_nodes = g.mark_dnr_nodes()
|
||||
assert 2 == len(dnr_nodes), "node[1] and node[2] should be marked DNR"
|
||||
assert nodes[1] == dnr_nodes[0], "Node 1 should be marked DNR"
|
||||
@@ -233,7 +233,7 @@ class TestAllWorkflowNodes:
|
||||
return (g, nodes)
|
||||
|
||||
def test_all_converge_edge_case_2(self, workflow_all_converge_2):
|
||||
(g, nodes) = workflow_all_converge_2
|
||||
g, nodes = workflow_all_converge_2
|
||||
dnr_nodes = g.mark_dnr_nodes()
|
||||
assert 1 == len(dnr_nodes), "1 and only 1 node should be marked DNR"
|
||||
assert nodes[2] == dnr_nodes[0], "Node 3 should be marked DNR"
|
||||
@@ -268,7 +268,7 @@ class TestAllWorkflowNodes:
|
||||
return (g, nodes)
|
||||
|
||||
def test_workflow_all_converge_will_run(self, workflow_all_converge_will_run):
|
||||
(g, nodes) = workflow_all_converge_will_run
|
||||
g, nodes = workflow_all_converge_will_run
|
||||
dnr_nodes = g.mark_dnr_nodes()
|
||||
assert 0 == len(dnr_nodes), "No nodes should get marked DNR"
|
||||
|
||||
@@ -306,7 +306,7 @@ class TestAllWorkflowNodes:
|
||||
return (g, nodes)
|
||||
|
||||
def test_workflow_all_converge_while_parent_runs(self, workflow_all_converge_dnr):
|
||||
(g, nodes) = workflow_all_converge_dnr
|
||||
g, nodes = workflow_all_converge_dnr
|
||||
dnr_nodes = g.mark_dnr_nodes()
|
||||
assert 0 == len(dnr_nodes), "No nodes should get marked DNR"
|
||||
|
||||
@@ -315,7 +315,7 @@ class TestAllWorkflowNodes:
|
||||
|
||||
def test_workflow_all_converge_with_incorrect_parent(self, workflow_all_converge_dnr):
|
||||
# Another tick of the scheduler
|
||||
(g, nodes) = workflow_all_converge_dnr
|
||||
g, nodes = workflow_all_converge_dnr
|
||||
nodes[1].job.status = 'successful'
|
||||
dnr_nodes = g.mark_dnr_nodes()
|
||||
assert 1 == len(dnr_nodes), "1 and only 1 node should be marked DNR"
|
||||
@@ -326,7 +326,7 @@ class TestAllWorkflowNodes:
|
||||
|
||||
def test_workflow_all_converge_runs(self, workflow_all_converge_dnr):
|
||||
# Trick the scheduler again to make sure the convergence node acutally runs
|
||||
(g, nodes) = workflow_all_converge_dnr
|
||||
g, nodes = workflow_all_converge_dnr
|
||||
nodes[1].job.status = 'failed'
|
||||
dnr_nodes = g.mark_dnr_nodes()
|
||||
assert 0 == len(dnr_nodes), "No nodes should be marked DNR"
|
||||
@@ -375,7 +375,7 @@ class TestAllWorkflowNodes:
|
||||
return (g, nodes)
|
||||
|
||||
def test_workflow_all_converge_deep_dnr_tree(self, workflow_all_converge_deep_dnr_tree):
|
||||
(g, nodes) = workflow_all_converge_deep_dnr_tree
|
||||
g, nodes = workflow_all_converge_deep_dnr_tree
|
||||
dnr_nodes = g.mark_dnr_nodes()
|
||||
|
||||
assert 4 == len(dnr_nodes), "All nodes w/ no jobs should be marked DNR"
|
||||
@@ -391,7 +391,7 @@ class TestAllWorkflowNodes:
|
||||
class TestIsWorkflowDone:
|
||||
@pytest.fixture
|
||||
def workflow_dag_2(self, workflow_dag_1):
|
||||
(g, nodes) = workflow_dag_1
|
||||
g, nodes = workflow_dag_1
|
||||
r'''
|
||||
S0
|
||||
/\
|
||||
@@ -416,7 +416,7 @@ class TestIsWorkflowDone:
|
||||
|
||||
@pytest.fixture
|
||||
def workflow_dag_failed(self, workflow_dag_1):
|
||||
(g, nodes) = workflow_dag_1
|
||||
g, nodes = workflow_dag_1
|
||||
r'''
|
||||
S0
|
||||
/\
|
||||
@@ -453,7 +453,7 @@ class TestIsWorkflowDone:
|
||||
|
||||
@pytest.fixture
|
||||
def workflow_dag_failure(self, workflow_dag_canceled):
|
||||
(g, nodes) = workflow_dag_canceled
|
||||
g, nodes = workflow_dag_canceled
|
||||
nodes[0].job.status = 'failed'
|
||||
return (g, nodes)
|
||||
|
||||
@@ -463,7 +463,7 @@ class TestIsWorkflowDone:
|
||||
assert g.is_workflow_done() is False
|
||||
|
||||
def test_workflow_done_and_failed(self, workflow_dag_failed):
|
||||
(g, nodes) = workflow_dag_failed
|
||||
g, nodes = workflow_dag_failed
|
||||
|
||||
assert g.is_workflow_done() is True
|
||||
assert g.has_workflow_failed() == (
|
||||
@@ -477,7 +477,7 @@ class TestIsWorkflowDone:
|
||||
)
|
||||
|
||||
def test_is_workflow_done_no_unified_job_tempalte_end(self, workflow_dag_failed):
|
||||
(g, nodes) = workflow_dag_failed
|
||||
g, nodes = workflow_dag_failed
|
||||
|
||||
nodes[2].unified_job_template = None
|
||||
|
||||
@@ -492,7 +492,7 @@ class TestIsWorkflowDone:
|
||||
)
|
||||
|
||||
def test_is_workflow_done_no_unified_job_tempalte_begin(self, workflow_dag_1):
|
||||
(g, nodes) = workflow_dag_1
|
||||
g, nodes = workflow_dag_1
|
||||
|
||||
nodes[0].unified_job_template = None
|
||||
g.mark_dnr_nodes()
|
||||
@@ -508,7 +508,7 @@ class TestIsWorkflowDone:
|
||||
)
|
||||
|
||||
def test_canceled_should_fail(self, workflow_dag_canceled):
|
||||
(g, nodes) = workflow_dag_canceled
|
||||
g, nodes = workflow_dag_canceled
|
||||
|
||||
assert g.has_workflow_failed() == (
|
||||
True,
|
||||
@@ -521,7 +521,7 @@ class TestIsWorkflowDone:
|
||||
)
|
||||
|
||||
def test_failure_should_fail(self, workflow_dag_failure):
|
||||
(g, nodes) = workflow_dag_failure
|
||||
g, nodes = workflow_dag_failure
|
||||
|
||||
assert g.has_workflow_failed() == (
|
||||
True,
|
||||
@@ -555,7 +555,7 @@ class TestBFSNodesToRun:
|
||||
return (g, nodes)
|
||||
|
||||
def test_cancel_still_runs_children(self, workflow_dag_canceled):
|
||||
(g, nodes) = workflow_dag_canceled
|
||||
g, nodes = workflow_dag_canceled
|
||||
g.mark_dnr_nodes()
|
||||
|
||||
assert set([nodes[1], nodes[2]]) == set(g.bfs_nodes_to_run())
|
||||
@@ -587,7 +587,7 @@ class TestDocsExample:
|
||||
return (g, nodes)
|
||||
|
||||
def test_dnr_step(self, complex_dag):
|
||||
(g, nodes) = complex_dag
|
||||
g, nodes = complex_dag
|
||||
base_dir = '/awx_devel'
|
||||
|
||||
g.generate_graphviz_plot(file_name=os.path.join(base_dir, "workflow_step0.gv"))
|
||||
|
||||
@@ -9,7 +9,6 @@ import pytest
|
||||
import awx
|
||||
from awx.main.db.profiled_pg.base import RecordedQueryLog
|
||||
|
||||
|
||||
QUERY = {'sql': 'SELECT * FROM main_job', 'time': '.01'}
|
||||
EXPLAIN = 'Seq Scan on public.main_job (cost=0.00..1.18 rows=18 width=86)'
|
||||
|
||||
|
||||
@@ -36,8 +36,7 @@ uri = URI(scheme="https", username="myusername", password="mypasswordwith%40", h
|
||||
TEST_CLEARTEXT.append(
|
||||
{
|
||||
'uri': uri,
|
||||
'text': textwrap.dedent(
|
||||
"""\
|
||||
'text': textwrap.dedent("""\
|
||||
PLAY [all] ********************************************************************
|
||||
|
||||
TASK: [delete project directory before update] ********************************
|
||||
@@ -59,9 +58,7 @@ TEST_CLEARTEXT.append(
|
||||
|
||||
localhost : ok=0 changed=0 unreachable=0 failed=1
|
||||
|
||||
"""
|
||||
% (uri.username, uri.password, str(uri), str(uri))
|
||||
),
|
||||
""" % (uri.username, uri.password, str(uri), str(uri))),
|
||||
'host_occurrences': 2,
|
||||
}
|
||||
)
|
||||
@@ -70,8 +67,7 @@ uri = URI(scheme="https", username="Dhh3U47nmC26xk9PKscV", password="PXPfWW8YzYr
|
||||
TEST_CLEARTEXT.append(
|
||||
{
|
||||
'uri': uri,
|
||||
'text': textwrap.dedent(
|
||||
"""\
|
||||
'text': textwrap.dedent("""\
|
||||
TASK: [update project using git] **
|
||||
failed: [localhost] => {"cmd": "/usr/bin/git ls-remote https://REDACTED:********", "failed": true, "rc": 128}
|
||||
stderr: error: Couldn't resolve host '@%s' while accessing %s
|
||||
@@ -81,9 +77,7 @@ TEST_CLEARTEXT.append(
|
||||
msg: error: Couldn't resolve host '@%s' while accessing %s
|
||||
|
||||
fatal: HTTP request failed
|
||||
"""
|
||||
% (uri.host, str(uri), uri.host, str(uri))
|
||||
),
|
||||
""" % (uri.host, str(uri), uri.host, str(uri))),
|
||||
'host_occurrences': 4,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from awx.main.views import ApiErrorView
|
||||
from awx.api.views import JobList
|
||||
from awx.api.generics import ListCreateAPIView, SubListAttachDetachAPIView
|
||||
|
||||
|
||||
HTTP_METHOD_NAMES = [
|
||||
'get',
|
||||
'post',
|
||||
|
||||
@@ -4,7 +4,6 @@ from unittest import mock
|
||||
|
||||
from awx.main.utils.analytics_proxy import OIDCClient, TokenType, TokenError
|
||||
|
||||
|
||||
MOCK_TOKEN_RESPONSE = {
|
||||
'access_token': 'bob-access-token',
|
||||
'expires_in': 500,
|
||||
|
||||
@@ -6,7 +6,6 @@ import pytest
|
||||
|
||||
from awx_plugins.interfaces._temporary_private_container_api import get_incontainer_path
|
||||
|
||||
|
||||
private_data_dir = '/tmp/pdd_iso/awx_xxx'
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user