Search in sources :

Example 11 with JUnitSnmpAgent

use of org.opennms.core.test.snmp.annotations.JUnitSnmpAgent in project opennms by OpenNMS.

the class InstanceStrategyIntegrationTest method testReloadDaemon.

/*
     * Test the behaviour when the configuration is modified and the daemon is
     * reloaded. Verify: That the proper events are sent by the daemon. The AP
     * state in the database after the poll.
     */
@Test
@JUnitSnmpAgent(host = "10.1.0.2", resource = SNMP_DATA_PATH + "10.1.0.2-walk.txt")
public void testReloadDaemon() throws Exception {
    // Add AP1 and AP2 to the default package
    addNewAccessPoint("ap1", AP1_MAC, "default");
    addNewAccessPoint("ap2", AP2_MAC, "default");
    // Add AP3 to a separate package
    addNewAccessPoint("ap3", AP3_MAC, "not-default");
    // Add a controller to the default package
    addNewController("amc1", "10.1.0.2", "default");
    // Set AP1 as UP
    setOidValueForAccessPoint("10.1.0.2", AP1_MAC, 1);
    // Initialize and start the daemon
    initApmdWithConfig(getEmptyConfig());
    m_apm.start();
    // Sleep for a polling cycle
    sleep(POLLING_INTERVAL_DELTA);
    // Verify the state of the APs in the database
    OnmsAccessPoint ap1 = m_accessPointDao.get(AP1_MAC);
    LOG.debug(ap1.getStatus().getLabel());
    assertTrue(ap1.getStatus() == AccessPointStatus.UNKNOWN);
    OnmsAccessPoint ap2 = m_accessPointDao.get(AP2_MAC);
    assertTrue(ap2.getStatus() == AccessPointStatus.UNKNOWN);
    OnmsAccessPoint ap3 = m_accessPointDao.get(AP3_MAC);
    assertTrue(ap3.getStatus() == AccessPointStatus.UNKNOWN);
    // Anticipate the events
    anticipateApStatusEvent(AP1_MAC, "UP");
    anticipateApStatusEvent(AP2_MAC, "DOWN");
    // Update the configuration and send a reload event to the daemon
    updateConfigAndReloadDaemon(getStandardConfig(), true);
    // Verify the events
    verifyAnticipated(POLLING_INTERVAL_DELTA);
    // Verify the state of the APs in the database
    ap1 = m_accessPointDao.get(AP1_MAC);
    assertTrue(ap1.getStatus() == AccessPointStatus.ONLINE);
    ap2 = m_accessPointDao.get(AP2_MAC);
    assertTrue(ap2.getStatus() == AccessPointStatus.OFFLINE);
    ap3 = m_accessPointDao.get(AP3_MAC);
    assertTrue(ap3.getStatus() == AccessPointStatus.UNKNOWN);
}
Also used : OnmsAccessPoint(org.opennms.netmgt.model.OnmsAccessPoint) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Example 12 with JUnitSnmpAgent

use of org.opennms.core.test.snmp.annotations.JUnitSnmpAgent in project opennms by OpenNMS.

the class InstanceStrategyIntegrationTest method testApUpDown.

/*
     * Run a series of tests with a single controller and 3 access points.
     * Verify: That the proper events are sent by the daemon. The AP state in
     * the database after the poll.
     */
@Test
@JUnitSnmpAgent(host = "10.1.0.2", resource = SNMP_DATA_PATH + "10.1.0.2-walk.txt")
public void testApUpDown() throws Exception {
    // Add AP1 and AP2 to the default package
    addNewAccessPoint("ap1", AP1_MAC, "default");
    addNewAccessPoint("ap2", AP2_MAC, "default");
    // Add AP3 to a separate package
    addNewAccessPoint("ap3", AP3_MAC, "not-default");
    // Add a controller to the default package
    addNewController("amc1", "10.1.0.2", "default");
    // Set AP1 as UP and AP2 as DOWN
    setOidValueForAccessPoint("10.1.0.2", AP1_MAC, 1);
    setOidValueForAccessPoint("10.1.0.2", AP2_MAC, 0);
    // Anticipate the events
    anticipateApStatusEvent(AP1_MAC, "UP");
    anticipateApStatusEvent(AP2_MAC, "DOWN");
    // Initialize and start the daemon
    initApmdWithConfig(getStandardConfig());
    m_apm.start();
    // Verify the events
    verifyAnticipated(POLLING_INTERVAL_DELTA);
    // Verify the state of the APs in the database
    OnmsAccessPoint ap1 = m_accessPointDao.get(AP1_MAC);
    assertTrue(ap1.getStatus() == AccessPointStatus.ONLINE);
    OnmsAccessPoint ap2 = m_accessPointDao.get(AP2_MAC);
    assertTrue(ap2.getStatus() == AccessPointStatus.OFFLINE);
    OnmsAccessPoint ap3 = m_accessPointDao.get(AP3_MAC);
    assertTrue(ap3.getStatus() == AccessPointStatus.UNKNOWN);
    // Change AP3's package, the next poll should send an additional DOWN
    // event
    anticipateApStatusEvent(AP1_MAC, "UP");
    anticipateApStatusEvent(AP2_MAC, "DOWN");
    anticipateApStatusEvent(AP3_MAC, "DOWN");
    ap3.setPollingPackage("default");
    m_accessPointDao.update(ap3);
    m_accessPointDao.flush();
    // Verify the events
    verifyAnticipated(POLLING_INTERVAL_DELTA);
    // Update the data in the SNMP agent to show AP1 as DOWN
    anticipateApStatusEvent(AP1_MAC, "DOWN");
    anticipateApStatusEvent(AP2_MAC, "DOWN");
    anticipateApStatusEvent(AP3_MAC, "DOWN");
    setOidValueForAccessPoint("10.1.0.2", AP1_MAC, 2);
    // Verify the events
    verifyAnticipated(POLLING_INTERVAL_DELTA);
    // Verify the DB again, all APs should be DOWN now
    ap1 = m_accessPointDao.get(AP1_MAC);
    assertTrue(ap1.getStatus() == AccessPointStatus.OFFLINE);
    ap2 = m_accessPointDao.get(AP2_MAC);
    assertTrue(ap2.getStatus() == AccessPointStatus.OFFLINE);
    ap3 = m_accessPointDao.get(AP3_MAC);
    assertTrue(ap3.getStatus() == AccessPointStatus.OFFLINE);
    // Bring AP1 back UP
    anticipateApStatusEvent(AP1_MAC, "UP");
    anticipateApStatusEvent(AP2_MAC, "DOWN");
    anticipateApStatusEvent(AP3_MAC, "DOWN");
    setOidValueForAccessPoint("10.1.0.2", AP1_MAC, 1);
    // Verify the events
    verifyAnticipated(POLLING_INTERVAL_DELTA);
}
Also used : OnmsAccessPoint(org.opennms.netmgt.model.OnmsAccessPoint) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Example 13 with JUnitSnmpAgent

