Close ONOS cli log handles on cli disconnect.
And truncate the onoscli.session file instead of appending to cli session log file on every connect.

Change-Id: I3bdacb5aabd2e708cc8a86d8076a17e2f1bb9077
diff --git a/src/test/cli/component.py b/src/test/cli/component.py
index 12defa8..b56b899 100644
--- a/src/test/cli/component.py
+++ b/src/test/cli/component.py
@@ -1,12 +1,12 @@
-# 
+#
 # Copyright 2016-present Ciena Corporation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
-# 
+#
 # http://www.apache.org/licenses/LICENSE-2.0
-# 
+#
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -96,7 +96,7 @@
         # Adding header for the component log
         vars( main )[ self.name + 'log' ].info( main.logHeader )
         # Opening the session log to append command's execution output
-        self.logfile_handler = open( session_file, "a" )
+        self.logfile_handler = open( session_file, "w" )
 
         return "Dummy"
 
@@ -139,4 +139,3 @@
 if __name__ != "__main__":
     import sys
     sys.modules[ __name__ ] = Component()
-
diff --git a/src/test/cli/onosclidriver.py b/src/test/cli/onosclidriver.py
index ca43f7a..4ea1fb6 100644
--- a/src/test/cli/onosclidriver.py
+++ b/src/test/cli/onosclidriver.py
@@ -140,6 +140,7 @@
                     self.handle.expect( "\$" )
                     self.handle.sendline( "exit" )
                     self.handle.expect( "closed" )
+                self.close_log_handles()
         except TypeError:
             main.log.exception( self.name + ": Object not as expected" )
             response = main.FALSE
@@ -4689,4 +4690,3 @@
   flows_json = onos_cli.flows(state = "ADDED")
   print('Flows %s' %flows_json)
   onos_cli.disconnect()
-