Browse Source

adds support for CA provinces

pull/755/head
Sham 4 years ago
parent
commit
6d302af719
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: for c in countries:
geos.add('{}-{}'.format(continent, c)) 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', []): for state in meta.get('us_state', []):
geos.add('NA-US-{}'.format(state)) geos.add('NA-US-{}'.format(state))
for province in meta.get('ca_province', []):
geos.add('NA-CA-{}'.format(province))
if geos: if geos:
# There are geos, combine them with any existing geos for this # There are geos, combine them with any existing geos for this
# pool and recorded the sorted unique set of them # pool and recorded the sorted unique set of them
@ -1144,12 +1147,15 @@ class Ns1Provider(BaseProvider):
country = set() country = set()
georegion = set() georegion = set()
us_state = set() us_state = set()
ca_province = set()
for geo in rule.data.get('geos', []): for geo in rule.data.get('geos', []):
n = len(geo) n = len(geo)
if n == 8: if n == 8:
# US state, e.g. NA-US-KY # 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 # For filtering. State filtering is done by the country
# filter # filter
has_country = True has_country = True
@ -1182,7 +1188,7 @@ class Ns1Provider(BaseProvider):
'meta': georegion_meta, '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, # If there's country and/or states its a country pool,
# countries and states can coexist as they're handled by the # countries and states can coexist as they're handled by the
# same step in the filterchain (countries and georegions # same step in the filterchain (countries and georegions
@ -1193,11 +1199,12 @@ class Ns1Provider(BaseProvider):
country_state_meta['country'] = sorted(country) country_state_meta['country'] = sorted(country)
if us_state: if us_state:
country_state_meta['us_state'] = sorted(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)] = { regions['{}__country'.format(pool_name)] = {
'meta': country_state_meta, '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 # If there's no targeting it's a catchall
regions['{}__catchall'.format(pool_name)] = { regions['{}__catchall'.format(pool_name)] = {
'meta': meta, '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] rule0 = record.data['dynamic']['rules'][0]
rule1 = record.data['dynamic']['rules'][1] rule1 = record.data['dynamic']['rules'][1]
rule0['geos'] = ['AF', 'EU'] rule0['geos'] = ['AF', 'EU']
rule1['geos'] = ['NA-US-CA']
rule1['geos'] = ['NA-US-CA', 'NA-CA-NL']
ret, _ = provider._params_for_A(record) ret, _ = provider._params_for_A(record)
self.assertEquals(10, len(ret['answers'])) self.assertEquals(10, len(ret['answers']))
exp = Ns1Provider._FILTER_CHAIN_WITH_REGION_AND_COUNTRY(provider, exp = Ns1Provider._FILTER_CHAIN_WITH_REGION_AND_COUNTRY(provider,
@ -1262,7 +1262,8 @@ class TestNs1ProviderDynamic(TestCase):
'iad__country': { 'iad__country': {
'meta': { 'meta': {
'note': 'rule-order:1', 'note': 'rule-order:1',
'us_state': ['CA']
'us_state': ['CA'],
'ca_province': ['NL']
} }
}, },
'lhr__georegion': { 'lhr__georegion': {
@ -1624,8 +1625,9 @@ class TestNs1ProviderDynamic(TestCase):
'lhr__country': { 'lhr__country': {
'meta': { 'meta': {
'note': 'rule-order:1 fallback:iad', 'note': 'rule-order:1 fallback:iad',
'country': ['CA'],
'country': ['MX'],
'us_state': ['OR'], 'us_state': ['OR'],
'ca_province': ['NL']
}, },
}, },
# iad will use the old style "plain" region naming. We won't # iad will use the old style "plain" region naming. We won't
@ -1669,8 +1671,9 @@ class TestNs1ProviderDynamic(TestCase):
'_order': '1', '_order': '1',
'geos': [ 'geos': [
'AF', 'AF',
'NA-CA',
'NA-US-OR',
'NA-CA-NL',
'NA-MX',
'NA-US-OR'
], ],
'pool': 'lhr', 'pool': 'lhr',
}, { }, {


Loading…
Cancel
Save