Browse Source

Support explicitly configured DHCP interfaces

Based on

 http://git.openstack.org/cgit/openstack/nova/tree/nova/tests/unit/network/test_network_info.py#n941

there is the possibility to get an explicit request for an interface to
be configured with DHCP. Honor it.

Change-Id: Ic4282f58e3751827af2777bf99a9e0c5d674cdba
changes/50/202250/6
Monty Taylor 6 years ago
committed by Chris Jones
parent
commit
923de8740c
35 changed files with 181 additions and 7 deletions
  1. +22
    -6
      glean/cmd.py
  2. +1
    -0
      glean/tests/fixtures/hp/sys/class/net/eth3/addr_assign_type
  3. +1
    -0
      glean/tests/fixtures/hp/sys/class/net/eth3/address
  4. +1
    -0
      glean/tests/fixtures/hp/sys/class/net/eth3/carrier
  5. +15
    -0
      glean/tests/fixtures/liberty/mnt/config/openstack/latest/network_info.json
  6. +1
    -0
      glean/tests/fixtures/liberty/sys/class/net/eth3/addr_assign_type
  7. +1
    -0
      glean/tests/fixtures/liberty/sys/class/net/eth3/address
  8. +1
    -0
      glean/tests/fixtures/liberty/sys/class/net/eth3/carrier
  9. +1
    -0
      glean/tests/fixtures/nokey/sys/class/net/eth3/addr_assign_type
  10. +1
    -0
      glean/tests/fixtures/nokey/sys/class/net/eth3/address
  11. +1
    -0
      glean/tests/fixtures/nokey/sys/class/net/eth3/carrier
  12. +1
    -0
      glean/tests/fixtures/rax/sys/class/net/eth3/addr_assign_type
  13. +1
    -0
      glean/tests/fixtures/rax/sys/class/net/eth3/address
  14. +1
    -0
      glean/tests/fixtures/rax/sys/class/net/eth3/carrier
  15. +8
    -0
      glean/tests/fixtures/test/hp.centos.network.out
  16. +3
    -0
      glean/tests/fixtures/test/hp.debian.network.out
  17. +8
    -0
      glean/tests/fixtures/test/hp.fedora.network.out
  18. +8
    -0
      glean/tests/fixtures/test/hp.redhat.network.out
  19. +3
    -0
      glean/tests/fixtures/test/hp.ubuntu.network.out
  20. +8
    -0
      glean/tests/fixtures/test/liberty.centos.network.out
  21. +3
    -0
      glean/tests/fixtures/test/liberty.debian.network.out
  22. +8
    -0
      glean/tests/fixtures/test/liberty.fedora.network.out
  23. +8
    -0
      glean/tests/fixtures/test/liberty.redhat.network.out
  24. +3
    -0
      glean/tests/fixtures/test/liberty.ubuntu.network.out
  25. +8
    -0
      glean/tests/fixtures/test/nokey.centos.network.out
  26. +3
    -0
      glean/tests/fixtures/test/nokey.debian.network.out
  27. +8
    -0
      glean/tests/fixtures/test/nokey.fedora.network.out
  28. +8
    -0
      glean/tests/fixtures/test/nokey.redhat.network.out
  29. +3
    -0
      glean/tests/fixtures/test/nokey.ubuntu.network.out
  30. +8
    -0
      glean/tests/fixtures/test/rax.centos.network.out
  31. +3
    -0
      glean/tests/fixtures/test/rax.debian.network.out
  32. +8
    -0
      glean/tests/fixtures/test/rax.fedora.network.out
  33. +8
    -0
      glean/tests/fixtures/test/rax.redhat.network.out
  34. +3
    -0
      glean/tests/fixtures/test/rax.ubuntu.network.out
  35. +12
    -1
      rebuild-test-output.sh

+ 22
- 6
glean/cmd.py View File

