Merge "Restore dynamic_inventory unit testing"

This commit is contained in:
Zuul 2023-01-13 18:20:10 +00:00 committed by Gerrit Code Review
commit c4118f0cbf
10 changed files with 60 additions and 49 deletions

View File

@ -31,7 +31,7 @@ used_ips:
- "172.29.248.100"
global_overrides:
internal_lb_vip_address: 172.29.236.100
internal_lb_vip_address: 172.29.236.101
# The external IP is quoted simply to ensure that the .aio file can be used as input
# dynamic inventory testing.
external_lb_vip_address: "{{ bootstrap_host_public_address | default(ansible_facts['default_ipv4']['address']) }}"
@ -132,10 +132,6 @@ repo-infra_hosts:
aio1:
ip: 172.29.236.100
log_hosts:
aio1:
ip: 172.29.236.100
haproxy_hosts:
aio1:
ip: 172.29.236.100

View File

@ -802,26 +802,6 @@
# filter_function: "share.size >= 0"
# goodness_function: "share.size >= 0"
#
# --------
#
# Level: log_hosts (optional)
# List of target hosts on which to deploy logging services. Recommend
# one minimum target host for this service.
#
# Level: <value> (required, string)
# Hostname of a target host.
#
# Option: ip (required, string)
# IP address of this target host, typically the IP address assigned to
# the management bridge.
#
# Example:
#
# Define a logging host:
#
# log_hosts:
# log1:
# ip: 172.29.236.171
#
# --------
#

View File

@ -16,12 +16,9 @@
# (c) 2016, Nolan Brubaker <nolan.brubaker@rackspace.com>
import glob
import os
from os import path
import yaml
CONFIGS_DIR = path.join(os.getcwd(), 'etc', 'openstack_deploy')
AIO_CONFIG_FILE = path.join(CONFIGS_DIR, 'openstack_user_config.yml.aio')
CONFD = path.join(CONFIGS_DIR, 'conf.d')
import jinja2
import yaml
def make_example_config(aio_config_file, configs_dir):
@ -31,11 +28,14 @@ def make_example_config(aio_config_file, configs_dir):
:param configs_dir: ``str`` Directory containing independent conf.d files
"""
config = {}
j2env = jinja2.Environment(loader=jinja2.BaseLoader,
autoescape=jinja2.select_autoescape())
files = glob.glob(os.path.join(configs_dir, '*.aio'))
for file_name in files:
with open(file_name, 'r') as f:
config.update(yaml.safe_load(f.read()))
template = j2env.from_string(f.read())
jinja_data = template.render()
config.update(yaml.safe_load(jinja_data))
with open(aio_config_file, 'r') as f:
config.update(yaml.safe_load(f.read()))

View File

@ -12,3 +12,5 @@ virtualenv>=14.0.6 # MIT
# openstack-ansible-tests/test-ansible-lint.sh
flake8==3.8.3 # MIT
ansible-lint==5.3.2 # MIT
netaddr>=0.7.18 # BSD
Jinja2>=2.10 # BSD

View File

@ -90,7 +90,7 @@ class TestMultipleRuns(unittest.TestCase):
self.assertIn('_meta', inv)
# This test is basically just making sure we get more than
# INVENTORY_SKEL populated, so we're not going to do deep testing
self.assertIn('log_hosts', inv)
self.assertIn('dashboard_hosts', inv)
def tearDown(self):
# Clean up here since get_inventory will not do it by design in

View File

@ -163,7 +163,6 @@ class TestAnsibleInventoryFormatConstraints(unittest.TestCase):
'ceph-mon_hosts',
'ceph-mon',
'ceph-mds',
'ceph-mds_all',
'ceph-mds_containers',
'ceph-mds_container',
'ceph-mds_hosts',
@ -178,7 +177,6 @@ class TestAnsibleInventoryFormatConstraints(unittest.TestCase):
'ceph-rgw_hosts',
'ceph-rgw',
'ceph-nfs',
'ceph-nfs_all',
'ceph-nfs_containers',
'ceph-nfs_container',
'ceph-nfs_hosts',
@ -195,6 +193,8 @@ class TestAnsibleInventoryFormatConstraints(unittest.TestCase):
'cloudkitty_container',
'cloudkitty_engine',
'cloudkitty_hosts',
'coordination_containers',
'coordination_hosts',
'compute-infra_all',
'compute-infra_containers',
'compute-infra_hosts',
@ -259,6 +259,7 @@ class TestAnsibleInventoryFormatConstraints(unittest.TestCase):
'ironic_api',
'ironic_api_container',
'ironic_conductor',
'ironic_console',
'ironic_compute',
'ironic_compute_container',
'ironic-compute_containers',
@ -278,9 +279,6 @@ class TestAnsibleInventoryFormatConstraints(unittest.TestCase):
'keystone_container',
'kvm-compute_containers',
'kvm-compute_hosts',
'log_all',
'log_containers',
'log_hosts',
'lxc_hosts',
'magnum',
'magnum-infra_all',
@ -385,6 +383,8 @@ class TestAnsibleInventoryFormatConstraints(unittest.TestCase):
'network_hosts',
'network-agent_containers',
'network-agent_hosts',
'network-gateway_containers',
'network-gateway_hosts',
'network-infra_containers',
'network-infra_hosts',
'neutron_agent',
@ -396,7 +396,14 @@ class TestAnsibleInventoryFormatConstraints(unittest.TestCase):
'neutron_linuxbridge_agent',
'neutron_metadata_agent',
'neutron_metering_agent',
'network-northd_containers',
'network-northd_hosts',
'neutron_openvswitch_agent',
'neutron_ovn_controller',
'neutron_ovn_gateway',
'neutron_ovn_gateway_container',
'neutron_ovn_northd',
'neutron_ovn_northd_container',
'neutron_sriov_nic_agent',
'neutron_server',
'neutron_server_container',
@ -435,6 +442,7 @@ class TestAnsibleInventoryFormatConstraints(unittest.TestCase):
'repo-infra_all',
'repo-infra_containers',
'repo-infra_hosts',
'repo-infra_all',
'repo_all',
'repo_container',
'sahara-infra_all',
@ -492,6 +500,9 @@ class TestAnsibleInventoryFormatConstraints(unittest.TestCase):
'utility',
'utility_all',
'utility_container',
'zookeeper',
'zookeeper_all',
'zookeeper_container',
'zun-infra_all',
'zun-infra_containers',
'zun-infra_hosts',
@ -1270,8 +1281,8 @@ class TestSetUsedIPS(unittest.TestCase):
class TestConfigCheckFunctional(TestConfigCheckBase):
def duplicate_ip(self):
ip = self.user_defined_config['log_hosts']['aio1']
self.user_defined_config['log_hosts']['bogus'] = ip
ip = self.user_defined_config['dashboard_hosts']['aio1']
self.user_defined_config['dashboard_hosts']['bogus'] = ip
def test_checking_good_config(self):
output = di.main(config=TARGET_DIR, check=True,
@ -1288,15 +1299,15 @@ class TestConfigCheckFunctional(TestConfigCheckBase):
class TestNetworkEntry(unittest.TestCase):
def test_all_args_filled(self):
entry = di.network_entry(True, 'eth1', 'br-mgmt', 'my_type', '1700')
entry = di.network_entry(True, 'eth1', 'br-mgmt', 'my_bridge', 'my_type', '1700')
self.assertNotIn('interface', entry.keys())
self.assertEqual(entry['bridge'], 'br-mgmt')
self.assertEqual(entry['type'], 'my_type')
self.assertEqual(entry['bridge_type'], 'my_bridge')
self.assertEqual(entry['mtu'], '1700')
def test_container_dict(self):
entry = di.network_entry(False, 'eth1', 'br-mgmt', 'my_type', '1700')
entry = di.network_entry(False, 'eth1', 'br-mgmt', 'my_type', net_mtu='1700')
self.assertEqual(entry['interface'], 'eth1')
@ -1379,7 +1390,7 @@ class TestLxcHosts(TestConfigCheckBase):
inv_mock.return_value = (inventory, faked_path)
new_inventory = get_inventory()
self.assertEqual(original_lxc_hosts, new_inventory['lxc_hosts'])
self.assertEqual(set(original_lxc_hosts['hosts']), set(new_inventory['lxc_hosts']['hosts']))
class TestConfigMatchesEnvironment(unittest.TestCase):
@ -1459,6 +1470,11 @@ class TestInventoryGroupConstraints(unittest.TestCase):
# bug #1646136
override = """
physical_skel:
compute_containers:
belongs_to:
- all_containers
compute_hosts:
- hosts
local-compute_containers:
belongs_to:
- compute_containers

