Merge lp:~jameinel/juju-core/1.17-set-get-environment-compat-1253625 into lp:~go-bot/juju-core/trunk

Proposed by John A Meinel
Status: Merged
Approved by: John A Meinel
Approved revision: no longer in the source branch.
Merged at revision: 2111
Proposed branch: lp:~jameinel/juju-core/1.17-set-get-environment-compat-1253625
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 104 lines (+67/-1)
1 file modified
cmd/juju/environment.go (+67/-1)
To merge this branch: bzr merge lp:~jameinel/juju-core/1.17-set-get-environment-compat-1253625
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+197059@code.launchpad.net

Commit message

cmd/juju/environ.go: restore 1.16 compat

bug #1253625 is about "juju get-environment" and "juju
set-environment" not being compatible with a 1.16 API server because
Client.EnvironmentGet and Client.EnvironmentSet were not available.

So we fall back to direct DB access.

This replaces 'all' of SetEnvironment.Run because it has virtually no
other local logic. For GetEnvironment.Run we only replace the
EnvironmentGet step. (hence the different names for the functions.)

https://codereview.appspot.com/34750043/

Description of the change

cmd/juju/environ.go: restore 1.16 compat

bug #1253625 is about "juju get-environment" and "juju
set-environment" not being compatible with a 1.16 API server because
Client.EnvironmentGet and Client.EnvironmentSet were not available.

So we fall back to direct DB access.

This replaces 'all' of SetEnvironment.Run because it has virtually no
other local logic. For GetEnvironment.Run we only replace the
EnvironmentGet step. (hence the different names for the functions.)

https://codereview.appspot.com/34750043/

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :
Download full text (4.4 KiB)

Reviewers: mp+197059_code.launchpad.net,

Message:
Please take a look.

Description:
cmd/juju/environ.go: restore 1.16 compat

bug #1253625 is about "juju get-environment" and "juju
set-environment" not being compatible with a 1.16 API server because
Client.EnvironmentGet and Client.EnvironmentSet were not available.

So we fall back to direct DB access.

This replaces 'all' of SetEnvironment.Run because it has virtually no
other local logic. For GetEnvironment.Run we only replace the
EnvironmentGet step. (hence the different names for the functions.)

https://code.launchpad.net/~jameinel/juju-core/1.17-set-get-environment-compat-1253625/+merge/197059

(do not edit description out of merge proposal)

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

Affected files (+69, -1 lines):
   A [revision details]
   M cmd/juju/environment.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: tarmac-20131128093217-llqiq8yepsvtg5py
+New revision: <email address hidden>

Index: cmd/juju/environment.go
=== modified file 'cmd/juju/environment.go'
--- cmd/juju/environment.go 2013-11-06 10:51:34 +0000
+++ cmd/juju/environment.go 2013-11-28 12:52:51 +0000
@@ -11,6 +11,7 @@

   "launchpad.net/juju-core/cmd"
   "launchpad.net/juju-core/juju"
+ "launchpad.net/juju-core/rpc"
  )

  // GetEnvironmentCommand is able to output either the entire environment or
@@ -53,6 +54,26 @@
   return
  }

