mirror of
https://github.com/ansible/awx.git
synced 2026-05-17 14:27:42 -02:30
check for open license
This commit is contained in:
@@ -12,6 +12,7 @@ from django.utils.encoding import smart_str
|
|||||||
from django.utils.timezone import now, timedelta
|
from django.utils.timezone import now, timedelta
|
||||||
from rest_framework.exceptions import PermissionDenied
|
from rest_framework.exceptions import PermissionDenied
|
||||||
|
|
||||||
|
from awx.conf.license import get_license
|
||||||
from awx.main.models import Job
|
from awx.main.models import Job
|
||||||
from awx.main.access import access_registry
|
from awx.main.access import access_registry
|
||||||
from awx.main.models.ha import TowerAnalyticsState
|
from awx.main.models.ha import TowerAnalyticsState
|
||||||
@@ -25,6 +26,8 @@ logger = logging.getLogger('awx.main.analytics')
|
|||||||
|
|
||||||
def _valid_license():
|
def _valid_license():
|
||||||
try:
|
try:
|
||||||
|
if get_license(show_key=False)['license_type'] == 'open':
|
||||||
|
return False
|
||||||
access_registry[Job](None).check_license()
|
access_registry[Job](None).check_license()
|
||||||
except PermissionDenied:
|
except PermissionDenied:
|
||||||
logger.exception("A valid license was not found:")
|
logger.exception("A valid license was not found:")
|
||||||
@@ -73,8 +76,8 @@ def gather(dest=None, module=None):
|
|||||||
|
|
||||||
if _valid_license() is False:
|
if _valid_license() is False:
|
||||||
logger.exception("Invalid License provided, or No License Provided")
|
logger.exception("Invalid License provided, or No License Provided")
|
||||||
return
|
return "Error: Invalid License provided, or No License Provided"
|
||||||
|
|
||||||
if not settings.INSIGHTS_DATA_ENABLED:
|
if not settings.INSIGHTS_DATA_ENABLED:
|
||||||
logger.error("Insights analytics not enabled")
|
logger.error("Insights analytics not enabled")
|
||||||
return "Error: Insights analytics not enabled"
|
return "Error: Insights analytics not enabled"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import importlib
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import tarfile
|
import tarfile
|
||||||
|
from unittest import mock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -22,11 +22,23 @@ def bad_json(since):
|
|||||||
@register('throws_error')
|
@register('throws_error')
|
||||||
def throws_error(since):
|
def throws_error(since):
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
|
|
||||||
|
|
||||||
|
def _valid_license():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_valid_license():
|
||||||
|
with mock.patch('awx.main.analytics.core._valid_license') as license:
|
||||||
|
license.return_value = True
|
||||||
|
yield license
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_gather():
|
def test_gather(mock_valid_license):
|
||||||
settings.INSIGHTS_DATA_ENABLED = True
|
settings.INSIGHTS_DATA_ENABLED = True
|
||||||
|
|
||||||
tgz = gather(module=importlib.import_module(__name__))
|
tgz = gather(module=importlib.import_module(__name__))
|
||||||
files = {}
|
files = {}
|
||||||
with tarfile.open(tgz, "r:gz") as archive:
|
with tarfile.open(tgz, "r:gz") as archive:
|
||||||
|
|||||||
Reference in New Issue
Block a user