1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 15:21:13 +03:00

check for open license

This commit is contained in:
Christian Adams 2019-03-26 13:51:36 -04:00
parent 58f0e42bd6
commit c481919a49
2 changed files with 19 additions and 4 deletions

View File

@ -12,6 +12,7 @@ from django.utils.encoding import smart_str
from django.utils.timezone import now, timedelta
from rest_framework.exceptions import PermissionDenied
from awx.conf.license import get_license
from awx.main.models import Job
from awx.main.access import access_registry
from awx.main.models.ha import TowerAnalyticsState
@ -25,6 +26,8 @@ logger = logging.getLogger('awx.main.analytics')
def _valid_license():
try:
if get_license(show_key=False)['license_type'] == 'open':
return False
access_registry[Job](None).check_license()
except PermissionDenied:
logger.exception("A valid license was not found:")
@ -73,8 +76,8 @@ def gather(dest=None, module=None):
if _valid_license() is False:
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:
logger.error("Insights analytics not enabled")
return "Error: Insights analytics not enabled"

View File

@ -2,7 +2,7 @@ import importlib
import json
import os
import tarfile
from unittest import mock
import pytest
from django.conf import settings
@ -22,11 +22,23 @@ def bad_json(since):
@register('throws_error')
def throws_error(since):
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
def test_gather():
def test_gather(mock_valid_license):
settings.INSIGHTS_DATA_ENABLED = True
tgz = gather(module=importlib.import_module(__name__))
files = {}
with tarfile.open(tgz, "r:gz") as archive: