Search in sources :

Example 21 with BatfishLogger

use of org.batfish.common.BatfishLogger in project batfish by batfish.

the class BatfishTestUtils method initBatfish.

private static Batfish initBatfish(SortedMap<String, Configuration> configurations, @Nonnull TemporaryFolder tempFolder) throws IOException {
    Settings settings = new Settings(new String[] {});
    settings.setLogger(new BatfishLogger("debug", false));
    final Cache<Snapshot, SortedMap<String, Configuration>> testrigs = makeTestrigCache();
    final Cache<Snapshot, SortedMap<String, Configuration>> compressedTestrigs = makeTestrigCache();
    Path containerDir = tempFolder.newFolder().toPath();
    settings.setContainerDir(containerDir);
    if (!configurations.isEmpty()) {
        settings.setTestrig("tempTestrig");
        settings.setEnvironmentName("tempEnvironment");
        Batfish.initTestrigSettings(settings);
        settings.getBaseTestrigSettings().getEnvironmentSettings().getEnvPath().toFile().mkdirs();
        testrigs.put(new Snapshot("tempTestrig", "tempEnvironment"), configurations);
        settings.setActiveTestrigSettings(settings.getBaseTestrigSettings());
    }
    Batfish batfish = new Batfish(settings, compressedTestrigs, testrigs, makeDataPlaneCache(), makeDataPlaneCache(), makeEnvBgpCache(), makeEnvRouteCache(), makeForwardingAnalysisCache());
    if (!configurations.isEmpty()) {
        Batfish.serializeAsJson(settings.getBaseTestrigSettings().getEnvironmentSettings().getSerializedTopologyPath(), batfish.computeEnvironmentTopology(configurations), "environment topology");
    }
    return batfish;
}
Also used : Path(java.nio.file.Path) Snapshot(org.batfish.common.Snapshot) BatfishLogger(org.batfish.common.BatfishLogger) SortedMap(java.util.SortedMap) TestrigSettings(org.batfish.config.Settings.TestrigSettings) EnvironmentSettings(org.batfish.config.Settings.EnvironmentSettings) Settings(org.batfish.config.Settings)

Example 22 with BatfishLogger

use of org.batfish.common.BatfishLogger in project batfish by batfish.

the class ClientTest method checkProcessCommandErrorMessage.

private void checkProcessCommandErrorMessage(Command command, String[] parameters, String expected) throws Exception {
    Client client = new Client(new String[] { "-runmode", "gendatamodel" });
    File tempFile = _folder.newFile("writer");
    FileWriter writer = new FileWriter(tempFile);
    client._logger = new BatfishLogger("output", false);
    String[] args = ArrayUtils.addAll(new String[] { command.commandName() }, parameters);
    assertFalse(client.processCommand(args, writer));
    assertThat(client.getLogger().getHistory().toString(500), equalTo(expected));
    writer.close();
}
Also used : BatfishLogger(org.batfish.common.BatfishLogger) FileWriter(java.io.FileWriter) File(java.io.File)

Aggregations

BatfishLogger (org.batfish.common.BatfishLogger)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Settings (org.batfish.config.Settings)6 Configuration (org.batfish.datamodel.Configuration)6 Test (org.junit.Test)6 Path (java.nio.file.Path)5 BatfishException (org.batfish.common.BatfishException)5 Topology (org.batfish.datamodel.Topology)5 Vrf (org.batfish.datamodel.Vrf)5 File (java.io.File)4 IOException (java.io.IOException)4 EnvironmentSettings (org.batfish.config.Settings.EnvironmentSettings)4 TestrigSettings (org.batfish.config.Settings.TestrigSettings)4 Ip (org.batfish.datamodel.Ip)4 BdpAnswerElement (org.batfish.datamodel.answers.BdpAnswerElement)4 ActiveSpan (io.opentracing.ActiveSpan)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Nullable (javax.annotation.Nullable)3 CleanBatfishException (org.batfish.common.CleanBatfishException)3