← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/maas/config-default-values into lp:maas

 

Raphaël Badin has proposed merging lp:~rvb/maas/config-default-values into lp:maas with lp:~rvb/maas/config-form as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~rvb/maas/config-default-values/+merge/94105

This branch adds a way to define default config values when not present in the Config table.  Note that I've done it this way (i.e. with a python dict in the code) instead of populating the Config table with initial values to allow us more flexibility when we will need to change the default values and have that applied to maas instances.
-- 
https://code.launchpad.net/~rvb/maas/config-default-values/+merge/94105
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/config-default-values into lp:maas.
=== modified file 'src/maasserver/models.py'
--- src/maasserver/models.py	2012-02-21 19:05:33 +0000
+++ src/maasserver/models.py	2012-02-22 09:04:20 +0000
@@ -567,6 +567,12 @@
         self.data.save(filename, content)
 
 
+# Default values for config options.
+DEFAULT_CONFIG = {
+    'maas_name': "My",
+    }
+
+
 class ConfigManager(models.Manager):
     """A utility to manage the configuration settings.
 
@@ -588,7 +594,7 @@
         try:
             return self.get(name=name).value
         except Config.DoesNotExist:
-            return default
+            return DEFAULT_CONFIG.get(name, default)
 
     def get_config_list(self, name):
         """Return the config value list corresponding to the given config

=== modified file 'src/maasserver/tests/test_models.py'
--- src/maasserver/tests/test_models.py	2012-02-21 19:05:33 +0000
+++ src/maasserver/tests/test_models.py	2012-02-22 09:04:20 +0000
@@ -25,6 +25,7 @@
 from maasserver.models import (
     Config,
     create_auth_token,
+    DEFAULT_CONFIG,
     GENERIC_CONSUMER,
     get_auth_tokens,
     MACAddress,
@@ -449,6 +450,13 @@
         config = Config.objects.get_config('name')
         self.assertIsNone(config)
 
+    def test_manager_get_config_not_found_in_default_config(self):
+        name = factory.getRandomString()
+        value = factory.getRandomString()
+        DEFAULT_CONFIG[name] = value
+        config = Config.objects.get_config(name, None)
+        self.assertEqual(value, config)
+
     def test_manager_get_config_list_returns_config_list(self):
         Config.objects.create(name='name', value='config1')
         Config.objects.create(name='name', value='config2')