Merge lp:~danilo/charms/trusty/glance-simplestreams-sync/conditional-endpoint-update into lp:~landscape/charms/trusty/glance-simplestreams-sync/landscape

Proposed by Данило Шеган
Status: Merged
Merged at revision: 68
Proposed branch: lp:~danilo/charms/trusty/glance-simplestreams-sync/conditional-endpoint-update
Merge into: lp:~landscape/charms/trusty/glance-simplestreams-sync/landscape
Diff against target: 82 lines (+20/-15)
1 file modified
scripts/glance-simplestreams-sync.py (+20/-15)
To merge this branch: bzr merge lp:~danilo/charms/trusty/glance-simplestreams-sync/conditional-endpoint-update
Reviewer Review Type Date Requested Status
Bogdana Vereha (community) Approve
Geoff Teale (community) Approve
Review via email: mp+295554@code.launchpad.net

Description of the change

Only update (delete/create) "image-stream" endpoint if different from values we want to set it to

This will reduce the changes of hitting a race on keystone units during Autopilot installation: instead of doing delete/create dance every time, we only do it when really needed.

Testing instructions:

1. Deploy OPL
2. Modify canonical/landscape/model/openstack/charms/trusty-stable.json to point at
    cs:~danilo/trusty/glance-simplestreams-sync-26
3. Deploy Autopilot (swift and ceph for object store will use different endpoints, so might be worth re-testing both, even though we do not change that part of the logic)
4. Watch for logging messages about not updating the endpoint ("Endpoint already set to desired values, moving on.") in /var/log/glance-simplestreams-sync.log on gs3 unit
5. Check that things like juju bootstrap still work, that images are correctly synced, etc.

To post a comment you must log in.
Revision history for this message
Geoff Teale (tealeg) wrote :

+1 This looks great. Especially like the use of all(), because I'm a sucker for that stuff ;-)

review: Approve
Revision history for this message
Bogdana Vereha (bogdana) wrote :

+1

review: Approve
Revision history for this message
Данило Шеган (danilo) wrote :

Merged and published as cs:~landscape-charmers/xenial/glance-simplestreams-sync-4 and cs:~landscape-charmers/trusty/glance-simplestreams-sync-10

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'scripts/glance-simplestreams-sync.py'
--- scripts/glance-simplestreams-sync.py 2016-05-23 14:40:23 +0000
+++ scripts/glance-simplestreams-sync.py 2016-05-24 07:54:10 +0000
@@ -45,7 +45,6 @@
4545
46import atexit46import atexit
47import fcntl47import fcntl
48import glanceclient
49from keystoneclient.v2_0 import client as keystone_client48from keystoneclient.v2_0 import client as keystone_client
50import keystoneclient.exceptions as keystone_exceptions49import keystoneclient.exceptions as keystone_exceptions
51import kombu50import kombu
@@ -53,13 +52,10 @@
53from simplestreams.mirrors import glance, UrlMirrorReader52from simplestreams.mirrors import glance, UrlMirrorReader
54from simplestreams.objectstores.swift import SwiftObjectStore53from simplestreams.objectstores.swift import SwiftObjectStore
55from simplestreams.util import read_signed, path_from_mirror_url54from simplestreams.util import read_signed, path_from_mirror_url
56import swiftclient
57import sys55import sys
58import time56import time
59import traceback57import traceback
60import yaml58import yaml
61import requests
62import requests.exceptions
63import subprocess59import subprocess
6460
65KEYRING = '/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg'61KEYRING = '/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg'
@@ -253,20 +249,28 @@
253 " endpoint".format(len(ps_endpoints), region))249 " endpoint".format(len(ps_endpoints), region))
254 return250 return
255251
256 log.info("Deleting existing product-streams endpoint: ")
257 ksc.endpoints.delete(ps_endpoints[0]['id'])
258
259 create_args = dict(region=region,252 create_args = dict(region=region,
260 service_id=ps_service_id,253 service_id=ps_service_id,
261 publicurl=catalog['publicURL'],254 publicurl=catalog['publicURL'],
262 adminurl=catalog['adminURL'],255 adminurl=catalog['adminURL'],
263 internalurl=catalog['internalURL'])256 internalurl=catalog['internalURL'])
264 status_set('maintenance', 'Updating product-streams endpoint')257 ps_endpoint = ps_endpoints[0]
265 log.info("creating product-streams endpoint: {}".format(create_args))258
266 ksc.endpoints.create(**create_args)259 endpoint_already_exists = all(
267 update_endpoint_urls(region, catalog['publicURL'],260 create_args[key] == ps_endpoint.get(key) for key in create_args)
268 catalog['adminURL'],261
269 catalog['internalURL'])262 if endpoint_already_exists:
263 log.info("Endpoint already set to desired values, moving on.")
264 else:
265 status_set('maintenance', 'Updating product-streams endpoint')
266
267 log.info("Deleting existing product-streams endpoint: ")
268 ksc.endpoints.delete(ps_endpoints[0]['id'])
269 log.info("creating product-streams endpoint: {}".format(create_args))
270 ksc.endpoints.create(**create_args)
271 update_endpoint_urls(region, catalog['publicURL'],
272 catalog['adminURL'],
273 catalog['internalURL'])
270274
271275
272def juju_run_cmd(cmd):276def juju_run_cmd(cmd):
@@ -288,7 +292,7 @@
288292
289def update_endpoint_urls(region, publicurl, adminurl, internalurl):293def update_endpoint_urls(region, publicurl, adminurl, internalurl):
290 # Notify keystone via the identity service relation about294 # Notify keystone via the identity service relation about
291 # and endpoint changes295 # any endpoint changes.
292 for rid in juju_run_cmd(['relation-ids', 'identity-service']).split():296 for rid in juju_run_cmd(['relation-ids', 'identity-service']).split():
293 log.info("Updating relation data for: {}".format(rid))297 log.info("Updating relation data for: {}".format(rid))
294 _cmd = ['relation-set', '-r', rid]298 _cmd = ['relation-set', '-r', rid]
@@ -446,7 +450,8 @@
446 # If this is an initial per-minute sync attempt, delete it on success.450 # If this is an initial per-minute sync attempt, delete it on success.
447 if os.path.exists(CRON_POLL_FILENAME):451 if os.path.exists(CRON_POLL_FILENAME):
448 os.unlink(CRON_POLL_FILENAME)452 os.unlink(CRON_POLL_FILENAME)
449 log.info("Initial sync attempt done. every-minute cronjob removed.")453 log.info(
454 "Initial sync attempt done: every-minute cronjob removed.")
450455
451 except keystone_exceptions.EndpointNotFound as e:456 except keystone_exceptions.EndpointNotFound as e:
452 # matching string "{PublicURL} endpoint for {type}{region} not457 # matching string "{PublicURL} endpoint for {type}{region} not

Subscribers

People subscribed via source and target branches