From: Marian Dubai Date: Thu, 19 Feb 2015 16:18:14 +0000 (+0100) Subject: Bug 2731: Discard changes only when transaction exist. X-Git-Tag: release/lithium~482^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=b64695583bf72ed6dc8d5cdd642b4807fb671fba Bug 2731: Discard changes only when transaction exist. Change-Id: I2aef83475092e75cc87d3a5edcb37e985ef132f6 Signed-off-by: Marian Dubai --- diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/DiscardChanges.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/DiscardChanges.java index dd2ceaec19..1f70a1e52d 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/DiscardChanges.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/DiscardChanges.java @@ -54,13 +54,15 @@ public class DiscardChanges extends AbstractConfigNetconfOperation { protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException { fromXml(xml); try { - this.transactionProvider.abortTransaction(); - } catch (final IllegalStateException e) { + if (transactionProvider.getTransaction().isPresent()) { + this.transactionProvider.abortTransaction(); + } + } catch (final RuntimeException e) { LOG.warn("Abort failed: ", e); final Map errorInfo = new HashMap<>(); errorInfo .put(ErrorTag.operation_failed.name(), - "Operation failed. Use 'get-config' or 'edit-config' before triggering 'discard-changes' operation"); + "Abort failed."); throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.application, ErrorTag.operation_failed, ErrorSeverity.error, errorInfo); } diff --git a/opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java b/opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java index f1fc27725b..fdae71a16b 100644 --- a/opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java +++ b/opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java @@ -568,14 +568,14 @@ public class NetconfMappingTest extends AbstractConfigTest { commit(); } - @Test(expected = NetconfDocumentedException.class) + @Test public void testEx2() throws Exception { - discard(); + assertContainsElement(discard(), readXmlToElement("")); } - private void discard() throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException { + private Document discard() throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException { DiscardChanges discardOp = new DiscardChanges(transactionProvider, configRegistryClient, NETCONF_SESSION_ID); - executeOp(discardOp, "netconfMessages/discardChanges.xml"); + return executeOp(discardOp, "netconfMessages/discardChanges.xml"); } private void checkBinaryLeafEdited(final Document response) throws NodeTestException, SAXException, IOException {