Merge lp:~thumper/juju-core/machine-id-from-tag into lp:~go-bot/juju-core/trunk

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 1285
Proposed branch: lp:~thumper/juju-core/machine-id-from-tag
Merge into: lp:~go-bot/juju-core/trunk
Prerequisite: lp:~thumper/juju-core/instance-instance
Diff against target: 51 lines (+21/-1)
2 files modified
state/machine.go (+12/-1)
state/machine_test.go (+9/-0)
To merge this branch: bzr merge lp:~thumper/juju-core/machine-id-from-tag
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+169327@code.launchpad.net

Commit message

Add a MachineIdFromTag function.

There are times (coming in future branches) where you want to be able to
reverse the MachineTag result back into a machineId.

https://codereview.appspot.com/10274044/

Description of the change

Add a MachineIdFromTag function.

There are times (coming in future branches) where you want to be able to
reverse the MachineTag result back into a machineId.

https://codereview.appspot.com/10274044/

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Reviewers: mp+169327_code.launchpad.net,

Message:
Please take a look.

Description:
Add a MachineIdFromTag function.

There are times (coming in future branches) where you want to be able to
reverse the MachineTag result back into a machineId.

https://code.launchpad.net/~thumper/juju-core/machine-id-from-tag/+merge/169327

Requires:
https://code.launchpad.net/~thumper/juju-core/instance-instance/+merge/169325

(do not edit description out of merge proposal)

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

Affected files:
   A [revision details]
   M state/machine.go
   M state/machine_test.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 2013-06-12 00:05:50 +0000
+++ state/machine.go 2013-06-14 02:27:04 +0000
@@ -107,15 +107,26 @@
   return machineGlobalKey(m.doc.Id)
  }

+const machineTagPrefix = "machine-"
+
  // MachineTag returns the tag for the
  // machine with the given id.
  func MachineTag(id string) string {
- tag := fmt.Sprintf("machine-%s", id)
+ tag := fmt.Sprintf("%s%s", machineTagPrefix, id)
   // Containers require "/" to be replaced by "-".
   tag = strings.Replace(tag, "/", "-", -1)
   return tag
  }

+// MachineIdFromTag returns the machine id that was used to create the tag.
+func MachineIdFromTag(tag string) string {
+ // Strip off the "machine-" prefix.
+ id := tag[len(machineTagPrefix):]
+ // Put the slashes back.
+ id = strings.Replace(id, "-", "/", -1)
+ return id
+}
+
  // Tag returns a name identifying the machine that is safe to use
  // as a file name. The returned name will be different from other
  // Tag values returned by any other entities from the same state.

Index: state/machine_test.go
=== modified file 'state/machine_test.go'
--- state/machine_test.go 2013-06-12 00:01:40 +0000
+++ state/machine_test.go 2013-06-14 02:27:04 +0000
@@ -192,6 +192,15 @@
   c.Assert(state.MachineTag("10/lxc/1"), Equals, "machine-10-lxc-1")
  }

