Esempio n. 1
0
    def test_devicename_exists(self):
        """Testing function devicename_exists."""
        # Test known working value
        result = db_device.devicename_exists(self.expected['devicename'])
        self.assertEqual(result, True)

        # Test known false value
        result = db_device.devicename_exists(False)
        self.assertEqual(result, False)
Esempio n. 2
0
    def valid(self):
        """Check if data keys are OK.

        Args:
            None

        Returns:
            valid: True if valid

        """
        # Initialize key variables
        valid = True

        # Return if instantiation tests have failed
        if self._valid is False:
            valid = False
            return valid

        # Assign other values
        timestamp = int(self.data['timestamp'])
        id_agent = self.data['id_agent']
        devicename = self.data['devicename']

        # Check if there is a duplicate entry for this id_agent
        if db_agent.id_agent_exists(id_agent) is not False:
            idx_agent = db_agent.GetIDAgent(id_agent).idx_agent()

            # Check if device exists
            if db_device.devicename_exists(devicename) is True:
                idx_device = db_device.GetDevice(devicename).idx_device()

                # Check for device / agent entry existence
                if db_deviceagent.device_agent_exists(
                        idx_device, idx_agent) is True:
                    # Check if this device / agent has been updated before
                    last_timesamp = db_deviceagent.GetDeviceAgent(
                        idx_device, idx_agent).last_timestamp()

                    # Validate
                    if timestamp <= last_timesamp:
                        log_message = (
                            'Data for id_agent %s, devicename %s '
                            'at timestamp %s '
                            'is already found in database.'
                            '') % (id_agent, devicename, timestamp)
                        log.log2warning(1113, log_message)
                        valid = False

        # Return
        return valid