mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Add create param to Plan
This commit is contained in:
+1
-1
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)),
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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([
|
||||
|
||||
@@ -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', {}),
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user