private boolean cachedConfigsAreCompatible(NetworkId network, SnapshotId snapshot) { try { ConvertConfigurationAnswerElement ccae = loadConvertConfigurationAnswerElement(network, snapshot); return ccae != null && Version.isCompatibleVersion( FileBasedStorage.class.getCanonicalName(), "Old processed configurations", ccae.getVersion()); } catch (BatfishException e) { _logger.warnf( "Unexpected exception caught while deserializing configs for snapshot %s: %s", snapshot, Throwables.getStackTraceAsString(e)); return false; } }
@Override public ConvertConfigurationAnswerElement loadConvertConfigurationAnswerElementOrReparse() { ConvertConfigurationAnswerElement ccae = _storage.loadConvertConfigurationAnswerElement( _settings.getContainer(), _testrigSettings.getName()); if (ccae != null && Version.isCompatibleVersion( "Service", "Old processed configurations", ccae.getVersion())) { return ccae; } repairConfigurations(); ccae = _storage.loadConvertConfigurationAnswerElement( _settings.getContainer(), _testrigSettings.getName()); if (ccae != null && Version.isCompatibleVersion( "Service", "Old processed configurations", ccae.getVersion())) { return ccae; } else { throw new BatfishException( "Version error repairing configurations for convert configuration answer element"); } }
@Test public void loadOldConfigurationsReturnsNull() { ConvertConfigurationAnswerElement oldConvertAnswer = new ConvertConfigurationAnswerElement(); oldConvertAnswer.setVersion(INCOMPATIBLE_VERSION); assertThat( "should not be compatible with current code", Version.isCompatibleVersion("current", "old test", oldConvertAnswer.getVersion()), equalTo(false)); NetworkId network = new NetworkId("network"); SnapshotId snapshot = new SnapshotId("snapshot"); Map<String, Configuration> configs = new HashMap<>(); configs.put("node1", new Configuration("node1", ConfigurationFormat.CISCO_IOS)); _storage.storeConfigurations(configs, oldConvertAnswer, network, snapshot); assertThat(_storage.loadConfigurations(network, snapshot), nullValue()); }