Beispiel #1
0
 def test_cpu_core_count_missing(self):
     """Test missing connection_port."""
     engine = Engine()
     fact_collection = self._create_json_fc(cpu_core_count=None)
     fact = fact_collection['facts'][0]
     fingerprint = engine.process_fact(fact_collection['id'], fact)
     self.assertNotIn('cpu_core_count', fingerprint)
Beispiel #2
0
 def test_virt_num_running_guests_missing(self):
     """Test missing virt_num_running_guests."""
     engine = Engine()
     fact_collection = self._create_json_fc(virt_num_running_guests=None)
     fact = fact_collection['facts'][0]
     fingerprint = engine.process_fact(fact_collection['id'], fact)
     self.assertNotIn('virtualization_num_running_guests', fingerprint)
Beispiel #3
0
 def test_os_release_missing(self):
     """Test missing etc_release_release."""
     engine = Engine()
     fact_collection = self._create_json_fc(etc_release_release=None)
     fact = fact_collection['facts'][0]
     fingerprint = engine.process_fact(fact_collection['id'], fact)
     self.assertNotIn('os_release', fingerprint)
Beispiel #4
0
 def test_cpu_hyperthreading_missing(self):
     """Test missing cpu_hyperthreading."""
     engine = Engine()
     fact_collection = self._create_json_fc(cpu_hyperthreading=None)
     fact = fact_collection['facts'][0]
     fingerprint = engine.process_fact(fact_collection['id'], fact)
     self.assertNotIn('cpu_hyperthreading', fingerprint)
Beispiel #5
0
 def test_infrastructure_baremetal(self):
     """Test virt_what_type set to bare metal."""
     engine = Engine()
     fact_collection = self._create_json_fc(virt_what_type='bare metal')
     fact = fact_collection['facts'][0]
     fingerprint = engine.process_fact(fact_collection['id'], fact)
     self.assertEqual('bare_metal', fingerprint['infrastructure_type'])
Beispiel #6
0
 def test_basic_engine_process_fact(self):
     """Test basic engine process_fact."""
     engine = Engine()
     fact_collection = self._create_json_fc()
     fact = fact_collection['facts'][0]
     fingerprint = engine.process_fact(fact_collection['id'], fact)
     self.validate_result(fact_collection['id'], fingerprint, fact)
Beispiel #7
0
 def test_infrastructure_missing(self):
     """Test missing virt_what_type and virt_type yields unknown type."""
     engine = Engine()
     fact_collection = self._create_json_fc(virt_what_type=None,
                                            virt_type=None)
     fact = fact_collection['facts'][0]
     fingerprint = engine.process_fact(fact_collection['id'], fact)
     self.assertEqual('unknown', fingerprint['infrastructure_type'])
Beispiel #8
0
 def test_create_yum(self):
     """Test date_yum_history used for sys create time."""
     engine = Engine()
     fact_collection = self._create_json_fc(date_yum_history='2015-07-18')
     fact = fact_collection['facts'][0]
     fingerprint = engine.process_fact(fact_collection['id'], fact)
     fact_date = datetime.strptime(fact['date_yum_history'], '%Y-%m-%d')
     fact_date = fact_date.date()
     self.assertEqual(fact_date, fingerprint['system_creation_date'])
Beispiel #9
0
    def test_infrastructure_unknown(self):
        """Test virt_what_type not bear metal.

        virt_type None yields unknown infrastructure type
        """
        engine = Engine()
        fact_collection = self._create_json_fc(virt_what_type='foobar',
                                               virt_type=None)
        fact = fact_collection['facts'][0]
        fingerprint = engine.process_fact(fact_collection['id'], fact)
        self.assertEqual('unknown', fingerprint['infrastructure_type'])
Beispiel #10
0
# version 3 (GPLv3). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv3
# along with this software; if not, see
# https://www.gnu.org/licenses/gpl-3.0.txt.
#
"""Models to capture system facts."""

import logging
from django.db.models.signals import post_save
from django.dispatch import receiver
from fingerprinter import Engine
from api.serializers import FingerprintSerializer, FactCollectionSerializer
from api.models import FactCollection

ENGINE = Engine()
logger = logging.getLogger(__name__)  # pylint: disable=invalid-name


@receiver(post_save, sender=FactCollection)
def process_fact_collection(sender, instance, **kwargs):
    """Process facts using engine and convert to fingerprints.

    :param sender: Class that was saved
    :param instance: FactCollection that was saved
    :param kwargs: Other args
    :returns: None
    """
    # pylint: disable=unused-argument

    # Convert to python dictionary