initial servername write test

This commit is contained in:
Noah Swartz 2016-01-26 13:42:56 -08:00
parent 90c7a73146
commit 80ce6e2942

View file

@ -298,12 +298,12 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
return self.assoc[target_name]
# Try to find a reasonable vhost
vhost = self._find_best_vhost(target_name)
vhost, is_generic_host = self._find_best_vhost(target_name)
if vhost is not None:
if temp:
return vhost
if not vhost.ssl:
vhost = self.make_vhost_ssl(vhost)
vhost = self.make_vhost_ssl(vhost, is_generic_host, target_name)
self.assoc[target_name] = vhost
return vhost
@ -353,6 +353,7 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
# Points 1 - Address name with no SSL
best_candidate = None
best_points = 0
is_generic_host = False
for vhost in self.vhosts:
if vhost.modmacro is True:
@ -364,6 +365,7 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
else:
# No points given if names can't be found.
# This gets hit but doesn't register
is_generic_host = True
continue # pragma: no cover
if vhost.ssl:
@ -383,7 +385,7 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
if len(reasonable_vhosts) == 1:
best_candidate = reasonable_vhosts[0]
return best_candidate
return (best_candidate, is_generic_host)
def _non_default_vhosts(self):
"""Return all non _default_ only vhosts."""
@ -666,7 +668,7 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
"based virtual host", addr)
self.add_name_vhost(addr)
def make_vhost_ssl(self, nonssl_vhost): # pylint: disable=too-many-locals
def make_vhost_ssl(self, nonssl_vhost, is_generic_host=False, target_name=None): # pylint: disable=too-many-locals
"""Makes an ssl_vhost version of a nonssl_vhost.
Duplicates vhost and adds default ssl options
@ -692,7 +694,7 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
# Reload augeas to take into account the new vhost
self.aug.load()
#TODO: add line to write vhost name
# Get Vhost augeas path for new vhost
vh_p = self.aug.match("/files%s//* [label()=~regexp('%s')]" %
(ssl_fp, parser.case_i("VirtualHost")))
@ -709,6 +711,8 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
# Add directives
self._add_dummy_ssl_directives(vh_p)
if is_generic_host:
self._add_servername(target_name, vh_p)
# Log actions and create save notes
logger.info("Created an SSL vhost at %s", ssl_fp)
@ -859,6 +863,10 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
"insert_key_file_path")
self.parser.add_dir(vh_path, "Include", self.mod_ssl_conf)
def _add_servername(self, servername, vh_path):
self.parser.add_dir(vh_path, "ServerName", servername)
self.parser.add_dir(vh_path, "ServerAlias", servername)
def _add_name_vhost_if_necessary(self, vhost):
"""Add NameVirtualHost Directives if necessary for new vhost.