Merge "Type checking in pool manager target sync"
This commit is contained in:
commit
61bc6c8174
@ -343,6 +343,15 @@ class Service(service.RPCService, coordination.CoordinationMixin,
|
||||
timestamp_dt = datetime.fromtimestamp(timestamp)
|
||||
|
||||
for zone in zones:
|
||||
if isinstance(zone.created_at, datetime):
|
||||
zone_created_at = zone.created_at
|
||||
elif isinstance(zone.created_at, str):
|
||||
zone_created_at = datetime.strptime(zone.created_at,
|
||||
"%Y-%m-%dT%H:%M:%S.%f")
|
||||
else:
|
||||
raise Exception("zone.created_at is of type %s" %
|
||||
str(type(zone.created_at)))
|
||||
|
||||
if zone.status == 'DELETED':
|
||||
# Remove any other ops for this zone
|
||||
for zone_op in zone_ops:
|
||||
@ -350,11 +359,9 @@ class Service(service.RPCService, coordination.CoordinationMixin,
|
||||
zone_ops.remove(zone_op)
|
||||
# If the zone was created before the timestamp delete it,
|
||||
# otherwise, it will just never be created
|
||||
if (datetime.strptime(zone.created_at, "%Y-%m-%dT%H:%M:%S.%f")
|
||||
<= timestamp_dt):
|
||||
if (zone_created_at <= timestamp_dt):
|
||||
zone_ops.append((zone, 'DELETE'))
|
||||
elif (datetime.strptime(zone.created_at, "%Y-%m-%dT%H:%M:%S.%f") >
|
||||
timestamp_dt):
|
||||
elif (zone_created_at > timestamp_dt):
|
||||
# If the zone was created after the timestamp
|
||||
for zone_op in zone_ops:
|
||||
if (
|
||||
|
@ -18,6 +18,7 @@
|
||||
Unit tests
|
||||
"""
|
||||
import unittest
|
||||
from datetime import datetime
|
||||
|
||||
from mock import call
|
||||
from mock import Mock
|
||||
@ -233,6 +234,32 @@ class PoolManagerTest(test.BaseTestCase):
|
||||
|
||||
self.assertEqual(3, self.pm.update_zone.call_count)
|
||||
|
||||
@patch.object(pm_module.DesignateContext, 'get_admin_context')
|
||||
def test_target_sync(self, mock_get_ctx, *mocks):
|
||||
mock_ctx = mock_get_ctx.return_value
|
||||
date = 1463154200
|
||||
older_date = datetime.fromtimestamp(1463154000)
|
||||
newer_date = datetime.fromtimestamp(1463154300)
|
||||
|
||||
zones = [
|
||||
RwObject(name='a_zone', status='ACTIVE', created_at=older_date),
|
||||
RwObject(name='b_zone', status='ACTIVE', created_at=newer_date),
|
||||
RwObject(name='c_zone', status='DELETED', created_at=older_date,
|
||||
serial=1),
|
||||
]
|
||||
|
||||
self.pm._delete_zone_on_target = Mock()
|
||||
self.pm._create_zone_on_target = Mock()
|
||||
self.pm._update_zone_on_target = Mock()
|
||||
self.pm.mdns_api.poll_for_serial_number = Mock()
|
||||
target = Mock()
|
||||
|
||||
self.pm._target_sync(mock_ctx, zones, target, date)
|
||||
|
||||
self.assertEqual(1, self.pm._delete_zone_on_target.call_count)
|
||||
self.assertEqual(1, self.pm._create_zone_on_target.call_count)
|
||||
self.assertEqual(1, self.pm._update_zone_on_target.call_count)
|
||||
|
||||
@patch.object(pm_module.DesignateContext, 'get_admin_context')
|
||||
def test_create_zone(self, mock_get_ctx, *mocks):
|
||||
z = RwObject(name='a_zone', serial=1)
|
||||
|
Loading…
Reference in New Issue
Block a user