Additional tests for config-download

Adds some unit and functional tests for the functionality added in
I7d7f6b831b8566390d8f747fb6f45e879b0392ba

implements: blueprint ansible-config-download
Change-Id: I4ca3c801388c301dfd4dcce7b0e98814692f6a39
This commit is contained in:
James Slagle 2017-10-12 11:28:20 -04:00
parent a6b0682bb4
commit 11e8ac5148
8 changed files with 513 additions and 0 deletions

View File

@ -0,0 +1,6 @@
Compute_pre_deployments:
- ComputeHostEntryDeployment
- NetworkDeployment
- MyExtraConfigPost
Compute_post_deployments: []

View File

@ -0,0 +1,7 @@
Controller_pre_deployments:
- ControllerHostEntryDeployment
- NetworkDeployment
- MyPostConfig
- MyExtraConfigPost
Controller_post_deployments: []

View File

@ -0,0 +1,126 @@
deployments:
- server: 00b3a5e1-5e8e-4b55-878b-2fa2271f15ad
deployment: a08ac0c0-7168-4fc5-b3fa-98d83b388676
config: 50fcb6ee-4ff2-4318-b734-d3a7b45a8d6d
name: ControllerHostEntryDeployment
- server: 00b3a5e1-5e8e-4b55-878b-2fa2271f15ad
deployment: 01161ba4-a7a5-4a3e-b82f-f80b7537e866
config: 613b3009-7708-4b06-8c2a-56f8cd379aff
name: NetworkDeployment
- server: a7db3010-a51f-4ae0-a791-2364d629d20d
deployment: eaf3757f-315a-416c-8975-684a0d41f6bf
config: 26db1678-fe18-4acb-86db-19885fccae4c
name: ComputeHostEntryDeployment
- server: 8b07cd31-3083-4b88-a433-955f72039e2c
deployment: 5b464758-b4ff-4bc7-bb37-fec04db932f1
config: 26db1678-fe18-4acb-86db-19885fccae4c
name: ComputeHostEntryDeployment
- server: 169b46f8-1965-4d90-a7de-f36fb4a830fe
deployment: 0ace55f9-fd01-44d5-af4b-6da663633f2a
config: 26db1678-fe18-4acb-86db-19885fccae4c
name: ComputeHostEntryDeployment
- server: a7db3010-a51f-4ae0-a791-2364d629d20d
deployment: 6054566d-8ab0-483c-a3a7-70913032d9ed
config: d21aefd1-9d94-44c0-b73a-16c8d4bc605c
name: NetworkDeployment
- server: 8b07cd31-3083-4b88-a433-955f72039e2c
deployment: c3a59b6a-a9e6-4ac1-9ef0-c72dfe5242bd
config: d21aefd1-9d94-44c0-b73a-16c8d4bc605c
name: NetworkDeployment
- server: 169b46f8-1965-4d90-a7de-f36fb4a830fe
deployment: 6f37e874-4380-4252-8665-31b4c5654627
config: d21aefd1-9d94-44c0-b73a-16c8d4bc605c
name: NetworkDeployment
- server: 00b3a5e1-5e8e-4b55-878b-2fa2271f15ad
deployment: 8967f92f-3232-46ee-9e4f-b7d3b5433163
config: ac63372f-bddd-45a0-aca9-6f0950d581e2
name: MyPostConfig
- server: 00b3a5e1-5e8e-4b55-878b-2fa2271f15ad
deployment: 7a07b2dc-cebf-474c-a8f1-d7c93b299555
config: 9ccb2f66-7cd8-4e3e-a034-4c1cfafd037e
name: MyExtraConfigPost
- server: a7db3010-a51f-4ae0-a791-2364d629d20d
deployment: 2acaf5d0-c170-449b-8015-37c2598baaec
config: 9ccb2f66-7cd8-4e3e-a034-4c1cfafd037e
name: MyExtraConfigPost
- server: 8b07cd31-3083-4b88-a433-955f72039e2c
deployment: 7e0f2650-b1b9-410e-96a6-4745ca735125
config: 9ccb2f66-7cd8-4e3e-a034-4c1cfafd037e
name: MyExtraConfigPost
- server: 169b46f8-1965-4d90-a7de-f36fb4a830fe
deployment: 5096a321-64f9-4f07-a74c-53f2b029e62e
config: 9ccb2f66-7cd8-4e3e-a034-4c1cfafd037e
name: MyExtraConfigPost
configs:
50fcb6ee-4ff2-4318-b734-d3a7b45a8d6d:
id: 50fcb6ee-4ff2-4318-b734-d3a7b45a8d6d
config: |
#!/bin/bash
echo "A script"
outputs: []
group: script
613b3009-7708-4b06-8c2a-56f8cd379aff:
id: 613b3009-7708-4b06-8c2a-56f8cd379aff
config: |
#!/bin/bash
echo "Another script"
outputs: []
group: script
26db1678-fe18-4acb-86db-19885fccae4c:
id: 26db1678-fe18-4acb-86db-19885fccae4c
config:
hiera_key1: hiera_value1
hiera_key2: hiera_value2
outputs: []
group: hiera
d21aefd1-9d94-44c0-b73a-16c8d4bc605c:
id: d21aefd1-9d94-44c0-b73a-16c8d4bc605c
config:
hiera_key3: hiera_value3
hiera_key4:
hiera_key4_subkey0: hiera_key4_subvalue0
hiera_key4_subkey1: hiera_key4_subvalue1
outputs: []
group: hiera
ac63372f-bddd-45a0-aca9-6f0950d581e2:
id: ac63372f-bddd-45a0-aca9-6f0950d581e2
config: |
#!/bin/bash
echo "A PostConfig script"
outputs: []
group: script
9ccb2f66-7cd8-4e3e-a034-4c1cfafd037e:
id: 9ccb2f66-7cd8-4e3e-a034-4c1cfafd037e
config: |
#!/bin/bash
echo "An ExtraConfigPost script"
outputs: []
group: script
servers:
- physical_resource_id: 00b3a5e1-5e8e-4b55-878b-2fa2271f15ad
name: overcloud-controller-0
OS::stack_id: 00b3a5e1-5e8e-4b55-878b-2fa2271f15ad
name: overcloud-controller-0
- physical_resource_id: a7db3010-a51f-4ae0-a791-2364d629d20d
name: overcloud-novacompute-0
OS::stack_id: a7db3010-a51f-4ae0-a791-2364d629d20d
name: overcloud-novacompute-0
- physical_resource_id: 8b07cd31-3083-4b88-a433-955f72039e2c
name: overcloud-novacompute-1
OS::stack_id: 8b07cd31-3083-4b88-a433-955f72039e2c
name: overcloud-novacompute-1
- physical_resource_id: 169b46f8-1965-4d90-a7de-f36fb4a830fe
name: overcloud-novacompute-2
OS::stack_id: 169b46f8-1965-4d90-a7de-f36fb4a830fe
name: overcloud-novacompute-2
server_id_data:
Controller:
- 00b3a5e1-5e8e-4b55-878b-2fa2271f15ad
Compute:
- a7db3010-a51f-4ae0-a791-2364d629d20d
- 8b07cd31-3083-4b88-a433-955f72039e2c
- 169b46f8-1965-4d90-a7de-f36fb4a830fe

