diff options
Diffstat (limited to 'designate')
-rwxr-xr-x | designate/backend/impl_dynect.py | 4 | ||||
-rw-r--r-- | designate/dnsutils.py | 4 | ||||
-rw-r--r-- | designate/notification_handler/base.py | 6 | ||||
-rw-r--r-- | designate/tests/__init__.py | 8 | ||||
-rw-r--r-- | designate/tests/test_notification_handler/test_base.py | 88 | ||||
-rw-r--r-- | designate/worker/processing.py | 4 |
6 files changed, 99 insertions, 15 deletions
diff --git a/designate/backend/impl_dynect.py b/designate/backend/impl_dynect.py index 19f586f5..7e30443c 100755 --- a/designate/backend/impl_dynect.py +++ b/designate/backend/impl_dynect.py @@ -202,11 +202,11 @@ class DynClient(object): self._http_log_req(method, url, kwargs) if self.timings: - start_time = time.time() + start_time = time.monotonic() resp = self.http.request(method, url, **kwargs) if self.timings: self.times.append(("%s %s" % (method, url), - start_time, time.time())) + start_time, time.monotonic())) self._http_log_resp(resp) if resp.status_code >= 400: diff --git a/designate/dnsutils.py b/designate/dnsutils.py index 81df8409..43c45dff 100644 --- a/designate/dnsutils.py +++ b/designate/dnsutils.py @@ -203,12 +203,12 @@ class ZoneLock(object): with self.lock: # If no one holds the lock for the zone, grant it if zone not in self.data: - self.data[zone] = time.time() + self.data[zone] = time.monotonic() return True # Otherwise, get the time that it was locked locktime = self.data[zone] - now = time.time() + now = time.monotonic() period = now - locktime diff --git a/designate/notification_handler/base.py b/designate/notification_handler/base.py index 8a270eb3..159eb786 100644 --- a/designate/notification_handler/base.py +++ b/designate/notification_handler/base.py @@ -144,8 +144,8 @@ class NotificationHandler(ExtensionPlugin): class BaseAddressHandler(NotificationHandler): - default_formatv4 = ('%(hostname)s.%(domain)s',) - default_formatv6 = ('%(hostname)s.%(domain)s',) + default_formatv4 = ('%(hostname)s.%(zone)s',) + default_formatv6 = ('%(hostname)s.%(zone)s',) def _get_ip_data(self, addr_dict): ip = addr_dict['address'] @@ -193,7 +193,7 @@ class BaseAddressHandler(NotificationHandler): """ LOG.debug('Using Zone ID: %s', zone_id) zone = self.get_zone(zone_id) - LOG.debug('Domain: %r', zone) + LOG.debug('Zone: %r', zone) data = extra.copy() LOG.debug('Event data: %s', data) diff --git a/designate/tests/__init__.py b/designate/tests/__init__.py index d65ef2bf..ac371ab7 100644 --- a/designate/tests/__init__.py +++ b/designate/tests/__init__.py @@ -820,7 +820,7 @@ class TestCase(base.BaseTestCase): Zone imports spawn a thread to parse the zone file and insert the data. This waits for this process before continuing """ - start_time = time.time() + start_time = time.monotonic() while True: # Retrieve it, and ensure it's the same zone_import = self.central_service.get_zone_import( @@ -835,7 +835,7 @@ class TestCase(base.BaseTestCase): if error_is_ok and zone_import.status != 'PENDING': break - if (time.time() - start_time) > max_wait: + if (time.monotonic() - start_time) > max_wait: break time.sleep(0.5) @@ -870,8 +870,8 @@ class TestCase(base.BaseTestCase): Poll every `interval` seconds. `condition` can be a callable. (Caution: some mocks behave both as values and callables.) """ - t_max = time.time() + timeout - while time.time() < t_max: + t_max = time.monotonic() + timeout + while time.monotonic() < t_max: if callable(condition): result = condition() else: diff --git a/designate/tests/test_notification_handler/test_base.py b/designate/tests/test_notification_handler/test_base.py index f1a10dab..c35d4304 100644 --- a/designate/tests/test_notification_handler/test_base.py +++ b/designate/tests/test_notification_handler/test_base.py @@ -13,6 +13,8 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +from unittest import expectedFailure + from designate.notification_handler import base from designate.tests import TestCase @@ -24,6 +26,8 @@ class InheritFormBaseAddressHandler(base.BaseAddressHandler): we need to create something to inherit from it so we have something instantiatable. """ + __plugin_name__ = 'nova_fixed' + def get_event_types(self): pass @@ -35,11 +39,91 @@ class InheritFormBaseAddressHandler(base.BaseAddressHandler): class BaseAddressHandlerTest(TestCase): + def setUp(self): + super(BaseAddressHandlerTest, self).setUp() + + self.zone = self.create_zone() + self.zone_id = self.zone['id'] + self.base = InheritFormBaseAddressHandler() + def test_get_ip_data_support_v6(self): addr_dict = {'address': '1762::B03:1:AF18', 'version': 6} - baseaddresshandler = InheritFormBaseAddressHandler() - observe = baseaddresshandler._get_ip_data(addr_dict) + observe = self.base._get_ip_data(addr_dict) expect = {'octet1': 'B03', 'octet0': '1762', 'octet3': 'AF18', 'octet2': '1', 'ip_version': 6, 'ip_address': '1762--B03-1-AF18'} self.assertEqual(observe, expect) + + def test_create_record(self): + self.base._create([ + {'address': '172.16.0.15', 'version': 4}], + {'hostname': 'test01'}, + self.zone_id, + resource_id='1fb1feba-2ea4-4925-ba2c-9a3706348a70', + resource_type='instance' + ) + + criterion = { + 'zone_id': self.zone_id, + 'type': 'A', + } + + recordsets = self.central_service.find_recordsets( + self.admin_context, criterion) + + self.assertEqual('test01.example.com.', recordsets[0].name) + self.assertEqual('A', recordsets[0].type) + + def test_delete_record(self): + self.base._create([ + {'address': '172.16.0.15', 'version': 4}], + {'hostname': 'test01'}, + self.zone_id, + resource_id='6d6deb76-e4e7-492e-8f9d-4d906653c511', + resource_type='instance' + ) + + criterion = { + 'zone_id': self.zone_id, + 'type': 'A', + } + + recordsets = self.central_service.find_recordsets( + self.admin_context, criterion) + + self.assertEqual('test01.example.com.', recordsets[0].name) + self.assertEqual('A', recordsets[0].type) + + self.base._delete(self.zone_id, '6d6deb76-e4e7-492e-8f9d-4d906653c511') + + recordsets = self.central_service.find_recordsets( + self.admin_context, criterion) + self.assertEqual(0, len(recordsets)) + + @expectedFailure + def test_delete_record_with_no_zone_id(self): + self.base._create([ + {'address': '172.16.0.15', 'version': 4}], + {'hostname': 'test01'}, + self.zone_id, + resource_id='6d6deb76-e4e7-492e-8f9d-4d906653c511', + resource_type='instance' + ) + + criterion = { + 'zone_id': self.zone_id, + 'type': 'A', + } + + recordsets = self.central_service.find_recordsets( + self.admin_context, criterion) + + self.assertEqual('test01.example.com.', recordsets[0].name) + self.assertEqual('A', recordsets[0].type) + + # NOTE(eandersson): _delete should succeed even without a zone_id. + self.base._delete(None, '6d6deb76-e4e7-492e-8f9d-4d906653c511') + + recordsets = self.central_service.find_recordsets( + self.admin_context, criterion) + self.assertEqual(0, len(recordsets)) diff --git a/designate/worker/processing.py b/designate/worker/processing.py index 59f8fcbe..cf280033 100644 --- a/designate/worker/processing.py +++ b/designate/worker/processing.py @@ -70,9 +70,9 @@ class Executor(object): if callable(tasks): tasks = [tasks] - start_time = time.time() + start_time = time.monotonic() results = [r for r in self._executor.map(self.do, tasks)] - elapsed_time = time.time() - start_time + elapsed_time = time.monotonic() - start_time LOG.debug( 'Finished Task(s): %(tasks)s in %(time)fs', |