use of org.opennms.core.test.snmp.annotations.JUnitSnmpAgent in project opennms by OpenNMS.

the class SnmpAssetProvisioningAdapterIT method testDelete.

@Test
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
@JUnitSnmpAgent(resource = "snmpAssetTestData.properties")
public void testDelete() throws Exception {
    AdapterOperationChecker verifyOperations = new AdapterOperationChecker(1);
    m_adapter.getOperationQueue().addListener(verifyOperations);
    OnmsNode n = m_nodeDao.findByForeignId("rancid", "1");
    assertNotNull(n);
    m_adapter.deleteNode(n.getId());
    assertTrue(verifyOperations.enqueueLatch.await(4, TimeUnit.SECONDS));
    assertTrue(verifyOperations.dequeueLatch.await(4, TimeUnit.SECONDS));
    assertTrue(verifyOperations.executeLatch.await(4, TimeUnit.SECONDS));
    assertEquals(0, m_adapter.getOperationQueue().getOperationQueueForNode(n.getId()).size());
// TODO: Add assertions to check that the deleteNode() adapter call updated the asset record
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Example 14 with JUnitSnmpAgent

use of org.opennms.core.test.snmp.annotations.JUnitSnmpAgent in project opennms by OpenNMS.

the class SnmpAssetProvisioningAdapterIT method testAdd.

@Test
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
@JUnitSnmpAgent(resource = "snmpAssetTestData.properties")
public void testAdd() throws Exception {
    AdapterOperationChecker verifyOperations = new AdapterOperationChecker(1);
    m_adapter.getOperationQueue().addListener(verifyOperations);
    OnmsNode n = m_nodeDao.findByForeignId("rancid", "1");
    assertNotNull(n);
    m_adapter.addNode(n.getId());
    assertTrue(verifyOperations.enqueueLatch.await(4, TimeUnit.SECONDS));
    assertTrue(verifyOperations.dequeueLatch.await(4, TimeUnit.SECONDS));
    assertTrue(verifyOperations.executeLatch.await(4, TimeUnit.SECONDS));
    assertEquals(0, m_adapter.getOperationQueue().getOperationQueueForNode(n.getId()).size());
// TODO: Add assertions to check that the addNode() adapter call updated the asset record
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Example 15 with JUnitSnmpAgent

use of org.opennms.core.test.snmp.annotations.JUnitSnmpAgent in project opennms by OpenNMS.

the class JUnitSnmpAgentExecutionListener method findAgentAnnotation.

private JUnitSnmpAgent findAgentAnnotation(final TestContext testContext) {
    final Method testMethod = testContext.getTestMethod();
    final JUnitSnmpAgent config = testMethod.getAnnotation(JUnitSnmpAgent.class);
    if (config != null) {
        return config;
    }
    final Class<?> testClass = testContext.getTestClass();
    return testClass.getAnnotation(JUnitSnmpAgent.class);
}
Also used : Method(java.lang.reflect.Method) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Aggregations

JUnitSnmpAgent (org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)21 Test (org.junit.Test)19 JUnitCollector (org.opennms.core.collection.test.JUnitCollector)8 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)6 OnmsNode (org.opennms.netmgt.model.OnmsNode)5 OnmsAccessPoint (org.opennms.netmgt.model.OnmsAccessPoint)4 Transactional (org.springframework.transaction.annotation.Transactional)4 File (java.io.File)2 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)2 SnmpAgentAddress (org.opennms.netmgt.snmp.SnmpAgentAddress)2 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)2 Method (java.lang.reflect.Method)1 InetAddress (java.net.InetAddress)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Ignore (org.junit.Ignore)1 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)1 EventAnticipator (org.opennms.netmgt.dao.mock.EventAnticipator)1 LldpRemTableTracker (org.opennms.netmgt.enlinkd.snmp.LldpRemTableTracker)1 LldpLink (org.opennms.netmgt.model.LldpLink)1 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)1