Remove old uses of CustomInventoryScript

some uses are minor references

Fix some test fails
This commit is contained in:
Alan Rominger 2021-04-12 14:54:44 -04:00
parent 38352063e8
commit a54aab9717
No known key found for this signature in database
GPG Key ID: C2D7EAAA12B63559
8 changed files with 18 additions and 61 deletions

View File

@ -2670,7 +2670,6 @@ class ActivityStreamAccess(BaseAccess):
'role',
'actor',
'schedule',
'custom_inventory_script',
'unified_job_template',
'workflow_job_template_node',
)

View File

@ -31,7 +31,6 @@ def metrics():
registry=REGISTRY,
)
SCHEDULE_COUNT = Gauge('awx_schedules_total', 'Number of schedules', registry=REGISTRY)
INV_SCRIPT_COUNT = Gauge('awx_inventory_scripts_total', 'Number of invetory scripts', registry=REGISTRY)
USER_SESSIONS = Gauge(
'awx_sessions_total',
'Number of sessions',
@ -160,7 +159,6 @@ def metrics():
HOST_COUNT.labels(type='active').set(current_counts['active_host_count'])
SCHEDULE_COUNT.set(current_counts['schedule'])
INV_SCRIPT_COUNT.set(current_counts['custom_inventory_script'])
CUSTOM_VENVS.set(current_counts['custom_virtualenvs'])
USER_SESSIONS.labels(type='all').set(current_counts['active_sessions'])

View File

@ -235,11 +235,7 @@ register(
'AWX_ISOLATION_BASE_PATH',
field_class=fields.CharField,
label=_('Job execution path'),
help_text=_(
'The directory in which Tower will create new temporary '
'directories for job execution and isolation '
'(such as credential files and custom inventory scripts).'
),
help_text=_('The directory in which Tower will create new temporary directories for job execution and isolation (such as credential files).'),
category=_('Jobs'),
category_slug='jobs',
)

View File

@ -147,9 +147,6 @@ class Command(BaseCommand):
parser.add_argument('--overwrite', dest='overwrite', action='store_true', default=False, help='overwrite the destination hosts and groups')
parser.add_argument('--overwrite-vars', dest='overwrite_vars', action='store_true', default=False, help='overwrite (rather than merge) variables')
parser.add_argument('--keep-vars', dest='keep_vars', action='store_true', default=False, help='DEPRECATED legacy option, has no effect')
parser.add_argument(
'--custom', dest='custom', action='store_true', default=False, help='DEPRECATED indicates a custom inventory script, no longer used'
)
parser.add_argument('--source', dest='source', type=str, default=None, metavar='s', help='inventory directory, file, or script to load')
parser.add_argument(
'--enabled-var',

View File

@ -2412,7 +2412,7 @@ class RunInventoryUpdate(BaseTask):
# All CLOUD_PROVIDERS sources implement as inventory plugin from collection
env['ANSIBLE_INVENTORY_ENABLED'] = 'auto'
if inventory_update.source in ['scm', 'custom']:
if inventory_update.source == 'scm':
for env_k in inventory_update.source_vars_dict:
if str(env_k) not in env and str(env_k) not in settings.INV_ENV_VARIABLE_BLOCKED:
env[str(env_k)] = str(inventory_update.source_vars_dict[env_k])
@ -2513,16 +2513,7 @@ class RunInventoryUpdate(BaseTask):
rel_path = injector.filename
elif src == 'scm':
rel_path = os.path.join('project', inventory_update.source_path)
elif src == 'custom':
handle, inventory_path = tempfile.mkstemp(dir=private_data_dir)
f = os.fdopen(handle, 'w')
if inventory_update.source_script is None:
raise RuntimeError('Inventory Script does not exist')
f.write(inventory_update.source_script.script)
f.close()
os.chmod(inventory_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
rel_path = os.path.split(inventory_path)[-1]
return rel_path
def build_cwd(self, inventory_update, private_data_dir):

View File

@ -147,7 +147,7 @@ def test_async_inventory_deletion_deletes_related_jt(delete, get, job_template,
@pytest.mark.parametrize('order_by', ('extra_vars', '-extra_vars', 'extra_vars,pk', '-extra_vars,pk'))
@pytest.mark.django_db
def test_list_cannot_order_by_unsearchable_field(get, organization, alice, order_by):
get(reverse('api:jobs_list'), alice, QUERY_STRING='order_by=%s' % order_by, expect=403)
get(reverse('api:job_list'), alice, QUERY_STRING='order_by=%s' % order_by, expect=403)
@pytest.mark.parametrize("role_field,expected_status_code", [(None, 403), ('admin_role', 201), ('update_role', 403), ('adhoc_role', 403), ('use_role', 403)])

View File

@ -174,7 +174,7 @@ class TestSCMClean:
@pytest.mark.django_db
class TestInventorySourceInjectors:
def test_extra_credentials(self, project, credential):
inventory_source = InventorySource.objects.create(name='foo', source='custom', source_project=project)
inventory_source = InventorySource.objects.create(name='foo', source='scm', source_project=project)
inventory_source.credentials.add(credential)
assert inventory_source.get_cloud_credential() == credential # for serializer
assert inventory_source.get_extra_credentials() == [credential]

View File

@ -128,7 +128,7 @@ page.register_page([resources.inventories, resources.related_inventories], Inven
class Group(HasCreate, HasVariables, base.Base):
dependencies = [Inventory]
optional_dependencies = [Credential, InventoryScript]
optional_dependencies = [Credential]
NATURAL_KEY = ('name', 'inventory')
@property
@ -157,9 +157,11 @@ class Group(HasCreate, HasVariables, base.Base):
return payload
def create_payload(self, name='', description='', inventory=Inventory, credential=None, source_script=None, **kwargs):
credential, source_script = filter_by_class((credential, Credential), (source_script, InventoryScript))
self.create_and_update_dependencies(inventory, credential, source_script)
def create_payload(self, name='', description='', inventory=Inventory, credential=None, **kwargs):
credential = filter_by_class(
(credential, Credential),
)
self.create_and_update_dependencies(inventory, credential)
credential = self.ds.credential if credential else None
payload = self.payload(inventory=self.ds.inventory, credential=credential, name=name, description=description, **kwargs)
payload.ds = DSAdapter(self.__class__.__name__, self._dependency_store)
@ -298,10 +300,10 @@ class InventorySource(HasCreate, HasNotifications, UnifiedJobTemplate):
optional_schedule_fields = tuple()
dependencies = [Inventory]
optional_dependencies = [Credential, InventoryScript, Project]
optional_dependencies = [Credential, Project]
NATURAL_KEY = ('organization', 'name', 'inventory')
def payload(self, inventory, source='scm', credential=None, source_script=None, project=None, **kwargs):
def payload(self, inventory, source='scm', credential=None, project=None, **kwargs):
payload = PseudoNamespace(
name=kwargs.get('name') or 'InventorySource - {}'.format(random_title()),
description=kwargs.get('description') or random_title(10),
@ -311,8 +313,6 @@ class InventorySource(HasCreate, HasNotifications, UnifiedJobTemplate):
if credential:
payload.credential = credential.id
if source_script:
payload.source_script = source_script.id
if project:
payload.source_project = project.id
@ -332,51 +332,27 @@ class InventorySource(HasCreate, HasNotifications, UnifiedJobTemplate):
return payload
def create_payload(
self, name='', description='', source='scm', inventory=Inventory, credential=None, source_script=InventoryScript, project=None, **kwargs
):
if source != 'custom' and source_script == InventoryScript:
source_script = None
def create_payload(self, name='', description='', source='scm', inventory=Inventory, credential=None, project=None, **kwargs):
if source == 'scm':
kwargs.setdefault('overwrite_vars', True)
kwargs.setdefault('source_path', 'inventories/script_migrations/script_source.py')
if project is None:
project = Project
inventory, credential, source_script, project = filter_by_class(
(inventory, Inventory), (credential, Credential), (source_script, InventoryScript), (project, Project)
)
self.create_and_update_dependencies(inventory, credential, source_script, project)
inventory, credential, project = filter_by_class((inventory, Inventory), (credential, Credential), (project, Project))
self.create_and_update_dependencies(inventory, credential, project)
if credential:
credential = self.ds.credential
if project:
project = self.ds.project
payload = self.payload(
inventory=self.ds.inventory,
source=source,
credential=credential,
source_script=source_script,
project=project,
name=name,
description=description,
**kwargs
)
payload = self.payload(inventory=self.ds.inventory, source=source, credential=credential, project=project, name=name, description=description, **kwargs)
payload.ds = DSAdapter(self.__class__.__name__, self._dependency_store)
return payload
def create(self, name='', description='', source='scm', inventory=Inventory, credential=None, source_script=InventoryScript, project=None, **kwargs):
payload = self.create_payload(
name=name,
description=description,
source=source,
inventory=inventory,
credential=credential,
source_script=source_script,
project=project,
**kwargs
)
def create(self, name='', description='', source='scm', inventory=Inventory, credential=None, project=None, **kwargs):
payload = self.create_payload(name=name, description=description, source=source, inventory=inventory, credential=credential, project=project, **kwargs)
return self.update_identity(InventorySources(self.connection).post(payload))
def update(self):