Bug 2731: Discard changes only when transaction exist. 04/15504/5
authorMarian Dubai <mdubai@cisco.com>
Thu, 19 Feb 2015 16:18:14 +0000 (17:18 +0100)
committerMarian Dubai <mdubai@cisco.com>
Mon, 23 Feb 2015 09:57:50 +0000 (09:57 +0000)
Change-Id: I2aef83475092e75cc87d3a5edcb37e985ef132f6
Signed-off-by: Marian Dubai <mdubai@cisco.com>
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/DiscardChanges.java
opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java

index dd2ceaec193bf3b55df22bd6d129c9f69f0e508f..1f70a1e52df63b62118e8c97af6b4107c9f068b8 100644 (file)
@@ -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<String, String> 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);
         }
index f1fc27725be99f1a95402f86b2b023e33fb1ecc8..fdae71a16b42160aee37d9bfb9aff95e593ab115 100644 (file)
@@ -568,14 +568,14 @@ public class NetconfMappingTest extends AbstractConfigTest {
         commit();
     }
 
-    @Test(expected = NetconfDocumentedException.class)
+    @Test
     public void testEx2() throws Exception {
-        discard();
+        assertContainsElement(discard(), readXmlToElement("<ok xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>"));
     }
 
-    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 {