@ -97,9 +97,14 @@ def write_redhat_interfaces(interfaces, sys_interfaces):
continue
if iname not in sys_interfaces:
continue
interface_name = sys_interfaces[iname]
files_to_write.update(
_write_rh_interface(interface_name, interface))
if interface['type'] == 'ipv4':
interface_name = sys_interfaces[iname]
files_to_write.update(
_write_rh_interface(interface_name, interface))
if interface['type'] == 'ipv4_dhcp':
interface_name = sys_interfaces[iname]
files_to_write.update(
_write_rh_dhcp(interface_name, interface['mac_address']))
for mac, iname in sorted(
sys_interfaces.items(), key=lambda x: x[1]):
if _exists_rh_interface(iname):
@ -129,10 +134,22 @@ def write_debian_interfaces(interfaces, sys_interfaces):
if iname not in sys_interfaces:
continue
interface = interfaces[iname]
link_type = "inet"
interface_name = sys_interfaces[iname]
iface_path = os.path.join(eni_d_path, '%s.cfg' % interface_name)
if interface['type'] == 'ipv4_dhcp':
result = "auto {0}\n".format(interface_name)
result += "iface {0} inet dhcp\n".format(interface_name)
files_to_write[iface_path] = result
continue
if interface['type'] == 'ipv6':
link_type = "inet6"
interface_name = sys_interfaces[iname]
elif interface['type'] == 'ipv4':
link_type = "inet"
# We do not know this type of entry
if not link_type:
continue
result = "auto {0}\n".format(interface_name)
result += "iface {name} {link_type} static\n".format(
name=interface_name, link_type=link_type)
@ -148,7 +165,6 @@ def write_debian_interfaces(interfaces, sys_interfaces):
result += pre_down.format(
net=route['network'], mask=route['netmask'],
gw=route['gateway'])
iface_path = os.path.join(eni_d_path, '%s.cfg' % interface_name)
files_to_write[iface_path] = result
for mac, iname in sorted(
sys_interfaces.items(), key=lambda x: x[1]):


+ 1
- 0
glean/tests/fixtures/hp/sys/class/net/eth3/addr_assign_type View File

@ -0,0 +1 @@
0

+ 1
- 0
glean/tests/fixtures/hp/sys/class/net/eth3/address View File

@ -0,0 +1 @@
bc:76:4e:12:a4:bb

+ 1
- 0
glean/tests/fixtures/hp/sys/class/net/eth3/carrier View File

@ -0,0 +1 @@
1

+ 15
- 0
glean/tests/fixtures/liberty/mnt/config/openstack/latest/network_info.json View File

@ -59,7 +59,14 @@
],
"ip_address": "192.0.2.2",
"id": "network2"
},
{
"network_id": "33333333-3333-3333-3333-333333333333",
"type": "ipv4_dhcp",
"link": "tap8aac87b9-37",
"id": "network3"
}
],
"links": [
{
@ -82,6 +89,14 @@
"type": null,
"id": "tap234ab34c-f1",
"vif_id": "acdb875a-87da-76cb-984c-acd9a75dbca7"
},
{
"ethernet_mac_address": "BC:76:4E:12:a4:bb",
"mtu": 1500,
"type": null,
"id": "tap8aac87b9-37",
"vif_id": "f12bedfa-87bv-a39f-1234-aaeb55bea7e6"
}
]
}

+ 1
- 0
glean/tests/fixtures/liberty/sys/class/net/eth3/addr_assign_type View File

@ -0,0 +1 @@
0

+ 1
- 0
glean/tests/fixtures/liberty/sys/class/net/eth3/address View File

@ -0,0 +1 @@
bc:76:4e:12:a4:bb

+ 1
- 0
glean/tests/fixtures/liberty/sys/class/net/eth3/carrier View File

@ -0,0 +1 @@
1

+ 1
- 0
glean/tests/fixtures/nokey/sys/class/net/eth3/addr_assign_type View File

@ -0,0 +1 @@
0

+ 1
- 0
glean/tests/fixtures/nokey/sys/class/net/eth3/address View File

@ -0,0 +1 @@
bc:76:4e:12:a4:bb

+ 1
- 0
glean/tests/fixtures/nokey/sys/class/net/eth3/carrier View File

@ -0,0 +1 @@
1

+ 1
- 0
glean/tests/fixtures/rax/sys/class/net/eth3/addr_assign_type View File

