Ejemplo n.º 1
0
    def test_assign(self):
        """Testing method / function assign."""
        # Add an entry to the database
        name = data.hashstring(str(random()))
        pair_xlate_group.insert_row(name)

        # Make sure it exists
        idx_pair_xlate_group = pair_xlate_group.exists(name)

        # Verify the index exists
        result = pair_xlate_group.idx_exists(idx_pair_xlate_group)
        self.assertTrue(result)

        # Prepare for adding an entry to the database
        agent_id = data.hashstring(str(random()))
        agent_target = data.hashstring(str(random()))
        agent_program = data.hashstring(str(random()))

        # Make sure it does not exist
        result = agent.exists(agent_id, agent_target)
        self.assertFalse(bool(result))

        # Add an entry to the database
        agent.insert_row(agent_id, agent_target, agent_program)
        idx_agent = agent.exists(agent_id, agent_target)

        # Assign
        agent.assign(idx_agent, idx_pair_xlate_group)

        # Get assigned idx_pair_xlate_group for the agent group
        with db.db_query(20099) as session:
            result = session.query(Agent.idx_pair_xlate_group).filter(
                Agent.idx_agent == idx_agent).one()
        idx_new = result.idx_pair_xlate_group
        self.assertEqual(idx_pair_xlate_group, idx_new)
Ejemplo n.º 2
0
def _idx_datapoint():
    """Create a new DataPoint db entry.

    Args:
        value: Value to convert

    Returns:
        result: idx_datapoint value for new DataPoint

    """
    # Initialize key variables
    polling_interval = 1

    # Create a new Agent entry
    agent_id = data.hashstring(str(random()))
    agent_target = data.hashstring(str(random()))
    agent_program = data.hashstring(str(random()))
    agent.insert_row(agent_id, agent_target, agent_program)
    idx_agent = agent.exists(agent_id, agent_target)

    # Create entry and check
    _checksum = data.hashstring(str(random()))
    result = datapoint.checksum_exists(_checksum)
    datapoint.insert_row(_checksum, DATA_FLOAT, polling_interval, idx_agent)
    result = datapoint.checksum_exists(_checksum)
    return result
Ejemplo n.º 3
0
    def test_insert_rows(self):
        """Testing method / function insert_rows."""
        # Initialize key variables
        polling_interval = 1
        checksum = data.hashstring(str(random()))
        key = data.hashstring(str(random()))
        value = data.hashstring(str(random()))

        # Create a new Agent entry
        agent_id = data.hashstring(str(random()))
        agent_target = data.hashstring(str(random()))
        agent_program = data.hashstring(str(random()))
        agent.insert_row(agent_id, agent_target, agent_program)
        idx_agent = agent.exists(agent_id, agent_target)

        # Insert values in tables
        pair.insert_rows((key, value))
        idx_pair = pair.pair_exists(key, value)
        datapoint.insert_row(checksum, DATA_FLOAT, polling_interval, idx_agent)
        idx_datapoint = datapoint.checksum_exists(checksum)

        # Create entry and check
        result = glue.glue_exists(idx_datapoint, idx_pair)
        self.assertFalse(result)
        glue.insert_rows(idx_datapoint, idx_pair)
        result = glue.glue_exists(idx_datapoint, idx_pair)
        self.assertTrue(bool(result))
        self.assertTrue(isinstance(result, int))
Ejemplo n.º 4
0
    def test_idx_pairs(self):
        """Testing method / function idx_pairs."""
        # Initialize key variables
        checksum = data.hashstring(str(random()))
        polling_interval = 1
        keypairs = []
        idx_pairs = []
        for _ in range(0, 10):
            time.sleep(0.05)
            key = data.hashstring(str(random()))
            value = data.hashstring(str(random()))
            keypairs.append((key, value))

        # Create a new Agent entry
        agent_id = data.hashstring(str(random()))
        agent_target = data.hashstring(str(random()))
        agent_program = data.hashstring(str(random()))
        agent.insert_row(agent_id, agent_target, agent_program)
        idx_agent = agent.exists(agent_id, agent_target)

        # Insert values in tables
        pair.insert_rows(keypairs)
        datapoint.insert_row(checksum, DATA_FLOAT, polling_interval, idx_agent)
        idx_datapoint = datapoint.checksum_exists(checksum)

        # Test
        for key, value in keypairs:
            idx_pairs.append(pair.pair_exists(key, value))
        glue.insert_rows(idx_datapoint, idx_pairs)

        result = glue.idx_pairs(idx_datapoint)
        self.assertEqual(len(result), len(idx_pairs))
        for idx_pair in idx_pairs:
            self.assertTrue(idx_pair in result)
Ejemplo n.º 5
0
    def test_chart_timestamp_args(self):
        """Testing function chart_timestamp_args."""
        # Create a new Agent entry
        _pi = 1000
        agent_id = data.hashstring(str(random()))
        agent_target = data.hashstring(str(random()))
        agent_program = data.hashstring(str(random()))
        agent.insert_row(agent_id, agent_target, agent_program)
        idx_agent = agent.exists(agent_id, agent_target)

        # Create entry and check
        checksum = data.hashstring(str(random()))
        result = datapoint.checksum_exists(checksum)
        self.assertFalse(result)
        datapoint.insert_row(checksum, DATA_FLOAT, _pi, idx_agent)
        idx_datapoint = datapoint.checksum_exists(checksum)

        # Test
        values = [False, None]
        for value in values:
            now = normalized_timestamp(_pi, int(time.time() * 1000))
            result = uri.chart_timestamp_args(idx_datapoint, value)
            self.assertEqual(result + 604800000, now)

        values = [-1, -6011, 1, 6011]
        for value in values:
            now = normalized_timestamp(_pi, int(time.time() * 1000))
            result = uri.chart_timestamp_args(idx_datapoint, value)
            self.assertEqual(result + (abs(value) * 1000), now)

        values = ['foo', [None]]
        for value in values:
            now = normalized_timestamp(_pi, int(time.time() * 1000))
            result = uri.chart_timestamp_args(idx_datapoint, value)
            self.assertEqual(result + 604800000, now)
