Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions otcextensions/osclient/dns/v2/recordset.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,24 @@ def get_parser(self, prog_name):
help=_('UUID or name of the zone. Recordsets of all zones '
'will be returned if not given.')
)
parser.add_argument(
'--zone-type',
Comment thread
tischrei marked this conversation as resolved.
help=_('DNS Zone type (private/public)')
)
return parser

def take_action(self, parsed_args):
client = self.app.client_manager.dns

zone = None
attrs = {}
if parsed_args.zone_type:
attrs['zone_type'] = parsed_args.zone_type

if parsed_args.zone:

zone = client.find_zone(parsed_args.zone, ignore_missing=False)
zone = client.find_zone(parsed_args.zone, ignore_missing=False,
**attrs)

data = client.recordsets(zone=zone)

Expand All @@ -81,6 +89,10 @@ def get_parser(self, prog_name):
metavar='<zone>',
help=_('UUID or name of the zone.')
)
parser.add_argument(
'--zone-type',
help=_('DNS Zone type (private/public)')
)

parser.add_argument(
'recordset',
Expand All @@ -96,6 +108,8 @@ def take_action(self, parsed_args):

zone = client.find_zone(
parsed_args.zone,
ignore_missing=False,
zone_type=parsed_args.zone_type
)

obj = client.find_recordset(zone=zone,
Expand All @@ -118,6 +132,10 @@ def get_parser(self, prog_name):
metavar='<zone>',
help=_('UUID or name of the zone.')
)
parser.add_argument(
'--zone-type',
Comment thread
tischrei marked this conversation as resolved.
help=_('DNS Zone type (private/public)')
)

parser.add_argument(
'recordset',
Expand All @@ -131,7 +149,8 @@ def get_parser(self, prog_name):
def take_action(self, parsed_args):
if parsed_args.zone:
client = self.app.client_manager.dns
zone = client.find_zone(parsed_args.zone, ignore_missing=False)
zone = client.find_zone(parsed_args.zone, ignore_missing=False,
zone_type=parsed_args.zone_type)
for rs in parsed_args.recordset:
rs = client.find_recordset(zone=zone, name_or_id=rs,
ignore_missing=False)
Expand All @@ -150,6 +169,10 @@ def get_parser(self, prog_name):
metavar='<zone>',
help=_('UUID or name of the zone.')
)
parser.add_argument(
'--zone-type',
help=_('DNS Zone type (private/public)')
)
parser.add_argument(
'--name',
metavar='<name>',
Expand Down Expand Up @@ -193,7 +216,8 @@ def take_action(self, parsed_args):

attrs = {'records': []}

zone = client.find_zone(parsed_args.zone, ignore_missing=False)
zone = client.find_zone(parsed_args.zone, ignore_missing=False,
zone_type=parsed_args.zone_type)

if parsed_args.name:
attrs['name'] = parsed_args.name
Expand Down Expand Up @@ -228,6 +252,10 @@ def get_parser(self, prog_name):
metavar='<zone>',
help=_('UUID or name of the zone.')
)
parser.add_argument(
'--zone-type',
help=_('DNS Zone type (private/public)')
)
parser.add_argument(
'recordset',
metavar='<rs>',
Expand Down Expand Up @@ -268,7 +296,8 @@ def take_action(self, parsed_args):
if parsed_args.ttl:
attrs['ttl'] = parsed_args.ttl

zone = client.find_zone(parsed_args.zone, ignore_missing=False)
zone = client.find_zone(parsed_args.zone, ignore_missing=False,
zone_type=parsed_args.zone_type)

if parsed_args.ttl:
attrs['zone_id'] = zone.id
Expand Down
2 changes: 1 addition & 1 deletion otcextensions/osclient/dns/v2/zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get_parser(self, prog_name):
metavar='{' + ','.join(ZONE_TYPES) + '}',
type=lambda s: s.lower(),
choices=ZONE_TYPES,
help=_('Zone type.')
help=_('Zone type. Default lists only public zones.')
)
return parser

Expand Down
5 changes: 3 additions & 2 deletions otcextensions/sdk/dns/v2/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def update_zone(self, zone, **attrs):
"""
return self._update(_zone.Zone, zone, **attrs)

def find_zone(self, name_or_id, ignore_missing=True):
def find_zone(self, name_or_id, ignore_missing=True, **attrs):
"""Find a single zone

:param name_or_id: The name or ID of a zone
Expand All @@ -96,7 +96,8 @@ def find_zone(self, name_or_id, ignore_missing=True):
:returns: ``None``
"""
return self._find(_zone.Zone, name_or_id,
ignore_missing=ignore_missing)
ignore_missing=ignore_missing,
**attrs)

def add_router_to_zone(self, zone, **router):
"""Add router(VPC) to private zone
Expand Down
183 changes: 183 additions & 0 deletions otcextensions/tests/unit/osclient/dns/v2/test_recordset.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,43 @@ def test_default_zone(self):
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))

def test_private_zone(self):
arglist = [
'zn',
'--zone-type', 'private'
]

verifylist = [
('zone', 'zn'),
('zone_type', 'private')
]

# Verify cm is triggereg with default parameters
parsed_args = self.check_parser(self.cmd, arglist, verifylist)

# Set the response
self.client.api_mock.side_effect = [
self.objects
]
self.client.find_zone.side_effect = [
self._zone
]

# Trigger the action
columns, data = self.cmd.take_action(parsed_args)

self.client.find_zone.assert_called_once_with(
'zn',
zone_type='private',
ignore_missing=False,
)
self.client.api_mock.assert_called_once_with(
zone=self._zone
)

self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))


class TestShowRS(fakes.TestDNS):

Expand Down Expand Up @@ -120,6 +157,53 @@ def test_default(self):
# Trigger the action
columns, data = self.cmd.take_action(parsed_args)

self.client.find_zone.assert_called_once_with(
'zone',
ignore_missing=False,
zone_type=None
)

self.client.api_mock.assert_called_once_with(
zone=self._zone,
name_or_id='rs'
)

self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)

def test_private(self):
arglist = [
'zone',
'rs',
'--zone-type', 'private'
]

verifylist = [
('zone', 'zone'),
('recordset', 'rs'),
('zone_type', 'private')
]

# Verify cm is triggereg with default parameters
parsed_args = self.check_parser(self.cmd, arglist, verifylist)

# Set the response
self.client.find_zone.side_effect = [
self._zone
]
self.client.api_mock.side_effect = [
self._data
]

# Trigger the action
columns, data = self.cmd.take_action(parsed_args)

self.client.find_zone.assert_called_once_with(
'zone',
ignore_missing=False,
zone_type='private'
)

self.client.api_mock.assert_called_once_with(
zone=self._zone,
name_or_id='rs'
Expand Down Expand Up @@ -195,6 +279,60 @@ def test_create(self):
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)

def test_create_private(self):
arglist = [
'zn',
'--name', 'rs',
'--description', 'descr',
'--type', 'A',
'--ttl', '500',
'--record', 'a=b',
'--record', 'c=d',
'--zone-type', 'private'
]

verifylist = [
('zone', 'zn'),
('name', 'rs'),
('description', 'descr'),
('type', 'A'),
('ttl', 500),
('record', ['a=b', 'c=d']),
('zone_type', 'private')
]

# Verify cm is triggereg with default parameters
parsed_args = self.check_parser(self.cmd, arglist, verifylist)

# Set the response
self.client.find_zone.side_effect = [
self._zone
]
self.client.api_mock.side_effect = [
self._data
]

# Trigger the action
columns, data = self.cmd.take_action(parsed_args)

self.client.find_zone.assert_called_once_with(
'zn',
ignore_missing=False,
zone_type='private'
)

self.client.api_mock.assert_called_once_with(
zone=self._zone,
description='descr',
name='rs',
type='A',
ttl=500,
records=['a=b', 'c=d']
)

self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)


class TestSetRS(fakes.TestDNS):

Expand Down Expand Up @@ -321,3 +459,48 @@ def test_delete_multiple(self):

self.client.api_mock.assert_has_calls(calls)
self.assertEqual(2, self.client.api_mock.call_count)

def test_private(self):
arglist = [
'zn',
't1',
'--zone-type', 'private'
]
verifylist = [
('zone', 'zn'),
('recordset', ['t1']),
('zone_type', 'private')
]
# Verify cm is triggereg with default parameters
parsed_args = self.check_parser(self.cmd, arglist, verifylist)

# Set the response
self.client.find_zone.side_effect = [
self._zone
]

self.client.find_recordset.side_effect = [self._rs, self._rs]
self.client.api_mock.side_effect = [{}, {}]

# Trigger the action
self.cmd.take_action(parsed_args)

self.client.find_zone.assert_called_once_with(
'zn',
ignore_missing=False,
zone_type='private'
)

find_calls = [
mock.call(zone=self._zone, name_or_id='t1', ignore_missing=False),
]

self.client.find_recordset.assert_has_calls(find_calls)

calls = [
mock.call(zone=self._zone, recordset=self._rs,
ignore_missing=False),
]

self.client.api_mock.assert_has_calls(calls)
self.assertEqual(1, self.client.api_mock.call_count)
7 changes: 7 additions & 0 deletions otcextensions/tests/unit/sdk/dns/v2/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ def test_zone_delete(self):
def test_zone_find(self):
self.verify_find(self.proxy.find_zone, zone.Zone)

def test_zone_find_private(self):
self.verify_find(self.proxy.find_zone, zone.Zone,
method_kwargs={
'p1': 'v1'
},
expected_kwargs={'p1': 'v1'})

def test_zone_get(self):
self.verify_get(self.proxy.get_zone, zone.Zone)

Expand Down