예제 #1
0
파일: system.py 프로젝트: mahak/awx
def gather_analytics():
    from awx.conf.models import Setting
    from rest_framework.fields import DateTimeField

    last_gather = Setting.objects.filter(key='AUTOMATION_ANALYTICS_LAST_GATHER').first()
    last_time = DateTimeField().to_internal_value(last_gather.value) if last_gather and last_gather.value else None
    gather_time = now()

    if not last_time or ((gather_time - last_time).total_seconds() > settings.AUTOMATION_ANALYTICS_GATHER_INTERVAL):
        analytics.gather()
예제 #2
0
    def handle(self, *args, **options):
        self.init_logging()
        opt_ship = options.get('ship')
        opt_dry_run = options.get('dry-run')
        opt_since = options.get('since') or None
        opt_until = options.get('until') or None

        if opt_since:
            since = parser.parse(opt_since)
        else:
            since = None
        if opt_until:
            until = parser.parse(opt_until)
        else:
            until = now()

        if opt_ship and opt_dry_run:
            self.logger.error(
                'Both --ship and --dry-run cannot be processed at the same time.'
            )
            return
        tgzfiles = gather(
            collection_type='manual' if not opt_dry_run else 'dry-run',
            since=since,
            until=until)
        if tgzfiles:
            for tgz in tgzfiles:
                self.logger.debug(tgz)
        else:
            self.logger.error('No analytics collected')
        if opt_ship:
            if tgzfiles:
                for tgz in tgzfiles:
                    ship(tgz)
예제 #3
0
 def handle(self, *args, **options):
     tgz = gather()
     self.init_logging()
     if not tgz:
         self.logger.debug(tgz)
     if options.get('ship'):
         ship(tgz)
    def handle(self, *args, **options):
        self.init_logging()
        opt_ship = options.get('ship')
        opt_dry_run = options.get('dry-run')
        opt_since = options.get('since') or None
        opt_until = options.get('until') or None

        since = parser.parse(opt_since) if opt_since else None
        if since and since.tzinfo is None:
            since = since.replace(tzinfo=timezone.utc)
        until = parser.parse(opt_until) if opt_until else None
        if until and until.tzinfo is None:
            until = until.replace(tzinfo=timezone.utc)

        if opt_ship and opt_dry_run:
            self.logger.error(
                'Both --ship and --dry-run cannot be processed at the same time.'
            )
            return
        tgzfiles = analytics.gather(
            collection_type='manual' if opt_ship else 'dry-run',
            since=since,
            until=until)
        if tgzfiles:
            for tgz in tgzfiles:
                self.logger.info(tgz)
        else:
            self.logger.error('No analytics collected')
예제 #5
0
 def handle(self, *args, **options):
     tgz = gather(collection_type='manual')
     self.init_logging()
     if tgz:
         self.logger.debug(tgz)
     if options.get('ship'):
         ship(tgz)
예제 #6
0
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:
        for member in archive.getmembers():
            files[member.name] = archive.extractfile(member)

        # functions that returned valid JSON should show up
        assert './example.json' in files.keys()
        assert json.loads(files['./example.json'].read()) == {'awx': 123}

        # functions that don't return serializable objects should not
        assert './bad_json.json' not in files.keys()
        assert './throws_error.json' not in files.keys()
    try:
        os.remove(tgz)
    except Exception:
        pass