Merge ~andreserl/maas:lp1513775_fix_named_init_config into maas:master

Proposed by Andres Rodriguez
Status: Merged
Approved by: Andres Rodriguez
Approved revision: 0db71cc47f37686f2a8e5fe19c775fb25e056342
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~andreserl/maas:lp1513775_fix_named_init_config
Merge into: maas:master
Diff against target: 155 lines (+46/-36)
2 files modified
src/maasserver/management/commands/edit_named_options.py (+43/-33)
src/maasserver/tests/test_commands_edit_named_options.py (+3/-3)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Mike Pontillo (community) Approve
MAAS Maintainers Pending
Review via email: mp+342212@code.launchpad.net

Commit message

LP: #1513775 - Ensure 'dnssec-validation' gets always parsed

On the original bind config, 'dnssec-validation' is set. In some cases, when parsing the config, 'dnssec-validation' is not removed automatically from the bind's config, but it is always added to MAAS' config. This, sometimes, causes bind to fail to start because of duplicate options.

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

@Mike,

I'm thinking that with this change we can drop migrate-conflicting-options, and always call these options without having to invoke migrate-conflicting-options. Thoutghs?

Revision history for this message
Mike Pontillo (mpontillo) wrote :

I think this change is good, as long as we can guarantee that the database is always up and running when MAAS is installed or upgraded. So +1, as long as the the maas-dns package is refactored to stop calling edit_named_options when the database isn't necessarily up and running. (That is, I'm not sure this should land separately from refactoring the packaging, but I'll leave it up to you.)

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1513775_fix_named_init_config lp:~andreserl/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 07ef3b9f5fc72a82ebb551f6fb188a78ee19db2d

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1513775_fix_named_init_config lp:~andreserl/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci-jenkins.internal:8080/job/maas/job/branch-tester/2131/console
COMMIT: cf13ead6cb288592106d236941a65201335dcc14

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :
Revision history for this message
MAAS Lander (maas-lander) wrote :
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1513775_fix_named_init_config lp:~andreserl/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 0db71cc47f37686f2a8e5fe19c775fb25e056342

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/management/commands/edit_named_options.py b/src/maasserver/management/commands/edit_named_options.py
2index cef2d49..960697f 100644
3--- a/src/maasserver/management/commands/edit_named_options.py
4+++ b/src/maasserver/management/commands/edit_named_options.py
5@@ -63,10 +63,8 @@ class Command(BaseCommand):
6 parser.add_argument(
7 '--migrate-conflicting-options', default=False,
8 dest='migrate_conflicting_options', action='store_true',
9- help="Causes any options that conflict with MAAS-managed options "
10- "to be deleted from the BIND configuration and moved to the "
11- "MAAS-managed configuration. Requires the MAAS database to "
12- "be configured and running.")
13+ help="**This option is now deprecated**. It no longer has any "
14+ "effect and it may be removed in a future release.")
15
16 def read_file(self, config_path):
17 """Open the named file and return its contents as a string."""
18@@ -113,27 +111,36 @@ class Command(BaseCommand):
19 if 'forwarders' in options_block:
20 bind_forwarders = options_block['forwarders']
21
22+ delete_forwarders = False
23 if not dry_run:
24- config, created = Config.objects.get_or_create(
25- name='upstream_dns',
26- defaults={'value': ' '.join(bind_forwarders)})
27- if not created:
28- # A configuration value already exists, so add the
29- # additional values we found in the configuration file to
30- # MAAS.
31- if config.value is None:
32- config.value = ''
33- maas_forwarders = OrderedDict.fromkeys(
34- config.value.split())
35- maas_forwarders.update(bind_forwarders)
36- config.value = ' '.join(maas_forwarders)
37- config.save()
38+ try:
39+ config, created = Config.objects.get_or_create(
40+ name='upstream_dns',
41+ defaults={'value': ' '.join(bind_forwarders)})
42+ if not created:
43+ # A configuration value already exists, so add the
44+ # additional values we found in the configuration
45+ # file to MAAS.
46+ if config.value is None:
47+ config.value = ''
48+ maas_forwarders = OrderedDict.fromkeys(
49+ config.value.split())
50+ maas_forwarders.update(bind_forwarders)
51+ config.value = ' '.join(maas_forwarders)
52+ config.save()
53+ delete_forwarders = True
54+ except:
55+ pass
56 else:
57 stdout.write(
58 "// Append to MAAS forwarders: %s\n"
59 % ' '.join(bind_forwarders))
60
61- del options_block['forwarders']
62+ # Only delete forwarders from the config if MAAS was able to
63+ # migrate the options. Otherwise leave them in the original
64+ # config.
65+ if delete_forwarders:
66+ del options_block['forwarders']
67
68 def migrate_dnssec_validation(self, options_block, dry_run, stdout):
69 """Remove existing dnssec-validation from the options block.
70@@ -148,19 +155,23 @@ class Command(BaseCommand):
71 dnssec_validation = options_block['dnssec-validation']
72
73 if not dry_run:
74- config, created = Config.objects.get_or_create(
75- name='dnssec_validation',
76- defaults={'value': dnssec_validation})
77- if not created:
78- # Update the MAAS configuration to reflect the new setting
79- # found in the configuration file.
80- config.value = dnssec_validation
81- config.save()
82+ try:
83+ config, created = Config.objects.get_or_create(
84+ name='dnssec_validation',
85+ defaults={'value': dnssec_validation})
86+ if not created:
87+ # Update the MAAS configuration to reflect the new
88+ # setting found in the configuration file.
89+ config.value = dnssec_validation
90+ config.save()
91+ except:
92+ pass
93 else:
94 stdout.write(
95 "// Set MAAS dnssec_validation to: %s\n"
96 % dnssec_validation)
97-
98+ # Always attempt to delete this option as MAAS will always create
99+ # a default for it.
100 del options_block['dnssec-validation']
101
102 def back_up_existing_file(self, config_path):
103@@ -199,8 +210,6 @@ class Command(BaseCommand):
104 stdout = options.get('stdout')
105 if stdout is None:
106 stdout = sys.stdout
107- migrate_conflicting_options = options.get(
108- 'migrate_conflicting_options')
109
110 options_file = self.read_file(config_path)
111 config_dict = self.parse_file(config_path, options_file)
112@@ -211,9 +220,10 @@ class Command(BaseCommand):
113 # Modify the configuration (if necessary).
114 self.set_up_include_statement(options_block, config_path)
115
116- if migrate_conflicting_options:
117- self.migrate_forwarders(options_block, dry_run, stdout)
118- self.migrate_dnssec_validation(options_block, dry_run, stdout)
119+ # Attempt to migrate the conflicting options if there's
120+ # database connection.
121+ self.migrate_forwarders(options_block, dry_run, stdout)
122+ self.migrate_dnssec_validation(options_block, dry_run, stdout)
123
124 # Re-parse the new configuration, so we can detect any changes.
125 new_content = make_isc_string(config_dict)
126diff --git a/src/maasserver/tests/test_commands_edit_named_options.py b/src/maasserver/tests/test_commands_edit_named_options.py
127index 776a861..c59c125 100644
128--- a/src/maasserver/tests/test_commands_edit_named_options.py
129+++ b/src/maasserver/tests/test_commands_edit_named_options.py
130@@ -120,14 +120,14 @@ class TestEditNamedOptionsCommand(MAASServerTestCase):
131 self.assertContentFailsWithMessage(
132 OPTIONS_FILE, "Failed to make a backup")
133
134- def test_does_not_remove_existing_forwarders_config(self):
135+ def test_remove_existing_forwarders_config(self):
136 options_file = self.make_file(contents=OPTIONS_FILE_WITH_FORWARDERS)
137 call_command(
138 "edit_named_options", config_path=options_file,
139 stdout=self.stdout)
140
141 options = read_isc_file(options_file)
142- self.assertThat(make_isc_string(options), Contains('forwarders'))
143+ self.assertThat(make_isc_string(options), Not(Contains('forwarders')))
144
145 def test_removes_existing_forwarders_config_if_migrate_set(self):
146 options_file = self.make_file(contents=OPTIONS_FILE_WITH_FORWARDERS)
147@@ -152,7 +152,7 @@ class TestEditNamedOptionsCommand(MAASServerTestCase):
148 # that's now in the included file).
149 options = read_isc_file(options_file)
150 self.assertThat(
151- make_isc_string(options), Contains('dnssec-validation'))
152+ make_isc_string(options), Not(Contains('dnssec-validation')))
153
154 def test_removes_existing_dnssec_validation_config_if_migration_set(self):
155 options_file = self.make_file(contents=OPTIONS_FILE_WITH_DNSSEC)

Subscribers

People subscribed via source and target branches