Generate stack name as a valid hostname
Truncate cluster name to 30 characters, map ('_', '.') to '-' and remove non alpha-numeric characters. Change-Id: Ibb2bddc5b602a34d0e2bebd1f6bb197669bf21ec Close-Bug: #1718947
This commit is contained in:
parent
375f44ceda
commit
283c093187
|
@ -14,6 +14,9 @@ import abc
|
||||||
import os
|
import os
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
from string import ascii_letters
|
||||||
|
from string import digits
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
|
@ -109,8 +112,18 @@ class HeatDriver(driver.Driver):
|
||||||
env_files)
|
env_files)
|
||||||
tpl_files.update(env_map)
|
tpl_files.update(env_map)
|
||||||
|
|
||||||
|
# Make sure we end up with a valid hostname
|
||||||
|
valid_chars = set(ascii_letters + digits + '-')
|
||||||
|
|
||||||
|
# valid hostnames are 63 chars long, leaving enough room
|
||||||
|
# to add the random id (for uniqueness)
|
||||||
|
stack_name = cluster.name[:30]
|
||||||
|
stack_name = stack_name.replace('_', '-')
|
||||||
|
stack_name = stack_name.replace('.', '-')
|
||||||
|
stack_name = ''.join(filter(valid_chars.__contains__, stack_name))
|
||||||
|
|
||||||
# Make sure no duplicate stack name
|
# Make sure no duplicate stack name
|
||||||
stack_name = '%s-%s' % (cluster.name, short_id.generate_id())
|
stack_name = '%s-%s' % (stack_name, short_id.generate_id())
|
||||||
if cluster_create_timeout:
|
if cluster_create_timeout:
|
||||||
heat_timeout = cluster_create_timeout
|
heat_timeout = cluster_create_timeout
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -755,7 +755,7 @@ class TestClusterConductorWithK8s(base.TestCase):
|
||||||
mock_generate_id):
|
mock_generate_id):
|
||||||
|
|
||||||
mock_generate_id.return_value = 'xx-xx-xx-xx'
|
mock_generate_id.return_value = 'xx-xx-xx-xx'
|
||||||
expected_stack_name = 'expected_stack_name-xx-xx-xx-xx'
|
expected_stack_name = 'expected-stack-name-xx-xx-xx-xx'
|
||||||
expected_template_contents = 'template_contents'
|
expected_template_contents = 'template_contents'
|
||||||
dummy_cluster_name = 'expected_stack_name'
|
dummy_cluster_name = 'expected_stack_name'
|
||||||
expected_timeout = 15
|
expected_timeout = 15
|
||||||
|
@ -796,7 +796,7 @@ class TestClusterConductorWithK8s(base.TestCase):
|
||||||
mock_generate_id):
|
mock_generate_id):
|
||||||
|
|
||||||
mock_generate_id.return_value = 'xx-xx-xx-xx'
|
mock_generate_id.return_value = 'xx-xx-xx-xx'
|
||||||
expected_stack_name = 'expected_stack_name-xx-xx-xx-xx'
|
expected_stack_name = 'expected-stack-name-xx-xx-xx-xx'
|
||||||
expected_template_contents = 'template_contents'
|
expected_template_contents = 'template_contents'
|
||||||
dummy_cluster_name = 'expected_stack_name'
|
dummy_cluster_name = 'expected_stack_name'
|
||||||
expected_timeout = CONF.cluster_heat.create_timeout
|
expected_timeout = CONF.cluster_heat.create_timeout
|
||||||
|
@ -836,7 +836,7 @@ class TestClusterConductorWithK8s(base.TestCase):
|
||||||
mock_generate_id):
|
mock_generate_id):
|
||||||
|
|
||||||
mock_generate_id.return_value = 'xx-xx-xx-xx'
|
mock_generate_id.return_value = 'xx-xx-xx-xx'
|
||||||
expected_stack_name = 'expected_stack_name-xx-xx-xx-xx'
|
expected_stack_name = 'expected-stack-name-xx-xx-xx-xx'
|
||||||
expected_template_contents = 'template_contents'
|
expected_template_contents = 'template_contents'
|
||||||
dummy_cluster_name = 'expected_stack_name'
|
dummy_cluster_name = 'expected_stack_name'
|
||||||
cluster_timeout = 0
|
cluster_timeout = 0
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
From now on, server names are prefixed with the cluster name.
|
||||||
|
The cluster name is truncated to 30 characters, ('_', '.') are mapped to '-'
|
||||||
|
and non alpha-numeric characters are removed to ensure FQDN compatibility.
|
Loading…
Reference in New Issue