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
1=== modified file 'scripts/glance-simplestreams-sync.py'
2--- scripts/glance-simplestreams-sync.py 2016-05-23 14:40:23 +0000
3+++ scripts/glance-simplestreams-sync.py 2016-05-24 07:54:10 +0000
4@@ -45,7 +45,6 @@
5
6 import atexit
7 import fcntl
8-import glanceclient
9 from keystoneclient.v2_0 import client as keystone_client
10 import keystoneclient.exceptions as keystone_exceptions
11 import kombu
12@@ -53,13 +52,10 @@
13 from simplestreams.mirrors import glance, UrlMirrorReader
14 from simplestreams.objectstores.swift import SwiftObjectStore
15 from simplestreams.util import read_signed, path_from_mirror_url
16-import swiftclient
17 import sys
18 import time
19 import traceback
20 import yaml
21-import requests
22-import requests.exceptions
23 import subprocess
24
25 KEYRING = '/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg'
26@@ -253,20 +249,28 @@
27 " endpoint".format(len(ps_endpoints), region))
28 return
29
30- log.info("Deleting existing product-streams endpoint: ")
31- ksc.endpoints.delete(ps_endpoints[0]['id'])
32-
33 create_args = dict(region=region,
34 service_id=ps_service_id,
35 publicurl=catalog['publicURL'],
36 adminurl=catalog['adminURL'],
37 internalurl=catalog['internalURL'])
38- status_set('maintenance', 'Updating product-streams endpoint')
39- log.info("creating product-streams endpoint: {}".format(create_args))
40- ksc.endpoints.create(**create_args)
41- update_endpoint_urls(region, catalog['publicURL'],
42- catalog['adminURL'],
43- catalog['internalURL'])
44+ ps_endpoint = ps_endpoints[0]
45+
46+ endpoint_already_exists = all(
47+ create_args[key] == ps_endpoint.get(key) for key in create_args)
48+
49+ if endpoint_already_exists:
50+ log.info("Endpoint already set to desired values, moving on.")
51+ else:
52+ status_set('maintenance', 'Updating product-streams endpoint')
53+
54+ log.info("Deleting existing product-streams endpoint: ")
55+ ksc.endpoints.delete(ps_endpoints[0]['id'])
56+ log.info("creating product-streams endpoint: {}".format(create_args))
57+ ksc.endpoints.create(**create_args)
58+ update_endpoint_urls(region, catalog['publicURL'],
59+ catalog['adminURL'],
60+ catalog['internalURL'])
61
62
63 def juju_run_cmd(cmd):
64@@ -288,7 +292,7 @@
65
66 def update_endpoint_urls(region, publicurl, adminurl, internalurl):
67 # Notify keystone via the identity service relation about
68- # and endpoint changes
69+ # any endpoint changes.
70 for rid in juju_run_cmd(['relation-ids', 'identity-service']).split():
71 log.info("Updating relation data for: {}".format(rid))
72 _cmd = ['relation-set', '-r', rid]
73@@ -446,7 +450,8 @@
74 # If this is an initial per-minute sync attempt, delete it on success.
75 if os.path.exists(CRON_POLL_FILENAME):
76 os.unlink(CRON_POLL_FILENAME)
77- log.info("Initial sync attempt done. every-minute cronjob removed.")
78+ log.info(
79+ "Initial sync attempt done: every-minute cronjob removed.")
80
81 except keystone_exceptions.EndpointNotFound as e:
82 # matching string "{PublicURL} endpoint for {type}{region} not

Subscribers

People subscribed via source and target branches