Exemple #1
0
  private LogicalDevice getLogicalDevice(String nameInterface, ComputerSystem router)
      throws Exception {
    Iterator<LogicalDevice> iterator = router.getLogicalDevices().iterator();

    while (iterator.hasNext()) {
      LogicalDevice logicalDevice = iterator.next();
      if (logicalDevice.getName().equals(nameInterface)) return logicalDevice;
    }

    throw new Exception("Not found logical device");
  }
Exemple #2
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);
    }
  }