+func (s *MachineSuite) TestMachineIdFromTag(c *C) {
+ c.Assert(state.MachineIdFromTag("machine-10"), Equals, "10")
+ // Check a container id.
+ c.Assert(state.MachineIdFromTag("machine-10-lxc-1"), Equals, "10/lxc/1")
+ // Check reversability.
+ nested := "2/kvm/0/lxc/3"
+ c.Assert(state.MachineIdFromTag(state.MachineTag(nested)), Equals, nested)
+}
+
  func (s *MachineSuite) TestSetMongoPassword(c *C) {
   testSetMongoPassword(c, func(st *state.State) (entity, error) {
    return st.Machine(s.machine.Id())

Revision history for this message
William Reade (fwereade) wrote :
Revision history for this message
John A Meinel (jameinel) wrote :
Revision history for this message
Go Bot (go-bot) wrote :
Revision history for this message
Go Bot (go-bot) wrote :
Download full text (24.1 KiB)

The attempt to merge lp:~thumper/juju-core/machine-id-from-tag into lp:juju-core failed. Below is the output from the failed tests.

ok launchpad.net/juju-core/bzr 7.887s
ok launchpad.net/juju-core/cert 5.241s
ok launchpad.net/juju-core/charm 0.693s
? launchpad.net/juju-core/charm/hooks [no test files]
ok launchpad.net/juju-core/cloudinit 0.010s
ok launchpad.net/juju-core/cmd 0.254s
? launchpad.net/juju-core/cmd/builddb [no test files]
? launchpad.net/juju-core/cmd/charmd [no test files]
? launchpad.net/juju-core/cmd/charmload [no test files]
ok launchpad.net/juju-core/cmd/juju 168.791s

----------------------------------------------------------------------
FAIL: agent.go:0: MachineSuite.TearDownTest

Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
/home/tarmac/trees/src/launchpad.net/juju-core/testing/mgo.go:240:
    c.Fatal("Test left sockets in a dirty state")
... Error: Test left sockets in a dirty state

----------------------------------------------------------------------
PANIC: machine_test.go:190: MachineSuite.TestManageEnviron

[LOG] 64.20527 INFO juju environs/testing: uploading FAKE tools 1.11.1-precise-amd64
[LOG] 64.20532 INFO juju environs: reading tools with major version 1
[LOG] 64.20534 DEBUG juju environs/tools: reading v1.* tools
[LOG] 64.20536 INFO juju environs: falling back to public bucket
[LOG] 64.20538 DEBUG juju environs/tools: reading v1.* tools
[LOG] 64.20541 DEBUG juju environs/tools: found 1.11.1-precise-amd64
[LOG] 64.20543 INFO juju environs: filtering tools by series: precise
[LOG] 64.20545 INFO juju environs: filtering tools by version: 1.11.1
[LOG] 64.20548 INFO juju environs/dummy: would pick tools from 1.11.1-precise-amd64
[LOG] 64.23659 INFO juju state: opening state; mongo addresses: ["localhost:43511"]; entity ""
[LOG] 64.24016 INFO juju state: connection established
[LOG] 64.29936 INFO juju state: initializing environment
[LOG] 64.54811 INFO juju state/api: listening on "localhost:0"
[LOG] 64.58435 INFO juju state: opening state; mongo addresses: ["localhost:43511"]; entity ""
[LOG] 64.58784 INFO juju state: connection established
[LOG] 64.58840 INFO juju juju: authorization error while connecting to state server; retrying
[LOG] 64.69674 INFO juju state: opening state; mongo addresses: ["localhost:43511"]; entity ""
[LOG]...

Revision history for this message
Tim Penhey (thumper) wrote :

Looks like a spurious test failure, trying again.

Revision history for this message
Go Bot (go-bot) wrote :
Download full text (24.1 KiB)

The attempt to merge lp:~thumper/juju-core/machine-id-from-tag into lp:juju-core failed. Below is the output from the failed tests.

ok launchpad.net/juju-core/bzr 7.212s
ok launchpad.net/juju-core/cert 3.952s
ok launchpad.net/juju-core/charm 0.546s
? launchpad.net/juju-core/charm/hooks [no test files]
ok launchpad.net/juju-core/cloudinit 0.010s
ok launchpad.net/juju-core/cmd 0.266s
? launchpad.net/juju-core/cmd/builddb [no test files]
? launchpad.net/juju-core/cmd/charmd [no test files]
? launchpad.net/juju-core/cmd/charmload [no test files]
ok launchpad.net/juju-core/cmd/juju 170.299s

----------------------------------------------------------------------
FAIL: agent.go:0: MachineSuite.TearDownTest

Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
Waiting for sockets to die: 0 in use, 1 alive
/home/tarmac/trees/src/launchpad.net/juju-core/testing/mgo.go:240:
    c.Fatal("Test left sockets in a dirty state")
... Error: Test left sockets in a dirty state

----------------------------------------------------------------------
PANIC: machine_test.go:190: MachineSuite.TestManageEnviron

[LOG] 64.28435 INFO juju environs/testing: uploading FAKE tools 1.11.1-precise-amd64
[LOG] 64.28441 INFO juju environs: reading tools with major version 1
[LOG] 64.28443 DEBUG juju environs/tools: reading v1.* tools
[LOG] 64.28444 INFO juju environs: falling back to public bucket
[LOG] 64.28446 DEBUG juju environs/tools: reading v1.* tools
[LOG] 64.28450 DEBUG juju environs/tools: found 1.11.1-precise-amd64
[LOG] 64.28451 INFO juju environs: filtering tools by series: precise
[LOG] 64.28454 INFO juju environs: filtering tools by version: 1.11.1
[LOG] 64.28456 INFO juju environs/dummy: would pick tools from 1.11.1-precise-amd64
[LOG] 64.31914 INFO juju state: opening state; mongo addresses: ["localhost:60317"]; entity ""
[LOG] 64.32250 INFO juju state: connection established
[LOG] 64.39301 INFO juju state: initializing environment
[LOG] 64.64011 INFO juju state/api: listening on "localhost:0"
[LOG] 64.66967 INFO juju state: opening state; mongo addresses: ["localhost:60317"]; entity ""
[LOG] 64.67300 INFO juju state: connection established
[LOG] 64.67352 INFO juju juju: authorization error while connecting to state server; retrying
[LOG] 64.77893 INFO juju state: opening state; mongo addresses: ["localhost:60317"]; entity ""
[LOG]...

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 2013-06-16 11:39:46 +0000
3+++ state/machine.go 2013-06-16 22:21:24 +0000
4@@ -107,15 +107,26 @@
5 return machineGlobalKey(m.doc.Id)
6 }
7
8+const machineTagPrefix = "machine-"
9+
10 // MachineTag returns the tag for the
11 // machine with the given id.
12 func MachineTag(id string) string {
13- tag := fmt.Sprintf("machine-%s", id)
14+ tag := fmt.Sprintf("%s%s", machineTagPrefix, id)
15 // Containers require "/" to be replaced by "-".
16 tag = strings.Replace(tag, "/", "-", -1)
17 return tag
18 }
19
20+// MachineIdFromTag returns the machine id that was used to create the tag.
21+func MachineIdFromTag(tag string) string {
22+ // Strip off the "machine-" prefix.
23+ id := tag[len(machineTagPrefix):]
24+ // Put the slashes back.
25+ id = strings.Replace(id, "-", "/", -1)
26+ return id
27+}
28+
29 // Tag returns a name identifying the machine that is safe to use
30 // as a file name. The returned name will be different from other
31 // Tag values returned by any other entities from the same state.
32
33=== modified file 'state/machine_test.go'
34--- state/machine_test.go 2013-06-12 00:01:40 +0000
35+++ state/machine_test.go 2013-06-16 22:21:24 +0000
36@@ -192,6 +192,15 @@
37 c.Assert(state.MachineTag("10/lxc/1"), Equals, "machine-10-lxc-1")
38 }
39
40+func (s *MachineSuite) TestMachineIdFromTag(c *C) {
41+ c.Assert(state.MachineIdFromTag("machine-10"), Equals, "10")
42+ // Check a container id.
43+ c.Assert(state.MachineIdFromTag("machine-10-lxc-1"), Equals, "10/lxc/1")
44+ // Check reversability.
45+ nested := "2/kvm/0/lxc/3"
46+ c.Assert(state.MachineIdFromTag(state.MachineTag(nested)), Equals, nested)
47+}
48+
49 func (s *MachineSuite) TestSetMongoPassword(c *C) {
50 testSetMongoPassword(c, func(st *state.State) (entity, error) {
51 return st.Machine(s.machine.Id())

Subscribers

People subscribed via source and target branches

to status/vote changes: