~ubuntu-branches/ubuntu/vivid/sahara/vivid-proposed

« back to all changes in this revision

Viewing changes to sahara/tests/integration/tests/resources/swift_test_script.sh

  • Committer: Package Import Robot
  • Author(s): Thomas Goirand
  • Date: 2014-09-24 16:34:46 UTC
  • Revision ID: package-import@ubuntu.com-20140924163446-8gu3zscu5e3n9lr2
Tags: upstream-2014.2~b3
ImportĀ upstreamĀ versionĀ 2014.2~b3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash -x
 
2
 
 
3
OS_TENANT_NAME=""
 
4
OS_USERNAME=""
 
5
OS_PASSWORD=""
 
6
 
 
7
HADOOP_USER=""
 
8
 
 
9
SWIFT_CONTAINER_NAME=""
 
10
 
 
11
compare_files() {
 
12
 
 
13
    a=`md5sum $1 | awk {'print \$1'}`
 
14
    b=`md5sum $2 | awk {'print \$1'}`
 
15
 
 
16
    if [ "$a" = "$b" ]
 
17
    then
 
18
        echo "md5-sums of files $1 and $2 are equal"
 
19
    else
 
20
        echo -e "\nUpload file to Swift: $1 \n"
 
21
        echo -e "Download file from Swift: $2 \n"
 
22
        echo -e "md5-sums of files $1 and $2 are not equal \n"
 
23
        echo "$1 != $2" && exit 1
 
24
    fi
 
25
}
 
26
 
 
27
check_return_code_after_command_execution() {
 
28
 
 
29
    if [ "$1" = "-exit" ]
 
30
    then
 
31
        if [ "$2" -ne 0 ]
 
32
        then
 
33
            exit 1
 
34
        fi
 
35
    fi
 
36
 
 
37
    if [ "$1" = "-clean_hdfs" ]
 
38
    then
 
39
        if [ "$2" -ne 0 ]
 
40
        then
 
41
            sudo -u $HADOOP_USER bash -lc "hadoop dfs -rmr /swift-test" && exit 1
 
42
        fi
 
43
    fi
 
44
}
 
45
 
 
46
check_swift_availability() {
 
47
 
 
48
    dd if=/dev/urandom of=/tmp/test-file bs=1048576 count=1
 
49
 
 
50
    sudo -u $HADOOP_USER bash -lc "hadoop dfs -mkdir /swift-test"
 
51
    check_return_code_after_command_execution -exit `echo "$?"`
 
52
 
 
53
    sudo -u $HADOOP_USER bash -lc "hadoop dfs -copyFromLocal /tmp/test-file /swift-test/"
 
54
    check_return_code_after_command_execution -clean_hdfs `echo "$?"`
 
55
 
 
56
    sudo -u $HADOOP_USER bash -lc "hadoop distcp -D fs.swift.service.sahara.username=$OS_USERNAME -D fs.swift.service.sahara.tenant=$OS_TENANT_NAME -D fs.swift.service.sahara.password=$OS_PASSWORD /swift-test/test-file swift://$SWIFT_CONTAINER_NAME.sahara/"
 
57
    check_return_code_after_command_execution -clean_hdfs `echo "$?"`
 
58
 
 
59
    sudo -u $HADOOP_USER bash -lc "hadoop distcp -D fs.swift.service.sahara.username=$OS_USERNAME -D fs.swift.service.sahara.tenant=$OS_TENANT_NAME -D fs.swift.service.sahara.password=$OS_PASSWORD swift://$SWIFT_CONTAINER_NAME.sahara/test-file /swift-test/swift-test-file"
 
60
    check_return_code_after_command_execution -clean_hdfs `echo "$?"`
 
61
 
 
62
    sudo -u $HADOOP_USER bash -lc "hadoop dfs -copyToLocal /swift-test/swift-test-file /tmp/swift-test-file"
 
63
    check_return_code_after_command_execution -clean_hdfs `echo "$?"`
 
64
 
 
65
    sudo -u $HADOOP_USER bash -lc "hadoop dfs -rmr /swift-test"
 
66
 
 
67
    compare_files /tmp/test-file /tmp/swift-test-file
 
68
 
 
69
    sudo  rm /tmp/test-file /tmp/swift-test-file
 
70
}
 
71
 
 
72
check_swift_availability