From 2e6c484a500b75c8bb46404ba6bdf7ef937fdca8 Mon Sep 17 00:00:00 2001 From: Rebeccah Date: Tue, 29 Oct 2019 18:23:03 -0400 Subject: [PATCH 1/2] added in testing for updating(or not allowing updates of) policy_instance variables in instance and container groups --- .../functional/api/test_instance_group.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/awx/main/tests/functional/api/test_instance_group.py b/awx/main/tests/functional/api/test_instance_group.py index 381e6b349e..64567f4285 100644 --- a/awx/main/tests/functional/api/test_instance_group.py +++ b/awx/main/tests/functional/api/test_instance_group.py @@ -45,6 +45,14 @@ def isolated_instance_group(instance_group, instance): return ig +@pytest.fixture +def containerized_instance_group(instance_group, kube_credential): + ig = InstanceGroup(name="container") + ig.credential = kube_credential + ig.save() + return ig + + @pytest.fixture def create_job_factory(job_factory, instance_group): def fn(status='running'): @@ -240,3 +248,29 @@ def test_instance_group_order_persistence(get, post, admin, source_model): resp = get(url, admin) assert resp.data['count'] == total assert [ig['name'] for ig in resp.data['results']] == [ig.name for ig in before] + + +@pytest.mark.django_db +def test_instance_group_update_fields(patch, instance, instance_group, admin, containerized_instance_group): + # policy_instance_ variables can only be updated in instance groups that are NOT containerized + # instance group (not containerized) + ig_url = reverse("api:instance_group_detail", kwargs={'pk': instance_group.pk}) + assert not instance_group.is_containerized + assert not containerized_instance_group.is_isolated + resp = patch(ig_url, {'policy_instance_percentage':15}, admin, expect=200) + assert 15 == resp.data['policy_instance_percentage'] + resp = patch(ig_url, {'policy_instance_minimum':15}, admin, expect=200) + assert 15 == resp.data['policy_instance_minimum'] + resp = patch(ig_url, {'policy_instance_list':[instance.hostname]}, admin) + assert [instance.hostname] == resp.data['policy_instance_list'] + + # containerized instance group + cg_url = reverse("api:instance_group_detail", kwargs={'pk': containerized_instance_group.pk}) + assert containerized_instance_group.is_containerized + assert not containerized_instance_group.is_isolated + resp = patch(cg_url, {'policy_instance_percentage':15}, admin, expect=400) + assert [u"Containerized instances may not be managed via the API"] == resp.data['policy_instance_percentage'] + resp = patch(cg_url, {'policy_instance_minimum':15}, admin, expect=400) + assert [u"Containerized instances may not be managed via the API"] == resp.data['policy_instance_minimum'] + resp = patch(cg_url, {'policy_instance_list':[instance.hostname]}, admin) + assert [u"Containerized instances may not be managed via the API"] == resp.data['policy_instance_list'] From e4a21b67c733ebbc1b56ed04ae1a3161e5b22cd1 Mon Sep 17 00:00:00 2001 From: Rebeccah Date: Wed, 30 Oct 2019 09:46:51 -0400 Subject: [PATCH 2/2] remove u markers in assertion statements, they are unnecessary in python3 --- awx/main/tests/functional/api/test_instance_group.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/awx/main/tests/functional/api/test_instance_group.py b/awx/main/tests/functional/api/test_instance_group.py index 64567f4285..7d0417124d 100644 --- a/awx/main/tests/functional/api/test_instance_group.py +++ b/awx/main/tests/functional/api/test_instance_group.py @@ -269,8 +269,8 @@ def test_instance_group_update_fields(patch, instance, instance_group, admin, co assert containerized_instance_group.is_containerized assert not containerized_instance_group.is_isolated resp = patch(cg_url, {'policy_instance_percentage':15}, admin, expect=400) - assert [u"Containerized instances may not be managed via the API"] == resp.data['policy_instance_percentage'] + assert ["Containerized instances may not be managed via the API"] == resp.data['policy_instance_percentage'] resp = patch(cg_url, {'policy_instance_minimum':15}, admin, expect=400) - assert [u"Containerized instances may not be managed via the API"] == resp.data['policy_instance_minimum'] + assert ["Containerized instances may not be managed via the API"] == resp.data['policy_instance_minimum'] resp = patch(cg_url, {'policy_instance_list':[instance.hostname]}, admin) - assert [u"Containerized instances may not be managed via the API"] == resp.data['policy_instance_list'] + assert ["Containerized instances may not be managed via the API"] == resp.data['policy_instance_list']