Ejemplo n.º 6
0
    def test_idx_pair_xlate_group(self):
        """Testing method / function idx_pair_xlate_group."""
        # Create a new PairXlateGroup entry
        translation = data.hashstring(str(random()))
        pair_xlate_group.insert_row(translation)
        idx_pair_xlate_group = pair_xlate_group.exists(translation)

        # Add an entry to the database
        translation = data.hashstring(str(random()))
        agent_group.insert_row(translation)

        # Make sure it exists
        idx_agent_group = agent_group.exists(translation)

        # Assign AgentGroup
        agent_group.assign(idx_agent_group, idx_pair_xlate_group)

        # Add an entry to the database
        agent_id = data.hashstring(str(random()))
        agent_target = data.hashstring(str(random()))
        agent_program = data.hashstring(str(random()))
        agent.insert_row(agent_id, agent_target, agent_program)
        idx_agent = agent.exists(agent_id, agent_target)

        # Assign Agent got AgentGroup
        agent.assign(idx_agent, idx_agent_group)

        # Test
        result = agent.idx_pair_xlate_group(agent_id)
        self.assertEqual(result, idx_pair_xlate_group)
Ejemplo n.º 7
0
    def test_exists(self):
        """Testing method / function exists."""
        # Create a translation
        agent_id = data.hashstring(str(random()))
        agent_target = data.hashstring(str(random()))
        agent_program = data.hashstring(str(random()))

        # Make sure it does not exist
        result = agent.exists(agent_id, agent_target)
        self.assertFalse(bool(result))

        # Add database row
        agent.insert_row(agent_id, agent_target, agent_program)

        # Make sure it exists
        result = agent.exists(agent_id, agent_target)
        self.assertTrue(bool(result))
Ejemplo n.º 8
0
    def test_insert_row(self):
        """Testing method / function insert_row."""
        # Add an entry to the database
        agent_id = data.hashstring(str(random()))
        agent_target = data.hashstring(str(random()))
        agent_program = data.hashstring(str(random()))
        agent.insert_row(agent_id, agent_target, agent_program)

        # Make sure it exists
        idx_agent = agent.exists(agent_id, agent_target)

        # Verify the index exists
        result = agent.idx_exists(idx_agent)
        self.assertTrue(result)
Ejemplo n.º 9
0
    def test_assign(self):
        """Testing method / function assign."""
        # Create a new AgentGroup entry
        translation = data.hashstring(str(random()))
        agent_group.insert_row(translation)
        idx_agent_group = agent_group.exists(translation)

        # Prepare for adding an entry to the database
        agent_id = data.hashstring(str(random()))
        agent_target = data.hashstring(str(random()))
        agent_program = data.hashstring(str(random()))

        # Make sure it does not exist
        result = agent.exists(agent_id, agent_target)
        self.assertFalse(bool(result))

        # Add an entry to the database
        agent.insert_row(agent_id, agent_target, agent_program)
        idx_agent = agent.exists(agent_id, agent_target)

        # Get current idx_agent for the agent
        with db.db_query(20001) as session:
            result = session.query(Agent.idx_agent_group).filter(
                Agent.idx_agent == idx_agent).one()
        idx_original = result.idx_agent_group
        self.assertNotEqual(idx_agent_group, idx_original)

        # Assign
        agent.assign(idx_agent, idx_agent_group)

        # Get current idx_agent_group for the agent group
        with db.db_query(20099) as session:
            result = session.query(Agent.idx_agent_group).filter(
                Agent.idx_agent == idx_agent).one()
        idx_new = result.idx_agent_group
        self.assertEqual(idx_agent_group, idx_new)
Ejemplo n.º 10
0
    def test_cli_show_dump(self):
        """Testing method / function cli_show_dump."""
        # Add an entry to the database
        agent_id = data.hashstring(str(random()))
        agent_target = data.hashstring(str(random()))
        agent_program = data.hashstring(str(random()))
        agent.insert_row(agent_id, agent_target, agent_program)

        # Make sure it exists
        idx_agent = agent.exists(agent_id, agent_target)

        result = agent.cli_show_dump()
        for item in result:
            if item.idx_agent == idx_agent:
                self.assertEqual(item.agent_target, agent_target)
                self.assertEqual(item.agent_program, agent_program)
                break
Ejemplo n.º 11
0
    def test_insert_row(self):
        """Testing method / function insert_row."""
        # Initialize key variables
        result = datapoint.checksum_exists(-1)
        polling_interval = 1
        self.assertFalse(result)

        # Create a new Agent entry
        agent_id = data.hashstring(str(random()))
        agent_target = data.hashstring(str(random()))
        agent_program = data.hashstring(str(random()))
        agent.insert_row(agent_id, agent_target, agent_program)
        idx_agent = agent.exists(agent_id, agent_target)

        # Create entry and check
        checksum = data.hashstring(str(random()))
        result = datapoint.checksum_exists(checksum)
        self.assertFalse(result)
        datapoint.insert_row(checksum, DATA_FLOAT, polling_interval, idx_agent)
        result = datapoint.checksum_exists(checksum)
        self.assertTrue(bool(result))
        self.assertTrue(isinstance(result, int))