Merge lp:~marcoceppi/charm-tools/unit-parsing into lp:~charmers/charm-tools/trunk

Proposed by Marco Ceppi
Status: Merged
Approved by: Mark Mims
Approved revision: 137
Merged at revision: 174
Proposed branch: lp:~marcoceppi/charm-tools/unit-parsing
Merge into: lp:~charmers/charm-tools/trunk
Diff against target: 147 lines (+96/-24)
3 files modified
helpers/sh/peer.sh (+2/-24)
helpers/sh/unit.sh (+67/-0)
tests/helpers/test_unit.sh (+27/-0)
To merge this branch: bzr merge lp:~marcoceppi/charm-tools/unit-parsing
Reviewer Review Type Date Requested Status
Clint Byrum (community) Needs Information
Juan L. Negron (community) Approve
Review via email: mp+104929@code.launchpad.net

Description of the change

I've added a few basic tools for unit/service name parsing. I've noticed that peer.sh has unit-based name stuff. This merge is more a review if these kinds of tools (ch_get_my_id, ch_get_unit_id) from peer.sh and the new ones in unit.sh should be a part of charm-helpers.

I'm also uncertain of how to carry copyright over, as such I've moved the code and placed both Canonical and myself as the Copyright holder.

To post a comment you must log in.
Revision history for this message
Juan L. Negron (negronjl) wrote :

Hi Marco:

Thanks for the updates....

This will help in my hacking :)

It looks good to me.

-Juan

review: Approve
135. By Marco Ceppi

Fixed hardcoded paths

136. By Marco Ceppi

Fixed hardcoded paths

137. By Marco Ceppi

Added unit test

Revision history for this message
Clint Byrum (clint-fewbar) wrote :

Marco this looks great. However, can you explain why there is a ch_unit_name and ch_service_name ? ch_unit_name seems misleading.

review: Needs Information
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

Thanks Clint,

ch_unit_name and ch_service_name are the same command, ch_unit_name exists to follow the same pattern as `ch_unit_id` which existed prior to this unit.sh. ch_service_name exists as it's a better name. I guess the goal was to have a naming sequence that followed what existed previously and one that makes more sense. If it's too redundant I can easily remove the ch_unit_name as it's less logical sounding than ch_service_name.

Thanks!
Marco

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'helpers/sh/peer.sh'
2--- helpers/sh/peer.sh 2012-01-18 23:53:48 +0000
3+++ helpers/sh/peer.sh 2012-05-07 16:45:21 +0000
4@@ -18,6 +18,8 @@
5 echo WARNING: peer functions are untested, and may provide unreliable
6 echo services. Their use is experimental.
7
8+. "${HELPERS_HOME:-/usr/share/charm-helper/sh}/unit.sh"
9+
10 ##
11 # ch_peer_i_am_leader
12 # Returns 1 if the current unit is the leader
13@@ -76,30 +78,6 @@
14 fi
15 }
16
17-##
18-# ch_unit_id <unit-name>
19-# Returns the unit id
20-#
21-# Param <unit-name> is the name of the unit
22-#
23-# returns <unit-d> | FALSE
24-ch_unit_id()
25-{
26- echo "${1##*/}"
27-}
28-
29-##
30-# ch_my_unit_id
31-# Returns the unit id of the current unit
32-#
33-# param none
34-#
35-# returns <unit-id> | FALSE
36-ch_my_unit_id()
37-{
38- echo "`ch_unit_id $JUJU_UNIT_NAME`"
39-}
40-
41
42 ##
43 # ch_peer_copy [-r|--rsync][-p <port>][-o "<opt>"] sourcepath1 destpath1 [... sourcepathN destpathN]
44
45=== added file 'helpers/sh/unit.sh'
46--- helpers/sh/unit.sh 1970-01-01 00:00:00 +0000
47+++ helpers/sh/unit.sh 2012-05-07 16:45:21 +0000
48@@ -0,0 +1,67 @@
49+#!/bin/sh
50+
51+##
52+# Copyright: 2012 Marco Ceppi <marco@ceppi.net>
53+# Copyright: Copyright 2011, Canonical Ltd., All Rights Reserved.
54+#
55+# This file is part of Charm Helpers.
56+#
57+# This program is free software: you can redistribute it and/or modify
58+# it under the terms of the GNU General Public License as published by
59+# the Free Software Foundation, either version 3 of the License, or
60+# (at your option) any later version.
61+#
62+# This program is distributed in the hope that it will be useful,
63+# but WITHOUT ANY WARRANTY; without even the implied warranty of
64+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
65+# GNU General Public License for more details.
66+#
67+# You should have received a copy of the GNU General Public License
68+# along with this program. If not, see <http://www.gnu.org/licenses/>.
69+##
70+
71+##
72+# ch_unit_name <unit>
73+# Returns the unit (service) name
74+#
75+# Param <unit> is the name of the unit
76+#
77+# returns <service> | FALSE
78+ch_unit_name()
79+{
80+ echo "${1%%/*}"
81+}
82+
83+##
84+# ch_service_name <unit>
85+# Alias of ch_unit_name
86+#
87+# returns <service> | FALSE
88+ch_service_name()
89+{
90+ echo "`ch_unit_name $1`"
91+}
92+
93+##
94+# ch_unit_id <unit-name>
95+# Returns the unit id
96+#
97+# Param <unit-name> is the name of the unit
98+#
99+# returns <unit-d> | FALSE
100+ch_unit_id()
101+{
102+ echo "${1##*/}"
103+}
104+
105+##
106+# ch_my_unit_id
107+# Returns the unit id of the current unit
108+#
109+# param none
110+#
111+# returns <unit-id> | FALSE
112+ch_my_unit_id()
113+{
114+ echo "`ch_unit_id $JUJU_UNIT_NAME`"
115+}
116
117=== added file 'tests/helpers/test_unit.sh'
118--- tests/helpers/test_unit.sh 1970-01-01 00:00:00 +0000
119+++ tests/helpers/test_unit.sh 2012-05-07 16:45:21 +0000
120@@ -0,0 +1,27 @@
121+#!/bin/sh
122+
123+if [ -z "$test_home" ] ; then
124+ test_home=`dirname $0`
125+ test_home=`readlink -f $test_home`
126+fi
127+
128+[ "$LIB_SOURCED" = "1" ] || . $test_home/lib.sh
129+
130+set -ue
131+
132+JUJU_UNIT_NAME="test/9001"
133+
134+. $HELPERS_HOME/unit.sh
135+
136+start_test ch_unit_name...
137+[ "`ch_unit_name $JUJU_UNIT_NAME`" = "test" ]
138+[ "`ch_service_name $JUJU_UNIT_NAME`" = "test" ]
139+echo PASS
140+
141+start_test ch_unit_id...
142+[ "`ch_unit_id $JUJU_UNIT_NAME`" = "9001" ]
143+echo PASS
144+
145+start_test ch_my_unit_id...
146+[ "`ch_my_unit_id`" = "9001" ]
147+echo PASS

Subscribers

People subscribed via source and target branches