View File

@ -86,14 +86,14 @@ class TestRemoveIpfunction(unittest.TestCase):
def test_inventory_item_removed(self):
inventory = self.inv
# Make sure we have log_hosts in the original inventory
self.assertIn('log_hosts', inventory)
# Make sure we have dashboard_hosts in the original inventory
self.assertIn('dashboard_hosts', inventory)
mi.remove_inventory_item("log_hosts", inventory)
mi.remove_inventory_item("log_hosts", inventory, TARGET_DIR)
mi.remove_inventory_item("dashboard_hosts", inventory)
mi.remove_inventory_item("dashboard_hosts", inventory, TARGET_DIR)
# Now make sure it's gone
self.assertIn('log_hosts', inventory)
self.assertIn('dashboard_hosts', inventory)
def test_metal_ips_kept(self):
mi.remove_ip_addresses(self.inv)

View File

@ -117,6 +117,9 @@ commands =
[testenv:inventory]
# Use a fixed seed since some inventory tests rely on specific ordering
deps =
{[testenv]deps}
-e .
setenv =
{[testenv]setenv}
PYTHONHASHSEED = 100

View File

@ -110,6 +110,18 @@
# All deployment scenarios including infra need keystone
- name: openstack/keystone
- job:
name: openstack-ansible-tox-inventory
parent: tox
description: |
Dynamic dynamic_inventory unit tests using tox
vars:
tox_envlist: inventory
files:
- ^osa_toolkit/.*$
- ^etc/openstack_deploy/.*$
- ^inventory/.*$
- job:
name: openstack-ansible-deploy-aio-infra
parent: openstack-ansible-deploy

View File

@ -18,12 +18,14 @@
jobs:
- openstack-ansible-varstest-aio
- openstack-ansible-shastest-metal
- openstack-ansible-tox-inventory
- openstack-ansible-deploy-infra_lxc-validate
- openstack-tox-docs
gate:
jobs:
- openstack-ansible-varstest-aio
- openstack-ansible-shastest-metal
- openstack-ansible-tox-inventory
- openstack-ansible-deploy-infra_lxc-validate
- openstack-tox-docs
periodic: