Merge lp:~danilo/charms/trusty/glance-simplestreams-sync/lathiats-endpoints-fix into lp:~landscape/charms/trusty/glance-simplestreams-sync/landscape

Proposed by Данило Шеган
Status: Merged
Merged at revision: 63
Proposed branch: lp:~danilo/charms/trusty/glance-simplestreams-sync/lathiats-endpoints-fix
Merge into: lp:~landscape/charms/trusty/glance-simplestreams-sync/landscape
Diff against target: 130 lines (+27/-51)
1 file modified
scripts/glance-simplestreams-sync.py (+27/-51)
To merge this branch: bzr merge lp:~danilo/charms/trusty/glance-simplestreams-sync/lathiats-endpoints-fix
Reviewer Review Type Date Requested Status
Adam Collard (community) Approve
Geoff Teale (community) Approve
Review via email: mp+291857@code.launchpad.net

Description of the change

This is a resubmit of https://code.launchpad.net/~lathiat/charms/trusty/glance-simplestreams-sync/trunk/+merge/290950 against our branch with a few changes on top https://pastebin.canonical.com/154167/ (pep8 cleanups and a fix for an issue I've seen with ClientException).

This *has* been tested in ceph/ceph and swift/iscsi configurations (this requires only 4 nodes, whereas swift/ceph requires 6) and works properly and allows juju to bootstrap with the images.

This also supersedes my original proposal which only worked for ceph/ceph at https://code.launchpad.net/~danilo/charms/trusty/glance-simplestreams-sync/normalize-swift-endpoint/+merge/291612

This has been pushed to cs:~danilo/trusty/glance-simplestreams-sync-17 (see the old MP for testing instructions)

This in-turn is best tested with https://code.launchpad.net/~danilo/landscape/swift-endpoints-fix/+merge/291870 (otherwise, the code that branch removes might override the good value this sets: if that happens, re-run the /etc/cron.daily/glance-simplestreams-sync script on the glance-simplestreams-sync/0 unit).

To post a comment you must log in.
66. By Данило Шеган

Merge "landscape" branch.

Revision history for this message
Geoff Teale (tealeg) wrote :

+1 Awesome.

review: Approve
Revision history for this message
Adam Collard (adam-collard) wrote :

Not in this diff but the warning log about finding the wrong number of endpoints is bogus.

    if len(ps_endpoints) != 1:
        log.warning("found {} product-streams endpoints in region {},"
                    " expecting one - not updating"
                    " endpoint".format(ps_endpoints, region,
                                       len(ps_endpoints)))

It has two placeholders and three values to format in there.

It's crying out for tests.

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

Yes, it is crying out for tests, no disagreement there. Fixed the warning message about wrong number of endpoints, addressed your other comment inline.

67. By Данило Шеган

Address review comments regarding warning log messages.

Revision history for this message
Adam Collard (adam-collard) wrote :

Minor nit, let's test it properly with the corresponding branch for Landscape. +1

review: Approve
68. By Данило Шеган

Improve exceptions handling.

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

