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 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 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
}
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);
}
Aggregations