Skip to content

Commit

Permalink
Issue #114: Last modification and tests
Browse files Browse the repository at this point in the history
Issue #114: Last modification and tests
  • Loading branch information
alexdgilbert committed Apr 15, 2024
1 parent 097077a commit da23bd8
Show file tree
Hide file tree
Showing 14 changed files with 372 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.sentrysoftware.metricshub.engine.configuration.IConfiguration;

/**
* This abstract class defines a generic protocol configuration that will be extended to configure all the protocols such as {@link SshProtocolConfig} or {@link IpmiProtocolConfig}).
* This abstract class defines a generic protocol configuration that will be extended to configure all the protocols.
*/
public abstract class AbstractProtocolConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void testToProtocol() throws InvalidConfigurationException {
.timeout(120L)
.build();

assertEquals(ipmiConfigurationExpected, ipmiConfigCli.toProtocol(username, password));
assertEquals(ipmiConfigurationExpected, ipmiConfigCli.toProtocol(username, password));
assertEquals(ipmiConfigurationExpected, ipmiConfigCli.toProtocol(username, password));
}
}
Expand Down
20 changes: 20 additions & 0 deletions metricshub-engine/.checkstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<fileset-config file-format-version="1.2.0" simple-config="false" sync-formatter="false">
<local-check-config name="maven-checkstyle-plugin validate" location="file:/C:/SentryGit/metricshub/checkstyle.xml" type="remote" description="maven-checkstyle-plugin configuration validate">
<property name="checkstyle.header.file" value="C:\Users\Alex\matrix-reloaded\.metadata\.plugins\org.eclipse.core.resources\.projects\metricshub-engine\com.basistech.m2e.code.quality.checkstyleConfigurator\checkstyle-header-validate.txt"/>
<property name="checkstyle.cache.file" value="${project_loc}/target/checkstyle-cachefile"/>
</local-check-config>
<fileset name="java-sources-validate" enabled="true" check-config-name="maven-checkstyle-plugin validate" local="true">
<file-match-pattern match-pattern="^src/main/java/.*\.java" include-pattern="true"/>
<file-match-pattern match-pattern="^src/main/resources/.*\.properties" include-pattern="true"/>
<file-match-pattern match-pattern="^src/test/resources/.*\.properties" include-pattern="true"/>
<file-match-pattern match-pattern="^src/it/resources/.*\.properties" include-pattern="true"/>
</fileset>
<fileset name="java-sources-validate" enabled="true" check-config-name="maven-checkstyle-plugin validate" local="true">
<file-match-pattern match-pattern="^src/main/java/.*\.java" include-pattern="true"/>
<file-match-pattern match-pattern="^src/main/resources/.*\.properties" include-pattern="true"/>
<file-match-pattern match-pattern="^src/test/resources/.*\.properties" include-pattern="true"/>
<file-match-pattern match-pattern="^src/it/resources/.*\.properties" include-pattern="true"/>
</fileset>
</fileset-config>
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
package org.sentrysoftware.metricshub.engine.client;

/*-
* ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
* MetricsHub Engine
* ჻჻჻჻჻჻
* Copyright 2023 - 2024 Sentry Software
* ჻჻჻჻჻჻
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
*/

import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
import static org.sentrysoftware.metricshub.engine.common.helpers.MetricsHubConstants.EMPTY;
import static org.springframework.util.Assert.isTrue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
package org.sentrysoftware.metricshub.engine.strategy.collect;

/*-
* ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
* MetricsHub Engine
* ჻჻჻჻჻჻
* Copyright 2023 - 2024 Sentry Software
* ჻჻჻჻჻჻
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
*/

import static org.sentrysoftware.metricshub.engine.configuration.OsCommandConfiguration.DEFAULT_TIMEOUT;

import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
package org.sentrysoftware.metricshub.engine.strategy.detection;

/*-
* ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
* MetricsHub Engine
* ჻჻჻჻჻჻
* Copyright 2023 - 2024 Sentry Software
* ჻჻჻჻჻჻
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
*/

