Fix YAMLAdapter when optional attributes are missing
So far, using YAMLAdapter in pools.yaml context, without providing all
of the pools.yaml attributes altogether, failed because of YAMLAdapter.
An example could be an end user who wouldn't like to deploy catalog
zones in its pools and therefore would drop that attribute from the
pools.yaml file, like in
designate/tests/resources/pools_yaml/multiple-pools.yaml.
Running any designate-manage pool command on a file without all of the
pools.yaml attributes will fail with the following error message:
designate.exceptions.AdapterNotFound:
Adapter for None to format YAML not found
This patch fixes it.
Closes-Bug: #2064720
Change-Id: I214cfc05a834d97a61d0236ab223470631bfc405
(cherry picked from commit 6cc0a7d887
)
This commit is contained in:
parent
50b04e630c
commit
7e58bdd525
@ -49,6 +49,10 @@ class YAMLAdapter(base.DesignateAdapter):
|
|||||||
# if not, move on
|
# if not, move on
|
||||||
new_obj = getattr(obj, key, None)
|
new_obj = getattr(obj, key, None)
|
||||||
obj_key = key
|
obj_key = key
|
||||||
|
|
||||||
|
if new_obj is None:
|
||||||
|
continue
|
||||||
|
|
||||||
# Check if this item is a relation (another DesignateObject that
|
# Check if this item is a relation (another DesignateObject that
|
||||||
# will need to be converted itself
|
# will need to be converted itself
|
||||||
if hasattr(obj.FIELDS.get(obj_key, {}), 'objname'):
|
if hasattr(obj.FIELDS.get(obj_key, {}), 'objname'):
|
||||||
|
@ -68,6 +68,21 @@ class ManagePoolTestCase(designate.tests.functional.TestCase):
|
|||||||
'Default PowerDNS 4 Pool', ''.join(self.command.output_message)
|
'Default PowerDNS 4 Pool', ''.join(self.command.output_message)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_show_config_catalog_zone(self):
|
||||||
|
self.command._setup()
|
||||||
|
self.command._create_pool(get_pools('pools-catalog-zone.yaml')[0])
|
||||||
|
|
||||||
|
pool_id = self.central_service.find_pool(
|
||||||
|
self.admin_context, {'name': 'default'}).id
|
||||||
|
|
||||||
|
self.command.show_config(pool_id)
|
||||||
|
|
||||||
|
self.print_result.assert_called_once()
|
||||||
|
self.assertIn('Pool Configuration', self.command.output_message[1])
|
||||||
|
self.assertIn(
|
||||||
|
'Default PowerDNS 4 Pool', ''.join(self.command.output_message)
|
||||||
|
)
|
||||||
|
|
||||||
@mock.patch.object(service.Service, 'find_pool',
|
@mock.patch.object(service.Service, 'find_pool',
|
||||||
side_effect=oslo_messaging.MessagingTimeout())
|
side_effect=oslo_messaging.MessagingTimeout())
|
||||||
def test_show_config_rpc_timeout(self, mock_find_pool):
|
def test_show_config_rpc_timeout(self, mock_find_pool):
|
||||||
|
36
designate/tests/resources/pools_yaml/pools-catalog-zone.yaml
Normal file
36
designate/tests/resources/pools_yaml/pools-catalog-zone.yaml
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: default
|
||||||
|
description: Default PowerDNS 4 Pool
|
||||||
|
|
||||||
|
attributes:
|
||||||
|
type: internal
|
||||||
|
|
||||||
|
ns_records:
|
||||||
|
- hostname: ns1-1.example.org.
|
||||||
|
priority: 1
|
||||||
|
- hostname: ns1-2.example.org.
|
||||||
|
priority: 2
|
||||||
|
|
||||||
|
nameservers:
|
||||||
|
- host: 192.0.2.2
|
||||||
|
port: 53
|
||||||
|
- host: 192.0.2.3
|
||||||
|
port: 53
|
||||||
|
|
||||||
|
targets:
|
||||||
|
- type: pdns4
|
||||||
|
description: PowerDNS 4 Server
|
||||||
|
masters:
|
||||||
|
- host: 192.0.2.1
|
||||||
|
port: 5354
|
||||||
|
options:
|
||||||
|
api_endpoint: http://192.0.2.1:8081
|
||||||
|
api_token: api_key
|
||||||
|
also_notifies:
|
||||||
|
- host: 192.0.2.4
|
||||||
|
port: 53
|
||||||
|
|
||||||
|
catalog_zone:
|
||||||
|
catalog_zone_fqdn: example.org.
|
||||||
|
catalog_zone_refresh: '60'
|
@ -30,7 +30,3 @@
|
|||||||
also_notifies:
|
also_notifies:
|
||||||
- host: 192.0.2.4
|
- host: 192.0.2.4
|
||||||
port: 53
|
port: 53
|
||||||
|
|
||||||
catalog_zone:
|
|
||||||
catalog_zone_fqdn: example.org.
|
|
||||||
catalog_zone_refresh: '60'
|
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
So far, the yaml Adapter made every designate-manage pool command
|
||||||
|
fail if the pools.yaml file was missing any of the pool attributes.
|
||||||
|
This patch makes the adapter to continue without raising any error.
|
Loading…
Reference in New Issue
Block a user