Fail config-download when group:os-apply-config used

Instead of just ignoring deployments with group:os-apply-config and
silently not applying them, this commit updates config-download to raise
an exception instead.

Deployments of this type are all deprecated across TripleO anyway,
although technically they may still work when not using config-download.
Raising an exception early will warn uses that they need to update any
custom deployments they may be using that still use
group:os-apply-config.

Change-Id: I2fb9ec3964b53d219905043a0cd9732aabbd88b2
Closes-Bug: #1741292
This commit is contained in:
James Slagle 2018-01-05 15:58:14 -05:00
parent 04317fff33
commit f32e264f7e
3 changed files with 77 additions and 0 deletions

View File

@ -118,3 +118,14 @@ class RoleMetadataError(Exception):
class UnauthorizedException(Exception):
"""Authorization failed"""
class GroupOsApplyConfigException(Exception):
"""group:os-apply-config not supported with config-download"""
def __init__(self, deployment_name):
self.deployment_name = deployment_name
message = (
"Deployment %s with group:os-apply-config not supported with "
"config-download." % self.deployment_name)
super(GroupOsApplyConfigException, self).__init__(message)

View File

@ -14,12 +14,14 @@ import datetime
import fixtures
import mock
import os
import uuid
import yaml
from mock import call
from mock import patch
from tripleo_common import constants
from tripleo_common import exception
from tripleo_common.tests import base
from tripleo_common.tests.fake_config import fakes
from tripleo_common.utils import config as ooo_config
@ -279,3 +281,62 @@ class TestConfig(base.TestCase):
yaml.safe_load(
open(os.path.join(tmp_path, 'group_vars', f)).read()),
self._get_yaml_file(f))
@patch('tripleo_common.utils.config.Config.get_config_dict')
@patch('tripleo_common.utils.config.Config.get_deployment_data')
def test_config_download_os_apply_config(
self, mock_deployment_data, mock_config_dict):
heat = mock.MagicMock()
self.config = ooo_config.Config(heat)
stack = mock.MagicMock()
heat.stacks.get.return_value = stack
stack.outputs = [
{'output_key': 'RoleNetHostnameMap',
'output_value': {
'Controller': {
'ctlplane': [
'overcloud-controller-0.ctlplane.localdomain']},
'Compute': {
'ctlplane': [
'overcloud-novacompute-0.ctlplane.localdomain',
'overcloud-novacompute-1.ctlplane.localdomain',
'overcloud-novacompute-2.ctlplane.localdomain']}}},
{'output_key': 'ServerIdData',
'output_value': {
'server_ids': {
'Controller': [
'00b3a5e1-5e8e-4b55-878b-2fa2271f15ad'],
'Compute': [
'a7db3010-a51f-4ae0-a791-2364d629d20d',
'8b07cd31-3083-4b88-a433-955f72039e2c',
'169b46f8-1965-4d90-a7de-f36fb4a830fe']}}}]
deployment_data, configs = \
self._get_config_data('config_data.yaml')
# Add a group:os-apply-config config and deployment
config_uuid = str(uuid.uuid4())
configs[config_uuid] = dict(
id=config_uuid,
config=dict(a='a'),
group='os-apply-config',
outputs=[])
deployment_uuid = str(uuid.uuid4())
deployment_mock = mock.MagicMock()
deployment_mock.id = deployment_uuid
deployment_mock.attributes = dict(
value=dict(server='00b3a5e1-5e8e-4b55-878b-2fa2271f15ad',
deployment=deployment_uuid,
config=config_uuid,
name='OsApplyConfigDeployment'))
deployment_data.append(deployment_mock)
self.configs = configs
mock_deployment_data.return_value = deployment_data
mock_config_dict.side_effect = self._get_config_dict
self.tmp_dir = self.useFixture(fixtures.TempDir()).path
self.assertRaises(exception.GroupOsApplyConfigException,
self.config.download_config, stack, self.tmp_dir)

View File

@ -24,6 +24,7 @@ import yaml
import jinja2
from tripleo_common import constants
from tripleo_common import exception
class Config(object):
@ -276,6 +277,10 @@ class Config(object):
else:
d['scalar'] = True
if d['group'] == 'os-apply-config':
raise exception.GroupOsApplyConfigException(
d['deployment_name'])
with open(group_var_server_path, 'w') as f:
f.write(group_var_server_template.render(
deployments=deployments,