~admcleod/charms/trusty/apache-hadoop-hdfs-master/unstable

« back to all changes in this revision

Viewing changes to actions/smoke-test

[merge] merge bigdata-dev r92..r101 into bigdata-charmers

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
import sys
 
4
 
 
5
try:
 
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)
 
10
except ImportError:
 
11
    charm_ready = False
 
12
 
 
13
if not charm_ready:
 
14
    # might not have hookenv.action_fail available yet
 
15
    from subprocess import call
 
16
    call(['action-fail', 'HDFS service not yet ready'])
 
17
 
 
18
 
 
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')
 
26
        sys.exit()
 
27
 
 
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')
 
31
 
 
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')
 
38
            sys.exit()
 
39
        break
 
40
else:
 
41
    hookenv.action_fail('Unable to create hdfs-test directory')
 
42
    sys.exit()
 
43
 
 
44
# remove the directory
 
45
run_as('ubuntu', 'hdfs', 'dfs', '-rm', '-R', '/tmp/hdfs-test')
 
46
 
 
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')
 
51
    sys.exit()
 
52
 
 
53
hookenv.action_set({'outcome': 'success'})