@ -0,0 +1 @@
0

+ 1
- 0
glean/tests/fixtures/rax/sys/class/net/eth3/address View File

@ -0,0 +1 @@
bc:76:4e:12:a4:bb

+ 1
- 0
glean/tests/fixtures/rax/sys/class/net/eth3/carrier View File

@ -0,0 +1 @@
1

+ 8
- 0
glean/tests/fixtures/test/hp.centos.network.out View File

@ -14,3 +14,11 @@ HWADDR=bc:76:4e:05:7b:06
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=bc:76:4e:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet

+ 3
- 0
glean/tests/fixtures/test/hp.debian.network.out View File

@ -8,3 +8,6 @@ iface eth0 inet dhcp
### Write /etc/network/interfaces.d/eth1.cfg
auto eth1
iface eth1 inet dhcp
### Write /etc/network/interfaces.d/eth3.cfg
auto eth3
iface eth3 inet dhcp

+ 8
- 0
glean/tests/fixtures/test/hp.fedora.network.out View File

@ -14,3 +14,11 @@ HWADDR=bc:76:4e:05:7b:06
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=bc:76:4e:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet

+ 8
- 0
glean/tests/fixtures/test/hp.redhat.network.out View File

@ -14,3 +14,11 @@ HWADDR=bc:76:4e:05:7b:06
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=bc:76:4e:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet

+ 3
- 0
glean/tests/fixtures/test/hp.ubuntu.network.out View File

@ -8,3 +8,6 @@ iface eth0 inet dhcp
### Write /etc/network/interfaces.d/eth1.cfg
auto eth1
iface eth1 inet dhcp
### Write /etc/network/interfaces.d/eth3.cfg
auto eth3
iface eth3 inet dhcp

+ 8
- 0
glean/tests/fixtures/test/liberty.centos.network.out View File

@ -21,6 +21,14 @@ IPADDR=10.208.169.118
NETMASK=255.255.224.0
ONBOOT=yes
NM_CONTROLLED=no
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=BC:76:4E:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/route-eth1
ADDRESS0=10.176.0.0
NETMASK0=255.240.0.0


+ 3
- 0
glean/tests/fixtures/test/liberty.debian.network.out View File

@ -17,6 +17,9 @@ iface eth1 inet static
pre-down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
post-up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
pre-down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
### Write /etc/network/interfaces.d/eth3.cfg
auto eth3
iface eth3 inet dhcp
### Write /etc/resolv.conf
nameserver 72.3.128.241
nameserver 72.3.128.240

+ 8
- 0
glean/tests/fixtures/test/liberty.fedora.network.out View File

@ -21,6 +21,14 @@ IPADDR=10.208.169.118
NETMASK=255.255.224.0
ONBOOT=yes
NM_CONTROLLED=no
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=BC:76:4E:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/route-eth1
ADDRESS0=10.176.0.0
NETMASK0=255.240.0.0


+ 8
- 0
glean/tests/fixtures/test/liberty.redhat.network.out View File

@ -21,6 +21,14 @@ IPADDR=10.208.169.118
NETMASK=255.255.224.0
ONBOOT=yes
NM_CONTROLLED=no
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=BC:76:4E:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/route-eth1
ADDRESS0=10.176.0.0
NETMASK0=255.240.0.0


+ 3
- 0
glean/tests/fixtures/test/liberty.ubuntu.network.out View File

@ -17,6 +17,9 @@ iface eth1 inet static
pre-down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
post-up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
pre-down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
### Write /etc/network/interfaces.d/eth3.cfg
auto eth3
iface eth3 inet dhcp
### Write /etc/resolv.conf
nameserver 72.3.128.241
nameserver 72.3.128.240

+ 8
- 0
glean/tests/fixtures/test/nokey.centos.network.out View File

@ -14,3 +14,11 @@ HWADDR=bc:76:4e:05:7b:06
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=bc:76:4e:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet

+ 3
- 0
glean/tests/fixtures/test/nokey.debian.network.out View File

