func (api *MachinerAPI) SetObservedNetworkConfig(args params.SetMachineNetworkConfig) error { m, err := api.getMachineForSettingNetworkConfig(args.Tag) if err != nil { return errors.Trace(err) } if m.IsContainer() { return nil } observedConfig := args.Config logger.Tracef("observed network config of machine %q: %+v", m.Id(), observedConfig) if len(observedConfig) == 0 { logger.Infof("not updating machine network config: no observed network config found") return nil } providerConfig, err := api.getOneMachineProviderNetworkConfig(m) if errors.IsNotProvisioned(err) { logger.Infof("not updating provider network config: %v", err) return nil } if err != nil { return errors.Trace(err) } if len(providerConfig) == 0 { logger.Infof("not updating machine network config: no provider network config found") return nil } mergedConfig := networkingcommon.MergeProviderAndObservedNetworkConfigs(providerConfig, observedConfig) logger.Tracef("merged observed and provider network config: %+v", mergedConfig) return api.setOneMachineNetworkConfig(m, mergedConfig) }
func (s *TypesSuite) TestMergeProviderAndObservedNetworkConfigs(c *gc.C) { observedConfigsLength := len(expectedSortedObservedNetworkConfigs) providerConfigsLength := len(expectedSortedProviderNetworkConfigs) jsonExpected := s.networkConfigsAsJSON(c, expectedSortedMergedNetworkConfigs) for i := 0; i < observedConfigsLength; i++ { shuffledObservedConfigs := shuffleNetworkConfigs(expectedSortedObservedNetworkConfigs) for j := 0; j < providerConfigsLength; j++ { shuffledProviderConfigs := shuffleNetworkConfigs(expectedSortedProviderNetworkConfigs) mergedConfigs := networkingcommon.MergeProviderAndObservedNetworkConfigs(shuffledProviderConfigs, shuffledObservedConfigs) jsonResult := s.networkConfigsAsJSON(c, mergedConfigs) c.Check(jsonResult, gc.Equals, jsonExpected) } } }
func (s *TypesSuite) TestMergeProviderAndObservedNetworkConfigs(c *gc.C) { observedConfig := expectedObservedNetworkConfigs providerConfig := expectedProviderNetworkConfigs result := networkingcommon.MergeProviderAndObservedNetworkConfigs(providerConfig, observedConfig) c.Check(result, jc.DeepEquals, expectedFinalNetworkConfigs) }
func (s *TypesSuite) TestMergeProviderAndObservedNetworkConfigsNilProviderConfigs(c *gc.C) { input := expectedObservedNetworkConfigs result := networkingcommon.MergeProviderAndObservedNetworkConfigs(nil, input) c.Check(result, jc.DeepEquals, input) }
func (s *TypesSuite) TestMergeProviderAndObservedNetworkConfigsNilObservedConfigs(c *gc.C) { input := expectedProviderNetworkConfigs result := networkingcommon.MergeProviderAndObservedNetworkConfigs(input, nil) c.Check(result, gc.IsNil) }
func (s *TypesSuite) TestMergeProviderAndObservedNetworkConfigsBothNil(c *gc.C) { result := networkingcommon.MergeProviderAndObservedNetworkConfigs(nil, nil) c.Check(result, gc.IsNil) }