Merge lp:~adalbas/ibmcharms/unit-fix into lp:ibmcharms

Proposed by Adalberto Medeiros
Status: Merged
Approved by: Adalberto Medeiros
Approved revision: 21
Merged at revision: 22
Proposed branch: lp:~adalbas/ibmcharms/unit-fix
Merge into: lp:ibmcharms
Diff against target: 85 lines (+26/-14)
1 file modified
charms/trusty/gpfs/hooks/gpfshooklib.py (+26/-14)
To merge this branch: bzr merge lp:~adalbas/ibmcharms/unit-fix
Reviewer Review Type Date Requested Status
Adalberto Medeiros Approve
Review via email: mp+250297@code.launchpad.net

This proposal supersedes a proposal from 2015-02-18.

Description of the change

Improve gpsfshooklib.py
Improve log and call methods (using check_output)

To post a comment you must log in.
Revision history for this message
Michael Chase-Salerno (mcs-chasal) wrote : Posted in a previous version of this proposal

Small spelling error in comment, and opportunity to test reviewing.

review: Needs Fixing
Revision history for this message
Adalberto Medeiros (adalbas) wrote : Posted in a previous version of this proposal

Going to merge now

Revision history for this message
Adalberto Medeiros (adalbas) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charms/trusty/gpfs/hooks/gpfshooklib.py'
2--- charms/trusty/gpfs/hooks/gpfshooklib.py 2015-02-10 12:24:34 +0000
3+++ charms/trusty/gpfs/hooks/gpfshooklib.py 2015-02-19 12:48:32 +0000
4@@ -8,7 +8,8 @@
5 from shlex import split
6 from subprocess import (
7 call,
8- check_call
9+ check_call,
10+ check_output
11 )
12
13 sys.path.insert(0, os.path.join(os.environ['CHARM_DIR'], 'lib'))
14@@ -18,6 +19,12 @@
15 )
16 log = hookenv.log
17
18+def add_to_path(p, new):
19+ return p if new in p.split(':') else p + ':' + new
20+
21+os.environ['PATH'] = add_to_path(os.environ['PATH'], '/usr/lpp/mmfs/bin')
22+
23+## ssh key methods ##
24 def create_ssh_keys():
25 # Generate ssh keys if needed
26 log("Configuring ssh keys")
27@@ -83,26 +90,34 @@
28 idfile.write("StrictHostKeyChecking no\n")
29 idfile.close()
30
31+## cluster management methods ##
32+
33 def start():
34 # Only manager can start/stop cluster
35 if is_manager():
36- call(split('/usr/lpp/mmfs/bin/mmstartup -a'))
37+ log(check_output(split('mmstartup -a')))
38
39 def stop():
40 # stop the server
41 if is_manager():
42- call(split('/usr/lpp/mmfs/bin/mmshutdown -a'))
43+ check_output(split('mmshutdown -a'))
44+
45+def node_exists(nodename):
46+ # Check if node has already been added to cluster
47+ lscluster = check_output('mmlscluster')
48+ node = re.search('^.*\d+.*%s.*\n' % nodename, lscluster, re.M)
49+ return False if node is None else True
50
51 def add_node(nodename, m_designation='client', q_designation='nonquorum'):
52 # add new node to the cluster
53- if cluster_exists():
54- call(split('/usr/lpp/mmfs/bin/mmaddnode -N %s:%s-%s' % (nodename, m_designation,
55- q_designation)))
56+ if cluster_exists() and not node_exists(nodename):
57+ log(check_output(split('mmaddnode -N %s:%s-%s' % \
58+ (nodename, m_designation, q_designation))))
59 else:
60 log('Node %s could not be added. Manager not defined' % nodename)
61
62 def apply_license(nodename):
63- call(split('/usr/lpp/mmfs/bin/mmchlicense server --accept -N %s' % nodename))
64+ check_output(split('mmchlicense server --accept -N %s' % nodename))
65
66 def set_manager_file():
67 # define a file that indicates the node is a manager
68@@ -115,13 +130,10 @@
69
70 def cluster_exists():
71 # Check if cluster is already defined
72- if call('/usr/lpp/mmfs/bin/mmlscluster') == 0:
73- return True
74- else:
75- return False
76-
77+ return True if call('mmlscluster') == 0 else False
78+
79 def create_cluster(hostname):
80 # create the cluster for the hostname, manager only
81 if not is_manager() and not cluster_exists():
82- call(split('/usr/lpp/mmfs/bin/mmcrcluster -N %s:quorum-manager' % hostname +
83- ' -r /usr/bin/ssh -R /usr/bin/scp'))
84+ log(check_output(split('mmcrcluster -N %s:quorum-manager' % \
85+ hostname + ' -r /usr/bin/ssh -R /usr/bin/scp')))

Subscribers

People subscribed via source and target branches