TripleO Ansible project repository. Contains playbooks for use with TripleO OpenStack deployments.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
4.4 KiB

# Copyright 2020 Red Hat, Inc.
# All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
import openstack
from tripleo_ansible.ansible_plugins.modules import (
tripleo_network_ports_populate_environment as plugin)
from tripleo_ansible.tests import base as tests_base
from tripleo_ansible.tests import stubs
class TestTripleoNetworkPortsPopulateEnvironment(tests_base.TestCase):
def test_update_environment(self):
env = {
'parameter_defaults': {
'FooParam': 'foo',
'BarParam': 'bar'},
'resource_registry': {
'OS::Some::Existing::Resource': '/foo/bar/some_resource.yaml'}
node_port_map = {
'role-a-0': {'foo': {'ip_address': ''},
'bar': {'ip_address': ''},
'baz': {'ip_address': ''}},
'role-b-0': {'foo': {'ip_address': ''},
'bar': {'ip_address': ''}},
role_net_map = {
'RoleA': ['ctlplane', 'foo', 'bar', 'baz'],
'RoleB': ['ctlplane', 'foo', 'bar']
net_name_map = {'foo': 'Foo', 'bar': 'Bar', 'baz': 'Baz'}
plugin.update_environment(env, node_port_map, role_net_map,
{'FooParam': 'foo',
'BarParam': 'bar',
'NodePortMap': {
'role-a-0': {'bar': {'ip_address': ''},
'baz': {'ip_address': ''},
'foo': {'ip_address': ''}},
'role-b-0': {'bar': {'ip_address': ''},
'foo': {'ip_address': ''}},
}}, env['parameter_defaults'])
{'OS::Some::Existing::Resource': '/foo/bar/some_resource.yaml',
'network/ports/deployed_foo.yaml'}, env['resource_registry'])
@mock.patch.object(openstack.connection, 'Connection', autospec=True)
def test_get_net_name_map(self, mock_conn):
fake_networks = [
stubs.FakeNeutronNetwork(id='bar', name='bar',
stubs.FakeNeutronNetwork(id='baz', name='baz',
stubs.FakeNeutronNetwork(id='foo', name='foo',
] = fake_networks
role_net_map = {
'RoleA': [plugin.CTLPLANE_NETWORK, 'foo', 'bar', 'baz'],
'RoleB': [plugin.CTLPLANE_NETWORK, 'foo', 'bar']
# NOTE(hjensas): Different tripleo_network_name in stubs would require
# set to list conversion and sorting.
self.assertEqual({plugin.CTLPLANE_NETWORK: plugin.CTLPLANE_NETWORK,
'foo': 'UPPERNAME',
'bar': 'UPPERNAME',
'baz': 'UPPERNAME'},
plugin.get_net_name_map(mock_conn, role_net_map))