Merge lp:~hloeung/ubuntu-repository-cache/dont-disable-unit-on-failover-or-pause into lp:ubuntu-repository-cache

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 326
Merged at revision: 326
Proposed branch: lp:~hloeung/ubuntu-repository-cache/dont-disable-unit-on-failover-or-pause
Merge into: lp:ubuntu-repository-cache
Diff against target: 99 lines (+16/-24)
2 files modified
lib/ubuntu_repository_cache/apache.py (+0/-5)
tests/unit/test_apache.py (+16/-19)
To merge this branch: bzr merge lp:~hloeung/ubuntu-repository-cache/dont-disable-unit-on-failover-or-pause
Reviewer Review Type Date Requested Status
Paul Collins lgtm Approve
Canonical IS Reviewers Pending
Review via email: mp+399254@code.launchpad.net

Commit message

Don't set health-check-disabled flag in apache.create_metadata_site()

On non-leader units, metadata sync calls service.pause() which then
calls this. This causes a brief period where the unit is disabled and
not serving requests. It's useful for initial unit provisioning but
not so on a fully functional unit where metadata points to an existing
copy on disk.

NOTE: The setting of health-check-disabled flag was introduced in r309 (MP:398100).

Description of the change

Seems only happening in gce-us-central1 where it has a large no. of u-r-c units compared to all the others (that or metadata sync between them takes longer).

