/** * This test require the dirty model, since the checkParams method would check there's a * GreTunnelService in the model. * * @throws CapabilityException * @throws ProtocolException */ @Test @Ignore public void testDeleteUnexistingTunnelAction() throws CapabilityException, ProtocolException { log.info("TEST GRE TUNNEL ACTION"); IGRETunnelCapability greCapability = (IGRETunnelCapability) routerResource.getCapability( InitializerTestHelper.getCapabilityInformation(TestsConstants.GRE_CAPABILITY_TYPE)); greCapability.deleteGRETunnel( ParamCreationHelper.getGRETunnelService(TUNNEL_NAME, null, null, null, null)); IQueueManagerCapability queueCapability = (IQueueManagerCapability) routerResource.getCapability( InitializerTestHelper.getCapabilityInformation( TestsConstants.QUEUE_CAPABILIY_TYPE)); List<IAction> queue = (List<IAction>) queueCapability.getActions(); Assert.assertEquals(queue.size(), 1); QueueResponse queueResponse = (QueueResponse) queueCapability.execute(); Assert.assertEquals(queueResponse.getResponses().size(), 1); Assert.assertFalse(queueResponse.isOk()); queue = (List<IAction>) queueCapability.getActions(); Assert.assertEquals(queue.size(), 0); }
@Override public void bootstrap(Resource resource) throws ResourceException { log.info("Loading bootstrap to start resource..."); oldModel = resource.getModel(); resetModel(resource); /* start its capabilities */ for (ICapability capab : resource.getCapabilities()) { /* abstract capabilities have to be initialized */ log.debug("Found a capability in the resource."); /* abstract capabilities have to be initialized */ if (capab instanceof AbstractCapability) { log.debug("Executing capabilities startup..."); ((AbstractCapability) capab).sendRefreshActions(); } } IQueueManagerCapability queueCapab = (IQueueManagerCapability) resource.getCapabilityByInterface(IQueueManagerCapability.class); QueueResponse response; try { response = queueCapab.execute(); if (!response.isOk()) { // TODO IMPROVE ERROR REPORTING throw new ResourceException( "Error during capabilities startup. Failed to execute startUp actions."); } } catch (ProtocolException e) { throw new ResourceException( "Error during capabilities startup. Failed to execute startUp actions.", e); } catch (ActionException e) { throw new ResourceException( "Error during capabilities startup. Failed to execute startUp actions.", e); } catch (CapabilityException e) { throw new ResourceException( "Error during capabilities startup. Failed to execute startUp actions.", e); } if (resource.getProfile() != null) { log.debug("Executing initModel from profile..."); resource.getProfile().initModel(resource.getModel()); } if (ModelHelper.getInterfaces(((ComputerSystem) resource.getModel())).isEmpty()) { log.warn("Router has no interfaces"); } // FIXME This should be part of refresh action initVirtualResources(resource); }
@Test public void testSetInterfaceDescription() throws ProtocolException, ResourceException { IIPCapability ipCapability = (IIPCapability) routerResource.getCapability( InitializerTestHelper.getCapabilityInformation(TestsConstants.IP_CAPABILITY_TYPE)); ipCapability.setInterfaceDescription(ParamCreationHelper.getLogicalPort()); IQueueManagerCapability queueCapability = (IQueueManagerCapability) routerResource.getCapability( InitializerTestHelper.getCapabilityInformation( TestsConstants.QUEUE_CAPABILIY_TYPE)); QueueResponse queueResponse = (QueueResponse) queueCapability.execute(); Assert.assertTrue(queueResponse.isOk()); }
@Test public void testGRECreateTunnelAction() throws CapabilityException, ProtocolException { log.info("TEST GRE TUNNEL ACTION"); IGRETunnelCapability greCapability = (IGRETunnelCapability) routerResource.getCapability( InitializerTestHelper.getCapabilityInformation(TestsConstants.GRE_CAPABILITY_TYPE)); greCapability.createGRETunnel( ParamCreationHelper.getGRETunnelService(TUNNEL_NAME, IPv4_ADDRESS, IP_SOURCE, IP_DESTINY)); IQueueManagerCapability queueCapability = (IQueueManagerCapability) routerResource.getCapability( InitializerTestHelper.getCapabilityInformation( TestsConstants.QUEUE_CAPABILIY_TYPE)); List<IAction> queue = (List<IAction>) queueCapability.getActions(); Assert.assertEquals(queue.size(), 1); QueueResponse queueResponse = (QueueResponse) queueCapability.execute(); Assert.assertEquals(queueResponse.getResponses().size(), 1); Assert.assertEquals(queueResponse.getPrepareResponse().getStatus(), ActionResponse.STATUS.OK); Assert.assertEquals(queueResponse.getConfirmResponse().getStatus(), ActionResponse.STATUS.OK); Assert.assertEquals(queueResponse.getRefreshResponse().getStatus(), ActionResponse.STATUS.OK); Assert.assertEquals( queueResponse.getRestoreResponse().getStatus(), ActionResponse.STATUS.PENDING); Assert.assertTrue(queueResponse.isOk()); queue = (List<IAction>) queueCapability.getActions(); Assert.assertEquals(queue.size(), 0); }
@Test public void createGRETunnelv6Test() throws CapabilityException, ProtocolException { log.info("Test createGRETunnel method"); IGRETunnelCapability greCapability = (IGRETunnelCapability) routerResource.getCapability( InitializerTestHelper.getCapabilityInformation(TestsConstants.GRE_CAPABILITY_TYPE)); greCapability.createGRETunnel( ParamCreationHelper.getGRETunnelService(TUNNEL_NAME, IPv6_ADDRESS, IP_SOURCE, IP_DESTINY)); IQueueManagerCapability queueCapability = (IQueueManagerCapability) routerResource.getCapability( InitializerTestHelper.getCapabilityInformation( TestsConstants.QUEUE_CAPABILIY_TYPE)); QueueResponse queueResponse = (QueueResponse) queueCapability.execute(); Assert.assertTrue(queueResponse.isOk()); }
/** Test to check create static route method */ @Test public void createStaticRouteTest() throws ProtocolException, ResourceException { startResource(); StaticRouteCapability staticRouteCapability = (StaticRouteCapability) routerResource.getCapability( InitializerTestHelper.getCapabilityInformation( TestsConstants.STATIC_ROUTE_CAPABILITY_TYPE)); staticRouteCapability.createStaticRoute("0.0.0.0", "0.0.0.0", "192.168.1.1"); IQueueManagerCapability queueCapability = (IQueueManagerCapability) routerResource.getCapability( InitializerTestHelper.getCapabilityInformation( TestsConstants.QUEUE_CAPABILIY_TYPE)); QueueResponse queueResponse = (QueueResponse) queueCapability.execute(); Assert.assertTrue(queueResponse.isOk()); stopResource(); }
@Test public void testGREDeleteTunnelAction() throws CapabilityException, ProtocolException { log.info("TEST GRE TUNNEL ACTION"); IGRETunnelCapability greCapability = (IGRETunnelCapability) routerResource.getCapability( InitializerTestHelper.getCapabilityInformation(TestsConstants.GRE_CAPABILITY_TYPE)); // add gre tunnel service to the router model. GRETunnelService greTunnelService = new GRETunnelService(); greTunnelService.setName(TUNNEL_NAME); ComputerSystem model = (ComputerSystem) routerResource.getModel(); model.addHostedService(greTunnelService); routerResource.setModel(model); greCapability.deleteGRETunnel( ParamCreationHelper.getGRETunnelService(TUNNEL_NAME, null, null, null, null)); IQueueManagerCapability queueCapability = (IQueueManagerCapability) routerResource.getCapability( InitializerTestHelper.getCapabilityInformation( TestsConstants.QUEUE_CAPABILIY_TYPE)); List<IAction> queue = (List<IAction>) queueCapability.getActions(); Assert.assertEquals(queue.size(), 1); QueueResponse queueResponse = (QueueResponse) queueCapability.execute(); Assert.assertEquals(queueResponse.getResponses().size(), 1); Assert.assertEquals(queueResponse.getPrepareResponse().getStatus(), ActionResponse.STATUS.OK); Assert.assertEquals(queueResponse.getConfirmResponse().getStatus(), ActionResponse.STATUS.OK); Assert.assertEquals(queueResponse.getRefreshResponse().getStatus(), ActionResponse.STATUS.OK); Assert.assertEquals( queueResponse.getRestoreResponse().getStatus(), ActionResponse.STATUS.PENDING); Assert.assertTrue(queueResponse.isOk()); queue = (List<IAction>) queueCapability.getActions(); Assert.assertEquals(queue.size(), 0); }
@Test public void UpDownActionTest() throws CapabilityException { Response resp; QueueResponse queueResponse; resp = (Response) chassisCapability.sendMessage(ActionConstants.GETCONFIG, null); Assert.assertEquals(Status.QUEUED, resp.getStatus()); Assert.assertTrue(resp.getErrors().size() == 0); queueResponse = (QueueResponse) queueCapability.sendMessage(QueueConstants.EXECUTE, null); Assert.assertTrue(queueResponse.isOk()); String str = ""; ComputerSystem model = (ComputerSystem) mockResource.getModel(); Assert.assertNotNull(model); for (LogicalDevice device : model.getLogicalDevices()) { if (device instanceof EthernetPort) { EthernetPort port = (EthernetPort) device; Assert.assertNotNull("OperationalStatus must be set", port.getOperationalStatus()); str += "- EthernetPort: " + '\n'; str += port.getName() + '.' + port.getPortNumber() + '\n'; str += port.getOperationalStatus(); str += '\n'; for (ProtocolEndpoint protocolEndpoint : port.getProtocolEndpoint()) { if (protocolEndpoint instanceof IPProtocolEndpoint) { IPProtocolEndpoint ipProtocol = (IPProtocolEndpoint) protocolEndpoint; str += "ipv4: " + ipProtocol.getIPv4Address() + '\n'; str += "ipv6: " + ipProtocol.getIPv6Address() + '\n'; } } } else { str += "not searched device"; } } log.info(str); String interfaceName = "fe-0/1/3"; /* check model */ LogicalDevice logicalDevice = null; try { logicalDevice = getLogicalDevice(interfaceName, (ComputerSystem) mockResource.getModel()); } catch (Exception ex) { Assert.fail("LogicalDevice not found"); } if (logicalDevice.getOperationalStatus() != OperationalStatus.OK) { Assert.fail("The test can't be executed because the needed interface is down"); } /* send to change status */ resp = (Response) chassisCapability.sendMessage( ActionConstants.CONFIGURESTATUS, newParamsConfigureStatus(interfaceName, OperationalStatus.STOPPED)); Assert.assertEquals(Status.QUEUED, resp.getStatus()); Assert.assertTrue(resp.getErrors().size() == 0); Assert.assertTrue( ((List<IAction>) queueCapability.sendMessage(QueueConstants.GETQUEUE, null)).size() == 1); queueResponse = (QueueResponse) queueCapability.sendMessage(QueueConstants.EXECUTE, null); Assert.assertTrue(queueResponse.isOk()); Assert.assertTrue( ((List<IAction>) queueCapability.sendMessage(QueueConstants.GETQUEUE, null)).size() == 0); if (!isMock) { checkOperationalStatus( (ComputerSystem) mockResource.getModel(), interfaceName, OperationalStatus.STOPPED); } /* send to change status */ resp = (Response) chassisCapability.sendMessage( ActionConstants.CONFIGURESTATUS, newParamsConfigureStatus(interfaceName, OperationalStatus.OK)); Assert.assertEquals(Status.QUEUED, resp.getStatus()); Assert.assertTrue(resp.getErrors().size() == 0); Assert.assertTrue( ((List<IAction>) queueCapability.sendMessage(QueueConstants.GETQUEUE, null)).size() == 1); queueResponse = (QueueResponse) queueCapability.sendMessage(QueueConstants.EXECUTE, null); Assert.assertTrue(queueResponse.isOk()); Assert.assertTrue( ((List<IAction>) queueCapability.sendMessage(QueueConstants.GETQUEUE, null)).size() == 0); if (!isMock) { checkOperationalStatus( (ComputerSystem) mockResource.getModel(), interfaceName, OperationalStatus.OK); } }
@Test public void MakeRemoveConnectionsResourceTest() throws Exception { ResourceDescriptor resourceDescriptor = ResourceHelper.newResourceDescriptorProteus("roadm"); /* create resource */ Resource resource = (Resource) repository.createResource(resourceDescriptor); Assert.assertNotNull(resource.getResourceIdentifier()); Assert.assertNotNull(resource.getResourceDescriptor()); Assert.assertTrue(resource.getCapabilities().isEmpty()); Assert.assertNull(resource.getModel()); Assert.assertNull(resource.getProfile()); Assert.assertFalse(repository.listResources().isEmpty()); // add protocol for resource createProtocolForResource(resource.getResourceIdentifier().getId()); /* start resource */ repository.startResource(resource.getResourceIdentifier().getId()); Assert.assertFalse(resource.getCapabilities().isEmpty()); Assert.assertNotNull(resource.getModel()); // Assert.assertNotNull(resource.getProfile()); IConnectionsCapability connections = (IConnectionsCapability) resource.getCapabilityByInterface(IConnectionsCapability.class); if (connections == null) Assert.fail("Capability not found"); IQueueManagerCapability queueCapability = (IQueueManagerCapability) resource.getCapabilityByInterface(IQueueManagerCapability.class); if (queueCapability == null) Assert.fail("Capability not found"); /* checking model */ // TODO CHECK NEW MODEL CONFIG /* refresh connection */ // Response resp = (Response) connections.sendMessage(ActionConstants.REFRESHCONNECTIONS, null); // List<ActionResponse> responses = (List<ActionResponse>) // queueCapability.sendMessage(QueueManagerConstants.EXECUTE, null); // // Assert.assertTrue(responses.size() == 2); // ActionResponse actionResponse = responses.get(0); // Assert.assertEquals(ActionConstants.REFRESHCONNECTIONS, actionResponse.getActionID()); // for (Response response : actionResponse.getResponses()) { // Assert.assertTrue(response.getStatus() == Response.Status.OK); // } // // List<IAction> queue = (List<IAction>) // queueCapability.sendMessage(QueueManagerConstants.GETQUEUE, null); // Assert.assertTrue(queue.size() == 0); OpticalSwitchFactory opticalSwitchFactory = new OpticalSwitchFactory(); resource.setModel(opticalSwitchFactory.newPedrosaProteusOpticalSwitch()); /* make connection */ FiberConnection connectionRequest = newMakeConnectionParams((ProteusOpticalSwitch) resource.getModel()); connections.makeConnection(connectionRequest); QueueResponse queueResponse = queueCapability.execute(); Assert.assertTrue(queueResponse.isOk()); boolean foundAndOk = false; for (ActionResponse response : queueResponse.getResponses()) { if (response.getActionID().equals(ActionConstants.MAKECONNECTION)) { if (response.getStatus() == STATUS.OK) { foundAndOk = true; for (Response subresponse : response.getResponses()) { Assert.assertTrue(subresponse.getStatus() == Response.Status.OK); } } } } Assert.assertTrue(foundAndOk); List<IAction> queue = (List<IAction>) queueCapability.getActions(); Assert.assertTrue(queue.size() == 0); /* checking model */ Assert.assertNotNull( getFiberConnection(connectionRequest, (ProteusOpticalSwitch) resource.getModel())); // checking for model intern details is in action tests /* remove connection */ connections.removeConnection(connectionRequest); queueResponse = (QueueResponse) queueCapability.execute(); Assert.assertTrue(queueResponse.isOk()); foundAndOk = false; for (ActionResponse response : queueResponse.getResponses()) { if (response.getActionID().equals(ActionConstants.REMOVECONNECTION)) { if (response.getStatus() == STATUS.OK) { foundAndOk = true; for (Response subresponse : response.getResponses()) { Assert.assertTrue(subresponse.getStatus() == Response.Status.OK); } } } } Assert.assertTrue(foundAndOk); queue = (List<IAction>) queueCapability.getActions(); Assert.assertTrue(queue.size() == 0); /* checking model */ Assert.assertNull( getFiberConnection(connectionRequest, (ProteusOpticalSwitch) resource.getModel())); /* stop resource */ repository.stopResource(resource.getResourceIdentifier().getId()); Assert.assertNotNull(resource.getResourceIdentifier()); Assert.assertNotNull(resource.getResourceDescriptor()); Assert.assertTrue(resource.getCapabilities().isEmpty()); Assert.assertNull(resource.getModel()); // Assert.assertNull(resource.getProfile()); Assert.assertFalse(repository.listResources().isEmpty()); /* remove resource */ createProtocolForResource(resource.getResourceIdentifier().getId()); repository.removeResource(resource.getResourceIdentifier().getId()); Assert.assertTrue(resource.getCapabilities().isEmpty()); Assert.assertNull(resource.getModel()); Assert.assertNull(resource.getProfile()); // Assert.assertTrue(repository.listResources().isEmpty()); }