+// environmentGet1dot16 runs matches client.EnvironmentGet using a direct
DB
+// connection to maintain compatibility with an API server running 1.16 or
+// older (when EnvironmentGet was not available). This fallback can be
removed
+// when we no longer maintain 1.16 compatibility.
+func (c *GetEnvironmentCommand) environmentGet1dot16()
(map[string]interface{}, error) {
+ conn, err := juju.NewConnFromName(c.EnvName)
+ if err != nil {
+ return nil, err
+ }
+ defer conn.Close()
+
+ // Get the existing environment config from the state.
+ config, err := conn.State.EnvironConfig()
+ if err != nil {
+ return nil, err
+ }
+ attrs := config.AllAttrs()
+ return attrs, nil
+}
+
  func (c *GetEnvironmentCommand) Run(ctx *cmd.Context) error {
   client, err := juju.NewAPIClientFromName(c.EnvName)
   if err != nil {
@@ -61,6 +82,11 @@
   defer client.Close()

   attrs, err := client.EnvironmentGet()
+ if rpc.IsNoSuchRequest(err) {
+ logger.Infof("EnvironmentGet not supported by the API server, " +
+ "falling back to 1.16 compatibility mode (direct DB access)")
+ attrs, err = c.environmentGet1dot16()
+ }
   if err != nil {
    return err
   }
@@ -124,6 +150,40 @@
   return nil
  }

+// run1dot16 runs matches client.EnvironmentSet using a direct DB
+// connection to maintain compatibility with an API server running 1.16 or
+// older (when EnvironmentSet was not available). This fallback can be
removed
+// when we no longer maintain 1.16 compatibility.
+// This content was copied from SetEnvironmentCommand.Run in 1.16
+func (c *SetEnvironmentCommand) run1dot16() error {
+ conn, err := juju.N...

Read more...

Revision history for this message
Andrew Wilkins (axwalk) wrote :

On 2013/11/28 12:53:09, jameinel wrote:
> Please take a look.

LGTM

https://codereview.appspot.com/34750043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmd/juju/environment.go'
2--- cmd/juju/environment.go 2013-11-06 10:51:34 +0000
3+++ cmd/juju/environment.go 2013-11-28 12:53:06 +0000
4@@ -11,6 +11,7 @@
5
6 "launchpad.net/juju-core/cmd"
7 "launchpad.net/juju-core/juju"
8+ "launchpad.net/juju-core/rpc"
9 )
10
11 // GetEnvironmentCommand is able to output either the entire environment or
12@@ -53,6 +54,26 @@
13 return
14 }
15
16+// environmentGet1dot16 runs matches client.EnvironmentGet using a direct DB
17+// connection to maintain compatibility with an API server running 1.16 or
18+// older (when EnvironmentGet was not available). This fallback can be removed
19+// when we no longer maintain 1.16 compatibility.
20+func (c *GetEnvironmentCommand) environmentGet1dot16() (map[string]interface{}, error) {
21+ conn, err := juju.NewConnFromName(c.EnvName)
22+ if err != nil {
23+ return nil, err
24+ }
25+ defer conn.Close()
26+
27+ // Get the existing environment config from the state.
28+ config, err := conn.State.EnvironConfig()
29+ if err != nil {
30+ return nil, err
31+ }
32+ attrs := config.AllAttrs()
33+ return attrs, nil
34+}
35+
36 func (c *GetEnvironmentCommand) Run(ctx *cmd.Context) error {
37 client, err := juju.NewAPIClientFromName(c.EnvName)
38 if err != nil {
39@@ -61,6 +82,11 @@
40 defer client.Close()
41
42 attrs, err := client.EnvironmentGet()
43+ if rpc.IsNoSuchRequest(err) {
44+ logger.Infof("EnvironmentGet not supported by the API server, " +
45+ "falling back to 1.16 compatibility mode (direct DB access)")
46+ attrs, err = c.environmentGet1dot16()
47+ }
48 if err != nil {
49 return err
50 }
51@@ -124,6 +150,40 @@
52 return nil
53 }
54
55+// run1dot16 runs matches client.EnvironmentSet using a direct DB
56+// connection to maintain compatibility with an API server running 1.16 or
57+// older (when EnvironmentSet was not available). This fallback can be removed
58+// when we no longer maintain 1.16 compatibility.
59+// This content was copied from SetEnvironmentCommand.Run in 1.16
60+func (c *SetEnvironmentCommand) run1dot16() error {
61+ conn, err := juju.NewConnFromName(c.EnvName)
62+ if err != nil {
63+ return err
64+ }
65+ defer conn.Close()
66+
67+ // Here is the magic around setting the attributes:
68+ // TODO(thumper): get this magic under test somewhere, and update other call-sites to use it.
69+ // Get the existing environment config from the state.
70+ oldConfig, err := conn.State.EnvironConfig()
71+ if err != nil {
72+ return err
73+ }
74+ // Apply the attributes specified for the command to the state config.
75+ newConfig, err := oldConfig.Apply(c.values)
76+ if err != nil {
77+ return err
78+ }
79+ // Now validate this new config against the existing config via the provider.
80+ provider := conn.Environ.Provider()
81+ newProviderConfig, err := provider.Validate(newConfig, oldConfig)
82+ if err != nil {
83+ return err
84+ }
85+ // Now try to apply the new validated config.
86+ return conn.State.SetEnvironConfig(newProviderConfig)
87+}
88+
89 func (c *SetEnvironmentCommand) Run(ctx *cmd.Context) error {
90 client, err := juju.NewAPIClientFromName(c.EnvName)
91 if err != nil {
92@@ -131,5 +191,11 @@
93 }
94 defer client.Close()
95
96- return client.EnvironmentSet(c.values)
97+ err = client.EnvironmentSet(c.values)
98+ if rpc.IsNoSuchRequest(err) {
99+ logger.Infof("EnvironmentSet not supported by the API server, " +
100+ "falling back to 1.16 compatibility mode (direct DB access)")
101+ err = c.run1dot16()
102+ }
103+ return err
104 }

Subscribers

People subscribed via source and target branches

to status/vote changes: