fix: apply_cell_name regex now matches zone files with TTL field
_generate_zone_content writes records as "name TTL IN A value" but the regex only matched "name IN A value" (no TTL), so renaming the cell never updated the DNS hostname record. Updated regex to make TTL optional. Also fixed the unit test zone fixture to use the actual generated format. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -349,13 +349,16 @@ class TestNetworkManagerApplyCellName(unittest.TestCase):
|
||||
f.write('domain=cell\n')
|
||||
with open(os.path.join(self.config_dir, 'ntp', 'chrony.conf'), 'w') as f:
|
||||
f.write('server pool.ntp.org iburst\n')
|
||||
# Create a zone file with old cell name
|
||||
# Create a zone file matching _generate_zone_content format (name TTL IN type value)
|
||||
with open(os.path.join(self.data_dir, 'dns', 'cell.zone'), 'w') as f:
|
||||
f.write('$ORIGIN cell.\n$TTL 300\n'
|
||||
'@ IN SOA ns1.cell. admin.cell. 2024010101 3600 900 604800 300\n'
|
||||
'ns1 IN A 172.20.0.3\n'
|
||||
'mycell IN A 172.20.0.2\n'
|
||||
'@ IN A 172.20.0.2\n')
|
||||
f.write('$TTL 3600\n'
|
||||
'@ IN SOA cell. admin.cell. (\n'
|
||||
' 2024010101 ; Serial\n'
|
||||
' 3600 ; Refresh\n'
|
||||
' )\n\n'
|
||||
'ns1 3600 IN A 172.20.0.3\n'
|
||||
'mycell 3600 IN A 172.20.0.2\n'
|
||||
'@ 3600 IN A 172.20.0.2\n')
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent / 'api'))
|
||||
from network_manager import NetworkManager
|
||||
self.nm = NetworkManager(self.data_dir, self.config_dir)
|
||||
@@ -368,8 +371,10 @@ class TestNetworkManagerApplyCellName(unittest.TestCase):
|
||||
mock_run.return_value = MagicMock(returncode=0)
|
||||
result = self.nm.apply_cell_name('mycell', 'newcell')
|
||||
zone = open(os.path.join(self.data_dir, 'dns', 'cell.zone')).read()
|
||||
self.assertIn('newcell IN A 172.20.0.2', zone)
|
||||
self.assertNotIn('mycell IN A', zone)
|
||||
self.assertIn('newcell', zone)
|
||||
self.assertIn('172.20.0.2', zone)
|
||||
# old name must be gone from A records (the @ record still contains 172.20.0.2)
|
||||
self.assertNotIn('mycell 3600 IN A', zone)
|
||||
self.assertIn('cell-dns', ' '.join(result['restarted']))
|
||||
|
||||
@patch('subprocess.run')
|
||||
|
||||
Reference in New Issue
Block a user