6
from charmhelpers.core import hookenv
7
from charmhelpers.core import unitdata
8
from jujubigdata.utils import run_as
9
charm_ready = unitdata.kv().get('charm.active', False)
14
# might not have hookenv.action_fail available yet
15
from subprocess import call
16
call(['action-fail', 'HDFS service not yet ready'])
19
# verify the hdfs-test directory does not already exist
20
output = run_as('ubuntu', 'hdfs', 'dfs', '-ls', '/tmp', capture_output=True)
21
if '/tmp/hdfs-test' in output:
22
run_as('ubuntu', 'hdfs', 'dfs', '-rm', '-R', '/tmp/hdfs-test')
23
output = run_as('ubuntu', 'hdfs', 'dfs', '-ls', '/tmp', capture_output=True)
24
if 'hdfs-test' in output:
25
hookenv.action_fail('Unable to remove existing hdfs-test directory')
28
# create the directory
29
run_as('ubuntu', 'hdfs', 'dfs', '-mkdir', '-p', '/tmp/hdfs-test')
30
run_as('ubuntu', 'hdfs', 'dfs', '-chmod', '-R', '777', '/tmp/hdfs-test')
32
# verify the newly created hdfs-test subdirectory exists
33
output = run_as('ubuntu', 'hdfs', 'dfs', '-ls', '/tmp', capture_output=True)
34
for line in output.split('\n'):
35
if '/tmp/hdfs-test' in line:
36
if 'ubuntu' not in line or 'drwxrwxrwx' not in line:
37
hookenv.action_fail('Permissions incorrect for hdfs-test directory')
41
hookenv.action_fail('Unable to create hdfs-test directory')
44
# remove the directory
45
run_as('ubuntu', 'hdfs', 'dfs', '-rm', '-R', '/tmp/hdfs-test')
47
# verify the hdfs-test subdirectory has been removed
48
output = run_as('ubuntu', 'hdfs', 'dfs', '-ls', '/tmp', capture_output=True)
49
if '/tmp/hdfs-test' in output:
50
hookenv.action_fail('Unable to remove hdfs-test directory')
53
hookenv.action_set({'outcome': 'success'})