~niedbalski/charms/trusty/rabbitmq-server/fix-lp-1489053

« back to all changes in this revision

Viewing changes to tests/charmhelpers/cli/unitdata.py

  • Committer: Liam Young
  • Date: 2015-09-09 13:12:47 UTC
  • mfrom: (110.1.4 rabbitmq-server)
  • Revision ID: liam.young@canonical.com-20150909131247-16hxw74o91c57kpg
[1chb1n, r=gnuoy] Refactor amulet tests, deprecate old tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2014-2015 Canonical Limited.
2
 
#
3
 
# This file is part of charm-helpers.
4
 
#
5
 
# charm-helpers is free software: you can redistribute it and/or modify
6
 
# it under the terms of the GNU Lesser General Public License version 3 as
7
 
# published by the Free Software Foundation.
8
 
#
9
 
# charm-helpers is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU Lesser General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU Lesser General Public License
15
 
# along with charm-helpers.  If not, see <http://www.gnu.org/licenses/>.
16
 
 
17
 
from . import cmdline
18
 
from charmhelpers.core import unitdata
19
 
 
20
 
 
21
 
@cmdline.subcommand_builder('unitdata', description="Store and retrieve data")
22
 
def unitdata_cmd(subparser):
23
 
    nested = subparser.add_subparsers()
24
 
    get_cmd = nested.add_parser('get', help='Retrieve data')
25
 
    get_cmd.add_argument('key', help='Key to retrieve the value of')
26
 
    get_cmd.set_defaults(action='get', value=None)
27
 
    set_cmd = nested.add_parser('set', help='Store data')
28
 
    set_cmd.add_argument('key', help='Key to set')
29
 
    set_cmd.add_argument('value', help='Value to store')
30
 
    set_cmd.set_defaults(action='set')
31
 
 
32
 
    def _unitdata_cmd(action, key, value):
33
 
        if action == 'get':
34
 
            return unitdata.kv().get(key)
35
 
        elif action == 'set':
36
 
            unitdata.kv().set(key, value)
37
 
            unitdata.kv().flush()
38
 
            return ''
39
 
    return _unitdata_cmd