Merge "Move build_service_filter to kolla_builder from tripleoclient"

This commit is contained in:
Zuul 2018-04-03 08:11:33 +00:00 committed by Gerrit Code Review
commit 62dc219822
2 changed files with 180 additions and 11 deletions

View File

@ -46,6 +46,43 @@ DEFAULT_TEMPLATE_FILE = os.path.join(sys.prefix, 'share', 'tripleo-common',
'overcloud_containers.yaml.j2')
def get_enabled_services(environment, roles_data):
"""Build list of enabled services
:param environment: Heat environment for deployment
:param roles_data: Roles file data used to filter services
:returns: set of resource types representing enabled services
"""
enabled_services = set()
parameter_defaults = environment.get('parameter_defaults', {})
for role in roles_data:
count = parameter_defaults.get('%sCount' % role['name'],
role.get('CountDefault', 0))
if count > 0:
enabled_services.update(
parameter_defaults.get('%sServices' % role['name'],
role.get('ServicesDefault', [])))
return enabled_services
def build_service_filter(environment, roles_data):
"""Build list of containerized services
:param environment: Heat environment for deployment
:param roles_data: Roles file data used to filter services
:returns: set of resource types representing containerized services
"""
enabled_services = get_enabled_services(environment, roles_data)
containerized_services = set()
for service, env_path in environment.get('resource_registry', {}).items():
# Use the template path to determine if it represents a
# containerized service
if '/docker/services/' in env_path:
containerized_services.add(service)
return containerized_services.intersection(enabled_services)
def container_images_prepare_defaults():
"""Return default dict for prepare substitutions
@ -66,7 +103,7 @@ def container_images_prepare(template_file=DEFAULT_TEMPLATE_FILE,
:param template_file: path to Jinja2 file containing all image entries
:param excludes: list of image name substrings to use for exclude filter
:param service_filter: set of heat resource types for containerized
services to filter by
services to filter by. Disable by passing None.
:param pull_source: DEPRECATED namespace for pulling during image uploads
:param push_destination: namespace for pushing during image uploads. When
specified the image parameters will use this
@ -84,6 +121,12 @@ def container_images_prepare(template_file=DEFAULT_TEMPLATE_FILE,
if mapping_args is None:
mapping_args = {}
if service_filter:
if 'OS::TripleO::Services::OpenDaylightApi' in service_filter:
mapping_args['neutron_driver'] = 'odl'
elif 'OS::TripleO::Services::OVNController' in service_filter:
mapping_args['neutron_driver'] = 'ovn'
def ffunc(entry):
imagename = entry.get('imagename', '')
if excludes:

View File

@ -478,19 +478,24 @@ class TestPrepare(base.TestCase):
def test_prepare_neutron_driver_ovn(self, mock_get):
self.assertEqual({
'container_images.yaml': [
{'imagename': 't/p-neutron-server-ovn:l'}
{'imagename': 't/p-neutron-server-ovn:l'},
{'imagename': 't/p-ovn-controller:l'}
],
'environments/containers-default-parameters.yaml': {
'DockerNeutronApiImage': 't/p-neutron-server-ovn:l',
'DockerNeutronConfigImage': 't/p-neutron-server-ovn:l'
'DockerNeutronConfigImage': 't/p-neutron-server-ovn:l',
'DockerOvnControllerConfigImage': 't/p-ovn-controller:l',
'DockerOvnControllerImage': 't/p-ovn-controller:l'
}},
kb.container_images_prepare(
template_file=TEMPLATE_PATH,
output_env_file=constants.CONTAINER_DEFAULTS_ENVIRONMENT,
output_images_file='container_images.yaml',
service_filter=['OS::TripleO::Services::NeutronServer'],
service_filter=[
'OS::TripleO::Services::NeutronServer',
'OS::TripleO::Services::OVNController'
],
mapping_args={
'neutron_driver': 'ovn',
'namespace': 't',
'name_prefix': 'p',
'name_suffix': '',
@ -503,23 +508,144 @@ class TestPrepare(base.TestCase):
def test_prepare_neutron_driver_odl(self, mock_get):
self.assertEqual({
'container_images.yaml': [
{'imagename': 't/p-neutron-server-opendaylight:l'}
{'imagename': 't/neutron-server-opendaylight:l'},
{'imagename': 't/opendaylight:l'}
],
'environments/containers-default-parameters.yaml': {
'DockerNeutronApiImage': 't/p-neutron-server-opendaylight:l',
'DockerNeutronConfigImage': 't/p-neutron-server-opendaylight:l'
'DockerNeutronApiImage': 't/neutron-server-opendaylight:l',
'DockerNeutronConfigImage': 't/neutron-server-opendaylight:l',
'DockerOpendaylightApiImage': 't/opendaylight:l',
'DockerOpendaylightConfigImage': 't/opendaylight:l',
}},
kb.container_images_prepare(
template_file=TEMPLATE_PATH,
output_env_file=constants.CONTAINER_DEFAULTS_ENVIRONMENT,
output_images_file='container_images.yaml',
service_filter=['OS::TripleO::Services::NeutronServer'],
service_filter=[
'OS::TripleO::Services::NeutronServer',
'OS::TripleO::Services::OpenDaylightApi'
],
mapping_args={
'neutron_driver': 'odl',
'namespace': 't',
'name_prefix': 'p',
'name_prefix': '',
'name_suffix': '',
'tag': 'l',
}
)
)
def test_get_enabled_services_empty(self):
self.assertEqual(
set([]),
kb.get_enabled_services({}, [])
)
def test_get_enabled_services_default_count(self):
self.assertEqual(
set([
'OS::TripleO::Services::NeutronApi',
'OS::TripleO::Services::NovaApi',
'OS::TripleO::Services::NovaCompute'
]),
kb.get_enabled_services({
'parameter_defaults': {}
}, [
{
'name': 'Controller',
'CountDefault': 1,
'ServicesDefault': [
'OS::TripleO::Services::NeutronApi',
'OS::TripleO::Services::NovaApi'
]
}, {
'name': 'Compute',
'CountDefault': 1,
'ServicesDefault': [
'OS::TripleO::Services::NovaCompute'
]
}, {
'name': 'BlockStorage',
'ServicesDefault': [
'OS::TripleO::Services::Ntp'
]
}
])
)
def test_get_enabled_services(self):
self.assertEqual(
set([
'OS::TripleO::Services::NeutronApi',
'OS::TripleO::Services::NovaApi',
'OS::TripleO::Services::NovaCompute',
'OS::TripleO::Services::NovaLibvirt'
]),
kb.get_enabled_services({
'parameter_defaults': {
'ControllerCount': 1,
'ComputeCount': 1,
'BlockStorageCount': 0,
'ComputeServices': [
'OS::TripleO::Services::NovaCompute',
'OS::TripleO::Services::NovaLibvirt'
]
}
}, [
{
'name': 'Controller',
'CountDefault': 0,
'ServicesDefault': [
'OS::TripleO::Services::NeutronApi',
'OS::TripleO::Services::NovaApi'
]
}, {
'name': 'Compute',
'ServicesDefault': [
'OS::TripleO::Services::NovaCompute'
]
}, {
'name': 'BlockStorage',
'ServicesDefault': [
'OS::TripleO::Services::Ntp'
]
}
])
)
def test_build_service_filter(self):
self.assertEqual(
set([
'OS::TripleO::Services::NovaApi',
'OS::TripleO::Services::NovaCompute'
]),
kb.build_service_filter({
'resource_registry': {
'OS::TripleO::Services::NeutronApi':
'/tht/puppet/services/foo.yaml',
'OS::TripleO::Services::NovaApi':
'/tht/docker/services/foo.yaml',
'OS::TripleO::Services::NovaCompute':
'/tht/docker/services/foo.yaml',
}
}, [
{
'name': 'Controller',
'CountDefault': 1,
'ServicesDefault': [
'OS::TripleO::Services::NeutronApi',
'OS::TripleO::Services::NovaApi'
]
}, {
'name': 'Compute',
'CountDefault': 1,
'ServicesDefault': [
'OS::TripleO::Services::NovaCompute'
]
}, {
'name': 'BlockStorage',
'ServicesDefault': [
'OS::TripleO::Services::Ntp'
]
}
])
)