Thanks, fixed the other exception cases as well to include a message, will clean this up in a follow-up branch.

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-04-14 06:50:42 +0000
3+++ scripts/glance-simplestreams-sync.py 2016-04-15 09:13:31 +0000
4@@ -55,6 +55,7 @@
5 from simplestreams.mirrors import glance, UrlMirrorReader
6 from simplestreams.objectstores.swift import SwiftObjectStore
7 from simplestreams.util import read_signed, path_from_mirror_url
8+import swiftclient
9 import sys
10 import time
11 import traceback
12@@ -333,28 +334,21 @@
13 Updates URLs of product-streams endpoint to point to swift URLs.
14 """
15
16- swift_services = [s for s in services
17- if s['name'] == 'swift']
18- if len(swift_services) != 1:
19- log.error("found {} swift services. expecting one."
20- " - not updating endpoint.".format(len(swift_services)))
21- return
22+ try:
23+ catalog = {
24+ endpoint_type: ksc.service_catalog.url_for(
25+ service_type='object-store', endpoint_type=endpoint_type)
26+ for endpoint_type in ['publicURL', 'internalURL', 'adminURL']}
27+ except keystone_exceptions.EndpointNotFound as e:
28+ log.warning("could not retrieve swift endpoint, not updating "
29+ "product-streams endpoint: {}".format(e))
30+ raise
31
32- swift_service_id = swift_services[0]['id']
33+ for endpoint_type in ['publicURL', 'internalURL']:
34+ catalog[endpoint_type] += "/{}".format(SWIFT_DATA_DIR)
35
36 endpoints = [e._info for e in ksc.endpoints.list()
37 if e._info['region'] == region]
38-
39- swift_endpoints = [e for e in endpoints
40- if e['service_id'] == swift_service_id]
41- if len(swift_endpoints) != 1:
42- log.warning("found {} swift endpoints, expecting one - not"
43- " updating product-streams"
44- " endpoint.".format(len(swift_endpoints)))
45- return
46-
47- swift_endpoint = swift_endpoints[0]
48-
49 ps_services = [s for s in services
50 if s['name'] == PRODUCT_STREAMS_SERVICE_NAME]
51 if len(ps_services) != 1:
52@@ -370,45 +364,23 @@
53 if len(ps_endpoints) != 1:
54 log.warning("found {} product-streams endpoints in region {},"
55 " expecting one - not updating"
56- " endpoint".format(ps_endpoints, region,
57- len(ps_endpoints)))
58+ " endpoint".format(len(ps_endpoints), region))
59 return
60
61 log.info("Deleting existing product-streams endpoint: ")
62 ksc.endpoints.delete(ps_endpoints[0]['id'])
63
64- services_tenant_ids = [t.id for t in ksc.tenants.list()
65- if t.name == 'services']
66-
67- if len(services_tenant_ids) != 1:
68- log.warning("found {} tenants named 'services',"
69- " expecting one. Not updating"
70- " endpoint".format(len(services_tenant_ids)))
71-
72- services_tenant_id = services_tenant_ids[0]
73-
74- path = "/v1/AUTH_{}/{}".format(services_tenant_id,
75- SWIFT_DATA_DIR)
76-
77- swift_public_url = swift_endpoint['publicurl']
78- sr_p = urlsplit(swift_public_url)
79- ps_public_url = sr_p._replace(path=path).geturl()
80-
81- swift_internal_url = swift_endpoint['internalurl']
82- sr_i = urlsplit(swift_internal_url)
83- ps_internal_url = sr_i._replace(path=path).geturl()
84-
85 create_args = dict(region=region,
86 service_id=ps_service_id,
87- publicurl=ps_public_url,
88- adminurl=swift_endpoint['adminurl'],
89- internalurl=ps_internal_url)
90+ publicurl=catalog['publicURL'],
91+ adminurl=catalog['adminURL'],
92+ internalurl=catalog['internalURL'])
93 status_set('maintenance', 'Updating product-streams endpoint')
94 log.info("creating product-streams endpoint: {}".format(create_args))
95 ksc.endpoints.create(**create_args)
96- update_endpoint_urls(region, ps_public_url,
97- swift_endpoint['adminurl'],
98- ps_internal_url)
99+ update_endpoint_urls(region, catalog['publicURL'],
100+ catalog['adminURL'],
101+ catalog['internalURL'])
102
103
104 def juju_run_cmd(cmd):
105@@ -570,6 +542,7 @@
106 charm_conf['region'])
107 except:
108 log.exception("Exception during update_product_streams_service")
109+ should_delete_cron_poll = False
110
111 else:
112 log.info("Not updating product streams service.")
113@@ -597,10 +570,13 @@
114 log.info("Glance endpoint not found, will continue polling.")
115
116 except glanceclient.exc.ClientException as e:
117- log.exception("Glance Client exception during do_sync."
118- " will continue polling.")
119- should_delete_cron_poll = False
120-
121+ log.exception("Glance Client exception during do_sync:\n%s\n"
122+ "Will continue polling." % e.message)
123+ should_delete_cron_poll = False
124+ except swiftclient.ClientException as e:
125+ log.exception("Swift Client exception during do_sync:\n%s\n"
126+ "Will continue polling." % e.message)
127+ should_delete_cron_poll = False
128 except requests.exceptions.RequestException as e:
129 log.exception("Requests exception during do_sync:\n%s\n"
130 "Will continue polling." % e.message)

Subscribers

People subscribed via source and target branches