Skip to content

Commit

Permalink
Merge pull request #649 from unclejack/return_err
Browse files Browse the repository at this point in the history
return directly instead of using if where possible
  • Loading branch information
unclejack authored Dec 21, 2016
2 parents f66d2a8 + f03f917 commit a063024
Show file tree
Hide file tree
Showing 18 changed files with 33 additions and 179 deletions.
15 changes: 2 additions & 13 deletions drivers/ovsdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,7 @@ func (d *OvsDriver) AddMaster(node core.ServiceInfo) error {
if err != nil {
return err
}
err = d.switchDb["vxlan"].AddMaster(node)

if err != nil {
return err
}
return nil
return d.switchDb["vxlan"].AddMaster(node)
}

// DeleteMaster deletes master node
Expand All @@ -628,13 +623,7 @@ func (d *OvsDriver) DeleteMaster(node core.ServiceInfo) error {
if err != nil {
return err
}
err = d.switchDb["vxlan"].DeleteMaster(node)

if err != nil {
return err
}

return nil
return d.switchDb["vxlan"].DeleteMaster(node)
}

// AddBgp adds bgp config by named identifier
Expand Down
14 changes: 2 additions & 12 deletions netmaster/docknet/docknet.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,7 @@ func CreateDockNet(tenantName, networkName, serviceName string, nwCfg *mastercfg
dnetOper.StateDriver = stateDriver

// write the dnet oper state
err = dnetOper.Write()
if err != nil {
return err
}

return nil
return dnetOper.Write()
}

// DeleteDockNet deletes a network in docker daemon
Expand Down Expand Up @@ -238,12 +233,7 @@ func DeleteDockNet(tenantName, networkName, serviceName string) error {
dnetOper.StateDriver = stateDriver

// write the dnet oper state
err = dnetOper.Clear()
if err != nil {
return err
}

return nil
return dnetOper.Clear()
}

// FindDocknetByUUID find the docknet by UUID
Expand Down
6 changes: 1 addition & 5 deletions netmaster/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ func parseOpts(opts *cliOpts) error {
false,
"prints current version")

if err := flagSet.Parse(os.Args[1:]); err != nil {
return err
}

return nil
return flagSet.Parse(os.Args[1:])
}

func execOpts(opts *cliOpts) {
Expand Down
7 changes: 1 addition & 6 deletions netmaster/master/bgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ func AddBgp(stateDriver core.StateDriver, bgpCfg *intent.ConfigBgp) error {
bgpState.Neighbor = bgpCfg.Neighbor
bgpState.StateDriver = stateDriver
bgpState.ID = bgpCfg.Hostname
err := bgpState.Write()

if err != nil {
return err
}
return nil
return bgpState.Write()
}

//DeleteBgp deletes from etcd state
Expand Down
13 changes: 2 additions & 11 deletions netmaster/master/endpointGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,7 @@ func CreateEndpointGroup(tenantName, networkName, groupName string) error {
log.Debugf("ACI -- Allocated vlan %v for epg %v", pktTag, groupName)

}
err = epgCfg.Write()
if err != nil {
return err
}

return nil
return epgCfg.Write()
}

// DeleteEndpointGroup handles endpoint group deletes
Expand Down Expand Up @@ -224,9 +219,5 @@ func UpdateEndpointGroup(bandwidth, groupName, tenantName string, Dscp, burst in
epCfg.Burst = burst

//Write to etcd
err = epCfg.Write()
if err != nil {
return err
}
return nil
return epCfg.Write()
}
14 changes: 2 additions & 12 deletions netmaster/master/netmaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,7 @@ func CreateGlobal(stateDriver core.StateDriver, gc *intent.ConfigGlobal) error {
return err
}
}
err = masterGc.Write()
if err != nil {
return err
}

return nil
return masterGc.Write()
}

// UpdateGlobal updates the global state
Expand Down Expand Up @@ -287,12 +282,7 @@ func UpdateGlobal(stateDriver core.StateDriver, gc *intent.ConfigGlobal) error {
}
}

err = masterGc.Write()
if err != nil {
return err
}

return nil
return masterGc.Write()
}

// DeleteGlobal delete global state
Expand Down
7 changes: 1 addition & 6 deletions netmaster/master/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,7 @@ func attachServiceContainer(tenantName, networkName string, stateDriver core.Sta
log.Infof("Dns server for network %s: %s", networkName, nwCfg.DNSServer)

// write the network config
err = nwCfg.Write()
if err != nil {
return err
}

return nil
return nwCfg.Write()
}

