Merge lp:~gz/juju-core/status_api_1.16_compat into lp:~go-bot/juju-core/trunk

Proposed by Martin Packman
Status: Merged
Approved by: Martin Packman
Approved revision: no longer in the source branch.
Merged at revision: 2350
Proposed branch: lp:~gz/juju-core/status_api_1.16_compat
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 139 lines (+102/-6)
3 files modified
state/api/client.go (+25/-5)
state/apiserver/client/status.go (+19/-1)
state/apiserver/client/status_test.go (+58/-0)
To merge this branch: bzr merge lp:~gz/juju-core/status_api_1.16_compat
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+207482@code.launchpad.net

Commit message

Restore juju status compatibility with 1.16

A stub 'Status' api call was included in 1.16 though not used
in our codebase. It does break the fallback logic to switch
and operate on state directly when talking to a 1.16 state
server however. This branch reintroduces the old call with
the existing name, and uses 'FullStatus' for actual status
api.

https://codereview.appspot.com/66590043/

R=dimitern

Description of the change

Restore juju status compatibility with 1.16

A stub 'Status' api call was included in 1.16 though not used
in our codebase. It does break the fallback logic to switch
and operate on state directly when talking to a 1.16 state
server however. This branch reintroduces the old call with
the existing name, and uses 'FullStatus' for actual status
api.

https://codereview.appspot.com/66590043/

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :
Download full text (3.4 KiB)

Reviewers: mp+207482_code.launchpad.net,

Message:
Please take a look.

Description:
Restore juju status compatibility with 1.16

A stub 'Status' api call was included in 1.16 though not used
in our codebase. It does break the fallback logic to switch
and operate on state directly when talking to a 1.16 state
server however. This branch reintroduces the old call with
the existing name, and uses 'FullStatus' for actual status
api.

I want to add a test for the legacy Status method added in
state/apiserver/client/status.go just to exercise that
code. Where should it go?

https://code.launchpad.net/~gz/juju-core/status_api_1.16_compat/+merge/207482

(do not edit description out of merge proposal)

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

Affected files (+41, -2 lines):
   A [revision details]
   M state/api/client.go
   M state/apiserver/client/status.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-20140220084222-vp7yz0ga1ligfdkq
+New revision: <email address hidden>

Index: state/api/client.go
=== modified file 'state/api/client.go'
--- state/api/client.go 2014-01-30 02:20:09 +0000
+++ state/api/client.go 2014-02-20 15:56:17 +0000
@@ -77,7 +77,26 @@
  func (c *Client) Status(patterns []string) (*Status, error) {
   var s Status
   p := params.StatusParams{Patterns: patterns}
- if err := c.st.Call("Client", "", "Status", p, &s); err != nil {
+ if err := c.st.Call("Client", "", "FullStatus", p, &s); err != nil {
+ return nil, err
+ }
+ return &s, nil
+}
+
+// LegacyMachineStatus holds just the instance-id of a machine.
+type LegacyMachineStatus struct {
+ InstanceId string
+}
+
+// LegacyStatus holds minimal information on the status of a juju
environment.
+type LegacyStatus struct {
+ Machines map[string]LegacyMachineStatus
+}
+
+// LegacyStatus is a stub version of Status that 1.16 introduced.
+func (c *Client) LegacyStatus() (*LegacyStatus, error) {
+ var s LegacyStatus
+ if err := c.st.Call("Client", "", "Status", nil, &s); err != nil {
    return nil, err
   }
   return &s, nil

Index: state/apiserver/client/status.go
=== modified file 'state/apiserver/client/status.go'
--- state/apiserver/client/status.go 2013-12-19 18:13:24 +0000
+++ state/apiserver/client/status.go 2014-02-20 15:56:17 +0000
@@ -10,7 +10,8 @@
   "launchpad.net/juju-core/state/statecmd"
  )

-func (c *Client) Status(args params.StatusParams) (api.Status, error) {
+// FullStatus gives the information needed for juju status over the api
+func (c *Client) FullStatus(args params.StatusParams) (api.Status, error) {
   conn, err := juju.NewConnFromState(c.api.state)
   if err != nil {
    return api.Status{}, err
@@ -19,3 +20,20 @@
   status, err := statecmd.Status(conn, args.Patterns)
   return *status, err
  }
+
+// Status is a stub version of FullStatus that was introduced in 1.16
+func (c *Client) Status() (api.LegacyStatus, error) {
+ var legacyStatus api.LegacyStatus
+ status, err := c.FullStatus(params.StatusParams{})
+ if err != nil {
+ return legacyStat...

Read more...

Revision history for this message
Dimiter Naydenov (dimitern) wrote :

Looks like a good start.

Tests usually go in apiserver/client/, and in this case perhaps it
should be in status_test.go. Look how similar calls are tested. There
are also api/client tests to verify end-to-end integration.

https://codereview.appspot.com/66590043/diff/1/state/api/client.go
File state/api/client.go (right):

https://codereview.appspot.com/66590043/diff/1/state/api/client.go#newcode86
state/api/client.go:86: // LegacyMachineStatus holds just the
instance-id of a machine.
// Remove this in 1.20 or something?
(in all three doc comments below)

https://codereview.appspot.com/66590043/diff/1/state/api/client.go#newcode98
state/api/client.go:98: var s LegacyStatus
s/s/result/ - it's more often called like this in other calls.

https://codereview.appspot.com/66590043/diff/1/state/apiserver/client/status.go
File state/apiserver/client/status.go (right):

https://codereview.appspot.com/66590043/diff/1/state/apiserver/client/status.go#newcode25
state/apiserver/client/status.go:25: func (c *Client) Status()
(api.LegacyStatus, error) {
Shouldn't we keep the params.StatusParams argument?

https://codereview.appspot.com/66590043/

Revision history for this message
Martin Packman (gz) wrote :

Thanks Dimiter!

https://codereview.appspot.com/66590043/diff/1/state/api/client.go
File state/api/client.go (right):

https://codereview.appspot.com/66590043/diff/1/state/api/client.go#newcode86
state/api/client.go:86: // LegacyMachineStatus holds just the
instance-id of a machine.
On 2014/02/20 16:14:01, dimitern wrote:
> // Remove this in 1.20 or something?
> (in all three doc comments below)

Good idea. Can we actually remove it in 1.20 though? Don't we need api
versioning to incompatibily change the api at all?

https://codereview.appspot.com/66590043/diff/1/state/api/client.go#newcode98
state/api/client.go:98: var s LegacyStatus
On 2014/02/20 16:14:01, dimitern wrote:
> s/s/result/ - it's more often called like this in other calls.

Heh, this is actually how it was originally written, but I agree naming
it result (here and above) is clearer.

https://codereview.appspot.com/66590043/diff/1/state/apiserver/client/status.go
File state/apiserver/client/status.go (right):

https://codereview.appspot.com/66590043/diff/1/state/apiserver/client/status.go#newcode25
state/apiserver/client/status.go:25: func (c *Client) Status()
(api.LegacyStatus, error) {
On 2014/02/20 16:14:01, dimitern wrote:
> Shouldn't we keep the params.StatusParams argument?

This is where a longer-range diff would be useful. This method is
reproducing the old 1.16 status api method exactly, which didn't take
arguments and didn't return anything of much use. However, I'm readding
it for compat reasons.

https://codereview.appspot.com/66590043/

Revision history for this message
Martin Packman (gz) wrote :
Revision history for this message
Dimiter Naydenov (dimitern) wrote :

Better, thanks.

Now you only need to add some api/client tests I think and should be
good to land.

https://codereview.appspot.com/66590043/diff/20001/state/apiserver/client/status_test.go
File state/apiserver/client/status_test.go (right):

https://codereview.appspot.com/66590043/diff/20001/state/apiserver/client/status_test.go#newcode29
state/apiserver/client/status_test.go:29: // XXX: Have to test via the
client even though this is in apiserver,
This is fine and not unusual (other tests use the client as well), so
remove this comment :)

https://codereview.appspot.com/66590043/

Revision history for this message
Martin Packman (gz) wrote :
Revision history for this message
Dimiter Naydenov (dimitern) wrote :

On 2014/02/20 17:11:01, dimitern wrote:
> Better, thanks.

> Now you only need to add some api/client tests I think and should be
good to
> land.

Forget about this, sorry. I was thinking of the agent api client tests.
LGTM.

https://codereview.appspot.com/66590043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'state/api/client.go'
2--- state/api/client.go 2014-01-30 02:20:09 +0000
3+++ state/api/client.go 2014-02-24 17:41:32 +0000
4@@ -75,12 +75,32 @@
5
6 // Status returns the status of the juju environment.
7 func (c *Client) Status(patterns []string) (*Status, error) {
8- var s Status
9+ var result Status
10 p := params.StatusParams{Patterns: patterns}
11- if err := c.st.Call("Client", "", "Status", p, &s); err != nil {
12- return nil, err
13- }
14- return &s, nil
15+ if err := c.st.Call("Client", "", "FullStatus", p, &result); err != nil {
16+ return nil, err
17+ }
18+ return &result, nil
19+}
20+
21+// LegacyMachineStatus holds just the instance-id of a machine.
22+type LegacyMachineStatus struct {
23+ InstanceId string // Not type instance.Id just to match original api.
24+}
25+
26+// LegacyStatus holds minimal information on the status of a juju environment.
27+type LegacyStatus struct {
28+ Machines map[string]LegacyMachineStatus
29+}
30+
31+// LegacyStatus is a stub version of Status that 1.16 introduced. Should be
32+// removed along with structs when api versioning makes it safe to do so.
33+func (c *Client) LegacyStatus() (*LegacyStatus, error) {
34+ var result LegacyStatus
35+ if err := c.st.Call("Client", "", "Status", nil, &result); err != nil {
36+ return nil, err
37+ }
38+ return &result, nil
39 }
40
41 // ServiceSet sets configuration options on a service.
42
43=== modified file 'state/apiserver/client/status.go'
44--- state/apiserver/client/status.go 2013-12-19 18:13:24 +0000
45+++ state/apiserver/client/status.go 2014-02-24 17:41:32 +0000
46@@ -10,7 +10,8 @@
47 "launchpad.net/juju-core/state/statecmd"
48 )
49
50-func (c *Client) Status(args params.StatusParams) (api.Status, error) {
51+// FullStatus gives the information needed for juju status over the api
52+func (c *Client) FullStatus(args params.StatusParams) (api.Status, error) {
53 conn, err := juju.NewConnFromState(c.api.state)
54 if err != nil {
55 return api.Status{}, err
56@@ -19,3 +20,20 @@
57 status, err := statecmd.Status(conn, args.Patterns)
58 return *status, err
59 }
60+
61+// Status is a stub version of FullStatus that was introduced in 1.16
62+func (c *Client) Status() (api.LegacyStatus, error) {
63+ var legacyStatus api.LegacyStatus
64+ status, err := c.FullStatus(params.StatusParams{})
65+ if err != nil {
66+ return legacyStatus, err
67+ }
68+
69+ legacyStatus.Machines = make(map[string]api.LegacyMachineStatus)
70+ for machineName, machineStatus := range status.Machines {
71+ legacyStatus.Machines[machineName] = api.LegacyMachineStatus{
72+ InstanceId: string(machineStatus.InstanceId),
73+ }
74+ }
75+ return legacyStatus, nil
76+}
77
78=== added file 'state/apiserver/client/status_test.go'
79--- state/apiserver/client/status_test.go 1970-01-01 00:00:00 +0000
80+++ state/apiserver/client/status_test.go 2014-02-24 17:41:32 +0000
81@@ -0,0 +1,58 @@
82+// Copyright 2014 Canonical Ltd.
83+// Licensed under the AGPLv3, see LICENCE file for details.
84+
85+package client_test
86+
87+import (
88+ gc "launchpad.net/gocheck"
89+
90+ "launchpad.net/juju-core/instance"
91+ "launchpad.net/juju-core/state"
92+)
93+
94+type statusSuite struct {
95+ baseSuite
96+}
97+
98+var _ = gc.Suite(&statusSuite{})
99+
100+func (s *statusSuite) addMachine(c *gc.C) *state.Machine {
101+ machine, err := s.State.AddMachine("quantal", state.JobHostUnits)
102+ c.Assert(err, gc.IsNil)
103+ return machine
104+}
105+
106+// Complete testing of status functionality happens elsewhere in the codebase,
107+// these tests just sanity-check the api itself.
108+
109+func (s *statusSuite) TestFullStatus(c *gc.C) {
110+ machine := s.addMachine(c)
111+ client := s.APIState.Client()
112+ status, err := client.Status(nil)
113+ c.Assert(err, gc.IsNil)
114+ c.Check(status.EnvironmentName, gc.Equals, "dummyenv")
115+ c.Check(status.Services, gc.HasLen, 0)
116+ c.Check(status.Machines, gc.HasLen, 1)
117+ resultMachine, ok := status.Machines[machine.Id()]
118+ if !ok {
119+ c.Fatalf("Missing machine with id %q", machine.Id())
120+ }
121+ c.Check(resultMachine.Id, gc.Equals, machine.Id())
122+ c.Check(resultMachine.Series, gc.Equals, machine.Series())
123+}
124+
125+func (s *statusSuite) TestLegacyStatus(c *gc.C) {
126+ machine := s.addMachine(c)
127+ instanceId := "i-fakeinstance"
128+ err := machine.SetProvisioned(instance.Id(instanceId), "fakenonce", nil)
129+ c.Assert(err, gc.IsNil)
130+ client := s.APIState.Client()
131+ status, err := client.LegacyStatus()
132+ c.Assert(err, gc.IsNil)
133+ c.Check(status.Machines, gc.HasLen, 1)
134+ resultMachine, ok := status.Machines[machine.Id()]
135+ if !ok {
136+ c.Fatalf("Missing machine with id %q", machine.Id())
137+ }
138+ c.Check(resultMachine.InstanceId, gc.Equals, instanceId)
139+}

Subscribers

People subscribed via source and target branches

to status/vote changes: