Skip to content

Commit 47417cc

Browse files
#1195 refactored the vs/hw dns-sync commands, moved most of the logic to the managers/dns.py file. Fixed up unit tests to take account of the changes
1 parent 27a1d3d commit 47417cc

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

SoftLayer/CLI/hardware/dns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def cli(env, identifier, a_record, aaaa_record, ptr, ttl):
5252

5353
if both or ptr:
5454
# getReverseDomainRecords returns a list of 1 element, so just get the top.
55-
ptr_domains = env.client['Virtual_Guest'].getReverseDomainRecords(id=instance['id']).pop()
55+
ptr_domains = env.client['Hardware_Server'].getReverseDomainRecords(id=instance['id']).pop()
5656
dns.sync_ptr_record(ptr_domains, instance['primaryIpAddress'], instance['fullyQualifiedDomainName'], ttl)
5757

5858
if aaaa_record:

SoftLayer/managers/dns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def sync_ptr_record(self, ptr_domains, ip_address, fqdn, ttl=7200):
269269
host_rec = ip_address.split('.')[-1]
270270
edit_ptr = None
271271
for ptr in ptr_domains['resourceRecords']:
272-
if ptr['host'] == host_rec:
272+
if ptr.get('host', '') == host_rec:
273273
ptr['ttl'] = ttl
274274
edit_ptr = ptr
275275
break

tests/CLI/modules/server_tests.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import sys
1313

1414
from SoftLayer.CLI import exceptions
15+
from SoftLayer import SoftLayerError
1516
from SoftLayer import testing
1617

1718
import json
@@ -660,7 +661,7 @@ def test_dns_sync_both(self, confirm_mock):
660661
createAargs = ({
661662
'type': 'a',
662663
'host': 'hardware-test1',
663-
'domainId': 98765,
664+
'domainId': 12345, # from SoftLayer_Account::getDomains
664665
'data': '172.16.1.100',
665666
'ttl': 7200
666667
},)
@@ -715,7 +716,7 @@ def test_dns_sync_v6(self, confirm_mock):
715716
createV6args = ({
716717
'type': 'aaaa',
717718
'host': 'hardware-test1',
718-
'domainId': 98765,
719+
'domainId': 12345, # from SoftLayer_Account::getDomains
719720
'data': '2607:f0d0:1b01:0023:0000:0000:0000:0004',
720721
'ttl': 7200
721722
},)
@@ -748,8 +749,8 @@ def test_dns_sync_v6(self, confirm_mock):
748749
'getResourceRecords')
749750
getResourceRecords.return_value = [v6Record, v6Record]
750751
result = self.run_command(['hw', 'dns-sync', '--aaaa-record', '1000'])
751-
self.assertEqual(result.exit_code, 2)
752-
self.assertIsInstance(result.exception, exceptions.CLIAbort)
752+
self.assertEqual(result.exit_code, 1)
753+
self.assertIsInstance(result.exception, SoftLayerError)
753754

754755
@mock.patch('SoftLayer.CLI.formatting.confirm')
755756
def test_dns_sync_edit_a(self, confirm_mock):
@@ -779,8 +780,8 @@ def test_dns_sync_edit_a(self, confirm_mock):
779780
'host': 'hardware-test1', 'type': 'a'}
780781
]
781782
result = self.run_command(['hw', 'dns-sync', '-a', '1000'])
782-
self.assertEqual(result.exit_code, 2)
783-
self.assertIsInstance(result.exception, exceptions.CLIAbort)
783+
self.assertEqual(result.exit_code, 1)
784+
self.assertIsInstance(result.exception, SoftLayerError)
784785

785786
@mock.patch('SoftLayer.CLI.formatting.confirm')
786787
def test_dns_sync_edit_ptr(self, confirm_mock):
@@ -789,7 +790,7 @@ def test_dns_sync_edit_ptr(self, confirm_mock):
789790
'getReverseDomainRecords')
790791
getReverseDomainRecords.return_value = [{
791792
'networkAddress': '172.16.1.100',
792-
'name': '2.240.16.172.in-addr.arpa',
793+
'name': '100.1.16.172.in-addr.arpa',
793794
'resourceRecords': [{'data': 'test.softlayer.com.',
794795
'id': 123,
795796
'host': '100'}],

tests/CLI/modules/vs/vs_tests.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from SoftLayer.CLI import exceptions
1313
from SoftLayer.fixtures import SoftLayer_Virtual_Guest as SoftLayer_Virtual_Guest
1414
from SoftLayer import SoftLayerAPIError
15+
from SoftLayer import SoftLayerError
1516
from SoftLayer import testing
1617

1718

@@ -310,7 +311,7 @@ def test_dns_sync_both(self, confirm_mock):
310311
createAargs = ({
311312
'type': 'a',
312313
'host': 'vs-test1',
313-
'domainId': 98765,
314+
'domainId': 12345, # from SoftLayer_Account::getDomains
314315
'data': '172.16.240.2',
315316
'ttl': 7200
316317
},)
@@ -365,7 +366,7 @@ def test_dns_sync_v6(self, confirm_mock):
365366
createV6args = ({
366367
'type': 'aaaa',
367368
'host': 'vs-test1',
368-
'domainId': 98765,
369+
'domainId': 12345,
369370
'data': '2607:f0d0:1b01:0023:0000:0000:0000:0004',
370371
'ttl': 7200
371372
},)
@@ -398,8 +399,8 @@ def test_dns_sync_v6(self, confirm_mock):
398399
'getResourceRecords')
399400
getResourceRecords.return_value = [v6Record, v6Record]
400401
result = self.run_command(['vs', 'dns-sync', '--aaaa-record', '100'])
401-
self.assertEqual(result.exit_code, 2)
402-
self.assertIsInstance(result.exception, exceptions.CLIAbort)
402+
self.assertEqual(result.exit_code, 1)
403+
self.assertIsInstance(result.exception, SoftLayerError)
403404

404405
@mock.patch('SoftLayer.CLI.formatting.confirm')
405406
def test_dns_sync_edit_a(self, confirm_mock):
@@ -429,8 +430,8 @@ def test_dns_sync_edit_a(self, confirm_mock):
429430
'host': 'vs-test1', 'type': 'a'}
430431
]
431432
result = self.run_command(['vs', 'dns-sync', '-a', '100'])
432-
self.assertEqual(result.exit_code, 2)
433-
self.assertIsInstance(result.exception, exceptions.CLIAbort)
433+
self.assertEqual(result.exit_code, 1)
434+
self.assertIsInstance(result.exception, SoftLayerError)
434435

435436
@mock.patch('SoftLayer.CLI.formatting.confirm')
436437
def test_dns_sync_edit_ptr(self, confirm_mock):

0 commit comments

Comments
 (0)