Exemplo n.º 1
0
Arquivo: machiner.go Projeto: bac/juju
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)
}
Exemplo n.º 2
0
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)
		}
	}
}
Exemplo n.º 3
0
func (s *TypesSuite) TestMergeProviderAndObservedNetworkConfigs(c *gc.C) {
	observedConfig := expectedObservedNetworkConfigs
	providerConfig := expectedProviderNetworkConfigs
	result := networkingcommon.MergeProviderAndObservedNetworkConfigs(providerConfig, observedConfig)
	c.Check(result, jc.DeepEquals, expectedFinalNetworkConfigs)
}
Exemplo n.º 4
0
func (s *TypesSuite) TestMergeProviderAndObservedNetworkConfigsNilProviderConfigs(c *gc.C) {
	input := expectedObservedNetworkConfigs
	result := networkingcommon.MergeProviderAndObservedNetworkConfigs(nil, input)
	c.Check(result, jc.DeepEquals, input)
}
Exemplo n.º 5
0
func (s *TypesSuite) TestMergeProviderAndObservedNetworkConfigsNilObservedConfigs(c *gc.C) {
	input := expectedProviderNetworkConfigs
	result := networkingcommon.MergeProviderAndObservedNetworkConfigs(input, nil)
	c.Check(result, gc.IsNil)
}
Exemplo n.º 6
0
func (s *TypesSuite) TestMergeProviderAndObservedNetworkConfigsBothNil(c *gc.C) {
	result := networkingcommon.MergeProviderAndObservedNetworkConfigs(nil, nil)
	c.Check(result, gc.IsNil)
}