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
}
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);
}
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);
}
use of org.opennms.core.test.snmp.annotations.JUnitSnmpAgent in project opennms by OpenNMS.
the class MultipleImportIT method testScanTwice.
@Test
@Ignore
@JUnitSnmpAgent(host = "0.0.0.0", resource = "classpath:/snmpwalk-empty.properties")
public void testScanTwice() throws Exception {
final String[] ueis = { EventConstants.PROVISION_SCAN_COMPLETE_UEI, EventConstants.PROVISION_SCAN_ABORTED_UEI };
final CountDownLatch eventReceived = anticipateEvents(1, ueis);
System.err.println("triggering first import");
m_provisioner.importModelFromResource(m_resourceLoader.getResource("classpath:/SPC-222-a.xml"), Boolean.TRUE.toString());
waitForEverything();
System.err.println("triggering second import");
m_provisioner.importModelFromResource(m_resourceLoader.getResource("classpath:/SPC-222-b.xml"), Boolean.TRUE.toString());
waitForEverything();
System.err.println("finished triggering imports");
eventReceived.await(5, TimeUnit.MINUTES);
final List<OnmsNode> nodes = getNodeDao().findAll();
assertEquals(200, nodes.size());
}
use of org.opennms.core.test.snmp.annotations.JUnitSnmpAgent in project opennms by OpenNMS.
the class ProvisionerIT method testProvisionerServiceRescanAfterAddingSnmpNms7838.
// fail if we take more than five minutes
@Test(timeout = 300000)
// Start the test with an empty SNMP agent
@JUnitSnmpAgent(host = "198.51.100.201", port = 161, resource = "classpath:/snmpwalk-empty.properties")
public void testProvisionerServiceRescanAfterAddingSnmpNms7838() throws Exception {
importFromResource("classpath:/requisition_then_scan2.xml", Boolean.TRUE.toString());
final List<OnmsNode> nodes = getNodeDao().findAll();
final OnmsNode node = nodes.get(0);
runPendingScans();
m_nodeDao.flush();
assertEquals(1, getInterfaceDao().countAll());
// Make sure that the OnmsIpInterface doesn't have an ifIndex
assertNull(getInterfaceDao().get(node, "198.51.100.201").getIfIndex());
// Make sure that no OnmsSnmpInterface records exist for the node
assertNull(getSnmpInterfaceDao().findByNodeIdAndIfIndex(node.getId(), 4));
assertNull(getSnmpInterfaceDao().findByNodeIdAndIfIndex(node.getId(), 5));
LOG.info("******************** ADDING SNMP DATA ********************");
// Add some SNMP data to the agent
m_mockSnmpDataProvider.setDataForAddress(new SnmpAgentAddress(addr("198.51.100.201"), 161), new DefaultResourceLoader().getResource("classpath:/snmpTestData3.properties"));
// Rescan
m_mockEventIpcManager.sendEventToListeners(nodeUpdated(node.getId()));
runPendingScans();
m_nodeDao.flush();
// Make sure that a second interface was added from the SNMP agent data
assertEquals(2, getInterfaceDao().countAll());
// Verify the ifIndex entries
assertEquals(5, getInterfaceDao().get(node, "198.51.100.201").getIfIndex().intValue());
assertEquals(5, getInterfaceDao().get(node, "198.51.100.201").getSnmpInterface().getIfIndex().intValue());
assertEquals(4, getInterfaceDao().get(node, "198.51.100.204").getIfIndex().intValue());
assertEquals(4, getInterfaceDao().get(node, "198.51.100.204").getSnmpInterface().getIfIndex().intValue());
}
Aggregations