// detachServiceContainer detaches the service container's endpoint during network delete
Expand Down
13 changes: 2 additions & 11 deletions netmaster/master/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ func SvcProviderUpdate(serviceID string, isDelete bool) error {

if _, present := mastercfg.ServiceLBDb[serviceID]; !present {
svcProvider.ID = serviceID
err = svcProvider.Clear()
if err != nil {
return err
}
return nil
return svcProvider.Clear()
}

for _, provider := range mastercfg.ServiceLBDb[serviceID].Providers {
Expand All @@ -55,12 +51,7 @@ func SvcProviderUpdate(serviceID string, isDelete bool) error {

log.Infof("Updating service providers with {%v} on service %s", svcProvider.Providers, serviceID)

err = svcProvider.Write()

if err != nil {
return err
}
return nil
return svcProvider.Write()
}

func getProviderID(provider *mastercfg.Provider) string {
Expand Down
12 changes: 2 additions & 10 deletions netmaster/objApi/apiController.go
Original file line number Diff line number Diff line change
Expand Up @@ -1133,12 +1133,7 @@ func (ac *APIController) NetworkDelete(network *contivModel.Network) error {
}

// Save the tenant too since we removed the links
err = tenant.Write()
if err != nil {
return err
}

return nil
return tenant.Write()
}

// NetprofileCreate creates the network rule
Expand Down Expand Up @@ -2149,10 +2144,7 @@ func (ac *APIController) ServiceLBGetOper(serviceLB *contivModel.ServiceLBInspec
}

func validateSelectors(selector string) bool {
if strings.Count(selector, "=") == 1 {
return true
}
return false
return strings.Count(selector, "=") == 1
}

func validatePorts(ports []string) bool {
Expand Down
6 changes: 1 addition & 5 deletions netmaster/objApi/extContracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ func setupExternalContracts(endpointGroup *contivModel.EndpointGroup, extContrac

// Check if the external contracts are being used by any of the EPGs.
func isExtContractsGroupUsed(contractsGroup *contivModel.ExtContractsGroup) bool {
if len(contractsGroup.LinkSets.EndpointGroups) > 0 {
return true
}

return false
return len(contractsGroup.LinkSets.EndpointGroups) > 0
}

// ExtContractsGroupCreate creates a new group of external contracts
Expand Down
7 changes: 1 addition & 6 deletions netmaster/resources/stateresourcemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,7 @@ func (rm *StateResourceManager) DefineResource(id, desc string,
return core.Errorf("Resource with id: %q already exists", id)
}

err = rsrc.Init(rsrcCfg)
if err != nil {
return err
}

return nil
return rsrc.Init(rsrcCfg)
}

// UndefineResource deinitializes a resource.
Expand Down
20 changes: 3 additions & 17 deletions netmaster/resources/vlanresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,7 @@ func (r *AutoVLANCfgResource) Init(rsrcCfg interface{}) error {
oper := &AutoVLANOperResource{FreeVLANs: r.VLANs}
oper.StateDriver = r.StateDriver
oper.ID = r.ID
err = oper.Write()
if err != nil {
return err
}

return nil
return oper.Write()
}

// Deinit the resource.
Expand Down Expand Up @@ -148,12 +143,7 @@ func (r *AutoVLANCfgResource) Reinit(rsrcCfg interface{}) error {
oper.FreeVLANs.Clear(i)
}

err = oper.Write()
if err != nil {
return err
}

return nil
return oper.Write()
}

// Description is a description of this resource. returns AutoVLANResource.
Expand Down Expand Up @@ -268,11 +258,7 @@ func (r *AutoVLANCfgResource) Deallocate(value interface{}) error {
}
oper.FreeVLANs.Set(vlan)

err = oper.Write()
if err != nil {
return err
}
return nil
return oper.Write()
}

// AutoVLANOperResource is an implementation of core.State.
Expand Down
20 changes: 3 additions & 17 deletions netmaster/resources/vxlanresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,7 @@ func (r *AutoVXLANCfgResource) Init(rsrcCfg interface{}) error {
oper := &AutoVXLANOperResource{FreeVXLANs: r.VXLANs, FreeLocalVLANs: r.LocalVLANs}
oper.StateDriver = r.StateDriver
oper.ID = r.ID
err = oper.Write()
if err != nil {
return err
}

return nil
return oper.Write()
}

// Deinit the resource.
Expand Down Expand Up @@ -169,12 +164,7 @@ func (r *AutoVXLANCfgResource) Reinit(rsrcCfg interface{}) error {

oper.FreeLocalVLANs = oper.FreeLocalVLANs.Intersection(r.LocalVLANs)

err = oper.Write()
if err != nil {
return err
}

return nil
return oper.Write()
}

// Description is a string description of the resource. Returns AutoVXLANResource.
Expand Down Expand Up @@ -288,11 +278,7 @@ func (r *AutoVXLANCfgResource) Deallocate(value interface{}) error {
vlan := pair.VLAN
oper.FreeLocalVLANs.Set(vlan)

err = oper.Write()
if err != nil {
return err
}
return nil
return oper.Write()
}

// AutoVXLANOperResource is an implementation of core.State
Expand Down
5 changes: 1 addition & 4 deletions netplugin/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,8 @@ func Init(storeURL string) error {

// Create an objdb client
ObjdbClient, err = objdb.NewClient(storeURL)
if err != nil {
return err
}

return nil
return err
}

// RunLoop registers netplugin service with cluster store and runs peer discovery
Expand Down
6 changes: 2 additions & 4 deletions netplugin/svcplugin/skydns2extension/skydns2.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ type Skydns2Adapter struct {
// Ping will try to connect to skydns2 by attempting to retrieve a key
func (r *Skydns2Adapter) Ping() error {
_, err := r.client.Get(context.Background(), "/", &client.GetOptions{Recursive: true, Sort: true})
if err != nil {
return err
}
return nil

return err
}

// Register will register Skydns2Adapter's interface with RegistryAdapter
Expand Down
19 changes: 3 additions & 16 deletions state/consulstatedriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,8 @@ func (d *ConsulStateDriver) Init(instInfo *core.InstanceInfo) error {
}

d.Client, err = api.NewClient(&cfg)
if err != nil {
return err
}

return nil
return err
}

// Deinit is currently a no-op.
Expand Down Expand Up @@ -270,12 +267,7 @@ func (d *ConsulStateDriver) ReadState(key string, value core.State,
return err
}

err = unmarshal(encodedState, value)
if err != nil {
return err
}

return nil
return unmarshal(encodedState, value)
}

// ReadAllState Reads all the state from baseKey and returns a list of core.State.
Expand Down Expand Up @@ -313,10 +305,5 @@ func (d *ConsulStateDriver) WriteState(key string, value core.State,
return err
}

err = d.Write(key, encodedState)
if err != nil {
return err
}

return nil
return d.Write(key, encodedState)
}
Loading

0 comments on commit a063024

Please sign in to comment.