Skip to content

Commit

Permalink
Always generate the global options in named config.
Browse files Browse the repository at this point in the history
If contrail-dns doesnt generate global options and named reads the
config file in the time between contrail-dns generation and script
update, it woulnt listen on port 8094.

Change-Id: Iabb6203bbde1d900b7f20bbe2330373e001ff300
closes-bug: #1694927
  • Loading branch information
haripk committed Jun 1, 2017
1 parent da5af8c commit 7ee4969
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
36 changes: 36 additions & 0 deletions src/dns/applynamedconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@
import subprocess
import ConfigParser


class AttributeString(str):
"""
Simple string subclass to allow arbitrary attribute access.
"""
@property
def stdout(self):
return str(self)


def local(cmd, capture=False, warn_only=False, executable='/bin/sh'):
"""
Wrapper to execute local command and collect its stdout/status.
"""
output, succeeded, failed = (AttributeString(''), True, False)
try:
output = AttributeString(subprocess.check_output(
cmd, stderr=subprocess.STDOUT, shell=True, executable=executable))
except subprocess.CalledProcessError as err:
succeeded, failed = (False, True)

output.succeeded = succeeded
output.failed = failed

return output

def parse_contrail_dns_conf():

named_defaults = {
Expand Down Expand Up @@ -101,12 +127,22 @@ def parse_contrail_dns_conf():

# end parse_contrail_dns_conf

def get_base_file_hash():
return local('md5sum /etc/contrail/dns/contrail-named-base.conf')

def main():
if not os.path.exists('/etc/contrail/dns/contrail-named-base.conf'):
# parse contrail-dns.conf and build contrail-named-base.conf
parse_contrail_dns_conf()

# TODO : improve the scheme for scale configuration needs
# if the base named file hasnt changed, dont do anything
default_base_file_hash = '41be1c1ea7805f3de22f53d77453aa11'
base_file_hash = get_base_file_hash().split()
if base_file_hash[0] == default_base_file_hash:
os.system('/usr/bin/contrail-rndc -c /etc/contrail/dns/contrail-rndc.conf reconfig')
return

# open contrail-named-base.conf and read the base configs
file1 = open('/etc/contrail/dns/contrail-named-base.conf', 'r')
file1_lines = file1.readlines()
Expand Down
10 changes: 3 additions & 7 deletions src/dns/bind/named_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,9 @@ void NamedConfig::CreateNamedConf(const VirtualDnsConfig *updated_vdns) {
GetDefaultForwarders();
file_.open(named_config_file_.c_str());

ifstream pyscript("/etc/contrail/dns/applynamedconfig.py");
if (!pyscript.good()) {
WriteOptionsConfig();
WriteRndcConfig();
WriteLoggingConfig();
}

WriteOptionsConfig();
WriteRndcConfig();
WriteLoggingConfig();
WriteViewConfig(updated_vdns);

file_.flush();
Expand Down

0 comments on commit 7ee4969

Please sign in to comment.