232
218
InterfaceName: "br-eth0.250",
233
InterfaceType: string(network.VLAN_8021QInterface),
219
InterfaceType: string(network.BridgeInterface),
234
220
MACAddress: "aa:bb:cc:dd:ee:f0",
235
221
CIDR: "10.250.19.0/24",
236
222
Address: "10.250.19.100",
224
ConfigType: string(network.ConfigStatic),
240
227
InterfaceName: "br-eth0.50",
241
InterfaceType: string(network.VLAN_8021QInterface),
228
InterfaceType: string(network.BridgeInterface),
242
229
MACAddress: "aa:bb:cc:dd:ee:f0",
243
230
CIDR: "10.50.19.0/24",
244
231
Address: "10.50.19.100",
248
InterfaceName: "eth0",
249
InterfaceType: string(network.EthernetInterface),
250
MACAddress: "aa:bb:cc:dd:ee:f0",
254
InterfaceName: "eth0.100",
255
InterfaceType: string(network.VLAN_8021QInterface),
256
MACAddress: "aa:bb:cc:dd:ee:f0",
260
InterfaceName: "eth0.250",
261
InterfaceType: string(network.VLAN_8021QInterface),
262
MACAddress: "aa:bb:cc:dd:ee:f0",
266
InterfaceName: "eth0.50",
267
InterfaceType: string(network.VLAN_8021QInterface),
268
MACAddress: "aa:bb:cc:dd:ee:f0",
233
ConfigType: string(network.ConfigStatic),
236
InterfaceName: "eth0",
237
ParentInterfaceName: "br-eth0",
238
InterfaceType: string(network.EthernetInterface),
239
MACAddress: "aa:bb:cc:dd:ee:f0",
241
ConfigType: string(network.ConfigManual),
244
InterfaceName: "eth0.100",
245
ParentInterfaceName: "br-eth0.100",
246
InterfaceType: string(network.VLAN_8021QInterface),
247
MACAddress: "aa:bb:cc:dd:ee:f0",
249
ConfigType: string(network.ConfigManual),
252
InterfaceName: "eth0.250",
253
ParentInterfaceName: "br-eth0.250",
254
InterfaceType: string(network.VLAN_8021QInterface),
255
MACAddress: "aa:bb:cc:dd:ee:f0",
257
ConfigType: string(network.ConfigManual),
260
InterfaceName: "eth0.50",
261
ParentInterfaceName: "br-eth0.50",
262
InterfaceType: string(network.VLAN_8021QInterface),
263
MACAddress: "aa:bb:cc:dd:ee:f0",
265
ConfigType: string(network.ConfigManual),
272
268
InterfaceName: "br-eth1",
273
InterfaceType: string(network.EthernetInterface),
269
InterfaceType: string(network.BridgeInterface),
274
270
MACAddress: "aa:bb:cc:dd:ee:f1",
275
271
CIDR: "10.20.19.0/24",
276
272
Address: "10.20.19.105",
274
ConfigType: string(network.ConfigStatic),
280
277
InterfaceName: "br-eth1.11",
281
InterfaceType: string(network.VLAN_8021QInterface),
278
InterfaceType: string(network.BridgeInterface),
282
279
MACAddress: "aa:bb:cc:dd:ee:f1",
283
280
CIDR: "10.11.19.0/24",
284
281
Address: "10.11.19.101",
283
ConfigType: string(network.ConfigStatic),
288
286
InterfaceName: "br-eth1.12",
289
InterfaceType: string(network.VLAN_8021QInterface),
287
InterfaceType: string(network.BridgeInterface),
290
288
MACAddress: "aa:bb:cc:dd:ee:f1",
291
289
CIDR: "10.12.19.0/24",
292
290
Address: "10.12.19.101",
292
ConfigType: string(network.ConfigStatic),
296
295
InterfaceName: "br-eth1.13",
297
InterfaceType: string(network.VLAN_8021QInterface),
296
InterfaceType: string(network.BridgeInterface),
298
297
MACAddress: "aa:bb:cc:dd:ee:f1",
299
298
CIDR: "10.13.19.0/24",
300
299
Address: "10.13.19.101",
304
InterfaceName: "eth1",
305
InterfaceType: string(network.EthernetInterface),
306
MACAddress: "aa:bb:cc:dd:ee:f1",
310
InterfaceName: "eth1.11",
311
InterfaceType: string(network.VLAN_8021QInterface),
312
MACAddress: "aa:bb:cc:dd:ee:f1",
316
InterfaceName: "eth1.12",
317
InterfaceType: string(network.VLAN_8021QInterface),
318
MACAddress: "aa:bb:cc:dd:ee:f1",
322
InterfaceName: "eth1.13",
323
InterfaceType: string(network.VLAN_8021QInterface),
324
MACAddress: "aa:bb:cc:dd:ee:f1",
301
ConfigType: string(network.ConfigStatic),
304
InterfaceName: "eth1",
305
ParentInterfaceName: "br-eth1",
306
InterfaceType: string(network.EthernetInterface),
307
MACAddress: "aa:bb:cc:dd:ee:f1",
309
ConfigType: string(network.ConfigManual),
312
InterfaceName: "eth1.11",
313
ParentInterfaceName: "br-eth1.11",
314
InterfaceType: string(network.VLAN_8021QInterface),
315
MACAddress: "aa:bb:cc:dd:ee:f1",
317
ConfigType: string(network.ConfigManual),
320
InterfaceName: "eth1.12",
321
ParentInterfaceName: "br-eth1.12",
322
InterfaceType: string(network.VLAN_8021QInterface),
323
MACAddress: "aa:bb:cc:dd:ee:f1",
325
ConfigType: string(network.ConfigManual),
328
InterfaceName: "eth1.13",
329
ParentInterfaceName: "br-eth1.13",
330
InterfaceType: string(network.VLAN_8021QInterface),
331
MACAddress: "aa:bb:cc:dd:ee:f1",
333
ConfigType: string(network.ConfigManual),
328
var expectedSortedProviderNetworkConfigs = []params.NetworkConfig{{
336
var expectedProviderNetworkConfigs = []params.NetworkConfig{{
329
337
InterfaceName: "eth0",
330
338
InterfaceType: string(network.EthernetInterface),
331
339
MACAddress: "aa:bb:cc:dd:ee:f0",
896
887
ProviderID: "1302",
899
func (s *TypesSuite) TestSortNetworkConfigsByParentsWithObservedConfigs(c *gc.C) {
900
s.checkSortNetworkConfigsByParentsWithAllInputPremutationsMatches(c, expectedSortedObservedNetworkConfigs)
903
func (s *TypesSuite) checkSortNetworkConfigsByParentsWithAllInputPremutationsMatches(c *gc.C, expectedOutput []params.NetworkConfig) {
904
expectedLength := len(expectedOutput)
905
jsonExpected := s.networkConfigsAsJSON(c, expectedOutput)
906
for i := 0; i < expectedLength; i++ {
907
shuffledInput := shuffleNetworkConfigs(expectedOutput)
908
result := networkingcommon.SortNetworkConfigsByParents(shuffledInput)
909
c.Assert(result, gc.HasLen, expectedLength)
910
jsonResult := s.networkConfigsAsJSON(c, result)
911
c.Check(jsonResult, gc.Equals, jsonExpected)
915
func (s *TypesSuite) networkConfigsAsJSON(c *gc.C, input []params.NetworkConfig) string {
916
asJSON, err := networkingcommon.NetworkConfigsToIndentedJSON(input)
917
c.Assert(err, jc.ErrorIsNil)
921
func shuffleNetworkConfigs(input []params.NetworkConfig) []params.NetworkConfig {
922
inputLength := len(input)
923
output := make([]params.NetworkConfig, inputLength)
924
shuffled := rand.Perm(inputLength)
925
for i, j := range shuffled {
931
func (s *TypesSuite) TestSortNetworkConfigsByParentsWithProviderConfigs(c *gc.C) {
932
s.checkSortNetworkConfigsByParentsWithAllInputPremutationsMatches(c, expectedSortedProviderNetworkConfigs)
935
func (s *TypesSuite) TestSortNetworkConfigsByParentsWithMergedConfigs(c *gc.C) {
936
s.checkSortNetworkConfigsByParentsWithAllInputPremutationsMatches(c, expectedSortedMergedNetworkConfigs)
939
func (s *TypesSuite) TestSortNetworkConfigsByInterfaceName(c *gc.C) {
940
expectedLength := len(expectedSortedNetworkConfigsByInterfaceName)
941
jsonExpected := s.networkConfigsAsJSON(c, expectedSortedNetworkConfigsByInterfaceName)
942
for i := 0; i < expectedLength; i++ {
943
shuffledInput := shuffleNetworkConfigs(expectedSortedNetworkConfigsByInterfaceName)
944
result := networkingcommon.SortNetworkConfigsByInterfaceName(shuffledInput)
945
c.Assert(result, gc.HasLen, expectedLength)
946
jsonResult := s.networkConfigsAsJSON(c, result)
947
c.Check(jsonResult, gc.Equals, jsonExpected)
951
890
func (s *TypesSuite) TestNetworkConfigsToStateArgs(c *gc.C) {
952
devicesArgs, devicesAddrs := networkingcommon.NetworkConfigsToStateArgs(expectedSortedMergedNetworkConfigs)
954
c.Check(devicesArgs, jc.DeepEquals, expectedLinkLayerDeviceArgsWithMergedNetworkConfig)
955
c.Check(devicesAddrs, jc.DeepEquals, expectedLinkLayerDeviceAdressesWithMergedNetworkConfig)
891
devicesArgs, devicesAddrs := networkingcommon.NetworkConfigsToStateArgs(expectedFinalNetworkConfigs)
893
c.Check(devicesArgs, jc.DeepEquals, expectedLinkLayerDeviceArgsWithFinalNetworkConfig)
894
c.Check(devicesAddrs, jc.DeepEquals, expectedLinkLayerDeviceAdressesWithFinalNetworkConfig)
897
func (s *TypesSuite) TestMergeProviderAndObservedNetworkConfigsBothNil(c *gc.C) {
898
result := networkingcommon.MergeProviderAndObservedNetworkConfigs(nil, nil)
899
c.Check(result, gc.IsNil)
902
func (s *TypesSuite) TestMergeProviderAndObservedNetworkConfigsNilObservedConfigs(c *gc.C) {
903
input := expectedProviderNetworkConfigs
904
result := networkingcommon.MergeProviderAndObservedNetworkConfigs(input, nil)
905
c.Check(result, gc.IsNil)
908
func (s *TypesSuite) TestMergeProviderAndObservedNetworkConfigsNilProviderConfigs(c *gc.C) {
909
input := expectedObservedNetworkConfigs
910
result := networkingcommon.MergeProviderAndObservedNetworkConfigs(nil, input)
911
c.Check(result, jc.DeepEquals, input)
958
914
func (s *TypesSuite) TestMergeProviderAndObservedNetworkConfigs(c *gc.C) {
959
observedConfigsLength := len(expectedSortedObservedNetworkConfigs)
960
providerConfigsLength := len(expectedSortedProviderNetworkConfigs)
961
jsonExpected := s.networkConfigsAsJSON(c, expectedSortedMergedNetworkConfigs)
962
for i := 0; i < observedConfigsLength; i++ {
963
shuffledObservedConfigs := shuffleNetworkConfigs(expectedSortedObservedNetworkConfigs)
964
for j := 0; j < providerConfigsLength; j++ {
965
shuffledProviderConfigs := shuffleNetworkConfigs(expectedSortedProviderNetworkConfigs)
967
mergedConfigs, err := networkingcommon.MergeProviderAndObservedNetworkConfigs(shuffledProviderConfigs, shuffledObservedConfigs)
968
c.Assert(err, jc.ErrorIsNil)
969
jsonResult := s.networkConfigsAsJSON(c, mergedConfigs)
970
c.Check(jsonResult, gc.Equals, jsonExpected)
915
observedConfig := expectedObservedNetworkConfigs
916
providerConfig := expectedProviderNetworkConfigs
917
result := networkingcommon.MergeProviderAndObservedNetworkConfigs(providerConfig, observedConfig)
918
c.Check(result, jc.DeepEquals, expectedFinalNetworkConfigs)
975
921
func (s *TypesSuite) TestGetObservedNetworkConfigInterfacesError(c *gc.C) {