@ -8,3 +8,6 @@ iface eth0 inet dhcp
### Write /etc/network/interfaces.d/eth1.cfg
auto eth1
iface eth1 inet dhcp
### Write /etc/network/interfaces.d/eth3.cfg
auto eth3
iface eth3 inet dhcp

+ 8
- 0
glean/tests/fixtures/test/nokey.fedora.network.out View File

@ -14,3 +14,11 @@ HWADDR=bc:76:4e:05:7b:06
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=bc:76:4e:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet

+ 8
- 0
glean/tests/fixtures/test/nokey.redhat.network.out View File

@ -14,3 +14,11 @@ HWADDR=bc:76:4e:05:7b:06
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=bc:76:4e:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet

+ 3
- 0
glean/tests/fixtures/test/nokey.ubuntu.network.out View File

@ -8,3 +8,6 @@ iface eth0 inet dhcp
### Write /etc/network/interfaces.d/eth1.cfg
auto eth1
iface eth1 inet dhcp
### Write /etc/network/interfaces.d/eth3.cfg
auto eth3
iface eth3 inet dhcp

+ 8
- 0
glean/tests/fixtures/test/rax.centos.network.out View File

@ -21,6 +21,14 @@ IPADDR=10.208.169.118
NETMASK=255.255.224.0
ONBOOT=yes
NM_CONTROLLED=no
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=bc:76:4e:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/route-eth1
ADDRESS0=10.176.0.0
NETMASK0=255.240.0.0


+ 3
- 0
glean/tests/fixtures/test/rax.debian.network.out View File

@ -17,6 +17,9 @@ iface eth1 inet static
pre-down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
post-up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
pre-down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
### Write /etc/network/interfaces.d/eth3.cfg
auto eth3
iface eth3 inet dhcp
### Write /etc/resolv.conf
nameserver 72.3.128.241
nameserver 72.3.128.240

+ 8
- 0
glean/tests/fixtures/test/rax.fedora.network.out View File

@ -21,6 +21,14 @@ IPADDR=10.208.169.118
NETMASK=255.255.224.0
ONBOOT=yes
NM_CONTROLLED=no
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=bc:76:4e:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/route-eth1
ADDRESS0=10.176.0.0
NETMASK0=255.240.0.0


+ 8
- 0
glean/tests/fixtures/test/rax.redhat.network.out View File

@ -21,6 +21,14 @@ IPADDR=10.208.169.118
NETMASK=255.255.224.0
ONBOOT=yes
NM_CONTROLLED=no
### Write /etc/sysconfig/network-scripts/ifcfg-eth3
# Automatically generated, do not edit
DEVICE=eth3
BOOTPROTO=dhcp
HWADDR=bc:76:4e:12:a4:bb
ONBOOT=yes
NM_CONTROLLED=no
TYPE=Ethernet
### Write /etc/sysconfig/network-scripts/route-eth1
ADDRESS0=10.176.0.0
NETMASK0=255.240.0.0


+ 3
- 0
glean/tests/fixtures/test/rax.ubuntu.network.out View File

@ -17,6 +17,9 @@ iface eth1 inet static
pre-down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
post-up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
pre-down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true
### Write /etc/network/interfaces.d/eth3.cfg
auto eth3
iface eth3 inet dhcp
### Write /etc/resolv.conf
nameserver 72.3.128.241
nameserver 72.3.128.240

+ 12
- 1
rebuild-test-output.sh View File

@ -26,6 +26,17 @@ for vendor_dir in $(find $SAMPLE_DIR \
> $SAMPLE_DIR/test/$vendor.keys.out
for distro in debian ubuntu redhat fedora centos ; do
python glean/cmd.py \
-n --root $vendor_dir --distro $distro > $SAMPLE_DIR/test/$vendor.$distro.network.out
-n --root $vendor_dir --distro $distro | python -c 'import sys
skipping = False
for line in sys.stdin.readlines():
if "eth2" in line:
skipping = True
continue
if line.startswith("### Write"):
skipping = False
if skipping:
continue
sys.stdout.write(line)
' > $SAMPLE_DIR/test/$vendor.$distro.network.out
done
done

Loading…
Cancel
Save