View File

@ -0,0 +1,74 @@
deploy_server_id: 00b3a5e1-5e8e-4b55-878b-2fa2271f15ad
ControllerHostEntryDeployment:
config: |
#!/bin/bash
echo "A script"
creation_time: "None"
deployment_name: ControllerHostEntryDeployment
group: script
id: 50fcb6ee-4ff2-4318-b734-d3a7b45a8d6d
inputs:
- name: deploy_server_id
description: None
type: None
value: |-
00b3a5e1-5e8e-4b55-878b-2fa2271f15ad
name: None
options: None
outputs:
NetworkDeployment:
config: |
#!/bin/bash
echo "Another script"
creation_time: "None"
deployment_name: NetworkDeployment
group: script
id: 613b3009-7708-4b06-8c2a-56f8cd379aff
inputs:
- name: deploy_server_id
description: None
type: None
value: |-
00b3a5e1-5e8e-4b55-878b-2fa2271f15ad
name: None
options: None
outputs:
MyPostConfig:
config: |
#!/bin/bash
echo "A PostConfig script"
creation_time: "None"
deployment_name: MyPostConfig
group: script
id: ac63372f-bddd-45a0-aca9-6f0950d581e2
inputs:
- name: deploy_server_id
description: None
type: None
value: |-
00b3a5e1-5e8e-4b55-878b-2fa2271f15ad
name: None
options: None
outputs:
MyExtraConfigPost:
config: |
#!/bin/bash
echo "An ExtraConfigPost script"
creation_time: "None"
deployment_name: MyExtraConfigPost
group: script
id: 9ccb2f66-7cd8-4e3e-a034-4c1cfafd037e
inputs:
- name: deploy_server_id
description: None
type: None
value: |-
00b3a5e1-5e8e-4b55-878b-2fa2271f15ad
name: None
options: None
outputs:

