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
=== modified file 'scripts/glance-simplestreams-sync.py'
--- scripts/glance-simplestreams-sync.py 2016-04-14 06:50:42 +0000
+++ scripts/glance-simplestreams-sync.py 2016-04-15 09:13:31 +0000
@@ -55,6 +55,7 @@
55from simplestreams.mirrors import glance, UrlMirrorReader55from simplestreams.mirrors import glance, UrlMirrorReader
56from simplestreams.objectstores.swift import SwiftObjectStore56from simplestreams.objectstores.swift import SwiftObjectStore
57from simplestreams.util import read_signed, path_from_mirror_url57from simplestreams.util import read_signed, path_from_mirror_url
58import swiftclient
58import sys59import sys
59import time60import time
60import traceback61import traceback
@@ -333,28 +334,21 @@
333 Updates URLs of product-streams endpoint to point to swift URLs.334 Updates URLs of product-streams endpoint to point to swift URLs.
334 """335 """
335336
336 swift_services = [s for s in services337 try:
337 if s['name'] == 'swift']338 catalog = {
338 if len(swift_services) != 1:339 endpoint_type: ksc.service_catalog.url_for(
339 log.error("found {} swift services. expecting one."340 service_type='object-store', endpoint_type=endpoint_type)
340 " - not updating endpoint.".format(len(swift_services)))341 for endpoint_type in ['publicURL', 'internalURL', 'adminURL']}
341 return342 except keystone_exceptions.EndpointNotFound as e:
343 log.warning("could not retrieve swift endpoint, not updating "
344 "product-streams endpoint: {}".format(e))
345 raise
342346
343 swift_service_id = swift_services[0]['id']347 for endpoint_type in ['publicURL', 'internalURL']:
348 catalog[endpoint_type] += "/{}".format(SWIFT_DATA_DIR)
344349
345 endpoints = [e._info for e in ksc.endpoints.list()350 endpoints = [e._info for e in ksc.endpoints.list()
346 if e._info['region'] == region]351 if e._info['region'] == region]
347
348 swift_endpoints = [e for e in endpoints
349 if e['service_id'] == swift_service_id]
350 if len(swift_endpoints) != 1:
351 log.warning("found {} swift endpoints, expecting one - not"
352 " updating product-streams"
353 " endpoint.".format(len(swift_endpoints)))
354 return
355
356 swift_endpoint = swift_endpoints[0]
357
358 ps_services = [s for s in services352 ps_services = [s for s in services
359 if s['name'] == PRODUCT_STREAMS_SERVICE_NAME]353 if s['name'] == PRODUCT_STREAMS_SERVICE_NAME]
360 if len(ps_services) != 1:354 if len(ps_services) != 1:
@@ -370,45 +364,23 @@
370 if len(ps_endpoints) != 1:364 if len(ps_endpoints) != 1:
371 log.warning("found {} product-streams endpoints in region {},"365 log.warning("found {} product-streams endpoints in region {},"
372 " expecting one - not updating"366 " expecting one - not updating"
373 " endpoint".format(ps_endpoints, region,367 " endpoint".format(len(ps_endpoints), region))
374 len(ps_endpoints)))
375 return368 return
376369
377 log.info("Deleting existing product-streams endpoint: ")370 log.info("Deleting existing product-streams endpoint: ")
378 ksc.endpoints.delete(ps_endpoints[0]['id'])371 ksc.endpoints.delete(ps_endpoints[0]['id'])
379372
380 services_tenant_ids = [t.id for t in ksc.tenants.list()
381 if t.name == 'services']
382
383 if len(services_tenant_ids) != 1:
384 log.warning("found {} tenants named 'services',"
385 " expecting one. Not updating"
386 " endpoint".format(len(services_tenant_ids)))
387
388 services_tenant_id = services_tenant_ids[0]
389
390 path = "/v1/AUTH_{}/{}".format(services_tenant_id,
391 SWIFT_DATA_DIR)
392
393 swift_public_url = swift_endpoint['publicurl']
394 sr_p = urlsplit(swift_public_url)
395 ps_public_url = sr_p._replace(path=path).geturl()
396
397 swift_internal_url = swift_endpoint['internalurl']
398 sr_i = urlsplit(swift_internal_url)
399 ps_internal_url = sr_i._replace(path=path).geturl()
400
401 create_args = dict(region=region,373 create_args = dict(region=region,
402 service_id=ps_service_id,374 service_id=ps_service_id,
403 publicurl=ps_public_url,375 publicurl=catalog['publicURL'],
404 adminurl=swift_endpoint['adminurl'],376 adminurl=catalog['adminURL'],
405 internalurl=ps_internal_url)377 internalurl=catalog['internalURL'])
406 status_set('maintenance', 'Updating product-streams endpoint')378 status_set('maintenance', 'Updating product-streams endpoint')
407 log.info("creating product-streams endpoint: {}".format(create_args))379 log.info("creating product-streams endpoint: {}".format(create_args))
408 ksc.endpoints.create(**create_args)380 ksc.endpoints.create(**create_args)
409 update_endpoint_urls(region, ps_public_url,381 update_endpoint_urls(region, catalog['publicURL'],
410 swift_endpoint['adminurl'],382 catalog['adminURL'],
411 ps_internal_url)383 catalog['internalURL'])
412384
413385
414def juju_run_cmd(cmd):386def juju_run_cmd(cmd):
@@ -570,6 +542,7 @@
570 charm_conf['region'])542 charm_conf['region'])
571 except:543 except:
572 log.exception("Exception during update_product_streams_service")544 log.exception("Exception during update_product_streams_service")
545 should_delete_cron_poll = False
573546
574 else:547 else:
575 log.info("Not updating product streams service.")548 log.info("Not updating product streams service.")
@@ -597,10 +570,13 @@
597 log.info("Glance endpoint not found, will continue polling.")570 log.info("Glance endpoint not found, will continue polling.")
598571
599 except glanceclient.exc.ClientException as e:572 except glanceclient.exc.ClientException as e:
600 log.exception("Glance Client exception during do_sync."573 log.exception("Glance Client exception during do_sync:\n%s\n"
601 " will continue polling.")574 "Will continue polling." % e.message)
602 should_delete_cron_poll = False575 should_delete_cron_poll = False
603576 except swiftclient.ClientException as e:
577 log.exception("Swift Client exception during do_sync:\n%s\n"
578 "Will continue polling." % e.message)
579 should_delete_cron_poll = False
604 except requests.exceptions.RequestException as e:580 except requests.exceptions.RequestException as e:
605 log.exception("Requests exception during do_sync:\n%s\n"581 log.exception("Requests exception during do_sync:\n%s\n"
606 "Will continue polling." % e.message)582 "Will continue polling." % e.message)

Subscribers

People subscribed via source and target branches