Skip to content

Commit

Permalink
ParseVendorConfigurationJob: do not crash on unsupported configuratio…
Browse files Browse the repository at this point in the history
…n format (#8151)

Add it to the unsupported list, and add a test that would have caught this.
  • Loading branch information
dhalperi committed Mar 16, 2022
1 parent 113682d commit d2bda2b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Expand Up @@ -100,6 +100,7 @@ public class ParseVendorConfigurationJob extends BatfishJob<ParseVendorConfigura
ConfigurationFormat.MRV_COMMANDS,
ConfigurationFormat.MSS,
ConfigurationFormat.RUCKUS_ICX,
ConfigurationFormat.UNSUPPORTED,
ConfigurationFormat.VXWORKS);

/**
Expand Down
Expand Up @@ -6,16 +6,19 @@
import static org.batfish.job.ParseVendorConfigurationJob.getSonicFrrFilename;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import java.util.Optional;
import org.batfish.common.NetworkSnapshot;
import org.batfish.common.Warnings;
import org.batfish.config.Settings;
import org.batfish.datamodel.ConfigurationFormat;
import org.batfish.datamodel.answers.ParseStatus;
import org.batfish.identifiers.NetworkId;
import org.batfish.identifiers.SnapshotId;
import org.junit.Rule;
Expand Down Expand Up @@ -54,6 +57,24 @@ public void testHostInvalid() {
assertThat(result.getFailureCause(), not(equalTo(null)));
}

@Test
public void testFormatUnsupported() {
ParseResult result =
new ParseVendorConfigurationJob(
new Settings(),
new NetworkSnapshot(new NetworkId("net"), new SnapshotId("ss")),
ImmutableMap.of("config", "some nonempty content"),
new Warnings.Settings(false, false, false),
ConfigurationFormat.UNSUPPORTED,
ImmutableMultimap.of(),
null)
.parse();
assertThat(result.getFormat(), equalTo(ConfigurationFormat.UNSUPPORTED));
assertThat(result.getFailureCause(), nullValue());
assertThat(result.getConfig(), nullValue());
assertThat(result.getParseStatus("config"), equalTo(Optional.of(ParseStatus.UNSUPPORTED)));
}

// Tests that empty files are detected as empty, even when another format is provided.
@Test
public void testDetectFormatEmpty() {
Expand Down

0 comments on commit d2bda2b

Please sign in to comment.