mirror of
https://github.com/ansible/awx.git
synced 2026-03-30 23:35:05 -02:30
Compare commits
31 Commits
constructe
...
revert-136
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44fa30f91b | ||
|
|
2902b40084 | ||
|
|
9669b9dd2f | ||
|
|
d27aada817 | ||
|
|
2fca07ee4c | ||
|
|
f4bcc03ac7 | ||
|
|
5e28f5dca1 | ||
|
|
d088d36448 | ||
|
|
89e41597a6 | ||
|
|
283adc30a8 | ||
|
|
019e6a52fe | ||
|
|
35e5610642 | ||
|
|
3a303875bb | ||
|
|
4499a50019 | ||
|
|
3fe46e2e27 | ||
|
|
6d3f39fe92 | ||
|
|
a3233b5fdd | ||
|
|
fe3aa6ce2b | ||
|
|
77ec46f6cf | ||
|
|
b5f240ce70 | ||
|
|
fb2647ff7b | ||
|
|
23a34c5dc9 | ||
|
|
bef3da6fb2 | ||
|
|
7f50679e68 | ||
|
|
52d071f9d1 | ||
|
|
26a888547d | ||
|
|
eb9431ee1f | ||
|
|
fd6605932a | ||
|
|
5d96ee084d | ||
|
|
e2cee10767 | ||
|
|
31c2e1a450 |
1
.github/workflows/promote.yml
vendored
1
.github/workflows/promote.yml
vendored
@@ -10,6 +10,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
promote:
|
promote:
|
||||||
|
if: endsWith(github.repository, '/awx')
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout awx
|
- name: Checkout awx
|
||||||
|
|||||||
1
.github/workflows/stage.yml
vendored
1
.github/workflows/stage.yml
vendored
@@ -21,6 +21,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
stage:
|
stage:
|
||||||
|
if: endsWith(github.repository, '/awx')
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
packages: write
|
packages: write
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ from rest_framework import generics
|
|||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework import views
|
from rest_framework import views
|
||||||
from rest_framework.permissions import AllowAny
|
from rest_framework.permissions import IsAuthenticated
|
||||||
from rest_framework.renderers import StaticHTMLRenderer
|
from rest_framework.renderers import StaticHTMLRenderer
|
||||||
from rest_framework.negotiation import DefaultContentNegotiation
|
from rest_framework.negotiation import DefaultContentNegotiation
|
||||||
|
|
||||||
@@ -822,7 +822,7 @@ def trigger_delayed_deep_copy(*args, **kwargs):
|
|||||||
|
|
||||||
class CopyAPIView(GenericAPIView):
|
class CopyAPIView(GenericAPIView):
|
||||||
serializer_class = CopySerializer
|
serializer_class = CopySerializer
|
||||||
permission_classes = (AllowAny,)
|
permission_classes = (IsAuthenticated,)
|
||||||
copy_return_serializer_class = None
|
copy_return_serializer_class = None
|
||||||
new_in_330 = True
|
new_in_330 = True
|
||||||
new_in_api_v2 = True
|
new_in_api_v2 = True
|
||||||
|
|||||||
@@ -1680,8 +1680,13 @@ class InventorySerializer(LabelsListMixin, BaseSerializerWithVariables):
|
|||||||
res.update(
|
res.update(
|
||||||
dict(
|
dict(
|
||||||
hosts=self.reverse('api:inventory_hosts_list', kwargs={'pk': obj.pk}),
|
hosts=self.reverse('api:inventory_hosts_list', kwargs={'pk': obj.pk}),
|
||||||
|
groups=self.reverse('api:inventory_groups_list', kwargs={'pk': obj.pk}),
|
||||||
|
root_groups=self.reverse('api:inventory_root_groups_list', kwargs={'pk': obj.pk}),
|
||||||
variable_data=self.reverse('api:inventory_variable_data', kwargs={'pk': obj.pk}),
|
variable_data=self.reverse('api:inventory_variable_data', kwargs={'pk': obj.pk}),
|
||||||
script=self.reverse('api:inventory_script_view', kwargs={'pk': obj.pk}),
|
script=self.reverse('api:inventory_script_view', kwargs={'pk': obj.pk}),
|
||||||
|
tree=self.reverse('api:inventory_tree_view', kwargs={'pk': obj.pk}),
|
||||||
|
inventory_sources=self.reverse('api:inventory_inventory_sources_list', kwargs={'pk': obj.pk}),
|
||||||
|
update_inventory_sources=self.reverse('api:inventory_inventory_sources_update', kwargs={'pk': obj.pk}),
|
||||||
activity_stream=self.reverse('api:inventory_activity_stream_list', kwargs={'pk': obj.pk}),
|
activity_stream=self.reverse('api:inventory_activity_stream_list', kwargs={'pk': obj.pk}),
|
||||||
job_templates=self.reverse('api:inventory_job_template_list', kwargs={'pk': obj.pk}),
|
job_templates=self.reverse('api:inventory_job_template_list', kwargs={'pk': obj.pk}),
|
||||||
ad_hoc_commands=self.reverse('api:inventory_ad_hoc_commands_list', kwargs={'pk': obj.pk}),
|
ad_hoc_commands=self.reverse('api:inventory_ad_hoc_commands_list', kwargs={'pk': obj.pk}),
|
||||||
@@ -1692,18 +1697,8 @@ class InventorySerializer(LabelsListMixin, BaseSerializerWithVariables):
|
|||||||
labels=self.reverse('api:inventory_label_list', kwargs={'pk': obj.pk}),
|
labels=self.reverse('api:inventory_label_list', kwargs={'pk': obj.pk}),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if obj.kind in ('', 'constructed'):
|
|
||||||
# links not relevant for the "old" smart inventory
|
|
||||||
res['groups'] = self.reverse('api:inventory_groups_list', kwargs={'pk': obj.pk})
|
|
||||||
res['root_groups'] = self.reverse('api:inventory_root_groups_list', kwargs={'pk': obj.pk})
|
|
||||||
res['update_inventory_sources'] = self.reverse('api:inventory_inventory_sources_update', kwargs={'pk': obj.pk})
|
|
||||||
res['inventory_sources'] = self.reverse('api:inventory_inventory_sources_list', kwargs={'pk': obj.pk})
|
|
||||||
res['tree'] = self.reverse('api:inventory_tree_view', kwargs={'pk': obj.pk})
|
|
||||||
if obj.organization:
|
if obj.organization:
|
||||||
res['organization'] = self.reverse('api:organization_detail', kwargs={'pk': obj.organization.pk})
|
res['organization'] = self.reverse('api:organization_detail', kwargs={'pk': obj.organization.pk})
|
||||||
if obj.kind == 'constructed':
|
|
||||||
res['input_inventories'] = self.reverse('api:inventory_input_inventories', kwargs={'pk': obj.pk})
|
|
||||||
res['constructed_url'] = self.reverse('api:constructed_inventory_detail', kwargs={'pk': obj.pk})
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def to_representation(self, obj):
|
def to_representation(self, obj):
|
||||||
@@ -1745,91 +1740,6 @@ class InventorySerializer(LabelsListMixin, BaseSerializerWithVariables):
|
|||||||
return super(InventorySerializer, self).validate(attrs)
|
return super(InventorySerializer, self).validate(attrs)
|
||||||
|
|
||||||
|
|
||||||
class ConstructedFieldMixin(serializers.Field):
|
|
||||||
def get_attribute(self, instance):
|
|
||||||
if not hasattr(instance, '_constructed_inv_src'):
|
|
||||||
instance._constructed_inv_src = instance.inventory_sources.first()
|
|
||||||
inv_src = instance._constructed_inv_src
|
|
||||||
return super().get_attribute(inv_src) # yoink
|
|
||||||
|
|
||||||
|
|
||||||
class ConstructedCharField(ConstructedFieldMixin, serializers.CharField):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class ConstructedIntegerField(ConstructedFieldMixin, serializers.IntegerField):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class ConstructedInventorySerializer(InventorySerializer):
|
|
||||||
source_vars = ConstructedCharField(
|
|
||||||
required=False,
|
|
||||||
default=None,
|
|
||||||
allow_blank=True,
|
|
||||||
help_text=_('The source_vars for the related auto-created inventory source, special to constructed inventory.'),
|
|
||||||
)
|
|
||||||
update_cache_timeout = ConstructedIntegerField(
|
|
||||||
required=False,
|
|
||||||
allow_null=True,
|
|
||||||
min_value=0,
|
|
||||||
default=None,
|
|
||||||
help_text=_('The cache timeout for the related auto-created inventory source, special to constructed inventory'),
|
|
||||||
)
|
|
||||||
limit = ConstructedCharField(
|
|
||||||
required=False,
|
|
||||||
default=None,
|
|
||||||
allow_blank=True,
|
|
||||||
help_text=_('The limit to restrict the returned hosts for the related auto-created inventory source, special to constructed inventory.'),
|
|
||||||
)
|
|
||||||
verbosity = ConstructedIntegerField(
|
|
||||||
required=False,
|
|
||||||
allow_null=True,
|
|
||||||
min_value=0,
|
|
||||||
max_value=2,
|
|
||||||
default=None,
|
|
||||||
help_text=_('The verbosity level for the related auto-created inventory source, special to constructed inventory'),
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Inventory
|
|
||||||
fields = ('*', '-host_filter', 'source_vars', 'update_cache_timeout', 'limit', 'verbosity')
|
|
||||||
read_only_fields = ('*', 'kind')
|
|
||||||
|
|
||||||
def pop_inv_src_data(self, data):
|
|
||||||
inv_src_data = {}
|
|
||||||
for field in ('source_vars', 'update_cache_timeout', 'limit', 'verbosity'):
|
|
||||||
if field in data:
|
|
||||||
# values always need to be removed, as they are not valid for Inventory model
|
|
||||||
value = data.pop(field)
|
|
||||||
# null is not valid for any of those fields, taken as not-provided
|
|
||||||
if value is not None:
|
|
||||||
inv_src_data[field] = value
|
|
||||||
return inv_src_data
|
|
||||||
|
|
||||||
def apply_inv_src_data(self, inventory, inv_src_data):
|
|
||||||
if inv_src_data:
|
|
||||||
update_fields = []
|
|
||||||
inv_src = inventory.inventory_sources.first()
|
|
||||||
for field, value in inv_src_data.items():
|
|
||||||
setattr(inv_src, field, value)
|
|
||||||
update_fields.append(field)
|
|
||||||
if update_fields:
|
|
||||||
inv_src.save(update_fields=update_fields)
|
|
||||||
|
|
||||||
def create(self, validated_data):
|
|
||||||
validated_data['kind'] = 'constructed'
|
|
||||||
inv_src_data = self.pop_inv_src_data(validated_data)
|
|
||||||
inventory = super().create(validated_data)
|
|
||||||
self.apply_inv_src_data(inventory, inv_src_data)
|
|
||||||
return inventory
|
|
||||||
|
|
||||||
def update(self, obj, validated_data):
|
|
||||||
inv_src_data = self.pop_inv_src_data(validated_data)
|
|
||||||
obj = super().update(obj, validated_data)
|
|
||||||
self.apply_inv_src_data(obj, inv_src_data)
|
|
||||||
return obj
|
|
||||||
|
|
||||||
|
|
||||||
class InventoryScriptSerializer(InventorySerializer):
|
class InventoryScriptSerializer(InventorySerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
fields = ()
|
fields = ()
|
||||||
@@ -1883,8 +1793,6 @@ class HostSerializer(BaseSerializerWithVariables):
|
|||||||
ansible_facts=self.reverse('api:host_ansible_facts_detail', kwargs={'pk': obj.pk}),
|
ansible_facts=self.reverse('api:host_ansible_facts_detail', kwargs={'pk': obj.pk}),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if obj.inventory.kind == 'constructed':
|
|
||||||
res['original_host'] = self.reverse('api:host_detail', kwargs={'pk': obj.instance_id})
|
|
||||||
if obj.inventory:
|
if obj.inventory:
|
||||||
res['inventory'] = self.reverse('api:inventory_detail', kwargs={'pk': obj.inventory.pk})
|
res['inventory'] = self.reverse('api:inventory_detail', kwargs={'pk': obj.inventory.pk})
|
||||||
if obj.last_job:
|
if obj.last_job:
|
||||||
@@ -1941,8 +1849,8 @@ class HostSerializer(BaseSerializerWithVariables):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
def validate_inventory(self, value):
|
def validate_inventory(self, value):
|
||||||
if value.kind in ('constructed', 'smart'):
|
if value.kind == 'smart':
|
||||||
raise serializers.ValidationError({"detail": _("Cannot create Host for Smart or Constructed Inventories")})
|
raise serializers.ValidationError({"detail": _("Cannot create Host for Smart Inventory")})
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def validate_variables(self, value):
|
def validate_variables(self, value):
|
||||||
@@ -2040,8 +1948,8 @@ class GroupSerializer(BaseSerializerWithVariables):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
def validate_inventory(self, value):
|
def validate_inventory(self, value):
|
||||||
if value.kind in ('constructed', 'smart'):
|
if value.kind == 'smart':
|
||||||
raise serializers.ValidationError({"detail": _("Cannot create Group for Smart or Constructed Inventories")})
|
raise serializers.ValidationError({"detail": _("Cannot create Group for Smart Inventory")})
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def to_representation(self, obj):
|
def to_representation(self, obj):
|
||||||
@@ -2115,7 +2023,6 @@ class InventorySourceOptionsSerializer(BaseSerializer):
|
|||||||
'custom_virtualenv',
|
'custom_virtualenv',
|
||||||
'timeout',
|
'timeout',
|
||||||
'verbosity',
|
'verbosity',
|
||||||
'limit',
|
|
||||||
)
|
)
|
||||||
read_only_fields = ('*', 'custom_virtualenv')
|
read_only_fields = ('*', 'custom_virtualenv')
|
||||||
|
|
||||||
@@ -2222,8 +2129,8 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
def validate_inventory(self, value):
|
def validate_inventory(self, value):
|
||||||
if value and value.kind in ('constructed', 'smart'):
|
if value and value.kind == 'smart':
|
||||||
raise serializers.ValidationError({"detail": _("Cannot create Inventory Source for Smart or Constructed Inventories")})
|
raise serializers.ValidationError({"detail": _("Cannot create Inventory Source for Smart Inventory")})
|
||||||
return value
|
return value
|
||||||
|
|
||||||
# TODO: remove when old 'credential' fields are removed
|
# TODO: remove when old 'credential' fields are removed
|
||||||
@@ -2244,8 +2151,6 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt
|
|||||||
obj = super(InventorySourceSerializer, self).update(obj, validated_data)
|
obj = super(InventorySourceSerializer, self).update(obj, validated_data)
|
||||||
if deprecated_fields:
|
if deprecated_fields:
|
||||||
self._update_deprecated_fields(deprecated_fields, obj)
|
self._update_deprecated_fields(deprecated_fields, obj)
|
||||||
if obj.source == 'constructed':
|
|
||||||
raise serializers.ValidationError({'error': _("Cannot edit source of type constructed.")})
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
# TODO: remove when old 'credential' fields are removed
|
# TODO: remove when old 'credential' fields are removed
|
||||||
@@ -2272,8 +2177,6 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt
|
|||||||
if get_field_from_model_or_attrs('source') == 'scm':
|
if get_field_from_model_or_attrs('source') == 'scm':
|
||||||
if ('source' in attrs or 'source_project' in attrs) and get_field_from_model_or_attrs('source_project') is None:
|
if ('source' in attrs or 'source_project' in attrs) and get_field_from_model_or_attrs('source_project') is None:
|
||||||
raise serializers.ValidationError({"source_project": _("Project required for scm type sources.")})
|
raise serializers.ValidationError({"source_project": _("Project required for scm type sources.")})
|
||||||
elif (get_field_from_model_or_attrs('source') == 'constructed') and (self.instance and self.instance.source != 'constructed'):
|
|
||||||
raise serializers.ValidationError({"Error": _('constructed not a valid source for inventory')})
|
|
||||||
else:
|
else:
|
||||||
redundant_scm_fields = list(filter(lambda x: attrs.get(x, None), ['source_project', 'source_path']))
|
redundant_scm_fields = list(filter(lambda x: attrs.get(x, None), ['source_project', 'source_path']))
|
||||||
if redundant_scm_fields:
|
if redundant_scm_fields:
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ from django.urls import re_path
|
|||||||
from awx.api.views.inventory import (
|
from awx.api.views.inventory import (
|
||||||
InventoryList,
|
InventoryList,
|
||||||
InventoryDetail,
|
InventoryDetail,
|
||||||
ConstructedInventoryDetail,
|
|
||||||
ConstructedInventoryList,
|
|
||||||
InventoryActivityStreamList,
|
InventoryActivityStreamList,
|
||||||
InventoryInputInventoriesList,
|
|
||||||
InventoryJobTemplateList,
|
InventoryJobTemplateList,
|
||||||
InventoryAccessList,
|
InventoryAccessList,
|
||||||
InventoryObjectRolesList,
|
InventoryObjectRolesList,
|
||||||
@@ -40,7 +37,6 @@ urls = [
|
|||||||
re_path(r'^(?P<pk>[0-9]+)/script/$', InventoryScriptView.as_view(), name='inventory_script_view'),
|
re_path(r'^(?P<pk>[0-9]+)/script/$', InventoryScriptView.as_view(), name='inventory_script_view'),
|
||||||
re_path(r'^(?P<pk>[0-9]+)/tree/$', InventoryTreeView.as_view(), name='inventory_tree_view'),
|
re_path(r'^(?P<pk>[0-9]+)/tree/$', InventoryTreeView.as_view(), name='inventory_tree_view'),
|
||||||
re_path(r'^(?P<pk>[0-9]+)/inventory_sources/$', InventoryInventorySourcesList.as_view(), name='inventory_inventory_sources_list'),
|
re_path(r'^(?P<pk>[0-9]+)/inventory_sources/$', InventoryInventorySourcesList.as_view(), name='inventory_inventory_sources_list'),
|
||||||
re_path(r'^(?P<pk>[0-9]+)/input_inventories/$', InventoryInputInventoriesList.as_view(), name='inventory_input_inventories'),
|
|
||||||
re_path(r'^(?P<pk>[0-9]+)/update_inventory_sources/$', InventoryInventorySourcesUpdate.as_view(), name='inventory_inventory_sources_update'),
|
re_path(r'^(?P<pk>[0-9]+)/update_inventory_sources/$', InventoryInventorySourcesUpdate.as_view(), name='inventory_inventory_sources_update'),
|
||||||
re_path(r'^(?P<pk>[0-9]+)/activity_stream/$', InventoryActivityStreamList.as_view(), name='inventory_activity_stream_list'),
|
re_path(r'^(?P<pk>[0-9]+)/activity_stream/$', InventoryActivityStreamList.as_view(), name='inventory_activity_stream_list'),
|
||||||
re_path(r'^(?P<pk>[0-9]+)/job_templates/$', InventoryJobTemplateList.as_view(), name='inventory_job_template_list'),
|
re_path(r'^(?P<pk>[0-9]+)/job_templates/$', InventoryJobTemplateList.as_view(), name='inventory_job_template_list'),
|
||||||
@@ -52,10 +48,4 @@ urls = [
|
|||||||
re_path(r'^(?P<pk>[0-9]+)/copy/$', InventoryCopy.as_view(), name='inventory_copy'),
|
re_path(r'^(?P<pk>[0-9]+)/copy/$', InventoryCopy.as_view(), name='inventory_copy'),
|
||||||
]
|
]
|
||||||
|
|
||||||
# Constructed inventory special views
|
__all__ = ['urls']
|
||||||
constructed_inventory_urls = [
|
|
||||||
re_path(r'^$', ConstructedInventoryList.as_view(), name='constructed_inventory_list'),
|
|
||||||
re_path(r'^(?P<pk>[0-9]+)/$', ConstructedInventoryDetail.as_view(), name='constructed_inventory_detail'),
|
|
||||||
]
|
|
||||||
|
|
||||||
__all__ = ['urls', 'constructed_inventory_urls']
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ from .organization import urls as organization_urls
|
|||||||
from .user import urls as user_urls
|
from .user import urls as user_urls
|
||||||
from .project import urls as project_urls
|
from .project import urls as project_urls
|
||||||
from .project_update import urls as project_update_urls
|
from .project_update import urls as project_update_urls
|
||||||
from .inventory import urls as inventory_urls, constructed_inventory_urls
|
from .inventory import urls as inventory_urls
|
||||||
from .execution_environments import urls as execution_environment_urls
|
from .execution_environments import urls as execution_environment_urls
|
||||||
from .team import urls as team_urls
|
from .team import urls as team_urls
|
||||||
from .host import urls as host_urls
|
from .host import urls as host_urls
|
||||||
@@ -110,7 +110,6 @@ v2_urls = [
|
|||||||
re_path(r'^project_updates/', include(project_update_urls)),
|
re_path(r'^project_updates/', include(project_update_urls)),
|
||||||
re_path(r'^teams/', include(team_urls)),
|
re_path(r'^teams/', include(team_urls)),
|
||||||
re_path(r'^inventories/', include(inventory_urls)),
|
re_path(r'^inventories/', include(inventory_urls)),
|
||||||
re_path(r'^constructed_inventories/', include(constructed_inventory_urls)),
|
|
||||||
re_path(r'^hosts/', include(host_urls)),
|
re_path(r'^hosts/', include(host_urls)),
|
||||||
re_path(r'^groups/', include(group_urls)),
|
re_path(r'^groups/', include(group_urls)),
|
||||||
re_path(r'^inventory_sources/', include(inventory_source_urls)),
|
re_path(r'^inventory_sources/', include(inventory_source_urls)),
|
||||||
|
|||||||
@@ -1559,8 +1559,6 @@ class HostDetail(RelatedJobsPreventDeleteMixin, RetrieveUpdateDestroyAPIView):
|
|||||||
def delete(self, request, *args, **kwargs):
|
def delete(self, request, *args, **kwargs):
|
||||||
if self.get_object().inventory.pending_deletion:
|
if self.get_object().inventory.pending_deletion:
|
||||||
return Response({"error": _("The inventory for this host is already being deleted.")}, status=status.HTTP_400_BAD_REQUEST)
|
return Response({"error": _("The inventory for this host is already being deleted.")}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
if self.get_object().inventory.kind == 'constructed':
|
|
||||||
return Response({"error": _("Delete constructed inventory hosts from input inventory.")}, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
return super(HostDetail, self).delete(request, *args, **kwargs)
|
return super(HostDetail, self).delete(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
@@ -4290,7 +4288,7 @@ class WorkflowApprovalTemplateJobsList(SubListAPIView):
|
|||||||
parent_key = 'workflow_approval_template'
|
parent_key = 'workflow_approval_template'
|
||||||
|
|
||||||
|
|
||||||
class WorkflowApprovalList(ListCreateAPIView):
|
class WorkflowApprovalList(ListAPIView):
|
||||||
model = models.WorkflowApproval
|
model = models.WorkflowApproval
|
||||||
serializer_class = serializers.WorkflowApprovalListSerializer
|
serializer_class = serializers.WorkflowApprovalListSerializer
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
from rest_framework.exceptions import PermissionDenied
|
from rest_framework.exceptions import PermissionDenied
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework import serializers
|
|
||||||
|
|
||||||
# AWX
|
# AWX
|
||||||
from awx.main.models import ActivityStream, Inventory, JobTemplate, Role, User, InstanceGroup, InventoryUpdateEvent, InventoryUpdate
|
from awx.main.models import ActivityStream, Inventory, JobTemplate, Role, User, InstanceGroup, InventoryUpdateEvent, InventoryUpdate
|
||||||
@@ -32,7 +31,6 @@ from awx.api.views.labels import LabelSubListCreateAttachDetachView
|
|||||||
|
|
||||||
from awx.api.serializers import (
|
from awx.api.serializers import (
|
||||||
InventorySerializer,
|
InventorySerializer,
|
||||||
ConstructedInventorySerializer,
|
|
||||||
ActivityStreamSerializer,
|
ActivityStreamSerializer,
|
||||||
RoleSerializer,
|
RoleSerializer,
|
||||||
InstanceGroupSerializer,
|
InstanceGroupSerializer,
|
||||||
@@ -81,9 +79,7 @@ class InventoryDetail(RelatedJobsPreventDeleteMixin, RetrieveUpdateDestroyAPIVie
|
|||||||
|
|
||||||
# Do not allow changes to an Inventory kind.
|
# Do not allow changes to an Inventory kind.
|
||||||
if kind is not None and obj.kind != kind:
|
if kind is not None and obj.kind != kind:
|
||||||
return Response(
|
return Response(dict(error=_('You cannot turn a regular inventory into a "smart" inventory.')), status=status.HTTP_405_METHOD_NOT_ALLOWED)
|
||||||
dict(error=_('You cannot turn a regular inventory into a "smart" or "constructed" inventory.')), status=status.HTTP_405_METHOD_NOT_ALLOWED
|
|
||||||
)
|
|
||||||
return super(InventoryDetail, self).update(request, *args, **kwargs)
|
return super(InventoryDetail, self).update(request, *args, **kwargs)
|
||||||
|
|
||||||
def destroy(self, request, *args, **kwargs):
|
def destroy(self, request, *args, **kwargs):
|
||||||
@@ -98,29 +94,6 @@ class InventoryDetail(RelatedJobsPreventDeleteMixin, RetrieveUpdateDestroyAPIVie
|
|||||||
return Response(dict(error=_("{0}".format(e))), status=status.HTTP_400_BAD_REQUEST)
|
return Response(dict(error=_("{0}".format(e))), status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
class ConstructedInventoryDetail(InventoryDetail):
|
|
||||||
serializer_class = ConstructedInventorySerializer
|
|
||||||
|
|
||||||
|
|
||||||
class ConstructedInventoryList(InventoryList):
|
|
||||||
serializer_class = ConstructedInventorySerializer
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
r = super().get_queryset()
|
|
||||||
return r.filter(kind='constructed')
|
|
||||||
|
|
||||||
|
|
||||||
class InventoryInputInventoriesList(SubListAttachDetachAPIView):
|
|
||||||
model = Inventory
|
|
||||||
serializer_class = InventorySerializer
|
|
||||||
parent_model = Inventory
|
|
||||||
relationship = 'input_inventories'
|
|
||||||
|
|
||||||
def is_valid_relation(self, parent, sub, created=False):
|
|
||||||
if sub.kind == 'constructed':
|
|
||||||
raise serializers.ValidationError({'error': 'You cannot add a constructed inventory to another constructed inventory.'})
|
|
||||||
|
|
||||||
|
|
||||||
class InventoryActivityStreamList(SubListAPIView):
|
class InventoryActivityStreamList(SubListAPIView):
|
||||||
model = ActivityStream
|
model = ActivityStream
|
||||||
serializer_class = ActivityStreamSerializer
|
serializer_class = ActivityStreamSerializer
|
||||||
|
|||||||
@@ -98,7 +98,6 @@ class ApiVersionRootView(APIView):
|
|||||||
data['tokens'] = reverse('api:o_auth2_token_list', request=request)
|
data['tokens'] = reverse('api:o_auth2_token_list', request=request)
|
||||||
data['metrics'] = reverse('api:metrics_view', request=request)
|
data['metrics'] = reverse('api:metrics_view', request=request)
|
||||||
data['inventory'] = reverse('api:inventory_list', request=request)
|
data['inventory'] = reverse('api:inventory_list', request=request)
|
||||||
data['constructed_inventory'] = reverse('api:constructed_inventory_list', request=request)
|
|
||||||
data['inventory_sources'] = reverse('api:inventory_source_list', request=request)
|
data['inventory_sources'] = reverse('api:inventory_source_list', request=request)
|
||||||
data['inventory_updates'] = reverse('api:inventory_update_list', request=request)
|
data['inventory_updates'] = reverse('api:inventory_update_list', request=request)
|
||||||
data['groups'] = reverse('api:group_list', request=request)
|
data['groups'] = reverse('api:group_list', request=request)
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.timezone import now
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger('awx.conf.migrations')
|
||||||
|
|
||||||
|
|
||||||
def fill_ldap_group_type_params(apps, schema_editor):
|
def fill_ldap_group_type_params(apps, schema_editor):
|
||||||
@@ -15,7 +19,7 @@ def fill_ldap_group_type_params(apps, schema_editor):
|
|||||||
entry = qs[0]
|
entry = qs[0]
|
||||||
group_type_params = entry.value
|
group_type_params = entry.value
|
||||||
else:
|
else:
|
||||||
entry = Setting(key='AUTH_LDAP_GROUP_TYPE_PARAMS', value=group_type_params, created=now(), modified=now())
|
return # for new installs we prefer to use the default value
|
||||||
|
|
||||||
init_attrs = set(inspect.getfullargspec(group_type.__init__).args[1:])
|
init_attrs = set(inspect.getfullargspec(group_type.__init__).args[1:])
|
||||||
for k in list(group_type_params.keys()):
|
for k in list(group_type_params.keys()):
|
||||||
@@ -23,4 +27,5 @@ def fill_ldap_group_type_params(apps, schema_editor):
|
|||||||
del group_type_params[k]
|
del group_type_params[k]
|
||||||
|
|
||||||
entry.value = group_type_params
|
entry.value = group_type_params
|
||||||
|
logger.warning(f'Migration updating AUTH_LDAP_GROUP_TYPE_PARAMS with value {entry.value}')
|
||||||
entry.save()
|
entry.save()
|
||||||
|
|||||||
25
awx/conf/tests/functional/test_migrations.py
Normal file
25
awx/conf/tests/functional/test_migrations.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
from awx.conf.migrations._ldap_group_type import fill_ldap_group_type_params
|
||||||
|
from awx.conf.models import Setting
|
||||||
|
|
||||||
|
from django.apps import apps
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_fill_group_type_params_no_op():
|
||||||
|
fill_ldap_group_type_params(apps, 'dont-use-me')
|
||||||
|
assert Setting.objects.count() == 0
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_keep_old_setting_with_default_value():
|
||||||
|
Setting.objects.create(key='AUTH_LDAP_GROUP_TYPE', value={'name_attr': 'cn', 'member_attr': 'member'})
|
||||||
|
fill_ldap_group_type_params(apps, 'dont-use-me')
|
||||||
|
assert Setting.objects.count() == 1
|
||||||
|
s = Setting.objects.first()
|
||||||
|
assert s.value == {'name_attr': 'cn', 'member_attr': 'member'}
|
||||||
|
|
||||||
|
|
||||||
|
# NOTE: would be good to test the removal of attributes by migration
|
||||||
|
# but this requires fighting with the validator and is not done here
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
# Generated by Django 3.2.16 on 2022-12-07 14:20
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
dependencies = [
|
|
||||||
('main', '0174_ensure_org_ee_admin_roles'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='inventory',
|
|
||||||
name='input_inventories',
|
|
||||||
field=models.ManyToManyField(
|
|
||||||
blank=True,
|
|
||||||
help_text='Only valid for constructed inventories, this links to the inventories that will be used.',
|
|
||||||
related_name='destination_inventories',
|
|
||||||
to='main.Inventory',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='inventory',
|
|
||||||
name='kind',
|
|
||||||
field=models.CharField(
|
|
||||||
blank=True,
|
|
||||||
choices=[
|
|
||||||
('', 'Hosts have a direct link to this inventory.'),
|
|
||||||
('smart', 'Hosts for inventory generated using the host_filter property.'),
|
|
||||||
('constructed', 'Parse list of source inventories with the constructed inventory plugin.'),
|
|
||||||
],
|
|
||||||
default='',
|
|
||||||
help_text='Kind of inventory being represented.',
|
|
||||||
max_length=32,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='inventorysource',
|
|
||||||
name='source',
|
|
||||||
field=models.CharField(
|
|
||||||
choices=[
|
|
||||||
('file', 'File, Directory or Script'),
|
|
||||||
('constructed', 'Template additional groups and hostvars at runtime'),
|
|
||||||
('scm', 'Sourced from a Project'),
|
|
||||||
('ec2', 'Amazon EC2'),
|
|
||||||
('gce', 'Google Compute Engine'),
|
|
||||||
('azure_rm', 'Microsoft Azure Resource Manager'),
|
|
||||||
('vmware', 'VMware vCenter'),
|
|
||||||
('satellite6', 'Red Hat Satellite 6'),
|
|
||||||
('openstack', 'OpenStack'),
|
|
||||||
('rhv', 'Red Hat Virtualization'),
|
|
||||||
('controller', 'Red Hat Ansible Automation Platform'),
|
|
||||||
('insights', 'Red Hat Insights'),
|
|
||||||
],
|
|
||||||
default=None,
|
|
||||||
max_length=32,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='inventoryupdate',
|
|
||||||
name='source',
|
|
||||||
field=models.CharField(
|
|
||||||
choices=[
|
|
||||||
('file', 'File, Directory or Script'),
|
|
||||||
('constructed', 'Template additional groups and hostvars at runtime'),
|
|
||||||
('scm', 'Sourced from a Project'),
|
|
||||||
('ec2', 'Amazon EC2'),
|
|
||||||
('gce', 'Google Compute Engine'),
|
|
||||||
('azure_rm', 'Microsoft Azure Resource Manager'),
|
|
||||||
('vmware', 'VMware vCenter'),
|
|
||||||
('satellite6', 'Red Hat Satellite 6'),
|
|
||||||
('openstack', 'OpenStack'),
|
|
||||||
('rhv', 'Red Hat Virtualization'),
|
|
||||||
('controller', 'Red Hat Ansible Automation Platform'),
|
|
||||||
('insights', 'Red Hat Insights'),
|
|
||||||
],
|
|
||||||
default=None,
|
|
||||||
max_length=32,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='inventorysource',
|
|
||||||
name='limit',
|
|
||||||
field=models.TextField(blank=True, default='', help_text='Enter host, group or pattern match'),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='inventoryupdate',
|
|
||||||
name='limit',
|
|
||||||
field=models.TextField(blank=True, default='', help_text='Enter host, group or pattern match'),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='inventorysource',
|
|
||||||
name='host_filter',
|
|
||||||
field=models.TextField(
|
|
||||||
blank=True,
|
|
||||||
default='',
|
|
||||||
help_text='This field is deprecated and will be removed in a future release. Regex where only matching hosts will be imported.',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='inventoryupdate',
|
|
||||||
name='host_filter',
|
|
||||||
field=models.TextField(
|
|
||||||
blank=True,
|
|
||||||
default='',
|
|
||||||
help_text='This field is deprecated and will be removed in a future release. Regex where only matching hosts will be imported.',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@@ -49,7 +49,7 @@ from awx.main.models.notifications import (
|
|||||||
from awx.main.models.credential.injectors import _openstack_data
|
from awx.main.models.credential.injectors import _openstack_data
|
||||||
from awx.main.utils import _inventory_updates
|
from awx.main.utils import _inventory_updates
|
||||||
from awx.main.utils.safe_yaml import sanitize_jinja
|
from awx.main.utils.safe_yaml import sanitize_jinja
|
||||||
from awx.main.utils.execution_environments import to_container_path, get_control_plane_execution_environment
|
from awx.main.utils.execution_environments import to_container_path
|
||||||
from awx.main.utils.licensing import server_product_name
|
from awx.main.utils.licensing import server_product_name
|
||||||
|
|
||||||
|
|
||||||
@@ -67,7 +67,6 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin, RelatedJobsMixin):
|
|||||||
KIND_CHOICES = [
|
KIND_CHOICES = [
|
||||||
('', _('Hosts have a direct link to this inventory.')),
|
('', _('Hosts have a direct link to this inventory.')),
|
||||||
('smart', _('Hosts for inventory generated using the host_filter property.')),
|
('smart', _('Hosts for inventory generated using the host_filter property.')),
|
||||||
('constructed', _('Parse list of source inventories with the constructed inventory plugin.')),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@@ -140,12 +139,6 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin, RelatedJobsMixin):
|
|||||||
default=None,
|
default=None,
|
||||||
help_text=_('Filter that will be applied to the hosts of this inventory.'),
|
help_text=_('Filter that will be applied to the hosts of this inventory.'),
|
||||||
)
|
)
|
||||||
input_inventories = models.ManyToManyField(
|
|
||||||
'Inventory',
|
|
||||||
blank=True,
|
|
||||||
related_name='destination_inventories',
|
|
||||||
help_text=_('Only valid for constructed inventories, this links to the inventories that will be used.'),
|
|
||||||
)
|
|
||||||
instance_groups = OrderedManyToManyField(
|
instance_groups = OrderedManyToManyField(
|
||||||
'InstanceGroup',
|
'InstanceGroup',
|
||||||
blank=True,
|
blank=True,
|
||||||
@@ -438,22 +431,12 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin, RelatedJobsMixin):
|
|||||||
|
|
||||||
connection.on_commit(on_commit)
|
connection.on_commit(on_commit)
|
||||||
|
|
||||||
def _enforce_constructed_source(self):
|
|
||||||
"""
|
|
||||||
Constructed inventory should always have exactly 1 inventory source, constructed type
|
|
||||||
this enforces that requirement
|
|
||||||
"""
|
|
||||||
if self.kind == 'constructed':
|
|
||||||
if not self.inventory_sources.exists():
|
|
||||||
self.inventory_sources.create(source='constructed', name=f'Auto-created source for: {self.name}'[:512], overwrite=True, update_on_launch=True)
|
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self._update_host_smart_inventory_memeberships()
|
self._update_host_smart_inventory_memeberships()
|
||||||
super(Inventory, self).save(*args, **kwargs)
|
super(Inventory, self).save(*args, **kwargs)
|
||||||
if self.kind == 'smart' and 'host_filter' in kwargs.get('update_fields', ['host_filter']) and connection.vendor != 'sqlite':
|
if self.kind == 'smart' and 'host_filter' in kwargs.get('update_fields', ['host_filter']) and connection.vendor != 'sqlite':
|
||||||
# Minimal update of host_count for smart inventory host filter changes
|
# Minimal update of host_count for smart inventory host filter changes
|
||||||
self.update_computed_fields()
|
self.update_computed_fields()
|
||||||
self._enforce_constructed_source()
|
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
self._update_host_smart_inventory_memeberships()
|
self._update_host_smart_inventory_memeberships()
|
||||||
@@ -851,7 +834,6 @@ class InventorySourceOptions(BaseModel):
|
|||||||
|
|
||||||
SOURCE_CHOICES = [
|
SOURCE_CHOICES = [
|
||||||
('file', _('File, Directory or Script')),
|
('file', _('File, Directory or Script')),
|
||||||
('constructed', _('Template additional groups and hostvars at runtime')),
|
|
||||||
('scm', _('Sourced from a Project')),
|
('scm', _('Sourced from a Project')),
|
||||||
('ec2', _('Amazon EC2')),
|
('ec2', _('Amazon EC2')),
|
||||||
('gce', _('Google Compute Engine')),
|
('gce', _('Google Compute Engine')),
|
||||||
@@ -925,7 +907,7 @@ class InventorySourceOptions(BaseModel):
|
|||||||
host_filter = models.TextField(
|
host_filter = models.TextField(
|
||||||
blank=True,
|
blank=True,
|
||||||
default='',
|
default='',
|
||||||
help_text=_('This field is deprecated and will be removed in a future release. Regex where only matching hosts will be imported.'),
|
help_text=_('Regex where only matching hosts will be imported.'),
|
||||||
)
|
)
|
||||||
overwrite = models.BooleanField(
|
overwrite = models.BooleanField(
|
||||||
default=False,
|
default=False,
|
||||||
@@ -945,21 +927,6 @@ class InventorySourceOptions(BaseModel):
|
|||||||
blank=True,
|
blank=True,
|
||||||
default=1,
|
default=1,
|
||||||
)
|
)
|
||||||
limit = models.TextField(
|
|
||||||
blank=True,
|
|
||||||
default='',
|
|
||||||
help_text=_("Enter host, group or pattern match"),
|
|
||||||
)
|
|
||||||
|
|
||||||
def resolve_execution_environment(self):
|
|
||||||
"""
|
|
||||||
Project updates, themselves, will use the control plane execution environment.
|
|
||||||
Jobs using the project can use the default_environment, but the project updates
|
|
||||||
are not flexible enough to allow customizing the image they use.
|
|
||||||
"""
|
|
||||||
if self.inventory.kind == 'constructed':
|
|
||||||
return get_control_plane_execution_environment()
|
|
||||||
return super().resolve_execution_environment()
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def cloud_credential_validation(source, cred):
|
def cloud_credential_validation(source, cred):
|
||||||
@@ -1396,8 +1363,6 @@ class PluginFileInjector(object):
|
|||||||
env.update(injector_env)
|
env.update(injector_env)
|
||||||
# Preserves current behavior for Ansible change in default planned for 2.10
|
# Preserves current behavior for Ansible change in default planned for 2.10
|
||||||
env['ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS'] = 'never'
|
env['ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS'] = 'never'
|
||||||
# All CLOUD_PROVIDERS sources implement as inventory plugin from collection
|
|
||||||
env['ANSIBLE_INVENTORY_ENABLED'] = 'auto'
|
|
||||||
return env
|
return env
|
||||||
|
|
||||||
def _get_shared_env(self, inventory_update, private_data_dir, private_data_files):
|
def _get_shared_env(self, inventory_update, private_data_dir, private_data_files):
|
||||||
@@ -1581,17 +1546,5 @@ class insights(PluginFileInjector):
|
|||||||
use_fqcn = True
|
use_fqcn = True
|
||||||
|
|
||||||
|
|
||||||
class constructed(PluginFileInjector):
|
|
||||||
plugin_name = 'constructed'
|
|
||||||
namespace = 'ansible'
|
|
||||||
collection = 'builtin'
|
|
||||||
|
|
||||||
def build_env(self, *args, **kwargs):
|
|
||||||
env = super().build_env(*args, **kwargs)
|
|
||||||
# Enable all types of inventory plugins so we pick up the script files from source inventories
|
|
||||||
del env['ANSIBLE_INVENTORY_ENABLED']
|
|
||||||
return env
|
|
||||||
|
|
||||||
|
|
||||||
for cls in PluginFileInjector.__subclasses__():
|
for cls in PluginFileInjector.__subclasses__():
|
||||||
InventorySourceOptions.injectors[cls.__name__] = cls
|
InventorySourceOptions.injectors[cls.__name__] = cls
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ class AWXProtocolTypeRouter(ProtocolTypeRouter):
|
|||||||
|
|
||||||
|
|
||||||
websocket_urlpatterns = [
|
websocket_urlpatterns = [
|
||||||
re_path(r'websocket/$', consumers.EventConsumer.as_asgi()),
|
re_path(r'websocket/', consumers.EventConsumer.as_asgi()),
|
||||||
re_path(r'websocket/broadcast/$', consumers.BroadcastConsumer.as_asgi()),
|
re_path(r'websocket/broadcast/', consumers.BroadcastConsumer.as_asgi()),
|
||||||
]
|
]
|
||||||
|
|
||||||
application = AWXProtocolTypeRouter(
|
application = AWXProtocolTypeRouter(
|
||||||
|
|||||||
@@ -311,26 +311,21 @@ class BaseTask(object):
|
|||||||
env['AWX_PRIVATE_DATA_DIR'] = private_data_dir
|
env['AWX_PRIVATE_DATA_DIR'] = private_data_dir
|
||||||
|
|
||||||
if self.instance.execution_environment is None:
|
if self.instance.execution_environment is None:
|
||||||
raise RuntimeError('The project could not sync because there is no Execution Environment.')
|
raise RuntimeError(f'The {self.model.__name__} could not run because there is no Execution Environment.')
|
||||||
|
|
||||||
return env
|
return env
|
||||||
|
|
||||||
def write_inventory_file(self, inventory, private_data_dir, file_name, script_params):
|
|
||||||
script_data = inventory.get_script_data(**script_params)
|
|
||||||
for hostname, hv in script_data.get('_meta', {}).get('hostvars', {}).items():
|
|
||||||
# maintain a list of host_name --> host_id
|
|
||||||
# so we can associate emitted events to Host objects
|
|
||||||
self.runner_callback.host_map[hostname] = hv.get('remote_tower_id', '')
|
|
||||||
file_content = '#! /usr/bin/env python3\n# -*- coding: utf-8 -*-\nprint(%r)\n' % json.dumps(script_data)
|
|
||||||
return self.write_private_data_file(private_data_dir, file_name, file_content, sub_dir='inventory', file_permissions=0o700)
|
|
||||||
|
|
||||||
def build_inventory(self, instance, private_data_dir):
|
def build_inventory(self, instance, private_data_dir):
|
||||||
script_params = dict(hostvars=True, towervars=True)
|
script_params = dict(hostvars=True, towervars=True)
|
||||||
if hasattr(instance, 'job_slice_number'):
|
if hasattr(instance, 'job_slice_number'):
|
||||||
script_params['slice_number'] = instance.job_slice_number
|
script_params['slice_number'] = instance.job_slice_number
|
||||||
script_params['slice_count'] = instance.job_slice_count
|
script_params['slice_count'] = instance.job_slice_count
|
||||||
|
script_data = instance.inventory.get_script_data(**script_params)
|
||||||
return self.write_inventory_file(instance.inventory, private_data_dir, 'hosts', script_params)
|
# maintain a list of host_name --> host_id
|
||||||
|
# so we can associate emitted events to Host objects
|
||||||
|
self.runner_callback.host_map = {hostname: hv.pop('remote_tower_id', '') for hostname, hv in script_data.get('_meta', {}).get('hostvars', {}).items()}
|
||||||
|
file_content = '#! /usr/bin/env python3\n# -*- coding: utf-8 -*-\nprint(%r)\n' % json.dumps(script_data)
|
||||||
|
return self.write_private_data_file(private_data_dir, 'hosts', file_content, sub_dir='inventory', file_permissions=0o700)
|
||||||
|
|
||||||
def build_args(self, instance, private_data_dir, passwords):
|
def build_args(self, instance, private_data_dir, passwords):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
@@ -1469,6 +1464,8 @@ class RunInventoryUpdate(SourceControlMixin, BaseTask):
|
|||||||
|
|
||||||
if injector is not None:
|
if injector is not None:
|
||||||
env = injector.build_env(inventory_update, env, private_data_dir, private_data_files)
|
env = injector.build_env(inventory_update, env, private_data_dir, private_data_files)
|
||||||
|
# All CLOUD_PROVIDERS sources implement as inventory plugin from collection
|
||||||
|
env['ANSIBLE_INVENTORY_ENABLED'] = 'auto'
|
||||||
|
|
||||||
if inventory_update.source == 'scm':
|
if inventory_update.source == 'scm':
|
||||||
for env_k in inventory_update.source_vars_dict:
|
for env_k in inventory_update.source_vars_dict:
|
||||||
@@ -1521,15 +1518,6 @@ class RunInventoryUpdate(SourceControlMixin, BaseTask):
|
|||||||
|
|
||||||
args = ['ansible-inventory', '--list', '--export']
|
args = ['ansible-inventory', '--list', '--export']
|
||||||
|
|
||||||
# special case for constructed inventories, we pass source inventories from database
|
|
||||||
# these must come in order, and in order _before_ the constructed inventory itself
|
|
||||||
if inventory_update.inventory.kind == 'constructed':
|
|
||||||
for input_inventory in inventory_update.inventory.input_inventories.all():
|
|
||||||
args.append('-i')
|
|
||||||
script_params = dict(hostvars=True, towervars=True)
|
|
||||||
source_inv_path = self.write_inventory_file(input_inventory, private_data_dir, f'hosts_{input_inventory.id}', script_params)
|
|
||||||
args.append(to_container_path(source_inv_path, private_data_dir))
|
|
||||||
|
|
||||||
# Add arguments for the source inventory file/script/thing
|
# Add arguments for the source inventory file/script/thing
|
||||||
rel_path = self.pseudo_build_inventory(inventory_update, private_data_dir)
|
rel_path = self.pseudo_build_inventory(inventory_update, private_data_dir)
|
||||||
container_location = os.path.join(CONTAINER_ROOT, rel_path)
|
container_location = os.path.join(CONTAINER_ROOT, rel_path)
|
||||||
@@ -1537,11 +1525,6 @@ class RunInventoryUpdate(SourceControlMixin, BaseTask):
|
|||||||
|
|
||||||
args.append('-i')
|
args.append('-i')
|
||||||
args.append(container_location)
|
args.append(container_location)
|
||||||
# Added this in order to allow older versions of ansible-inventory https://github.com/ansible/ansible/pull/79596
|
|
||||||
# limit should be usable in ansible-inventory 2.15+
|
|
||||||
if inventory_update.limit:
|
|
||||||
args.append('--limit')
|
|
||||||
args.append(inventory_update.limit)
|
|
||||||
|
|
||||||
args.append('--output')
|
args.append('--output')
|
||||||
args.append(os.path.join(CONTAINER_ROOT, 'artifacts', str(inventory_update.id), 'output.json'))
|
args.append(os.path.join(CONTAINER_ROOT, 'artifacts', str(inventory_update.id), 'output.json'))
|
||||||
|
|||||||
@@ -594,45 +594,3 @@ class TestControlledBySCM:
|
|||||||
rando,
|
rando,
|
||||||
expect=403,
|
expect=403,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
class TestConstructedInventory:
|
|
||||||
@pytest.fixture
|
|
||||||
def constructed_inventory(self, organization):
|
|
||||||
return Inventory.objects.create(name='constructed-test-inventory', kind='constructed', organization=organization)
|
|
||||||
|
|
||||||
def test_get_constructed_inventory(self, constructed_inventory, admin_user, get):
|
|
||||||
inv_src = constructed_inventory.inventory_sources.first()
|
|
||||||
inv_src.update_cache_timeout = 53
|
|
||||||
inv_src.save(update_fields=['update_cache_timeout'])
|
|
||||||
r = get(url=reverse('api:constructed_inventory_detail', kwargs={'pk': constructed_inventory.pk}), user=admin_user, expect=200)
|
|
||||||
assert r.data['update_cache_timeout'] == 53
|
|
||||||
|
|
||||||
def test_patch_constructed_inventory(self, constructed_inventory, admin_user, patch):
|
|
||||||
inv_src = constructed_inventory.inventory_sources.first()
|
|
||||||
assert inv_src.update_cache_timeout == 0
|
|
||||||
assert inv_src.limit == ''
|
|
||||||
r = patch(
|
|
||||||
url=reverse('api:constructed_inventory_detail', kwargs={'pk': constructed_inventory.pk}),
|
|
||||||
data=dict(update_cache_timeout=54, limit='foobar'),
|
|
||||||
user=admin_user,
|
|
||||||
expect=200,
|
|
||||||
)
|
|
||||||
assert r.data['update_cache_timeout'] == 54
|
|
||||||
inv_src = constructed_inventory.inventory_sources.first()
|
|
||||||
assert inv_src.update_cache_timeout == 54
|
|
||||||
assert inv_src.limit == 'foobar'
|
|
||||||
|
|
||||||
def test_create_constructed_inventory(self, constructed_inventory, admin_user, post, organization):
|
|
||||||
r = post(
|
|
||||||
url=reverse('api:constructed_inventory_list'),
|
|
||||||
data=dict(name='constructed-inventory-just-created', kind='constructed', organization=organization.id, update_cache_timeout=55, limit='foobar'),
|
|
||||||
user=admin_user,
|
|
||||||
expect=201,
|
|
||||||
)
|
|
||||||
pk = r.data['id']
|
|
||||||
constructed_inventory = Inventory.objects.get(pk=pk)
|
|
||||||
inv_src = constructed_inventory.inventory_sources.first()
|
|
||||||
assert inv_src.update_cache_timeout == 55
|
|
||||||
assert inv_src.limit == 'foobar'
|
|
||||||
|
|||||||
@@ -511,14 +511,6 @@ def group(inventory):
|
|||||||
return inventory.groups.create(name='single-group')
|
return inventory.groups.create(name='single-group')
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def constructed_inventory(organization):
|
|
||||||
"""
|
|
||||||
creates a new constructed inventory source
|
|
||||||
"""
|
|
||||||
return Inventory.objects.create(name='dummy1', kind='constructed', organization=organization)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def inventory_source(inventory):
|
def inventory_source(inventory):
|
||||||
# by making it ec2, the credential is not required
|
# by making it ec2, the credential is not required
|
||||||
|
|||||||
@@ -169,8 +169,7 @@ class TestInventorySourceInjectors:
|
|||||||
CLOUD_PROVIDERS constant contains the same names as what are
|
CLOUD_PROVIDERS constant contains the same names as what are
|
||||||
defined within the injectors
|
defined within the injectors
|
||||||
"""
|
"""
|
||||||
# slight exception case for constructed, because it has a FQCN but is not a cloud source
|
assert set(CLOUD_PROVIDERS) == set(InventorySource.injectors.keys())
|
||||||
assert set(CLOUD_PROVIDERS) | set(['constructed']) == set(InventorySource.injectors.keys())
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('source,filename', [('ec2', 'aws_ec2.yml'), ('openstack', 'openstack.yml'), ('gce', 'gcp_compute.yml')])
|
@pytest.mark.parametrize('source,filename', [('ec2', 'aws_ec2.yml'), ('openstack', 'openstack.yml'), ('gce', 'gcp_compute.yml')])
|
||||||
def test_plugin_filenames(self, source, filename):
|
def test_plugin_filenames(self, source, filename):
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
import pytest
|
|
||||||
from awx.main.models import Inventory
|
|
||||||
from awx.api.versioning import reverse
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_constructed_inventory_post(post, admin_user, organization):
|
|
||||||
inv1 = Inventory.objects.create(name='dummy1', kind='constructed', organization=organization)
|
|
||||||
inv2 = Inventory.objects.create(name='dummy2', kind='constructed', organization=organization)
|
|
||||||
resp = post(
|
|
||||||
url=reverse('api:inventory_input_inventories', kwargs={'pk': inv1.pk}),
|
|
||||||
data={'id': inv2.pk},
|
|
||||||
user=admin_user,
|
|
||||||
expect=400,
|
|
||||||
)
|
|
||||||
assert resp.status_code == 400
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_add_constructed_inventory_source(post, admin_user, constructed_inventory):
|
|
||||||
resp = post(
|
|
||||||
url=reverse('api:inventory_inventory_sources_list', kwargs={'pk': constructed_inventory.pk}),
|
|
||||||
data={'name': 'dummy1', 'source': 'constructed'},
|
|
||||||
user=admin_user,
|
|
||||||
expect=400,
|
|
||||||
)
|
|
||||||
assert resp.status_code == 400
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_add_constructed_inventory_host(post, admin_user, constructed_inventory):
|
|
||||||
resp = post(
|
|
||||||
url=reverse('api:inventory_hosts_list', kwargs={'pk': constructed_inventory.pk}),
|
|
||||||
data={'name': 'dummy1'},
|
|
||||||
user=admin_user,
|
|
||||||
expect=400,
|
|
||||||
)
|
|
||||||
assert resp.status_code == 400
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_add_constructed_inventory_group(post, admin_user, constructed_inventory):
|
|
||||||
resp = post(
|
|
||||||
reverse('api:inventory_groups_list', kwargs={'pk': constructed_inventory.pk}),
|
|
||||||
data={'name': 'group-test'},
|
|
||||||
user=admin_user,
|
|
||||||
expect=400,
|
|
||||||
)
|
|
||||||
assert resp.status_code == 400
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_edit_constructed_inventory_source(patch, admin_user, inventory_source_factory):
|
|
||||||
inv_src = inventory_source_factory(name='dummy1', source='constructed')
|
|
||||||
resp = patch(
|
|
||||||
reverse('api:inventory_source_detail', kwargs={'pk': inv_src.pk}),
|
|
||||||
data={'description': inv_src.name},
|
|
||||||
user=admin_user,
|
|
||||||
expect=400,
|
|
||||||
)
|
|
||||||
assert resp.status_code == 400
|
|
||||||
@@ -2008,7 +2008,7 @@ def test_project_update_no_ee(mock_me):
|
|||||||
with pytest.raises(RuntimeError) as e:
|
with pytest.raises(RuntimeError) as e:
|
||||||
task.build_env(job, {})
|
task.build_env(job, {})
|
||||||
|
|
||||||
assert 'The project could not sync because there is no Execution Environment' in str(e.value)
|
assert 'The ProjectUpdate could not run because there is no Execution Environment' in str(e.value)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -6,8 +7,15 @@ from django.conf import settings
|
|||||||
from awx.main.models.execution_environments import ExecutionEnvironment
|
from awx.main.models.execution_environments import ExecutionEnvironment
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def get_control_plane_execution_environment():
|
def get_control_plane_execution_environment():
|
||||||
return ExecutionEnvironment.objects.filter(organization=None, managed=True).first()
|
ee = ExecutionEnvironment.objects.filter(organization=None, managed=True).first()
|
||||||
|
if ee == None:
|
||||||
|
logger.error('Failed to find control plane ee, there are no managed EEs without organizations')
|
||||||
|
raise RuntimeError("Failed to find default control plane EE")
|
||||||
|
return ee
|
||||||
|
|
||||||
|
|
||||||
def get_default_execution_environment():
|
def get_default_execution_environment():
|
||||||
|
|||||||
@@ -172,9 +172,7 @@ GLOBAL_JOB_EXECUTION_ENVIRONMENTS = [{'name': 'AWX EE (latest)', 'image': 'quay.
|
|||||||
# This image is distinguished from others by having "managed" set to True and users have limited
|
# This image is distinguished from others by having "managed" set to True and users have limited
|
||||||
# ability to modify it through the API.
|
# ability to modify it through the API.
|
||||||
# If a registry credential is needed to pull the image, that can be provided to the awx-manage command
|
# If a registry credential is needed to pull the image, that can be provided to the awx-manage command
|
||||||
|
CONTROL_PLANE_EXECUTION_ENVIRONMENT = 'quay.io/ansible/awx-ee:latest'
|
||||||
# HACK: this is done temporarily for feature development, remove before merge
|
|
||||||
CONTROL_PLANE_EXECUTION_ENVIRONMENT = 'quay.io/relrod/awx-ee-invlimit:latest'
|
|
||||||
|
|
||||||
# Note: This setting may be overridden by database settings.
|
# Note: This setting may be overridden by database settings.
|
||||||
STDOUT_MAX_BYTES_DISPLAY = 1048576
|
STDOUT_MAX_BYTES_DISPLAY = 1048576
|
||||||
@@ -744,13 +742,6 @@ CUSTOM_EXCLUDE_EMPTY_GROUPS = False
|
|||||||
SCM_EXCLUDE_EMPTY_GROUPS = False
|
SCM_EXCLUDE_EMPTY_GROUPS = False
|
||||||
# SCM_INSTANCE_ID_VAR =
|
# SCM_INSTANCE_ID_VAR =
|
||||||
|
|
||||||
# ----------------
|
|
||||||
# -- Constructed --
|
|
||||||
# ----------------
|
|
||||||
CONSTRUCTED_INSTANCE_ID_VAR = 'remote_tower_id'
|
|
||||||
|
|
||||||
CONSTRUCTED_EXCLUDE_EMPTY_GROUPS = False
|
|
||||||
|
|
||||||
# ---------------------
|
# ---------------------
|
||||||
# -- Activity Stream --
|
# -- Activity Stream --
|
||||||
# ---------------------
|
# ---------------------
|
||||||
|
|||||||
@@ -385,10 +385,10 @@ def on_populate_user(sender, **kwargs):
|
|||||||
logger.warning('LDAP user {} has {} > max {} characters'.format(user.username, field, max_len))
|
logger.warning('LDAP user {} has {} > max {} characters'.format(user.username, field, max_len))
|
||||||
|
|
||||||
org_map = getattr(backend.settings, 'ORGANIZATION_MAP', {})
|
org_map = getattr(backend.settings, 'ORGANIZATION_MAP', {})
|
||||||
team_map = getattr(backend.settings, 'TEAM_MAP', {})
|
team_map_settings = getattr(backend.settings, 'TEAM_MAP', {})
|
||||||
orgs_list = list(org_map.keys())
|
orgs_list = list(org_map.keys())
|
||||||
team_map = {}
|
team_map = {}
|
||||||
for team_name, team_opts in team_map.items():
|
for team_name, team_opts in team_map_settings.items():
|
||||||
if not team_opts.get('organization', None):
|
if not team_opts.get('organization', None):
|
||||||
# You can't save the LDAP config in the UI w/o an org (or '' or null as the org) so if we somehow got this condition its an error
|
# You can't save the LDAP config in the UI w/o an org (or '' or null as the org) so if we somehow got this condition its an error
|
||||||
logger.error("Team named {} in LDAP team map settings is invalid due to missing organization".format(team_name))
|
logger.error("Team named {} in LDAP team map settings is invalid due to missing organization".format(team_name))
|
||||||
@@ -416,7 +416,7 @@ def on_populate_user(sender, **kwargs):
|
|||||||
|
|
||||||
# Compute in memory what the state is of the different LDAP teams
|
# Compute in memory what the state is of the different LDAP teams
|
||||||
desired_team_states = {}
|
desired_team_states = {}
|
||||||
for team_name, team_opts in team_map.items():
|
for team_name, team_opts in team_map_settings.items():
|
||||||
if 'organization' not in team_opts:
|
if 'organization' not in team_opts:
|
||||||
continue
|
continue
|
||||||
users_opts = team_opts.get('users', None)
|
users_opts = team_opts.get('users', None)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import Config from './models/Config';
|
|||||||
import CredentialInputSources from './models/CredentialInputSources';
|
import CredentialInputSources from './models/CredentialInputSources';
|
||||||
import CredentialTypes from './models/CredentialTypes';
|
import CredentialTypes from './models/CredentialTypes';
|
||||||
import Credentials from './models/Credentials';
|
import Credentials from './models/Credentials';
|
||||||
import ConstructedInventories from './models/ConstructedInventories';
|
|
||||||
import Dashboard from './models/Dashboard';
|
import Dashboard from './models/Dashboard';
|
||||||
import ExecutionEnvironments from './models/ExecutionEnvironments';
|
import ExecutionEnvironments from './models/ExecutionEnvironments';
|
||||||
import Groups from './models/Groups';
|
import Groups from './models/Groups';
|
||||||
@@ -54,7 +53,6 @@ const ConfigAPI = new Config();
|
|||||||
const CredentialInputSourcesAPI = new CredentialInputSources();
|
const CredentialInputSourcesAPI = new CredentialInputSources();
|
||||||
const CredentialTypesAPI = new CredentialTypes();
|
const CredentialTypesAPI = new CredentialTypes();
|
||||||
const CredentialsAPI = new Credentials();
|
const CredentialsAPI = new Credentials();
|
||||||
const ConstructedInventoriesAPI = new ConstructedInventories();
|
|
||||||
const DashboardAPI = new Dashboard();
|
const DashboardAPI = new Dashboard();
|
||||||
const ExecutionEnvironmentsAPI = new ExecutionEnvironments();
|
const ExecutionEnvironmentsAPI = new ExecutionEnvironments();
|
||||||
const GroupsAPI = new Groups();
|
const GroupsAPI = new Groups();
|
||||||
@@ -103,7 +101,6 @@ export {
|
|||||||
CredentialInputSourcesAPI,
|
CredentialInputSourcesAPI,
|
||||||
CredentialTypesAPI,
|
CredentialTypesAPI,
|
||||||
CredentialsAPI,
|
CredentialsAPI,
|
||||||
ConstructedInventoriesAPI,
|
|
||||||
DashboardAPI,
|
DashboardAPI,
|
||||||
ExecutionEnvironmentsAPI,
|
ExecutionEnvironmentsAPI,
|
||||||
GroupsAPI,
|
GroupsAPI,
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
import Base from '../Base';
|
|
||||||
import InstanceGroupsMixin from '../mixins/InstanceGroups.mixin';
|
|
||||||
|
|
||||||
class ConstructedInventories extends InstanceGroupsMixin(Base) {
|
|
||||||
constructor(http) {
|
|
||||||
super(http);
|
|
||||||
this.baseUrl = 'api/v2/constructed_inventories/';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export default ConstructedInventories;
|
|
||||||
@@ -13,7 +13,6 @@ class Inventories extends InstanceGroupsMixin(Base) {
|
|||||||
this.readGroups = this.readGroups.bind(this);
|
this.readGroups = this.readGroups.bind(this);
|
||||||
this.readGroupsOptions = this.readGroupsOptions.bind(this);
|
this.readGroupsOptions = this.readGroupsOptions.bind(this);
|
||||||
this.promoteGroup = this.promoteGroup.bind(this);
|
this.promoteGroup = this.promoteGroup.bind(this);
|
||||||
this.readInputInventories = this.readInputInventories.bind(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
readAccessList(id, params) {
|
readAccessList(id, params) {
|
||||||
@@ -73,12 +72,6 @@ class Inventories extends InstanceGroupsMixin(Base) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
readInputInventories(inventoryId, params) {
|
|
||||||
return this.http.get(`${this.baseUrl}${inventoryId}/input_inventories/`, {
|
|
||||||
params,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
readSources(inventoryId, params) {
|
readSources(inventoryId, params) {
|
||||||
return this.http.get(`${this.baseUrl}${inventoryId}/inventory_sources/`, {
|
return this.http.get(`${this.baseUrl}${inventoryId}/inventory_sources/`, {
|
||||||
params,
|
params,
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
export { default } from './AdvancedInventoryHost';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export { default } from './AdvancedInventoryHostDetail';
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { Route, Switch } from 'react-router-dom';
|
|
||||||
import { Inventory } from 'types';
|
|
||||||
import AdvancedInventoryHostList from './AdvancedInventoryHostList';
|
|
||||||
import AdvancedInventoryHost from '../AdvancedInventoryHost';
|
|
||||||
|
|
||||||
function AdvancedInventoryHosts({ inventory, setBreadcrumb }) {
|
|
||||||
return (
|
|
||||||
<Switch>
|
|
||||||
<Route key="host" path="/inventories/:inventoryType/:id/hosts/:hostId">
|
|
||||||
<AdvancedInventoryHost
|
|
||||||
setBreadcrumb={setBreadcrumb}
|
|
||||||
inventory={inventory}
|
|
||||||
/>
|
|
||||||
</Route>
|
|
||||||
<Route key="host-list" path="/inventories/:inventoryType/:id/hosts">
|
|
||||||
<AdvancedInventoryHostList inventory={inventory} />
|
|
||||||
</Route>
|
|
||||||
</Switch>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
AdvancedInventoryHosts.propTypes = {
|
|
||||||
inventory: Inventory.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default AdvancedInventoryHosts;
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export { default } from './AdvancedInventoryHosts';
|
|
||||||
@@ -1,215 +0,0 @@
|
|||||||
import React, { useCallback, useEffect } from 'react';
|
|
||||||
import { t } from '@lingui/macro';
|
|
||||||
import {
|
|
||||||
Link,
|
|
||||||
Switch,
|
|
||||||
Route,
|
|
||||||
Redirect,
|
|
||||||
useRouteMatch,
|
|
||||||
useLocation,
|
|
||||||
} from 'react-router-dom';
|
|
||||||
import { CaretLeftIcon } from '@patternfly/react-icons';
|
|
||||||
import { Card, PageSection } from '@patternfly/react-core';
|
|
||||||
|
|
||||||
import useRequest from 'hooks/useRequest';
|
|
||||||
import { ConstructedInventoriesAPI, InventoriesAPI } from 'api';
|
|
||||||
|
|
||||||
import ContentError from 'components/ContentError';
|
|
||||||
import ContentLoading from 'components/ContentLoading';
|
|
||||||
import JobList from 'components/JobList';
|
|
||||||
import RelatedTemplateList from 'components/RelatedTemplateList';
|
|
||||||
import { ResourceAccessList } from 'components/ResourceAccessList';
|
|
||||||
import RoutedTabs from 'components/RoutedTabs';
|
|
||||||
import ConstructedInventoryDetail from './ConstructedInventoryDetail';
|
|
||||||
import ConstructedInventoryEdit from './ConstructedInventoryEdit';
|
|
||||||
import InventoryGroups from './InventoryGroups';
|
|
||||||
import AdvancedInventoryHosts from './AdvancedInventoryHosts';
|
|
||||||
import { getInventoryPath } from './shared/utils';
|
|
||||||
|
|
||||||
function ConstructedInventory({ setBreadcrumb }) {
|
|
||||||
const location = useLocation();
|
|
||||||
const match = useRouteMatch('/inventories/constructed_inventory/:id');
|
|
||||||
|
|
||||||
const {
|
|
||||||
result: inventory,
|
|
||||||
error: contentError,
|
|
||||||
isLoading: hasContentLoading,
|
|
||||||
request: fetchInventory,
|
|
||||||
} = useRequest(
|
|
||||||
useCallback(async () => {
|
|
||||||
const { data } = await ConstructedInventoriesAPI.readDetail(
|
|
||||||
match.params.id
|
|
||||||
);
|
|
||||||
return data;
|
|
||||||
}, [match.params.id]),
|
|
||||||
{ isLoading: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetchInventory();
|
|
||||||
}, [fetchInventory, location.pathname]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (inventory) {
|
|
||||||
setBreadcrumb(inventory);
|
|
||||||
}
|
|
||||||
}, [inventory, setBreadcrumb]);
|
|
||||||
|
|
||||||
const tabsArray = [
|
|
||||||
{
|
|
||||||
name: (
|
|
||||||
<>
|
|
||||||
<CaretLeftIcon />
|
|
||||||
{t`Back to Inventories`}
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
link: `/inventories`,
|
|
||||||
id: 99,
|
|
||||||
},
|
|
||||||
{ name: t`Details`, link: `${match.url}/details`, id: 0 },
|
|
||||||
{ name: t`Access`, link: `${match.url}/access`, id: 1 },
|
|
||||||
{ name: t`Hosts`, link: `${match.url}/hosts`, id: 2 },
|
|
||||||
{ name: t`Groups`, link: `${match.url}/groups`, id: 3 },
|
|
||||||
{
|
|
||||||
name: t`Jobs`,
|
|
||||||
link: `${match.url}/jobs`,
|
|
||||||
id: 4,
|
|
||||||
},
|
|
||||||
{ name: t`Job Templates`, link: `${match.url}/job_templates`, id: 5 },
|
|
||||||
];
|
|
||||||
|
|
||||||
if (hasContentLoading) {
|
|
||||||
return (
|
|
||||||
<PageSection>
|
|
||||||
<Card>
|
|
||||||
<ContentLoading />
|
|
||||||
</Card>
|
|
||||||
</PageSection>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (contentError) {
|
|
||||||
return (
|
|
||||||
<PageSection>
|
|
||||||
<Card>
|
|
||||||
<ContentError error={contentError}>
|
|
||||||
{contentError?.response?.status === 404 && (
|
|
||||||
<span>
|
|
||||||
{t`Constructed Inventory not found.`}{' '}
|
|
||||||
<Link to="/inventories">{t`View all Inventories.`}</Link>
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</ContentError>
|
|
||||||
</Card>
|
|
||||||
</PageSection>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inventory && inventory?.kind !== 'constructed') {
|
|
||||||
return <Redirect to={`${getInventoryPath(inventory)}/details`} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
let showCardHeader = true;
|
|
||||||
if (
|
|
||||||
['edit', 'add', 'groups/', 'hosts/'].some((name) =>
|
|
||||||
location.pathname.includes(name)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
showCardHeader = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<PageSection>
|
|
||||||
<Card>
|
|
||||||
{showCardHeader && <RoutedTabs tabsArray={tabsArray} />}
|
|
||||||
<Switch>
|
|
||||||
<Redirect
|
|
||||||
from="/inventories/constructed_inventory/:id"
|
|
||||||
to="/inventories/constructed_inventory/:id/details"
|
|
||||||
exact
|
|
||||||
/>
|
|
||||||
{inventory && [
|
|
||||||
<Route
|
|
||||||
path="/inventories/constructed_inventory/:id/details"
|
|
||||||
key="details"
|
|
||||||
>
|
|
||||||
<ConstructedInventoryDetail
|
|
||||||
inventory={inventory}
|
|
||||||
hasInventoryLoading={hasContentLoading}
|
|
||||||
/>
|
|
||||||
</Route>,
|
|
||||||
<Route
|
|
||||||
key="edit"
|
|
||||||
path="/inventories/constructed_inventory/:id/edit"
|
|
||||||
>
|
|
||||||
<ConstructedInventoryEdit />
|
|
||||||
</Route>,
|
|
||||||
<Route
|
|
||||||
path="/inventories/constructed_inventory/:id/access"
|
|
||||||
key="access"
|
|
||||||
>
|
|
||||||
<ResourceAccessList
|
|
||||||
resource={inventory}
|
|
||||||
apiModel={InventoriesAPI}
|
|
||||||
/>
|
|
||||||
</Route>,
|
|
||||||
<Route
|
|
||||||
path="/inventories/constructed_inventory/:id/hosts"
|
|
||||||
key="hosts"
|
|
||||||
>
|
|
||||||
<AdvancedInventoryHosts
|
|
||||||
inventory={inventory}
|
|
||||||
setBreadcrumb={setBreadcrumb}
|
|
||||||
/>
|
|
||||||
</Route>,
|
|
||||||
<Route
|
|
||||||
path="/inventories/constructed_inventory/:id/groups"
|
|
||||||
key="constructed_inventory_groups"
|
|
||||||
>
|
|
||||||
<InventoryGroups
|
|
||||||
inventory={inventory}
|
|
||||||
setBreadcrumb={setBreadcrumb}
|
|
||||||
/>
|
|
||||||
</Route>,
|
|
||||||
<Route
|
|
||||||
key="jobs"
|
|
||||||
path="/inventories/constructed_inventory/:id/jobs"
|
|
||||||
>
|
|
||||||
<JobList
|
|
||||||
defaultParams={{
|
|
||||||
or__job__inventory: inventory.id,
|
|
||||||
or__adhoccommand__inventory: inventory.id,
|
|
||||||
or__inventoryupdate__inventory_source__inventory:
|
|
||||||
inventory.id,
|
|
||||||
or__workflowjob__inventory: inventory.id,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Route>,
|
|
||||||
<Route
|
|
||||||
key="job_templates"
|
|
||||||
path="/inventories/constructed_inventory/:id/job_templates"
|
|
||||||
>
|
|
||||||
<RelatedTemplateList
|
|
||||||
searchParams={{ inventory__id: inventory.id }}
|
|
||||||
/>
|
|
||||||
</Route>,
|
|
||||||
]}
|
|
||||||
<Route path="*" key="not-found">
|
|
||||||
<ContentError isNotFound>
|
|
||||||
{match.params.id && (
|
|
||||||
<Link
|
|
||||||
to={`/inventories/constructed_inventory/${match.params.id}/details`}
|
|
||||||
>
|
|
||||||
{t`View Constructed Inventory Details`}
|
|
||||||
</Link>
|
|
||||||
)}
|
|
||||||
</ContentError>
|
|
||||||
</Route>
|
|
||||||
</Switch>
|
|
||||||
</Card>
|
|
||||||
</PageSection>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export { ConstructedInventory as _ConstructedInventory };
|
|
||||||
export default ConstructedInventory;
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { act } from 'react-dom/test-utils';
|
|
||||||
import { createMemoryHistory } from 'history';
|
|
||||||
import { ConstructedInventoriesAPI } from 'api';
|
|
||||||
import {
|
|
||||||
mountWithContexts,
|
|
||||||
waitForElement,
|
|
||||||
} from '../../../testUtils/enzymeHelpers';
|
|
||||||
import mockInventory from './shared/data.inventory.json';
|
|
||||||
import ConstructedInventory from './ConstructedInventory';
|
|
||||||
|
|
||||||
jest.mock('../../api');
|
|
||||||
jest.mock('react-router-dom', () => ({
|
|
||||||
...jest.requireActual('react-router-dom'),
|
|
||||||
useRouteMatch: () => ({
|
|
||||||
url: '/constructed_inventories/1',
|
|
||||||
params: { id: 1 },
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe('<ConstructedInventory />', () => {
|
|
||||||
let wrapper;
|
|
||||||
|
|
||||||
test('should render expected tabs', async () => {
|
|
||||||
ConstructedInventoriesAPI.readDetail.mockResolvedValue({
|
|
||||||
data: mockInventory,
|
|
||||||
});
|
|
||||||
const expectedTabs = [
|
|
||||||
'Back to Inventories',
|
|
||||||
'Details',
|
|
||||||
'Access',
|
|
||||||
'Hosts',
|
|
||||||
'Groups',
|
|
||||||
'Jobs',
|
|
||||||
'Job Templates',
|
|
||||||
];
|
|
||||||
await act(async () => {
|
|
||||||
wrapper = mountWithContexts(
|
|
||||||
<ConstructedInventory setBreadcrumb={() => {}} />
|
|
||||||
);
|
|
||||||
});
|
|
||||||
wrapper.find('RoutedTabs li').forEach((tab, index) => {
|
|
||||||
expect(tab.text()).toEqual(expectedTabs[index]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should show content error when user attempts to navigate to erroneous route', async () => {
|
|
||||||
ConstructedInventoriesAPI.readDetail.mockResolvedValue({
|
|
||||||
data: { ...mockInventory, kind: 'constructed' },
|
|
||||||
});
|
|
||||||
const history = createMemoryHistory({
|
|
||||||
initialEntries: ['/inventories/constructed_inventory/1/foobar'],
|
|
||||||
});
|
|
||||||
await act(async () => {
|
|
||||||
wrapper = mountWithContexts(
|
|
||||||
<ConstructedInventory setBreadcrumb={() => {}} />,
|
|
||||||
{
|
|
||||||
context: {
|
|
||||||
router: {
|
|
||||||
history,
|
|
||||||
route: {
|
|
||||||
location: history.location,
|
|
||||||
match: {
|
|
||||||
params: { id: 1 },
|
|
||||||
url: '/inventories/constructed_inventory/1/foobar',
|
|
||||||
path: '/inventories/:inventoryType/:id/foobar',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0);
|
|
||||||
expect(wrapper.find('ContentError').length).toBe(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
/* eslint i18next/no-literal-string: "off" */
|
|
||||||
import React from 'react';
|
|
||||||
import { Card, PageSection } from '@patternfly/react-core';
|
|
||||||
import { CardBody } from 'components/Card';
|
|
||||||
|
|
||||||
function ConstructedInventoryAdd() {
|
|
||||||
return (
|
|
||||||
<PageSection>
|
|
||||||
<Card>
|
|
||||||
<CardBody>
|
|
||||||
<div>Coming Soon!</div>
|
|
||||||
</CardBody>
|
|
||||||
</Card>
|
|
||||||
</PageSection>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ConstructedInventoryAdd;
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { act } from 'react-dom/test-utils';
|
|
||||||
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
|
||||||
import ConstructedInventoryAdd from './ConstructedInventoryAdd';
|
|
||||||
|
|
||||||
describe('<ConstructedInventoryAdd />', () => {
|
|
||||||
test('initially renders successfully', async () => {
|
|
||||||
let wrapper;
|
|
||||||
await act(async () => {
|
|
||||||
wrapper = mountWithContexts(<ConstructedInventoryAdd />);
|
|
||||||
});
|
|
||||||
expect(wrapper.length).toBe(1);
|
|
||||||
expect(wrapper.find('ConstructedInventoryAdd').length).toBe(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export { default } from './ConstructedInventoryAdd';
|
|
||||||
@@ -1,371 +0,0 @@
|
|||||||
import React, { useCallback, useEffect } from 'react';
|
|
||||||
import { Link, useHistory } from 'react-router-dom';
|
|
||||||
|
|
||||||
import { t } from '@lingui/macro';
|
|
||||||
import {
|
|
||||||
Button,
|
|
||||||
Chip,
|
|
||||||
Label,
|
|
||||||
LabelGroup,
|
|
||||||
TextList,
|
|
||||||
TextListItem,
|
|
||||||
TextListItemVariants,
|
|
||||||
TextListVariants,
|
|
||||||
Tooltip,
|
|
||||||
} from '@patternfly/react-core';
|
|
||||||
import { InventoriesAPI, ConstructedInventoriesAPI } from 'api';
|
|
||||||
import { Inventory } from 'types';
|
|
||||||
import { formatDateString } from 'util/dates';
|
|
||||||
import { relatedResourceDeleteRequests } from 'util/getRelatedResourceDeleteDetails';
|
|
||||||
import useRequest, { useDismissableError } from 'hooks/useRequest';
|
|
||||||
import AlertModal from 'components/AlertModal';
|
|
||||||
import { CardBody, CardActionsRow } from 'components/Card';
|
|
||||||
import ChipGroup from 'components/ChipGroup';
|
|
||||||
import { VariablesDetail } from 'components/CodeEditor';
|
|
||||||
import ContentError from 'components/ContentError';
|
|
||||||
import ContentLoading from 'components/ContentLoading';
|
|
||||||
import { DetailList, Detail, UserDateDetail } from 'components/DetailList';
|
|
||||||
import DeleteButton from 'components/DeleteButton';
|
|
||||||
import ErrorDetail from 'components/ErrorDetail';
|
|
||||||
import InstanceGroupLabels from 'components/InstanceGroupLabels';
|
|
||||||
import JobCancelButton from 'components/JobCancelButton';
|
|
||||||
import Popover from 'components/Popover';
|
|
||||||
import StatusLabel from 'components/StatusLabel';
|
|
||||||
import ConstructedInventorySyncButton from './ConstructedInventorySyncButton';
|
|
||||||
import useWsInventorySourcesDetails from '../shared/useWsInventorySourcesDetails';
|
|
||||||
import getHelpText from '../shared/Inventory.helptext';
|
|
||||||
|
|
||||||
function JobStatusLabel({ job }) {
|
|
||||||
if (!job) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Tooltip
|
|
||||||
position="top"
|
|
||||||
content={
|
|
||||||
<>
|
|
||||||
<div>{t`MOST RECENT SYNC`}</div>
|
|
||||||
<div>
|
|
||||||
{t`JOB ID:`} {job.id}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
{t`STATUS:`} {job.status.toUpperCase()}
|
|
||||||
</div>
|
|
||||||
{job.finished && (
|
|
||||||
<div>
|
|
||||||
{t`FINISHED:`} {formatDateString(job.finished)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
key={job.id}
|
|
||||||
>
|
|
||||||
<Link to={`/jobs/inventory/${job.id}`}>
|
|
||||||
<StatusLabel status={job.status} />
|
|
||||||
</Link>
|
|
||||||
</Tooltip>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ConstructedInventoryDetail({ inventory }) {
|
|
||||||
const history = useHistory();
|
|
||||||
const helpText = getHelpText();
|
|
||||||
|
|
||||||
const {
|
|
||||||
result: { instanceGroups, inputInventories, inventorySource, actions },
|
|
||||||
request: fetchRelatedDetails,
|
|
||||||
error: contentError,
|
|
||||||
isLoading,
|
|
||||||
} = useRequest(
|
|
||||||
useCallback(async () => {
|
|
||||||
const [
|
|
||||||
instanceGroupsResponse,
|
|
||||||
inputInventoriesResponse,
|
|
||||||
inventorySourceResponse,
|
|
||||||
optionsResponse,
|
|
||||||
] = await Promise.all([
|
|
||||||
InventoriesAPI.readInstanceGroups(inventory.id),
|
|
||||||
InventoriesAPI.readInputInventories(inventory.id),
|
|
||||||
InventoriesAPI.readSources(inventory.id),
|
|
||||||
ConstructedInventoriesAPI.readOptions(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return {
|
|
||||||
instanceGroups: instanceGroupsResponse.data.results,
|
|
||||||
inputInventories: inputInventoriesResponse.data.results,
|
|
||||||
inventorySource: inventorySourceResponse.data.results[0],
|
|
||||||
actions: optionsResponse.data.actions.GET,
|
|
||||||
};
|
|
||||||
}, [inventory.id]),
|
|
||||||
{
|
|
||||||
instanceGroups: [],
|
|
||||||
inputInventories: [],
|
|
||||||
inventorySource: {},
|
|
||||||
actions: {},
|
|
||||||
isLoading: true,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetchRelatedDetails();
|
|
||||||
}, [fetchRelatedDetails]);
|
|
||||||
|
|
||||||
const wsInventorySource = useWsInventorySourcesDetails(inventorySource);
|
|
||||||
const inventorySourceSyncJob =
|
|
||||||
wsInventorySource.summary_fields?.current_job ||
|
|
||||||
wsInventorySource.summary_fields?.last_job ||
|
|
||||||
null;
|
|
||||||
const wsInventory = {
|
|
||||||
...inventory,
|
|
||||||
...wsInventorySource?.summary_fields?.inventory,
|
|
||||||
};
|
|
||||||
|
|
||||||
const { request: deleteInventory, error: deleteError } = useRequest(
|
|
||||||
useCallback(async () => {
|
|
||||||
await InventoriesAPI.destroy(inventory.id);
|
|
||||||
history.push(`/inventories`);
|
|
||||||
}, [inventory.id, history])
|
|
||||||
);
|
|
||||||
|
|
||||||
const { error, dismissError } = useDismissableError(deleteError);
|
|
||||||
|
|
||||||
const deleteDetailsRequests =
|
|
||||||
relatedResourceDeleteRequests.inventory(inventory);
|
|
||||||
|
|
||||||
if (isLoading) {
|
|
||||||
return <ContentLoading />;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (contentError) {
|
|
||||||
return <ContentError error={contentError} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<CardBody>
|
|
||||||
<DetailList>
|
|
||||||
<Detail
|
|
||||||
label={t`Name`}
|
|
||||||
value={inventory.name}
|
|
||||||
dataCy="constructed-inventory-name"
|
|
||||||
/>
|
|
||||||
<Detail
|
|
||||||
label={t`Last Job Status`}
|
|
||||||
value={
|
|
||||||
inventorySourceSyncJob && (
|
|
||||||
<JobStatusLabel job={inventorySourceSyncJob} />
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Detail
|
|
||||||
label={t`Description`}
|
|
||||||
value={inventory.description}
|
|
||||||
dataCy="constructed-inventory-description"
|
|
||||||
/>
|
|
||||||
<Detail
|
|
||||||
label={t`Type`}
|
|
||||||
value={t`Constructed Inventory`}
|
|
||||||
dataCy="constructed-inventory-type"
|
|
||||||
/>
|
|
||||||
<Detail
|
|
||||||
label={actions.limit.label}
|
|
||||||
value={inventory.limit}
|
|
||||||
helpText={actions.limit.help_text}
|
|
||||||
dataCy="constructed-inventory-limit"
|
|
||||||
/>
|
|
||||||
<Detail
|
|
||||||
label={t`Organization`}
|
|
||||||
dataCy="constructed-inventory-organization"
|
|
||||||
value={
|
|
||||||
<Link
|
|
||||||
to={`/organizations/${inventory.summary_fields?.organization.id}/details`}
|
|
||||||
>
|
|
||||||
{inventory.summary_fields?.organization.name}
|
|
||||||
</Link>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Detail
|
|
||||||
label={actions.total_groups.label}
|
|
||||||
value={wsInventory.total_groups}
|
|
||||||
helpText={actions.total_groups.help_text}
|
|
||||||
dataCy="constructed-inventory-total-groups"
|
|
||||||
/>
|
|
||||||
<Detail
|
|
||||||
label={actions.total_hosts.label}
|
|
||||||
value={wsInventory.total_hosts}
|
|
||||||
helpText={actions.total_hosts.help_text}
|
|
||||||
dataCy="constructed-inventory-total-hosts"
|
|
||||||
/>
|
|
||||||
<Detail
|
|
||||||
label={actions.total_inventory_sources.label}
|
|
||||||
value={wsInventory.total_inventory_sources}
|
|
||||||
helpText={actions.total_inventory_sources.help_text}
|
|
||||||
dataCy="constructed-inventory-sources"
|
|
||||||
/>
|
|
||||||
<Detail
|
|
||||||
label={actions.update_cache_timeout.label}
|
|
||||||
value={inventory.update_cache_timeout}
|
|
||||||
helpText={actions.update_cache_timeout.help_text}
|
|
||||||
dataCy="constructed-inventory-cache-timeout"
|
|
||||||
/>
|
|
||||||
<Detail
|
|
||||||
label={actions.inventory_sources_with_failures.label}
|
|
||||||
value={wsInventory.inventory_sources_with_failures}
|
|
||||||
helpText={actions.inventory_sources_with_failures.help_text}
|
|
||||||
dataCy="constructed-inventory-sources-with-failures"
|
|
||||||
/>
|
|
||||||
<Detail
|
|
||||||
label={actions.verbosity.label}
|
|
||||||
value={inventory.verbosity}
|
|
||||||
helpText={actions.verbosity.help_text}
|
|
||||||
dataCy="constructed-inventory-verbosity"
|
|
||||||
/>
|
|
||||||
{instanceGroups && (
|
|
||||||
<Detail
|
|
||||||
fullWidth
|
|
||||||
label={t`Instance Groups`}
|
|
||||||
value={<InstanceGroupLabels labels={instanceGroups} isLinkable />}
|
|
||||||
isEmpty={instanceGroups.length === 0}
|
|
||||||
dataCy="constructed-inventory-instance-groups"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{inventory.prevent_instance_group_fallback && (
|
|
||||||
<Detail
|
|
||||||
fullWidth
|
|
||||||
label={t`Enabled Options`}
|
|
||||||
dataCy="constructed-inventory-instance-group-fallback"
|
|
||||||
value={
|
|
||||||
<TextList component={TextListVariants.ul}>
|
|
||||||
{inventory.prevent_instance_group_fallback && (
|
|
||||||
<TextListItem component={TextListItemVariants.li}>
|
|
||||||
{t`Prevent Instance Group Fallback`}
|
|
||||||
<Popover
|
|
||||||
header={t`Prevent Instance Group Fallback`}
|
|
||||||
content={helpText.preventInstanceGroupFallback}
|
|
||||||
/>
|
|
||||||
</TextListItem>
|
|
||||||
)}
|
|
||||||
</TextList>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<Detail
|
|
||||||
fullWidth
|
|
||||||
helpText={helpText.labels}
|
|
||||||
dataCy="constructed-inventory-labels"
|
|
||||||
label={t`Labels`}
|
|
||||||
value={
|
|
||||||
<ChipGroup
|
|
||||||
numChips={5}
|
|
||||||
totalChips={inventory.summary_fields.labels?.results?.length}
|
|
||||||
>
|
|
||||||
{inventory.summary_fields.labels?.results?.map((l) => (
|
|
||||||
<Chip key={l.id} isReadOnly>
|
|
||||||
{l.name}
|
|
||||||
</Chip>
|
|
||||||
))}
|
|
||||||
</ChipGroup>
|
|
||||||
}
|
|
||||||
isEmpty={inventory.summary_fields.labels?.results?.length === 0}
|
|
||||||
/>
|
|
||||||
<Detail
|
|
||||||
fullWidth
|
|
||||||
label={t`Input Inventories`}
|
|
||||||
value={
|
|
||||||
<LabelGroup numLabels={5}>
|
|
||||||
{inputInventories?.map((inputInventory) => (
|
|
||||||
<Label
|
|
||||||
color="blue"
|
|
||||||
key={inputInventory.id}
|
|
||||||
render={({ className, content, componentRef }) => (
|
|
||||||
<Link
|
|
||||||
className={className}
|
|
||||||
innerRef={componentRef}
|
|
||||||
to={`/inventories/inventory/${inputInventory.id}/details`}
|
|
||||||
>
|
|
||||||
{content}
|
|
||||||
</Link>
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{inputInventory.name}
|
|
||||||
</Label>
|
|
||||||
))}
|
|
||||||
</LabelGroup>
|
|
||||||
}
|
|
||||||
isEmpty={inputInventories?.length === 0}
|
|
||||||
/>
|
|
||||||
<VariablesDetail
|
|
||||||
label={actions.source_vars.label}
|
|
||||||
helpText={helpText.variables()}
|
|
||||||
value={inventory.source_vars}
|
|
||||||
rows={4}
|
|
||||||
name="variables"
|
|
||||||
dataCy="inventory-detail-variables"
|
|
||||||
/>
|
|
||||||
<UserDateDetail
|
|
||||||
label={actions.created.label}
|
|
||||||
date={inventory.created}
|
|
||||||
user={inventory.summary_fields.created_by}
|
|
||||||
/>
|
|
||||||
<UserDateDetail
|
|
||||||
label={actions.modified.label}
|
|
||||||
date={inventory.modified}
|
|
||||||
user={inventory.summary_fields.modified_by}
|
|
||||||
/>
|
|
||||||
</DetailList>
|
|
||||||
<CardActionsRow>
|
|
||||||
{inventory?.summary_fields?.user_capabilities?.edit && (
|
|
||||||
<Button
|
|
||||||
ouiaId="inventory-detail-edit-button"
|
|
||||||
component={Link}
|
|
||||||
to={`/inventories/constructed_inventory/${inventory.id}/edit`}
|
|
||||||
>
|
|
||||||
{t`Edit`}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{inventorySource?.summary_fields?.user_capabilities?.start &&
|
|
||||||
(['new', 'running', 'pending', 'waiting'].includes(
|
|
||||||
inventorySourceSyncJob?.status
|
|
||||||
) ? (
|
|
||||||
<JobCancelButton
|
|
||||||
job={{ id: inventorySourceSyncJob.id, type: 'inventory_update' }}
|
|
||||||
errorTitle={t`Constructed Inventory Source Sync Error`}
|
|
||||||
title={t`Cancel Constructed Inventory Source Sync`}
|
|
||||||
errorMessage={t`Failed to cancel Constructed Inventory Source Sync`}
|
|
||||||
buttonText={t`Cancel Sync`}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<ConstructedInventorySyncButton inventoryId={inventory.id} />
|
|
||||||
))}
|
|
||||||
{inventory?.summary_fields?.user_capabilities?.delete && (
|
|
||||||
<DeleteButton
|
|
||||||
name={inventory.name}
|
|
||||||
modalTitle={t`Delete Inventory`}
|
|
||||||
onConfirm={deleteInventory}
|
|
||||||
deleteDetailsRequests={deleteDetailsRequests}
|
|
||||||
deleteMessage={t`This inventory is currently being used by other resources. Are you sure you want to delete it?`}
|
|
||||||
>
|
|
||||||
{t`Delete`}
|
|
||||||
</DeleteButton>
|
|
||||||
)}
|
|
||||||
</CardActionsRow>
|
|
||||||
{error && (
|
|
||||||
<AlertModal
|
|
||||||
isOpen={error}
|
|
||||||
variant="error"
|
|
||||||
title={t`Error!`}
|
|
||||||
onClose={dismissError}
|
|
||||||
>
|
|
||||||
{t`Failed to delete inventory.`}
|
|
||||||
<ErrorDetail error={error} />
|
|
||||||
</AlertModal>
|
|
||||||
)}
|
|
||||||
</CardBody>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
ConstructedInventoryDetail.propTypes = {
|
|
||||||
inventory: Inventory.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ConstructedInventoryDetail;
|
|
||||||
@@ -1,250 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { Router } from 'react-router-dom';
|
|
||||||
import { InventoriesAPI, ConstructedInventoriesAPI } from 'api';
|
|
||||||
import {
|
|
||||||
render,
|
|
||||||
screen,
|
|
||||||
waitForElementToBeRemoved,
|
|
||||||
} from '@testing-library/react';
|
|
||||||
import '@testing-library/jest-dom';
|
|
||||||
import { createMemoryHistory } from 'history';
|
|
||||||
import { I18nProvider } from '@lingui/react';
|
|
||||||
import { i18n } from '@lingui/core';
|
|
||||||
import { en } from 'make-plural/plurals';
|
|
||||||
import english from '../../../locales/en/messages';
|
|
||||||
import ConstructedInventoryDetail from './ConstructedInventoryDetail';
|
|
||||||
|
|
||||||
jest.mock('../../../api');
|
|
||||||
|
|
||||||
const mockInventory = {
|
|
||||||
id: 1,
|
|
||||||
type: 'inventory',
|
|
||||||
summary_fields: {
|
|
||||||
organization: {
|
|
||||||
id: 1,
|
|
||||||
name: 'The Organization',
|
|
||||||
description: '',
|
|
||||||
},
|
|
||||||
created_by: {
|
|
||||||
username: 'the_creator',
|
|
||||||
id: 2,
|
|
||||||
},
|
|
||||||
modified_by: {
|
|
||||||
username: 'the_modifier',
|
|
||||||
id: 3,
|
|
||||||
},
|
|
||||||
user_capabilities: {
|
|
||||||
edit: true,
|
|
||||||
delete: true,
|
|
||||||
copy: true,
|
|
||||||
adhoc: true,
|
|
||||||
},
|
|
||||||
labels: {
|
|
||||||
count: 1,
|
|
||||||
results: [
|
|
||||||
{
|
|
||||||
id: 17,
|
|
||||||
name: 'seventeen',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
created: '2019-10-04T16:56:48.025455Z',
|
|
||||||
modified: '2019-10-04T16:56:48.025468Z',
|
|
||||||
name: 'Constructed Inv',
|
|
||||||
description: '',
|
|
||||||
organization: 1,
|
|
||||||
kind: 'constructed',
|
|
||||||
has_active_failures: false,
|
|
||||||
total_hosts: 0,
|
|
||||||
hosts_with_active_failures: 0,
|
|
||||||
total_groups: 0,
|
|
||||||
groups_with_active_failures: 0,
|
|
||||||
has_inventory_sources: false,
|
|
||||||
total_inventory_sources: 0,
|
|
||||||
inventory_sources_with_failures: 0,
|
|
||||||
pending_deletion: false,
|
|
||||||
prevent_instance_group_fallback: true,
|
|
||||||
update_cache_timeout: 0,
|
|
||||||
limit: '',
|
|
||||||
verbosity: 1,
|
|
||||||
source_vars:
|
|
||||||
'{\n "plugin": "constructed",\n "strict": true,\n "groups": {\n "shutdown": "resolved_state == \\"shutdown\\"",\n "shutdown_in_product_dev": "resolved_state == \\"shutdown\\" and account_alias == \\"product_dev\\""\n },\n "compose": {\n "resolved_state": "state | default(\\"running\\")"\n }\n}',
|
|
||||||
};
|
|
||||||
|
|
||||||
describe('<ConstructedInventoryDetail />', () => {
|
|
||||||
const history = createMemoryHistory({
|
|
||||||
initialEntries: ['/inventories/constructed_inventory/1/details'],
|
|
||||||
});
|
|
||||||
|
|
||||||
const Component = (props) => (
|
|
||||||
<I18nProvider i18n={i18n}>
|
|
||||||
<Router history={history}>
|
|
||||||
<ConstructedInventoryDetail inventory={mockInventory} {...props} />
|
|
||||||
</Router>
|
|
||||||
</I18nProvider>
|
|
||||||
);
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
i18n.loadLocaleData({ en: { plurals: en } });
|
|
||||||
i18n.load({ en: english });
|
|
||||||
i18n.activate('en');
|
|
||||||
|
|
||||||
InventoriesAPI.readInstanceGroups.mockResolvedValue({
|
|
||||||
data: { results: [] },
|
|
||||||
});
|
|
||||||
InventoriesAPI.readInputInventories.mockResolvedValue({
|
|
||||||
data: {
|
|
||||||
results: [
|
|
||||||
{
|
|
||||||
id: 123,
|
|
||||||
name: 'input_inventory_123',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 456,
|
|
||||||
name: 'input_inventory_456',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
InventoriesAPI.readSources.mockResolvedValue({
|
|
||||||
data: {
|
|
||||||
results: [
|
|
||||||
{
|
|
||||||
id: 999,
|
|
||||||
type: 'inventory_source',
|
|
||||||
summary_fields: {
|
|
||||||
last_job: {
|
|
||||||
id: 101,
|
|
||||||
name: 'Auto-created source for: Constructed Inv',
|
|
||||||
status: 'successful',
|
|
||||||
finished: '2023-02-02T22:22:22.222220Z',
|
|
||||||
},
|
|
||||||
user_capabilities: {
|
|
||||||
start: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
ConstructedInventoriesAPI.readOptions.mockResolvedValue({
|
|
||||||
data: {
|
|
||||||
related: {},
|
|
||||||
actions: {
|
|
||||||
GET: {
|
|
||||||
limit: {
|
|
||||||
label: 'Limit',
|
|
||||||
help_text: '',
|
|
||||||
},
|
|
||||||
total_groups: {
|
|
||||||
label: 'Total Groups',
|
|
||||||
help_text: '',
|
|
||||||
},
|
|
||||||
total_hosts: {
|
|
||||||
label: 'Total Hosts',
|
|
||||||
help_text: '',
|
|
||||||
},
|
|
||||||
total_inventory_sources: {
|
|
||||||
label: 'Total inventory sources',
|
|
||||||
help_text: '',
|
|
||||||
},
|
|
||||||
update_cache_timeout: {
|
|
||||||
label: 'Update cache timeout',
|
|
||||||
help_text: '',
|
|
||||||
},
|
|
||||||
inventory_sources_with_failures: {
|
|
||||||
label: 'Inventory sources with failures',
|
|
||||||
help_text: '',
|
|
||||||
},
|
|
||||||
source_vars: {
|
|
||||||
label: 'Source vars',
|
|
||||||
help_text: '',
|
|
||||||
},
|
|
||||||
verbosity: {
|
|
||||||
label: 'Verbosity',
|
|
||||||
help_text: '',
|
|
||||||
},
|
|
||||||
created: {
|
|
||||||
label: 'Created by',
|
|
||||||
help_text: '',
|
|
||||||
},
|
|
||||||
modified: {
|
|
||||||
label: 'Modified by',
|
|
||||||
help_text: '',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
jest.clearAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should render details', async () => {
|
|
||||||
render(<Component />);
|
|
||||||
await waitForElementToBeRemoved(() => screen.getByRole('progressbar'));
|
|
||||||
expect(screen.getByText('Name')).toBeInTheDocument();
|
|
||||||
expect(screen.getByText('Constructed Inv')).toBeInTheDocument();
|
|
||||||
expect(screen.getByText('Last Job Status')).toBeInTheDocument();
|
|
||||||
expect(screen.getByText('Successful')).toBeInTheDocument();
|
|
||||||
expect(screen.getByText('Type')).toBeInTheDocument();
|
|
||||||
expect(screen.getByText('Constructed Inventory')).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should render action buttons', async () => {
|
|
||||||
render(<Component />);
|
|
||||||
await waitForElementToBeRemoved(() => screen.getByRole('progressbar'));
|
|
||||||
expect(screen.getByRole('link', { name: 'Edit' })).toHaveAttribute(
|
|
||||||
'href',
|
|
||||||
'/inventories/constructed_inventory/1/edit'
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
screen.getByRole('button', { name: 'Start inventory source sync' })
|
|
||||||
).toBeInTheDocument();
|
|
||||||
expect(screen.getByRole('button', { name: 'Delete' })).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should show cancel sync button during an inventory source sync running job', async () => {
|
|
||||||
InventoriesAPI.readSources.mockResolvedValue({
|
|
||||||
data: {
|
|
||||||
results: [
|
|
||||||
{
|
|
||||||
id: 999,
|
|
||||||
type: 'inventory_source',
|
|
||||||
summary_fields: {
|
|
||||||
current_job: {
|
|
||||||
id: 111,
|
|
||||||
name: 'Auto-created source for: Constructed Inv',
|
|
||||||
status: 'running',
|
|
||||||
},
|
|
||||||
user_capabilities: {
|
|
||||||
start: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
render(<Component />);
|
|
||||||
await waitForElementToBeRemoved(() => screen.getByRole('progressbar'));
|
|
||||||
expect(
|
|
||||||
screen.getByRole('button', {
|
|
||||||
name: 'Cancel Constructed Inventory Source Sync',
|
|
||||||
})
|
|
||||||
).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should show error when the api throws while fetching details', async () => {
|
|
||||||
InventoriesAPI.readInputInventories.mockRejectedValueOnce(new Error());
|
|
||||||
render(<Component />);
|
|
||||||
await waitForElementToBeRemoved(() => screen.getByRole('progressbar'));
|
|
||||||
expect(
|
|
||||||
screen.getByText(
|
|
||||||
'There was an error loading this content. Please reload the page.'
|
|
||||||
)
|
|
||||||
).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
import React, { useCallback } from 'react';
|
|
||||||
import { t } from '@lingui/macro';
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import { Button, Tooltip } from '@patternfly/react-core';
|
|
||||||
import useRequest, { useDismissableError } from 'hooks/useRequest';
|
|
||||||
import AlertModal from 'components/AlertModal/AlertModal';
|
|
||||||
import ErrorDetail from 'components/ErrorDetail/ErrorDetail';
|
|
||||||
import { InventoriesAPI } from 'api';
|
|
||||||
|
|
||||||
function ConstructedInventorySyncButton({ inventoryId }) {
|
|
||||||
const testId = `constructed-inventory-${inventoryId}-sync`;
|
|
||||||
const {
|
|
||||||
isLoading: startSyncLoading,
|
|
||||||
error: startSyncError,
|
|
||||||
request: startSyncProcess,
|
|
||||||
} = useRequest(
|
|
||||||
useCallback(
|
|
||||||
async () => InventoriesAPI.syncAllSources(inventoryId),
|
|
||||||
[inventoryId]
|
|
||||||
),
|
|
||||||
{}
|
|
||||||
);
|
|
||||||
|
|
||||||
const { error: startError, dismissError: dismissStartError } =
|
|
||||||
useDismissableError(startSyncError);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Tooltip content={t`Start sync process`} position="top">
|
|
||||||
<Button
|
|
||||||
ouiaId={testId}
|
|
||||||
isDisabled={startSyncLoading}
|
|
||||||
aria-label={t`Start inventory source sync`}
|
|
||||||
variant="secondary"
|
|
||||||
onClick={startSyncProcess}
|
|
||||||
>
|
|
||||||
{t`Sync`}
|
|
||||||
</Button>
|
|
||||||
</Tooltip>
|
|
||||||
{startError && (
|
|
||||||
<AlertModal
|
|
||||||
isOpen={startError}
|
|
||||||
variant="error"
|
|
||||||
title={t`Error!`}
|
|
||||||
onClose={dismissStartError}
|
|
||||||
>
|
|
||||||
{t`Failed to sync constructed inventory source`}
|
|
||||||
<ErrorDetail error={startError} />
|
|
||||||
</AlertModal>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
ConstructedInventorySyncButton.propTypes = {
|
|
||||||
inventoryId: PropTypes.number.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ConstructedInventorySyncButton;
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { InventoriesAPI } from 'api';
|
|
||||||
import ConstructedInventorySyncButton from './ConstructedInventorySyncButton';
|
|
||||||
import { render, fireEvent, screen, waitFor } from '@testing-library/react';
|
|
||||||
import '@testing-library/jest-dom';
|
|
||||||
|
|
||||||
jest.mock('../../../api');
|
|
||||||
|
|
||||||
const inventory = { id: 100, name: 'Constructed Inventory' };
|
|
||||||
|
|
||||||
describe('<ConstructedInventorySyncButton />', () => {
|
|
||||||
const Component = () => (
|
|
||||||
<ConstructedInventorySyncButton inventoryId={inventory.id} />
|
|
||||||
);
|
|
||||||
|
|
||||||
test('should render start sync button', () => {
|
|
||||||
render(<Component />);
|
|
||||||
expect(
|
|
||||||
screen.getByRole('button', { name: 'Start inventory source sync' })
|
|
||||||
).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should make expected api request on sync', async () => {
|
|
||||||
render(<Component />);
|
|
||||||
const syncButton = screen.queryByText('Sync');
|
|
||||||
fireEvent.click(syncButton);
|
|
||||||
await waitFor(() =>
|
|
||||||
expect(InventoriesAPI.syncAllSources).toHaveBeenCalledWith(100)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should show alert modal on throw', async () => {
|
|
||||||
InventoriesAPI.syncAllSources.mockRejectedValueOnce(new Error());
|
|
||||||
render(<Component />);
|
|
||||||
await waitFor(() => {
|
|
||||||
const syncButton = screen.queryByText('Sync');
|
|
||||||
fireEvent.click(syncButton);
|
|
||||||
});
|
|
||||||
expect(screen.getByRole('dialog', { name: 'Alert modal Error!' }));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export { default } from './ConstructedInventoryDetail';
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
/* eslint i18next/no-literal-string: "off" */
|
|
||||||
import React from 'react';
|
|
||||||
import { CardBody } from 'components/Card';
|
|
||||||
|
|
||||||
function ConstructedInventoryEdit() {
|
|
||||||
return (
|
|
||||||
<CardBody>
|
|
||||||
<div>Coming Soon!</div>
|
|
||||||
</CardBody>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ConstructedInventoryEdit;
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { act } from 'react-dom/test-utils';
|
|
||||||
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
|
||||||
import ConstructedInventoryEdit from './ConstructedInventoryEdit';
|
|
||||||
|
|
||||||
describe('<ConstructedInventoryEdit />', () => {
|
|
||||||
test('initially renders successfully', async () => {
|
|
||||||
let wrapper;
|
|
||||||
await act(async () => {
|
|
||||||
wrapper = mountWithContexts(<ConstructedInventoryEdit />);
|
|
||||||
});
|
|
||||||
expect(wrapper.length).toBe(1);
|
|
||||||
expect(wrapper.find('ConstructedInventoryEdit').length).toBe(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export { default } from './ConstructedInventoryEdit';
|
|
||||||
@@ -9,18 +9,14 @@ import PersistentFilters from 'components/PersistentFilters';
|
|||||||
import { InventoryList } from './InventoryList';
|
import { InventoryList } from './InventoryList';
|
||||||
import Inventory from './Inventory';
|
import Inventory from './Inventory';
|
||||||
import SmartInventory from './SmartInventory';
|
import SmartInventory from './SmartInventory';
|
||||||
import ConstructedInventory from './ConstructedInventory';
|
|
||||||
import InventoryAdd from './InventoryAdd';
|
import InventoryAdd from './InventoryAdd';
|
||||||
import SmartInventoryAdd from './SmartInventoryAdd';
|
import SmartInventoryAdd from './SmartInventoryAdd';
|
||||||
import ConstructedInventoryAdd from './ConstructedInventoryAdd';
|
|
||||||
import { getInventoryPath } from './shared/utils';
|
|
||||||
|
|
||||||
function Inventories() {
|
function Inventories() {
|
||||||
const initScreenHeader = useRef({
|
const initScreenHeader = useRef({
|
||||||
'/inventories': t`Inventories`,
|
'/inventories': t`Inventories`,
|
||||||
'/inventories/inventory/add': t`Create new inventory`,
|
'/inventories/inventory/add': t`Create new inventory`,
|
||||||
'/inventories/smart_inventory/add': t`Create new smart inventory`,
|
'/inventories/smart_inventory/add': t`Create new smart inventory`,
|
||||||
'/inventories/constructed_inventory/add': t`Create new constructed inventory`,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const [breadcrumbConfig, setScreenHeader] = useState(
|
const [breadcrumbConfig, setScreenHeader] = useState(
|
||||||
@@ -49,7 +45,10 @@ function Inventories() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const inventoryPath = getInventoryPath(inventory);
|
const inventoryKind =
|
||||||
|
inventory.kind === 'smart' ? 'smart_inventory' : 'inventory';
|
||||||
|
|
||||||
|
const inventoryPath = `/inventories/${inventoryKind}/${inventory.id}`;
|
||||||
const inventoryHostsPath = `${inventoryPath}/hosts`;
|
const inventoryHostsPath = `${inventoryPath}/hosts`;
|
||||||
const inventoryGroupsPath = `${inventoryPath}/groups`;
|
const inventoryGroupsPath = `${inventoryPath}/groups`;
|
||||||
const inventorySourcesPath = `${inventoryPath}/sources`;
|
const inventorySourcesPath = `${inventoryPath}/sources`;
|
||||||
@@ -110,9 +109,6 @@ function Inventories() {
|
|||||||
<Route path="/inventories/smart_inventory/add">
|
<Route path="/inventories/smart_inventory/add">
|
||||||
<SmartInventoryAdd />
|
<SmartInventoryAdd />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/inventories/constructed_inventory/add">
|
|
||||||
<ConstructedInventoryAdd />
|
|
||||||
</Route>
|
|
||||||
<Route path="/inventories/inventory/:id">
|
<Route path="/inventories/inventory/:id">
|
||||||
<Config>
|
<Config>
|
||||||
{({ me }) => (
|
{({ me }) => (
|
||||||
@@ -123,9 +119,6 @@ function Inventories() {
|
|||||||
<Route path="/inventories/smart_inventory/:id">
|
<Route path="/inventories/smart_inventory/:id">
|
||||||
<SmartInventory setBreadcrumb={setBreadcrumbConfig} />
|
<SmartInventory setBreadcrumb={setBreadcrumbConfig} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/inventories/constructed_inventory/:id">
|
|
||||||
<ConstructedInventory setBreadcrumb={setBreadcrumbConfig} />
|
|
||||||
</Route>
|
|
||||||
<Route path="/inventories">
|
<Route path="/inventories">
|
||||||
<PersistentFilters pageKey="inventories">
|
<PersistentFilters pageKey="inventories">
|
||||||
<InventoryList />
|
<InventoryList />
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import InventoryEdit from './InventoryEdit';
|
|||||||
import InventoryGroups from './InventoryGroups';
|
import InventoryGroups from './InventoryGroups';
|
||||||
import InventoryHosts from './InventoryHosts/InventoryHosts';
|
import InventoryHosts from './InventoryHosts/InventoryHosts';
|
||||||
import InventorySources from './InventorySources';
|
import InventorySources from './InventorySources';
|
||||||
import { getInventoryPath } from './shared/utils';
|
|
||||||
|
|
||||||
function Inventory({ setBreadcrumb }) {
|
function Inventory({ setBreadcrumb }) {
|
||||||
const [contentError, setContentError] = useState(null);
|
const [contentError, setContentError] = useState(null);
|
||||||
@@ -112,8 +111,10 @@ function Inventory({ setBreadcrumb }) {
|
|||||||
showCardHeader = false;
|
showCardHeader = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inventory && inventory?.kind !== '') {
|
if (inventory?.kind === 'smart') {
|
||||||
return <Redirect to={`${getInventoryPath(inventory)}/details`} />;
|
return (
|
||||||
|
<Redirect to={`/inventories/smart_inventory/${inventory.id}/details`} />
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ function InventoryGroup({ setBreadcrumb, inventory }) {
|
|||||||
const [inventoryGroup, setInventoryGroup] = useState(null);
|
const [inventoryGroup, setInventoryGroup] = useState(null);
|
||||||
const [contentLoading, setContentLoading] = useState(true);
|
const [contentLoading, setContentLoading] = useState(true);
|
||||||
const [contentError, setContentError] = useState(null);
|
const [contentError, setContentError] = useState(null);
|
||||||
const { id: inventoryId, groupId, inventoryType } = useParams();
|
const { id: inventoryId, groupId } = useParams();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -50,22 +50,22 @@ function InventoryGroup({ setBreadcrumb, inventory }) {
|
|||||||
{t`Back to Groups`}
|
{t`Back to Groups`}
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
link: `/inventories/${inventoryType}/${inventoryId}/groups`,
|
link: `/inventories/inventory/${inventory.id}/groups`,
|
||||||
id: 99,
|
id: 99,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: t`Details`,
|
name: t`Details`,
|
||||||
link: `/inventories/${inventoryType}/${inventoryId}/groups/${inventoryGroup?.id}/details`,
|
link: `/inventories/inventory/${inventory.id}/groups/${inventoryGroup?.id}/details`,
|
||||||
id: 0,
|
id: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: t`Related Groups`,
|
name: t`Related Groups`,
|
||||||
link: `/inventories/${inventoryType}/${inventoryId}/groups/${inventoryGroup?.id}/nested_groups`,
|
link: `/inventories/inventory/${inventory.id}/groups/${inventoryGroup?.id}/nested_groups`,
|
||||||
id: 1,
|
id: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: t`Hosts`,
|
name: t`Hosts`,
|
||||||
link: `/inventories/${inventoryType}/${inventoryId}/groups/${inventoryGroup?.id}/nested_hosts`,
|
link: `/inventories/inventory/${inventory.id}/groups/${inventoryGroup?.id}/nested_hosts`,
|
||||||
id: 2,
|
id: 2,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -105,32 +105,32 @@ function InventoryGroup({ setBreadcrumb, inventory }) {
|
|||||||
{showCardHeader && <RoutedTabs tabsArray={tabsArray} />}
|
{showCardHeader && <RoutedTabs tabsArray={tabsArray} />}
|
||||||
<Switch>
|
<Switch>
|
||||||
<Redirect
|
<Redirect
|
||||||
from="/inventories/:inventoryType/:id/groups/:groupId"
|
from="/inventories/inventory/:id/groups/:groupId"
|
||||||
to="/inventories/:inventoryType/:id/groups/:groupId/details"
|
to="/inventories/inventory/:id/groups/:groupId/details"
|
||||||
exact
|
exact
|
||||||
/>
|
/>
|
||||||
{inventoryGroup && [
|
{inventoryGroup && [
|
||||||
<Route
|
<Route
|
||||||
key="edit"
|
key="edit"
|
||||||
path="/inventories/:inventoryType/:id/groups/:groupId/edit"
|
path="/inventories/inventory/:id/groups/:groupId/edit"
|
||||||
>
|
>
|
||||||
<InventoryGroupEdit inventoryGroup={inventoryGroup} />
|
<InventoryGroupEdit inventoryGroup={inventoryGroup} />
|
||||||
</Route>,
|
</Route>,
|
||||||
<Route
|
<Route
|
||||||
key="details"
|
key="details"
|
||||||
path="/inventories/:inventoryType/:id/groups/:groupId/details"
|
path="/inventories/inventory/:id/groups/:groupId/details"
|
||||||
>
|
>
|
||||||
<InventoryGroupDetail inventoryGroup={inventoryGroup} />
|
<InventoryGroupDetail inventoryGroup={inventoryGroup} />
|
||||||
</Route>,
|
</Route>,
|
||||||
<Route
|
<Route
|
||||||
key="hosts"
|
key="hosts"
|
||||||
path="/inventories/:inventoryType/:id/groups/:groupId/nested_hosts"
|
path="/inventories/inventory/:id/groups/:groupId/nested_hosts"
|
||||||
>
|
>
|
||||||
<InventoryGroupHosts inventoryGroup={inventoryGroup} />
|
<InventoryGroupHosts inventoryGroup={inventoryGroup} />
|
||||||
</Route>,
|
</Route>,
|
||||||
<Route
|
<Route
|
||||||
key="relatedGroups"
|
key="relatedGroups"
|
||||||
path="/inventories/:inventoryType/:id/groups/:groupId/nested_groups"
|
path="/inventories/inventory/:id/groups/:groupId/nested_groups"
|
||||||
>
|
>
|
||||||
<InventoryRelatedGroups />
|
<InventoryRelatedGroups />
|
||||||
</Route>,
|
</Route>,
|
||||||
@@ -138,7 +138,7 @@ function InventoryGroup({ setBreadcrumb, inventory }) {
|
|||||||
<Route key="not-found" path="*">
|
<Route key="not-found" path="*">
|
||||||
<ContentError>
|
<ContentError>
|
||||||
{inventory && (
|
{inventory && (
|
||||||
<Link to={`/inventories/:inventoryType/${inventory.id}/details`}>
|
<Link to={`/inventories/inventory/${inventory.id}/details`}>
|
||||||
{t`View Inventory Details`}
|
{t`View Inventory Details`}
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -11,16 +11,15 @@ import {
|
|||||||
import InventoryGroup from './InventoryGroup';
|
import InventoryGroup from './InventoryGroup';
|
||||||
|
|
||||||
jest.mock('../../../api');
|
jest.mock('../../../api');
|
||||||
describe('<InventoryGroup />', () => {
|
jest.mock('react-router-dom', () => ({
|
||||||
jest.mock('react-router-dom', () => ({
|
...jest.requireActual('react-router-dom'),
|
||||||
...jest.requireActual('react-router-dom'),
|
useParams: () => ({
|
||||||
useParams: () => ({
|
id: 1,
|
||||||
id: 1,
|
groupId: 2,
|
||||||
groupId: 1,
|
}),
|
||||||
inventoryType: 'inventory',
|
}));
|
||||||
}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
|
describe('<InventoryGroup />', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
let history;
|
let history;
|
||||||
const inventory = { id: 1, name: 'Foo' };
|
const inventory = { id: 1, name: 'Foo' };
|
||||||
@@ -42,11 +41,11 @@ describe('<InventoryGroup />', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
history = createMemoryHistory({
|
history = createMemoryHistory({
|
||||||
initialEntries: [`/inventories/inventory/1/groups/1/details`],
|
initialEntries: ['/inventories/inventory/1/groups/1/details'],
|
||||||
});
|
});
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<Route path="/inventories/:inventoryType/:id/groups">
|
<Route path="/inventories/inventory/:id/groups">
|
||||||
<InventoryGroup setBreadcrumb={() => {}} inventory={inventory} />
|
<InventoryGroup setBreadcrumb={() => {}} inventory={inventory} />
|
||||||
</Route>,
|
</Route>,
|
||||||
{ context: { router: { history } } }
|
{ context: { router: { history } } }
|
||||||
@@ -64,7 +63,7 @@ describe('<InventoryGroup />', () => {
|
|||||||
expect(routedTabs).toHaveLength(1);
|
expect(routedTabs).toHaveLength(1);
|
||||||
|
|
||||||
const tabs = routedTabs.prop('tabsArray');
|
const tabs = routedTabs.prop('tabsArray');
|
||||||
expect(tabs[0].link).toEqual(`/inventories/inventory/1/groups`);
|
expect(tabs[0].link).toEqual('/inventories/inventory/1/groups');
|
||||||
expect(tabs[1].name).toEqual('Details');
|
expect(tabs[1].name).toEqual('Details');
|
||||||
expect(tabs[2].name).toEqual('Related Groups');
|
expect(tabs[2].name).toEqual('Related Groups');
|
||||||
expect(tabs[3].name).toEqual('Hosts');
|
expect(tabs[3].name).toEqual('Hosts');
|
||||||
@@ -72,7 +71,7 @@ describe('<InventoryGroup />', () => {
|
|||||||
|
|
||||||
test('should show content error when user attempts to navigate to erroneous route', async () => {
|
test('should show content error when user attempts to navigate to erroneous route', async () => {
|
||||||
history = createMemoryHistory({
|
history = createMemoryHistory({
|
||||||
initialEntries: [`/inventories/inventory/1/groups/1/foobar`],
|
initialEntries: ['/inventories/inventory/1/groups/1/foobar'],
|
||||||
});
|
});
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
@@ -93,60 +92,3 @@ describe('<InventoryGroup />', () => {
|
|||||||
await waitForElement(wrapper, 'ContentError', (el) => el.length === 1);
|
await waitForElement(wrapper, 'ContentError', (el) => el.length === 1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('constructed inventory', () => {
|
|
||||||
let wrapper;
|
|
||||||
let history;
|
|
||||||
const inventory = { id: 1, name: 'Foo' };
|
|
||||||
|
|
||||||
jest.mock('react-router-dom', () => ({
|
|
||||||
...jest.requireActual('react-router-dom'),
|
|
||||||
useParams: () => ({
|
|
||||||
id: 1,
|
|
||||||
groupId: 2,
|
|
||||||
inventoryType: 'constructed_inventory',
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
GroupsAPI.readDetail.mockResolvedValue({
|
|
||||||
data: {
|
|
||||||
id: 1,
|
|
||||||
name: 'Foo',
|
|
||||||
description: 'Bar',
|
|
||||||
variables: 'bizz: buzz',
|
|
||||||
summary_fields: {
|
|
||||||
inventory: { id: 1 },
|
|
||||||
created_by: { id: 1, username: 'Athena' },
|
|
||||||
modified_by: { id: 1, username: 'Apollo' },
|
|
||||||
},
|
|
||||||
created: '2020-04-25T01:23:45.678901Z',
|
|
||||||
modified: '2020-04-25T01:23:45.678901Z',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
history = createMemoryHistory({
|
|
||||||
initialEntries: [`/inventories/constructed_inventory/1/groups/1/details`],
|
|
||||||
});
|
|
||||||
|
|
||||||
await act(async () => {
|
|
||||||
wrapper = mountWithContexts(
|
|
||||||
<Route path="/inventories/:inventoryType/:id/groups">
|
|
||||||
<InventoryGroup setBreadcrumb={() => {}} inventory={inventory} />
|
|
||||||
</Route>,
|
|
||||||
{ context: { router: { history } } }
|
|
||||||
);
|
|
||||||
});
|
|
||||||
await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Constructed Inventory expect all tabs to exist, including Back to Groups', () => {
|
|
||||||
const routedTabs = wrapper.find('RoutedTabs');
|
|
||||||
expect(routedTabs).toHaveLength(1);
|
|
||||||
|
|
||||||
const tabs = routedTabs.prop('tabsArray');
|
|
||||||
expect(tabs[0].link).toEqual(`/inventories/constructed_inventory/1/groups`);
|
|
||||||
expect(tabs[1].name).toEqual('Details');
|
|
||||||
expect(tabs[2].name).toEqual('Related Groups');
|
|
||||||
expect(tabs[3].name).toEqual('Hosts');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { useHistory, useParams } from 'react-router-dom';
|
|
||||||
import { Button } from '@patternfly/react-core';
|
import { Button } from '@patternfly/react-core';
|
||||||
|
|
||||||
|
import { useHistory, useParams } from 'react-router-dom';
|
||||||
import { VariablesDetail } from 'components/CodeEditor';
|
import { VariablesDetail } from 'components/CodeEditor';
|
||||||
import { CardBody, CardActionsRow } from 'components/Card';
|
import { CardBody, CardActionsRow } from 'components/Card';
|
||||||
import ErrorDetail from 'components/ErrorDetail';
|
import ErrorDetail from 'components/ErrorDetail';
|
||||||
@@ -11,7 +12,6 @@ import { DetailList, Detail, UserDateDetail } from 'components/DetailList';
|
|||||||
import InventoryGroupsDeleteModal from '../shared/InventoryGroupsDeleteModal';
|
import InventoryGroupsDeleteModal from '../shared/InventoryGroupsDeleteModal';
|
||||||
|
|
||||||
function InventoryGroupDetail({ inventoryGroup }) {
|
function InventoryGroupDetail({ inventoryGroup }) {
|
||||||
const { inventoryType, id, groupId } = useParams();
|
|
||||||
const {
|
const {
|
||||||
summary_fields: { created_by, modified_by, user_capabilities },
|
summary_fields: { created_by, modified_by, user_capabilities },
|
||||||
created,
|
created,
|
||||||
@@ -22,6 +22,7 @@ function InventoryGroupDetail({ inventoryGroup }) {
|
|||||||
} = inventoryGroup;
|
} = inventoryGroup;
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState(false);
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const params = useParams();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CardBody>
|
<CardBody>
|
||||||
@@ -46,33 +47,31 @@ function InventoryGroupDetail({ inventoryGroup }) {
|
|||||||
user={modified_by}
|
user={modified_by}
|
||||||
/>
|
/>
|
||||||
</DetailList>
|
</DetailList>
|
||||||
{inventoryType !== 'constructed_inventory' && (
|
<CardActionsRow>
|
||||||
<CardActionsRow>
|
{user_capabilities?.edit && (
|
||||||
{user_capabilities?.edit && (
|
<Button
|
||||||
<Button
|
ouiaId="inventory-group-detail-edit-button"
|
||||||
ouiaId="inventory-group-detail-edit-button"
|
variant="primary"
|
||||||
variant="primary"
|
aria-label={t`Edit`}
|
||||||
aria-label={t`Edit`}
|
onClick={() =>
|
||||||
onClick={() =>
|
history.push(
|
||||||
history.push(
|
`/inventories/inventory/${params.id}/groups/${params.groupId}/edit`
|
||||||
`/inventories/inventory/${id}/groups/${groupId}/edit`
|
)
|
||||||
)
|
}
|
||||||
}
|
>
|
||||||
>
|
{t`Edit`}
|
||||||
{t`Edit`}
|
</Button>
|
||||||
</Button>
|
)}
|
||||||
)}
|
{user_capabilities?.delete && (
|
||||||
{user_capabilities?.delete && (
|
<InventoryGroupsDeleteModal
|
||||||
<InventoryGroupsDeleteModal
|
groups={[inventoryGroup]}
|
||||||
groups={[inventoryGroup]}
|
isDisabled={false}
|
||||||
isDisabled={false}
|
onAfterDelete={() =>
|
||||||
onAfterDelete={() =>
|
history.push(`/inventories/inventory/${params.id}/groups`)
|
||||||
history.push(`/inventories/inventory/${id}/groups`)
|
}
|
||||||
}
|
/>
|
||||||
/>
|
)}
|
||||||
)}
|
</CardActionsRow>
|
||||||
</CardActionsRow>
|
|
||||||
)}
|
|
||||||
{error && (
|
{error && (
|
||||||
<AlertModal
|
<AlertModal
|
||||||
variant="error"
|
variant="error"
|
||||||
|
|||||||
@@ -39,14 +39,6 @@ describe('<InventoryGroupDetail />', () => {
|
|||||||
let history;
|
let history;
|
||||||
|
|
||||||
describe('User has full permissions', () => {
|
describe('User has full permissions', () => {
|
||||||
jest.mock('react-router-dom', () => ({
|
|
||||||
...jest.requireActual('react-router-dom'),
|
|
||||||
useParams: () => ({
|
|
||||||
id: 1,
|
|
||||||
groupId: 3,
|
|
||||||
inventoryType: 'inventory',
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
history = createMemoryHistory({
|
history = createMemoryHistory({
|
||||||
@@ -124,14 +116,6 @@ describe('<InventoryGroupDetail />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('User has read-only permissions', () => {
|
describe('User has read-only permissions', () => {
|
||||||
jest.mock('react-router-dom', () => ({
|
|
||||||
...jest.requireActual('react-router-dom'),
|
|
||||||
useParams: () => ({
|
|
||||||
id: 1,
|
|
||||||
groupId: 3,
|
|
||||||
inventoryType: 'inventory',
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
test('should hide edit/delete buttons', async () => {
|
test('should hide edit/delete buttons', async () => {
|
||||||
const readOnlyGroup = {
|
const readOnlyGroup = {
|
||||||
...inventoryGroup,
|
...inventoryGroup,
|
||||||
@@ -175,48 +159,4 @@ describe('<InventoryGroupDetail />', () => {
|
|||||||
expect(wrapper.find('button[aria-label="Delete"]').length).toBe(0);
|
expect(wrapper.find('button[aria-label="Delete"]').length).toBe(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('Cannot edit or delete constructed inventory group', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
await act(async () => {
|
|
||||||
history = createMemoryHistory({
|
|
||||||
initialEntries: ['/inventories/inventory/1/groups/1/details'],
|
|
||||||
});
|
|
||||||
wrapper = mountWithContexts(
|
|
||||||
<Route path="/inventories/inventory/:id/groups/:groupId">
|
|
||||||
<InventoryGroupDetail inventoryGroup={inventoryGroup} />
|
|
||||||
</Route>,
|
|
||||||
{
|
|
||||||
context: {
|
|
||||||
router: {
|
|
||||||
history,
|
|
||||||
route: {
|
|
||||||
location: history.location,
|
|
||||||
match: {
|
|
||||||
params: {
|
|
||||||
id: 1,
|
|
||||||
group: 2,
|
|
||||||
inventoryType: 'constructed_inventory',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
await waitForElement(
|
|
||||||
wrapper,
|
|
||||||
'ContentLoading',
|
|
||||||
(el) => el.length === 0
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
afterEach(() => {
|
|
||||||
jest.clearAllMocks();
|
|
||||||
});
|
|
||||||
test('should not show edit button', () => {
|
|
||||||
const editButton = wrapper.find('Button[aria-label="edit"]');
|
|
||||||
expect(editButton.length).toBe(0);
|
|
||||||
expect(wrapper.find('Button[aria-label="delete"]').length).toBe(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ const QS_CONFIG = getQSConfig('host', {
|
|||||||
function InventoryGroupHostList() {
|
function InventoryGroupHostList() {
|
||||||
const [isAdHocLaunchLoading, setIsAdHocLaunchLoading] = useState(false);
|
const [isAdHocLaunchLoading, setIsAdHocLaunchLoading] = useState(false);
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
const { id: inventoryId, groupId, inventoryType } = useParams();
|
const { id: inventoryId, groupId } = useParams();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -145,11 +145,9 @@ function InventoryGroupHostList() {
|
|||||||
useDismissableError(associateErr);
|
useDismissableError(associateErr);
|
||||||
const { error: disassociateError, dismissError: dismissDisassociateError } =
|
const { error: disassociateError, dismissError: dismissDisassociateError } =
|
||||||
useDismissableError(disassociateErr);
|
useDismissableError(disassociateErr);
|
||||||
const isNotConstructedInventory = inventoryType !== 'constructed_inventory';
|
|
||||||
const canAdd =
|
const canAdd =
|
||||||
actions &&
|
actions && Object.prototype.hasOwnProperty.call(actions, 'POST');
|
||||||
Object.prototype.hasOwnProperty.call(actions, 'POST') &&
|
|
||||||
isNotConstructedInventory;
|
|
||||||
const addFormUrl = `/inventories/inventory/${inventoryId}/groups/${groupId}/nested_hosts/add`;
|
const addFormUrl = `/inventories/inventory/${inventoryId}/groups/${groupId}/nested_hosts/add`;
|
||||||
const addExistingHost = t`Add existing host`;
|
const addExistingHost = t`Add existing host`;
|
||||||
const addNewHost = t`Add new host`;
|
const addNewHost = t`Add new host`;
|
||||||
@@ -242,21 +240,17 @@ function InventoryGroupHostList() {
|
|||||||
/>,
|
/>,
|
||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
...(isNotConstructedInventory
|
<DisassociateButton
|
||||||
? [
|
key="disassociate"
|
||||||
<DisassociateButton
|
onDisassociate={handleDisassociate}
|
||||||
key="disassociate"
|
itemsToDisassociate={selected}
|
||||||
onDisassociate={handleDisassociate}
|
modalTitle={t`Disassociate host from group?`}
|
||||||
itemsToDisassociate={selected}
|
modalNote={t`
|
||||||
modalTitle={t`Disassociate host from group?`}
|
|
||||||
modalNote={t`
|
|
||||||
Note that only hosts directly in this group can
|
Note that only hosts directly in this group can
|
||||||
be disassociated. Hosts in sub-groups must be disassociated
|
be disassociated. Hosts in sub-groups must be disassociated
|
||||||
directly from the sub-group level that they belong.
|
directly from the sub-group level that they belong.
|
||||||
`}
|
`}
|
||||||
/>,
|
/>,
|
||||||
]
|
|
||||||
: []),
|
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -265,8 +259,8 @@ function InventoryGroupHostList() {
|
|||||||
key={host.id}
|
key={host.id}
|
||||||
rowIndex={index}
|
rowIndex={index}
|
||||||
host={host}
|
host={host}
|
||||||
detailUrl={`/inventories/${inventoryType}/${inventoryId}/hosts/${host.id}/details`}
|
detailUrl={`/inventories/inventory/${inventoryId}/hosts/${host.id}/details`}
|
||||||
editUrl={`/inventories/${inventoryType}/${inventoryId}/hosts/${host.id}/edit`}
|
editUrl={`/inventories/inventory/${inventoryId}/hosts/${host.id}/edit`}
|
||||||
isSelected={selected.some((row) => row.id === host.id)}
|
isSelected={selected.some((row) => row.id === host.id)}
|
||||||
onSelect={() => handleSelect(host)}
|
onSelect={() => handleSelect(host)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -8,20 +8,19 @@ import {
|
|||||||
} from '../../../../testUtils/enzymeHelpers';
|
} from '../../../../testUtils/enzymeHelpers';
|
||||||
import InventoryGroupHostList from './InventoryGroupHostList';
|
import InventoryGroupHostList from './InventoryGroupHostList';
|
||||||
import mockHosts from '../shared/data.hosts.json';
|
import mockHosts from '../shared/data.hosts.json';
|
||||||
import { Route } from 'react-router-dom';
|
|
||||||
|
|
||||||
jest.mock('../../../api/models/Groups');
|
jest.mock('../../../api/models/Groups');
|
||||||
jest.mock('../../../api/models/Inventories');
|
jest.mock('../../../api/models/Inventories');
|
||||||
jest.mock('../../../api/models/CredentialTypes');
|
jest.mock('../../../api/models/CredentialTypes');
|
||||||
|
jest.mock('react-router-dom', () => ({
|
||||||
|
...jest.requireActual('react-router-dom'),
|
||||||
|
useParams: () => ({
|
||||||
|
id: 1,
|
||||||
|
groupId: 2,
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
describe('<InventoryGroupHostList />', () => {
|
describe('<InventoryGroupHostList />', () => {
|
||||||
jest.mock('react-router-dom', () => ({
|
|
||||||
...jest.requireActual('react-router-dom'),
|
|
||||||
useParams: () => ({
|
|
||||||
id: 1,
|
|
||||||
groupId: 2,
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@@ -304,64 +303,3 @@ describe('<InventoryGroupHostList />', () => {
|
|||||||
expect(wrapper.find('AdHocCommands')).toHaveLength(0);
|
expect(wrapper.find('AdHocCommands')).toHaveLength(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('<InventoryGroupHostList> for constructed inventories', () => {
|
|
||||||
jest.mock('react-router-dom', () => ({
|
|
||||||
...jest.requireActual('react-router-dom'),
|
|
||||||
useParams: () => ({
|
|
||||||
id: 1,
|
|
||||||
groupId: 2,
|
|
||||||
inventoryType: 'constructed_inventory',
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
let wrapper;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
GroupsAPI.readAllHosts.mockResolvedValue({
|
|
||||||
data: { ...mockHosts },
|
|
||||||
});
|
|
||||||
InventoriesAPI.readHostsOptions.mockResolvedValue({
|
|
||||||
data: {
|
|
||||||
actions: {
|
|
||||||
GET: {},
|
|
||||||
POST: {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
InventoriesAPI.readAdHocOptions.mockResolvedValue({
|
|
||||||
data: {
|
|
||||||
actions: {
|
|
||||||
GET: {
|
|
||||||
module_name: {
|
|
||||||
choices: [
|
|
||||||
['command', 'command'],
|
|
||||||
['shell', 'shell'],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
POST: {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const history = createMemoryHistory({
|
|
||||||
initialEntries: ['/inventories/constructed_inventory/1/groups/2/hosts'],
|
|
||||||
});
|
|
||||||
await act(async () => {
|
|
||||||
wrapper = mountWithContexts(
|
|
||||||
<Route path="/inventories/:inventoryType/:id/groups/:groupId/hosts">
|
|
||||||
<InventoryGroupHostList />
|
|
||||||
</Route>,
|
|
||||||
{ context: { router: { history } } }
|
|
||||||
);
|
|
||||||
});
|
|
||||||
await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
jest.clearAllMocks();
|
|
||||||
});
|
|
||||||
test('Should not show associate, or disassociate button', async () => {
|
|
||||||
expect(wrapper.find('AddDropDownButton').length).toBe(0);
|
|
||||||
expect(wrapper.find('DisassociateButton').length).toBe(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'styled-components/macro';
|
import 'styled-components/macro';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Link, useParams } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { string, bool, func, number } from 'prop-types';
|
import { string, bool, func, number } from 'prop-types';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { Button, Tooltip } from '@patternfly/react-core';
|
import { Button, Tooltip } from '@patternfly/react-core';
|
||||||
@@ -24,7 +24,7 @@ function InventoryGroupHostListItem({
|
|||||||
...job,
|
...job,
|
||||||
type: 'job',
|
type: 'job',
|
||||||
}));
|
}));
|
||||||
const { inventoryType } = useParams();
|
|
||||||
const labelId = `check-action-${host.id}`;
|
const labelId = `check-action-${host.id}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -57,24 +57,22 @@ function InventoryGroupHostListItem({
|
|||||||
>
|
>
|
||||||
<HostToggle host={host} />
|
<HostToggle host={host} />
|
||||||
</ActionItem>
|
</ActionItem>
|
||||||
{inventoryType !== 'constructed_inventory' && (
|
<ActionItem
|
||||||
<ActionItem
|
tooltip={t`Edit Host`}
|
||||||
tooltip={t`Edit Host`}
|
visible={host.summary_fields.user_capabilities?.edit}
|
||||||
visible={host.summary_fields.user_capabilities?.edit}
|
>
|
||||||
>
|
<Tooltip content={t`Edit Host`} position="top">
|
||||||
<Tooltip content={t`Edit Host`} position="top">
|
<Button
|
||||||
<Button
|
ouiaId={`${host.id}-edit-button`}
|
||||||
ouiaId={`${host.id}-edit-button`}
|
aria-label={t`Edit Host`}
|
||||||
aria-label={t`Edit Host`}
|
variant="plain"
|
||||||
variant="plain"
|
component={Link}
|
||||||
component={Link}
|
to={`${editUrl}`}
|
||||||
to={`${editUrl}`}
|
>
|
||||||
>
|
<PencilAltIcon />
|
||||||
<PencilAltIcon />
|
</Button>
|
||||||
</Button>
|
</Tooltip>
|
||||||
</Tooltip>
|
</ActionItem>
|
||||||
</ActionItem>
|
|
||||||
)}
|
|
||||||
</ActionsTd>
|
</ActionsTd>
|
||||||
</Tr>
|
</Tr>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,35 +1,28 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { createMemoryHistory } from 'history';
|
|
||||||
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
||||||
import InventoryGroupHostListItem from './InventoryGroupHostListItem';
|
import InventoryGroupHostListItem from './InventoryGroupHostListItem';
|
||||||
import mockHosts from '../shared/data.hosts.json';
|
import mockHosts from '../shared/data.hosts.json';
|
||||||
import { Route } from 'react-router-dom';
|
|
||||||
|
|
||||||
jest.mock('../../../api');
|
jest.mock('../../../api');
|
||||||
|
|
||||||
describe('<InventoryGroupHostListItem />', () => {
|
describe('<InventoryGroupHostListItem />', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
const mockHost = mockHosts.results[0];
|
const mockHost = mockHosts.results[0];
|
||||||
const history = createMemoryHistory({
|
|
||||||
initialEntries: ['/inventories/inventory/1/groups/2/hosts'],
|
|
||||||
});
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<Route path="/inventories/:inventoryType/:id/groups/:groupId/hosts">
|
<table>
|
||||||
<table>
|
<tbody>
|
||||||
<tbody>
|
<InventoryGroupHostListItem
|
||||||
<InventoryGroupHostListItem
|
detailUrl="/host/1"
|
||||||
detailUrl="/host/1"
|
editUrl="/host/1"
|
||||||
editUrl="/host/1"
|
host={mockHost}
|
||||||
host={mockHost}
|
isSelected={false}
|
||||||
isSelected={false}
|
onSelect={() => {}}
|
||||||
onSelect={() => {}}
|
rowIndex={0}
|
||||||
rowIndex={0}
|
/>
|
||||||
/>
|
</tbody>
|
||||||
</tbody>
|
</table>
|
||||||
</table>
|
|
||||||
</Route>,
|
|
||||||
{ context: { router: { history } } }
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -59,60 +52,19 @@ describe('<InventoryGroupHostListItem />', () => {
|
|||||||
const copyMockHost = { ...mockHost };
|
const copyMockHost = { ...mockHost };
|
||||||
copyMockHost.summary_fields.user_capabilities.edit = false;
|
copyMockHost.summary_fields.user_capabilities.edit = false;
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<Route path="/inventories/:inventoryType/:id/groups/:groupId/hosts">
|
<table>
|
||||||
<table>
|
<tbody>
|
||||||
<tbody>
|
<InventoryGroupHostListItem
|
||||||
<InventoryGroupHostListItem
|
detailUrl="/host/1"
|
||||||
detailUrl="/host/1"
|
editUrl="/host/1"
|
||||||
editUrl="/host/1"
|
host={mockHost}
|
||||||
host={mockHost}
|
isSelected={false}
|
||||||
isSelected={false}
|
onSelect={() => {}}
|
||||||
onSelect={() => {}}
|
rowIndex={0}
|
||||||
rowIndex={0}
|
/>
|
||||||
/>
|
</tbody>
|
||||||
</tbody>
|
</table>
|
||||||
</table>
|
|
||||||
</Route>,
|
|
||||||
{ context: { router: { history } } }
|
|
||||||
);
|
);
|
||||||
expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy();
|
expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('<InventoryGroupHostListItem> inside constructed inventories', () => {
|
|
||||||
jest.mock('react-router-dom', () => ({
|
|
||||||
...jest.requireActual('react-router-dom'),
|
|
||||||
useParams: () => ({
|
|
||||||
id: 1,
|
|
||||||
groupId: 2,
|
|
||||||
inventoryType: 'constructed_inventory',
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
let wrapper;
|
|
||||||
const mockHost = mockHosts.results[0];
|
|
||||||
const history = createMemoryHistory({
|
|
||||||
initialEntries: ['/inventories/constructed_inventory/1/groups/2/hosts'],
|
|
||||||
});
|
|
||||||
beforeEach(() => {
|
|
||||||
wrapper = mountWithContexts(
|
|
||||||
<Route path="/inventories/:inventoryType/:id/groups/:groupId/hosts">
|
|
||||||
<table>
|
|
||||||
<tbody>
|
|
||||||
<InventoryGroupHostListItem
|
|
||||||
detailUrl="/host/1"
|
|
||||||
editUrl="/host/1"
|
|
||||||
host={mockHost}
|
|
||||||
isSelected={false}
|
|
||||||
onSelect={() => {}}
|
|
||||||
rowIndex={0}
|
|
||||||
/>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</Route>,
|
|
||||||
{ context: { router: { history } } }
|
|
||||||
);
|
|
||||||
});
|
|
||||||
test('Edit button hidden for constructed inventory', () => {
|
|
||||||
expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ function InventoryGroupHosts({ inventoryGroup }) {
|
|||||||
<Route path="/inventories/inventory/:id/groups/:groupId/nested_hosts/add">
|
<Route path="/inventories/inventory/:id/groups/:groupId/nested_hosts/add">
|
||||||
<InventoryGroupHostAdd inventoryGroup={inventoryGroup} />
|
<InventoryGroupHostAdd inventoryGroup={inventoryGroup} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/inventories/:inventoryType/:id/groups/:groupId/nested_hosts">
|
<Route path="/inventories/inventory/:id/groups/:groupId/nested_hosts">
|
||||||
<InventoryGroupHostList />
|
<InventoryGroupHostList />
|
||||||
</Route>
|
</Route>
|
||||||
</Switch>
|
</Switch>
|
||||||
|
|||||||
@@ -1,20 +1,25 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { bool, func } from 'prop-types';
|
import { bool, func, number, oneOfType, string } from 'prop-types';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
|
|
||||||
import { Button } from '@patternfly/react-core';
|
import { Button } from '@patternfly/react-core';
|
||||||
import { Tr, Td } from '@patternfly/react-table';
|
import { Tr, Td } from '@patternfly/react-table';
|
||||||
|
|
||||||
import { Link, useParams } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { PencilAltIcon } from '@patternfly/react-icons';
|
import { PencilAltIcon } from '@patternfly/react-icons';
|
||||||
import { ActionsTd, ActionItem } from 'components/PaginatedTable';
|
import { ActionsTd, ActionItem } from 'components/PaginatedTable';
|
||||||
import { Group } from 'types';
|
import { Group } from 'types';
|
||||||
|
|
||||||
function InventoryGroupItem({ group, isSelected, onSelect, rowIndex }) {
|
function InventoryGroupItem({
|
||||||
const { id: inventoryId, inventoryType } = useParams();
|
group,
|
||||||
|
inventoryId,
|
||||||
|
isSelected,
|
||||||
|
onSelect,
|
||||||
|
rowIndex,
|
||||||
|
}) {
|
||||||
const labelId = `check-action-${group.id}`;
|
const labelId = `check-action-${group.id}`;
|
||||||
const detailUrl = `/inventories/${inventoryType}/${inventoryId}/groups/${group.id}/details`;
|
const detailUrl = `/inventories/inventory/${inventoryId}/groups/${group.id}/details`;
|
||||||
const editUrl = `/inventories/${inventoryType}/${inventoryId}/groups/${group.id}/edit`;
|
const editUrl = `/inventories/inventory/${inventoryId}/groups/${group.id}/edit`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tr id={`group-row-${group.id}`} ouiaId={`group-row-${group.id}`}>
|
<Tr id={`group-row-${group.id}`} ouiaId={`group-row-${group.id}`}>
|
||||||
@@ -31,30 +36,29 @@ function InventoryGroupItem({ group, isSelected, onSelect, rowIndex }) {
|
|||||||
<b>{group.name}</b>
|
<b>{group.name}</b>
|
||||||
</Link>
|
</Link>
|
||||||
</Td>
|
</Td>
|
||||||
{inventoryType !== 'constructed_inventory' && (
|
<ActionsTd dataLabel={t`Actions`} gridColumns="auto 40px">
|
||||||
<ActionsTd dataLabel={t`Actions`} gridColumns="auto 40px">
|
<ActionItem
|
||||||
<ActionItem
|
visible={group.summary_fields.user_capabilities.edit}
|
||||||
visible={group.summary_fields.user_capabilities.edit}
|
tooltip={t`Edit group`}
|
||||||
tooltip={t`Edit group`}
|
>
|
||||||
|
<Button
|
||||||
|
ouiaId={`${group.id}-edit-button`}
|
||||||
|
aria-label={t`Edit Group`}
|
||||||
|
variant="plain"
|
||||||
|
component={Link}
|
||||||
|
to={editUrl}
|
||||||
>
|
>
|
||||||
<Button
|
<PencilAltIcon />
|
||||||
ouiaId={`${group.id}-edit-button`}
|
</Button>
|
||||||
aria-label={t`Edit Group`}
|
</ActionItem>
|
||||||
variant="plain"
|
</ActionsTd>
|
||||||
component={Link}
|
|
||||||
to={editUrl}
|
|
||||||
>
|
|
||||||
<PencilAltIcon />
|
|
||||||
</Button>
|
|
||||||
</ActionItem>
|
|
||||||
</ActionsTd>
|
|
||||||
)}
|
|
||||||
</Tr>
|
</Tr>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
InventoryGroupItem.propTypes = {
|
InventoryGroupItem.propTypes = {
|
||||||
group: Group.isRequired,
|
group: Group.isRequired,
|
||||||
|
inventoryId: oneOfType([number, string]).isRequired,
|
||||||
isSelected: bool.isRequired,
|
isSelected: bool.isRequired,
|
||||||
onSelect: func.isRequired,
|
onSelect: func.isRequired,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Route } from 'react-router-dom';
|
|
||||||
import { act } from 'react-dom/test-utils';
|
|
||||||
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
||||||
import InventoryGroupItem from './InventoryGroupItem';
|
import InventoryGroupItem from './InventoryGroupItem';
|
||||||
|
|
||||||
@@ -59,39 +57,4 @@ describe('<InventoryGroupItem />', () => {
|
|||||||
);
|
);
|
||||||
expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy();
|
expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy();
|
||||||
});
|
});
|
||||||
test('edit button should be hidden from constructed inventory group', async () => {
|
|
||||||
jest.mock('react-router-dom', () => ({
|
|
||||||
...jest.requireActual('react-router-dom'),
|
|
||||||
useParams: () => ({ id: 42, inventoryType: 'constructed_inventory' }),
|
|
||||||
}));
|
|
||||||
const mockGroup = {
|
|
||||||
id: 2,
|
|
||||||
type: 'group',
|
|
||||||
name: 'foo',
|
|
||||||
inventory: 1,
|
|
||||||
summary_fields: {
|
|
||||||
user_capabilities: {
|
|
||||||
edit: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
await act(async () => {
|
|
||||||
wrapper = mountWithContexts(
|
|
||||||
<Route path="/inventories/:inventoryType/:id/groups">
|
|
||||||
<table>
|
|
||||||
<tbody>
|
|
||||||
<InventoryGroupItem
|
|
||||||
group={mockGroup}
|
|
||||||
inventoryId={1}
|
|
||||||
isSelected={false}
|
|
||||||
onSelect={() => {}}
|
|
||||||
/>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</Route>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,14 +16,11 @@ function InventoryGroups({ setBreadcrumb, inventory }) {
|
|||||||
inventory={inventory}
|
inventory={inventory}
|
||||||
/>
|
/>
|
||||||
</Route>
|
</Route>
|
||||||
<Route
|
<Route key="details" path="/inventories/inventory/:id/groups/:groupId/">
|
||||||
key="details"
|
|
||||||
path="/inventories/:inventoryType/:id/groups/:groupId/"
|
|
||||||
>
|
|
||||||
<InventoryGroup inventory={inventory} setBreadcrumb={setBreadcrumb} />
|
<InventoryGroup inventory={inventory} setBreadcrumb={setBreadcrumb} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route key="list" path="/inventories/:inventoryType/:id/groups">
|
<Route key="list" path="/inventories/inventory/:id/groups">
|
||||||
<InventoryGroupsList inventory={inventory} />
|
<InventoryGroupsList />
|
||||||
</Route>
|
</Route>
|
||||||
</Switch>
|
</Switch>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ function cannotDelete(item) {
|
|||||||
|
|
||||||
function InventoryGroupsList() {
|
function InventoryGroupsList() {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const { id: inventoryId, inventoryType } = useParams();
|
const { id: inventoryId } = useParams();
|
||||||
const [isAdHocLaunchLoading, setIsAdHocLaunchLoading] = useState(false);
|
const [isAdHocLaunchLoading, setIsAdHocLaunchLoading] = useState(false);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -102,11 +102,9 @@ function InventoryGroupsList() {
|
|||||||
}
|
}
|
||||||
return t`Select a row to delete`;
|
return t`Select a row to delete`;
|
||||||
};
|
};
|
||||||
const isNotConstructedInventory = inventoryType !== 'constructed_inventory';
|
|
||||||
const canAdd =
|
const canAdd =
|
||||||
actions &&
|
actions && Object.prototype.hasOwnProperty.call(actions, 'POST');
|
||||||
Object.prototype.hasOwnProperty.call(actions, 'POST') &&
|
|
||||||
isNotConstructedInventory;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PaginatedTable
|
<PaginatedTable
|
||||||
@@ -141,13 +139,14 @@ function InventoryGroupsList() {
|
|||||||
headerRow={
|
headerRow={
|
||||||
<HeaderRow qsConfig={QS_CONFIG}>
|
<HeaderRow qsConfig={QS_CONFIG}>
|
||||||
<HeaderCell sortKey="name">{t`Name`}</HeaderCell>
|
<HeaderCell sortKey="name">{t`Name`}</HeaderCell>
|
||||||
{isNotConstructedInventory && <HeaderCell>{t`Actions`}</HeaderCell>}
|
<HeaderCell>{t`Actions`}</HeaderCell>
|
||||||
</HeaderRow>
|
</HeaderRow>
|
||||||
}
|
}
|
||||||
renderRow={(item, index) => (
|
renderRow={(item, index) => (
|
||||||
<InventoryGroupItem
|
<InventoryGroupItem
|
||||||
key={item.id}
|
key={item.id}
|
||||||
group={item}
|
group={item}
|
||||||
|
inventoryId={inventoryId}
|
||||||
isSelected={selected.some((row) => row.id === item.id)}
|
isSelected={selected.some((row) => row.id === item.id)}
|
||||||
onSelect={() => handleSelect(item)}
|
onSelect={() => handleSelect(item)}
|
||||||
rowIndex={index}
|
rowIndex={index}
|
||||||
@@ -178,28 +177,20 @@ function InventoryGroupsList() {
|
|||||||
/>,
|
/>,
|
||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
...(isNotConstructedInventory
|
<Tooltip content={renderTooltip()} position="top" key="delete">
|
||||||
? [
|
<div>
|
||||||
<Tooltip
|
<InventoryGroupsDeleteModal
|
||||||
content={renderTooltip()}
|
groups={selected}
|
||||||
position="top"
|
isDisabled={
|
||||||
key="delete"
|
selected.length === 0 || selected.some(cannotDelete)
|
||||||
>
|
}
|
||||||
<div>
|
onAfterDelete={() => {
|
||||||
<InventoryGroupsDeleteModal
|
fetchData();
|
||||||
groups={selected}
|
clearSelected();
|
||||||
isDisabled={
|
}}
|
||||||
selected.length === 0 || selected.some(cannotDelete)
|
/>
|
||||||
}
|
</div>
|
||||||
onAfterDelete={() => {
|
</Tooltip>,
|
||||||
fetchData();
|
|
||||||
clearSelected();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</Tooltip>,
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -10,6 +10,12 @@ import {
|
|||||||
import InventoryGroupsList from './InventoryGroupsList';
|
import InventoryGroupsList from './InventoryGroupsList';
|
||||||
|
|
||||||
jest.mock('../../../api');
|
jest.mock('../../../api');
|
||||||
|
jest.mock('react-router-dom', () => ({
|
||||||
|
...jest.requireActual('react-router-dom'),
|
||||||
|
useParams: () => ({
|
||||||
|
id: 1,
|
||||||
|
}),
|
||||||
|
}));
|
||||||
const mockGroups = [
|
const mockGroups = [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
@@ -54,14 +60,7 @@ const mockGroups = [
|
|||||||
|
|
||||||
describe('<InventoryGroupsList />', () => {
|
describe('<InventoryGroupsList />', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
jest.mock('react-router-dom', () => ({
|
|
||||||
...jest.requireActual('react-router-dom'),
|
|
||||||
useParams: () => ({
|
|
||||||
id: 1,
|
|
||||||
groupId: 2,
|
|
||||||
inventoryType: 'inventory',
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
InventoriesAPI.readGroups.mockResolvedValue({
|
InventoriesAPI.readGroups.mockResolvedValue({
|
||||||
data: {
|
data: {
|
||||||
@@ -97,7 +96,7 @@ describe('<InventoryGroupsList />', () => {
|
|||||||
});
|
});
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<Route path="/inventories/:inventoryType/:id/groups">
|
<Route path="/inventories/inventory/:id/groups">
|
||||||
<InventoryGroupsList />
|
<InventoryGroupsList />
|
||||||
</Route>,
|
</Route>,
|
||||||
{
|
{
|
||||||
@@ -317,77 +316,3 @@ describe('<InventoryGroupsList/> error handling', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Constructed Inventory group', () => {
|
|
||||||
let wrapper;
|
|
||||||
jest.mock('react-router-dom', () => ({
|
|
||||||
...jest.requireActual('react-router-dom'),
|
|
||||||
useParams: () => ({
|
|
||||||
id: 1,
|
|
||||||
groupId: 2,
|
|
||||||
inventoryType: 'constructed_inventory',
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
InventoriesAPI.readGroups.mockResolvedValue({
|
|
||||||
data: {
|
|
||||||
count: mockGroups.length,
|
|
||||||
results: mockGroups,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
InventoriesAPI.readGroupsOptions.mockResolvedValue({
|
|
||||||
data: {
|
|
||||||
actions: {
|
|
||||||
GET: {},
|
|
||||||
POST: {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
InventoriesAPI.readAdHocOptions.mockResolvedValue({
|
|
||||||
data: {
|
|
||||||
actions: {
|
|
||||||
GET: {
|
|
||||||
module_name: {
|
|
||||||
choices: [
|
|
||||||
['command', 'command'],
|
|
||||||
['shell', 'shell'],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
POST: {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const history = createMemoryHistory({
|
|
||||||
initialEntries: ['/inventories/constructed_inventory/3/groups'],
|
|
||||||
});
|
|
||||||
await act(async () => {
|
|
||||||
wrapper = mountWithContexts(
|
|
||||||
<Route path="/inventories/:inventoryType/:id/groups">
|
|
||||||
<InventoryGroupsList />
|
|
||||||
</Route>,
|
|
||||||
{
|
|
||||||
context: {
|
|
||||||
router: {
|
|
||||||
history,
|
|
||||||
route: {
|
|
||||||
location: history.location,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
jest.clearAllMocks();
|
|
||||||
});
|
|
||||||
test('should not show add button', () => {
|
|
||||||
expect(wrapper.find('ToolbarAddButton').length).toBe(0);
|
|
||||||
expect(wrapper.find('ToolbarDeleteButton').length).toBe(0);
|
|
||||||
expect(wrapper.find('AdHocCommands').length).toBe(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -135,7 +135,6 @@ function InventoryList() {
|
|||||||
|
|
||||||
const addInventory = t`Add inventory`;
|
const addInventory = t`Add inventory`;
|
||||||
const addSmartInventory = t`Add smart inventory`;
|
const addSmartInventory = t`Add smart inventory`;
|
||||||
const addConstructedInventory = t`Add constructed inventory`;
|
|
||||||
const addButton = (
|
const addButton = (
|
||||||
<AddDropDownButton
|
<AddDropDownButton
|
||||||
ouiaId="add-inventory-button"
|
ouiaId="add-inventory-button"
|
||||||
@@ -159,15 +158,6 @@ function InventoryList() {
|
|||||||
>
|
>
|
||||||
{addSmartInventory}
|
{addSmartInventory}
|
||||||
</DropdownItem>,
|
</DropdownItem>,
|
||||||
<DropdownItem
|
|
||||||
ouiaId="add-constructed-inventory-item"
|
|
||||||
to={`${match.url}/constructed_inventory/add/`}
|
|
||||||
component={Link}
|
|
||||||
key={addConstructedInventory}
|
|
||||||
aria-label={addConstructedInventory}
|
|
||||||
>
|
|
||||||
{addConstructedInventory}
|
|
||||||
</DropdownItem>,
|
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -195,7 +185,6 @@ function InventoryList() {
|
|||||||
options: [
|
options: [
|
||||||
['', t`Inventory`],
|
['', t`Inventory`],
|
||||||
['smart', t`Smart Inventory`],
|
['smart', t`Smart Inventory`],
|
||||||
['constructed', t`Constructed Inventory`],
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -272,6 +261,11 @@ function InventoryList() {
|
|||||||
inventory={inventory}
|
inventory={inventory}
|
||||||
rowIndex={index}
|
rowIndex={index}
|
||||||
fetchInventories={fetchInventories}
|
fetchInventories={fetchInventories}
|
||||||
|
detailUrl={
|
||||||
|
inventory.kind === 'smart'
|
||||||
|
? `${match.url}/smart_inventory/${inventory.id}/details`
|
||||||
|
: `${match.url}/inventory/${inventory.id}/details`
|
||||||
|
}
|
||||||
onSelect={() => {
|
onSelect={() => {
|
||||||
if (!inventory.pending_deletion) {
|
if (!inventory.pending_deletion) {
|
||||||
handleSelect(inventory);
|
handleSelect(inventory);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useState, useCallback } from 'react';
|
import React, { useState, useCallback } from 'react';
|
||||||
import { bool, func } from 'prop-types';
|
import { string, bool, func } from 'prop-types';
|
||||||
|
|
||||||
import { Button, Label } from '@patternfly/react-core';
|
import { Button, Label } from '@patternfly/react-core';
|
||||||
import { Tr, Td } from '@patternfly/react-table';
|
import { Tr, Td } from '@patternfly/react-table';
|
||||||
@@ -12,7 +12,6 @@ import { Inventory } from 'types';
|
|||||||
import { ActionsTd, ActionItem, TdBreakWord } from 'components/PaginatedTable';
|
import { ActionsTd, ActionItem, TdBreakWord } from 'components/PaginatedTable';
|
||||||
import CopyButton from 'components/CopyButton';
|
import CopyButton from 'components/CopyButton';
|
||||||
import StatusLabel from 'components/StatusLabel';
|
import StatusLabel from 'components/StatusLabel';
|
||||||
import { getInventoryPath } from '../shared/utils';
|
|
||||||
|
|
||||||
function InventoryListItem({
|
function InventoryListItem({
|
||||||
inventory,
|
inventory,
|
||||||
@@ -20,10 +19,12 @@ function InventoryListItem({
|
|||||||
isSelected,
|
isSelected,
|
||||||
onSelect,
|
onSelect,
|
||||||
onCopy,
|
onCopy,
|
||||||
|
detailUrl,
|
||||||
fetchInventories,
|
fetchInventories,
|
||||||
}) {
|
}) {
|
||||||
InventoryListItem.propTypes = {
|
InventoryListItem.propTypes = {
|
||||||
inventory: Inventory.isRequired,
|
inventory: Inventory.isRequired,
|
||||||
|
detailUrl: string.isRequired,
|
||||||
isSelected: bool.isRequired,
|
isSelected: bool.isRequired,
|
||||||
onSelect: func.isRequired,
|
onSelect: func.isRequired,
|
||||||
};
|
};
|
||||||
@@ -49,12 +50,6 @@ function InventoryListItem({
|
|||||||
|
|
||||||
const labelId = `check-action-${inventory.id}`;
|
const labelId = `check-action-${inventory.id}`;
|
||||||
|
|
||||||
const typeLabel = {
|
|
||||||
'': t`Inventory`,
|
|
||||||
smart: t`Smart Inventory`,
|
|
||||||
constructed: t`Constructed Inventory`,
|
|
||||||
};
|
|
||||||
|
|
||||||
let syncStatus = 'disabled';
|
let syncStatus = 'disabled';
|
||||||
if (inventory.isSourceSyncRunning) {
|
if (inventory.isSourceSyncRunning) {
|
||||||
syncStatus = 'syncing';
|
syncStatus = 'syncing';
|
||||||
@@ -98,20 +93,16 @@ function InventoryListItem({
|
|||||||
{inventory.pending_deletion ? (
|
{inventory.pending_deletion ? (
|
||||||
<b>{inventory.name}</b>
|
<b>{inventory.name}</b>
|
||||||
) : (
|
) : (
|
||||||
<Link to={`${getInventoryPath(inventory)}/details`}>
|
<Link to={`${detailUrl}`}>
|
||||||
<b>{inventory.name}</b>
|
<b>{inventory.name}</b>
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
</TdBreakWord>
|
</TdBreakWord>
|
||||||
<Td dataLabel={t`Status`}>
|
<Td dataLabel={t`Status`}>
|
||||||
{inventory.kind === '' &&
|
{inventory.kind !== 'smart' &&
|
||||||
(inventory.has_inventory_sources ? (
|
(inventory.has_inventory_sources ? (
|
||||||
<Link
|
<Link
|
||||||
to={`${getInventoryPath(
|
to={`/inventories/inventory/${inventory.id}/jobs?job.or__inventoryupdate__inventory_source__inventory__id=${inventory.id}`}
|
||||||
inventory
|
|
||||||
)}/jobs?job.or__inventoryupdate__inventory_source__inventory__id=${
|
|
||||||
inventory.id
|
|
||||||
}`}
|
|
||||||
>
|
>
|
||||||
<StatusLabel
|
<StatusLabel
|
||||||
status={syncStatus}
|
status={syncStatus}
|
||||||
@@ -122,7 +113,9 @@ function InventoryListItem({
|
|||||||
<StatusLabel status={syncStatus} tooltipContent={tooltipContent} />
|
<StatusLabel status={syncStatus} tooltipContent={tooltipContent} />
|
||||||
))}
|
))}
|
||||||
</Td>
|
</Td>
|
||||||
<Td dataLabel={t`Type`}>{typeLabel[inventory.kind]}</Td>
|
<Td dataLabel={t`Type`}>
|
||||||
|
{inventory.kind === 'smart' ? t`Smart Inventory` : t`Inventory`}
|
||||||
|
</Td>
|
||||||
<TdBreakWord key="organization" dataLabel={t`Organization`}>
|
<TdBreakWord key="organization" dataLabel={t`Organization`}>
|
||||||
<Link
|
<Link
|
||||||
to={`/organizations/${inventory?.summary_fields?.organization?.id}/details`}
|
to={`/organizations/${inventory?.summary_fields?.organization?.id}/details`}
|
||||||
@@ -146,7 +139,9 @@ function InventoryListItem({
|
|||||||
aria-label={t`Edit Inventory`}
|
aria-label={t`Edit Inventory`}
|
||||||
variant="plain"
|
variant="plain"
|
||||||
component={Link}
|
component={Link}
|
||||||
to={`${getInventoryPath(inventory)}edit`}
|
to={`/inventories/${
|
||||||
|
inventory.kind === 'smart' ? 'smart_inventory' : 'inventory'
|
||||||
|
}/${inventory.id}/edit`}
|
||||||
>
|
>
|
||||||
<PencilAltIcon />
|
<PencilAltIcon />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ function InventoryRelatedGroupList() {
|
|||||||
const [isAdHocLaunchLoading, setIsAdHocLaunchLoading] = useState(false);
|
const [isAdHocLaunchLoading, setIsAdHocLaunchLoading] = useState(false);
|
||||||
const [associateError, setAssociateError] = useState(null);
|
const [associateError, setAssociateError] = useState(null);
|
||||||
const [disassociateError, setDisassociateError] = useState(null);
|
const [disassociateError, setDisassociateError] = useState(null);
|
||||||
const { id: inventoryId, groupId, inventoryType } = useParams();
|
const { id: inventoryId, groupId } = useParams();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -69,10 +69,9 @@ function InventoryRelatedGroupList() {
|
|||||||
searchableKeys: getSearchableKeys(actions.data.actions?.GET),
|
searchableKeys: getSearchableKeys(actions.data.actions?.GET),
|
||||||
canAdd:
|
canAdd:
|
||||||
actions.data.actions &&
|
actions.data.actions &&
|
||||||
Object.prototype.hasOwnProperty.call(actions.data.actions, 'POST') &&
|
Object.prototype.hasOwnProperty.call(actions.data.actions, 'POST'),
|
||||||
inventoryType !== 'constructed_inventory',
|
|
||||||
};
|
};
|
||||||
}, [groupId, location.search, inventoryType, inventoryId]),
|
}, [groupId, location.search, inventoryId]),
|
||||||
{
|
{
|
||||||
groups: [],
|
groups: [],
|
||||||
itemCount: 0,
|
itemCount: 0,
|
||||||
@@ -165,7 +164,7 @@ function InventoryRelatedGroupList() {
|
|||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
const isNotConstructedInventory = inventoryType !== 'constructed_inventory';
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PaginatedTable
|
<PaginatedTable
|
||||||
@@ -219,23 +218,19 @@ function InventoryRelatedGroupList() {
|
|||||||
/>,
|
/>,
|
||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
...(isNotConstructedInventory
|
<DisassociateButton
|
||||||
? [
|
key="disassociate"
|
||||||
<DisassociateButton
|
onDisassociate={disassociateGroups}
|
||||||
key="disassociate"
|
itemsToDisassociate={selected}
|
||||||
onDisassociate={disassociateGroups}
|
modalTitle={t`Disassociate related group(s)?`}
|
||||||
itemsToDisassociate={selected}
|
/>,
|
||||||
modalTitle={t`Disassociate related group(s)?`}
|
|
||||||
/>,
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
headerRow={
|
headerRow={
|
||||||
<HeaderRow qsConfig={QS_CONFIG}>
|
<HeaderRow qsConfig={QS_CONFIG}>
|
||||||
<HeaderCell sortKey="name">{t`Name`}</HeaderCell>
|
<HeaderCell sortKey="name">{t`Name`}</HeaderCell>
|
||||||
{isNotConstructedInventory && <HeaderCell>{t`Actions`}</HeaderCell>}
|
<HeaderCell>{t`Actions`}</HeaderCell>
|
||||||
</HeaderRow>
|
</HeaderRow>
|
||||||
}
|
}
|
||||||
renderRow={(group, index) => (
|
renderRow={(group, index) => (
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { act } from 'react-dom/test-utils';
|
import { act } from 'react-dom/test-utils';
|
||||||
import { createMemoryHistory } from 'history';
|
|
||||||
import { Route } from 'react-router-dom';
|
|
||||||
import { GroupsAPI, InventoriesAPI } from 'api';
|
import { GroupsAPI, InventoriesAPI } from 'api';
|
||||||
import {
|
import {
|
||||||
mountWithContexts,
|
mountWithContexts,
|
||||||
@@ -14,6 +13,14 @@ jest.mock('../../../api/models/Groups');
|
|||||||
jest.mock('../../../api/models/Inventories');
|
jest.mock('../../../api/models/Inventories');
|
||||||
jest.mock('../../../api/models/CredentialTypes');
|
jest.mock('../../../api/models/CredentialTypes');
|
||||||
|
|
||||||
|
jest.mock('react-router-dom', () => ({
|
||||||
|
...jest.requireActual('react-router-dom'),
|
||||||
|
useParams: () => ({
|
||||||
|
id: 1,
|
||||||
|
groupId: 2,
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
const mockGroups = [
|
const mockGroups = [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
@@ -58,14 +65,6 @@ const mockGroups = [
|
|||||||
|
|
||||||
describe('<InventoryRelatedGroupList />', () => {
|
describe('<InventoryRelatedGroupList />', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
jest.mock('react-router-dom', () => ({
|
|
||||||
...jest.requireActual('react-router-dom'),
|
|
||||||
useParams: () => ({
|
|
||||||
id: 2,
|
|
||||||
groupId: 2,
|
|
||||||
inventoryType: 'inventory',
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
GroupsAPI.readChildren.mockResolvedValue({
|
GroupsAPI.readChildren.mockResolvedValue({
|
||||||
@@ -211,22 +210,11 @@ describe('<InventoryRelatedGroupList />', () => {
|
|||||||
GroupsAPI.readPotentialGroups.mockResolvedValue({
|
GroupsAPI.readPotentialGroups.mockResolvedValue({
|
||||||
data: { count: mockGroups.length, results: mockGroups },
|
data: { count: mockGroups.length, results: mockGroups },
|
||||||
});
|
});
|
||||||
const history = createMemoryHistory({
|
|
||||||
initialEntries: ['/inventories/inventory/2/groups/2/nested_groups'],
|
|
||||||
});
|
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(<InventoryRelatedGroupList />);
|
||||||
<Route path="/inventories/:inventoryType/:id/groups/:groupId/nested_groups">
|
|
||||||
<InventoryRelatedGroupList />
|
|
||||||
</Route>,
|
|
||||||
{ context: { router: { history } } }
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
await waitForElement(
|
await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0);
|
||||||
wrapper,
|
|
||||||
'InventoryRelatedGroupList',
|
|
||||||
(el) => el.length > 0
|
|
||||||
);
|
|
||||||
act(() => wrapper.find('Button[aria-label="Add"]').prop('onClick')());
|
act(() => wrapper.find('Button[aria-label="Add"]').prop('onClick')());
|
||||||
wrapper.update();
|
wrapper.update();
|
||||||
await act(async () =>
|
await act(async () =>
|
||||||
@@ -234,9 +222,9 @@ describe('<InventoryRelatedGroupList />', () => {
|
|||||||
.find('DropdownItem[aria-label="Add existing group"]')
|
.find('DropdownItem[aria-label="Add existing group"]')
|
||||||
.prop('onClick')()
|
.prop('onClick')()
|
||||||
);
|
);
|
||||||
expect(GroupsAPI.readPotentialGroups).toBeCalledWith('2', {
|
expect(GroupsAPI.readPotentialGroups).toBeCalledWith(2, {
|
||||||
not__id: '2',
|
not__id: 2,
|
||||||
not__parents: '2',
|
not__parents: 2,
|
||||||
order_by: 'name',
|
order_by: 'name',
|
||||||
page: 1,
|
page: 1,
|
||||||
page_size: 5,
|
page_size: 5,
|
||||||
@@ -273,85 +261,3 @@ describe('<InventoryRelatedGroupList />', () => {
|
|||||||
expect(wrapper.find('AdHocCommands')).toHaveLength(0);
|
expect(wrapper.find('AdHocCommands')).toHaveLength(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('<InventoryRelatedGroupList> for constructed inventories', () => {
|
|
||||||
jest.mock('react-router-dom', () => ({
|
|
||||||
...jest.requireActual('react-router-dom'),
|
|
||||||
useParams: () => ({
|
|
||||||
id: 1,
|
|
||||||
groupId: 2,
|
|
||||||
inventoryType: 'constructed_inventory',
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
let wrapper;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
GroupsAPI.readChildren.mockResolvedValue({
|
|
||||||
data: { ...mockRelatedGroups },
|
|
||||||
});
|
|
||||||
InventoriesAPI.readGroupsOptions.mockResolvedValue({
|
|
||||||
data: {
|
|
||||||
actions: {
|
|
||||||
GET: {},
|
|
||||||
POST: {},
|
|
||||||
},
|
|
||||||
related_search_fields: [
|
|
||||||
'parents__search',
|
|
||||||
'inventory__search',
|
|
||||||
'inventory_sources__search',
|
|
||||||
'created_by__search',
|
|
||||||
'children__search',
|
|
||||||
'modified_by__search',
|
|
||||||
'hosts__search',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
InventoriesAPI.readAdHocOptions.mockResolvedValue({
|
|
||||||
data: {
|
|
||||||
actions: {
|
|
||||||
GET: {
|
|
||||||
module_name: {
|
|
||||||
choices: [
|
|
||||||
['command', 'command'],
|
|
||||||
['shell', 'shell'],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
POST: {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const history = createMemoryHistory({
|
|
||||||
initialEntries: [
|
|
||||||
'/inventories/constructed_inventory/1/groups/2/nested_groupss',
|
|
||||||
],
|
|
||||||
});
|
|
||||||
await act(async () => {
|
|
||||||
wrapper = mountWithContexts(
|
|
||||||
<Route path="/inventories/:inventoryType/:id/groups/:groupId/nested_groups">
|
|
||||||
<InventoryRelatedGroupList />
|
|
||||||
</Route>,
|
|
||||||
{ context: { router: { history } } }
|
|
||||||
);
|
|
||||||
});
|
|
||||||
await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
jest.clearAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Should not show associate, or disassociate button', async () => {
|
|
||||||
InventoriesAPI.readHostsOptions.mockResolvedValueOnce({
|
|
||||||
data: {
|
|
||||||
actions: {
|
|
||||||
GET: {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0);
|
|
||||||
expect(wrapper.find('AddDropDownButton').length).toBe(0);
|
|
||||||
expect(wrapper.find('DisassociateButton').length).toBe(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'styled-components/macro';
|
import 'styled-components/macro';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Link, useParams } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { string, bool, func, number } from 'prop-types';
|
import { string, bool, func, number } from 'prop-types';
|
||||||
|
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
@@ -21,7 +21,7 @@ function InventoryRelatedGroupListItem({
|
|||||||
onSelect,
|
onSelect,
|
||||||
}) {
|
}) {
|
||||||
const labelId = `check-action-${group.id}`;
|
const labelId = `check-action-${group.id}`;
|
||||||
const { inventoryType } = useParams();
|
|
||||||
return (
|
return (
|
||||||
<Tr
|
<Tr
|
||||||
id={group.id}
|
id={group.id}
|
||||||
@@ -41,24 +41,22 @@ function InventoryRelatedGroupListItem({
|
|||||||
<b>{group.name}</b>
|
<b>{group.name}</b>
|
||||||
</Link>
|
</Link>
|
||||||
</Td>
|
</Td>
|
||||||
{inventoryType !== 'constructed_inventory' && (
|
<ActionsTd dataLabel={t`Actions`}>
|
||||||
<ActionsTd dataLabel={t`Actions`}>
|
<ActionItem
|
||||||
<ActionItem
|
tooltip={t`Edit Group`}
|
||||||
tooltip={t`Edit Group`}
|
visible={group.summary_fields.user_capabilities?.edit}
|
||||||
visible={group.summary_fields.user_capabilities?.edit}
|
>
|
||||||
|
<Button
|
||||||
|
ouiaId={`${group.id}-edit-button`}
|
||||||
|
aria-label={t`Edit Group`}
|
||||||
|
variant="plain"
|
||||||
|
component={Link}
|
||||||
|
to={`${editUrl}`}
|
||||||
>
|
>
|
||||||
<Button
|
<PencilAltIcon />
|
||||||
ouiaId={`${group.id}-edit-button`}
|
</Button>
|
||||||
aria-label={t`Edit Group`}
|
</ActionItem>
|
||||||
variant="plain"
|
</ActionsTd>
|
||||||
component={Link}
|
|
||||||
to={`${editUrl}`}
|
|
||||||
>
|
|
||||||
<PencilAltIcon />
|
|
||||||
</Button>
|
|
||||||
</ActionItem>
|
|
||||||
</ActionsTd>
|
|
||||||
)}
|
|
||||||
</Tr>
|
</Tr>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,43 +1,28 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { createMemoryHistory } from 'history';
|
|
||||||
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
||||||
import InventoryRelatedGroupListItem from './InventoryRelatedGroupListItem';
|
import InventoryRelatedGroupListItem from './InventoryRelatedGroupListItem';
|
||||||
import mockRelatedGroups from '../shared/data.relatedGroups.json';
|
import mockRelatedGroups from '../shared/data.relatedGroups.json';
|
||||||
import { Route } from 'react-router-dom';
|
|
||||||
|
|
||||||
jest.mock('../../../api');
|
jest.mock('../../../api');
|
||||||
|
|
||||||
const mockGroup = mockRelatedGroups.results[0];
|
|
||||||
describe('<InventoryRelatedGroupListItem />', () => {
|
describe('<InventoryRelatedGroupListItem />', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
const history = createMemoryHistory({
|
const mockGroup = mockRelatedGroups.results[0];
|
||||||
initialEntries: ['/inventories/inventory/1/groups/2/nested_groups'],
|
|
||||||
});
|
|
||||||
jest.mock('react-router-dom', () => ({
|
|
||||||
...jest.requireActual('react-router-dom'),
|
|
||||||
useParams: () => ({
|
|
||||||
id: 1,
|
|
||||||
groupId: 2,
|
|
||||||
inventoryType: 'inventory',
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<Route path="/inventories/:inventoryType/:id/groups/:groupId/nested_groups">
|
<table>
|
||||||
<table>
|
<tbody>
|
||||||
<tbody>
|
<InventoryRelatedGroupListItem
|
||||||
<InventoryRelatedGroupListItem
|
detailUrl="/group/1"
|
||||||
detailUrl="/group/1"
|
editUrl="/group/1"
|
||||||
editUrl="/group/1"
|
group={mockGroup}
|
||||||
group={mockGroup}
|
isSelected={false}
|
||||||
isSelected={false}
|
onSelect={() => {}}
|
||||||
onSelect={() => {}}
|
rowIndex={0}
|
||||||
rowIndex={0}
|
/>
|
||||||
/>
|
</tbody>
|
||||||
</tbody>
|
</table>
|
||||||
</table>
|
|
||||||
</Route>,
|
|
||||||
{ context: { router: { history } } }
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -51,60 +36,18 @@ describe('<InventoryRelatedGroupListItem />', () => {
|
|||||||
|
|
||||||
test('edit button hidden from users without edit capabilities', () => {
|
test('edit button hidden from users without edit capabilities', () => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<Route path="/inventories/:inventoryType/:id/groups/:groupId/nested_groups">
|
<table>
|
||||||
<table>
|
<tbody>
|
||||||
<tbody>
|
<InventoryRelatedGroupListItem
|
||||||
<InventoryRelatedGroupListItem
|
detailUrl="/group/1"
|
||||||
detailUrl="/group/1"
|
editUrl="/group/1"
|
||||||
editUrl="/group/1"
|
group={mockRelatedGroups.results[2]}
|
||||||
group={mockRelatedGroups.results[2]}
|
isSelected={false}
|
||||||
isSelected={false}
|
onSelect={() => {}}
|
||||||
onSelect={() => {}}
|
rowIndex={0}
|
||||||
rowIndex={0}
|
/>
|
||||||
/>
|
</tbody>
|
||||||
</tbody>
|
</table>
|
||||||
</table>
|
|
||||||
</Route>,
|
|
||||||
{ context: { router: { history } } }
|
|
||||||
);
|
|
||||||
expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('<InventoryRelatedGroupList> for constructed inventories', () => {
|
|
||||||
jest.mock('react-router-dom', () => ({
|
|
||||||
...jest.requireActual('react-router-dom'),
|
|
||||||
useParams: () => ({
|
|
||||||
id: 1,
|
|
||||||
groupId: 2,
|
|
||||||
inventoryType: 'constructed_inventory',
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
let wrapper;
|
|
||||||
|
|
||||||
test('edit button hidden from users without edit capabilities', () => {
|
|
||||||
const history = createMemoryHistory({
|
|
||||||
initialEntries: [
|
|
||||||
'/inventories/constructed_inventory/1/groups/2/nested_groups',
|
|
||||||
],
|
|
||||||
});
|
|
||||||
wrapper = mountWithContexts(
|
|
||||||
<Route path="/inventories/:inventoryType/:id/groups/:groupId/nested_groups">
|
|
||||||
<table>
|
|
||||||
<tbody>
|
|
||||||
<InventoryRelatedGroupListItem
|
|
||||||
detailUrl="/group/1"
|
|
||||||
editUrl="/group/1"
|
|
||||||
group={mockGroup}
|
|
||||||
isSelected={false}
|
|
||||||
onSelect={() => {}}
|
|
||||||
rowIndex={0}
|
|
||||||
/>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</Route>,
|
|
||||||
{ context: { router: { history } } }
|
|
||||||
);
|
);
|
||||||
expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy();
|
expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ function InventoryRelatedGroups() {
|
|||||||
<Switch>
|
<Switch>
|
||||||
<Route
|
<Route
|
||||||
key="addRelatedGroups"
|
key="addRelatedGroups"
|
||||||
path="/inventories/:inventoryType/:id/groups/:groupId/nested_groups/add"
|
path="/inventories/inventory/:id/groups/:groupId/nested_groups/add"
|
||||||
>
|
>
|
||||||
<InventoryRelatedGroupAdd />
|
<InventoryRelatedGroupAdd />
|
||||||
</Route>
|
</Route>
|
||||||
<Route
|
<Route
|
||||||
key="relatedGroups"
|
key="relatedGroups"
|
||||||
path="/inventories/:inventoryType/:id/groups/:groupId/nested_groups"
|
path="/inventories/inventory/:id/groups/:groupId/nested_groups"
|
||||||
>
|
>
|
||||||
<InventoryRelatedGroupList />
|
<InventoryRelatedGroupList />
|
||||||
</Route>
|
</Route>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import { formatDateString } from 'util/dates';
|
|||||||
import Popover from 'components/Popover';
|
import Popover from 'components/Popover';
|
||||||
import { VERBOSITY } from 'components/VerbositySelectField';
|
import { VERBOSITY } from 'components/VerbositySelectField';
|
||||||
import InventorySourceSyncButton from '../shared/InventorySourceSyncButton';
|
import InventorySourceSyncButton from '../shared/InventorySourceSyncButton';
|
||||||
import useWsInventorySourcesDetails from '../shared/useWsInventorySourcesDetails';
|
import useWsInventorySourcesDetails from '../InventorySources/useWsInventorySourcesDetails';
|
||||||
import getHelpText from '../shared/Inventory.helptext';
|
import getHelpText from '../shared/Inventory.helptext';
|
||||||
|
|
||||||
function InventorySourceDetail({ inventorySource }) {
|
function InventorySourceDetail({ inventorySource }) {
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { useState, useEffect } from 'react';
|
||||||
|
import useWebsocket from 'hooks/useWebsocket';
|
||||||
|
|
||||||
|
export default function useWsInventorySourcesDetails(initialSources) {
|
||||||
|
const [sources, setSources] = useState(initialSources);
|
||||||
|
const lastMessage = useWebsocket({
|
||||||
|
jobs: ['status_changed'],
|
||||||
|
control: ['limit_reached_1'],
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setSources(initialSources);
|
||||||
|
}, [initialSources]);
|
||||||
|
|
||||||
|
useEffect(
|
||||||
|
() => {
|
||||||
|
if (
|
||||||
|
!lastMessage?.unified_job_id ||
|
||||||
|
!lastMessage?.inventory_source_id ||
|
||||||
|
lastMessage.type !== 'inventory_update'
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const updateSource = {
|
||||||
|
...sources,
|
||||||
|
summary_fields: {
|
||||||
|
...sources.summary_fields,
|
||||||
|
current_job: {
|
||||||
|
id: lastMessage.unified_job_id,
|
||||||
|
status: lastMessage.status,
|
||||||
|
finished: lastMessage.finished,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
setSources(updateSource);
|
||||||
|
},
|
||||||
|
[lastMessage] // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
);
|
||||||
|
|
||||||
|
return sources;
|
||||||
|
}
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { act } from 'react-dom/test-utils';
|
import { act } from 'react-dom/test-utils';
|
||||||
import WS from 'jest-websocket-mock';
|
import WS from 'jest-websocket-mock';
|
||||||
import { InventorySourcesAPI } from 'api';
|
|
||||||
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
||||||
import useWsInventorySourceDetails from './useWsInventorySourcesDetails';
|
import useWsInventorySourceDetails from './useWsInventorySourcesDetails';
|
||||||
|
|
||||||
jest.mock('../../../api/models/InventorySources');
|
|
||||||
|
|
||||||
function TestInner() {
|
function TestInner() {
|
||||||
return <div />;
|
return <div />;
|
||||||
}
|
}
|
||||||
@@ -114,27 +111,6 @@ describe('useWsProject', () => {
|
|||||||
status: 'running',
|
status: 'running',
|
||||||
finished: null,
|
finished: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(InventorySourcesAPI.readDetail).toHaveBeenCalledTimes(0);
|
|
||||||
InventorySourcesAPI.readDetail.mockResolvedValue({
|
|
||||||
data: {},
|
|
||||||
});
|
|
||||||
await act(async () => {
|
|
||||||
mockServer.send(
|
|
||||||
JSON.stringify({
|
|
||||||
group_name: 'jobs',
|
|
||||||
inventory_id: 1,
|
|
||||||
status: 'successful',
|
|
||||||
type: 'inventory_update',
|
|
||||||
unified_job_id: 2,
|
|
||||||
unified_job_template_id: 1,
|
|
||||||
inventory_source_id: 1,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
expect(InventorySourcesAPI.readDetail).toHaveBeenCalledTimes(1);
|
|
||||||
|
|
||||||
jest.clearAllMocks();
|
|
||||||
WS.clean();
|
WS.clean();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -22,8 +22,7 @@ import RoutedTabs from 'components/RoutedTabs';
|
|||||||
import RelatedTemplateList from 'components/RelatedTemplateList';
|
import RelatedTemplateList from 'components/RelatedTemplateList';
|
||||||
import SmartInventoryDetail from './SmartInventoryDetail';
|
import SmartInventoryDetail from './SmartInventoryDetail';
|
||||||
import SmartInventoryEdit from './SmartInventoryEdit';
|
import SmartInventoryEdit from './SmartInventoryEdit';
|
||||||
import AdvancedInventoryHosts from './AdvancedInventoryHosts';
|
import SmartInventoryHosts from './SmartInventoryHosts';
|
||||||
import { getInventoryPath } from './shared/utils';
|
|
||||||
|
|
||||||
function SmartInventory({ setBreadcrumb }) {
|
function SmartInventory({ setBreadcrumb }) {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
@@ -102,8 +101,8 @@ function SmartInventory({ setBreadcrumb }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inventory && inventory?.kind !== 'smart') {
|
if (inventory?.kind === '') {
|
||||||
return <Redirect to={`${getInventoryPath(inventory)}/details`} />;
|
return <Redirect to={`/inventories/inventory/${inventory.id}/details`} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
let showCardHeader = true;
|
let showCardHeader = true;
|
||||||
@@ -142,7 +141,7 @@ function SmartInventory({ setBreadcrumb }) {
|
|||||||
/>
|
/>
|
||||||
</Route>,
|
</Route>,
|
||||||
<Route key="hosts" path="/inventories/smart_inventory/:id/hosts">
|
<Route key="hosts" path="/inventories/smart_inventory/:id/hosts">
|
||||||
<AdvancedInventoryHosts
|
<SmartInventoryHosts
|
||||||
inventory={inventory}
|
inventory={inventory}
|
||||||
setBreadcrumb={setBreadcrumb}
|
setBreadcrumb={setBreadcrumb}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ import ContentLoading from 'components/ContentLoading';
|
|||||||
import RoutedTabs from 'components/RoutedTabs';
|
import RoutedTabs from 'components/RoutedTabs';
|
||||||
import useRequest from 'hooks/useRequest';
|
import useRequest from 'hooks/useRequest';
|
||||||
import { InventoriesAPI } from 'api';
|
import { InventoriesAPI } from 'api';
|
||||||
import AdvancedInventoryHostDetail from '../AdvancedInventoryHostDetail';
|
import SmartInventoryHostDetail from '../SmartInventoryHostDetail';
|
||||||
|
|
||||||
function AdvancedInventoryHost({ inventory, setBreadcrumb }) {
|
function SmartInventoryHost({ inventory, setBreadcrumb }) {
|
||||||
const { params, path, url } = useRouteMatch(
|
const { params, path, url } = useRouteMatch(
|
||||||
'/inventories/:inventoryType/:id/hosts/:hostId'
|
'/inventories/smart_inventory/:id/hosts/:hostId'
|
||||||
);
|
);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -28,7 +28,7 @@ function AdvancedInventoryHost({ inventory, setBreadcrumb }) {
|
|||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
}, [inventory.id, params.hostId]),
|
}, [inventory.id, params.hostId]),
|
||||||
{ isLoading: true }
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -44,6 +44,7 @@ function AdvancedInventoryHost({ inventory, setBreadcrumb }) {
|
|||||||
if (error) {
|
if (error) {
|
||||||
return <ContentError error={error} />;
|
return <ContentError error={error} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tabsArray = [
|
const tabsArray = [
|
||||||
{
|
{
|
||||||
name: (
|
name: (
|
||||||
@@ -52,7 +53,7 @@ function AdvancedInventoryHost({ inventory, setBreadcrumb }) {
|
|||||||
{t`Back to Hosts`}
|
{t`Back to Hosts`}
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
link: `/inventories/${params.inventoryType}/${inventory.id}/hosts`,
|
link: `/inventories/smart_inventory/${inventory.id}/hosts`,
|
||||||
id: 0,
|
id: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -71,19 +72,17 @@ function AdvancedInventoryHost({ inventory, setBreadcrumb }) {
|
|||||||
{!isLoading && host && (
|
{!isLoading && host && (
|
||||||
<Switch>
|
<Switch>
|
||||||
<Redirect
|
<Redirect
|
||||||
from="/inventories/:inventoryType/:id/hosts/:hostId"
|
from="/inventories/smart_inventory/:id/hosts/:hostId"
|
||||||
to={`${path}/details`}
|
to={`${path}/details`}
|
||||||
exact
|
exact
|
||||||
/>
|
/>
|
||||||
<Route key="details" path={`${path}/details`}>
|
<Route key="details" path={`${path}/details`}>
|
||||||
<AdvancedInventoryHostDetail host={host} />
|
<SmartInventoryHostDetail host={host} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route key="not-found" path="*">
|
<Route key="not-found" path="*">
|
||||||
<ContentError isNotFound>
|
<ContentError isNotFound>
|
||||||
<Link to={`${url}/details`}>
|
<Link to={`${url}/details`}>
|
||||||
{params.inventoryType === 'smart_inventory'
|
{t`View smart inventory host details`}
|
||||||
? t`View smart inventory host details`
|
|
||||||
: t`View constructed inventory host details`}
|
|
||||||
</Link>
|
</Link>
|
||||||
</ContentError>
|
</ContentError>
|
||||||
</Route>
|
</Route>
|
||||||
@@ -93,4 +92,4 @@ function AdvancedInventoryHost({ inventory, setBreadcrumb }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AdvancedInventoryHost;
|
export default SmartInventoryHost;
|
||||||
@@ -7,14 +7,14 @@ import {
|
|||||||
waitForElement,
|
waitForElement,
|
||||||
} from '../../../../testUtils/enzymeHelpers';
|
} from '../../../../testUtils/enzymeHelpers';
|
||||||
import mockHost from '../shared/data.host.json';
|
import mockHost from '../shared/data.host.json';
|
||||||
import AdvancedInventoryHost from './AdvancedInventoryHost';
|
import SmartInventoryHost from './SmartInventoryHost';
|
||||||
|
|
||||||
jest.mock('../../../api');
|
jest.mock('../../../api');
|
||||||
jest.mock('react-router-dom', () => ({
|
jest.mock('react-router-dom', () => ({
|
||||||
...jest.requireActual('react-router-dom'),
|
...jest.requireActual('react-router-dom'),
|
||||||
useRouteMatch: () => ({
|
useRouteMatch: () => ({
|
||||||
params: { id: 1234, hostId: 2 },
|
params: { id: 1234, hostId: 2 },
|
||||||
path: '/inventories/:inventoryType/:id/hosts/:hostId',
|
path: '/inventories/smart_inventory/:id/hosts/:hostId',
|
||||||
url: '/inventories/smart_inventory/1234/hosts/2',
|
url: '/inventories/smart_inventory/1234/hosts/2',
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
@@ -24,7 +24,7 @@ const mockSmartInventory = {
|
|||||||
name: 'Mock Smart Inventory',
|
name: 'Mock Smart Inventory',
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('<AdvancedInventoryHost />', () => {
|
describe('<SmartInventoryHost />', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
let history;
|
let history;
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ describe('<AdvancedInventoryHost />', () => {
|
|||||||
InventoriesAPI.readHostDetail.mockResolvedValue(mockHost);
|
InventoriesAPI.readHostDetail.mockResolvedValue(mockHost);
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<AdvancedInventoryHost
|
<SmartInventoryHost
|
||||||
inventory={mockSmartInventory}
|
inventory={mockSmartInventory}
|
||||||
setBreadcrumb={() => {}}
|
setBreadcrumb={() => {}}
|
||||||
/>
|
/>
|
||||||
@@ -55,7 +55,7 @@ describe('<AdvancedInventoryHost />', () => {
|
|||||||
InventoriesAPI.readHostDetail.mockRejectedValueOnce(new Error());
|
InventoriesAPI.readHostDetail.mockRejectedValueOnce(new Error());
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<AdvancedInventoryHost
|
<SmartInventoryHost
|
||||||
inventory={mockSmartInventory}
|
inventory={mockSmartInventory}
|
||||||
setBreadcrumb={() => {}}
|
setBreadcrumb={() => {}}
|
||||||
/>
|
/>
|
||||||
@@ -76,7 +76,7 @@ describe('<AdvancedInventoryHost />', () => {
|
|||||||
});
|
});
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<AdvancedInventoryHost
|
<SmartInventoryHost
|
||||||
inventory={mockSmartInventory}
|
inventory={mockSmartInventory}
|
||||||
setBreadcrumb={() => {}}
|
setBreadcrumb={() => {}}
|
||||||
/>,
|
/>,
|
||||||
1
awx/ui/src/screens/Inventory/SmartInventoryHost/index.js
Normal file
1
awx/ui/src/screens/Inventory/SmartInventoryHost/index.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export { default } from './SmartInventoryHost';
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Link, useParams } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { Host } from 'types';
|
import { Host } from 'types';
|
||||||
@@ -8,8 +8,7 @@ import { Detail, DetailList, UserDateDetail } from 'components/DetailList';
|
|||||||
import Sparkline from 'components/Sparkline';
|
import Sparkline from 'components/Sparkline';
|
||||||
import { VariablesDetail } from 'components/CodeEditor';
|
import { VariablesDetail } from 'components/CodeEditor';
|
||||||
|
|
||||||
function AdvancedInventoryHostDetail({ host }) {
|
function SmartInventoryHostDetail({ host }) {
|
||||||
const { inventoryType } = useParams();
|
|
||||||
const {
|
const {
|
||||||
created,
|
created,
|
||||||
description,
|
description,
|
||||||
@@ -25,7 +24,6 @@ function AdvancedInventoryHostDetail({ host }) {
|
|||||||
type: 'job',
|
type: 'job',
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const inventoryKind = inventory.kind === '' ? 'inventory' : inventoryType;
|
|
||||||
return (
|
return (
|
||||||
<CardBody>
|
<CardBody>
|
||||||
<DetailList gutter="sm">
|
<DetailList gutter="sm">
|
||||||
@@ -39,7 +37,7 @@ function AdvancedInventoryHostDetail({ host }) {
|
|||||||
<Detail
|
<Detail
|
||||||
label={t`Inventory`}
|
label={t`Inventory`}
|
||||||
value={
|
value={
|
||||||
<Link to={`/inventories/${inventoryKind}/${inventory?.id}/details`}>
|
<Link to={`/inventories/inventory/${inventory?.id}/details`}>
|
||||||
{inventory?.name}
|
{inventory?.name}
|
||||||
</Link>
|
</Link>
|
||||||
}
|
}
|
||||||
@@ -63,8 +61,8 @@ function AdvancedInventoryHostDetail({ host }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
AdvancedInventoryHostDetail.propTypes = {
|
SmartInventoryHostDetail.propTypes = {
|
||||||
host: Host.isRequired,
|
host: Host.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AdvancedInventoryHostDetail;
|
export default SmartInventoryHostDetail;
|
||||||
@@ -1,17 +1,15 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
||||||
import AdvancedInventoryHostDetail from './AdvancedInventoryHostDetail';
|
import SmartInventoryHostDetail from './SmartInventoryHostDetail';
|
||||||
import mockHost from '../shared/data.host.json';
|
import mockHost from '../shared/data.host.json';
|
||||||
|
|
||||||
jest.mock('../../../api');
|
jest.mock('../../../api');
|
||||||
|
|
||||||
describe('<AdvancedInventoryHostDetail />', () => {
|
describe('<SmartInventoryHostDetail />', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(<SmartInventoryHostDetail host={mockHost} />);
|
||||||
<AdvancedInventoryHostDetail host={mockHost} />
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should render Details', () => {
|
test('should render Details', () => {
|
||||||
@@ -32,12 +30,11 @@ describe('<AdvancedInventoryHostDetail />', () => {
|
|||||||
|
|
||||||
test('should not load Activity', () => {
|
test('should not load Activity', () => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<AdvancedInventoryHostDetail
|
<SmartInventoryHostDetail
|
||||||
host={{
|
host={{
|
||||||
...mockHost,
|
...mockHost,
|
||||||
summary_fields: {
|
summary_fields: {
|
||||||
recent_jobs: [],
|
recent_jobs: [],
|
||||||
inventory: { kind: 'constructed', id: 2 },
|
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { default } from './SmartInventoryHostDetail';
|
||||||
@@ -13,7 +13,7 @@ import { getQSConfig, parseQueryString } from 'util/qs';
|
|||||||
import { InventoriesAPI } from 'api';
|
import { InventoriesAPI } from 'api';
|
||||||
import { Inventory } from 'types';
|
import { Inventory } from 'types';
|
||||||
import AdHocCommands from 'components/AdHocCommands/AdHocCommands';
|
import AdHocCommands from 'components/AdHocCommands/AdHocCommands';
|
||||||
import AdvancedInventoryHostListItem from './AdvancedInventoryHostListItem';
|
import SmartInventoryHostListItem from './SmartInventoryHostListItem';
|
||||||
|
|
||||||
const QS_CONFIG = getQSConfig('host', {
|
const QS_CONFIG = getQSConfig('host', {
|
||||||
page: 1,
|
page: 1,
|
||||||
@@ -21,7 +21,7 @@ const QS_CONFIG = getQSConfig('host', {
|
|||||||
order_by: 'name',
|
order_by: 'name',
|
||||||
});
|
});
|
||||||
|
|
||||||
function AdvancedInventoryHostList({ inventory }) {
|
function SmartInventoryHostList({ inventory }) {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const [isAdHocLaunchLoading, setIsAdHocLaunchLoading] = useState(false);
|
const [isAdHocLaunchLoading, setIsAdHocLaunchLoading] = useState(false);
|
||||||
const {
|
const {
|
||||||
@@ -61,10 +61,7 @@ function AdvancedInventoryHostList({ inventory }) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchHosts();
|
fetchHosts();
|
||||||
}, [fetchHosts]);
|
}, [fetchHosts]);
|
||||||
const inventoryType =
|
|
||||||
inventory.kind === 'constructed'
|
|
||||||
? 'constructed_inventory'
|
|
||||||
: 'smart_inventory';
|
|
||||||
return (
|
return (
|
||||||
<PaginatedTable
|
<PaginatedTable
|
||||||
contentError={contentError}
|
contentError={contentError}
|
||||||
@@ -117,11 +114,10 @@ function AdvancedInventoryHostList({ inventory }) {
|
|||||||
</HeaderRow>
|
</HeaderRow>
|
||||||
}
|
}
|
||||||
renderRow={(host, index) => (
|
renderRow={(host, index) => (
|
||||||
<AdvancedInventoryHostListItem
|
<SmartInventoryHostListItem
|
||||||
key={host.id}
|
key={host.id}
|
||||||
host={host}
|
host={host}
|
||||||
inventoryType={inventoryType}
|
detailUrl={`/inventories/smart_inventory/${inventory.id}/hosts/${host.id}/details`}
|
||||||
detailUrl={`/inventories/${inventoryType}/${inventory.id}/hosts/${host.id}/details`}
|
|
||||||
isSelected={selected.some((row) => row.id === host.id)}
|
isSelected={selected.some((row) => row.id === host.id)}
|
||||||
onSelect={() => handleSelect(host)}
|
onSelect={() => handleSelect(host)}
|
||||||
rowIndex={index}
|
rowIndex={index}
|
||||||
@@ -131,8 +127,8 @@ function AdvancedInventoryHostList({ inventory }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
AdvancedInventoryHostList.propTypes = {
|
SmartInventoryHostList.propTypes = {
|
||||||
inventory: Inventory.isRequired,
|
inventory: Inventory.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AdvancedInventoryHostList;
|
export default SmartInventoryHostList;
|
||||||
@@ -5,13 +5,13 @@ import {
|
|||||||
mountWithContexts,
|
mountWithContexts,
|
||||||
waitForElement,
|
waitForElement,
|
||||||
} from '../../../../testUtils/enzymeHelpers';
|
} from '../../../../testUtils/enzymeHelpers';
|
||||||
import AdvancedInventoryHostList from './AdvancedInventoryHostList';
|
import SmartInventoryHostList from './SmartInventoryHostList';
|
||||||
import mockInventory from '../shared/data.inventory.json';
|
import mockInventory from '../shared/data.inventory.json';
|
||||||
import mockHosts from '../shared/data.hosts.json';
|
import mockHosts from '../shared/data.hosts.json';
|
||||||
|
|
||||||
jest.mock('../../../api');
|
jest.mock('../../../api');
|
||||||
|
|
||||||
describe('<AdvancedInventoryHostList />', () => {
|
describe('<SmartInventoryHostList />', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
const clonedInventory = {
|
const clonedInventory = {
|
||||||
...mockInventory,
|
...mockInventory,
|
||||||
@@ -44,7 +44,7 @@ describe('<AdvancedInventoryHostList />', () => {
|
|||||||
});
|
});
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<AdvancedInventoryHostList inventory={clonedInventory} />
|
<SmartInventoryHostList inventory={clonedInventory} />
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0);
|
await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0);
|
||||||
@@ -55,12 +55,12 @@ describe('<AdvancedInventoryHostList />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('initially renders successfully', () => {
|
test('initially renders successfully', () => {
|
||||||
expect(wrapper.find('AdvancedInventoryHostList').length).toBe(1);
|
expect(wrapper.find('SmartInventoryHostList').length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should fetch hosts from api and render them in the list', () => {
|
test('should fetch hosts from api and render them in the list', () => {
|
||||||
expect(InventoriesAPI.readHosts).toHaveBeenCalled();
|
expect(InventoriesAPI.readHosts).toHaveBeenCalled();
|
||||||
expect(wrapper.find('AdvancedInventoryHostListItem').length).toBe(3);
|
expect(wrapper.find('SmartInventoryHostListItem').length).toBe(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should select and deselect all items', async () => {
|
test('should select and deselect all items', async () => {
|
||||||
@@ -87,7 +87,7 @@ describe('<AdvancedInventoryHostList />', () => {
|
|||||||
);
|
);
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<AdvancedInventoryHostList inventory={mockInventory} />
|
<SmartInventoryHostList inventory={mockInventory} />
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
await waitForElement(wrapper, 'ContentError', (el) => el.length === 1);
|
await waitForElement(wrapper, 'ContentError', (el) => el.length === 1);
|
||||||
@@ -9,26 +9,20 @@ import { Tr, Td } from '@patternfly/react-table';
|
|||||||
import Sparkline from 'components/Sparkline';
|
import Sparkline from 'components/Sparkline';
|
||||||
import { Host } from 'types';
|
import { Host } from 'types';
|
||||||
|
|
||||||
function AdvancedInventoryHostListItem({
|
function SmartInventoryHostListItem({
|
||||||
detailUrl,
|
detailUrl,
|
||||||
host: {
|
host,
|
||||||
name,
|
|
||||||
id,
|
|
||||||
summary_fields: { recent_jobs, inventory },
|
|
||||||
},
|
|
||||||
isSelected,
|
isSelected,
|
||||||
onSelect,
|
onSelect,
|
||||||
rowIndex,
|
rowIndex,
|
||||||
inventoryType,
|
|
||||||
}) {
|
}) {
|
||||||
const recentPlaybookJobs = recent_jobs.map((job) => ({
|
const recentPlaybookJobs = host.summary_fields.recent_jobs.map((job) => ({
|
||||||
...job,
|
...job,
|
||||||
type: 'job',
|
type: 'job',
|
||||||
}));
|
}));
|
||||||
const inventoryKind = inventory.kind === '' ? 'inventory' : inventoryType;
|
|
||||||
const inventoryLink = `/inventories/${inventoryKind}/${inventory.id}/details`;
|
|
||||||
return (
|
return (
|
||||||
<Tr id={`host-row-${id}`} ouiaId={`host-row-${id}`}>
|
<Tr id={`host-row-${host.id}`} ouiaId={`host-row-${host.id}`}>
|
||||||
<Td
|
<Td
|
||||||
select={{
|
select={{
|
||||||
rowIndex,
|
rowIndex,
|
||||||
@@ -38,24 +32,28 @@ function AdvancedInventoryHostListItem({
|
|||||||
/>
|
/>
|
||||||
<Td dataLabel={t`Name`}>
|
<Td dataLabel={t`Name`}>
|
||||||
<Link to={`${detailUrl}`}>
|
<Link to={`${detailUrl}`}>
|
||||||
<b>{name}</b>
|
<b>{host.name}</b>
|
||||||
</Link>
|
</Link>
|
||||||
</Td>
|
</Td>
|
||||||
<Td dataLabel={t`Recent jobs`}>
|
<Td dataLabel={t`Recent jobs`}>
|
||||||
<Sparkline jobs={recentPlaybookJobs} />
|
<Sparkline jobs={recentPlaybookJobs} />
|
||||||
</Td>
|
</Td>
|
||||||
<Td dataLabel={t`Inventory`}>
|
<Td dataLabel={t`Inventory`}>
|
||||||
<Link to={inventoryLink}>{inventory.name}</Link>
|
<Link
|
||||||
|
to={`/inventories/inventory/${host.summary_fields.inventory.id}/details`}
|
||||||
|
>
|
||||||
|
{host.summary_fields.inventory.name}
|
||||||
|
</Link>
|
||||||
</Td>
|
</Td>
|
||||||
</Tr>
|
</Tr>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
AdvancedInventoryHostListItem.propTypes = {
|
SmartInventoryHostListItem.propTypes = {
|
||||||
detailUrl: string.isRequired,
|
detailUrl: string.isRequired,
|
||||||
host: Host.isRequired,
|
host: Host.isRequired,
|
||||||
isSelected: bool.isRequired,
|
isSelected: bool.isRequired,
|
||||||
onSelect: func.isRequired,
|
onSelect: func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AdvancedInventoryHostListItem;
|
export default SmartInventoryHostListItem;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
||||||
import AdvancedInventoryHostListItem from './AdvancedInventoryHostListItem';
|
import SmartInventoryHostListItem from './SmartInventoryHostListItem';
|
||||||
|
|
||||||
const mockHost = {
|
const mockHost = {
|
||||||
id: 2,
|
id: 2,
|
||||||
@@ -19,14 +19,14 @@ const mockHost = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('<AdvancedInventoryHostListItem />', () => {
|
describe('<SmartInventoryHostListItem />', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<table>
|
<table>
|
||||||
<tbody>
|
<tbody>
|
||||||
<AdvancedInventoryHostListItem
|
<SmartInventoryHostListItem
|
||||||
detailUrl="/inventories/smart_inventory/1/hosts/2"
|
detailUrl="/inventories/smart_inventory/1/hosts/2"
|
||||||
host={mockHost}
|
host={mockHost}
|
||||||
isSelected={false}
|
isSelected={false}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Route, Switch } from 'react-router-dom';
|
||||||
|
import { Inventory } from 'types';
|
||||||
|
import SmartInventoryHostList from './SmartInventoryHostList';
|
||||||
|
import SmartInventoryHost from '../SmartInventoryHost';
|
||||||
|
|
||||||
|
function SmartInventoryHosts({ inventory, setBreadcrumb }) {
|
||||||
|
return (
|
||||||
|
<Switch>
|
||||||
|
<Route key="host" path="/inventories/smart_inventory/:id/hosts/:hostId">
|
||||||
|
<SmartInventoryHost
|
||||||
|
setBreadcrumb={setBreadcrumb}
|
||||||
|
inventory={inventory}
|
||||||
|
/>
|
||||||
|
</Route>
|
||||||
|
<Route key="host-list" path="/inventories/smart_inventory/:id/hosts">
|
||||||
|
<SmartInventoryHostList inventory={inventory} />
|
||||||
|
</Route>
|
||||||
|
</Switch>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
SmartInventoryHosts.propTypes = {
|
||||||
|
inventory: Inventory.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SmartInventoryHosts;
|
||||||
@@ -5,39 +5,37 @@ import {
|
|||||||
mountWithContexts,
|
mountWithContexts,
|
||||||
waitForElement,
|
waitForElement,
|
||||||
} from '../../../../testUtils/enzymeHelpers';
|
} from '../../../../testUtils/enzymeHelpers';
|
||||||
import AdvancedInventoryHosts from './AdvancedInventoryHosts';
|
import SmartInventoryHosts from './SmartInventoryHosts';
|
||||||
|
|
||||||
jest.mock('../../../api');
|
jest.mock('../../../api');
|
||||||
jest.mock('./AdvancedInventoryHostList', () => {
|
jest.mock('./SmartInventoryHostList', () => {
|
||||||
const AdvancedInventoryHostList = () => <div />;
|
const SmartInventoryHostList = () => <div />;
|
||||||
return {
|
return {
|
||||||
__esModule: true,
|
__esModule: true,
|
||||||
default: AdvancedInventoryHostList,
|
default: SmartInventoryHostList,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('<AdvancedInventoryHosts />', () => {
|
describe('<SmartInventoryHosts />', () => {
|
||||||
test('should render smart inventory host list', () => {
|
test('should render smart inventory host list', () => {
|
||||||
const history = createMemoryHistory({
|
const history = createMemoryHistory({
|
||||||
initialEntries: ['/inventories/smart_inventory/1/hosts'],
|
initialEntries: ['/inventories/smart_inventory/1/hosts'],
|
||||||
});
|
});
|
||||||
const match = {
|
const match = {
|
||||||
path: '/inventories/:inventoryType/:id/hosts',
|
path: '/inventories/smart_inventory/:id/hosts',
|
||||||
url: '/inventories/smart_inventory/1/hosts',
|
url: '/inventories/smart_inventory/1/hosts',
|
||||||
isExact: true,
|
isExact: true,
|
||||||
};
|
};
|
||||||
const wrapper = mountWithContexts(
|
const wrapper = mountWithContexts(
|
||||||
<AdvancedInventoryHosts inventory={{ id: 1 }} />,
|
<SmartInventoryHosts inventory={{ id: 1 }} />,
|
||||||
{
|
{
|
||||||
context: { router: { history, route: { match } } },
|
context: { router: { history, route: { match } } },
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
expect(wrapper.find('AdvancedInventoryHostList').length).toBe(1);
|
expect(wrapper.find('SmartInventoryHostList').length).toBe(1);
|
||||||
expect(wrapper.find('AdvancedInventoryHostList').prop('inventory')).toEqual(
|
expect(wrapper.find('SmartInventoryHostList').prop('inventory')).toEqual({
|
||||||
{
|
id: 1,
|
||||||
id: 1,
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -47,23 +45,20 @@ describe('<AdvancedInventoryHosts />', () => {
|
|||||||
initialEntries: ['/inventories/smart_inventory/1/hosts/2'],
|
initialEntries: ['/inventories/smart_inventory/1/hosts/2'],
|
||||||
});
|
});
|
||||||
const match = {
|
const match = {
|
||||||
path: '/inventories/:inventoryType/:id/hosts/:hostId',
|
path: '/inventories/smart_inventory/:id/hosts/:hostId',
|
||||||
url: '/inventories/smart_inventory/1/hosts/2',
|
url: '/inventories/smart_inventory/1/hosts/2',
|
||||||
isExact: true,
|
isExact: true,
|
||||||
};
|
};
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<AdvancedInventoryHosts
|
<SmartInventoryHosts inventory={{ id: 1 }} setBreadcrumb={() => {}} />,
|
||||||
inventory={{ id: 1 }}
|
|
||||||
setBreadcrumb={() => {}}
|
|
||||||
/>,
|
|
||||||
{
|
{
|
||||||
context: { router: { history, route: { match } } },
|
context: { router: { history, route: { match } } },
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0);
|
await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0);
|
||||||
expect(wrapper.find('AdvancedInventoryHost').length).toBe(1);
|
expect(wrapper.find('SmartInventoryHost').length).toBe(1);
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { default } from './SmartInventoryHosts';
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
import { useState, useEffect } from 'react';
|
|
||||||
import useWebsocket from 'hooks/useWebsocket';
|
|
||||||
import { InventorySourcesAPI } from 'api';
|
|
||||||
|
|
||||||
export default function useWsInventorySourcesDetails(initialSource) {
|
|
||||||
const [source, setSource] = useState(initialSource);
|
|
||||||
const lastMessage = useWebsocket({
|
|
||||||
jobs: ['status_changed'],
|
|
||||||
control: ['limit_reached_1'],
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setSource(initialSource);
|
|
||||||
}, [initialSource]);
|
|
||||||
|
|
||||||
useEffect(
|
|
||||||
() => {
|
|
||||||
if (
|
|
||||||
!lastMessage?.unified_job_id ||
|
|
||||||
!lastMessage?.inventory_source_id ||
|
|
||||||
lastMessage.type !== 'inventory_update'
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
['successful', 'failed', 'error', 'cancelled'].includes(
|
|
||||||
lastMessage.status
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
fetchSource();
|
|
||||||
}
|
|
||||||
setSource(updateSource(source, lastMessage));
|
|
||||||
},
|
|
||||||
[lastMessage] // eslint-disable-line react-hooks/exhaustive-deps
|
|
||||||
);
|
|
||||||
|
|
||||||
async function fetchSource() {
|
|
||||||
const { data } = await InventorySourcesAPI.readDetail(source.id);
|
|
||||||
setSource(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return source;
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateSource(source, message) {
|
|
||||||
return {
|
|
||||||
...source,
|
|
||||||
summary_fields: {
|
|
||||||
...source.summary_fields,
|
|
||||||
current_job: {
|
|
||||||
id: message.unified_job_id,
|
|
||||||
status: message.status,
|
|
||||||
finished: message.finished,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -8,12 +8,3 @@ const parseHostFilter = (value) => {
|
|||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
export default parseHostFilter;
|
export default parseHostFilter;
|
||||||
|
|
||||||
export function getInventoryPath(inventory) {
|
|
||||||
const url = {
|
|
||||||
'': `/inventories/inventory/${inventory.id}`,
|
|
||||||
smart: `/inventories/smart_inventory/${inventory.id}`,
|
|
||||||
constructed: `/inventories/constructed_inventory/${inventory.id}`,
|
|
||||||
};
|
|
||||||
return url[inventory.kind];
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import parseHostFilter, { getInventoryPath } from './utils';
|
import parseHostFilter from './utils';
|
||||||
|
|
||||||
describe('parseHostFilter', () => {
|
describe('parseHostFilter', () => {
|
||||||
test('parse host filter', () => {
|
test('parse host filter', () => {
|
||||||
@@ -19,21 +19,3 @@ describe('parseHostFilter', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getInventoryPath', () => {
|
|
||||||
test('should return inventory path', () => {
|
|
||||||
expect(getInventoryPath({ id: 1, kind: '' })).toMatch(
|
|
||||||
'/inventories/inventory/1'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
test('should return smart inventory path', () => {
|
|
||||||
expect(getInventoryPath({ id: 2, kind: 'smart' })).toMatch(
|
|
||||||
'/inventories/smart_inventory/2'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
test('should return constructed inventory path', () => {
|
|
||||||
expect(getInventoryPath({ id: 3, kind: 'constructed' })).toMatch(
|
|
||||||
'/inventories/constructed_inventory/3'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ options:
|
|||||||
kind:
|
kind:
|
||||||
description:
|
description:
|
||||||
- The kind field. Cannot be modified after created.
|
- The kind field. Cannot be modified after created.
|
||||||
choices: ["", "smart", "constructed"]
|
choices: ["", "smart"]
|
||||||
type: str
|
type: str
|
||||||
host_filter:
|
host_filter:
|
||||||
description:
|
description:
|
||||||
@@ -65,11 +65,6 @@ options:
|
|||||||
- list of Instance Groups for this Organization to run on.
|
- list of Instance Groups for this Organization to run on.
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
input_inventories:
|
|
||||||
description:
|
|
||||||
- List of Inventories to use as input for Constructed Inventory.
|
|
||||||
type: list
|
|
||||||
elements: str
|
|
||||||
prevent_instance_group_fallback:
|
prevent_instance_group_fallback:
|
||||||
description:
|
description:
|
||||||
- Prevent falling back to instance groups set on the organization
|
- Prevent falling back to instance groups set on the organization
|
||||||
@@ -116,12 +111,11 @@ def main():
|
|||||||
description=dict(),
|
description=dict(),
|
||||||
organization=dict(required=True),
|
organization=dict(required=True),
|
||||||
variables=dict(type='dict'),
|
variables=dict(type='dict'),
|
||||||
kind=dict(choices=['', 'smart', 'constructed']),
|
kind=dict(choices=['', 'smart']),
|
||||||
host_filter=dict(),
|
host_filter=dict(),
|
||||||
instance_groups=dict(type="list", elements='str'),
|
instance_groups=dict(type="list", elements='str'),
|
||||||
prevent_instance_group_fallback=dict(type='bool'),
|
prevent_instance_group_fallback=dict(type='bool'),
|
||||||
state=dict(choices=['present', 'absent'], default='present'),
|
state=dict(choices=['present', 'absent'], default='present'),
|
||||||
input_inventories=dict(type='list', elements='str'),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create a module for ourselves
|
# Create a module for ourselves
|
||||||
@@ -187,13 +181,6 @@ def main():
|
|||||||
if inventory and inventory['kind'] == '' and inventory_fields['kind'] == 'smart':
|
if inventory and inventory['kind'] == '' and inventory_fields['kind'] == 'smart':
|
||||||
module.fail_json(msg='You cannot turn a regular inventory into a "smart" inventory.')
|
module.fail_json(msg='You cannot turn a regular inventory into a "smart" inventory.')
|
||||||
|
|
||||||
if kind == 'constructed':
|
|
||||||
input_inventory_names = module.params.get('input_inventories')
|
|
||||||
if input_inventory_names is not None:
|
|
||||||
association_fields['input_inventories'] = []
|
|
||||||
for item in input_inventory_names:
|
|
||||||
association_fields['input_inventories'].append(module.resolve_name_to_id('inventories', item))
|
|
||||||
|
|
||||||
# If the state was present and we can let the module build or update the existing inventory, this will return on its own
|
# If the state was present and we can let the module build or update the existing inventory, this will return on its own
|
||||||
module.create_or_update_if_needed(
|
module.create_or_update_if_needed(
|
||||||
inventory,
|
inventory,
|
||||||
|
|||||||
@@ -64,10 +64,6 @@ options:
|
|||||||
description:
|
description:
|
||||||
- If specified, AWX will only import hosts that match this regular expression.
|
- If specified, AWX will only import hosts that match this regular expression.
|
||||||
type: str
|
type: str
|
||||||
limit:
|
|
||||||
description:
|
|
||||||
- Enter host, group or pattern match
|
|
||||||
type: str
|
|
||||||
credential:
|
credential:
|
||||||
description:
|
description:
|
||||||
- Credential to use for the source.
|
- Credential to use for the source.
|
||||||
@@ -171,7 +167,6 @@ def main():
|
|||||||
enabled_var=dict(),
|
enabled_var=dict(),
|
||||||
enabled_value=dict(),
|
enabled_value=dict(),
|
||||||
host_filter=dict(),
|
host_filter=dict(),
|
||||||
limit=dict(),
|
|
||||||
credential=dict(),
|
credential=dict(),
|
||||||
execution_environment=dict(),
|
execution_environment=dict(),
|
||||||
custom_virtualenv=dict(),
|
custom_virtualenv=dict(),
|
||||||
@@ -277,7 +272,6 @@ def main():
|
|||||||
'enabled_var',
|
'enabled_var',
|
||||||
'enabled_value',
|
'enabled_value',
|
||||||
'host_filter',
|
'host_filter',
|
||||||
'limit',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Layer in all remaining optional information
|
# Layer in all remaining optional information
|
||||||
|
|||||||
@@ -57,7 +57,15 @@ extends_documentation_fragment: awx.awx.auth
|
|||||||
|
|
||||||
|
|
||||||
EXAMPLES = """
|
EXAMPLES = """
|
||||||
- name: Launch a workflow with a timeout of 10 seconds
|
- name: Create a workflow approval node
|
||||||
|
workflow_job_template_node:
|
||||||
|
identifier: approval_test
|
||||||
|
approval_node:
|
||||||
|
name: approval_jt_name
|
||||||
|
timeout: 900
|
||||||
|
workflow: "Test Workflow"
|
||||||
|
|
||||||
|
- name: Launch the workflow with a timeout of 10 seconds
|
||||||
workflow_launch:
|
workflow_launch:
|
||||||
workflow_template: "Test Workflow"
|
workflow_template: "Test Workflow"
|
||||||
wait: False
|
wait: False
|
||||||
@@ -66,7 +74,7 @@ EXAMPLES = """
|
|||||||
- name: Wait for approval node to activate and approve
|
- name: Wait for approval node to activate and approve
|
||||||
workflow_approval:
|
workflow_approval:
|
||||||
workflow_job_id: "{{ workflow.id }}"
|
workflow_job_id: "{{ workflow.id }}"
|
||||||
name: Approve Me
|
name: approval_jt_name
|
||||||
interval: 10
|
interval: 10
|
||||||
timeout: 20
|
timeout: 20
|
||||||
action: deny
|
action: deny
|
||||||
|
|||||||
@@ -183,7 +183,21 @@ options:
|
|||||||
inventory:
|
inventory:
|
||||||
description:
|
description:
|
||||||
- Inventory applied as a prompt, if job template prompts for inventory
|
- Inventory applied as a prompt, if job template prompts for inventory
|
||||||
type: str
|
type: dict
|
||||||
|
suboptions:
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- Name Inventory to be applied to job as launch-time prompts.
|
||||||
|
type: str
|
||||||
|
organization:
|
||||||
|
description:
|
||||||
|
- Name of key for use in model for organizational reference
|
||||||
|
type: dict
|
||||||
|
suboptions:
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- The organization of the credentials exists in.
|
||||||
|
type: str
|
||||||
scm_branch:
|
scm_branch:
|
||||||
description:
|
description:
|
||||||
- SCM branch applied as a prompt, if job template prompts for SCM branch
|
- SCM branch applied as a prompt, if job template prompts for SCM branch
|
||||||
@@ -544,6 +558,10 @@ EXAMPLES = '''
|
|||||||
type: job_template
|
type: job_template
|
||||||
execution_environment:
|
execution_environment:
|
||||||
name: My EE
|
name: My EE
|
||||||
|
inventory:
|
||||||
|
name: Test inventory
|
||||||
|
organization:
|
||||||
|
name: Default
|
||||||
related:
|
related:
|
||||||
credentials:
|
credentials:
|
||||||
- name: cyberark
|
- name: cyberark
|
||||||
@@ -613,10 +631,6 @@ def create_workflow_nodes(module, response, workflow_nodes, workflow_id):
|
|||||||
if workflow_node['unified_job_template']['type'] != 'workflow_approval':
|
if workflow_node['unified_job_template']['type'] != 'workflow_approval':
|
||||||
module.fail_json(msg="Unable to Find unified_job_template: {0}".format(search_fields))
|
module.fail_json(msg="Unable to Find unified_job_template: {0}".format(search_fields))
|
||||||
|
|
||||||
inventory = workflow_node.get('inventory')
|
|
||||||
if inventory:
|
|
||||||
workflow_node_fields['inventory'] = module.resolve_name_to_id('inventories', inventory)
|
|
||||||
|
|
||||||
# Lookup Values for other fields
|
# Lookup Values for other fields
|
||||||
|
|
||||||
for field_name in (
|
for field_name in (
|
||||||
@@ -645,6 +659,17 @@ def create_workflow_nodes(module, response, workflow_nodes, workflow_id):
|
|||||||
'execution_environments', name_or_id=workflow_node['execution_environment']['name']
|
'execution_environments', name_or_id=workflow_node['execution_environment']['name']
|
||||||
)['id']
|
)['id']
|
||||||
|
|
||||||
|
# Two lookup methods are used based on a fix added in 21.11.0, and the awx export model
|
||||||
|
if 'inventory' in workflow_node:
|
||||||
|
if 'name' in workflow_node['inventory']:
|
||||||
|
inv_lookup_data = {}
|
||||||
|
if 'organization' in workflow_node['inventory']:
|
||||||
|
inv_lookup_data['organization'] = module.resolve_name_to_id('organizations', workflow_node['inventory']['organization']['name'])
|
||||||
|
workflow_node_fields['inventory'] = module.get_one(
|
||||||
|
'inventories', name_or_id=workflow_node['inventory']['name'], data=inv_lookup_data)['id']
|
||||||
|
else:
|
||||||
|
workflow_node_fields['inventory'] = module.get_one('inventories', name_or_id=workflow_node['inventory'])['id']
|
||||||
|
|
||||||
# Set Search fields
|
# Set Search fields
|
||||||
search_fields['workflow_job_template'] = workflow_node_fields['workflow_job_template'] = workflow_id
|
search_fields['workflow_job_template'] = workflow_node_fields['workflow_job_template'] = workflow_id
|
||||||
|
|
||||||
|
|||||||
@@ -16,13 +16,11 @@ import glob
|
|||||||
# Normally a read-only endpoint should not have a module (i.e. /api/v2/me) but sometimes we reuse a name
|
# Normally a read-only endpoint should not have a module (i.e. /api/v2/me) but sometimes we reuse a name
|
||||||
# For example, we have a role module but /api/v2/roles is a read only endpoint.
|
# For example, we have a role module but /api/v2/roles is a read only endpoint.
|
||||||
# This list indicates which read-only endpoints have associated modules with them.
|
# This list indicates which read-only endpoints have associated modules with them.
|
||||||
read_only_endpoints_with_modules = ['settings', 'role', 'project_update']
|
read_only_endpoints_with_modules = ['settings', 'role', 'project_update', 'workflow_approval']
|
||||||
|
|
||||||
# If a module should not be created for an endpoint and the endpoint is not read-only add it here
|
# If a module should not be created for an endpoint and the endpoint is not read-only add it here
|
||||||
# THINK HARD ABOUT DOING THIS
|
# THINK HARD ABOUT DOING THIS
|
||||||
no_module_for_endpoint = [
|
no_module_for_endpoint = []
|
||||||
'constructed_inventories', # This is a view for inventory with kind=constructed
|
|
||||||
]
|
|
||||||
|
|
||||||
# Some modules work on the related fields of an endpoint. These modules will not have an auto-associated endpoint
|
# Some modules work on the related fields of an endpoint. These modules will not have an auto-associated endpoint
|
||||||
no_endpoint_for_module = [
|
no_endpoint_for_module = [
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
---
|
||||||
|
- name: Generate a random string for names
|
||||||
|
set_fact:
|
||||||
|
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
|
||||||
|
test_prefix: AWX-Collection-tests-workflow_approval
|
||||||
|
|
||||||
|
- name: Generate random names for test objects
|
||||||
|
set_fact:
|
||||||
|
org_name: "{{ test_prefix }}-org-{{ test_id }}"
|
||||||
|
approval_node_name: "{{ test_prefix }}-node-{{ test_id }}"
|
||||||
|
wfjt_name: "{{ test_prefix }}-wfjt-{{ test_id }}"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: Create a new organization for test isolation
|
||||||
|
organization:
|
||||||
|
name: "{{ org_name }}"
|
||||||
|
|
||||||
|
- name: Create a workflow job template
|
||||||
|
workflow_job_template:
|
||||||
|
name: "{{ wfjt_name }}"
|
||||||
|
organization: "{{ org_name }}"
|
||||||
|
|
||||||
|
- name: Create approval node
|
||||||
|
workflow_job_template_node:
|
||||||
|
identifier: approval_test
|
||||||
|
approval_node:
|
||||||
|
name: "{{ approval_node_name }}" # Referenced later on
|
||||||
|
timeout: 900
|
||||||
|
workflow: "{{ wfjt_name }}"
|
||||||
|
|
||||||
|
# Launch and approve the workflow
|
||||||
|
- name: Launch the workflow
|
||||||
|
workflow_launch:
|
||||||
|
workflow_template: "{{ wfjt_name }}"
|
||||||
|
wait: False
|
||||||
|
register: workflow_job
|
||||||
|
|
||||||
|
- name: Wait for approval node to activate and approve
|
||||||
|
workflow_approval:
|
||||||
|
workflow_job_id: "{{ workflow_job.id }}"
|
||||||
|
name: "{{ approval_node_name }}"
|
||||||
|
interval: 10
|
||||||
|
timeout: 20
|
||||||
|
action: approve
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "result is changed"
|
||||||
|
- "result is not failed"
|
||||||
|
|
||||||
|
always:
|
||||||
|
- name: Delete the workflow job template
|
||||||
|
workflow_job_template:
|
||||||
|
name: "{{ wfjt_name }}"
|
||||||
|
state: absent
|
||||||
|
ignore_errors: True
|
||||||
@@ -493,6 +493,7 @@
|
|||||||
workflow_job_template:
|
workflow_job_template:
|
||||||
name: "copy_{{ wfjt_name }}"
|
name: "copy_{{ wfjt_name }}"
|
||||||
organization: Default
|
organization: Default
|
||||||
|
ask_inventory_on_launch: true
|
||||||
survey_spec:
|
survey_spec:
|
||||||
name: Basic Survey
|
name: Basic Survey
|
||||||
description: Basic Survey
|
description: Basic Survey
|
||||||
@@ -737,6 +738,10 @@
|
|||||||
timeout: 23
|
timeout: 23
|
||||||
execution_environment:
|
execution_environment:
|
||||||
name: "{{ ee1 }}"
|
name: "{{ ee1 }}"
|
||||||
|
inventory:
|
||||||
|
name: Test inventory
|
||||||
|
organization:
|
||||||
|
name: Default
|
||||||
related:
|
related:
|
||||||
credentials:
|
credentials:
|
||||||
- name: "{{ scm_cred_name }}"
|
- name: "{{ scm_cred_name }}"
|
||||||
|
|||||||
@@ -125,23 +125,14 @@ class Inventory(HasCopy, HasCreate, HasInstanceGroups, HasVariables, base.Base):
|
|||||||
return inv_updates
|
return inv_updates
|
||||||
|
|
||||||
|
|
||||||
page.register_page(
|
page.register_page([resources.inventory, (resources.inventories, 'post'), (resources.inventory_copy, 'post')], Inventory)
|
||||||
[
|
|
||||||
resources.inventory,
|
|
||||||
resources.constructed_inventory,
|
|
||||||
(resources.inventories, 'post'),
|
|
||||||
(resources.inventory_copy, 'post'),
|
|
||||||
(resources.constructed_inventories, 'post'),
|
|
||||||
],
|
|
||||||
Inventory,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class Inventories(page.PageList, Inventory):
|
class Inventories(page.PageList, Inventory):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
page.register_page([resources.inventories, resources.related_inventories, resources.constructed_inventories], Inventories)
|
page.register_page([resources.inventories, resources.related_inventories], Inventories)
|
||||||
|
|
||||||
|
|
||||||
class Group(HasCreate, HasVariables, base.Base):
|
class Group(HasCreate, HasVariables, base.Base):
|
||||||
|
|||||||
@@ -57,9 +57,7 @@ class Resources(object):
|
|||||||
_instance_related_jobs = r'instances/\d+/jobs/'
|
_instance_related_jobs = r'instances/\d+/jobs/'
|
||||||
_instances = 'instances/'
|
_instances = 'instances/'
|
||||||
_inventories = 'inventories/'
|
_inventories = 'inventories/'
|
||||||
_constructed_inventories = 'constructed_inventories/'
|
|
||||||
_inventory = r'inventories/\d+/'
|
_inventory = r'inventories/\d+/'
|
||||||
_constructed_inventory = r'constructed_inventories/\d+/'
|
|
||||||
_inventory_access_list = r'inventories/\d+/access_list/'
|
_inventory_access_list = r'inventories/\d+/access_list/'
|
||||||
_inventory_copy = r'inventories/\d+/copy/'
|
_inventory_copy = r'inventories/\d+/copy/'
|
||||||
_inventory_labels = r'inventories/\d+/labels/'
|
_inventory_labels = r'inventories/\d+/labels/'
|
||||||
|
|||||||
@@ -75,7 +75,8 @@ In the root of awx-operator:
|
|||||||
-e image_version=devel \
|
-e image_version=devel \
|
||||||
-e image_pull_policy=Always \
|
-e image_pull_policy=Always \
|
||||||
-e service_type=nodeport \
|
-e service_type=nodeport \
|
||||||
-e namespace=awx
|
-e namespace=awx \
|
||||||
|
-e nodeport_port=30080
|
||||||
```
|
```
|
||||||
Check the operator with the following commands:
|
Check the operator with the following commands:
|
||||||
|
|
||||||
|
|||||||
@@ -1,86 +0,0 @@
|
|||||||
### Constructed inventory in AWX
|
|
||||||
|
|
||||||
Constructed inventory is a separate "kind" of inventory, along-side of
|
|
||||||
normal (manual) inventories and "smart" inventories.
|
|
||||||
The functionality overlaps with smart inventory, and it is intended that
|
|
||||||
smart inventory is sunsetted and will be eventually removed.
|
|
||||||
|
|
||||||
#### Demo Problem
|
|
||||||
|
|
||||||
This is branched from original demo at:
|
|
||||||
|
|
||||||
https://github.com/AlanCoding/Ansible-inventory-file-examples/tree/master/issues/AWX371
|
|
||||||
|
|
||||||
Consider that we have 2 original "source" inventories named "East" and "West".
|
|
||||||
|
|
||||||
```
|
|
||||||
# East inventory original contents
|
|
||||||
host1 account_alias=product_dev
|
|
||||||
host2 account_alias=product_dev state=shutdown
|
|
||||||
host3 account_alias=sustaining
|
|
||||||
```
|
|
||||||
|
|
||||||
```
|
|
||||||
# West inventory original contents
|
|
||||||
host4 account_alias=product_dev
|
|
||||||
host6 account_alias=product_dev state=shutdown
|
|
||||||
host5 account_alias=sustaining state=shutdown
|
|
||||||
```
|
|
||||||
|
|
||||||
The user's intent is to operate on _shutdown_ hosts in the _product_dev_ group.
|
|
||||||
So these are two AND conditions that we want to filter on.
|
|
||||||
|
|
||||||
To accomplish this, the user will create a constructed inventory with
|
|
||||||
the following properties.
|
|
||||||
|
|
||||||
`source_vars` =
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
plugin: constructed
|
|
||||||
strict: true
|
|
||||||
use_vars_plugins: true # https://github.com/ansible/ansible/issues/75365
|
|
||||||
groups:
|
|
||||||
shutdown: resolved_state == "shutdown"
|
|
||||||
shutdown_in_product_dev: resolved_state == "shutdown" and account_alias == "product_dev"
|
|
||||||
compose:
|
|
||||||
resolved_state: state | default("running")
|
|
||||||
```
|
|
||||||
|
|
||||||
`limit` = "shutdown_in_product_dev"
|
|
||||||
|
|
||||||
Then when running a job template against the constructed inventory, it should
|
|
||||||
act on host2 and host6, because those are the two hosts that fit the criteria.
|
|
||||||
|
|
||||||
#### Mechanic
|
|
||||||
|
|
||||||
The constructed inventory contents will be materialized by an inventory update
|
|
||||||
which runs via `ansible-inventory`.
|
|
||||||
This is always configured to update-on-launch before a job,
|
|
||||||
but the user can still select a cache timeout value in case this takes too long.
|
|
||||||
|
|
||||||
When creating a constructed inventory, the API enforces that it always has 1
|
|
||||||
inventory source associated with it.
|
|
||||||
All inventory updates have an associated inventory source, and the fields
|
|
||||||
needed for constructed inventory (`source_vars` and `limit`) are fields
|
|
||||||
on the inventory source model normally.
|
|
||||||
|
|
||||||
#### Capabilities
|
|
||||||
|
|
||||||
In addition to filtering on hostvars, users will be able to filter based on
|
|
||||||
facts, which are prepared before the update in the same way as for jobs.
|
|
||||||
|
|
||||||
For filtering on related objects in the database, users will need to use "meta"
|
|
||||||
vars that are automatically prepared by the server.
|
|
||||||
These have names such as:
|
|
||||||
- `awx_inventory_name`
|
|
||||||
- `awx_inventory_id`
|
|
||||||
|
|
||||||
#### Best Practices
|
|
||||||
|
|
||||||
It is very important to set the `strict` parameter to `True` so that users
|
|
||||||
can debug problems with their templates, because these can get complicated.
|
|
||||||
If the template fails to render, users will get an error in the
|
|
||||||
associated inventory update for that constructed inventory.
|
|
||||||
|
|
||||||
When encountering errors, it may be prudent to increase `verbosity` to get
|
|
||||||
more details.
|
|
||||||
Reference in New Issue
Block a user