summaryrefslogtreecommitdiffstats
path: root/Libraries/Validate/ATFValidate.py
blob: 9cebbf86401ec3c8d5a2d19cdc833de0a44b1dc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python

import re
import ATFUtils

def validate_replication(**arguments):
    """
    Description: 
        Validate whether the files are replicated or not

    Parameters:
        arguments: key=value pair.
            key: file1..filen
            value: host:exportdir:filename comabination

        Example:f1 = 'host1:export1:file1.txt', f2 = 'host1:export2:file1.txt

    Returns:
        Success: 0
        Failure: 1
    """

    Map = []
    command = "ls"

    for key in arguments.keys():
        value = arguments[key]
        hostkey, exportkey, filename = re.split(":", value)

        host = ATFUtils.TestEnvObj.get_host(hostkey)
        if (host == ''):
            ATFUtils.Logger.error("Host %s Not defined in GlobalParam File" %
                                    hostkey)
            return 1
        
        exportdir = ATFUtils.TestEnvObj.get_exportdir(exportkey)
        if (exportdir == ''):
            ATFUtils.Logger.error(
                "ExportDir %s Not defined in GlobalParam File" % exportkey)
            return 1
        else:
            abspath = exportdir + "/" + filename
            Map.append({'host':host, 'path':abspath})


    for item in Map:
        arguments['host'] = item['host']
        arguments['user'] = 'root'
        abspath = item['path']
        val_command = command + " " + abspath

        status, stdin, stdout, stderr = ATFUtils.execute_command(val_command,
                                                                **arguments)

        if ( status == 1):
            ATFUtils.Logger.error("Error in Validation")
        else:
            status = False
            readout = stdout.readlines()
            readerr = stderr.readlines()

            if( len(readerr) == 0):
                for line in readout:
                    if ( re.match(abspath, line)):
                         status = True
            else:
                     status = False

        if (status == False):
            ATFUtils.Logger.error("Validation Failed: Path Not found - %s" % abspath)
            return
        else:
            continue

    if(status == True):
        ATFUtils.Logger.info("Validate_replication Successfully Complete")

    return 0