mirror of
https://github.com/ansible/awx.git
synced 2026-05-14 21:07:39 -02:30
Test for HA license before allowing cluster job start
This commit is contained in:
@@ -1044,6 +1044,8 @@ class JobTemplateAccess(BaseAccess):
|
|||||||
self.check_license(feature='system_tracking')
|
self.check_license(feature='system_tracking')
|
||||||
if obj.survey_enabled:
|
if obj.survey_enabled:
|
||||||
self.check_license(feature='surveys')
|
self.check_license(feature='surveys')
|
||||||
|
if Instance.objects.active_count() > 1:
|
||||||
|
self.check_license(feature='ha')
|
||||||
|
|
||||||
# Super users can start any job
|
# Super users can start any job
|
||||||
if self.user.is_superuser:
|
if self.user.is_superuser:
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ class InstanceManager(models.Manager):
|
|||||||
return node[0]
|
return node[0]
|
||||||
raise RuntimeError("No instance found with the current cluster host id")
|
raise RuntimeError("No instance found with the current cluster host id")
|
||||||
|
|
||||||
|
def active_count(self):
|
||||||
|
"""Return count of active Tower nodes for licensing."""
|
||||||
|
return self.all().count()
|
||||||
|
|
||||||
def my_role(self):
|
def my_role(self):
|
||||||
# NOTE: TODO: Likely to repurpose this once standalone ramparts are a thing
|
# NOTE: TODO: Likely to repurpose this once standalone ramparts are a thing
|
||||||
return "tower"
|
return "tower"
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ from awx.main.access import (
|
|||||||
JobTemplateAccess,
|
JobTemplateAccess,
|
||||||
WorkflowJobTemplateAccess,
|
WorkflowJobTemplateAccess,
|
||||||
)
|
)
|
||||||
from awx.main.models import Credential, Inventory, Project, Role, Organization
|
from awx.conf.license import LicenseForbids
|
||||||
|
from awx.main.models import Credential, Inventory, Project, Role, Organization, Instance
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@@ -106,6 +107,18 @@ def test_jt_add_scan_job_check(job_template_with_ids, user_unit):
|
|||||||
'job_type': 'scan'
|
'job_type': 'scan'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def mock_raise_license_forbids(self, add_host=False, feature=None, check_expiration=True):
|
||||||
|
raise LicenseForbids("Feature not enabled")
|
||||||
|
|
||||||
|
def mock_raise_none(self, add_host=False, feature=None, check_expiration=True):
|
||||||
|
return None
|
||||||
|
|
||||||
|
def test_jt_can_start_ha(job_template_with_ids):
|
||||||
|
with mock.patch.object(Instance.objects, 'active_count', return_value=2):
|
||||||
|
with mock.patch('awx.main.access.BaseAccess.check_license', new=mock_raise_license_forbids):
|
||||||
|
with pytest.raises(LicenseForbids):
|
||||||
|
JobTemplateAccess(user_unit).can_start(job_template_with_ids)
|
||||||
|
|
||||||
def test_jt_can_add_bad_data(user_unit):
|
def test_jt_can_add_bad_data(user_unit):
|
||||||
"Assure that no server errors are returned if we call JT can_add with bad data"
|
"Assure that no server errors are returned if we call JT can_add with bad data"
|
||||||
access = JobTemplateAccess(user_unit)
|
access = JobTemplateAccess(user_unit)
|
||||||
|
|||||||
Reference in New Issue
Block a user