ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject git commit: AMBARI-6808. Make getting AmbariConfigs properties more robust when called by DataCleaner.py (Alejandro Fernandez via ncole)
Date Wed, 20 Aug 2014 21:36:17 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 9fc23106f -> 62fb70e15


AMBARI-6808. Make getting AmbariConfigs properties more robust when called by DataCleaner.py
(Alejandro Fernandez via ncole)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/62fb70e1
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/62fb70e1
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/62fb70e1

Branch: refs/heads/trunk
Commit: 62fb70e1504f333c303fb4770a581e21b46d10b5
Parents: 9fc2310
Author: Nate Cole <ncole@hortonworks.com>
Authored: Wed Aug 20 17:36:05 2014 -0400
Committer: Nate Cole <ncole@hortonworks.com>
Committed: Wed Aug 20 17:36:05 2014 -0400

----------------------------------------------------------------------
 .../src/main/python/ambari_agent/AmbariConfig.py     |  9 +++++++--
 .../src/main/python/ambari_agent/DataCleaner.py      |  6 +++---
 .../src/test/python/ambari_agent/TestDataCleaner.py  | 15 +++++++++++++++
 3 files changed, 25 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/62fb70e1/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py b/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py
index 4453161..6e2ec84 100644
--- a/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py
+++ b/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py
@@ -237,8 +237,13 @@ class AmbariConfig:
     self.net = NetUtil()
     self.config.readfp(StringIO.StringIO(content))
 
-  def get(self, section, value):
-    return self.config.get(section, value)
+  def get(self, section, value, default=None):
+    try:
+      return self.config.get(section, value)
+    except ConfigParser.Error, err:
+      if default:
+        return default
+      raise err
 
   def set(self, section, option, value):
     self.config.set(section, option, value)

http://git-wip-us.apache.org/repos/asf/ambari/blob/62fb70e1/ambari-agent/src/main/python/ambari_agent/DataCleaner.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/DataCleaner.py b/ambari-agent/src/main/python/ambari_agent/DataCleaner.py
index 0102eef..e767be1 100644
--- a/ambari-agent/src/main/python/ambari_agent/DataCleaner.py
+++ b/ambari-agent/src/main/python/ambari_agent/DataCleaner.py
@@ -36,21 +36,21 @@ class DataCleaner(threading.Thread):
     logger.info('Data cleanup thread started')
     self.config = config
 
-    self.file_max_age = config.get('agent','data_cleanup_max_age')
+    self.file_max_age = config.get('agent', 'data_cleanup_max_age', 86400)
     self.file_max_age = int(self.file_max_age) if self.file_max_age else None
     if self.file_max_age is None or self.file_max_age < 86400:       # keep for at least
24h
       logger.warn('The minimum value allowed for data_cleanup_max_age is 1 '
                   'day. Setting data_cleanup_max_age to 86400.')
       self.file_max_age = 86400
 
-    self.cleanup_interval = config.get('agent','data_cleanup_interval')
+    self.cleanup_interval = config.get('agent', 'data_cleanup_interval', 3600)
     self.cleanup_interval = int(self.cleanup_interval) if self.cleanup_interval else None
     if self.cleanup_interval is None or self.cleanup_interval < 3600:    # wait at least
1 hour between runs
       logger.warn('The minimum value allowed for data_cleanup_interval is 1 '
                   'hour. Setting data_cleanup_interval to 3600.')
       self.cleanup_interval = 3600
 
-    self.cleanup_max_size_MB = config.get('agent', 'data_cleanup_max_size_MB')
+    self.cleanup_max_size_MB = config.get('agent', 'data_cleanup_max_size_MB', 10000)
     self.cleanup_max_size_MB = int(self.cleanup_max_size_MB) if self.cleanup_max_size_MB
else None
     if self.cleanup_max_size_MB is None or self.cleanup_max_size_MB > 10000:  # no more
than 10 GBs
       logger.warn('The maximum value allowed for cleanup_max_size_MB is 10000 MB (10 GB).
'

http://git-wip-us.apache.org/repos/asf/ambari/blob/62fb70e1/ambari-agent/src/test/python/ambari_agent/TestDataCleaner.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestDataCleaner.py b/ambari-agent/src/test/python/ambari_agent/TestDataCleaner.py
index b64dc44..fc79d27 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestDataCleaner.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestDataCleaner.py
@@ -22,6 +22,7 @@ limitations under the License.
 import unittest
 from mock.mock import patch, MagicMock, call, Mock
 from ambari_agent import DataCleaner
+import AmbariConfig
 
 
 class TestDataCleaner(unittest.TestCase):
@@ -41,6 +42,20 @@ class TestDataCleaner(unittest.TestCase):
     cleaner = DataCleaner.DataCleaner(config)
     self.assertFalse(DataCleaner.logger.warn.called)
 
+  def test_config(self):
+    """
+    Verify that if the config does not have a property, default values are used.
+    """
+    DataCleaner.logger.reset_mock()
+    config = AmbariConfig.AmbariConfig()
+    config.remove_option('agent', 'data_cleanup_max_age')
+    config.remove_option('agent', 'data_cleanup_interval')
+    config.remove_option('agent', 'data_cleanup_max_size_MB')
+    cleaner = DataCleaner.DataCleaner(config)
+
+    self.assertEqual(cleaner.file_max_age, 86400)
+    self.assertEqual(cleaner.cleanup_interval, 3600)
+    self.assertEqual(cleaner.cleanup_max_size_MB, 10000)
 
   def test_init_warn(self):
     config = MagicMock()


Mime
View raw message