import static org.sentrysoftware.metricshub.engine.common.helpers.MetricsHubConstants.AUTOMATIC_NAMESPACE;
import static org.sentrysoftware.metricshub.engine.common.helpers.MetricsHubConstants.SUCCESSFUL_OS_DETECTION_MESSAGE;
import static org.sentrysoftware.metricshub.engine.common.helpers.MetricsHubConstants.TABLE_SEP;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
package org.sentrysoftware.metricshub.engine.strategy.source;

/*-
* ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
* MetricsHub Engine
* ჻჻჻჻჻჻
* Copyright 2023 - 2024 Sentry Software
* ჻჻჻჻჻჻
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
*/

import static org.sentrysoftware.metricshub.engine.common.helpers.MetricsHubConstants.AUTOMATIC_NAMESPACE;
import static org.sentrysoftware.metricshub.engine.common.helpers.MetricsHubConstants.NEW_LINE;
import static org.sentrysoftware.metricshub.engine.common.helpers.MetricsHubConstants.SEMICOLON;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,24 @@ private void initSnmp() {
.build();
}

private void initIpmi() {
final TestConfiguration ipmiConfiguration = new TestConfiguration();

telemetryManager =
TelemetryManager
.builder()
.hostConfiguration(
HostConfiguration
.builder()
.hostname(LOCALHOST)
.hostId(LOCALHOST)
.hostType(DeviceKind.OOB)
.configurations(Map.of(TestConfiguration.class, ipmiConfiguration))
.build()
)
.build();
}

