本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/platform/net/ip/fakes.FakeInterfaceAddressesProvider类的典型用法代码示例。如果您正苦于以下问题:Golang FakeInterfaceAddressesProvider类的具体用法?Golang FakeInterfaceAddressesProvider怎么用?Golang FakeInterfaceAddressesProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FakeInterfaceAddressesProvider类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
//.........这里部分代码省略.........
}
err := bootstrap()
Expect(err).NotTo(HaveOccurred())
Expect(2).To(Equal(len(platform.SetTimeWithNtpServersServers)))
Expect("0.north-america.pool.ntp.org").To(Equal(platform.SetTimeWithNtpServersServers[0]))
Expect("1.north-america.pool.ntp.org").To(Equal(platform.SetTimeWithNtpServersServers[1]))
})
It("setups up monit user", func() {
err := bootstrap()
Expect(err).NotTo(HaveOccurred())
Expect(platform.SetupMonitUserSetup).To(BeTrue())
})
It("starts monit", func() {
err := bootstrap()
Expect(err).NotTo(HaveOccurred())
Expect(platform.StartMonitStarted).To(BeTrue())
})
})
Describe("Network setup exercised by Run", func() {
var (
settingsJSON string
fs *fakesys.FakeFileSystem
platform boshplatform.Platform
boot Bootstrap
defaultNetworkResolver boshsettings.DefaultNetworkResolver
logger boshlog.Logger
dirProvider boshdirs.Provider
interfaceAddrsProvider *fakeip.FakeInterfaceAddressesProvider
)
writeNetworkDevice := func(iface string, macAddress string, isPhysical bool) string {
interfacePath := fmt.Sprintf("/sys/class/net/%s", iface)
fs.WriteFile(interfacePath, []byte{})
if isPhysical {
fs.WriteFile(fmt.Sprintf("/sys/class/net/%s/device", iface), []byte{})
}
fs.WriteFileString(fmt.Sprintf("/sys/class/net/%s/address", iface), fmt.Sprintf("%s\n", macAddress))
return interfacePath
}
stubInterfaces := func(interfaces [][]string) {
var interfacePaths []string
for _, iface := range interfaces {
interfaceName := iface[0]
interfaceMAC := iface[1]
interfaceType := iface[2]
isPhysical := interfaceType == "physical"
interfacePaths = append(interfacePaths, writeNetworkDevice(interfaceName, interfaceMAC, isPhysical))
}
fs.SetGlob("/sys/class/net/*", interfacePaths)
}
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
runner := fakesys.NewFakeCmdRunner()
dirProvider = boshdirs.NewProvider("/var/vcap/bosh")
示例2: describeUbuntuNetManager
func describeUbuntuNetManager() {
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
ipResolver *fakeip.FakeResolver
addressBroadcaster *fakearp.FakeAddressBroadcaster
interfaceAddrsProvider *fakeip.FakeInterfaceAddressesProvider
netManager UbuntuNetManager
interfaceConfigurationCreator InterfaceConfigurationCreator
)
writeNetworkDevice := func(iface string, macAddress string, isPhysical bool) string {
interfacePath := fmt.Sprintf("/sys/class/net/%s", iface)
fs.WriteFile(interfacePath, []byte{})
if isPhysical {
fs.WriteFile(fmt.Sprintf("/sys/class/net/%s/device", iface), []byte{})
}
fs.WriteFileString(fmt.Sprintf("/sys/class/net/%s/address", iface), fmt.Sprintf("%s\n", macAddress))
return interfacePath
}
stubInterfacesWithVirtual := func(physicalInterfaces map[string]boshsettings.Network, virtualInterfaces []string) {
interfacePaths := []string{}
for iface, networkSettings := range physicalInterfaces {
interfacePaths = append(interfacePaths, writeNetworkDevice(iface, networkSettings.Mac, true))
}
for _, iface := range virtualInterfaces {
interfacePaths = append(interfacePaths, writeNetworkDevice(iface, "virtual", false))
}
fs.SetGlob("/sys/class/net/*", interfacePaths)
}
stubInterfaces := func(physicalInterfaces map[string]boshsettings.Network) {
stubInterfacesWithVirtual(physicalInterfaces, nil)
}
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
ipResolver = &fakeip.FakeResolver{}
logger := boshlog.NewLogger(boshlog.LevelNone)
interfaceConfigurationCreator = NewInterfaceConfigurationCreator(logger)
addressBroadcaster = &fakearp.FakeAddressBroadcaster{}
interfaceAddrsProvider = &fakeip.FakeInterfaceAddressesProvider{}
interfaceAddrsValidator := boship.NewInterfaceAddressesValidator(interfaceAddrsProvider)
dnsValidator := NewDNSValidator(fs)
netManager = NewUbuntuNetManager(
fs,
cmdRunner,
ipResolver,
interfaceConfigurationCreator,
interfaceAddrsValidator,
dnsValidator,
addressBroadcaster,
logger,
).(UbuntuNetManager)
})
Describe("ComputeNetworkConfig", func() {
Context("when there is one manual network and neither is marked as default for DNS", func() {
It("should use the manual network for DNS", func() {
networks := boshsettings.Networks{
"manual": factory.Network{DNS: &[]string{"8.8.8.8"}}.Build(),
}
stubInterfaces(networks)
_, _, dnsServers, err := netManager.ComputeNetworkConfig(networks)
Expect(err).ToNot(HaveOccurred())
Expect(dnsServers).To(Equal([]string{"8.8.8.8"}))
})
})
Context("when there is a vip network and a manual network and neither is marked as default for DNS", func() {
It("should use the manual network for DNS", func() {
networks := boshsettings.Networks{
"vip": boshsettings.Network{Type: "vip"},
"manual": factory.Network{Type: "manual", DNS: &[]string{"8.8.8.8"}}.Build(),
}
stubInterfaces(networks)
_, _, dnsServers, err := netManager.ComputeNetworkConfig(networks)
Expect(err).ToNot(HaveOccurred())
Expect(dnsServers).To(Equal([]string{"8.8.8.8"}))
})
})
Context("when there is a vip network and a manual network and the manual network is marked as default for DNS", func() {
It("should use the manual network for DNS", func() {
networks := boshsettings.Networks{
"vip": boshsettings.Network{Type: "vip"},
"manual": factory.Network{Type: "manual", DNS: &[]string{"8.8.8.8"}, Default: []string{"dns"}}.Build(),
}
stubInterfaces(networks)
_, _, dnsServers, err := netManager.ComputeNetworkConfig(networks)
Expect(err).ToNot(HaveOccurred())
Expect(dnsServers).To(Equal([]string{"8.8.8.8"}))
})
})
//.........这里部分代码省略.........
示例3: describeCentosNetManager
func describeCentosNetManager() {
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
ipResolver *fakeip.FakeResolver
interfaceAddrsProvider *fakeip.FakeInterfaceAddressesProvider
addressBroadcaster *fakearp.FakeAddressBroadcaster
netManager Manager
interfaceConfigurationCreator InterfaceConfigurationCreator
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
ipResolver = &fakeip.FakeResolver{}
logger := boshlog.NewLogger(boshlog.LevelNone)
interfaceConfigurationCreator = NewInterfaceConfigurationCreator(logger)
interfaceAddrsProvider = &fakeip.FakeInterfaceAddressesProvider{}
interfaceAddrsValidator := boship.NewInterfaceAddressesValidator(interfaceAddrsProvider)
dnsValidator := NewDNSValidator(fs)
addressBroadcaster = &fakearp.FakeAddressBroadcaster{}
netManager = NewCentosNetManager(
fs,
cmdRunner,
ipResolver,
interfaceConfigurationCreator,
interfaceAddrsValidator,
dnsValidator,
addressBroadcaster,
logger,
)
})
writeNetworkDevice := func(iface string, macAddress string, isPhysical bool) string {
interfacePath := fmt.Sprintf("/sys/class/net/%s", iface)
fs.WriteFile(interfacePath, []byte{})
if isPhysical {
fs.WriteFile(fmt.Sprintf("/sys/class/net/%s/device", iface), []byte{})
}
fs.WriteFileString(fmt.Sprintf("/sys/class/net/%s/address", iface), fmt.Sprintf("%s\n", macAddress))
return interfacePath
}
Describe("SetupNetworking", func() {
var (
dhcpNetwork boshsettings.Network
staticNetwork boshsettings.Network
expectedNetworkConfigurationForStatic string
expectedNetworkConfigurationForDHCP string
expectedDhclientConfiguration string
)
BeforeEach(func() {
dhcpNetwork = boshsettings.Network{
Type: "dynamic",
Default: []string{"dns"},
DNS: []string{"8.8.8.8", "9.9.9.9"},
Mac: "fake-dhcp-mac-address",
}
staticNetwork = boshsettings.Network{
Type: "manual",
IP: "1.2.3.4",
Netmask: "255.255.255.0",
Gateway: "3.4.5.6",
Mac: "fake-static-mac-address",
}
interfaceAddrsProvider.GetInterfaceAddresses = []boship.InterfaceAddress{
boship.NewSimpleInterfaceAddress("ethstatic", "1.2.3.4"),
}
fs.WriteFileString("/etc/resolv.conf", `
nameserver 8.8.8.8
nameserver 9.9.9.9
`)
expectedNetworkConfigurationForStatic = `DEVICE=ethstatic
BOOTPROTO=static
IPADDR=1.2.3.4
NETMASK=255.255.255.0
BROADCAST=1.2.3.255
GATEWAY=3.4.5.6
ONBOOT=yes
PEERDNS=no
DNS1=8.8.8.8
DNS2=9.9.9.9
`
expectedNetworkConfigurationForDHCP = `DEVICE=ethdhcp
BOOTPROTO=dhcp
ONBOOT=yes
PEERDNS=yes
`
expectedDhclientConfiguration = `# Generated by bosh-agent
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
send host-name "<hostname>";
request subnet-mask, broadcast-address, time-offset, routers,
//.........这里部分代码省略.........
示例4:
package ip_test
import (
"errors"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
boship "github.com/cloudfoundry/bosh-agent/platform/net/ip"
fakeip "github.com/cloudfoundry/bosh-agent/platform/net/ip/fakes"
)
var _ = Describe("InterfaceAddressesValidator", func() {
var (
interfaceAddrsProvider *fakeip.FakeInterfaceAddressesProvider
interfaceAddrsValidator boship.InterfaceAddressesValidator
)
BeforeEach(func() {
interfaceAddrsProvider = &fakeip.FakeInterfaceAddressesProvider{}
interfaceAddrsValidator = boship.NewInterfaceAddressesValidator(interfaceAddrsProvider)
})
Context("when networks match", func() {
BeforeEach(func() {
interfaceAddrsProvider.GetInterfaceAddresses = []boship.InterfaceAddress{
boship.NewSimpleInterfaceAddress("eth0", "1.2.3.4"),
boship.NewSimpleInterfaceAddress("eth1", "5.6.7.8"),
}
})