Merge lp:~dimitern/juju-core/397-state-networking into lp:~go-bot/juju-core/trunk

Proposed by Dimiter Naydenov
Status: Merged
Approved by: Dimiter Naydenov
Approved revision: no longer in the source branch.
Merged at revision: 2649
Proposed branch: lp:~dimitern/juju-core/397-state-networking
Merge into: lp:~go-bot/juju-core/trunk
Prerequisite: lp:~dimitern/juju-core/396-improve-errors
Diff against target: 92 lines (+35/-35)
2 files modified
state/machine.go (+29/-31)
state/state.go (+6/-4)
To merge this branch: bzr merge lp:~dimitern/juju-core/397-state-networking
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+215660@code.launchpad.net

Commit message

state: Networking improvements, missed before

In this CL https://codereview.appspot.com/86010044/,
some of the suggestions regarding implementation
details of AddNetwork and AddNetworkInterface were
not included in time. This adds these suggestions.

https://codereview.appspot.com/87470044/
R=rogpeppe

Description of the change

state: Networking improvements, missed before

In this CL https://codereview.appspot.com/86010044/,
some of the suggestions regarding implementation
details of AddNetwork and AddNetworkInterface were
not included in time. This adds these suggestions.

https://codereview.appspot.com/87470044/

To post a comment you must log in.
Revision history for this message
Dimiter Naydenov (dimitern) wrote :
Download full text (4.6 KiB)

Reviewers: mp+215660_code.launchpad.net,

Message:
Please take a look.

Description:
state: Networking improvements, missed before

In this CL https://codereview.appspot.com/86010044/,
some of the suggestions regarding implementation
details of AddNetwork and AddNetworkInterface were
not included in time. This adds these suggestions.

https://code.launchpad.net/~dimitern/juju-core/397-state-networking/+merge/215660

Requires:
https://code.launchpad.net/~dimitern/juju-core/396-improve-errors/+merge/215652

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/87470044/

Affected files (+37, -35 lines):
   A [revision details]
   M state/machine.go
   M state/state.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision:
<email address hidden>
+New revision:
<email address hidden>

Index: state/machine.go
=== modified file 'state/machine.go'
--- state/machine.go 2014-04-14 12:36:13 +0000
+++ state/machine.go 2014-04-14 13:09:55 +0000
@@ -1036,38 +1036,36 @@
    Insert: doc,
   }}