View File

@ -0,0 +1,54 @@
deploy_server_id: a7db3010-a51f-4ae0-a791-2364d629d20d
ComputeHostEntryDeployment:
config:
{"hiera_key1": "hiera_value1", "hiera_key2": "hiera_value2"}
creation_time: "None"
deployment_name: ComputeHostEntryDeployment
group: hiera
id: 26db1678-fe18-4acb-86db-19885fccae4c
inputs:
- name: deploy_server_id
description: None
type: None
value: |-
a7db3010-a51f-4ae0-a791-2364d629d20d
name: None
options: None
outputs:
NetworkDeployment:
config:
{"hiera_key3": "hiera_value3", "hiera_key4": {"hiera_key4_subkey1": "hiera_key4_subvalue1", "hiera_key4_subkey0": "hiera_key4_subvalue0"}}
creation_time: "None"
deployment_name: NetworkDeployment
group: hiera
id: d21aefd1-9d94-44c0-b73a-16c8d4bc605c
inputs:
- name: deploy_server_id
description: None
type: None
value: |-
a7db3010-a51f-4ae0-a791-2364d629d20d
name: None
options: None
outputs:
MyExtraConfigPost:
config: |
#!/bin/bash
echo "An ExtraConfigPost script"
creation_time: "None"
deployment_name: MyExtraConfigPost
group: script
id: 9ccb2f66-7cd8-4e3e-a034-4c1cfafd037e
inputs:
- name: deploy_server_id
description: None
type: None
value: |-
a7db3010-a51f-4ae0-a791-2364d629d20d
name: None
options: None
outputs:

View File

@ -0,0 +1,54 @@
deploy_server_id: 8b07cd31-3083-4b88-a433-955f72039e2c
ComputeHostEntryDeployment:
config:
{"hiera_key1": "hiera_value1", "hiera_key2": "hiera_value2"}
creation_time: "None"
deployment_name: ComputeHostEntryDeployment
group: hiera
id: 26db1678-fe18-4acb-86db-19885fccae4c
inputs:
- name: deploy_server_id
description: None
type: None
value: |-
8b07cd31-3083-4b88-a433-955f72039e2c
name: None
options: None
outputs:
NetworkDeployment:
config:
{"hiera_key3": "hiera_value3", "hiera_key4": {"hiera_key4_subkey1": "hiera_key4_subvalue1", "hiera_key4_subkey0": "hiera_key4_subvalue0"}}
creation_time: "None"
deployment_name: NetworkDeployment
group: hiera
id: d21aefd1-9d94-44c0-b73a-16c8d4bc605c
inputs:
- name: deploy_server_id
description: None
type: None
value: |-
8b07cd31-3083-4b88-a433-955f72039e2c
name: None
options: None
outputs:
MyExtraConfigPost:
config: |
#!/bin/bash
echo "An ExtraConfigPost script"
creation_time: "None"
deployment_name: MyExtraConfigPost
group: script
id: 9ccb2f66-7cd8-4e3e-a034-4c1cfafd037e
inputs:
- name: deploy_server_id
description: None
type: None
value: |-
8b07cd31-3083-4b88-a433-955f72039e2c
name: None
options: None
outputs:

View File

@ -0,0 +1,54 @@
deploy_server_id: 169b46f8-1965-4d90-a7de-f36fb4a830fe
ComputeHostEntryDeployment:
config:
{"hiera_key1": "hiera_value1", "hiera_key2": "hiera_value2"}
creation_time: "None"
deployment_name: ComputeHostEntryDeployment
group: hiera
id: 26db1678-fe18-4acb-86db-19885fccae4c
inputs:
- name: deploy_server_id
description: None
type: None
value: |-
169b46f8-1965-4d90-a7de-f36fb4a830fe
name: None
options: None
outputs:
NetworkDeployment:
config:
{"hiera_key3": "hiera_value3", "hiera_key4": {"hiera_key4_subkey1": "hiera_key4_subvalue1", "hiera_key4_subkey0": "hiera_key4_subvalue0"}}
creation_time: "None"
deployment_name: NetworkDeployment
group: hiera
id: d21aefd1-9d94-44c0-b73a-16c8d4bc605c
inputs:
- name: deploy_server_id
description: None
type: None
value: |-
169b46f8-1965-4d90-a7de-f36fb4a830fe
name: None
options: None
outputs:
MyExtraConfigPost:
config: |
#!/bin/bash
echo "An ExtraConfigPost script"
creation_time: "None"
deployment_name: MyExtraConfigPost
group: script
id: 9ccb2f66-7cd8-4e3e-a034-4c1cfafd037e
inputs:
- name: deploy_server_id
description: None
type: None
value: |-
169b46f8-1965-4d90-a7de-f36fb4a830fe
name: None
options: None
outputs:

View File

@ -10,13 +10,16 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import datetime
import fixtures import fixtures
import mock import mock
import os import os
import yaml
from mock import call from mock import call
from mock import patch from mock import patch
from tripleo_common import constants
from tripleo_common.tests import base from tripleo_common.tests import base
from tripleo_common.tests.fake_config import fakes from tripleo_common.tests.fake_config import fakes
from tripleo_common.utils import config as ooo_config from tripleo_common.utils import config as ooo_config
@ -148,3 +151,138 @@ class TestConfig(base.TestCase):
['upgrade_tasks'], role, filepath) ['upgrade_tasks'], role, filepath)
self.assertTrue(os.path.isfile(filepath)) self.assertTrue(os.path.isfile(filepath))
self.assertEqual(expected_tasks[role], playbook_tasks) self.assertEqual(expected_tasks[role], playbook_tasks)
def test_get_server_data(self):
heat = mock.MagicMock()
self.config = ooo_config.Config(heat)
stack = 'overcloud'
role_names = ['Controller', 'Compute', 'Custom']
heat.resources.list.return_value = ['fakeserver']
server_data = self.config.get_server_data(stack, role_names)
self.assertEqual(heat.resources.list.call_count, 3)
self.assertEqual(
heat.resources.list.call_args_list[0],
mock.call(stack,
filters=dict(type='OS::TripleO::ControllerServer'),
nested_depth=constants.NESTED_DEPTH,
with_detail=True))
self.assertEqual(
heat.resources.list.call_args_list[1],
mock.call(stack,
filters=dict(type='OS::TripleO::ComputeServer'),
nested_depth=constants.NESTED_DEPTH,
with_detail=True))
self.assertEqual(
heat.resources.list.call_args_list[2],
mock.call(stack,
filters=dict(type='OS::TripleO::CustomServer'),
nested_depth=constants.NESTED_DEPTH,
with_detail=True))
self.assertEqual(server_data,
['fakeserver', 'fakeserver', 'fakeserver'])
def test_get_deployment_data(self):
heat = mock.MagicMock()
self.config = ooo_config.Config(heat)
stack = 'overcloud'
first = mock.MagicMock()
first.creation_time = datetime.datetime.now() - datetime.timedelta(2)
second = mock.MagicMock()
second.creation_time = datetime.datetime.now() - datetime.timedelta(1)
third = mock.MagicMock()
third.creation_time = datetime.datetime.now()
# Set return_value in a nonsorted order, as we expect the function to
# sort, so that's what we want to test
heat.resources.list.return_value = [second, third, first]
deployment_data = self.config.get_deployment_data(stack)
self.assertTrue(heat.resources.list.called)
self.assertEqual(
heat.resources.list.call_args,
mock.call(stack,
filters=dict(name=constants.TRIPLEO_DEPLOYMENT_RESOURCE),
nested_depth=constants.NESTED_DEPTH,
with_detail=True))
self.assertEqual(deployment_data,
[first, second, third])
def _get_config_data(self, datafile):
config_data_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'data',
datafile)
config_data = yaml.safe_load(open(config_data_path).read())
server_data = []
deployment_data = []
for server in config_data['servers']:
server_mock = mock.MagicMock()
server_mock.physical_resource_id = server['physical_resource_id']
server_mock.name = server['name']
server_mock.attributes = {'OS::stack_id': server['OS::stack_id'],
'name': server['name']}
server_data.append(server_mock)
for deployment in config_data['deployments']:
deployment_mock = mock.MagicMock()
deployment_mock.id = deployment['deployment']
deployment_mock.attributes = dict(
value=dict(server=deployment['server'],
deployment=deployment['deployment'],
config=deployment['config'],
name=deployment['name']))
deployment_data.append(deployment_mock)
server_id_data = config_data['server_id_data']
configs = config_data['configs']
return server_data, server_id_data, deployment_data, configs
def _get_config_dict(self, deployment):
config = self.configs[deployment.attributes['value']['config']].copy()
config['inputs'] = []
config['inputs'].append(dict(
name='deploy_server_id',
value=deployment.attributes['value']['server']))
return config
def _get_yaml_file(self, file_name):
file_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'data',
file_name)
return yaml.safe_load(open(file_path).read())
@patch('tripleo_common.utils.config.Config.get_config_dict')
@patch('tripleo_common.utils.config.Config.get_server_id_data')
@patch('tripleo_common.utils.config.Config.get_deployment_data')
@patch('tripleo_common.utils.config.Config.get_server_data')
def test_config_download(self, mock_server_data, mock_deployment_data,
mock_server_id_data, mock_config_dict):
heat = mock.MagicMock()
self.config = ooo_config.Config(heat)
stack = 'overcloud'
server_data, server_id_data, deployment_data, configs = \
self._get_config_data('config_data.yaml')
self.configs = configs
mock_server_data.return_value = server_data
mock_server_id_data.return_value = server_id_data
mock_deployment_data.return_value = deployment_data
mock_config_dict.side_effect = self._get_config_dict
tmp_path = self.config.download_config(stack, '/tmp')
print("config at %s" % tmp_path)
for f in ['overcloud-controller-0',
'overcloud-novacompute-0',
'overcloud-novacompute-1',
'overcloud-novacompute-2',
'Controller',
'Compute', ]:
self.assertEqual(
yaml.safe_load(
open(os.path.join(tmp_path, 'group_vars', f)).read()),
self._get_yaml_file(f))