Skip to content

Commit

Permalink
remove custom_virtualenv support from the AWX collection and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpetrello committed Mar 5, 2021
1 parent ec3b225 commit b2a4340
Show file tree
Hide file tree
Showing 14 changed files with 6 additions and 401 deletions.
4 changes: 4 additions & 0 deletions awx/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,7 @@ class OrganizationSerializer(BaseSerializer):
class Meta:
model = Organization
fields = ('*', 'max_hosts', 'custom_virtualenv', 'default_environment',)
read_only_fields = ('*', 'custom_virtualenv',)

def get_related(self, obj):
res = super(OrganizationSerializer, self).get_related(obj)
Expand Down Expand Up @@ -1399,6 +1400,7 @@ class Meta:
fields = ('*', '-execution_environment', 'organization', 'scm_update_on_launch',
'scm_update_cache_timeout', 'allow_override', 'custom_virtualenv', 'default_environment') + \
('last_update_failed', 'last_updated') # Backwards compatibility
read_only_fields = ('*', 'custom_virtualenv',)

def get_related(self, obj):
res = super(ProjectSerializer, self).get_related(obj)
Expand Down Expand Up @@ -1978,6 +1980,7 @@ class Meta:
fields = ('*', 'source', 'source_path', 'source_script', 'source_vars', 'credential',
'enabled_var', 'enabled_value', 'host_filter', 'overwrite', 'overwrite_vars',
'custom_virtualenv', 'timeout', 'verbosity')
read_only_fields = ('*', 'custom_virtualenv',)

def get_related(self, obj):
res = super(InventorySourceOptionsSerializer, self).get_related(obj)
Expand Down Expand Up @@ -2963,6 +2966,7 @@ class Meta:
'become_enabled', 'diff_mode', 'allow_simultaneous', 'custom_virtualenv',
'job_slice_count', 'webhook_service', 'webhook_credential',
)
read_only_fields = ('*', 'custom_virtualenv',)

def get_related(self, obj):
res = super(JobTemplateSerializer, self).get_related(obj)
Expand Down
55 changes: 0 additions & 55 deletions awx/main/tests/functional/api/test_job_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,61 +302,6 @@ def test_save_survey_passwords_on_migration(job_template_with_survey_passwords):
assert job.survey_passwords == {'SSN': '$encrypted$', 'secret_key': '$encrypted$'}


@pytest.mark.django_db
@pytest.mark.parametrize('access', ["superuser", "admin", "peon"])
def test_job_template_custom_virtualenv(get, patch, organization_factory, job_template_factory, alice, access):
objs = organization_factory("org", superusers=['admin'])
jt = job_template_factory("jt", organization=objs.organization,
inventory='test_inv', project='test_proj').job_template

user = alice
if access == "superuser":
user = objs.superusers.admin
elif access == "admin":
jt.admin_role.members.add(alice)
else:
jt.read_role.members.add(alice)

with TemporaryDirectory(dir=settings.BASE_VENV_PATH) as temp_dir:
os.makedirs(os.path.join(temp_dir, 'bin', 'activate'))
url = reverse('api:job_template_detail', kwargs={'pk': jt.id})

if access == "peon":
patch(url, {'custom_virtualenv': temp_dir}, user=user, expect=403)
assert 'custom_virtualenv' not in get(url, user=user)
assert JobTemplate.objects.get(pk=jt.id).custom_virtualenv is None
else:
patch(url, {'custom_virtualenv': temp_dir}, user=user, expect=200)
assert get(url, user=user).data['custom_virtualenv'] == os.path.join(temp_dir, '')


@pytest.mark.django_db
def test_job_template_invalid_custom_virtualenv(get, patch, organization_factory,
job_template_factory):
objs = organization_factory("org", superusers=['admin'])
jt = job_template_factory("jt", organization=objs.organization,
inventory='test_inv', project='test_proj').job_template

url = reverse('api:job_template_detail', kwargs={'pk': jt.id})
resp = patch(url, {'custom_virtualenv': '/foo/bar'}, user=objs.superusers.admin, expect=400)
assert resp.data['custom_virtualenv'] == [
'/foo/bar is not a valid virtualenv in {}'.format(settings.BASE_VENV_PATH)
]


