Support to archive also partition data along with logs for ONOS.
Used by clusterTest based on a new ARCHIVE_PARTITION config in clusterTest.json.
After every test iteration, the partition data would also be archived in setup/test_logs if set to true.
It defaults to false and can be enabled if required.

Change-Id: Iaeddea30e6a6ad8dacce134228959e2b4ded4ef1
diff --git a/src/test/cluster/clusterTest.json b/src/test/cluster/clusterTest.json
index 4780b62..0c05484 100644
--- a/src/test/cluster/clusterTest.json
+++ b/src/test/cluster/clusterTest.json
@@ -1,5 +1,6 @@
 {
     "V_INF1" : "veth0",
     "TLS_TIMEOUT" : 100,
-    "ITERATIONS" : 10
+    "ITERATIONS" : 10,
+    "ARCHIVE_PARTITION" : false
 }
diff --git a/src/test/cluster/clusterTest.py b/src/test/cluster/clusterTest.py
index 6d27955..88a9915 100644
--- a/src/test/cluster/clusterTest.py
+++ b/src/test/cluster/clusterTest.py
@@ -65,6 +65,7 @@
     testcaseLoggers = ('test_cluster_controller_restarts', 'test_cluster_graceful_controller_restarts',
                        'test_cluster_single_controller_restarts', 'test_cluster_restarts')
     ITERATIONS = int(os.getenv('ITERATIONS', 10))
+    ARCHIVE_PARTITION = False
 
     def setUp(self):
         if self._testMethodName not in self.testcaseLoggers:
@@ -377,7 +378,8 @@
                         log.error('Test failed on ITERATION %d' %iteration)
                         CordLogger.archive_results(self._testMethodName,
                                                    controllers = controllers,
-                                                   iteration = 'FAILED')
+                                                   iteration = 'FAILED',
+                                                   archive_partition = self.ARCHIVE_PARTITION)
                         assert_equal(len(failed), 0)
                     return controller
 
@@ -393,7 +395,8 @@
                 log.error('Test failed on ITERATION %d' %iteration)
                 CordLogger.archive_results(self._testMethodName,
                                            controllers = controllers,
-                                           iteration = 'FAILED')
+                                           iteration = 'FAILED',
+                                           archive_partition = self.ARCHIVE_PARTITION)
             assert_equal(len(failed), 0)
             if st is False:
                 log.info('No storage exception and ONOS cluster was not formed successfully')
@@ -429,7 +432,8 @@
             #first archive the test case logs for this run
             CordLogger.archive_results(self._testMethodName,
                                        controllers = controllers,
-                                       iteration = 'iteration_{}'.format(num+1))
+                                       iteration = 'iteration_{}'.format(num+1),
+                                       archive_partition = self.ARCHIVE_PARTITION)
             next_controller = check_exception(num, controller = controller)
 
     def test_cluster_controller_restarts(self):
@@ -476,7 +480,8 @@
                     log.error('Test failed on ITERATION %d' %iteration)
                     CordLogger.archive_results('test_cluster_single_controller_restarts',
                                                controllers = controllers,
-                                               iteration = 'FAILED')
+                                               iteration = 'FAILED',
+                                               archive_partition = self.ARCHIVE_PARTITION)
                     assert_equal(len(failed), 0)
                     return controller
 
@@ -518,7 +523,8 @@
             #archive the logs for this run
             CordLogger.archive_results('test_cluster_single_controller_restarts',
                                        controllers = controllers,
-                                       iteration = 'iteration_{}'.format(num+1))
+                                       iteration = 'iteration_{}'.format(num+1),
+                                       archive_partition = self.ARCHIVE_PARTITION)
             check_exception(num, controller, inclusive = True)
 
     def test_cluster_restarts(self):
@@ -555,7 +561,8 @@
                     log.error('Test failed on ITERATION %d' %iteration)
                     CordLogger.archive_results('test_cluster_restarts',
                                                controllers = controllers,
-                                               iteration = 'FAILED')
+                                               iteration = 'FAILED',
+                                               archive_partition = self.ARCHIVE_PARTITION)
                     assert_equal(len(failed), 0)
                     return
 
@@ -568,7 +575,8 @@
                     log.error('Test failed on ITERATION %d' %iteration)
                     CordLogger.archive_results('test_cluster_restarts',
                                                controllers = controllers,
-                                               iteration = 'FAILED')
+                                               iteration = 'FAILED',
+                                               archive_partition = self.ARCHIVE_PARTITION)
                 assert_equal(len(ips), len(controllers))
 
         tries = self.ITERATIONS
@@ -587,7 +595,8 @@
             #archive the logs for this run before verification
             CordLogger.archive_results('test_cluster_restarts',
                                        controllers = controllers,
-                                       iteration = 'iteration_{}'.format(num+1))
+                                       iteration = 'iteration_{}'.format(num+1),
+                                       archive_partition = self.ARCHIVE_PARTITION)
             #check for exceptions on the adjacent nodes
             check_exception(num)
 
diff --git a/src/test/utils/CordLogger.py b/src/test/utils/CordLogger.py
index 1efe086..54d8b11 100644
--- a/src/test/utils/CordLogger.py
+++ b/src/test/utils/CordLogger.py
@@ -84,7 +84,7 @@
         except: pass
 
     @classmethod
-    def archive_results(cls, testName, controllers = None, iteration = None):
+    def archive_results(cls, testName, controllers = None, iteration = None, archive_partition = False):
         if not os.path.exists(cls.onos_data_dir):
             return cls.archive_results_unshared(testName, controllers = controllers, iteration = iteration)
         if not os.path.exists(cls.archive_dir):
@@ -96,11 +96,18 @@
             controller_map = get_controller_map(controllers)
 
         iteration_str = '' if iteration is None else '_{}'.format(iteration)
+        if archive_partition is False:
+            archive_target = 'log'
+            tar_options = ''
+        else:
+            archive_target = ''
+            tar_options = '--exclude=cache --exclude=tmp'
+
         for c in controller_map.keys():
             archive_file = os.path.join(cls.archive_dir,
                                         'logs_{}_{}{}.tar.gz'.format(controller_map[c], testName, iteration_str))
-            archive_path = os.path.join(cls.setup_dir, '{}-data'.format(c), 'log')
-            cmd = 'cd {} && tar cvzf {} .'.format(archive_path, archive_file)
+            archive_path = os.path.join(cls.setup_dir, '{}-data'.format(c), archive_target)
+            cmd = 'cd {} && tar cvzf {} . {}'.format(archive_path, archive_file, tar_options)
             try:
                 os.system(cmd)
             except: pass