- for i := 0; i < 5; i++ {
- err = m.st.runTransaction(ops)
- switch err {
- case txn.ErrAborted:
- if err = m.st.networkInterfaces.FindId(macAddress).One(nil); err == nil
{
- return nil, errors.AlreadyExistsf("interface with MAC address %q",
macAddress)
- }
- if _, err = m.st.Network(networkName); err != nil {
- return nil, err
- }
- if err = m.Refresh(); err != nil {
- return nil, err
- } else if m.doc.Life != Alive {
- return nil, fmt.Errorf("machine is not alive")
- } else if m.doc.Nonce != "" {
- msg := "machine already provisioned: dynamic network interfaces not
currently supported"
- return nil, fmt.Errorf(msg)
- }
- case nil:
- // For some reason when using unique indices with mgo, and
- // we have an index violation the error is nil, but the
- // document is not added. So we check if the supposedly
- // successful transaction did actually add the document.
- if err = m.st.networkInterfaces.FindId(macAddress).One(nil); err != nil
{
- return nil, errors.AlreadyExistsf("%q on machine %q", interfaceName,
m.doc.Id)
- }
- return newNetworkInterface(m.st, doc), nil
- default:
- return nil, err
- }
+ err = m.st.runTransaction(ops)
+ switch err {
+ case txn.ErrAborted:
+ if err = m.st.networkInterfaces.FindId(macAddress).One(nil); err == nil {
+ return nil, errors.AlreadyExistsf("interface with MAC address %q",
macAddress)
+ }
+ if _, err = m.st.Network(networkName); err != nil {
+ return nil, err
+ }
+ if err = m.Refresh(); err != nil {
+ return nil, err
+ } else if m.doc.Life != Alive {
+ return nil, fmt.Errorf("machine is not alive")
+ } else if m.doc.Nonce != "" {
+ msg := "machine already provisioned: dynamic network interfaces not
currently supported"
+ return nil, fmt.Errorf(msg)
+ }
+ case nil:
+ // We have a unique key restriction on the InterfaceName
+ // field, which will cause the insert to fail ...

Read more...

Revision history for this message
Roger Peppe (rogpeppe) wrote :

On 2014/04/14 13:15:13, dimitern wrote:
> Please take a look.

LGTM, thanks.

https://codereview.appspot.com/87470044/

Revision history for this message
Go Bot (go-bot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'state/machine.go'
2--- state/machine.go 2014-04-14 13:14:11 +0000
3+++ state/machine.go 2014-04-14 13:14:11 +0000
4@@ -1036,38 +1036,36 @@
5 Insert: doc,
6 }}
7
8- for i := 0; i < 5; i++ {
9- err = m.st.runTransaction(ops)
10- switch err {
11- case txn.ErrAborted:
12- if err = m.st.networkInterfaces.FindId(macAddress).One(nil); err == nil {
13- return nil, errors.AlreadyExistsf("interface with MAC address %q", macAddress)
14- }
15- if _, err = m.st.Network(networkName); err != nil {
16- return nil, err
17- }
18- if err = m.Refresh(); err != nil {
19- return nil, err
20- } else if m.doc.Life != Alive {
21- return nil, fmt.Errorf("machine is not alive")
22- } else if m.doc.Nonce != "" {
23- msg := "machine already provisioned: dynamic network interfaces not currently supported"
24- return nil, fmt.Errorf(msg)
25- }
26- case nil:
27- // For some reason when using unique indices with mgo, and
28- // we have an index violation the error is nil, but the
29- // document is not added. So we check if the supposedly
30- // successful transaction did actually add the document.
31- if err = m.st.networkInterfaces.FindId(macAddress).One(nil); err != nil {
32- return nil, errors.AlreadyExistsf("%q on machine %q", interfaceName, m.doc.Id)
33- }
34- return newNetworkInterface(m.st, doc), nil
35- default:
36- return nil, err
37- }
38+ err = m.st.runTransaction(ops)
39+ switch err {
40+ case txn.ErrAborted:
41+ if err = m.st.networkInterfaces.FindId(macAddress).One(nil); err == nil {
42+ return nil, errors.AlreadyExistsf("interface with MAC address %q", macAddress)
43+ }
44+ if _, err = m.st.Network(networkName); err != nil {
45+ return nil, err
46+ }
47+ if err = m.Refresh(); err != nil {
48+ return nil, err
49+ } else if m.doc.Life != Alive {
50+ return nil, fmt.Errorf("machine is not alive")
51+ } else if m.doc.Nonce != "" {
52+ msg := "machine already provisioned: dynamic network interfaces not currently supported"
53+ return nil, fmt.Errorf(msg)
54+ }
55+ case nil:
56+ // We have a unique key restriction on the InterfaceName
57+ // field, which will cause the insert to fail if there is
58+ // another record with the same interface name in the table.
59+ // The txn logic does not report insertion errors, so we check
60+ // that the record has actually been inserted correctly before
61+ // reporting success.
62+ if err = m.st.networkInterfaces.FindId(macAddress).One(nil); err != nil {
63+ return nil, errors.AlreadyExistsf("%q on machine %q", interfaceName, m.doc.Id)
64+ }
65+ return newNetworkInterface(m.st, doc), nil
66 }
67- return nil, ErrExcessiveContention
68+ return nil, err
69 }
70
71 // CheckProvisioned returns true if the machine was provisioned with the given nonce.
72
73=== modified file 'state/state.go'
74--- state/state.go 2014-04-14 13:14:11 +0000
75+++ state/state.go 2014-04-14 13:14:11 +0000
76@@ -1059,10 +1059,12 @@
77 return nil, err
78 }
79 case nil:
80- // For some reason when using unique indices with mgo, and
81- // we have an index violation the error is nil, but the
82- // document is not added. So we check if the supposedly
83- // successful transaction did actually add the document.
84+ // We have a unique key restriction on the ProviderId field,
85+ // which will cause the insert to fail if there is another
86+ // record with the same provider id in the table. The txn
87+ // logic does not report insertion errors, so we check that
88+ // the record has actually been inserted correctly before
89+ // reporting success.
90 if _, err = st.Network(name); err != nil {
91 return nil, errors.AlreadyExistsf("network with provider id %q", providerId)
92 }

Subscribers

People subscribed via source and target branches

to status/vote changes: