Browse Source

Merge pull request #755 from meghashyamps/CA_province_support

adds support for CA provinces
pull/756/head
Ross McFarland 4 years ago
committed by GitHub
parent
commit
6f6f9717b2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 11 deletions
  1. +13
    -6
      octodns/provider/ns1.py
  2. +8
    -5
      tests/test_octodns_provider_ns1.py

+ 13
- 6
octodns/provider/ns1.py View File

@ -622,11 +622,14 @@ class Ns1Provider(BaseProvider):
for c in countries:
geos.add('{}-{}'.format(continent, c))
# States are easy too, just assume NA-US (CA providences aren't
# supported by octoDNS currently)
# States and provinces are easy too,
# just assume NA-US or NA-CA
for state in meta.get('us_state', []):
geos.add('NA-US-{}'.format(state))
for province in meta.get('ca_province', []):
geos.add('NA-CA-{}'.format(province))
if geos:
# There are geos, combine them with any existing geos for this
# pool and recorded the sorted unique set of them
@ -1144,12 +1147,15 @@ class Ns1Provider(BaseProvider):
country = set()
georegion = set()
us_state = set()
ca_province = set()
for geo in rule.data.get('geos', []):
n = len(geo)
if n == 8:
# US state, e.g. NA-US-KY
us_state.add(geo[-2:])
# CA province, e.g. NA-CA-NL
us_state.add(geo[-2:]) if "NA-US" in geo \
else ca_province.add(geo[-2:])
# For filtering. State filtering is done by the country
# filter
has_country = True
@ -1182,7 +1188,7 @@ class Ns1Provider(BaseProvider):
'meta': georegion_meta,
}
if country or us_state:
if country or us_state or ca_province:
# If there's country and/or states its a country pool,
# countries and states can coexist as they're handled by the
# same step in the filterchain (countries and georegions
@ -1193,11 +1199,12 @@ class Ns1Provider(BaseProvider):
country_state_meta['country'] = sorted(country)
if us_state:
country_state_meta['us_state'] = sorted(us_state)
if ca_province:
country_state_meta['ca_province'] = sorted(ca_province)
regions['{}__country'.format(pool_name)] = {
'meta': country_state_meta,
}
if not georegion and not country and not us_state:
elif not georegion:
# If there's no targeting it's a catchall
regions['{}__catchall'.format(pool_name)] = {
'meta': meta,


+ 8
- 5
tests/test_octodns_provider_ns1.py View File

@ -1247,7 +1247,7 @@ class TestNs1ProviderDynamic(TestCase):
rule0 = record.data['dynamic']['rules'][0]
rule1 = record.data['dynamic']['rules'][1]
rule0['geos'] = ['AF', 'EU']
rule1['geos'] = ['NA-US-CA']
rule1['geos'] = ['NA-US-CA', 'NA-CA-NL']
ret, _ = provider._params_for_A(record)
self.assertEquals(10, len(ret['answers']))
exp = Ns1Provider._FILTER_CHAIN_WITH_REGION_AND_COUNTRY(provider,
@ -1262,7 +1262,8 @@ class TestNs1ProviderDynamic(TestCase):
'iad__country': {
'meta': {
'note': 'rule-order:1',
'us_state': ['CA']
'us_state': ['CA'],
'ca_province': ['NL']
}
},
'lhr__georegion': {
@ -1624,8 +1625,9 @@ class TestNs1ProviderDynamic(TestCase):
'lhr__country': {
'meta': {
'note': 'rule-order:1 fallback:iad',
'country': ['CA'],
'country': ['MX'],
'us_state': ['OR'],
'ca_province': ['NL']
},
},
# iad will use the old style "plain" region naming. We won't
@ -1669,8 +1671,9 @@ class TestNs1ProviderDynamic(TestCase):
'_order': '1',
'geos': [
'AF',
'NA-CA',
'NA-US-OR',
'NA-CA-NL',
'NA-MX',
'NA-US-OR'
],
'pool': 'lhr',
}, {


Loading…
Cancel
Save