Browse Source

Add create param to Plan

pull/177/head
Ross McFarland 8 years ago
parent
commit
1e71bce907
No known key found for this signature in database GPG Key ID: 61C10C4FC8FE4A89
9 changed files with 32 additions and 23 deletions
  1. +1
    -1
      octodns/manager.py
  2. +2
    -1
      octodns/provider/base.py
  3. +2
    -1
      octodns/provider/plan.py
  4. +2
    -2
      tests/test_octodns_plan.py
  5. +6
    -3
      tests/test_octodns_provider_azuredns.py
  6. +12
    -10
      tests/test_octodns_provider_base.py
  7. +2
    -2
      tests/test_octodns_provider_cloudflare.py
  8. +1
    -1
      tests/test_octodns_provider_dyn.py
  9. +4
    -2
      tests/test_octodns_provider_googlecloud.py

+ 1
- 1
octodns/manager.py View File

@ -361,7 +361,7 @@ class Manager(object):
plan = target.plan(zone)
if plan is None:
plan = Plan(zone, zone, [])
plan = Plan(zone, zone, [], True)
target.apply(plan)
def validate_configs(self):


+ 2
- 1
octodns/provider/base.py View File

@ -64,8 +64,9 @@ class BaseProvider(BaseSource):
.join([str(c) for c in extra]))
changes += extra
create = False
if changes:
plan = Plan(existing, desired, changes,
plan = Plan(existing, desired, changes, create,
self.update_pcent_threshold,
self.delete_pcent_threshold)
self.log.info('plan: %s', plan)


+ 2
- 1
octodns/provider/plan.py View File

@ -21,12 +21,13 @@ class Plan(object):
MAX_SAFE_DELETE_PCENT = .3
MIN_EXISTING_RECORDS = 10
def __init__(self, existing, desired, changes,
def __init__(self, existing, desired, changes, create,
update_pcent_threshold=MAX_SAFE_UPDATE_PCENT,
delete_pcent_threshold=MAX_SAFE_DELETE_PCENT):
self.existing = existing
self.desired = desired
self.changes = changes
self.create = create
self.update_pcent_threshold = update_pcent_threshold
self.delete_pcent_threshold = delete_pcent_threshold


+ 2
- 2
tests/test_octodns_plan.py View File

@ -52,8 +52,8 @@ update = Update(existing, new)
delete = Delete(new)
changes = [create, delete, update]
plans = [
(simple, Plan(zone, zone, changes)),
(simple, Plan(zone, zone, changes)),
(simple, Plan(zone, zone, changes, False)),
(simple, Plan(zone, zone, changes, False)),
]


+ 6
- 3
tests/test_octodns_provider_azuredns.py View File

@ -338,8 +338,10 @@ class TestAzureDnsProvider(TestCase):
changes.append(Create(i))
deletes.append(Delete(i))
self.assertEquals(13, provider.apply(Plan(None, zone, changes)))
self.assertEquals(13, provider.apply(Plan(zone, zone, deletes)))
self.assertEquals(13, provider.apply(Plan(None, zone,
changes, False)))
self.assertEquals(13, provider.apply(Plan(zone, zone,
deletes, False)))
def test_create_zone(self):
provider = self._get_provider()
@ -354,7 +356,8 @@ class TestAzureDnsProvider(TestCase):
_get = provider._dns_client.zones.get
_get.side_effect = CloudError(Mock(status=404), err_msg)
self.assertEquals(13, provider.apply(Plan(None, desired, changes)))
self.assertEquals(13, provider.apply(Plan(None, desired, changes,
False)))
def test_check_zone_no_create(self):
provider = self._get_provider()


+ 12
- 10
tests/test_octodns_provider_base.py View File

@ -153,7 +153,7 @@ class TestBaseProvider(TestCase):
def test_safe_none(self):
# No changes is safe
Plan(None, None, []).raise_if_unsafe()
Plan(None, None, [], False).raise_if_unsafe()
def test_safe_creates(self):
# Creates are safe when existing records is under MIN_EXISTING_RECORDS
@ -164,7 +164,8 @@ class TestBaseProvider(TestCase):
'type': 'A',
'value': '1.2.3.4',
})
Plan(zone, zone, [Create(record) for i in range(10)]).raise_if_unsafe()
Plan(zone, zone, [Create(record) for i in range(10)], False) \
.raise_if_unsafe()
def test_safe_min_existing_creates(self):
# Creates are safe when existing records is over MIN_EXISTING_RECORDS
@ -183,7 +184,8 @@ class TestBaseProvider(TestCase):
'value': '2.3.4.5'
}))
Plan(zone, zone, [Create(record) for i in range(10)]).raise_if_unsafe()
Plan(zone, zone, [Create(record) for i in range(10)], False) \
.raise_if_unsafe()
def test_safe_no_existing(self):
# existing records fewer than MIN_EXISTING_RECORDS is safe
@ -195,7 +197,7 @@ class TestBaseProvider(TestCase):
})
updates = [Update(record, record), Update(record, record)]
Plan(zone, zone, updates).raise_if_unsafe()
Plan(zone, zone, updates, False).raise_if_unsafe()
def test_safe_updates_min_existing(self):
# MAX_SAFE_UPDATE_PCENT+1 fails when more
@ -219,7 +221,7 @@ class TestBaseProvider(TestCase):
Plan.MAX_SAFE_UPDATE_PCENT) + 1)]
with self.assertRaises(UnsafePlan) as ctx:
Plan(zone, zone, changes).raise_if_unsafe()
Plan(zone, zone, changes, False).raise_if_unsafe()
self.assertTrue('Too many updates' in ctx.exception.message)
@ -243,7 +245,7 @@ class TestBaseProvider(TestCase):
for i in range(int(Plan.MIN_EXISTING_RECORDS *
Plan.MAX_SAFE_UPDATE_PCENT))]
Plan(zone, zone, changes).raise_if_unsafe()
Plan(zone, zone, changes, False).raise_if_unsafe()
def test_safe_deletes_min_existing(self):
# MAX_SAFE_DELETE_PCENT+1 fails when more
@ -267,7 +269,7 @@ class TestBaseProvider(TestCase):
Plan.MAX_SAFE_DELETE_PCENT) + 1)]
with self.assertRaises(UnsafePlan) as ctx:
Plan(zone, zone, changes).raise_if_unsafe()
Plan(zone, zone, changes, False).raise_if_unsafe()
self.assertTrue('Too many deletes' in ctx.exception.message)
@ -291,7 +293,7 @@ class TestBaseProvider(TestCase):
for i in range(int(Plan.MIN_EXISTING_RECORDS *
Plan.MAX_SAFE_DELETE_PCENT))]
Plan(zone, zone, changes).raise_if_unsafe()
Plan(zone, zone, changes, False).raise_if_unsafe()
def test_safe_updates_min_existing_override(self):
safe_pcent = .4
@ -316,7 +318,7 @@ class TestBaseProvider(TestCase):
safe_pcent) + 1)]
with self.assertRaises(UnsafePlan) as ctx:
Plan(zone, zone, changes,
Plan(zone, zone, changes, False,
update_pcent_threshold=safe_pcent).raise_if_unsafe()
self.assertTrue('Too many updates' in ctx.exception.message)
@ -344,7 +346,7 @@ class TestBaseProvider(TestCase):
safe_pcent) + 1)]
with self.assertRaises(UnsafePlan) as ctx:
Plan(zone, zone, changes,
Plan(zone, zone, changes, False,
delete_pcent_threshold=safe_pcent).raise_if_unsafe()
self.assertTrue('Too many deletes' in ctx.exception.message)

+ 2
- 2
tests/test_octodns_provider_cloudflare.py View File

@ -347,7 +347,7 @@ class TestCloudflareProvider(TestCase):
'values': ['2.2.2.2', '3.3.3.3', '4.4.4.4'],
})
change = Update(existing, new)
plan = Plan(zone, zone, [change])
plan = Plan(zone, zone, [change], False)
provider._apply(plan)
provider._request.assert_has_calls([
@ -432,7 +432,7 @@ class TestCloudflareProvider(TestCase):
'value': 'ns2.foo.bar.',
})
change = Update(existing, new)
plan = Plan(zone, zone, [change])
plan = Plan(zone, zone, [change], False)
provider._apply(plan)
provider._request.assert_has_calls([


+ 1
- 1
tests/test_octodns_provider_dyn.py View File

@ -913,7 +913,7 @@ class TestDynProviderGeo(TestCase):
Delete(geo),
Delete(regular),
]
plan = Plan(None, desired, changes)
plan = Plan(None, desired, changes, False)
provider._apply(plan)
mock.assert_has_calls([
call('/Zone/unit.tests/', 'GET', {}),


+ 4
- 2
tests/test_octodns_provider_googlecloud.py View File

@ -263,7 +263,8 @@ class TestGoogleCloudProvider(TestCase):
provider.apply(Plan(
existing=[update_existing_r, delete_r],
desired=desired,
changes=changes
changes=changes,
create=False
))
calls_mock = gcloud_zone_mock.changes.return_value
@ -295,7 +296,8 @@ class TestGoogleCloudProvider(TestCase):
provider.apply(Plan(
existing=[update_existing_r, delete_r],
desired=desired,
changes=changes
changes=changes,
create=False
))
unsupported_change = Mock()


Loading…
Cancel
Save