Beispiel #1
0
def _create_report_slices(report, insights_hosts):
    """Process facts and convert to fingerprints.

    :param report: DeploymentReport used to create slices
    :param insights_hosts: insights host JSON objects
    :returns: list containing report meta-data and report slices
    """
    # pylint: disable=too-many-locals
    slice_size_limit = settings.QPC_INSIGHTS_REPORT_SLICE_SIZE
    number_hosts = len(insights_hosts)

    if number_hosts % slice_size_limit:
        number_of_slices = number_hosts // slice_size_limit + 1
        hosts_per_slice = number_hosts // number_of_slices + 1
    else:
        number_of_slices = number_hosts // slice_size_limit
        hosts_per_slice = number_hosts // number_of_slices

    insights_report_pieces = {}
    metadata_report_slices = {}
    source_metadata = {
        'report_platform_id': str(report.report_platform_id),
        'report_type': 'insights',
        'report_version': report.report_version,
        'qpc_server_report_id': report.id,
        'qpc_server_version': server_version(),
        'qpc_server_id': ServerInformation.create_or_retreive_server_id()
    }
    metadata = {
        'report_id': str(report.report_platform_id),
        'host_inventory_api_version': '1.0',
        'source': 'qpc',
        'source_metadata': source_metadata,
        'report_slices': metadata_report_slices
    }
    insights_report_pieces[create_filename('metadata', 'json',
                                           report.id)] = metadata
    list_slice_start = 0
    list_slice_end = hosts_per_slice
    for i in range(0, number_hosts, hosts_per_slice):
        hosts = []
        hosts = insights_hosts[list_slice_start:list_slice_end]

        report_slice_id = str(uuid.uuid4())
        report_slice_filename = create_filename(report_slice_id, 'json',
                                                report.id)
        metadata_report_slices[report_slice_id] = {'number_hosts': len(hosts)}
        report_slice = {'report_slice_id': report_slice_id, 'hosts': hosts}
        insights_report_pieces[report_slice_filename] = report_slice
        list_slice_start = list_slice_end
        if list_slice_end + hosts_per_slice < number_hosts:
            list_slice_end = hosts_per_slice * (i + 2)
        else:
            list_slice_end = number_hosts
    return Response(insights_report_pieces)
Beispiel #2
0
 def setUp(self):
     """Create test case setup."""
     self.server_id = ServerInformation.create_or_retreive_server_id()
     self.source = Source(name='source1',
                          hosts=json.dumps(['1.2.3.4']),
                          source_type='network',
                          port=22)
     self.source.save()
     scan_job, _ = create_scan_job(self.source)
     self.fp_task = scan_job.tasks.last()  # pylint: disable=no-member
     self.fp_task_runner = FingerprintTaskRunner(scan_job, self.fp_task)
Beispiel #3
0
    def setUp(self):
        """Create test case setup."""
        self.net_source = Source.objects.create(
            name='test_source', source_type=Source.NETWORK_SOURCE_TYPE)

        self.net_cred = Credential.objects.create(
            name='net_cred1',
            cred_type=Credential.NETWORK_CRED_TYPE,
            username='******',
            password='******',
            become_password=None,
            ssh_keyfile=None)
        self.net_source.credentials.add(self.net_cred)

        self.net_source.hosts = '["1.2.3.4"]'
        self.net_source.save()
        self.server_id = ServerInformation.create_or_retreive_server_id()
Beispiel #4
0
    def setUp(self):
        """Create test case setup."""
        management.call_command('flush', '--no-input')
        self.net_source = Source.objects.create(
            name='test_source', source_type=Source.NETWORK_SOURCE_TYPE)

        self.net_cred = Credential.objects.create(
            name='net_cred1',
            cred_type=Credential.NETWORK_CRED_TYPE,
            username='******',
            password='******',
            become_password=None,
            ssh_keyfile=None)
        self.net_source.credentials.add(self.net_cred)

        self.net_source.hosts = '["1.2.3.4"]'
        self.net_source.save()
        self.server_id = ServerInformation.create_or_retreive_server_id()
        self.report_version = create_report_version()
        self.details_json = None
        self.deployments_json = None
Beispiel #5
0
def build_sources_from_tasks(tasks):
    """Build sources for a set of tasks.

    :param tasks: ScanTask objects used to build results
    :returns: dict containing sources structure for facts endpoint
    """
    server_id = ServerInformation.create_or_retreive_server_id()
    sources = []
    for inspect_task in tasks:
        if inspect_task.scan_type != ScanTask.SCAN_TYPE_INSPECT:
            continue
        task_facts = inspect_task.get_facts()
        if task_facts:
            source = inspect_task.source
            if source is not None:
                source_dict = {
                    SERVER_ID_KEY: server_id,
                    SOURCE_NAME_KEY: source.name,
                    SOURCE_TYPE_KEY: source.source_type,
                    FACTS_KEY: task_facts
                }
                sources.append(source_dict)
    return sources
Beispiel #6
0
 def setUp(self):
     """Create test case setup."""
     self.server_id = ServerInformation.create_or_retreive_server_id()