@pytest.mark.django_db
@pytest.mark.parametrize('value', ["", None])
def test_job_template_unset_custom_virtualenv(get, patch, organization_factory,
job_template_factory, value):
objs = organization_factory("org", superusers=['admin'])
jt = job_template_factory("jt", organization=objs.organization,
inventory='test_inv', project='test_proj').job_template

url = reverse('api:job_template_detail', kwargs={'pk': jt.id})
resp = patch(url, {'custom_virtualenv': value}, user=objs.superusers.admin, expect=200)
assert resp.data['custom_virtualenv'] is None


@pytest.mark.django_db
def test_jt_organization_follows_project(post, patch, admin_user):
org1 = Organization.objects.create(name='foo1')
Expand Down
26 changes: 0 additions & 26 deletions awx/main/tests/functional/api/test_organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,32 +242,6 @@ def test_delete_organization_xfail2(delete, organization):
delete(reverse('api:organization_detail', kwargs={'pk': organization.id}), user=None, expect=401)


@pytest.mark.django_db
def test_organization_custom_virtualenv(get, patch, organization, admin):
with TemporaryDirectory(dir=settings.BASE_VENV_PATH) as temp_dir:
os.makedirs(os.path.join(temp_dir, 'bin', 'activate'))
url = reverse('api:organization_detail', kwargs={'pk': organization.id})
patch(url, {'custom_virtualenv': temp_dir}, user=admin, expect=200)
assert get(url, user=admin).data['custom_virtualenv'] == os.path.join(temp_dir, '')


@pytest.mark.django_db
def test_organization_invalid_custom_virtualenv(get, patch, organization, admin):
url = reverse('api:organization_detail', kwargs={'pk': organization.id})
resp = patch(url, {'custom_virtualenv': '/foo/bar'}, user=admin, expect=400)
assert resp.data['custom_virtualenv'] == [
'/foo/bar is not a valid virtualenv in {}'.format(settings.BASE_VENV_PATH)
]


@pytest.mark.django_db
@pytest.mark.parametrize('value', ["", None])
def test_organization_unset_custom_virtualenv(get, patch, organization, admin, value):
url = reverse('api:organization_detail', kwargs={'pk': organization.id})
resp = patch(url, {'custom_virtualenv': value}, user=admin, expect=200)
assert resp.data['custom_virtualenv'] is None


@pytest.mark.django_db
def test_organization_delete(delete, admin, organization, organization_jobs_successful):
url = reverse('api:organization_detail', kwargs={'pk': organization.id})
Expand Down
26 changes: 0 additions & 26 deletions awx/main/tests/functional/api/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,6 @@ def test_non_insights_credential(self, patch, insights_project, admin_user, scm_
expect=400)


@pytest.mark.django_db
def test_project_custom_virtualenv(get, patch, project, admin):
with TemporaryDirectory(dir=settings.BASE_VENV_PATH) as temp_dir:
os.makedirs(os.path.join(temp_dir, 'bin', 'activate'))
url = reverse('api:project_detail', kwargs={'pk': project.id})
patch(url, {'custom_virtualenv': temp_dir}, user=admin, expect=200)
assert get(url, user=admin).data['custom_virtualenv'] == os.path.join(temp_dir, '')


@pytest.mark.django_db
def test_project_invalid_custom_virtualenv(get, patch, project, admin):
url = reverse('api:project_detail', kwargs={'pk': project.id})
resp = patch(url, {'custom_virtualenv': '/foo/bar'}, user=admin, expect=400)
assert resp.data['custom_virtualenv'] == [
'/foo/bar is not a valid virtualenv in {}'.format(settings.BASE_VENV_PATH)
]


@pytest.mark.django_db
@pytest.mark.parametrize('value', ["", None])
def test_project_unset_custom_virtualenv(get, patch, project, admin, value):
url = reverse('api:project_detail', kwargs={'pk': project.id})
resp = patch(url, {'custom_virtualenv': value}, user=admin, expect=200)
assert resp.data['custom_virtualenv'] is None


