2019-09-17 10:59:54 +00:00
|
|
|
# ~*~ coding: utf-8 ~*~
|
|
|
|
from celery import shared_task
|
2023-02-17 09:14:53 +00:00
|
|
|
from django.utils.translation import gettext_noop, gettext_lazy as _
|
2019-09-17 10:59:54 +00:00
|
|
|
|
2023-02-08 05:53:21 +00:00
|
|
|
from assets.const import AutomationTypes
|
2023-02-08 02:14:09 +00:00
|
|
|
from common.utils import get_logger
|
2023-02-17 09:14:53 +00:00
|
|
|
from orgs.utils import tmp_to_org, current_org
|
2023-02-08 05:53:21 +00:00
|
|
|
from .common import quickstart_automation
|
2019-09-17 10:59:54 +00:00
|
|
|
|
|
|
|
logger = get_logger(__file__)
|
2023-01-16 11:02:09 +00:00
|
|
|
|
2020-03-12 08:24:38 +00:00
|
|
|
__all__ = [
|
2023-02-08 02:14:09 +00:00
|
|
|
'test_assets_connectivity_task',
|
2022-11-01 11:37:50 +00:00
|
|
|
'test_assets_connectivity_manual',
|
|
|
|
'test_node_assets_connectivity_manual',
|
2020-03-12 08:24:38 +00:00
|
|
|
]
|
2019-09-17 10:59:54 +00:00
|
|
|
|
|
|
|
|
2023-02-17 09:14:53 +00:00
|
|
|
@shared_task(
|
|
|
|
verbose_name=_('Test assets connectivity'), queue='ansible',
|
|
|
|
activity_callback=lambda self, asset_ids, org_id, *args, **kwargs: (asset_ids, org_id)
|
|
|
|
)
|
|
|
|
def test_assets_connectivity_task(asset_ids, org_id, task_name=None):
|
2022-11-01 11:37:50 +00:00
|
|
|
from assets.models import PingAutomation
|
2019-09-17 10:59:54 +00:00
|
|
|
if task_name is None:
|
2023-02-17 09:14:53 +00:00
|
|
|
task_name = gettext_noop("Test assets connectivity")
|
2019-09-17 10:59:54 +00:00
|
|
|
|
2022-11-01 11:37:50 +00:00
|
|
|
task_name = PingAutomation.generate_unique_name(task_name)
|
2023-02-17 09:14:53 +00:00
|
|
|
task_snapshot = {'assets': asset_ids}
|
|
|
|
with tmp_to_org(org_id):
|
|
|
|
quickstart_automation(task_name, AutomationTypes.ping, task_snapshot)
|
2020-03-12 08:24:38 +00:00
|
|
|
|
2021-01-06 03:08:35 +00:00
|
|
|
|
2023-02-17 09:14:53 +00:00
|
|
|
def test_assets_connectivity_manual(assets):
|
2022-11-02 09:27:47 +00:00
|
|
|
task_name = gettext_noop("Test assets connectivity ")
|
2023-02-22 12:31:20 +00:00
|
|
|
asset_ids = [str(i.id) for i in assets]
|
2023-02-17 09:14:53 +00:00
|
|
|
org_id = str(current_org.id)
|
|
|
|
return test_assets_connectivity_task.delay(asset_ids, org_id, task_name)
|
2021-01-06 03:08:35 +00:00
|
|
|
|
|
|
|
|
2023-02-17 09:14:53 +00:00
|
|
|
def test_node_assets_connectivity_manual(node):
|
2022-11-02 09:27:47 +00:00
|
|
|
task_name = gettext_noop("Test if the assets under the node are connectable ")
|
2023-02-17 09:14:53 +00:00
|
|
|
asset_ids = node.get_all_asset_ids()
|
2023-02-22 12:31:20 +00:00
|
|
|
asset_ids = [str(i) for i in asset_ids]
|
2023-02-17 09:14:53 +00:00
|
|
|
org_id = str(current_org.id)
|
|
|
|
return test_assets_connectivity_task.delay(asset_ids, org_id, task_name)
|