Skip IP address allocation and configuration if needed

Sometimes some hosts should be configured with an interface without any
IP address set (e.g. bridged interface) and to achieve that this change
adds the new attribute 'no_ip' for the network configuration. Also the
change contain a test for this.

Change-Id: I2c9dfeca7f0d37a96f9cbd9df51d94098cf07258
Signed-off-by: Maksim Malchuk <maksim.malchuk@gmail.com>
This commit is contained in:
Maksim Malchuk 2021-12-08 23:52:25 +03:00 committed by Pierre Riteau
parent a1ed4a05bb
commit 1de4f2a4a3
7 changed files with 30 additions and 1 deletions

View File

@ -27,6 +27,7 @@
when:
- item | net_cidr != None
- item | net_bootproto != 'dhcp'
- not item | net_no_ip | bool
roles:
- role: ip-allocation
ip_allocation_filename: "{{ kayobe_env_config_path }}/network-allocation.yml"

View File

@ -83,6 +83,9 @@ supported:
``libvirt_network_name``
A name to give to a Libvirt network representing this network on the seed
hypervisor.
``no_ip``
Whether to allocate an IP address for this network. If set to ``true``, an
IP address will not be allocated.
Configuring an IP Subnet
------------------------

View File

@ -174,6 +174,11 @@ def net_interface(context, name, inventory_hostname=None):
return net_attr(context, name, 'interface', inventory_hostname)
@jinja2.contextfilter
def net_no_ip(context, name, inventory_hostname=None):
return net_attr(context, name, 'no_ip', inventory_hostname)
@jinja2.contextfilter
def net_cidr(context, name, inventory_hostname=None):
return net_attr(context, name, 'cidr', inventory_hostname)
@ -673,6 +678,7 @@ def get_filters():
'net_fqdn': _make_attr_filter('fqdn'),
'net_ip': net_ip,
'net_interface': net_interface,
'net_no_ip': net_no_ip,
'net_cidr': net_cidr,
'net_mask': net_mask,
'net_prefix': net_prefix,

View File

@ -18,6 +18,7 @@ controller_extra_network_interfaces:
- test_net_bridge_vlan
- test_net_bond
- test_net_bond_vlan
- test_net_bridge_noip
# Custom IP routing tables.
network_route_tables:
@ -72,6 +73,12 @@ test_net_bond_vlan_interface: "{% raw %}{{ test_net_bond_interface }}.{{ test_ne
test_net_bond_vlan_vlan: 44
test_net_bond_vlan_zone: public
# br1: Bridge interface without IP address.
test_net_bridge_noip_cidr: 192.168.40.0/24
test_net_bridge_noip_interface: br1
test_net_bridge_noip_bridge_ports: [dummy7]
test_net_bridge_noip_no_ip: true
# Define a software RAID device consisting of two loopback devices.
controller_mdadm_arrays:
- name: md0

View File

@ -39,4 +39,4 @@
- name: Ensure dummy network interfaces exist
command: ip link add dummy{{ item }} type dummy
become: true
loop: "{{ range(2, 7) | list }}"
loop: "{{ range(2, 8) | list }}"

View File

@ -87,6 +87,12 @@ def test_network_bond_vlan(host):
assert host.file('/sys/class/net/bond0.44/lower_bond0').exists
def test_network_bridge_no_ip(host):
interface = host.interface('br1')
assert interface.exists
assert not '192.168.40.1' in interface.addresses
def test_additional_user_account(host):
user = host.user("kayobe-test-user")
assert user.name == "kayobe-test-user"

View File

@ -0,0 +1,6 @@
---
features:
- |
The new filter ``net_no_ip`` adds the attribute ``no_ip`` which can be set
to ``true`` to skip IP address allocation and configuration for specific
networks.