From: Tony Tkacik Date: Tue, 24 Feb 2015 09:39:34 +0000 (+0000) Subject: Merge "Bug 2731: Discard changes only when transaction exist." X-Git-Tag: release/lithium~473^2~5 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=5c008222efa5c0af49cf8a52881a6299b1e249dc;hp=7d6c45eb8cbafa91be10a66bfcdd841e74e02a4a Merge "Bug 2731: Discard changes only when transaction exist." --- 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 356223515a..d6b5e62b27 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 @@ -569,14 +569,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 {