2
0

environment.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import os
  2. import kscore.session
  3. SESSION = kscore.session.get_session()
  4. KNOWN_SERVICES = SESSION.get_available_services()
  5. # For the services where the tag name doesn't match
  6. # the name we use to create_client(), we need to maintain
  7. # a map until we can get these changes pushed upstream.
  8. TAG_TO_ENDPOINT_PREFIX = {
  9. 'tag': 'endpoint',
  10. }
  11. REGION = 'cn-beijing-6'
  12. REGION_OVERRIDES = {
  13. 'global': 'cn-beijing-6',
  14. }
  15. SKIP_SERVICES = set([
  16. 'kec',
  17. ])
  18. def before_feature(context, feature):
  19. for tag in feature.tags:
  20. if tag in TAG_TO_ENDPOINT_PREFIX:
  21. service_name = TAG_TO_ENDPOINT_PREFIX[tag]
  22. break
  23. elif tag in KNOWN_SERVICES:
  24. service_name = tag
  25. break
  26. else:
  27. raise RuntimeError("Unable to create a client for "
  28. "feature: %s" % feature)
  29. if service_name in SKIP_SERVICES:
  30. feature.mark_skipped()
  31. return
  32. region_name = _get_region_for_service(service_name)
  33. context.client = SESSION.create_client(service_name, region_name)
  34. def _get_region_for_service(service_name):
  35. if os.environ.get('AWS_SMOKE_TEST_REGION', ''):
  36. region_name = os.environ['AWS_SMOKE_TEST_REGION']
  37. else:
  38. region_name = REGION_OVERRIDES.get(service_name, REGION)
  39. return region_name