Browse Source

Merge "Generate stack name as a valid hostname"

changes/79/517479/1
Zuul 4 years ago
committed by Gerrit Code Review
parent
commit
b66338dc55
3 changed files with 23 additions and 4 deletions
  1. +14
    -1
      magnum/drivers/heat/driver.py
  2. +3
    -3
      magnum/tests/unit/conductor/handlers/test_k8s_cluster_conductor.py
  3. +6
    -0
      releasenotes/notes/bug-1718947-0d4e67529e2817d7.yaml

+ 14
- 1
magnum/drivers/heat/driver.py View File

@ -14,6 +14,9 @@ import abc
import os
import six
from string import ascii_letters
from string import digits
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import importutils
@ -109,8 +112,18 @@ class HeatDriver(driver.Driver):
env_files)
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
stack_name = '%s-%s' % (cluster.name, short_id.generate_id())
stack_name = '%s-%s' % (stack_name, short_id.generate_id())
if cluster_create_timeout:
heat_timeout = cluster_create_timeout
else:


+ 3
- 3
magnum/tests/unit/conductor/handlers/test_k8s_cluster_conductor.py View File

@ -755,7 +755,7 @@ class TestClusterConductorWithK8s(base.TestCase):
mock_generate_id):
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'
dummy_cluster_name = 'expected_stack_name'
expected_timeout = 15
@ -796,7 +796,7 @@ class TestClusterConductorWithK8s(base.TestCase):
mock_generate_id):
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'
dummy_cluster_name = 'expected_stack_name'
expected_timeout = CONF.cluster_heat.create_timeout
@ -836,7 +836,7 @@ class TestClusterConductorWithK8s(base.TestCase):
mock_generate_id):
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'
dummy_cluster_name = 'expected_stack_name'
cluster_timeout = 0


+ 6
- 0
releasenotes/notes/bug-1718947-0d4e67529e2817d7.yaml View File

@ -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…
Cancel
Save