mirror of
https://github.com/ansible/awx.git
synced 2026-05-17 06:17:36 -02:30
remove old task manager code
This commit is contained in:
@@ -4,7 +4,6 @@
|
|||||||
# Python
|
# Python
|
||||||
import datetime
|
import datetime
|
||||||
import hmac
|
import hmac
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
from urlparse import urljoin
|
from urlparse import urljoin
|
||||||
|
|
||||||
@@ -24,7 +23,6 @@ from jsonfield import JSONField
|
|||||||
# AWX
|
# AWX
|
||||||
from awx.main.models.base import * # noqa
|
from awx.main.models.base import * # noqa
|
||||||
from awx.main.models.unified_jobs import * # noqa
|
from awx.main.models.unified_jobs import * # noqa
|
||||||
from awx.main.utils import decrypt_field
|
|
||||||
from awx.main.models.notifications import JobNotificationMixin
|
from awx.main.models.notifications import JobNotificationMixin
|
||||||
|
|
||||||
logger = logging.getLogger('awx.main.models.ad_hoc_commands')
|
logger = logging.getLogger('awx.main.models.ad_hoc_commands')
|
||||||
@@ -181,13 +179,6 @@ class AdHocCommand(UnifiedJob, JobNotificationMixin):
|
|||||||
def get_passwords_needed_to_start(self):
|
def get_passwords_needed_to_start(self):
|
||||||
return self.passwords_needed_to_start
|
return self.passwords_needed_to_start
|
||||||
|
|
||||||
def is_blocked_by(self, obj):
|
|
||||||
from awx.main.models import InventoryUpdate
|
|
||||||
if type(obj) == InventoryUpdate:
|
|
||||||
if self.inventory == obj.inventory_source.inventory:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def task_impact(self):
|
def task_impact(self):
|
||||||
# NOTE: We sorta have to assume the host count matches and that forks default to 5
|
# NOTE: We sorta have to assume the host count matches and that forks default to 5
|
||||||
@@ -195,35 +186,6 @@ class AdHocCommand(UnifiedJob, JobNotificationMixin):
|
|||||||
count_hosts = Host.objects.filter( enabled=True, inventory__ad_hoc_commands__pk=self.pk).count()
|
count_hosts = Host.objects.filter( enabled=True, inventory__ad_hoc_commands__pk=self.pk).count()
|
||||||
return min(count_hosts, 5 if self.forks == 0 else self.forks) * 10
|
return min(count_hosts, 5 if self.forks == 0 else self.forks) * 10
|
||||||
|
|
||||||
def generate_dependencies(self, active_tasks):
|
|
||||||
from awx.main.models import InventoryUpdate
|
|
||||||
if not self.inventory:
|
|
||||||
return []
|
|
||||||
inventory_sources = self.inventory.inventory_sources.filter( update_on_launch=True)
|
|
||||||
inventory_sources_found = []
|
|
||||||
dependencies = []
|
|
||||||
for obj in active_tasks:
|
|
||||||
if type(obj) == InventoryUpdate:
|
|
||||||
if obj.inventory_source in inventory_sources:
|
|
||||||
inventory_sources_found.append(obj.inventory_source)
|
|
||||||
# Skip updating any inventory sources that were already updated before
|
|
||||||
# running this job (via callback inventory refresh).
|
|
||||||
try:
|
|
||||||
start_args = json.loads(decrypt_field(self, 'start_args'))
|
|
||||||
except Exception:
|
|
||||||
start_args = None
|
|
||||||
start_args = start_args or {}
|
|
||||||
inventory_sources_already_updated = start_args.get('inventory_sources_already_updated', [])
|
|
||||||
if inventory_sources_already_updated:
|
|
||||||
for source in inventory_sources.filter(pk__in=inventory_sources_already_updated):
|
|
||||||
if source not in inventory_sources_found:
|
|
||||||
inventory_sources_found.append(source)
|
|
||||||
if inventory_sources.count(): # and not has_setup_failures? Probably handled as an error scenario in the task runner
|
|
||||||
for source in inventory_sources:
|
|
||||||
if source not in inventory_sources_found and source.needs_update_on_launch:
|
|
||||||
dependencies.append(source.create_inventory_update(launch_type='dependency'))
|
|
||||||
return dependencies
|
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
data = {}
|
data = {}
|
||||||
for field in ('job_type', 'inventory_id', 'limit', 'credential_id',
|
for field in ('job_type', 'inventory_id', 'limit', 'credential_id',
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ from awx.main.constants import CLOUD_PROVIDERS
|
|||||||
from awx.main.fields import AutoOneToOneField, ImplicitRoleField
|
from awx.main.fields import AutoOneToOneField, ImplicitRoleField
|
||||||
from awx.main.managers import HostManager
|
from awx.main.managers import HostManager
|
||||||
from awx.main.models.base import * # noqa
|
from awx.main.models.base import * # noqa
|
||||||
from awx.main.models.jobs import Job
|
|
||||||
from awx.main.models.unified_jobs import * # noqa
|
from awx.main.models.unified_jobs import * # noqa
|
||||||
from awx.main.models.mixins import ResourceMixin
|
from awx.main.models.mixins import ResourceMixin
|
||||||
from awx.main.models.notifications import (
|
from awx.main.models.notifications import (
|
||||||
@@ -1250,15 +1249,6 @@ class InventoryUpdate(UnifiedJob, InventorySourceOptions, JobNotificationMixin):
|
|||||||
def get_ui_url(self):
|
def get_ui_url(self):
|
||||||
return urljoin(settings.TOWER_URL_BASE, "/#/inventory_sync/{}".format(self.pk))
|
return urljoin(settings.TOWER_URL_BASE, "/#/inventory_sync/{}".format(self.pk))
|
||||||
|
|
||||||
def is_blocked_by(self, obj):
|
|
||||||
if type(obj) == InventoryUpdate:
|
|
||||||
if self.inventory_source.inventory == obj.inventory_source.inventory:
|
|
||||||
return True
|
|
||||||
if type(obj) == Job:
|
|
||||||
if self.inventory_source.inventory == obj.inventory:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def task_impact(self):
|
def task_impact(self):
|
||||||
return 50
|
return 50
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ from awx.main.models.notifications import (
|
|||||||
NotificationTemplate,
|
NotificationTemplate,
|
||||||
JobNotificationMixin,
|
JobNotificationMixin,
|
||||||
)
|
)
|
||||||
from awx.main.utils import decrypt_field, ignore_inventory_computed_fields
|
from awx.main.utils import ignore_inventory_computed_fields
|
||||||
from awx.main.redact import PlainTextCleaner
|
from awx.main.redact import PlainTextCleaner
|
||||||
from awx.main.fields import ImplicitRoleField
|
from awx.main.fields import ImplicitRoleField
|
||||||
from awx.main.models.mixins import ResourceMixin
|
from awx.main.models.mixins import ResourceMixin
|
||||||
@@ -646,29 +646,6 @@ class Job(UnifiedJob, JobOptions, JobNotificationMixin):
|
|||||||
kwargs['job_host_summaries__job__pk'] = self.pk
|
kwargs['job_host_summaries__job__pk'] = self.pk
|
||||||
return Host.objects.filter(**kwargs)
|
return Host.objects.filter(**kwargs)
|
||||||
|
|
||||||
def is_blocked_by(self, obj):
|
|
||||||
from awx.main.models import InventoryUpdate, ProjectUpdate
|
|
||||||
if type(obj) == Job:
|
|
||||||
if obj.job_template is not None and obj.inventory is not None:
|
|
||||||
if obj.job_template == self.job_template and \
|
|
||||||
obj.inventory == self.inventory:
|
|
||||||
if self.allow_simultaneous:
|
|
||||||
return False
|
|
||||||
if obj.launch_type == 'callback' and self.launch_type == 'callback' and \
|
|
||||||
obj.limit != self.limit:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
if type(obj) == InventoryUpdate:
|
|
||||||
if self.inventory == obj.inventory_source.inventory:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
if type(obj) == ProjectUpdate:
|
|
||||||
if obj.project == self.project:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def task_impact(self):
|
def task_impact(self):
|
||||||
# NOTE: We sorta have to assume the host count matches and that forks default to 5
|
# NOTE: We sorta have to assume the host count matches and that forks default to 5
|
||||||
@@ -707,39 +684,6 @@ class Job(UnifiedJob, JobOptions, JobNotificationMixin):
|
|||||||
def processed_hosts(self):
|
def processed_hosts(self):
|
||||||
return self._get_hosts(job_host_summaries__processed__gt=0)
|
return self._get_hosts(job_host_summaries__processed__gt=0)
|
||||||
|
|
||||||
def generate_dependencies(self, active_tasks):
|
|
||||||
from awx.main.models import InventoryUpdate, ProjectUpdate
|
|
||||||
inventory_sources = self.inventory.inventory_sources.filter(update_on_launch=True)
|
|
||||||
project_found = False
|
|
||||||
inventory_sources_found = []
|
|
||||||
dependencies = []
|
|
||||||
for obj in active_tasks:
|
|
||||||
if type(obj) == ProjectUpdate and self.project is not None:
|
|
||||||
if obj.project == self.project:
|
|
||||||
project_found = True
|
|
||||||
if type(obj) == InventoryUpdate:
|
|
||||||
if obj.inventory_source in inventory_sources:
|
|
||||||
inventory_sources_found.append(obj.inventory_source)
|
|
||||||
# Skip updating any inventory sources that were already updated before
|
|
||||||
# running this job (via callback inventory refresh).
|
|
||||||
try:
|
|
||||||
start_args = json.loads(decrypt_field(self, 'start_args'))
|
|
||||||
except Exception:
|
|
||||||
start_args = None
|
|
||||||
start_args = start_args or {}
|
|
||||||
inventory_sources_already_updated = start_args.get('inventory_sources_already_updated', [])
|
|
||||||
if inventory_sources_already_updated:
|
|
||||||
for source in inventory_sources.filter(pk__in=inventory_sources_already_updated):
|
|
||||||
if source not in inventory_sources_found:
|
|
||||||
inventory_sources_found.append(source)
|
|
||||||
if not project_found and self.project is not None and self.project.needs_update_on_launch:
|
|
||||||
dependencies.append(self.project.create_project_update(launch_type='dependency'))
|
|
||||||
if inventory_sources.count(): # and not has_setup_failures? Probably handled as an error scenario in the task runner
|
|
||||||
for source in inventory_sources:
|
|
||||||
if source not in inventory_sources_found and source.needs_update_on_launch:
|
|
||||||
dependencies.append(source.create_inventory_update(launch_type='dependency'))
|
|
||||||
return dependencies
|
|
||||||
|
|
||||||
def notification_data(self, block=5):
|
def notification_data(self, block=5):
|
||||||
data = super(Job, self).notification_data()
|
data = super(Job, self).notification_data()
|
||||||
all_hosts = {}
|
all_hosts = {}
|
||||||
@@ -1526,9 +1470,6 @@ class SystemJob(UnifiedJob, SystemJobOptions, JobNotificationMixin):
|
|||||||
def get_ui_url(self):
|
def get_ui_url(self):
|
||||||
return urljoin(settings.TOWER_URL_BASE, "/#/management_jobs/{}".format(self.pk))
|
return urljoin(settings.TOWER_URL_BASE, "/#/management_jobs/{}".format(self.pk))
|
||||||
|
|
||||||
def is_blocked_by(self, obj):
|
|
||||||
return True
|
|
||||||
|
|
||||||
def handle_extra_data(self, extra_data):
|
def handle_extra_data(self, extra_data):
|
||||||
extra_vars = {}
|
extra_vars = {}
|
||||||
if isinstance(extra_data, dict):
|
if isinstance(extra_data, dict):
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ from django.utils.timezone import now, make_aware, get_default_timezone
|
|||||||
|
|
||||||
# AWX
|
# AWX
|
||||||
from awx.main.models.base import * # noqa
|
from awx.main.models.base import * # noqa
|
||||||
from awx.main.models.jobs import Job
|
|
||||||
from awx.main.models.notifications import (
|
from awx.main.models.notifications import (
|
||||||
NotificationTemplate,
|
NotificationTemplate,
|
||||||
JobNotificationMixin,
|
JobNotificationMixin,
|
||||||
@@ -424,15 +423,6 @@ class ProjectUpdate(UnifiedJob, ProjectOptions, JobNotificationMixin):
|
|||||||
from awx.main.tasks import RunProjectUpdate
|
from awx.main.tasks import RunProjectUpdate
|
||||||
return RunProjectUpdate
|
return RunProjectUpdate
|
||||||
|
|
||||||
def is_blocked_by(self, obj):
|
|
||||||
if type(obj) == ProjectUpdate:
|
|
||||||
if self.project == obj.project:
|
|
||||||
return True
|
|
||||||
if type(obj) == Job:
|
|
||||||
if self.project == obj.project:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def websocket_emit_data(self):
|
def websocket_emit_data(self):
|
||||||
return dict(project_id=self.project.id)
|
return dict(project_id=self.project.id)
|
||||||
|
|
||||||
|
|||||||
@@ -778,10 +778,6 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
|||||||
def task_impact(self):
|
def task_impact(self):
|
||||||
raise NotImplementedError # Implement in subclass.
|
raise NotImplementedError # Implement in subclass.
|
||||||
|
|
||||||
def is_blocked_by(self, task_object):
|
|
||||||
''' Given another task object determine if this task would be blocked by it '''
|
|
||||||
raise NotImplementedError # Implement in subclass.
|
|
||||||
|
|
||||||
def websocket_emit_data(self):
|
def websocket_emit_data(self):
|
||||||
''' Return extra data that should be included when submitting data to the browser over the websocket connection '''
|
''' Return extra data that should be included when submitting data to the browser over the websocket connection '''
|
||||||
return {}
|
return {}
|
||||||
@@ -792,11 +788,6 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
|||||||
status_data['group_name'] = 'jobs'
|
status_data['group_name'] = 'jobs'
|
||||||
emit_channel_notification('jobs-status_changed', status_data)
|
emit_channel_notification('jobs-status_changed', status_data)
|
||||||
|
|
||||||
def generate_dependencies(self, active_tasks):
|
|
||||||
''' Generate any tasks that the current task might be dependent on given a list of active
|
|
||||||
tasks that might preclude creating one'''
|
|
||||||
return []
|
|
||||||
|
|
||||||
def notification_data(self):
|
def notification_data(self):
|
||||||
return dict(id=self.id,
|
return dict(id=self.id,
|
||||||
name=self.name,
|
name=self.name,
|
||||||
|
|||||||
@@ -406,9 +406,6 @@ class WorkflowJob(UnifiedJob, WorkflowJobOptions, JobNotificationMixin, Workflow
|
|||||||
#def get_ui_url(self):
|
#def get_ui_url(self):
|
||||||
# return urlparse.urljoin(tower_settings.TOWER_URL_BASE, "/#/workflow_jobs/{}".format(self.pk))
|
# return urlparse.urljoin(tower_settings.TOWER_URL_BASE, "/#/workflow_jobs/{}".format(self.pk))
|
||||||
|
|
||||||
def is_blocked_by(self, obj):
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def task_impact(self):
|
def task_impact(self):
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -2,40 +2,6 @@ from awx.main.models import Job
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_job_blocking(get, post, job_template, inventory, inventory_factory):
|
|
||||||
j1 = Job.objects.create(job_template=job_template,
|
|
||||||
inventory=inventory)
|
|
||||||
j2 = Job.objects.create(job_template=job_template,
|
|
||||||
inventory=inventory)
|
|
||||||
assert j1.is_blocked_by(j2)
|
|
||||||
j2.inventory = inventory_factory(name='test-different-inventory')
|
|
||||||
assert not j1.is_blocked_by(j2)
|
|
||||||
j_callback_1 = Job.objects.create(job_template=job_template,
|
|
||||||
inventory=inventory,
|
|
||||||
launch_type='callback',
|
|
||||||
limit='a')
|
|
||||||
j_callback_2 = Job.objects.create(job_template=job_template,
|
|
||||||
inventory=inventory,
|
|
||||||
launch_type='callback',
|
|
||||||
limit='a')
|
|
||||||
assert j_callback_1.is_blocked_by(j_callback_2)
|
|
||||||
j_callback_2.limit = 'b'
|
|
||||||
assert not j_callback_1.is_blocked_by(j_callback_2)
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_job_blocking_allow_simul(get, post, job_template, inventory):
|
|
||||||
job_template.allow_simultaneous = True
|
|
||||||
j1 = Job.objects.create(job_template=job_template,
|
|
||||||
inventory=inventory)
|
|
||||||
j2 = Job.objects.create(job_template=job_template,
|
|
||||||
inventory=inventory)
|
|
||||||
assert not j1.is_blocked_by(j2)
|
|
||||||
assert not j2.is_blocked_by(j1)
|
|
||||||
job_template.allow_simultaneous = False
|
|
||||||
assert j1.is_blocked_by(j2)
|
|
||||||
assert j2.is_blocked_by(j1)
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_orphan_unified_job_creation(instance, inventory):
|
def test_orphan_unified_job_creation(instance, inventory):
|
||||||
job = Job.objects.create(job_template=None, inventory=inventory, name='hi world')
|
job = Job.objects.create(job_template=None, inventory=inventory, name='hi world')
|
||||||
|
|||||||
Reference in New Issue
Block a user