@Test
void testProcessSnmpGetCriterion() {
initSnmp();
Expand Down Expand Up @@ -1390,6 +1408,96 @@ void testGetIpmiCommandForSolaris() throws Exception {
assertTrue(actualMessage.contains(OLD_SOLARIS_VERSION_MESSAGE));
}

@Test
void testProcessIPMIOutOfBand() throws Exception {
initIpmi();

final IProtocolExtension protocolExtensionMock = spy(IProtocolExtension.class);

final ExtensionManager extensionManager = ExtensionManager
.builder()
.withProtocolExtensions(List.of(protocolExtensionMock))
.build();

doReturn(true)
.when(protocolExtensionMock)
.isValidConfiguration(telemetryManager.getHostConfiguration().getConfigurations().get(TestConfiguration.class));

doReturn(Set.of(IpmiCriterion.class)).when(protocolExtensionMock).getSupportedCriteria();

final TelemetryManager telemetryManager = TelemetryManager
.builder()
.hostConfiguration(
HostConfiguration
.builder()
.hostId(MANAGEMENT_CARD_HOST)
.hostType(DeviceKind.OOB)
.hostname(MANAGEMENT_CARD_HOST)
.configurations(Map.of(TestConfiguration.class, TestConfiguration.builder().build()))
.build()
)
.build();

final IpmiCriterion ipmiCriterion = IpmiCriterion.builder().build();

CriterionTestResult result = CriterionTestResult
.builder()
.result(SYSTEM_POWER_UP_MESSAGE)
.message(IPMI_CONNECTION_SUCCESS_WITH_IMPI_OVER_LAN_MESSAGE)
.success(true)
.build();

doReturn(result).when(protocolExtensionMock).processCriterion(ipmiCriterion, MY_CONNECTOR_1_NAME, telemetryManager);

final CriterionProcessor criterionProcessor = new CriterionProcessor(
clientsExecutorMock,
telemetryManager,
MY_CONNECTOR_1_NAME,
extensionManager
);

assertEquals(
CriterionTestResult
.builder()
.result(SYSTEM_POWER_UP_MESSAGE)
.message(IPMI_CONNECTION_SUCCESS_WITH_IMPI_OVER_LAN_MESSAGE)
.success(true)
.build(),
criterionProcessor.process(new IpmiCriterion())
);
}

@Test
void testProcessIPMIOutOfBandNullResult() throws Exception {
initIpmi();

final IProtocolExtension protocolExtensionMock = spy(IProtocolExtension.class);

final ExtensionManager extensionManager = ExtensionManager
.builder()
.withProtocolExtensions(List.of(protocolExtensionMock))
.build();

doReturn(true)
.when(protocolExtensionMock)
.isValidConfiguration(telemetryManager.getHostConfiguration().getConfigurations().get(TestConfiguration.class));

doReturn(Set.of(IpmiCriterion.class)).when(protocolExtensionMock).getSupportedCriteria();

final IpmiCriterion ipmiCriterion = IpmiCriterion.builder().build();

doReturn(null).when(protocolExtensionMock).processCriterion(ipmiCriterion, MY_CONNECTOR_1_NAME, telemetryManager);

final CriterionProcessor criterionProcessor = new CriterionProcessor(
clientsExecutorMock,
telemetryManager,
MY_CONNECTOR_1_NAME,
extensionManager
);

assertEquals(CriterionTestResult.empty(), criterionProcessor.process(new IpmiCriterion()));
}

@Test
void productRequirementsCriterionProcessCriterionNullTest() {
final ProductRequirementsCriterion productRequirementsCriterion = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -1047,6 +1048,74 @@ void testProcessOsCommandSource() {
}
}

@Test
void testProcessIpmiSourceOob() throws Exception {
final TelemetryManager telemetryManager = TelemetryManager
.builder()
.hostConfiguration(HostConfiguration.builder().build())
.build();

final ExtensionManager extensionManager = ExtensionManager
.builder()
.withProtocolExtensions(List.of(protocolExtensionMock))
.build();

final SourceProcessor sourceProcessor = SourceProcessor
.builder()
.telemetryManager(telemetryManager)
.clientsExecutor(clientsExecutorMock)
.extensionManager(extensionManager)
.connectorId(CONNECTOR_ID)
.build();

final TestConfiguration ipmiConfiguration = TestConfiguration.builder().build();

final HostConfiguration hostConfiguration = HostConfiguration
.builder()
.hostname(ECS1_01)
.hostId(ECS1_01)
.hostType(DeviceKind.OOB)
.configurations(Collections.singletonMap(TestConfiguration.class, ipmiConfiguration))
.build();
telemetryManager.setHostConfiguration(hostConfiguration);

final IpmiSource ipmiSource = IpmiSource.builder().build();

doReturn(true).when(protocolExtensionMock).isValidConfiguration(ipmiConfiguration);
doReturn(Set.of(IpmiSource.class)).when(protocolExtensionMock).getSupportedSources();

final SourceTable expected = SourceTable.builder().table(Arrays.asList(Arrays.asList(ECS1_01))).build();
doReturn(expected)
.when(protocolExtensionMock)
.processSource(eq(ipmiSource), anyString(), any(TelemetryManager.class));

final SourceTable actual = sourceProcessor.process(ipmiSource);
assertEquals(expected, actual);
}

@Test
void testProcessIpmiSourceOobNullResult() throws Exception {
final TelemetryManager telemetryManager = TelemetryManager
.builder()
.hostConfiguration(HostConfiguration.builder().hostType(DeviceKind.OOB).build())
.build();

final ExtensionManager extensionManager = ExtensionManager
.builder()
.withProtocolExtensions(List.of(protocolExtensionMock))
.build();

final SourceProcessor sourceProcessor = SourceProcessor
.builder()
.telemetryManager(telemetryManager)
.clientsExecutor(clientsExecutorMock)
.extensionManager(extensionManager)
.connectorId(CONNECTOR_ID)
.build();

assertEquals(SourceTable.empty(), sourceProcessor.process(new IpmiSource()));
}

@Test
void testProcessIpmiSourceStorageHost() {
final HostConfiguration hostConfiguration = HostConfiguration
Expand Down
7 changes: 0 additions & 7 deletions metricshub-ipmi-extension/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@
<artifactId>snmp4j-agent</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.sentrysoftware</groupId>
<artifactId>metricshub-it-common</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
package org.sentrysoftware.metricshub.extension.ipmi;

/*-
* ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
* MetricsHub Ipmi Extension
* ჻჻჻჻჻჻
* Copyright 2023 - 2024 Sentry Software
* ჻჻჻჻჻჻
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
*/

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature;
Expand Down
Loading

0 comments on commit da23bd8

Please sign in to comment.