Fixed issues highlighted by the new checks
Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
| ... | ... |
@@ -165,13 +165,13 @@ func (c *controller) handleKeyChange(keys []*types.EncryptionKey) error {
|
| 165 | 165 |
a.networkDB.SetKey(added) |
| 166 | 166 |
} |
| 167 | 167 |
|
| 168 |
- key, tag, err := c.getPrimaryKeyTag(subsysGossip) |
|
| 168 |
+ key, _, err := c.getPrimaryKeyTag(subsysGossip) |
|
| 169 | 169 |
if err != nil {
|
| 170 | 170 |
return err |
| 171 | 171 |
} |
| 172 | 172 |
a.networkDB.SetPrimaryKey(key) |
| 173 | 173 |
|
| 174 |
- key, tag, err = c.getPrimaryKeyTag(subsysIPSec) |
|
| 174 |
+ key, tag, err := c.getPrimaryKeyTag(subsysIPSec) |
|
| 175 | 175 |
if err != nil {
|
| 176 | 176 |
return err |
| 177 | 177 |
} |
| ... | ... |
@@ -914,6 +914,9 @@ func TestAttachDetachBackend(t *testing.T) {
|
| 914 | 914 |
|
| 915 | 915 |
cid := "abcdefghi" |
| 916 | 916 |
sbox, err := c.NewSandbox(cid) |
| 917 |
+ if err != nil {
|
|
| 918 |
+ t.Fatal(err) |
|
| 919 |
+ } |
|
| 917 | 920 |
sid := sbox.ID() |
| 918 | 921 |
defer sbox.Delete() |
| 919 | 922 |
|
| ... | ... |
@@ -1280,6 +1283,9 @@ func TestJoinLeave(t *testing.T) {
|
| 1280 | 1280 |
|
| 1281 | 1281 |
cid := "abcdefghi" |
| 1282 | 1282 |
sb, err := c.NewSandbox(cid) |
| 1283 |
+ if err != nil {
|
|
| 1284 |
+ t.Fatal(err) |
|
| 1285 |
+ } |
|
| 1283 | 1286 |
defer sb.Delete() |
| 1284 | 1287 |
|
| 1285 | 1288 |
jl := endpointJoin{SandboxID: sb.ID()}
|
| ... | ... |
@@ -13,7 +13,7 @@ var ( |
| 13 | 13 |
) |
| 14 | 14 |
|
| 15 | 15 |
func init() {
|
| 16 |
- flag.Bool([]string{"#hp", "#-halp"}, false, "display the halp")
|
|
| 16 |
+ flag.Bool([]string{"#hp", "#-help"}, false, "display the help")
|
|
| 17 | 17 |
flag.BoolVar(&b, []string{"b", "#bal", "#bol", "-bal"}, false, "a simple bool")
|
| 18 | 18 |
flag.BoolVar(&b, []string{"g", "#gil"}, false, "a simple bool")
|
| 19 | 19 |
flag.BoolVar(&b2, []string{"#-bool"}, false, "a simple bool")
|
| ... | ... |
@@ -22,7 +22,7 @@ type SetMatrix interface {
|
| 22 | 22 |
// returns true if the mapping was deleted, false otherwise |
| 23 | 23 |
// returns also the number of endpoints associated to the IP |
| 24 | 24 |
Remove(key string, value interface{}) (bool, int)
|
| 25 |
- // Cardinality returns the number of elements in the set of a specfic key |
|
| 25 |
+ // Cardinality returns the number of elements in the set of a specific key |
|
| 26 | 26 |
// returns false if the key is not in the map |
| 27 | 27 |
Cardinality(key string) (int, bool) |
| 28 | 28 |
// String returns the string version of the set, empty otherwise |
| ... | ... |
@@ -1014,7 +1014,7 @@ func (c *controller) NetworkByID(id string) (Network, error) {
|
| 1014 | 1014 |
} |
| 1015 | 1015 |
|
| 1016 | 1016 |
// NewSandbox creates a new sandbox for the passed container id |
| 1017 |
-func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (sBox Sandbox, err error) {
|
|
| 1017 |
+func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (Sandbox, error) {
|
|
| 1018 | 1018 |
if containerID == "" {
|
| 1019 | 1019 |
return nil, types.BadRequestErrorf("invalid container ID")
|
| 1020 | 1020 |
} |
| ... | ... |
@@ -1054,7 +1054,6 @@ func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (s |
| 1054 | 1054 |
extDNS: []extDNSEntry{},
|
| 1055 | 1055 |
} |
| 1056 | 1056 |
} |
| 1057 |
- sBox = sb |
|
| 1058 | 1057 |
|
| 1059 | 1058 |
heap.Init(&sb.endpoints) |
| 1060 | 1059 |
|
| ... | ... |
@@ -1073,6 +1072,8 @@ func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (s |
| 1073 | 1073 |
sb.id = "ingress_sbox" |
| 1074 | 1074 |
} |
| 1075 | 1075 |
c.Unlock() |
| 1076 |
+ |
|
| 1077 |
+ var err error |
|
| 1076 | 1078 |
defer func() {
|
| 1077 | 1079 |
if err != nil {
|
| 1078 | 1080 |
c.Lock() |
| ... | ... |
@@ -101,6 +101,9 @@ func TestAtomicKVObjectFlatKey(t *testing.T) {
|
| 101 | 101 |
// Get the Object using GetObject, then set again. |
| 102 | 102 |
newObj := dummyObject{}
|
| 103 | 103 |
err = store.GetObject(Key(expected.Key()...), &newObj) |
| 104 |
+ if err != nil {
|
|
| 105 |
+ t.Fatal(err) |
|
| 106 |
+ } |
|
| 104 | 107 |
assert.True(t, newObj.Exists()) |
| 105 | 108 |
err = store.PutObjectAtomic(&n) |
| 106 | 109 |
if err != nil {
|
| ... | ... |
@@ -670,7 +670,7 @@ func (n *network) initSandbox(restore bool) error {
|
| 670 | 670 |
// In the restore case network sandbox already exist; but we don't know |
| 671 | 671 |
// what epoch number it was created with. It has to be retrieved by |
| 672 | 672 |
// searching the net namespaces. |
| 673 |
- key := "" |
|
| 673 |
+ var key string |
|
| 674 | 674 |
if restore {
|
| 675 | 675 |
key = osl.GenerateKey("-" + n.id)
|
| 676 | 676 |
} else {
|
| ... | ... |
@@ -872,15 +872,10 @@ func (n *network) Value() []byte {
|
| 872 | 872 |
netJSON = append(netJSON, sj) |
| 873 | 873 |
} |
| 874 | 874 |
|
| 875 |
- b, err := json.Marshal(netJSON) |
|
| 876 |
- if err != nil {
|
|
| 877 |
- return []byte{}
|
|
| 878 |
- } |
|
| 879 |
- |
|
| 880 | 875 |
m["secure"] = n.secure |
| 881 | 876 |
m["subnets"] = netJSON |
| 882 | 877 |
m["mtu"] = n.mtu |
| 883 |
- b, err = json.Marshal(m) |
|
| 878 |
+ b, err := json.Marshal(m) |
|
| 884 | 879 |
if err != nil {
|
| 885 | 880 |
return []byte{}
|
| 886 | 881 |
} |
| ... | ... |
@@ -457,7 +457,7 @@ func (n *network) initSandbox(restore bool) error {
|
| 457 | 457 |
// In the restore case network sandbox already exist; but we don't know |
| 458 | 458 |
// what epoch number it was created with. It has to be retrieved by |
| 459 | 459 |
// searching the net namespaces. |
| 460 |
- key := "" |
|
| 460 |
+ var key string |
|
| 461 | 461 |
if restore {
|
| 462 | 462 |
key = osl.GenerateKey("-" + n.id)
|
| 463 | 463 |
} else {
|
| ... | ... |
@@ -570,15 +570,10 @@ func (n *network) Value() []byte {
|
| 570 | 570 |
netJSON = append(netJSON, sj) |
| 571 | 571 |
} |
| 572 | 572 |
|
| 573 |
- b, err := json.Marshal(netJSON) |
|
| 574 |
- if err != nil {
|
|
| 575 |
- return []byte{}
|
|
| 576 |
- } |
|
| 577 |
- |
|
| 578 | 573 |
m["secure"] = n.secure |
| 579 | 574 |
m["subnets"] = netJSON |
| 580 | 575 |
m["mtu"] = n.mtu |
| 581 |
- b, err = json.Marshal(m) |
|
| 576 |
+ b, err := json.Marshal(m) |
|
| 582 | 577 |
if err != nil {
|
| 583 | 578 |
return []byte{}
|
| 584 | 579 |
} |
| ... | ... |
@@ -324,6 +324,9 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
|
| 324 | 324 |
} |
| 325 | 325 |
|
| 326 | 326 |
n, err := d.getNetwork(id) |
| 327 |
+ if err != nil {
|
|
| 328 |
+ return err |
|
| 329 |
+ } |
|
| 327 | 330 |
n.created = true |
| 328 | 331 |
return d.storeUpdate(config) |
| 329 | 332 |
} |
| ... | ... |
@@ -530,7 +533,13 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, |
| 530 | 530 |
} |
| 531 | 531 |
|
| 532 | 532 |
epOption, err := parseEndpointOptions(epOptions) |
| 533 |
+ if err != nil {
|
|
| 534 |
+ return err |
|
| 535 |
+ } |
|
| 533 | 536 |
epConnectivity, err := parseEndpointConnectivity(epOptions) |
| 537 |
+ if err != nil {
|
|
| 538 |
+ return err |
|
| 539 |
+ } |
|
| 534 | 540 |
|
| 535 | 541 |
macAddress := ifInfo.MacAddress() |
| 536 | 542 |
// Use the macaddress if it was provided |
| ... | ... |
@@ -262,7 +262,7 @@ func TestAddSubnets(t *testing.T) {
|
| 262 | 262 |
t.Fatal("returned different pool id for same sub pool requests")
|
| 263 | 263 |
} |
| 264 | 264 |
|
| 265 |
- pid, _, _, err = a.RequestPool(localAddressSpace, "10.20.2.0/24", "", nil, false) |
|
| 265 |
+ _, _, _, err = a.RequestPool(localAddressSpace, "10.20.2.0/24", "", nil, false) |
|
| 266 | 266 |
if err == nil {
|
| 267 | 267 |
t.Fatal("Failed to detect overlapping subnets")
|
| 268 | 268 |
} |
| ... | ... |
@@ -296,7 +296,6 @@ func TestAddReleasePoolID(t *testing.T) {
|
| 296 | 296 |
t.Fatal(err) |
| 297 | 297 |
} |
| 298 | 298 |
|
| 299 |
- subnets := aSpace.subnets |
|
| 300 | 299 |
pid0, _, _, err := a.RequestPool(localAddressSpace, "10.0.0.0/8", "", nil, false) |
| 301 | 300 |
if err != nil {
|
| 302 | 301 |
t.Fatal("Unexpected failure in adding pool")
|
| ... | ... |
@@ -310,7 +309,7 @@ func TestAddReleasePoolID(t *testing.T) {
|
| 310 | 310 |
t.Fatal(err) |
| 311 | 311 |
} |
| 312 | 312 |
|
| 313 |
- subnets = aSpace.subnets |
|
| 313 |
+ subnets := aSpace.subnets |
|
| 314 | 314 |
|
| 315 | 315 |
if subnets[k0].RefCount != 1 {
|
| 316 | 316 |
t.Fatalf("Unexpected ref count for %s: %d", k0, subnets[k0].RefCount)
|
| ... | ... |
@@ -22,12 +22,18 @@ func TestNewChain(t *testing.T) {
|
| 22 | 22 |
|
| 23 | 23 |
bridgeName = "lo" |
| 24 | 24 |
natChain, err = NewChain(chainName, Nat, false) |
| 25 |
+ if err != nil {
|
|
| 26 |
+ t.Fatal(err) |
|
| 27 |
+ } |
|
| 25 | 28 |
err = ProgramChain(natChain, bridgeName, false, true) |
| 26 | 29 |
if err != nil {
|
| 27 | 30 |
t.Fatal(err) |
| 28 | 31 |
} |
| 29 | 32 |
|
| 30 | 33 |
filterChain, err = NewChain(chainName, Filter, false) |
| 34 |
+ if err != nil {
|
|
| 35 |
+ t.Fatal(err) |
|
| 36 |
+ } |
|
| 31 | 37 |
err = ProgramChain(filterChain, bridgeName, false, true) |
| 32 | 38 |
if err != nil {
|
| 33 | 39 |
t.Fatal(err) |
| ... | ... |
@@ -1904,7 +1904,7 @@ func (n *network) ResolveIP(ip string) string {
|
| 1904 | 1904 |
return "" |
| 1905 | 1905 |
} |
| 1906 | 1906 |
// NOTE it is possible to have more than one element in the Set, this will happen |
| 1907 |
- // because of interleave of diffent events from differnt sources (local container create vs |
|
| 1907 |
+ // because of interleave of different events from different sources (local container create vs |
|
| 1908 | 1908 |
// network db notifications) |
| 1909 | 1909 |
// In such cases the resolution will be based on the first element of the set, and can vary |
| 1910 | 1910 |
// during the system stabilitation |
| ... | ... |
@@ -75,6 +75,9 @@ func TestReuseReleasedPort(t *testing.T) {
|
| 75 | 75 |
if err != nil {
|
| 76 | 76 |
t.Fatal(err) |
| 77 | 77 |
} |
| 78 |
+ if port != 5000 {
|
|
| 79 |
+ t.Fatalf("Expected port 5000 got %d", port)
|
|
| 80 |
+ } |
|
| 78 | 81 |
} |
| 79 | 82 |
|
| 80 | 83 |
func TestReleaseUnreadledPort(t *testing.T) {
|
| ... | ... |
@@ -89,7 +92,7 @@ func TestReleaseUnreadledPort(t *testing.T) {
|
| 89 | 89 |
t.Fatalf("Expected port 5000 got %d", port)
|
| 90 | 90 |
} |
| 91 | 91 |
|
| 92 |
- port, err = p.RequestPort(defaultIP, "tcp", 5000) |
|
| 92 |
+ _, err = p.RequestPort(defaultIP, "tcp", 5000) |
|
| 93 | 93 |
|
| 94 | 94 |
switch err.(type) {
|
| 95 | 95 |
case ErrPortAlreadyAllocated: |