summaryrefslogtreecommitdiff
path: root/validation/test/av_home/av_home.py
blob: 2ec9f0330ff4c0ec0af675179dbdee2158849ada (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
80
81
82
83
84
85
86
87
# -*- coding: utf-8 -*-

"""Module allowing to generate P2P report in field test."""

import re, os, sys
import ConfigParser
import av_home_attr

def master_script():
    print ("Executing master script")
    test_init ()
    print ("Sending MME for environment discovery to " + av_home_attr.plug_mac +
    " through " + av_home_attr.iface + " ...")
    raw_input ("Press enter when slave script has been launched")
    print ("Executing ping on slave PC ("+ av_home_attr.addr +")...")
    print ("Executing upload iperf test on " + av_home_attr.addr + " ...")
    raw_input ("Press enter when slave script has finished upload iperf")

def slave_script():
    print ("Executing slave script")
    test_init ()
    print ("Sending MME for environment discovery...")
    print ("Starting iperf server...")
    raw_input ("Press enter when master script has finished upload iperf test")
    print ("Executing upload iperf test...")

def config_get_item (config, section, key):
    """Get the value of the key in the section from the config parser"""
    try:
        return config.get (section, key)
    except:
        return None

def parse_config(file):
    config = ConfigParser.RawConfigParser ()
    config.read (file)
    av_home_attr.plug_mac = config_get_item (config, 'Test', 'plug_mac')
    av_home_attr.peer_mac = config_get_item (config, 'Test', 'peer_mac')
    av_home_attr.source_mac = config_get_item (config, 'Test', 'source_mac')
    av_home_attr.iface = config_get_item (config, 'Test', 'iface')
    av_home_attr.addr = config_get_item (config, 'Test', 'addr')
    av_home_attr.output_dir = config_get_item (config, 'Test', 'output_dir')
    av_home_attr.scammer_path = config_get_item (config, 'Test', 'scammer_path')

def set_opts(options):
    if options.plug_mac:
        av_home_attr.plug_mac = options.plug_mac
    if options.peer_mac:
        av_home_attr.peer_mac = options.peer_mac
    if options.source_mac:
        av_home_attr.source_mac = options.source_mac
    if options.addr:
        av_home_attr.addr = options.addr
    if options.output_dir:
        av_home_attr.output_dir = options.output_dir
    if options.iface:
        av_home_attr.iface = options.iface
    if options.scammer_path:
        av_home_attr.scammer_path = options.scammer_path

def check_params():
    errorstr = ""
    error = 0
    mac_re = re.compile (r"([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$")
    if not re.match (mac_re, av_home_attr.plug_mac) \
            or not re.match (mac_re, av_home_attr.peer_mac) \
            or not re.match (mac_re, av_home_attr.source_mac):
                print "MAC address invalid"
                sys.exit (1)
    if not re.match (r"((((25[0-5])|(2[0-4][0-9])|(1?[0-9]{1,2})).){3})((25[0-5])|(2[0-4][0-9])|(1?[0-9]{1,2}))$",
            av_home_attr.addr):
        print "IP address invalid"
        sys.exit (1)
    if not av_home_attr.scammer_path:
        print "You must set the path to scammer"
        sys.exit (1)

def test_init():
    if not av_home_attr.output_dir:
        av_home_attr.output_dir = "test_home-default"
    else:
        av_home_attr.output_dir = "test_home-%s" % av_home_attr.output_dir
    if not os.path.exists(av_home_attr.output_dir):
        os.mkdir (av_home_attr.output_dir)
    else:
        print "Test directory already exists, choose another name"
        sys.exit (1)