Adding "address" to jinja env
* "address" function was added to jinja env. This function takes service name as a parameter and returns address of the service (<service_name>.<namespace>) currently * etcd_urls no longer being used, "address" function will be used instead Change-Id: Ibbb12e016570936468effbbd0648d4690abe3aab
This commit is contained in:
parent
af11052680
commit
5adb1110b7
|
@ -15,7 +15,6 @@ import jinja2
|
|||
import json
|
||||
import netifaces
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
|
||||
|
||||
VARIABLES = {}
|
||||
|
@ -167,8 +166,8 @@ def openstackclient_preexec_fn():
|
|||
os.environ["OS_PASSWORD"] = VARIABLES['openstack_user_password']
|
||||
os.environ["OS_USERNAME"] = VARIABLES['openstack_user_name']
|
||||
os.environ["OS_PROJECT_NAME"] = VARIABLES['openstack_project_name']
|
||||
os.environ["OS_AUTH_URL"] = 'http://keystone:%s/v3' % VARIABLES[
|
||||
'keystone_admin_port']
|
||||
os.environ["OS_AUTH_URL"] = 'http://%s:%s/v3' % (
|
||||
address('keystone'), VARIABLES['keystone_admin_port'])
|
||||
return result
|
||||
|
||||
|
||||
|
@ -195,17 +194,23 @@ def execute_cmd(cmd, user=None):
|
|||
return subprocess.Popen(cmd_str(cmd), **kwargs)
|
||||
|
||||
|
||||
def address(service):
|
||||
return '%s.%s' % (service, VARIABLES['namespace'])
|
||||
|
||||
|
||||
def jinja_render_file(path):
|
||||
env = jinja2.Environment(loader=jinja2.FileSystemLoader(
|
||||
os.path.dirname(path)))
|
||||
|
||||
env.globals['address'] = address
|
||||
content = env.get_template(os.path.basename(path)).render(VARIABLES)
|
||||
|
||||
return content
|
||||
|
||||
|
||||
def jinja_render_cmd(cmd):
|
||||
return jinja2.Environment().from_string(cmd).render(VARIABLES)
|
||||
env = jinja2.Environment()
|
||||
env.globals['address'] = address
|
||||
return env.from_string(cmd).render(VARIABLES)
|
||||
|
||||
|
||||
def create_files(files):
|
||||
|
@ -247,9 +252,9 @@ def get_etcd_client():
|
|||
(VARIABLES["network_topology"]["private"]["address"],
|
||||
VARIABLES["etcd_client_port"]))
|
||||
else:
|
||||
for etcd_machine in VARIABLES["etcd_urls"].split(","):
|
||||
parsed_url = parse.urlparse(etcd_machine)
|
||||
etcd_machines.append((parsed_url.hostname, parsed_url.port))
|
||||
etcd_machines.append(
|
||||
(address('etcd'), VARIABLES["etcd_client_port"])
|
||||
)
|
||||
|
||||
etcd_machines_str = " ".join(["%s:%d" % (h, p) for h, p in etcd_machines])
|
||||
LOG.debug("Using the following etcd urls: \"%s\"", etcd_machines_str)
|
||||
|
|
|
@ -148,7 +148,8 @@ class TestGetETCDClient(base.TestCase):
|
|||
def test_get_etcd_client(self):
|
||||
start_script.VARIABLES = {
|
||||
"role_name": "banana",
|
||||
"etcd_urls": "http://etcd1:10042,http://etcd2:10042"
|
||||
"namespace": "ccp",
|
||||
"etcd_client_port": 1234
|
||||
}
|
||||
with mock.patch("etcd.Client") as m_etcd:
|
||||
expected_value = object()
|
||||
|
@ -156,7 +157,7 @@ class TestGetETCDClient(base.TestCase):
|
|||
etcd_client = start_script.get_etcd_client()
|
||||
self.assertIs(expected_value, etcd_client)
|
||||
m_etcd.assert_called_once_with(
|
||||
host=(("etcd1", 10042), ("etcd2", 10042)),
|
||||
host=(('etcd.ccp', 1234),),
|
||||
allow_reconnect=True,
|
||||
read_timeout=2)
|
||||
|
||||
|
|
Loading…
Reference in New Issue