Exemple #1
0
func (s *TypesSuite) TestGetObservedNetworkConfigLoopbackInfrerred(c *gc.C) {
	s.stubConfigSource.interfaces = exampleObservedInterfaces[0:1] // only lo
	s.stubConfigSource.makeSysClassNetInterfacePath(c, "lo", "")

	observedConfig, err := networkingcommon.GetObservedNetworkConfig(s.stubConfigSource)
	c.Check(err, jc.ErrorIsNil)
	c.Check(observedConfig, jc.DeepEquals, []params.NetworkConfig{{
		DeviceIndex:   1,
		CIDR:          "127.0.0.0/8",
		Address:       "127.0.0.1",
		MTU:           65536,
		InterfaceName: "lo",
		InterfaceType: "loopback", // inferred from the flags.
		ConfigType:    "loopback", // since it is a loopback
	}, {
		DeviceIndex:   1,
		MTU:           65536,
		InterfaceName: "lo",
		InterfaceType: "loopback",
		ConfigType:    "loopback",
	}})

	s.stubConfigSource.CheckCallNames(c, "Interfaces", "SysClassNetPath", "InterfaceAddresses")
	s.stubConfigSource.CheckCall(c, 2, "InterfaceAddresses", "lo")
}
Exemple #2
0
func (s *TypesSuite) TestGetObservedNetworkConfigVLANInfrerred(c *gc.C) {
	s.stubConfigSource.interfaces = exampleObservedInterfaces[6:7] // only eth0.100
	s.stubConfigSource.interfaceAddrs = map[string][]net.Addr{
		"eth0.100": []net.Addr{
			fakeAddr("fe80::5054:ff:fedd:eef0:100/64"),
			fakeAddr("10.100.19.123/24"),
		},
	}
	s.stubConfigSource.makeSysClassNetInterfacePath(c, "eth0.100", "vlan")

	observedConfig, err := networkingcommon.GetObservedNetworkConfig(s.stubConfigSource)
	c.Check(err, jc.ErrorIsNil)
	c.Check(observedConfig, jc.DeepEquals, []params.NetworkConfig{{
		DeviceIndex:   13,
		MACAddress:    "aa:bb:cc:dd:ee:f0",
		MTU:           1500,
		InterfaceName: "eth0.100",
		InterfaceType: "802.1q",
		ConfigType:    "manual", // the IPv6 address treated as empty.
	}, {
		DeviceIndex:   13,
		CIDR:          "10.100.19.0/24",
		Address:       "10.100.19.123",
		MACAddress:    "aa:bb:cc:dd:ee:f0",
		MTU:           1500,
		InterfaceName: "eth0.100",
		InterfaceType: "802.1q",
		ConfigType:    "static",
	}})

	s.stubConfigSource.CheckCallNames(c, "Interfaces", "SysClassNetPath", "InterfaceAddresses")
	s.stubConfigSource.CheckCall(c, 2, "InterfaceAddresses", "eth0.100")
}
Exemple #3
0
func (s *TypesSuite) TestGetObservedNetworkConfigInterfacesError(c *gc.C) {
	s.stubConfigSource.SetErrors(errors.New("no interfaces"))

	observedConfig, err := networkingcommon.GetObservedNetworkConfig(s.stubConfigSource)
	c.Check(err, gc.ErrorMatches, "cannot get network interfaces: no interfaces")
	c.Check(observedConfig, gc.IsNil)

	s.stubConfigSource.CheckCallNames(c, "Interfaces")
}
Exemple #4
0
func (s *TypesSuite) TestGetObservedNetworkConfigInterfaceAddressesError(c *gc.C) {
	s.stubConfigSource.SetErrors(
		nil, // Interfaces() succeeds.
		errors.New("no addresses"), // InterfaceAddressses fails.
	)

	observedConfig, err := networkingcommon.GetObservedNetworkConfig(s.stubConfigSource)
	c.Check(err, gc.ErrorMatches, `cannot get interface "lo" addresses: no addresses`)
	c.Check(observedConfig, gc.IsNil)

	s.stubConfigSource.CheckCallNames(c, "Interfaces", "SysClassNetPath", "InterfaceAddresses")
	s.stubConfigSource.CheckCall(c, 2, "InterfaceAddresses", "lo")
}
Exemple #5
0
func (s *TypesSuite) TestGetObservedNetworkConfigInvalidAddressValue(c *gc.C) {
	s.stubConfigSource.interfaces = exampleObservedInterfaces[1:2] // only eth0
	s.stubConfigSource.makeSysClassNetInterfacePath(c, "eth0", "")
	s.stubConfigSource.interfaceAddrs = map[string][]net.Addr{
		"eth0": []net.Addr{fakeAddr("invalid")},
	}

	observedConfig, err := networkingcommon.GetObservedNetworkConfig(s.stubConfigSource)
	c.Check(err, gc.ErrorMatches, `cannot parse IP address "invalid" on interface "eth0"`)
	c.Check(observedConfig, gc.IsNil)

	s.stubConfigSource.CheckCallNames(c, "Interfaces", "SysClassNetPath", "InterfaceAddresses")
	s.stubConfigSource.CheckCall(c, 2, "InterfaceAddresses", "eth0")
}
Exemple #6
0
func (s *TypesSuite) TestGetObservedNetworkConfig(c *gc.C) {
	s.PatchValue(networkingcommon.NetInterfaces, func() ([]net.Interface, error) {
		return exampleObservedInterfaces, nil
	})
	s.PatchValue(networkingcommon.InterfaceAddrs, func(i *net.Interface) ([]net.Addr, error) {
		c.Assert(i, gc.NotNil)
		if addrs, found := exampleObservedInterfaceAddrs[i.Name]; found {
			return addrs, nil
		}
		return nil, nil
	})

	observedConfig, err := networkingcommon.GetObservedNetworkConfig()
	c.Assert(err, jc.ErrorIsNil)
	jsonResult := s.networkConfigsAsJSON(c, observedConfig)
	jsonExpected := s.networkConfigsAsJSON(c, expectedSortedObservedNetworkConfigs)
	c.Check(jsonResult, gc.Equals, jsonExpected)
}
Exemple #7
0
func (s *TypesSuite) TestGetObservedNetworkConfigEthernetInfrerred(c *gc.C) {
	s.stubConfigSource.interfaces = exampleObservedInterfaces[1:2] // only eth0
	s.stubConfigSource.makeSysClassNetInterfacePath(c, "eth0", "")

	observedConfig, err := networkingcommon.GetObservedNetworkConfig(s.stubConfigSource)
	c.Check(err, jc.ErrorIsNil)
	c.Check(observedConfig, jc.DeepEquals, []params.NetworkConfig{{
		DeviceIndex:   2,
		MACAddress:    "aa:bb:cc:dd:ee:f0",
		MTU:           1500,
		InterfaceName: "eth0",
		InterfaceType: "ethernet",
		ConfigType:    "manual", // the IPv6 address treated as empty.
	}})

	s.stubConfigSource.CheckCallNames(c, "Interfaces", "SysClassNetPath", "InterfaceAddresses")
	s.stubConfigSource.CheckCall(c, 2, "InterfaceAddresses", "eth0")
}
Exemple #8
0
func (s *TypesSuite) TestGetObservedNetworkConfigNoInterfaceAddresses(c *gc.C) {
	s.stubConfigSource.interfaces = exampleObservedInterfaces[3:4] // only br-eth1
	s.stubConfigSource.interfaceAddrs = make(map[string][]net.Addr)
	s.stubConfigSource.makeSysClassNetInterfacePath(c, "br-eth1", "bridge")

	observedConfig, err := networkingcommon.GetObservedNetworkConfig(s.stubConfigSource)
	c.Check(err, jc.ErrorIsNil)
	c.Check(observedConfig, jc.DeepEquals, []params.NetworkConfig{{
		DeviceIndex:   11,
		MACAddress:    "aa:bb:cc:dd:ee:f1",
		MTU:           1500,
		InterfaceName: "br-eth1",
		InterfaceType: "bridge",
		ConfigType:    "manual",
	}})

	s.stubConfigSource.CheckCallNames(c, "Interfaces", "SysClassNetPath", "InterfaceAddresses")
	s.stubConfigSource.CheckCall(c, 2, "InterfaceAddresses", "br-eth1")
}
Exemple #9
0
func (s *TypesSuite) TestGetObservedNetworkConfigAddressNotInCIDRFormat(c *gc.C) {
	s.stubConfigSource.interfaces = exampleObservedInterfaces[1:2] // only eth0
	s.stubConfigSource.makeSysClassNetInterfacePath(c, "eth0", "")
	// Simluate running on Windows, where net.InterfaceAddrs() returns
	// non-CIDR-formatted addresses.
	s.stubConfigSource.interfaceAddrs = map[string][]net.Addr{
		"eth0": []net.Addr{fakeAddr("10.20.19.42")},
	}

	observedConfig, err := networkingcommon.GetObservedNetworkConfig(s.stubConfigSource)
	c.Check(err, jc.ErrorIsNil)
	c.Check(observedConfig, jc.DeepEquals, []params.NetworkConfig{{
		DeviceIndex:   2,
		Address:       "10.20.19.42", // just Address, no CIDR as netmask cannot be inferred.
		MACAddress:    "aa:bb:cc:dd:ee:f0",
		MTU:           1500,
		InterfaceName: "eth0",
		InterfaceType: "ethernet",
		ConfigType:    "static",
	}})

	s.stubConfigSource.CheckCallNames(c, "Interfaces", "SysClassNetPath", "InterfaceAddresses")
	s.stubConfigSource.CheckCall(c, 2, "InterfaceAddresses", "eth0")
}
Exemple #10
0
func (s *TypesSuite) TestGetObservedNetworkConfigBridgePortsHaveParentSet(c *gc.C) {
	s.stubConfigSource.interfaces = exampleObservedInterfaces[1:5] // eth0, br-eth0, br-eth1, eth1
	br0Path := s.stubConfigSource.makeSysClassNetInterfacePath(c, "br-eth0", "bridge")
	// "extra" added below to verify bridge ports which are discovered, but not
	// found as interfaces from the source will be ignored.
	s.stubConfigSource.makeSysClassNetBridgePorts(c, br0Path, "eth0", "extra")
	br1Path := s.stubConfigSource.makeSysClassNetInterfacePath(c, "br-eth1", "bridge")
	s.stubConfigSource.makeSysClassNetBridgePorts(c, br1Path, "eth1")

	observedConfig, err := networkingcommon.GetObservedNetworkConfig(s.stubConfigSource)
	c.Check(err, jc.ErrorIsNil)
	c.Check(observedConfig, jc.DeepEquals, []params.NetworkConfig{{
		DeviceIndex:         2,
		MACAddress:          "aa:bb:cc:dd:ee:f0",
		MTU:                 1500,
		InterfaceName:       "eth0",
		InterfaceType:       "ethernet",
		ParentInterfaceName: "br-eth0",
		ConfigType:          "manual",
	}, {
		DeviceIndex:   10,
		CIDR:          "10.20.19.0/24",
		Address:       "10.20.19.100",
		MACAddress:    "aa:bb:cc:dd:ee:f0",
		MTU:           1500,
		InterfaceName: "br-eth0",
		InterfaceType: "bridge",
		ConfigType:    "static",
	}, {
		DeviceIndex:   10,
		CIDR:          "10.20.19.0/24",
		Address:       "10.20.19.123",
		MACAddress:    "aa:bb:cc:dd:ee:f0",
		MTU:           1500,
		InterfaceName: "br-eth0",
		InterfaceType: "bridge",
		ConfigType:    "static",
	}, {
		DeviceIndex:   10,
		MACAddress:    "aa:bb:cc:dd:ee:f0",
		MTU:           1500,
		InterfaceName: "br-eth0",
		InterfaceType: "bridge",
		ConfigType:    "manual",
	}, {
		DeviceIndex:   11,
		CIDR:          "10.20.19.0/24",
		Address:       "10.20.19.105",
		MACAddress:    "aa:bb:cc:dd:ee:f1",
		MTU:           1500,
		InterfaceName: "br-eth1",
		InterfaceType: "bridge",
		ConfigType:    "static",
	}, {
		DeviceIndex:   11,
		MACAddress:    "aa:bb:cc:dd:ee:f1",
		MTU:           1500,
		InterfaceName: "br-eth1",
		InterfaceType: "bridge",
		ConfigType:    "manual",
	}, {
		DeviceIndex:         3,
		MACAddress:          "aa:bb:cc:dd:ee:f1",
		MTU:                 1500,
		InterfaceName:       "eth1",
		InterfaceType:       "ethernet",
		ParentInterfaceName: "br-eth1",
		ConfigType:          "manual",
	}})

	s.stubConfigSource.CheckCallNames(c,
		"Interfaces", "SysClassNetPath",
		"InterfaceAddresses", // eth0
		"InterfaceAddresses", // br-eth0
		"InterfaceAddresses", // br-eth1
		"InterfaceAddresses", // eth1
	)
	s.stubConfigSource.CheckCall(c, 2, "InterfaceAddresses", "eth0")
	s.stubConfigSource.CheckCall(c, 3, "InterfaceAddresses", "br-eth0")
	s.stubConfigSource.CheckCall(c, 4, "InterfaceAddresses", "br-eth1")
	s.stubConfigSource.CheckCall(c, 5, "InterfaceAddresses", "eth1")
}