From 48566d84cd9f4047d96541540cdfc9ef4936acf8 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Thu, 19 Apr 2018 12:27:16 +0200 Subject: HC2VPP-308: forbid local0 deletion Adds special case for local0 in InterfaceCustomizer.deleteCurrentAttributes. Change-Id: I1eb0826f90bd5dbbdb3b6cbb4b19ac5cadb1a68f Signed-off-by: Marek Gradzki --- .../io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizer.java | 12 ++++++++++-- .../hc2vpp/v3po/interfaces/InterfaceCustomizerTest.java | 15 +++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'v3po') diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizer.java index be50aa6b7..2f155bb87 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizer.java @@ -40,6 +40,8 @@ public class InterfaceCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer, JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(InterfaceCustomizer.class); + private static final String LOCAL0_NAME = "local0"; + private final NamingContext interfaceContext; public InterfaceCustomizer(final FutureJVppCore vppApi, final NamingContext interfaceContext) { @@ -68,8 +70,14 @@ public class InterfaceCustomizer extends FutureJVppCustomizer @Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final Interface dataBefore, - @Nonnull final WriteContext writeContext) { - // Nothing to be done here, customizers for specific interface types e.g. vxlan handle the delete + @Nonnull final WriteContext writeContext) + throws WriteFailedException.DeleteFailedException { + // Special handling for local0 interface (HC2VPP-308): + if (LOCAL0_NAME.equals(dataBefore.getName())) { + throw new WriteFailedException.DeleteFailedException(id, + new UnsupportedOperationException("Removing " + LOCAL0_NAME + " interface is not supported")); + } + // For other interfaces, delegate delete to customizers for specific interface types (e.g. VXLan, Tap). } private void setInterface(final InstanceIdentifier id, final Interface swIf, diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizerTest.java index d33211842..6a659f484 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizerTest.java @@ -43,10 +43,14 @@ public class InterfaceCustomizerTest extends WriterCustomizerTest implements Byt private static final String IF_NAME = "eth1"; private static final int IF_INDEX = 1; - private InterfaceCustomizer customizer; - private InstanceIdentifier IID = + private static final InstanceIdentifier IID = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)); + private static final String LOCAL0_IFC_NAME = "local0"; + private static final InstanceIdentifier LOCAL0_IID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(LOCAL0_IFC_NAME)); + private InterfaceCustomizer customizer; + @Override protected void setUpTest() throws Exception { customizer = new InterfaceCustomizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME)); @@ -101,6 +105,13 @@ public class InterfaceCustomizerTest extends WriterCustomizerTest implements Byt verifyZeroInteractions(api); } + @Test(expected = WriteFailedException.DeleteFailedException.class) + public void testDeleteLocal0() throws WriteFailedException { + final Interface ifc = mock(Interface.class); + when(ifc.getName()).thenReturn(LOCAL0_IFC_NAME); + customizer.deleteCurrentAttributes(LOCAL0_IID, ifc, writeContext); + } + private Interface iface(final boolean enabled) { return new InterfaceBuilder().setName(IF_NAME).setEnabled(enabled).build(); } -- cgit 1.2.3-korg