See https://code.launchpad.net/~hloeung/ubuntu-repository-cache/health-check-handle-initial-sync/+merge/398100

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Paul Collins (pjdc) :
review: Approve (lgtm)
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 326

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/ubuntu_repository_cache/apache.py'
--- lib/ubuntu_repository_cache/apache.py 2021-02-22 22:51:22 +0000
+++ lib/ubuntu_repository_cache/apache.py 2021-03-07 22:12:50 +0000
@@ -212,7 +212,6 @@
212 apache_context['Path_Base'] = config['path-base']212 apache_context['Path_Base'] = config['path-base']
213 metaproxy_conf = '# No failover configured'213 metaproxy_conf = '# No failover configured'
214 failover_host = util.get_failover_host()214 failover_host = util.get_failover_host()
215 healthcheck_disabled = os.path.join(unitdata.kv().get('apache-root'), 'health-check', 'health-check-disabled.flag')
216 if util.in_failover() and failover_host:215 if util.in_failover() and failover_host:
217 uri = 'http://%s:80' % failover_host216 uri = 'http://%s:80' % failover_host
218 metaproxy_conf = (217 metaproxy_conf = (
@@ -220,10 +219,6 @@
220 '\tProxyPass / http://{disp}/\n'219 '\tProxyPass / http://{disp}/\n'
221 '\tProxyPassReverse / http://{disp}/'220 '\tProxyPassReverse / http://{disp}/'
222 ).format(uri=uri, disp=config['display-host'])221 ).format(uri=uri, disp=config['display-host'])
223 if not os.path.exists(healthcheck_disabled):
224 os.mknod(healthcheck_disabled)
225 elif os.path.exists(healthcheck_disabled):
226 os.unlink(healthcheck_disabled)
227 apache_context['MetadataProxy'] = metaproxy_conf222 apache_context['MetadataProxy'] = metaproxy_conf
228 apache_context['Enable_Healthcheck'] = config['enable_healthcheck']223 apache_context['Enable_Healthcheck'] = config['enable_healthcheck']
229224
230225
=== modified file 'tests/unit/test_apache.py'
--- tests/unit/test_apache.py 2021-02-22 03:43:03 +0000
+++ tests/unit/test_apache.py 2021-03-07 22:12:50 +0000
@@ -112,9 +112,8 @@
112 @mock.patch('lib.ubuntu_repository_cache.apache.start')112 @mock.patch('lib.ubuntu_repository_cache.apache.start')
113 @mock.patch('lib.ubuntu_repository_cache.util.get_failover_host')113 @mock.patch('lib.ubuntu_repository_cache.util.get_failover_host')
114 @mock.patch('lib.ubuntu_repository_cache.util.in_failover')114 @mock.patch('lib.ubuntu_repository_cache.util.in_failover')
115 @mock.patch('os.mknod')
116 @mock.patch('subprocess.call')115 @mock.patch('subprocess.call')
117 def test_create_metadata_site_in_failover(self, call, mknod, in_failover, get_failover_host, start, render):116 def test_create_metadata_site_in_failover(self, call, in_failover, get_failover_host, start, render):
118 config = hookenv.Config(117 config = hookenv.Config(
119 {118 {
120 'display-host': 'archive.ubuntu.com',119 'display-host': 'archive.ubuntu.com',
@@ -126,13 +125,9 @@
126 get_failover_host.return_value = '10.1.1.1'125 get_failover_host.return_value = '10.1.1.1'
127 in_failover.return_value = True126 in_failover.return_value = True
128127
129 health_check_path = os.path.join(self.tmpdir, 'apache', 'health-check')
130 disabled_flag = os.path.join(health_check_path, 'health-check-disabled.flag')
131 os.mkdir(os.path.join(self.tmpdir, 'apache'))128 os.mkdir(os.path.join(self.tmpdir, 'apache'))
132 os.mkdir(health_check_path)
133129
134 apache.create_metadata_site(config)130 apache.create_metadata_site(config)
135 mknod.assert_called_with(disabled_flag)
136 render.assert_called_with(131 render.assert_called_with(
137 'apache2/archive_ubuntu_com.conf',132 'apache2/archive_ubuntu_com.conf',
138 '/etc/apache2/sites-available/archive_ubuntu_com.conf',133 '/etc/apache2/sites-available/archive_ubuntu_com.conf',
@@ -149,18 +144,11 @@
149 )144 )
150 call.assert_called_with(['a2ensite', 'archive_ubuntu_com'])145 call.assert_called_with(['a2ensite', 'archive_ubuntu_com'])
151146
152 # If the disabled flag exists, no need to create it.
153 mknod.reset_mock()
154 open(disabled_flag, 'a').close()
155 apache.create_metadata_site(config)
156 mknod.assert_not_called()
157
158 @mock.patch('charmhelpers.core.templating.render')147 @mock.patch('charmhelpers.core.templating.render')
159 @mock.patch('lib.ubuntu_repository_cache.apache.start')148 @mock.patch('lib.ubuntu_repository_cache.apache.start')
160 @mock.patch('lib.ubuntu_repository_cache.util.get_failover_host')149 @mock.patch('lib.ubuntu_repository_cache.util.get_failover_host')
161 @mock.patch('os.unlink')
162 @mock.patch('subprocess.call')150 @mock.patch('subprocess.call')
163 def test_create_metadata_site_no_failover(self, call, unlink, get_failover_host, start, render):151 def test_create_metadata_site_no_failover(self, call, get_failover_host, start, render):
164 config = hookenv.Config(152 config = hookenv.Config(
165 {153 {
166 'display-host': 'archive.ubuntu.com',154 'display-host': 'archive.ubuntu.com',
@@ -170,13 +158,22 @@
170 }158 }
171 )159 )
172160
173 health_check_path = os.path.join(self.tmpdir, 'apache', 'health-check')
174 disabled_flag = os.path.join(health_check_path, 'health-check-disabled.flag')
175 os.mkdir(os.path.join(self.tmpdir, 'apache'))161 os.mkdir(os.path.join(self.tmpdir, 'apache'))
176 os.mkdir(health_check_path)162
177 os.mknod(disabled_flag)
178 apache.create_metadata_site(config)163 apache.create_metadata_site(config)
179 unlink.assert_called_with(disabled_flag)164 render.assert_called_with(
165 'apache2/archive_ubuntu_com.conf',
166 '/etc/apache2/sites-available/archive_ubuntu_com.conf',
167 {
168 'DocumentRoot': os.path.join(self.tmpdir, 'apache'),
169 'Sync_Host': 'us.archive.ubuntu.com',
170 'Display_Host': 'archive.ubuntu.com',
171 'Path_Base': 'ubuntu',
172 'MetadataProxy': '# No failover configured',
173 'Enable_Healthcheck': True,
174 },
175 )
176 call.assert_called_with(['a2ensite', 'archive_ubuntu_com'])
180177
181 @mock.patch('charmhelpers.core.host.service_start')178 @mock.patch('charmhelpers.core.host.service_start')
182 @mock.patch('charmhelpers.core.host.service_reload')179 @mock.patch('charmhelpers.core.host.service_reload')

Subscribers

People subscribed via source and target branches