@pytest.mark.django_db
def test_no_changing_overwrite_behavior_if_used(post, patch, organization, admin_user):
r1 = post(
Expand Down
7 changes: 1 addition & 6 deletions awx_collection/plugins/modules/tower_inventory_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@
description:
- Override vars in child groups and hosts with those from external source.
type: bool
custom_virtualenv:
description:
- Local absolute file path containing a custom Python virtualenv to use.
type: str
timeout:
description: The amount of time (in seconds) to run before the task is canceled.
type: int
Expand Down Expand Up @@ -181,7 +177,6 @@ def main():
organization=dict(),
overwrite=dict(type='bool'),
overwrite_vars=dict(type='bool'),
custom_virtualenv=dict(),
timeout=dict(type='int'),
verbosity=dict(type='int', choices=[0, 1, 2]),
update_on_launch=dict(type='bool'),
Expand Down Expand Up @@ -265,7 +260,7 @@ def main():

OPTIONAL_VARS = (
'description', 'source', 'source_path', 'source_vars',
'overwrite', 'overwrite_vars', 'custom_virtualenv',
'overwrite', 'overwrite_vars',
'timeout', 'verbosity', 'update_on_launch', 'update_cache_timeout',
'update_on_project_update', 'enabled_var', 'enabled_value', 'host_filter',
)
Expand Down
8 changes: 1 addition & 7 deletions awx_collection/plugins/modules/tower_job_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,6 @@
description:
- Maximum time in seconds to wait for a job to finish (server-side).
type: int
custom_virtualenv:
description:
- Local absolute file path containing a custom Python virtualenv to use.
type: str
job_slice_count:
description:
- The number of jobs to slice into at runtime. Will cause the Job Template to launch a workflow if value is greater than 1.
Expand Down Expand Up @@ -304,7 +300,6 @@
tower_config_file: "~/tower_cli.cfg"
survey_enabled: yes
survey_spec: "{{ lookup('file', 'my_survey.json') }}"
custom_virtualenv: "/var/lib/awx/venv/custom-venv/"
- name: Add start notification to Job Template
tower_job_template:
Expand Down Expand Up @@ -352,7 +347,6 @@ def main():
playbook=dict(),
credential=dict(),
vault_credential=dict(),
custom_virtualenv=dict(),
credentials=dict(type='list', elements='str'),
execution_environment=dict(),
forks=dict(type='int'),
Expand Down Expand Up @@ -442,7 +436,7 @@ def main():
'host_config_key', 'ask_scm_branch_on_launch', 'ask_diff_mode_on_launch', 'ask_variables_on_launch',
'ask_limit_on_launch', 'ask_tags_on_launch', 'ask_skip_tags_on_launch', 'ask_job_type_on_launch',
'ask_verbosity_on_launch', 'ask_inventory_on_launch', 'ask_credential_on_launch', 'survey_enabled',
'become_enabled', 'diff_mode', 'allow_simultaneous', 'custom_virtualenv', 'job_slice_count', 'webhook_service',
'become_enabled', 'diff_mode', 'allow_simultaneous', 'job_slice_count', 'webhook_service',
):
field_val = module.params.get(field_name)
if field_val is not None:
Expand Down
10 changes: 0 additions & 10 deletions awx_collection/plugins/modules/tower_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
description:
- The description to use for the organization.
type: str
custom_virtualenv:
description:
- Local absolute file path containing a custom Python virtualenv to use.
type: str
default: ''
default_environment:
description:
- Default Execution Environment to use for jobs owned by the Organization.
Expand Down Expand Up @@ -92,7 +87,6 @@
tower_organization:
name: "Foo"
description: "Foo bar organization using foo-venv"
custom_virtualenv: "/var/lib/awx/venv/foo-venv/"
state: present
tower_config_file: "~/tower_cli.cfg"
Expand All @@ -113,7 +107,6 @@ def main():
argument_spec = dict(
name=dict(required=True),
description=dict(),
custom_virtualenv=dict(),
default_environment=dict(),
max_hosts=dict(type='int', default="0"),
notification_templates_started=dict(type="list", elements='str'),
Expand All @@ -130,7 +123,6 @@ def main():
# Extract our parameters
name = module.params.get('name')
description = module.params.get('description')
custom_virtualenv = module.params.get('custom_virtualenv')
default_ee = module.params.get('default_environment')
max_hosts = module.params.get('max_hosts')
# instance_group_names = module.params.get('instance_groups')
Expand Down Expand Up @@ -179,8 +171,6 @@ def main():
org_fields = {'name': module.get_item_name(organization) if organization else name}
if description is not None:
org_fields['description'] = description
if custom_virtualenv is not None:
org_fields['custom_virtualenv'] = custom_virtualenv
if default_ee is not None:
org_fields['default_environment'] = module.resolve_name_to_id('execution_environments', default_ee)
if max_hosts is not None:
Expand Down
9 changes: 0 additions & 9 deletions awx_collection/plugins/modules/tower_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@
type: int
aliases:
- job_timeout
custom_virtualenv:
description:
- Local absolute file path containing a custom Python virtualenv to use
type: str
default: ''
default_environment:
description:
- Default Execution Environment to use for jobs relating to the project.
Expand Down Expand Up @@ -172,7 +167,6 @@
organization: "test"
scm_update_on_launch: True
scm_update_cache_timeout: 60
custom_virtualenv: "/var/lib/awx/var/lib/awx/venv/ansible-2.2"
state: present
tower_config_file: "~/tower_cli.cfg"
'''
Expand Down Expand Up @@ -242,7 +236,6 @@ def main():
scm_update_cache_timeout=dict(type='int', default=0),
allow_override=dict(type='bool', aliases=['scm_allow_override']),
timeout=dict(type='int', default=0, aliases=['job_timeout']),
custom_virtualenv=dict(),
default_environment=dict(),
organization=dict(),
notification_templates_started=dict(type="list", elements='str'),
Expand Down Expand Up @@ -274,7 +267,6 @@ def main():
scm_update_cache_timeout = module.params.get('scm_update_cache_timeout')
allow_override = module.params.get('allow_override')
timeout = module.params.get('timeout')
custom_virtualenv = module.params.get('custom_virtualenv')
default_ee = module.params.get('default_environment')
organization = module.params.get('organization')
state = module.params.get('state')
Expand Down Expand Up @@ -333,7 +325,6 @@ def main():
'organization': org_id,
'scm_update_on_launch': scm_update_on_launch,
'scm_update_cache_timeout': scm_update_cache_timeout,
'custom_virtualenv': custom_virtualenv,
}
if description is not None:
project_fields['description'] = description
Expand Down
55 changes: 0 additions & 55 deletions awx_collection/test/awx/test_inventory_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,61 +97,6 @@ def test_create_inventory_source_multiple_orgs(run_module, admin_user):
}


@pytest.mark.django_db
def test_create_inventory_source_with_venv(run_module, admin_user, base_inventory, mocker, project):
path = '/var/lib/awx/venv/custom-venv/foobar13489435/'
source_path = '/var/lib/awx/example_source_path/'
with mocker.patch('awx.main.models.mixins.get_custom_venv_choices', return_value=[path]):
result = run_module('tower_inventory_source', dict(
name='foo',
inventory=base_inventory.name,
state='present',
source='scm',
source_project=project.name,
custom_virtualenv=path,
source_path=source_path
), admin_user)
assert result.pop('changed'), result

inv_src = InventorySource.objects.get(name='foo')
assert inv_src.inventory == base_inventory
result.pop('invocation')

assert inv_src.custom_virtualenv == path


@pytest.mark.django_db
def test_custom_venv_no_op(run_module, admin_user, base_inventory, mocker, project):
"""If the inventory source is modified, then it should not blank fields
unrelated to the params that the user passed.
This enforces assumptions about the behavior of the AnsibleModule
default argument_spec behavior.
"""
source_path = '/var/lib/awx/example_source_path/'
inv_src = InventorySource.objects.create(
name='foo',
inventory=base_inventory,
source_project=project,
source='scm',
custom_virtualenv='/var/lib/awx/venv/foobar/'
)
# mock needed due to API behavior, not incorrect client behavior
with mocker.patch('awx.main.models.mixins.get_custom_venv_choices', return_value=['/var/lib/awx/venv/foobar/']):
result = run_module('tower_inventory_source', dict(
name='foo',
description='this is the changed description',
inventory=base_inventory.name,
source='scm', # is required, but behavior is arguable
state='present',
source_project=project.name,
source_path=source_path
), admin_user)
assert result.pop('changed', None), result
inv_src.refresh_from_db()
assert inv_src.custom_virtualenv == '/var/lib/awx/venv/foobar/'
assert inv_src.description == 'this is the changed description'


@pytest.mark.django_db
def test_falsy_value(run_module, admin_user, base_inventory):
result = run_module('tower_inventory_source', dict(
Expand Down
Loading

0 comments on commit b2a4340

Please sign in to comment.