def test_get_stored_pci_address_empty(self): def test_get_dpdk_map(): return [] self.stub_out('os_net_config.utils._get_dpdk_map', test_get_dpdk_map) pci = utils.get_stored_pci_address('eth1', False) self.assertEqual(None, pci)
def test_get_stored_pci_address_empty(self): def test_get_dpdk_map(): return [] self.stubs.Set(utils, '_get_dpdk_map', test_get_dpdk_map) pci = utils.get_stored_pci_address('eth1', False) self.assertEqual(None, pci)
def test_get_stored_pci_address_empty(self): def test_get_dpdk_map(): return [] self.stub_out('os_net_config.utils._get_dpdk_map', test_get_dpdk_map) pci = utils.get_stored_pci_address('eth1', False) self.assertEqual(None, pci)
def test_get_stored_pci_address_success(self): def test_get_dpdk_map(): return [{'name': 'eth1', 'pci_address': '0000:00:09.0', 'mac_address': '01:02:03:04:05:06', 'driver': 'vfio-pci'}] self.stubs.Set(utils, '_get_dpdk_map', test_get_dpdk_map) pci = utils.get_stored_pci_address('eth1', False) self.assertEqual('0000:00:09.0', pci)
def test_get_stored_pci_address_success(self): def test_get_dpdk_map(): return [{'name': 'eth1', 'pci_address': '0000:00:09.0', 'mac_address': '01:02:03:04:05:06', 'driver': 'vfio-pci'}] self.stub_out('os_net_config.utils._get_dpdk_map', test_get_dpdk_map) pci = utils.get_stored_pci_address('eth1', False) self.assertEqual('0000:00:09.0', pci)
def _add_common(self, base_opt): ovs_extra = [] data = "# This file is autogenerated by os-net-config\n" data += "DEVICE=%s\n" % base_opt.name data += "ONBOOT=yes\n" if isinstance(base_opt, objects.Interface) and base_opt.hotplug: data += "HOTPLUG=yes\n" else: data += "HOTPLUG=no\n" if base_opt.nm_controlled: data += "NM_CONTROLLED=yes\n" else: data += "NM_CONTROLLED=no\n" if not base_opt.dns_servers and not base_opt.use_dhcp: data += "PEERDNS=no\n" if isinstance(base_opt, objects.Vlan): if not base_opt.ovs_port: # vlans on OVS bridges are internal ports (no device, etc) data += "VLAN=yes\n" if base_opt.device: data += "PHYSDEV=%s\n" % base_opt.device else: if base_opt.linux_bond_name: data += "PHYSDEV=%s\n" % base_opt.linux_bond_name elif isinstance(base_opt, objects.IvsInterface): data += "TYPE=IVSIntPort\n" elif isinstance(base_opt, objects.NfvswitchInternal): data += "TYPE=NFVSWITCHIntPort\n" elif isinstance(base_opt, objects.IbInterface): data += "TYPE=Infiniband\n" if base_opt.ethtool_opts: data += "ETHTOOL_OPTS=\"%s\"\n" % base_opt.ethtool_opts elif re.match('\w+\.\d+$', base_opt.name): data += "VLAN=yes\n" if base_opt.linux_bond_name: data += "MASTER=%s\n" % base_opt.linux_bond_name data += "SLAVE=yes\n" if base_opt.linux_team_name: data += "TEAM_MASTER=%s\n" % base_opt.linux_team_name if base_opt.primary: data += "TEAM_PORT_CONFIG='{\"prio\": 100}'\n" if base_opt.ivs_bridge_name: data += "DEVICETYPE=ivs\n" data += "IVS_BRIDGE=%s\n" % base_opt.ivs_bridge_name if base_opt.nfvswitch_bridge_name: data += "DEVICETYPE=nfvswitch\n" data += "NFVSWITCH_BRIDGE=%s\n" % base_opt.nfvswitch_bridge_name if base_opt.ovs_port: if not isinstance(base_opt, objects.LinuxTeam): data += "DEVICETYPE=ovs\n" if base_opt.bridge_name: if isinstance(base_opt, objects.Vlan): data += "TYPE=OVSIntPort\n" data += "OVS_BRIDGE=%s\n" % base_opt.bridge_name data += "OVS_OPTIONS=\"tag=%s\"\n" % base_opt.vlan_id else: data += "TYPE=OVSPort\n" data += "OVS_BRIDGE=%s\n" % base_opt.bridge_name if base_opt.linux_bridge_name: data += "BRIDGE=%s\n" % base_opt.linux_bridge_name if isinstance(base_opt, objects.OvsBridge): data += "DEVICETYPE=ovs\n" data += "TYPE=OVSBridge\n" if base_opt.use_dhcp: data += "OVSBOOTPROTO=dhcp\n" if base_opt.members: members = [member.name for member in base_opt.members] self.member_names[base_opt.name] = members if base_opt.use_dhcp: data += ("OVSDHCPINTERFACES=\"%s\"\n" % " ".join(members)) if base_opt.primary_interface_name: mac = utils.interface_mac(base_opt.primary_interface_name) ovs_extra.append("set bridge %s other-config:hwaddr=%s" % (base_opt.name, mac)) if base_opt.ovs_options: data += "OVS_OPTIONS=\"%s\"\n" % base_opt.ovs_options ovs_extra.extend(base_opt.ovs_extra) elif isinstance(base_opt, objects.OvsUserBridge): data += "DEVICETYPE=ovs\n" data += "TYPE=OVSUserBridge\n" if base_opt.use_dhcp: data += "OVSBOOTPROTO=dhcp\n" if base_opt.members: members = [member.name for member in base_opt.members] self.member_names[base_opt.name] = members if base_opt.use_dhcp: data += ("OVSDHCPINTERFACES=\"%s\"\n" % " ".join(members)) if base_opt.ovs_options: data += "OVS_OPTIONS=\"%s\"\n" % base_opt.ovs_options ovs_extra.extend(base_opt.ovs_extra) elif isinstance(base_opt, objects.OvsBond): if base_opt.primary_interface_name: primary_name = base_opt.primary_interface_name self.bond_primary_ifaces[base_opt.name] = primary_name data += "DEVICETYPE=ovs\n" data += "TYPE=OVSBond\n" if base_opt.use_dhcp: data += "OVSBOOTPROTO=dhcp\n" if base_opt.members: members = [member.name for member in base_opt.members] self.member_names[base_opt.name] = members data += ("BOND_IFACES=\"%s\"\n" % " ".join(members)) if base_opt.ovs_options: data += "OVS_OPTIONS=\"%s\"\n" % base_opt.ovs_options ovs_extra.extend(base_opt.ovs_extra) elif isinstance(base_opt, objects.LinuxBridge): data += "TYPE=Bridge\n" data += "DELAY=0\n" if base_opt.use_dhcp: data += "BOOTPROTO=dhcp\n" if base_opt.members: members = [member.name for member in base_opt.members] self.member_names[base_opt.name] = members if base_opt.primary_interface_name: primary_name = base_opt.primary_interface_name primary_mac = utils.interface_mac(primary_name) data += "MACADDR=\"%s\"\n" % primary_mac elif isinstance(base_opt, objects.LinuxBond): if base_opt.primary_interface_name: primary_name = base_opt.primary_interface_name primary_mac = utils.interface_mac(primary_name) data += "MACADDR=\"%s\"\n" % primary_mac if base_opt.use_dhcp: data += "BOOTPROTO=dhcp\n" if base_opt.members: members = [member.name for member in base_opt.members] self.member_names[base_opt.name] = members if base_opt.bonding_options: data += "BONDING_OPTS=\"%s\"\n" % base_opt.bonding_options elif isinstance(base_opt, objects.LinuxTeam): if base_opt.primary_interface_name: primary_name = base_opt.primary_interface_name primary_mac = utils.interface_mac(primary_name) data += "MACADDR=\"%s\"\n" % primary_mac if base_opt.use_dhcp: data += "BOOTPROTO=dhcp\n" if base_opt.members: members = [member.name for member in base_opt.members] self.member_names[base_opt.name] = members data += "DEVICETYPE=Team\n" if base_opt.bonding_options: data += "TEAM_CONFIG='%s'\n" % base_opt.bonding_options elif isinstance(base_opt, objects.OvsTunnel): ovs_extra.extend(base_opt.ovs_extra) data += "DEVICETYPE=ovs\n" data += "TYPE=OVSTunnel\n" data += "OVS_BRIDGE=%s\n" % base_opt.bridge_name data += "OVS_TUNNEL_TYPE=%s\n" % base_opt.tunnel_type data += "OVS_TUNNEL_OPTIONS=\"%s\"\n" % \ ' '.join(base_opt.ovs_options) elif isinstance(base_opt, objects.OvsPatchPort): ovs_extra.extend(base_opt.ovs_extra) data += "DEVICETYPE=ovs\n" data += "TYPE=OVSPatchPort\n" data += "OVS_BRIDGE=%s\n" % base_opt.bridge_name data += "OVS_PATCH_PEER=%s\n" % base_opt.peer elif isinstance(base_opt, objects.OvsDpdkPort): ovs_extra.extend(base_opt.ovs_extra) data += "DEVICETYPE=ovs\n" data += "TYPE=OVSDPDKPort\n" data += "OVS_BRIDGE=%s\n" % base_opt.bridge_name # Validation of DPDK port having only one interface is done prior # to this. So accesing the interface name statically. # Also pci_address would be valid here, since # bind_dpdk_interfaces() is invoked before this. pci_address = utils.get_stored_pci_address( base_opt.members[0].name, self.noop) ovs_extra.append("set Interface $DEVICE options:dpdk-devargs=" "%s" % pci_address) if base_opt.mtu: ovs_extra.append("set Interface $DEVICE mtu_request=$MTU") if base_opt.rx_queue: data += "RX_QUEUE=%i\n" % base_opt.rx_queue ovs_extra.append("set Interface $DEVICE " + "options:n_rxq=$RX_QUEUE") elif isinstance(base_opt, objects.OvsDpdkBond): ovs_extra.extend(base_opt.ovs_extra) # Referring to bug:1643026, the below commenting of the interfaces, # is to workaround the error, but is not the long term solution. # The long term solution is to run DPDK options before # os-net-config, which is being tracked at BUG:1654975 # if base_opt.primary_interface_name: # primary_name = base_opt.primary_interface_name # self.bond_primary_ifaces[base_opt.name] = primary_name data += "DEVICETYPE=ovs\n" data += "TYPE=OVSDPDKBond\n" data += "OVS_BRIDGE=%s\n" % base_opt.bridge_name if base_opt.members: for bond_member in base_opt.members: # Validation of DPDK port having only one interface is done # prior to this. So accesing the interface name statically. # Also pci_address would be valid here, since # bind_dpdk_interfaces () is invoked before this. pci_address = utils.get_stored_pci_address( bond_member.members[0].name, self.noop) ovs_extra.append("set Interface %s options:" "dpdk-devargs=%s" % (bond_member.name, pci_address)) members = [member.name for member in base_opt.members] data += ("BOND_IFACES=\"%s\"\n" % " ".join(members)) # MTU configuration given for the OvsDpdkbond shall be applied # to each of the members of the OvsDpdkbond if base_opt.mtu: for member in base_opt.members: ovs_extra.append("set Interface %s mtu_request=$MTU" % member.name) if base_opt.rx_queue: data += "RX_QUEUE=%i\n" % base_opt.rx_queue for member in base_opt.members: ovs_extra.append("set Interface %s options:n_rxq=" "$RX_QUEUE" % member.name) if base_opt.ovs_options: data += "OVS_OPTIONS=\"%s\"\n" % base_opt.ovs_options ovs_extra.extend(base_opt.ovs_extra) else: if base_opt.use_dhcp: data += "BOOTPROTO=dhcp\n" elif not base_opt.addresses: data += "BOOTPROTO=none\n" if isinstance(base_opt, objects.Interface): if base_opt.ethtool_opts: data += "ETHTOOL_OPTS=\"%s\"\n" % base_opt.ethtool_opts if base_opt.mtu: data += "MTU=%i\n" % base_opt.mtu if base_opt.use_dhcpv6 or base_opt.v6_addresses(): data += "IPV6INIT=yes\n" if base_opt.mtu: data += "IPV6_MTU=%i\n" % base_opt.mtu if base_opt.use_dhcpv6: data += "DHCPV6C=yes\n" elif base_opt.addresses: v4_addresses = base_opt.v4_addresses() if v4_addresses: data += "BOOTPROTO=static\n" for i, address in enumerate(v4_addresses): num = '%s' % i if i else '' data += "IPADDR%s=%s\n" % (num, address.ip) data += "NETMASK%s=%s\n" % (num, address.netmask) v6_addresses = base_opt.v6_addresses() if v6_addresses: first_v6 = v6_addresses[0] data += "IPV6_AUTOCONF=no\n" data += "IPV6ADDR=%s\n" % first_v6.ip_netmask if len(v6_addresses) > 1: secondaries_v6 = " ".join(map(lambda a: a.ip_netmask, v6_addresses[1:])) data += "IPV6ADDR_SECONDARIES=\"%s\"\n" % secondaries_v6 if base_opt.hwaddr: data += "HWADDR=%s\n" % base_opt.hwaddr if ovs_extra: data += "OVS_EXTRA=\"%s\"\n" % " -- ".join(ovs_extra) if not base_opt.defroute: data += "DEFROUTE=no\n" if base_opt.dhclient_args: data += "DHCLIENTARGS=%s\n" % base_opt.dhclient_args if base_opt.dns_servers: data += "DNS1=%s\n" % base_opt.dns_servers[0] if len(base_opt.dns_servers) >= 2: data += "DNS2=%s\n" % base_opt.dns_servers[1] if len(base_opt.dns_servers) > 2: logger.warning('ifcfg format supports max 2 resolvers.') return data