From 586db067579aa5828d03b566dc0a50d5a49235da Mon Sep 17 00:00:00 2001 From: MasayaAoyama Date: Wed, 11 Jan 2017 19:00:15 +0900 Subject: [PATCH] nova/neutron format integration is failed Modify designate-sink formatv4/v6 parameter "project". "tenant" key is not contain at "context" variable, so I use "project_name" key. And "context" dict object cannot use getattr function. Change-Id: If485766a928bc2143b0b15afe99af38a6f927239 Closes-Bug: #1655581 (cherry picked from commit b23cae7b7839af2d2ed38c06a126f1e2a869ddd3) --- designate/notification_handler/neutron.py | 4 ++-- designate/notification_handler/nova.py | 2 +- .../test_notification_handler/test_neutron.py | 10 +++++----- .../test_notification_handler/test_nova.py | 17 ++++++++++------- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/designate/notification_handler/neutron.py b/designate/notification_handler/neutron.py index 035a681e7..5cacffcb3 100644 --- a/designate/notification_handler/neutron.py +++ b/designate/notification_handler/neutron.py @@ -70,8 +70,8 @@ class NeutronFloatingHandler(base.BaseAddressHandler): 'version': 4, 'address': payload['floatingip']['floating_ip_address'] } - payload['floatingip']['project'] = getattr( - context, 'tenant', None) + payload['floatingip']['project'] = context.get( + "project_name", None) self._create(addresses=[address], extra=payload['floatingip'], zone_id=zone_id, diff --git a/designate/notification_handler/nova.py b/designate/notification_handler/nova.py index 362a1949b..e3c676e27 100644 --- a/designate/notification_handler/nova.py +++ b/designate/notification_handler/nova.py @@ -65,7 +65,7 @@ class NovaFixedHandler(BaseAddressHandler): zone_id = cfg.CONF[self.name].zone_id if event_type == 'compute.instance.create.end': - payload['project'] = getattr(context, 'tenant', None) + payload['project'] = context.get("project_name", None) self._create(addresses=payload['fixed_ips'], extra=payload, zone_id=zone_id, diff --git a/designate/tests/test_notification_handler/test_neutron.py b/designate/tests/test_notification_handler/test_neutron.py index cfcd4ffd1..88f551083 100644 --- a/designate/tests/test_notification_handler/test_neutron.py +++ b/designate/tests/test_notification_handler/test_neutron.py @@ -52,7 +52,7 @@ class NeutronFloatingHandlerTest(TestCase, NotificationHandlerMixin): self.assertEqual(2, len(records)) self.plugin.process_notification( - self.admin_context, event_type, fixture['payload']) + self.admin_context.to_dict(), event_type, fixture['payload']) # Ensure we now have exactly 1 record, plus SOA & NS records = self.central_service.find_records(self.admin_context, @@ -64,7 +64,7 @@ class NeutronFloatingHandlerTest(TestCase, NotificationHandlerMixin): start_event_type = 'floatingip.update.end' start_fixture = self.get_notification_fixture( 'neutron', start_event_type + '_associate') - self.plugin.process_notification(self.admin_context, + self.plugin.process_notification(self.admin_context.to_dict(), start_event_type, start_fixture['payload']) @@ -83,7 +83,7 @@ class NeutronFloatingHandlerTest(TestCase, NotificationHandlerMixin): self.assertEqual(4, len(records)) self.plugin.process_notification( - self.admin_context, event_type, fixture['payload']) + self.admin_context.to_dict(), event_type, fixture['payload']) # Simulate the record having been deleted on the backend zone_serial = self.central_service.get_zone( @@ -101,7 +101,7 @@ class NeutronFloatingHandlerTest(TestCase, NotificationHandlerMixin): start_event_type = 'floatingip.update.end' start_fixture = self.get_notification_fixture( 'neutron', start_event_type + '_associate') - self.plugin.process_notification(self.admin_context, + self.plugin.process_notification(self.admin_context.to_dict(), start_event_type, start_fixture['payload']) @@ -119,7 +119,7 @@ class NeutronFloatingHandlerTest(TestCase, NotificationHandlerMixin): self.assertEqual(4, len(records)) self.plugin.process_notification( - self.admin_context, event_type, fixture['payload']) + self.admin_context.to_dict(), event_type, fixture['payload']) # Simulate the record having been deleted on the backend zone_serial = self.central_service.get_zone( diff --git a/designate/tests/test_notification_handler/test_nova.py b/designate/tests/test_notification_handler/test_nova.py index d157c835f..1d0d5b7f9 100644 --- a/designate/tests/test_notification_handler/test_nova.py +++ b/designate/tests/test_notification_handler/test_nova.py @@ -53,7 +53,7 @@ class NovaFixedHandlerTest(TestCase, NotificationHandlerMixin): self.assertEqual(2, len(records)) self.plugin.process_notification( - self.admin_context, event_type, fixture['payload']) + self.admin_context.to_dict(), event_type, fixture['payload']) # Ensure we now have exactly 1 more record records = self.central_service.find_records(self.admin_context, @@ -83,7 +83,7 @@ class NovaFixedHandlerTest(TestCase, NotificationHandlerMixin): self.assertEqual(2, len(recordsets)) self.plugin.process_notification( - self.admin_context, event_type, fixture['payload']) + self.admin_context.to_dict(), event_type, fixture['payload']) # Ensure we now have exactly 1 more recordset recordsets = self.central_service.find_recordsets( @@ -104,7 +104,7 @@ class NovaFixedHandlerTest(TestCase, NotificationHandlerMixin): start_event_type = 'compute.instance.create.end' start_fixture = self.get_notification_fixture('nova', start_event_type) - self.plugin.process_notification(self.admin_context, + self.plugin.process_notification(self.admin_context.to_dict(), start_event_type, start_fixture['payload']) @@ -123,7 +123,7 @@ class NovaFixedHandlerTest(TestCase, NotificationHandlerMixin): self.assertEqual(4, len(records)) self.plugin.process_notification( - self.admin_context, event_type, fixture['payload']) + self.admin_context.to_dict(), event_type, fixture['payload']) # Simulate the record having been deleted on the backend zone_serial = self.central_service.get_zone( @@ -148,7 +148,8 @@ class NovaFixedHandlerTest(TestCase, NotificationHandlerMixin): 'create_record'): finder.return_value = {'id': 'fakeid'} self.plugin.process_notification( - self.admin_context, event_type, fixture['payload']) + self.admin_context.to_dict(), + event_type, fixture['payload']) finder.assert_called_once_with( mock.ANY, type='A', zone_id=self.zone_id, name='private.example.com') @@ -164,7 +165,8 @@ class NovaFixedHandlerTest(TestCase, NotificationHandlerMixin): 'create_record'): finder.return_value = {'id': 'fakeid'} self.plugin.process_notification( - self.admin_context, event_type, fixture['payload']) + self.admin_context.to_dict(), + event_type, fixture['payload']) finder.assert_called_once_with( mock.ANY, type='A', zone_id=self.zone_id, name='private-v4.example.com') @@ -182,7 +184,8 @@ class NovaFixedHandlerTest(TestCase, NotificationHandlerMixin): 'create_record'): finder.return_value = {'id': 'fakeid'} self.plugin.process_notification( - self.admin_context, event_type, fixture['payload']) + self.admin_context.to_dict(), + event_type, fixture['payload']) finder.assert_called_once_with( mock.ANY, type='A', zone_id=self.zone_id, name='private-v4.example.com')