Skip to content

Commit 704d331

Browse files
authored
Merge pull request #1691 from grycap/devel
Improve additional_dns_names code
2 parents 206a627 + 5da25d2 commit 704d331

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

IM/connectors/CloudConnector.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -635,13 +635,19 @@ def get_dns_entries(self, vm):
635635
additional_dns_names = system.getValue('net_interface.%d.additional_dns_names' % num_conn)
636636
if additional_dns_names:
637637
for dns_name in additional_dns_names:
638-
dns_parts = dns_name.split("@")
639-
if len(dns_parts) != 2:
640-
self.log_error("Invalid format for additional name: %s." % dns_name)
641-
self.error_messages = "Invalid format for additional name: %s." % dns_name
642-
break
643-
hostname = dns_parts[0]
644-
domain = dns_parts[1]
638+
if "@" in dns_name:
639+
dns_parts = dns_name.split("@")
640+
if len(dns_parts) != 2:
641+
self.log_error("Invalid format for additional name: %s." % dns_name)
642+
self.error_messages = "Invalid format for additional name: %s." % dns_name
643+
break
644+
hostname = dns_parts[0]
645+
domain = dns_parts[1]
646+
else:
647+
dns_parts = dns_name.split(".")
648+
hostname = dns_parts[0]
649+
domain = ".".join(dns_parts[1:])
650+
645651
if not domain.endswith("."):
646652
domain += "."
647653
if domain != "localdomain." and ip and hostname:

test/unit/connectors/Linode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def test_30_updateVMInfo(self, get_dns_driver, get_driver):
184184
memory.size=512m and
185185
net_interface.0.connection = 'net' and
186186
net_interface.0.dns_name = 'test.domain.com' and
187-
net_interface.0.additional_dns_names = ['some.test@domain.com'] and
187+
net_interface.0.additional_dns_names = ['other-test.domain.com'] and
188188
disk.0.os.name = 'linux' and
189189
disk.0.image.url = 'lin://linode/ubuntu' and
190190
disk.0.os.credentials.username = 'user' and
@@ -246,7 +246,7 @@ def test_30_updateVMInfo(self, get_dns_driver, get_driver):
246246
self.assertEqual(dns_driver.create_record.call_args_list[0][0][0], 'test')
247247
self.assertEqual(dns_driver.create_record.call_args_list[0][0][2], 'A')
248248
self.assertEqual(dns_driver.create_record.call_args_list[0][0][3], '8.8.8.8')
249-
self.assertEqual(dns_driver.create_record.call_args_list[1][0][0], 'some.test')
249+
self.assertEqual(dns_driver.create_record.call_args_list[1][0][0], 'other-test')
250250

251251
self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
252252

0 commit comments

Comments
 (0)