settingsengines/sdb/monty/monty.py
author m2lahtel
Tue, 10 Aug 2010 14:29:28 +0300
changeset 3 e7e0ae78773e
parent 1 b538b70cbe51
permissions -rw-r--r--
ConE 1.2.11 release
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
     1
# Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
     2
# All rights reserved.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
     3
# This component and the accompanying materials are made available
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
     4
# under the terms of "Eclipse Public License v1.0"
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
     5
# which accompanies this distribution, and is available
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
     7
# 
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
     8
# Initial Contributors:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    10
# 
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    11
# Contributors:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    12
# 
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    13
# Description:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    14
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    15
"""
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    16
This is the automated test framework, called Monty. It's not an acronym; just
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    17
a name. It is pure coincidence that it's a Python script, and is called
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    18
monty.py...
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    19
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    20
@author : Chris Haynes, (C)2007-2008 Symbian Software Ltd.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    21
@date   : 03/09/2007 - present
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    22
@updated: 01/09/2008
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    23
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    24
To use the timeout function on Windows, you need to install PyWin32 from:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    25
  http://sourceforge.net/project/showfiles.php?group_id=78018
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    26
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    27
This script will:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    28
    - Read in the CSV file that contains the tests (with columns in the order
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    29
      as listed below, see docs for an example).
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    30
    - Delete the target files in the 'targets' array, if any.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    31
    - Execute the command.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    32
    - Check that the target files were created, if any.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    33
    - Count the warnings and errors reported.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    34
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    35
Each test is defined by:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    36
    1) id:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    37
       The test case identifier. It should be unique.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    38
    2) note:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    39
       A note about this test case, perhaps explaining what the test does.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    40
    3) timed:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    41
       1 or 0 to denote whether the test should be timed individually.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    42
    4) display_output:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    43
       1 or 0 to denote whether the output should be displayed on the screen.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    44
    5) store_output:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    45
       1 or 0 to denote whether the output should be stored in a file called
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    46
       "<id>_log.txt".
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    47
    6) command:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    48
       The command to run. To use the unix_path variable (and others) use:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    49
       command" + variable name + "rest of command. Do NOT put quotes around the
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    50
       entire string; just where you want to insert the variable.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    51
    7) targets:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    52
       An array of target files that should get built.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    53
    8) expected_output:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    54
       An array of text lines that should be seen in the output - in the order
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    55
       they appear.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    56
    9-12) expected:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    57
       A list of the number of missing files, warnings, errors and exceptions
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    58
       expected.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    59
    13) return_code:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    60
       The return code from the given command. Python will return zero for no
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    61
       return code. For no return code, or to ignore it, leave it at 0.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    62
    14) os_types:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    63
       The operating systems that the test can execute on. Currently, u (unix)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    64
       and w (windows) are valid. You can have one or the other, or both. When
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    65
       executing the test suite, any test matching the OS type will be executed.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    66
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    67
You can use environment variables, e.g. $ ( EPOCROOT ), $ ( USER ) etc.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    68
(These variables have spaces here to avoid being interpreted.)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    69
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    70
Tests can be commented out in the CSV file by starting the id with a hash,
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    71
e.g. #my_test_case...
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    72
Tests that you do not want to contribute to results, such as setup steps, should
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    73
end with a hash, e.g. my_setup_test#
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    74
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    75
You can also stop Monty from deleting the target files by ending your test case 
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    76
id with an 'at' symbol, e.g. test_targets_still_exist@
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    77
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    78
The script locates internal errors in the application you are testing and
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    79
    reports on them. You can specify the string to search for, e.g. "sbs.py",
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    80
    and it should be something which is only ever seen in internal errors. You
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    81
    can use the 'exceptions' value, but this will not report specific errors you
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    82
    are expecting.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    83
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    84
TESTING MONTY:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    85
- Using pylint, run the following command:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    86
pylint monty.py --max-line-length=600 --max-module-lines=5000 --disable-msg=E1101 --disable-msg=W0603 --disable-msg=W0122 --disable-msg=C0103 --disable-msg=R0911 --disable-msg=R0912 --disable-msg=R0913 --disable-msg=R0914 --disable-msg=R0915
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    87
- You should get a score of ten. Perfection.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    88
- This will mask the reporting of certain warning messages that do not apply, but which cause the score to fall.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    89
"""
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    90
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    91
import csv
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    92
import datetime
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    93
import os
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    94
import re
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    95
import shutil
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    96
import sys
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    97
import time
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    98
import types
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
    99
from optparse import OptionParser
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   100
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   101
# Simple setup variables
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   102
monty_version = '1.13 [2008-08-21]'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   103
line_dash_count = 120
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   104
line_separator = '=' * line_dash_count
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   105
line_separator_dash = '-' * line_dash_count
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   106
current_mode = 'header'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   107
output_mode = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   108
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   109
# Return codes - These are overridden in the monty_cfg.py file
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   110
monty_returncode_if_config_error = 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   111
monty_returncode_if_test_suite_error = 2
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   112
monty_returncode_if_file_error = 3
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   113
monty_returncode_if_test_failure = 4
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   114
monty_returncode_if_test_failure_conditional = 5
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   115
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   116
# Simple check for the OS we're running on
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   117
os_type = 'unix'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   118
if sys.platform.lower().startswith('win'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   119
    os_type = 'windows'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   120
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   121
# Set up the variables for the required command line values
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   122
execute_file = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   123
output_log_path = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   124
test_path = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   125
unix_path = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   126
unix_test_path = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   127
win_path = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   128
win_test_path = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   129
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   130
# Set up some defaults
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   131
path = ''                                         # The drive where the monty.py script is located
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   132
store_all_output = 1                              # Should all output be written to a file? (0 = no, 1 = yes)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   133
store_csv_results = 1                             # Should we store test results in a CSV file? (0 = no, 1 = yes)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   134
internal_error_string = ''                        # The string to find in internal error output
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   135
copy_log = 1                                      # If a logfile is generated, store it in the output_log_path?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   136
run_test = ''                                     # Set a test to run on its own
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   137
run_group_test = ''                               # Set a group of tests to run on their own
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   138
job_section = ''                                  # Execute a job section from the test suite
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   139
allow_missing_commands_to_fail_test = 0           # If a command cannot be found, specific text is displayed in the output, such as "command not found".
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   140
                                                  # If you want this to fail a test, set this to 1. (0 = no, 1 = yes)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   141
timeout_secs = 0                                  # The length in seconds for a command to execute before it is killed
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   142
                                                  # NOTE: To use the process timeout function on Windows, you need to install PyWin32 from:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   143
                                                  # http://sourceforge.net/project/showfiles.php?group_id=78018
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   144
                                                  # ***NOTE***: Timeout functionality is not yet working. Leave at zero for now.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   145
capture_stderr = 0                                # Capture output on stderr? If set to 1, errors will be output at the end of the normal stdout output
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   146
log_file_output_name = '.*in (.*\.log).*'         # A VALID regular expression for the location of the log file produced, if any.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   147
zip_results = 1                                   # Zip up successful results?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   148
output_mode = 0                                   # Force Monty to restrict its screen output to one of seven modes:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   149
                                                  # 0 = Output all text
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   150
                                                  # 1 = Output tests and results but not the header
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   151
                                                  # 2 = Output header and results only
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   152
                                                  # 3 = Output tests only
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   153
                                                  # 4 = Output results only
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   154
                                                  # 5 = Output header and tests only
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   155
                                                  # 6 = Output nothing at all - just run the tests and create the logs
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   156
                                                  # Notes: Errors and warnings will always be displayed on-screen unless in mode 6. Log output is unaffected by any mode and will continue to be written in full.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   157
determine_warning = "(.*warning:.*)"              # A VALID regular expression of what must be contained within a line of output on stdout to be interpreted as a warning
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   158
determine_warning_in_log = "(^<warning>.*)"       # A VALID regular expression of what must be contained within a line in the log file to be interpreted as a warning
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   159
determine_error = "(.*error:.*)"                  # A VALID regular expression of what must be contained within a line of output on stdout to be interpreted as an error
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   160
determine_error_in_log = "(^<error>.*)"           # A VALID regular expression of what must be contained within a line in the log file to be interpreted as an error
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   161
determine_traceback = '.*(Traceback).*'           # A VALID regular expression of what must be contained within a line of output to be interpreted as a traceback/internal error
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   162
results_date_format = "%Y-%m-%d %H-%M-%S"         # Valid Python datetime string for the results output
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   163
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   164
# Check for Python version
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   165
if sys.version_info[0:2] < (2, 4):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   166
    print 'WARNING: Monty requires Python 2.4 or later for accurate process control.'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   167
    if os_type == 'windows' and timeout_secs > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   168
        print 'ERROR: Aborting because Windows cannot cope.'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   169
        sys.exit(monty_returncode_if_config_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   170
else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   171
    import subprocess
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   172
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   173
# Now get the root drive so we don't need to alter the default locations. Use \\ for one \ in "" strings, e.g. "D:\\"
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   174
prog_path = sys.path[0]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   175
if os_type == 'windows':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   176
    root_drive = prog_path[0:2]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   177
    usage_slashes = '\\'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   178
else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   179
    root_drive = '~/'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   180
    usage_slashes = '/'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   181
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   182
# Get current working directory for when the current test's command is 'monty_restore_cwd'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   183
original_cwd = os.getcwd()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   184
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   185
# Make sure there's a MONTY_HOME variable set
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   186
if not 'MONTY_HOME' in os.environ:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   187
    print 'WARNING: MONTY_HOME environment variable not set. Defaulting to current working directory...'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   188
    os.environ['MONTY_HOME'] = os.getcwd()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   189
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   190
# List the internal variables that Monty allows the user to use in CSV files.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   191
# Note: 'path' MUST go at the end, or it will render the other '<xxx>_path' variables useless.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   192
vars_from_monty = ['root_drive', 'usage_slashes', 'win_path', 'win_test_path', 'unix_path', 'unix_test_path', 'test_path', 'path']
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   193
monty_config_py = 'monty_cfg'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   194
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   195
# Overriding the tests to execute based on OS type. Default is to adhere to the specified OS type execution.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   196
override_os_types = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   197
override_os_types_dict = {'u': 'Unix', 'w': 'Windows', 'all': 'all'}
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   198
override_os_types_usage = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   199
for x in override_os_types_dict.keys():
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   200
    override_os_types_usage = override_os_types_usage + " '" + x + "' for " + override_os_types_dict[x] + ','
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   201
override_os_types_usage = override_os_types_usage[0:-1]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   202
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   203
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   204
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   205
# The following variables are used for the compiler change commands:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   206
# Set up a list of valid compilers:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   207
valid_compilers = {'arm2_2': 'ARM 2.2', 'arm3_1': 'ARM 3.1', 'gcce3_4_3': 'GCCE 3.4.3', 'gcce4_2_3': 'GCCE 4.2.3'}
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   208
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   209
# Set up a list of variables to set for each compiler:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   210
compiler_vars = {
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   211
'arm2_2': {'ARMVER': '2.2[616]', 'ARMV5VER': 'ARM/Thumb C/C++ Compiler, RVCT2.2 [Build 616]', 'ARMROOT': 'C:\\APPS\\ARM\\RVCT2.2', 'RVCT22BIN': 'C:\\Apps\\ARM\\RVCT\\Programs\\2.2\\349\\win_32-pentium', 'RVCT22INC': 'C:\\APPS\\ARM\\RVCT\\Data\\2.2\\349\\include\windows', 'RVCT22LIB': 'C:\\APPS\\ARM\\RVCT\\Data\\2.2\\349\\lib', 'PATH': 'C:\\APPS\\ARM\\RVCT\\Programs\\2.2\\349\\win_32-pentium;' + os.environ['PATH']}, 
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   212
'arm3_1': {'ARMVER': '3.1[674]', 'ARMV5VER': 'ARM/Thumb C/C++ Compiler, RVCT3.1 [Build 674]', 'ARMROOT': 'C:\\APPS\\ARM\\RVCT3.1', 'RVCT31BIN': 'C:\\Apps\\ARM\\RVCT\\Programs\\3.1\\3.1.674\\bin', 'RVCT31INC': 'C:\\APPS\\ARM\\RVCT\\Programs\\3.1\\3.1.674\\inc', 'RVCT31LIB': 'C:\\APPS\\ARM\\RVCT\\Programs\\3.1\\3.1.674\\lib', 'PATH': 'C:\\Apps\\ARM\\RVCT\\Programs\\3.1\\3.1.674\\bin;' + os.environ['PATH']}, 
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   213
'gcce3_4_3': {'PATH': 'C:\\Apps\\gcce.x\\2005q1-c\\bin;' + os.environ['PATH']}, 
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   214
'gcce4_2_3': {'PATH': 'C:\\Apps\\gcce.x\\2008q1-102\\bin;' + os.environ['PATH']}
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   215
}
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   216
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   217
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   218
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   219
def correct_slashes(value):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   220
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   221
    This module corrects slashes in pathnames supplied to it.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   222
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   223
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   224
    while value.find('\\\\') != -1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   225
        value = value.replace('\\\\', '\\')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   226
        continue
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   227
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   228
    while value.find('//') != -1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   229
        value = value.replace('//', '/')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   230
        continue
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   231
    if os_type == 'windows' and '/' in value:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   232
        while value.find('/') != -1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   233
            value = value.replace('/', '\\')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   234
            continue
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   235
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   236
    return value
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   237
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   238
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   239
################################################################################
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   240
# Determine the available command line arguments
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   241
################################################################################
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   242
if __name__ == '__main__':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   243
    monty_parser = OptionParser(prog = 'monty.py', \
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   244
        usage = "%prog -h | -e <test suite csv file> -l <log path> [options]\n\nNotes: Internal commands (cd, monty_restore_cwd, etc.) in the CSV test file are executed but not counted.\n       Ensure you add trailing slashes to all directories entered on the command line.")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   245
    monty_parser.add_option('-e', '--execute', action='store', dest='execute_file',
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   246
        help='REQUIRED: The location and filename of the CSV file containing the tests to execute (the test suite)')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   247
    monty_parser.add_option('-t', '--testpath', action='store', dest='test_path',
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   248
        help="Directory for relative paths in the tests, e.g. '" + correct_slashes(root_drive + usage_slashes) + 'test' + usage_slashes + "'")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   249
    monty_parser.add_option('-l', '--logpath', action='store', dest='output_log_path',
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   250
        help="REQUIRED: Where to store the log output, e.g. '" + correct_slashes(root_drive + usage_slashes) + 'logs' + usage_slashes + "'")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   251
    monty_parser.add_option('-p', '--path', action='store', dest='path',
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   252
        help="Root directory of drive used, e.g. '" + correct_slashes(root_drive + usage_slashes) + "'")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   253
    monty_parser.add_option('-s', '--storeoutput', action='store', dest='store_output',
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   254
        help='Store all output in a file within the logs directory. Use 1 for yes, 0 for no. Default is 1.')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   255
    monty_parser.add_option('-i', '--interr', action='store', dest='internal_error_string',
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   256
        help="The text string to look for in output when an internal error is encountered, e.g. 'Line number:' or filename 'the_app.py'")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   257
    monty_parser.add_option('-r', '--run', action='store', dest='run_test',
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   258
        help='The id of a test to run (in lowercase). Only this test case will be executed. You may need to use double-quotes. Cannot be used with -g.')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   259
    monty_parser.add_option('-g', '--run_group', action='store', dest='run_group_test',
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   260
        help='A group of tests to run (in lowercase). Only test cases beginning with this text will be executed. You may need to use double-quotes. Cannot be used with -r.')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   261
    monty_parser.add_option('-j', '--run_job', action='store', dest='run_job',
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   262
        help='The name of a job section to run (in lowercase). Can be combined with -r or -g but not both.')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   263
    monty_parser.add_option('-c', '--csv', action='store', dest='store_csv_results',
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   264
        help='Write test results to a CSV file with id, date, result. Use 1 for yes, 0 for no. Default is 1.')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   265
    monty_parser.add_option('-k', '--copy_log', action='store', dest='copy_log',
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   266
        help='If a logfile is generated, store it for every test? Use 1 for yes, 0 for no. Default is 1.')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   267
    monty_parser.add_option('-x', '--config', action='store', dest='monty_config_py',
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   268
        help='The path and name of an external configuration file. Default is monty_cfg.py in the current working directory. You must supply the .py extension.')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   269
    monty_parser.add_option('-o', '--override_os_types', action='store', dest='override_os_types',
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   270
        help='Tests can be specified to execute on certain operating systems. Set to:' + override_os_types_usage + '.')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   271
    monty_parser.add_option('-z', '--zip_results', action='store', dest='zip_results',
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   272
        help='Zip up the results upon *successful* execution? Use 1 for yes, 0 for no. Default is 1.')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   273
    monty_parser.add_option('-m', '--mode', action='store', dest='output_mode',
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   274
        help='Force Monty to restrict its screen output to one of seven modes: 0 = Output all text (Default), 1 = Output tests and results but not the header, 2 = Output header and results only, 3 = Output tests only, 4 = Output results only, 5 = Output header and tests only, 6 = Output nothing at all - just run the tests and create the logs. Notes: Errors and warnings will always be displayed on-screen unless in mode 6. Log output is unaffected by any mode and will continue to be written in full.')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   275
    #monty_parser.add_option('-a', '--capture_stderr', action='store', dest='capture_stderr',
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   276
    #    help='Capture output on stderr? If set to 1, errors will be output at the end of the normal stdout output. Use 1 for yes, 0 for no. Default is 0.')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   277
    # Parse the arguments passed to the function in args
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   278
    (monty_options, leftover_args) = monty_parser.parse_args(sys.argv[1:])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   279
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   280
################################################################################
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   281
# Set up default variables
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   282
################################################################################
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   283
using_defaults = [' (default)', ' (default)', ' (default)', ' (default)', ' (default)', ' (default, will not report internal errors)', ' (default)', ' (default)', ' (default)', ' (default)', ' (default)']
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   284
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   285
unix_path = root_drive
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   286
win_path = root_drive + usage_slashes
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   287
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   288
# If the user has set the test_path in the config file, use that instead of the defaults created above
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   289
if test_path != '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   290
    win_test_path = correct_slashes(test_path)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   291
    unix_test_path = correct_slashes(test_path)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   292
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   293
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   294
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   295
def log_screen(the_text, the_mode):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   296
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   297
    This module simply writes out a message to the screen. It can be extended to
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   298
    restrict what is being displayed, much like the error_level of most apps.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   299
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   300
    There are seven modes currently available:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   301
    0 = Output all text
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   302
    1 = Output tests and results but not the header
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   303
    2 = Output header and results only
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   304
    3 = Output tests only
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   305
    4 = Output results only
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   306
    5 = Output header and tests only
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   307
    6 = Output nothing at all - just run the tests and create the logs
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   308
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   309
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   310
    printed = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   311
    if output_mode == 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   312
        print the_text
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   313
        printed = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   314
    elif output_mode == 1 and current_mode != 'header':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   315
        print the_text
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   316
        printed = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   317
    elif output_mode == 2 and current_mode != 'run_tests':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   318
        print the_text
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   319
        printed = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   320
    elif output_mode == 3 and current_mode == 'run_tests':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   321
        print the_text
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   322
        printed = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   323
    elif output_mode == 4 and current_mode == 'results':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   324
        print the_text
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   325
        printed = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   326
    elif output_mode == 5 and current_mode != 'results':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   327
        print the_text
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   328
        printed = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   329
    elif output_mode == 6:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   330
        # Do nothing, but need a line, or Python throws a barny
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   331
        printed = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   332
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   333
    if (current_mode == '' or the_mode != '') and printed == False:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   334
        if the_mode == 'error' or the_mode == 'warning':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   335
            # This can be changed in future to cope with different requirements for the output
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   336
            print the_text
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   337
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   338
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   339
################################################################################
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   340
# Functions for the command line arguments
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   341
################################################################################
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   342
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   343
def set_path(args):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   344
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   345
    This module sets the root path for the tests.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   346
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   347
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   348
    global win_path, unix_path
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   349
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   350
    if len(args[0:]) > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   351
        using_defaults[0] = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   352
        if args[len(args) - 1:(len(args))] != usage_slashes:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   353
            win_path = correct_slashes(args[0:] + usage_slashes)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   354
            unix_path = correct_slashes(args[0:] + usage_slashes)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   355
        else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   356
            win_path = correct_slashes(args[0:] + usage_slashes)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   357
            unix_path = correct_slashes(args[0:] + usage_slashes)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   358
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   359
        if ':' in unix_path:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   360
            unix_path = unix_path.replace('\\', '/')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   361
            unix_path = unix_path.replace(':', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   362
            unix_path = '/' + unix_path[0].lower() + unix_path[1:]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   363
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   364
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   365
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   366
def set_test_path(args):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   367
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   368
    This module sets the path for the tests to be executed.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   369
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   370
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   371
    global win_test_path, unix_test_path, test_path
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   372
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   373
    if len(args[0:]) > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   374
        using_defaults[1] = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   375
        if args[len(args) - 1:(len(args))] != usage_slashes:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   376
            test_path = correct_slashes(args[0:] + usage_slashes)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   377
            win_test_path = correct_slashes(args[0:] + usage_slashes)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   378
            unix_test_path = correct_slashes(args[0:] + usage_slashes)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   379
        else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   380
            test_path = correct_slashes(args[0:] + usage_slashes)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   381
            win_test_path = correct_slashes(args[0:] + usage_slashes)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   382
            unix_test_path = correct_slashes(args[0:] + usage_slashes)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   383
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   384
        if ':' in unix_test_path:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   385
            unix_test_path = unix_test_path.replace('\\', '/')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   386
            unix_test_path = unix_test_path.replace(':', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   387
            unix_test_path = '/' + unix_test_path[0].lower() + unix_test_path[1:]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   388
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   389
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   390
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   391
def set_execute_file(args):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   392
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   393
    This module sets the file CSV containing the tests to execute.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   394
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   395
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   396
    global execute_file
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   397
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   398
    if len(args[0:]) > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   399
        using_defaults[2] = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   400
        execute_file = args[0:]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   401
        if os_type == 'unix':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   402
            execute_file = execute_file.replace('\\', '/')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   403
            execute_file = execute_file.replace(':', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   404
            execute_file = execute_file[0].lower() + execute_file[1:]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   405
        execute_file = correct_slashes(execute_file[0:])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   406
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   407
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   408
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   409
def set_store_output(args):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   410
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   411
    This module sets the variable that determines whether output is stored in a
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   412
    file or not.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   413
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   414
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   415
    global store_all_output
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   416
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   417
    if args[0:] == '0':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   418
        using_defaults[3] = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   419
        store_all_output = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   420
    elif args[0:] == '1':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   421
        store_all_output = 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   422
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   423
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   424
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   425
def set_output_log_path(args):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   426
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   427
    This module sets the path of the output log files.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   428
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   429
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   430
    global output_log_path
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   431
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   432
    if len(args[0:]) > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   433
        using_defaults[4] = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   434
        if args[len(args) - 1:(len(args))] != usage_slashes:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   435
            output_log_path = correct_slashes(args[0:] + usage_slashes)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   436
        else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   437
            output_log_path = correct_slashes(args[0:] + usage_slashes)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   438
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   439
        if os_type == 'windows':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   440
            if ':' not in output_log_path:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   441
                log_screen('Monty ' + str(monty_version) + ' - Type monty.py -h for usage', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   442
                log_screen('ERROR: output_log_path must be in Windows DOS format', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   443
                sys.exit(monty_returncode_if_config_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   444
        else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   445
            if ':' in output_log_path:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   446
                log_screen('Monty ' + str(monty_version) + ' - Type monty.py -h for usage', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   447
                log_screen('ERROR: output_log_path must be in Unix format', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   448
                sys.exit(monty_returncode_if_config_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   449
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   450
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   451
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   452
def set_internal_error_string(args):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   453
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   454
    This module sets the internal error string to look for.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   455
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   456
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   457
    global internal_error_string
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   458
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   459
    if len(args[0:]) > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   460
        using_defaults[5] = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   461
        internal_error_string = args[0:]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   462
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   463
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   464
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   465
def set_run_this_test(args):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   466
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   467
    This module sets the variable containing a single test to execute.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   468
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   469
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   470
    global run_test
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   471
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   472
    if len(args[0:]) > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   473
        run_test = args[0:]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   474
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   475
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   476
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   477
def set_run_group_test(args):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   478
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   479
    This module sets the variable containing a group of tests to execute. If a
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   480
    group test is set, it will override the single run test value.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   481
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   482
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   483
    global run_group_test, run_test
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   484
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   485
    if len(args[0:]) > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   486
        run_group_test = args[0:]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   487
        run_test = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   488
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   489
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   490
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   491
def set_run_job_section(args):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   492
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   493
    This module sets the variable containing a test job to execute.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   494
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   495
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   496
    global job_section
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   497
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   498
    if len(args[0:]) > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   499
        job_section = args[0:]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   500
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   501
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   502
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   503
def set_store_csv_results(args):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   504
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   505
    This module sets the variable that determines whether results are stored in
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   506
    a CSV file or not. This is useful for importing results into a test
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   507
    management system.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   508
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   509
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   510
    global store_csv_results
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   511
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   512
    if args[0:] == '0':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   513
        using_defaults[6] = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   514
        store_csv_results = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   515
    elif args[0:] == '1':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   516
        store_csv_results = 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   517
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   518
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   519
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   520
def set_copy_log(args):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   521
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   522
    This module sets the variable that determines whether the make logfiles are
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   523
    copied or not.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   524
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   525
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   526
    global copy_log
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   527
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   528
    if args[0:] == '0':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   529
        using_defaults[7] = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   530
        copy_log = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   531
    elif args[0:] == '1':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   532
        copy_log = 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   533
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   534
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   535
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   536
def set_monty_config_py(args):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   537
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   538
    This module sets the monty_cfg path and filename for importing external
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   539
    configuration settings and new variables.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   540
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   541
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   542
    global monty_config_py
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   543
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   544
    if len(args[0:]) > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   545
        monty_config_py = args[0:]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   546
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   547
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   548
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   549
def set_override_os_types(args):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   550
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   551
    This module determines whether the tests are forced to execute on the
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   552
    current OS or not.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   553
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   554
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   555
    global override_os_types
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   556
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   557
    if args[0:].lower() == 'u' or args[0:].lower() == 'w' or args[0:].lower() == 'all':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   558
        using_defaults[8] = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   559
        override_os_types = args[0:].lower()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   560
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   561
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   562
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   563
def set_capture_stderr(args):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   564
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   565
    This module sets the variable that determines whether stderr output is
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   566
    captured separately or not.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   567
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   568
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   569
    global capture_stderr
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   570
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   571
    if args[0:] == '1':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   572
        using_defaults[9] = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   573
        capture_stderr = 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   574
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   575
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   576
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   577
def set_zip_results(args):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   578
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   579
    This module sets the variable that determines whether results are zipped up
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   580
    upon successful completion or not.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   581
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   582
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   583
    global zip_results
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   584
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   585
    if args[0:] == '0':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   586
        using_defaults[10] = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   587
        zip_results = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   588
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   589
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   590
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   591
def set_output_mode(args):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   592
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   593
    This module sets the level at which information is output to the screen.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   594
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   595
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   596
    global output_mode
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   597
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   598
    if args[0:] == '0':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   599
        output_mode = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   600
    elif args[0:] == '1':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   601
        output_mode = 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   602
    elif args[0:] == '2':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   603
        output_mode = 2
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   604
    elif args[0:] == '3':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   605
        output_mode = 3
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   606
    elif args[0:] == '4':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   607
        output_mode = 4
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   608
    elif args[0:] == '5':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   609
        output_mode = 5
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   610
    elif args[0:] == '6':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   611
        output_mode = 6
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   612
    elif args[0:] != '0' and args[0:] != '1' and args[0:] != '2' and args[0:] != '3' and args[0:] != '4' and args[0:] != '5' and args[0:] != '6':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   613
        log_screen('Monty ' + str(monty_version) + ' - Type monty.py -h for usage', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   614
        log_screen('ERROR: The output mode you supplied is invalid (-m). Use 0-6.', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   615
        sys.exit(monty_returncode_if_config_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   616
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   617
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   618
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   619
def display_stuff():
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   620
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   621
    This module displays stuff to the screen.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   622
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   623
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   624
    print "Cookies:\n\n\
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   625
This actually did happen to a real person, and the real person is me. I had gone to catch a train. This was April 1976, in Cambridge, U.K. I was a bit early for the train. I'd gotten the time of the train wrong. I went to get myself a newspaper to do the crossword, and a cup of coffee and a packet of cookies. I went and sat at a table. I want you to picture the scene. It's very important that you get this very clear in your mind. Here's the table, newspaper, cup of coffee, packet of cookies. There's a guy sitting opposite me, perfectly ordinary-looking guy wearing a business suit, carrying a briefcase. It didn't look like he was going to do anything weird. What he did was this: he suddenly leaned across, picked up the packet of cookies, tore it open, took one out, and ate it.\n\n\
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   626
Now this, I have to say, is the sort of thing the British are very bad at dealing with. There's nothing in our background, upbringing, or education that teaches you how to deal with someone who in broad daylight has just stolen your cookies. You know what would happen if this had been South Central Los Angeles. There would have very quickly been gunfire, helicopters coming in, CNN, you know... But in the end, I did what any red-blooded Englishman would do: I ignored it. And I stared at the newspaper, took a sip of coffee, tried to do a clue in the newspaper, couldn't do anything, and thought, What am I going to do?\n\n\
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   627
In the end I thought 'Nothing for it, I'll just have to go for it', and I tried very hard not to notice the fact that the packet was already mysteriously opened. I took out a cookie for myself. I thought, 'That settled him'. But it hadn't because a moment or two later he did it again. He took another cookie. Having not mentioned it the first time, it was somehow even harder to raise the subject the second time around. 'Excuse me, I couldn't help but notice'... I mean, it doesn't really work.\n\n\
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   628
We went through the whole packet like this. When I say the whole packet, I mean there were only about eight cookies, but it felt like a lifetime. He took one, I took one, he took one, I took one. Finally, when we got to the end, he stood up and walked away. Well, we exchanged meaningful looks, then he walked away, and I breathed a sigh of relief and sat back.\n\n\
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   629
A moment or two later the train was coming in, so I tossed back the rest of my coffee, stood up, picked up the newspaper, and underneath the newspaper were my cookies. The thing I like particularly about this story is the sensation that somewhere in England there has been wandering around for the last quarter-century a perfectly ordinary guy who's had the same exact story, only he doesn't have the punch line.\n\n\
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   630
-Douglas Adams, The Salmon of Doubt"
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   631
    sys.exit(0)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   632
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   633
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   634
################################################################################
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   635
# Interpret the command line arguments
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   636
################################################################################
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   637
functions = {'path': set_path,
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   638
             'test_path': set_test_path,
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   639
             'execute_file': set_execute_file,
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   640
             'store_output': set_store_output,
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   641
             'output_log_path': set_output_log_path,
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   642
             'internal_error_string': set_internal_error_string,
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   643
             'run_test': set_run_this_test,
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   644
             'run_group_test': set_run_group_test,
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   645
             'run_job': set_run_job_section,
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   646
             'store_csv_results': set_store_csv_results,
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   647
             'copy_log': set_copy_log,
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   648
             'monty_config_py': set_monty_config_py,
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   649
             'override_os_types': set_override_os_types,
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   650
             'zip_results': set_zip_results,
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   651
             'output_mode': set_output_mode,
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   652
             'capture_stderr': set_capture_stderr}
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   653
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   654
if __name__ == '__main__':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   655
    for the_opt in monty_options.__dict__.items():
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   656
        call_function = functions[str(the_opt[0])]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   657
        the_values = the_opt[1]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   658
        if not the_values:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   659
            pass
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   660
        else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   661
            # Check if the argument type is a List or a string.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   662
            # If a List, iterate through it and set the values.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   663
            if type(the_values) == types.ListType:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   664
                for val in the_values:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   665
                    call_function(val)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   666
            else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   667
                call_function(the_values)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   668
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   669
################################################################################
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   670
# Functions
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   671
################################################################################
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   672
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   673
# Include the config data - this will overwrite any existing values
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   674
vars_from_monty_cfg = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   675
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   676
if not os.path.basename(monty_config_py).lower().endswith('.py'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   677
    monty_config_py = monty_config_py + '.py'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   678
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   679
if os.path.exists(monty_config_py):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   680
    monty_len_of_cfg_filename = len(os.path.basename(monty_config_py))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   681
    monty_cfg_location = monty_config_py[:-monty_len_of_cfg_filename]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   682
    monty_config_py = os.path.basename(monty_config_py)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   683
    # Add the config path to the sys.path
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   684
    sys.path.append(monty_cfg_location)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   685
    if os.path.exists(monty_cfg_location + monty_config_py):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   686
        if monty_cfg_location != '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   687
            cwd = os.chdir(monty_cfg_location)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   688
        monty_cfg = __import__(monty_config_py[:-3])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   689
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   690
        # Get the variables and remove the unnecessary ones
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   691
        vars_from_monty_cfg = monty_cfg.__dict__.keys()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   692
        vars_from_monty_cfg.remove('__builtins__')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   693
        vars_from_monty_cfg.remove('__file__')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   694
        vars_from_monty_cfg.remove('__name__')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   695
        vars_from_monty_cfg.remove('__doc__')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   696
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   697
        # Go through the imported variables and get them into Monty.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   698
        # Horrible way of doing this. This is the kind of dirty that don't wash clean.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   699
        for var_idx in vars_from_monty_cfg:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   700
            statement = var_idx + ' = monty_cfg.' + var_idx
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   701
            #abc = monty_cfg.abc
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   702
            exec statement
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   703
        # Return to the original working directory
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   704
        os.chdir(original_cwd)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   705
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   706
    else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   707
        log_screen('Monty ' + str(monty_version) + ' - Type monty.py -h for usage', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   708
        log_screen('ERROR: Sorry, but the config module you supplied (\'' + os.path.basename(monty_config_py) + '\') was not found. Please try again.', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   709
        sys.exit(monty_returncode_if_config_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   710
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   711
else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   712
    if monty_config_py != 'monty_cfg.py' and (os.path.basename(monty_config_py)[:-3] != 'monty_cfg' or not os.path.basename(monty_config_py).lower().endswith('.py')):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   713
        log_screen('Monty ' + str(monty_version) + ' - Type monty.py -h for usage', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   714
        log_screen('ERROR: Sorry, but the config module you supplied (\'' + os.path.basename(monty_config_py) + '\') was not found. Please try again.', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   715
        sys.exit(monty_returncode_if_config_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   716
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   717
envRegex = re.compile("\$\((.+?)\)")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   718
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   719
# Get the USERNAME or USER environment variable. Not necessary anymore?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   720
if not 'USER' in os.environ:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   721
    os.environ['USER'] = 'montyuser'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   722
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   723
if not 'USERNAME' in os.environ:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   724
    os.environ['USERNAME'] = 'montyuser'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   725
else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   726
    os.environ['USERNAME'] = os.environ['USER']
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   727
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   728
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   729
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   730
def replace_envs(item):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   731
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   732
    This module substitutes environment variables specified in the command, into
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   733
    their actual values.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   734
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   735
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   736
    envs = envRegex.findall(item)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   737
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   738
    for envvar in set(envs):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   739
        try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   740
            item = item.replace("$(" + correct_slashes(envvar) + ")", os.environ[envvar])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   741
        except KeyError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   742
            log_screen("ERROR: The environment variable '" + envvar + "' (within the test suite) is not set in the environment.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   743
            log_msg(the_output_file, "ERROR: The environment variable '" + envvar + "' (within the test suite) is not set in the environment.")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   744
            sys.exit(monty_returncode_if_test_suite_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   745
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   746
    return item
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   747
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   748
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   749
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   750
def remove_whitespace(value):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   751
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   752
    This module simply removes blank lines from the provided text. It must have
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   753
    been accessed with x.readlines() first.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   754
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   755
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   756
    new_contents = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   757
    for line in value:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   758
        #print line.strip()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   759
        if os_type == 'windows':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   760
            new_contents.append(line.strip())
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   761
        else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   762
            new_contents.append(line)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   763
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   764
    if os_type == 'windows':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   765
        return "\n".join(new_contents)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   766
    else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   767
        return ''.join(new_contents)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   768
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   769
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   770
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   771
def normalise_filename(filename_to_normalise):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   772
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   773
    This module will convert invalid characters in a filename to those that can
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   774
    be used.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   775
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   776
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   777
    filename_to_normalise = filename_to_normalise.replace(' ', '_')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   778
    filename_to_normalise = filename_to_normalise.replace('/', '_')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   779
    filename_to_normalise = filename_to_normalise.replace('\\', '_')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   780
    filename_to_normalise = filename_to_normalise.replace(':', '_')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   781
    filename_to_normalise = filename_to_normalise.replace('*', '_')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   782
    filename_to_normalise = filename_to_normalise.replace('#', '_')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   783
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   784
    return filename_to_normalise
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   785
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   786
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   787
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   788
def simple_command(command):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   789
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   790
    This module executes the provided command and returns its output. It has no
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   791
    timeout functionality.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   792
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   793
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   794
    #sys.stdout = Unbuffered(sys.stdout)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   795
    #sys.stderr = Unbuffered(sys.stderr)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   796
    i, o = os.popen4(command)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   797
    i.close()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   798
    out = o.read()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   799
    return_code = o.close()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   800
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   801
    simple_command_return_list = ['SUCCESS', None, out, None, return_code]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   802
    return simple_command_return_list
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   803
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   804
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   805
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   806
def timeout_command(command):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   807
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   808
    This module executes the provided command and either returns its output or
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   809
    kills it if it doesn't normally exit within the timeout seconds, and returns
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   810
    None.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   811
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   812
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   813
    import signal
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   814
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   815
    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   816
        process_start = datetime.datetime.now()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   817
        cmd = command.split()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   818
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   819
        if os_type == 'windows':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   820
            use_shell = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   821
        else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   822
            use_shell = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   823
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   824
        if capture_stderr == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   825
            process = subprocess.Popen(cmd, bufsize=0, shell=use_shell, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   826
        else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   827
            process = subprocess.Popen(cmd, bufsize=0, shell=use_shell, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   828
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   829
        (child_stdin, child_stdout, child_stderr) = (process.stdin, process.stdout, process.stderr)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   830
        # We don't care about stdin
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   831
        child_stdin = None
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   832
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   833
        # Poll the process to check its returncode. None means it's still running
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   834
        timeout_return_code = process.poll()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   835
        while timeout_return_code is None:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   836
            timeout_return_code = process.poll()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   837
            #print 'Polled... Returncode = ' + str(timeout_return_code) + ', time = ' + str((datetime.datetime.now() - process_start).seconds)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   838
            time.sleep(0.2)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   839
            # Have we hit the timeout limit?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   840
            if(datetime.datetime.now() - process_start).seconds > timeout_secs:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   841
                if os_type == 'windows':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   842
                    # If using Windows, we need to use a different method to kill the task - win32api from PyWin32
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   843
                    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   844
                        import win32api
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   845
                        handle = win32api.OpenProcess(1, 0, process.pid)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   846
                        if not win32api.TerminateProcess(handle, 0):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   847
                            # Return a timeout notification
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   848
                            return ['TIMEOUT', None, None, None, None]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   849
                    except ImportError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   850
                        # Return a timeout error notification
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   851
                        return ['TIMEOUT-ERROR', None, None, None, None]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   852
                else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   853
                    # Kill the task on Unix and return a timeout notification
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   854
                    os.kill(process.pid, signal.SIGKILL)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   855
                    os.waitpid(-1, os.WNOHANG)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   856
                    return ['TIMEOUT', None, None, None, None]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   857
    except OSError,err:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   858
        # Return an error with id numebr and error string
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   859
        return ['ERROR', str(err.errno) + ': ' + err.strerror, None, None, None, None]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   860
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   861
    # The task completed successfully within the timeout, so return a success notification
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   862
    timeout_command_return_list = ['SUCCESS', child_stdin, child_stdout, child_stderr, timeout_return_code]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   863
    return timeout_command_return_list
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   864
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   865
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   866
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   867
def run_a_test(test_to_run):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   868
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   869
    This module actually runs the test and determines the result.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   870
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   871
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   872
    global total_time_taken, current_test_number, prev_test_id, prev_test_failed
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   873
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   874
    test_id = test_to_run['test_id']
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   875
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   876
    # Is the test commented out?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   877
    if test_id.startswith('#'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   878
        return 'SKIP'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   879
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   880
    # When running a job section, only the relevant jobs are in the dictionary, so we don't need to do anything here
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   881
    if job_section == '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   882
        # We're not running a job section
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   883
        # Are we running only one test?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   884
        if run_test != '' and test_id.lower() != run_test.lower() and test_id.lower() != run_test.lower() + '#' and test_id.lower() != run_test.lower() + '@':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   885
            return 'SKIP'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   886
        # Are we running a group of tests?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   887
        if run_group_test != '' and not test_id.lower().startswith(run_group_test.lower()):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   888
            return 'SKIP'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   889
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   890
    # Fail the test suite execution if the previous test failed?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   891
    if test_id.lower() == 'monty_end_if_failed' and prev_test_failed:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   892
        return 'MONTY_END_IF_FAILED'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   893
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   894
    # Do not execute the start or end of a job section
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   895
    if test_id.lower().startswith('--job'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   896
        return 'SKIP'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   897
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   898
    # Should this test be executed on this OS?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   899
    test_os_type = test_to_run['os_types']
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   900
    if override_os_types == '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   901
        if not os_type[0:1] in test_os_type:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   902
            return 'SKIP'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   903
    elif override_os_types == 'u':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   904
        if not 'u' in test_os_type:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   905
            return 'SKIP'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   906
    elif override_os_types == 'w':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   907
        if not 'w' in test_os_type:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   908
            return 'SKIP'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   909
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   910
    current_test_number = current_test_number + 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   911
    note = test_to_run['note']
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   912
    timed = test_to_run['timed']
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   913
    display_output = test_to_run['display_output']
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   914
    store_output = test_to_run['store_output']
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   915
    command = replace_envs(test_to_run['command'])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   916
    targets = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   917
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   918
    # Is this a monty_set_env command?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   919
    if command.lower().startswith('monty_set_env '):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   920
        meta_test_step_executed.append(test_id)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   921
        temp = command
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   922
        temp = temp.replace('monty_set_env ', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   923
        temp = temp.replace(' ', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   924
        split_temp = temp.split('=')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   925
        os.environ[split_temp[0]] = split_temp[1]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   926
        log_screen('INFO: [' + str(current_test_number) + '/' + str(total_tests) + "] Setting environment variable: '" + split_temp[0] + "' to: " + split_temp[1], '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   927
        log_msg(the_output_file, 'INFO: [' + str(current_test_number) + '/' + str(total_tests) + "] Setting environment variable: '" + split_temp[0] + "' to: " + split_temp[1])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   928
        return 'SKIP'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   929
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   930
    # Is this a monty_set_compiler command?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   931
    if command.lower().startswith('monty_set_compiler '):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   932
        meta_test_step_executed.append(test_id)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   933
        if os_type == 'windows':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   934
            # Get the compiler specified
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   935
            chosen_compiler = command
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   936
            chosen_compiler = chosen_compiler.replace('monty_set_compiler ', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   937
            chosen_compiler = chosen_compiler.replace(' ', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   938
            if not valid_compilers.has_key(chosen_compiler):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   939
                log_screen("WARNING: Unknown compiler chosen: '" + chosen_compiler + "'. Should be arm2_2, arm3_1, gcce3_4_3 or gcce4_2_3.", 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   940
                log_screen('       : Tests relying on this compiler *may* fail.', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   941
                log_msg(the_output_file, "WARNING: Unknown compiler chosen: '" + chosen_compiler + "'. Should be arm2_2, arm3_1, gcce3_4_3 or gcce4_2_3.")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   942
                log_msg(the_output_file, '       : Tests relying on this compiler *may* fail.')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   943
                return 'SKIP'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   944
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   945
            # Set the compiler variables to use the specified compiler
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   946
            log_screen('INFO: [' + str(current_test_number) + '/' + str(total_tests) + '] Setting compiler to ' + valid_compilers[chosen_compiler], '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   947
            log_msg(the_output_file, 'INFO: [' + str(current_test_number) + '/' + str(total_tests) + '] Setting compiler to ' + valid_compilers[chosen_compiler])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   948
            for key, value in compiler_vars.items():
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   949
                if key == chosen_compiler:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   950
                    for key2, value2 in value.items():
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   951
                        os.environ[key2] = value2
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   952
            return 'SKIP'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   953
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   954
    # Restore the original directory?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   955
    if command.lower() == 'monty_restore_cwd':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   956
        meta_test_step_executed.append(test_id)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   957
        log_screen('INFO: [' + str(current_test_number) + '/' + str(total_tests) + "] Changing directory back to: '" + original_cwd + "'", '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   958
        log_msg(the_output_file, 'INFO: [' + str(current_test_number) + '/' + str(total_tests) + "] Changing directory back to: '" + original_cwd + "'")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   959
        try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   960
            os.chdir(original_cwd)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   961
            return 'SKIP'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   962
        except OSError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   963
            log_screen('WARNING: Failed to change directory back to: ' + original_cwd, 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   964
            log_screen('       : Tests dependent upon this change *may* fail or produce incorrect results.', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   965
            log_msg(the_output_file, "WARNING: Failed to change directory back to: '" + original_cwd + "'")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   966
            log_msg(the_output_file, "       : The next test *may* fail or produce incorrect results.\n")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   967
            return 'SKIP'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   968
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   969
    # Is this the 'cd' command?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   970
    if command.lower().startswith('cd '):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   971
        meta_test_step_executed.append(test_id)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   972
        log_screen('INFO: [' + str(current_test_number) + '/' + str(total_tests) + "] Changing directory to: '" + command[3:] + "'", '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   973
        log_msg(the_output_file, 'INFO: [' + str(current_test_number) + '/' + str(total_tests) + "] Changing directory to: '" + command[3:] + "'")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   974
        try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   975
            os.chdir(command[3:])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   976
            return 'SKIP'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   977
        except OSError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   978
            log_screen('WARNING: Failed to change directory to: ' + command[3:], 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   979
            log_screen('       : Tests dependent upon this change *may* fail or produce incorrect results.', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   980
            log_msg(the_output_file, "WARNING: Failed to change directory to: '" + command[3:] + "'")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   981
            log_msg(the_output_file, "       : The next test *may* fail or produce incorrect results.")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   982
            return 'SKIP'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   983
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   984
    # Is this a special case test?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   985
    test_id_out = test_id
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   986
    test_id_note = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   987
    if test_id.endswith('#'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   988
        test_id_out = test_id[:-1]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   989
        test_id_note = ' (does not contribute to results)'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   990
        meta_test_step_executed.append(test_id_out)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   991
    elif test_id.endswith('@'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   992
        test_id_out = test_id[:-1]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   993
        test_id_note = ' (targets will not be deleted prior to execution)'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   994
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   995
    # Go through the specified targets and delete them so the environment is clean
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   996
    for t in test_to_run['targets']:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   997
        the_actual_target = replace_column_variables(os.path.normpath(replace_envs(t)), 1)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   998
        targets.append(the_actual_target)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
   999
        if not test_id.endswith('@'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1000
            if os.path.exists(the_actual_target):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1001
                try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1002
                    os.remove(the_actual_target)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1003
                    log_msg(the_output_file, "INFO: Removed target: '" + the_actual_target + "'")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1004
                except OSError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1005
                    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1006
                        os.rmdir(the_actual_target)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1007
                        log_msg(the_output_file, "INFO: Removed target dir: '" + the_actual_target + "'")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1008
                    except OSError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1009
                        log_screen("WARNING: Could not remove '" + the_actual_target + "' before test", 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1010
                        log_msg(the_output_file, "WARNING: Could not remove '" + the_actual_target + "' before test")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1011
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1012
    log_screen('', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1013
    if test_id.endswith('#'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1014
        test_id_step_text = 'TEST STEP  : '
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1015
    else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1016
        test_id_step_text = 'TEST ID    : '
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1017
        meta_test_case_executed.append(test_id)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1018
    log_screen(test_id_step_text + '[' + str(current_test_number) + '/' + str(total_tests) + '] ' + test_id_out + test_id_note, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1019
    log_screen('NOTE       : ' + note, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1020
    log_screen('COMMAND    : ' + command, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1021
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1022
    # Execute the command and capture its output, and time taken, if required
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1023
    start_time = time.time()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1024
    if timeout_secs > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1025
        # Timeout is set to more than zero seconds, so use the timeout function.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1026
        timeout_results = timeout_command(command)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1027
    else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1028
        #timeout_results = timeout_command(command)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1029
        timeout_results = simple_command(command)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1030
    end_time = time.time()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1031
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1032
    process_result = timeout_results[0]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1033
    child_stdin = timeout_results[1]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1034
    child_stdout = timeout_results[2]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1035
    child_stderr = timeout_results[3]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1036
    return_code = timeout_results[4]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1037
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1038
    # Check for timeouts, exceptions and no output
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1039
    if process_result == 'TIMEOUT-ERROR':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1040
        child_stdout = "ERROR: To use the process timeout function on Windows, you need to install PyWin32 from:\n"
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1041
        child_stdout = child_stdout + "http://sourceforge.net/project/showfiles.php?group_id=78018\n"
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1042
        child_stdout = child_stdout + 'ERROR: The task could not be terminated and may still be running...'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1043
    elif process_result == 'TIMEOUT':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1044
        child_stdout = 'ERROR: The command did not complete within the specified timeout period (' + str(timeout_secs) + ' seconds).'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1045
    elif process_result == 'ERROR':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1046
        child_stdout = "ERROR: The command caused the following exception and terminated:\n       #" + child_stdin
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1047
    elif process_result is None:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1048
        child_stdout = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1049
    elif process_result == 'SUCCESS':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1050
        if timeout_secs > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1051
            child_stdout = remove_whitespace(child_stdout)#.readlines())
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1052
    if child_stderr is not None:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1053
        if timeout_secs > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1054
            child_stderr = remove_whitespace(child_stderr)#.readlines())
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1055
        child_stdout = child_stdout + child_stderr
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1056
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1057
    # Count the targets that were built
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1058
    found = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1059
    missing = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1060
    if targets:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1061
        for t in targets:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1062
            the_actual_target = replace_column_variables(t, 1)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1063
            if os.path.exists(the_actual_target):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1064
                found = found + 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1065
            else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1066
                missing.append(the_actual_target)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1067
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1068
    # Count the errors and warnings
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1069
    warn = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1070
    error = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1071
    exception = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1072
    expected_output_count = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1073
    lines = child_stdout.split("\n")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1074
    dest_log_file_name = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1075
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1076
    for line in lines:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1077
        if determine_warning_Regex.search(line) != None:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1078
            warn = warn + 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1079
        elif determine_error_Regex.search(line) != None:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1080
            error = error + 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1081
        elif determine_traceback_Regex.search(line) != None:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1082
            exception = exception + 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1083
        else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1084
            log_found = None
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1085
            try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1086
                logRegex = re.compile(log_file_output_name)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1087
                log_found = logRegex.search(line)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1088
            except re.error:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1089
                log_screen("WARNING: The regular expression used for the 'log_file_output_name' variable is invalid. Check your '..._cfg.py' file.", 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1090
                log_msg(the_output_file, "WARNING: ")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1091
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1092
            if log_found != None:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1093
                # Copy the log file to the output_log_path
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1094
                log_file_name = log_found.group(1)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1095
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1096
                if os.path.exists(log_file_name):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1097
                    # Normalise the name and filename
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1098
                    normalised_name = normalise_filename(test_id)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1099
                    dest_log_file_name = normalise_filename(log_file_name)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1100
                    dest_log_file_name = log_dir + d.strftime("%Y-%m-%d_%H-%M-%S") + "_" + normalised_name + "---" + dest_log_file_name
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1101
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1102
                    # Increment the filename if it already exists
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1103
                    if os.path.exists(dest_log_file_name):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1104
                        log_file_name_count = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1105
                        while os.path.exists(dest_log_file_name + '_' + str(log_file_name_count)):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1106
                            log_file_name_count = log_file_name_count + 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1107
                        dest_log_file_name = dest_log_file_name + '_' + str(log_file_name_count)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1108
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1109
                    # Copy the file so that we have some readable output
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1110
                    shutil.copy(log_file_name, dest_log_file_name)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1111
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1112
                    if not os.path.isfile(dest_log_file_name):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1113
                        log_screen('WARNING: Could not copy command output log file for this test', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1114
                    else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1115
                        # Now search through the log file for warnings and errors
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1116
                        try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1117
                            output_log_check_lines_file = open(dest_log_file_name, 'r')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1118
                            output_log_check_lines = output_log_check_lines_file.readlines()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1119
                            for output_log_check_line in output_log_check_lines:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1120
                                if determine_warning_Regex.search(output_log_check_line) != None:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1121
                                    warn = warn + 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1122
                                elif determine_error_Regex.search(output_log_check_line) != None:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1123
                                    error = error + 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1124
                        except IOError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1125
                            log_screen("WARNING: Couldn't open log file: '" + dest_log_file_name + "' for reading.", 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1126
                            log_screen('       : Warnings and errors *may* be incorrect.', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1127
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1128
    # Send output to the screen
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1129
    if display_output == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1130
        log_screen('', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1131
        log_screen(centre_line_niceness('START OF OUTPUT OF THIS TEST', '-', line_dash_count), '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1132
        log_screen(child_stdout, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1133
        log_screen(centre_line_niceness('END OF OUTPUT OF THIS TEST', '-', line_dash_count), '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1134
        if child_stderr is not None and child_stderr != '' and capture_stderr == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1135
            log_screen('', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1136
            log_screen(centre_line_niceness('START OF STDERR OUTPUT OF THIS TEST', '-', line_dash_count), '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1137
            log_screen(child_stderr, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1138
            log_screen(centre_line_niceness('END OF STDERR OUTPUT OF THIS TEST', '-', line_dash_count), '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1139
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1140
    # If there was anything in child_stderr, output it to a file
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1141
    child_stderr_output_file = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1142
    if child_stderr is not None and child_stderr != '' and store_output == 1 and capture_stderr == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1143
        if ' ' in test_id:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1144
            ourPattern = re.compile('(.*?)(\s)')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1145
            result = ourPattern.match(test_id)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1146
            filename = result.group(0)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1147
        else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1148
            filename = test_id[:25]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1149
        filename = normalise_filename(filename)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1150
        log_screen('SAVE STDERR: ' + log_dir + filename + '_' + d.strftime("%Y-%m-%d_%H-%M-%S") + '_stderr_log.txt', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1151
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1152
        try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1153
            child_stderr_output_file = open(log_dir + filename + "_" + d.strftime("%Y-%m-%d_%H-%M-%S") + '_stderr_log.txt', 'wt')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1154
            log_msg(child_stderr_output_file, test_id_step_text + '[' + str(current_test_number) + '/' + str(total_tests) + '] ' + test_id_out + test_id_note + "\nNOTE       : " + note + "\nCOMMAND    : " + command + "\nSTDERR OUT :")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1155
            log_msg(child_stderr_output_file, centre_line_niceness('START OF STDERR OUTPUT OF THIS TEST', '-', line_dash_count))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1156
            log_msg(child_stderr_output_file, child_stderr)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1157
            log_msg(child_stderr_output_file, centre_line_niceness('END OF STDERR OUTPUT OF THIS TEST', '-', line_dash_count))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1158
        except IOError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1159
            show_error(log_dir + filename + '_' + d.strftime("%Y-%m-%d_%H-%M-%S") + '_stderr_log.txt', 'The file could not be created.', child_stderr_output_file, 0)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1160
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1161
    # Redirect all output to a file?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1162
    output_file = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1163
    output_file_exists = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1164
    if store_output == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1165
        if ' ' in test_id:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1166
            ourPattern = re.compile('(.*?)(\s)')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1167
            result = ourPattern.match(test_id)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1168
            filename = result.group(0)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1169
        else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1170
            filename = test_id[:25]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1171
        filename = normalise_filename(filename)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1172
        log_screen('SAVING LOG : ' + log_dir + filename + '_' + d.strftime("%Y-%m-%d_%H-%M-%S") + '_log_<RESULT>.txt', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1173
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1174
        try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1175
            output_file = open(log_dir + filename + "_" + d.strftime("%Y-%m-%d_%H-%M-%S") + '_log_IN_PROGRESS.txt', 'wt')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1176
            log_msg(output_file, test_id_step_text + '[' + str(current_test_number) + '/' + str(total_tests) + '] ' + test_id_out + test_id_note + "\nNOTE       : " + note + "\nCOMMAND    : " + command + "\nOUTPUT     :")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1177
            log_msg(output_file, centre_line_niceness('START OF OUTPUT OF THIS TEST', '-', line_dash_count))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1178
            log_msg(output_file, child_stdout)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1179
            log_msg(output_file, centre_line_niceness('END OF OUTPUT OF THIS TEST', '-', line_dash_count))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1180
            output_file_exists = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1181
        except IOError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1182
            show_error(log_dir + filename + '_' + d.strftime("%Y-%m-%d_%H-%M-%S") + '_log_IN_PROGRESS.txt', 'The file could not be created.', output_file, 0)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1183
            output_file_exists = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1184
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1185
    log_msg(the_output_file, "\n" + test_id_step_text + '[' + str(current_test_number) + '/' + str(total_tests) + '] ' + test_id_out + test_id_note)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1186
    log_msg(the_output_file, "NOTE       : " + note + "\nCOMMAND    : " + command + "\nOUTPUT     :\n" + child_stdout)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1187
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1188
    # Was this test timed?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1189
    if timed == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1190
        time_difference = end_time - start_time
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1191
        total_time_taken = total_time_taken + time_difference
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1192
        log_screen(str("TIME TAKEN : %.2f" % (time_difference, ) + ' seconds'), '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1193
        log_msg(the_output_file, str("TIME TAKEN : %.2f" % (time_difference, )) + ' seconds')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1194
        log_msg_if_exists(output_file, str("TIME TAKEN : %.2f" % (time_difference, )) + ' seconds', store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1195
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1196
    # Set up the results for checking later on
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1197
    expected = test_to_run['expected']
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1198
    result = {'missing': len(missing),
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1199
              'warnings': warn,
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1200
              'errors': error,
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1201
              'exceptions': exception}
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1202
    success = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1203
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1204
    # Check the results
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1205
    success = check_results(targets, found, missing, warn, error, exception, expected, the_output_file, output_file, store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1206
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1207
    # Check for internal errors. Only reports the first occurrence of 'internal_error_string' in the output
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1208
    found_internal_error = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1209
    if internal_error_string != "":
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1210
        for line in lines:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1211
            if line.find(internal_error_string) != -1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1212
                if not found_internal_error:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1213
                    found_internal_error = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1214
                    log_screen('INTERNAL ERROR. Check output (last 20 lines shown):', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1215
                    log_screen(centre_line_niceness('START OF INTERNAL ERROR OUTPUT', '-', line_dash_count), '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1216
                    log_screen('', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1217
                    log_msg(the_output_file, 'INTERNAL ERROR. Check output (last 20 lines shown):')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1218
                    log_msg(the_output_file, centre_line_niceness('START OF INTERNAL ERROR OUTPUT', '-', line_dash_count) + "\n")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1219
                    log_msg_if_exists(output_file, 'INTERNAL ERROR. Check output (last 20 lines shown):', store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1220
                    log_msg_if_exists(output_file, centre_line_niceness('START OF INTERNAL ERROR OUTPUT', '-', line_dash_count) + "\n", store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1221
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1222
                    line_count = len(lines) - 20
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1223
                    if line_count <= 20:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1224
                        line_count = len(lines) - 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1225
                    for line_index in range(len(lines) - line_count + 1, len(lines) - 1):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1226
                        log_screen(lines[line_index], '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1227
                        log_msg(the_output_file, str(lines[line_index]))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1228
                        log_msg_if_exists(output_file, str(lines[line_index]), store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1229
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1230
                    log_screen('', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1231
                    log_screen(centre_line_niceness('END OF INTERNAL ERROR OUTPUT', '-', line_dash_count), '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1232
                    log_msg(the_output_file, "\n" + centre_line_niceness('END OF INTERNAL ERROR OUTPUT', '-', line_dash_count))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1233
                    log_msg_if_exists(output_file, "\n" + centre_line_niceness('END OF INTERNAL ERROR OUTPUT', '-', line_dash_count), store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1234
                    success = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1235
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1236
    # Are we expecting some text in the output?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1237
    expected_output = test_to_run['expected_output']
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1238
    expected_output_len = len(expected_output)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1239
    expected_output_loop = expected_output_len - 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1240
    if expected_output_loop >= 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1241
        expected_output_index = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1242
        expected_output_count = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1243
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1244
        # If the log was copied, we need to read that log so we can check for expected output
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1245
        if copy_log == 1 and os.path.exists(dest_log_file_name):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1246
            log_file_contents = open(dest_log_file_name, 'r')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1247
            lines = lines + log_file_contents.readlines()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1248
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1249
        for line in lines:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1250
            if line.find(replace_column_variables(expected_output[expected_output_index], 1)) != -1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1251
                expected_output_count = expected_output_count + 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1252
                if expected_output_index < expected_output_loop:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1253
                    expected_output_index = expected_output_index + 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1254
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1255
        log_screen(str("EXP.OUTPUT : %d, expected %d" % (expected_output_count, expected_output_len)), '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1256
        log_msg(the_output_file, str("EXP.OUTPUT : %d, expected %d" % (expected_output_count, expected_output_len)))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1257
        log_msg_if_exists(output_file, str("EXP.OUTPUT : %d, expected %d" % (expected_output_count, expected_output_len)), store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1258
        if expected_output_count != expected_output_len:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1259
            success = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1260
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1261
    # Any known errors?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1262
    if allow_missing_commands_to_fail_test == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1263
        for line in lines:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1264
            if os_type == "windows" and line.find("is not recognized as an internal or external command") != -1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1265
                # This output means that the command entered was not found on Windows - fail the test
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1266
                success = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1267
            if os_type == "unix" and line.find("command not found") != -1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1268
                # This output means that the command entered was not found on Unix - fail the test
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1269
                success = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1270
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1271
    # Check the return code
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1272
    test_return_code = test_to_run['return_code']
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1273
    if return_code is None:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1274
        return_code = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1275
    if os_type == 'windows':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1276
        if test_return_code != 0 or (test_return_code == 0 and return_code != 0):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1277
            log_screen(str("RETURNCODE : %d, expected %d" % (return_code, test_return_code)), '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1278
            log_msg(the_output_file, str("RETURNCODE : %d, expected %d" % (return_code, test_return_code)))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1279
            log_msg_if_exists(output_file, str("RETURNCODE : %d, expected %d" % (return_code, test_return_code)), store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1280
        if (test_return_code != 0 and return_code != test_return_code) or (test_return_code == 0 and return_code != 0):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1281
            success = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1282
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1283
    # Determine the success, and mark the test appropriately
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1284
    if success:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1285
        log_screen('RESULT     : Pass', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1286
        log_msg(the_output_file, 'RESULT     : Pass')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1287
        log_msg_if_exists(output_file, 'RESULT     : Pass', store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1288
        result_csv = 'Passed'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1289
    else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1290
        log_screen('RESULT     : Failed', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1291
        log_msg(the_output_file, 'RESULT     : Failed')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1292
        log_msg_if_exists(output_file, 'RESULT     : Failed', store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1293
        if found_internal_error:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1294
            internal_error_failures.append(test_id)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1295
        else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1296
            failures.append(test_id + ' --- ' + note)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1297
        result_csv = 'Failed'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1298
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1299
    # Write the result to the CSV results file?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1300
    # If the id ends with a '#' it will not be written as a CSV result
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1301
    csv_indiv_file_exists = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1302
    if store_csv_results == 1 and not test_id.endswith('#'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1303
    	ts = d.fromtimestamp(start_time)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1304
    	te = d.fromtimestamp(end_time)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1305
    #Here is the implementation of adding microseconds in the end in ':000' format
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1306
    	start_microseconds = ts.microsecond/1000
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1307
    	end_microseconds = te.microsecond/1000
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1308
    
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1309
    	if start_microseconds == 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1310
                start_microseconds = "000"
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1311
        elif start_microseconds < 10:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1312
                start_microseconds = "00" + str(start_microseconds)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1313
        elif start_microseconds < 100:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1314
                start_microseconds = "0" + str(start_microseconds)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1315
                
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1316
        if end_microseconds == 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1317
                end_microseconds = "000"
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1318
        elif end_microseconds < 10:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1319
                end_microseconds = "00" + str(end_microseconds)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1320
        elif end_microseconds < 100:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1321
                end_microseconds = "0" + str(end_microseconds)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1322
                
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1323
                
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1324
        csv_results_file.write(test_id_out + ",'" + str(ts.strftime(results_date_format)+":"+str(start_microseconds)) + ",'" + str(te.strftime(results_date_format)+":"+str(end_microseconds)) + ',' + result_csv + "\n")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1325
        if store_output == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1326
            try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1327
                csv_indiv_results_file = open(log_dir + test_id_out + '_' + d.strftime("%Y-%m-%d_%H-%M-%S") + '_results_IN_PROGRESS.csv', 'wt')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1328
                csv_indiv_results_file.write("TestCaseId,StartTime,EndTime,Result\n")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1329
                csv_indiv_results_file.write(test_id_out + ",'" + str(ts.strftime(results_date_format)) + ",'" + str(te.strftime(results_date_format)) + ',' + result_csv + "\n")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1330
                csv_indiv_file_exists = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1331
                csv_indiv_results_file.close()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1332
            except OSError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1333
                log_screen("WARNING: Couldn't write CSV results file for test case: '" + test_id + "'.", 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1334
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1335
    log_screen(line_separator_dash, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1336
    log_msg(the_output_file, line_separator_dash)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1337
    log_msg_if_exists(output_file, line_separator_dash, store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1338
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1339
    # Rename the output files?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1340
    if store_output == 1 and output_file_exists:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1341
        output_file.close()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1342
        output_filename_result = '_PASS'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1343
        if not success:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1344
            output_filename_result = '_FAIL'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1345
        if found_internal_error:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1346
            output_filename_result = output_filename_result + '_WITH_INTERNAL_ERROR'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1347
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1348
        old_output_filename = log_dir + filename + '_' + d.strftime("%Y-%m-%d_%H-%M-%S") + '_log_IN_PROGRESS.txt'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1349
        new_output_filename = log_dir + filename + '_' + d.strftime("%Y-%m-%d_%H-%M-%S") + '_log' + output_filename_result + '.txt'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1350
        try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1351
            os.rename(old_output_filename, new_output_filename)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1352
            log_screen("INFO       : The output file has been renamed to: '" + new_output_filename + "'", '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1353
        except OSError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1354
            log_screen("WARNING: Couldn't rename the output log file for test case: " + old_output_filename, 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1355
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1356
        if csv_indiv_file_exists:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1357
            old_output_filename = log_dir + test_id_out + '_' + d.strftime("%Y-%m-%d_%H-%M-%S") + '_results_IN_PROGRESS.csv'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1358
            new_output_filename = log_dir + test_id_out + '_' + d.strftime("%Y-%m-%d_%H-%M-%S") + '_results' + output_filename_result + '.csv'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1359
            try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1360
                os.rename(old_output_filename, new_output_filename)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1361
                log_screen("INFO       : The CSV results file has been renamed to: '" + new_output_filename + "'", '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1362
            except OSError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1363
                log_screen("WARNING: Couldn't rename the CSV results file for test case: " + test_id_out + ' (' + old_output_filename + ').', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1364
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1365
        log_screen(line_separator_dash, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1366
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1367
    # Decide how to exit the module
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1368
    if success:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1369
        prev_test_failed = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1370
        return 'TRUE'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1371
    else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1372
        prev_test_id = test_id
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1373
        prev_test_failed = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1374
        if found_internal_error:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1375
            return 'FALSE-INTERNAL_ERROR'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1376
        elif test_id.endswith('#'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1377
            return 'FALSE-STEP'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1378
        else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1379
            return 'FALSE'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1380
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1381
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1382
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1383
def check_results(the_targets, found, the_missing, the_warn, the_error, the_exception, expected_items, in_the_output_file, in_output_file, store_output, output_file_exists):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1384
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1385
    This module checks whether the targets expected are present or missing, and
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1386
    whether there are any errors, warnings or exceptions.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1387
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1388
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1389
    this_test_success = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1390
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1391
    # Any targets?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1392
    if len(the_targets) > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1393
        if len(the_targets) == expected_items['missing']:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1394
            log_screen(str("TARGETS    : %d, all are expected to be missing" % (len(the_targets))), '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1395
            log_msg(in_the_output_file, str("TARGETS    : %d, all are expected to be missing" % (len(the_targets))))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1396
            log_msg_if_exists(in_output_file, str("TARGETS    : %d, all are expected to be missing" % (len(the_targets))), store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1397
        else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1398
            if expected_items['missing'] > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1399
                log_screen(str("TARGETS    : %d, expected %d" % (found, len(the_targets) - expected_items['missing'])), '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1400
                log_msg(in_the_output_file, str("TARGETS    : %d, expected %d" % (found, len(the_targets) - expected_items['missing'])))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1401
                log_msg_if_exists(in_output_file, str("TARGETS    : %d, expected %d" % (found, len(the_targets) - expected_items['missing'])), store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1402
                if (len(the_targets) - expected_items['missing']) != found:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1403
                    this_test_success = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1404
            else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1405
                log_screen(str("TARGETS    : %d, expected %d" % (found, len(the_targets))), '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1406
                log_msg(in_the_output_file, str("TARGETS    : %d, expected %d" % (found, len(the_targets))))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1407
                log_msg_if_exists(in_output_file, str("TARGETS    : %d, expected %d" % (found, len(the_targets))), store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1408
                if (len(the_targets) - expected_items['missing']) != found:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1409
                    this_test_success = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1410
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1411
    # Any missing items?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1412
    if expected_items['missing'] != 0 or len(the_missing) != 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1413
        log_screen(str("MISSING    : %d, expected %d" % (len(the_missing), expected_items['missing'])), '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1414
        log_msg(in_the_output_file, str("MISSING    : %d, expected %d" % (len(the_missing), expected_items['missing'])))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1415
        log_msg_if_exists(in_output_file, str("MISSING    : %d, expected %d" % (len(the_missing), expected_items['missing'])), store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1416
    if len(the_missing) != expected_items['missing']:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1417
        this_test_success = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1418
        for the_file in the_missing:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1419
            log_screen(str("           : %s" % (the_file)), '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1420
            log_msg(in_the_output_file, str("           : %s" % (the_file)))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1421
            log_msg_if_exists(in_output_file, str("           : %s" % (the_file)), store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1422
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1423
    # Any warnings?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1424
    if expected_items['warnings'] != 0 or the_warn != 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1425
        log_screen(str("WARNINGS   : %d, expected %d" % (the_warn, expected_items['warnings'])), '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1426
        log_msg(in_the_output_file, str("WARNINGS   : %d, expected %d" % (the_warn, expected_items['warnings'])))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1427
        log_msg_if_exists(in_output_file, str("WARNINGS   : %d, expected %d" % (the_warn, expected_items['warnings'])), store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1428
    if the_warn != expected_items['warnings']:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1429
        this_test_success = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1430
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1431
    # Any errors?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1432
    if expected_items['errors'] != 0 or the_error != 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1433
        log_screen(str("ERRORS     : %d, expected %d" % (the_error, expected_items['errors'])), '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1434
        log_msg(in_the_output_file, str("ERRORS     : %d, expected %d" % (the_error, expected_items['errors'])))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1435
        log_msg_if_exists(in_output_file, str("ERRORS     : %d, expected %d" % (the_error, expected_items['errors'])), store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1436
    if the_error != expected_items['errors']:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1437
        this_test_success = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1438
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1439
    # Any exceptions?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1440
    if expected_items['exceptions'] != 0 or the_exception != 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1441
        log_screen(str("EXCEPTIONS : %d, expected %d" % (the_exception, expected_items['exceptions'])), '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1442
        log_msg(in_the_output_file, str("EXCEPTIONS : %d, expected %d" % (the_exception, expected_items['exceptions'])))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1443
        log_msg_if_exists(in_output_file, str("EXCEPTIONS : %d, expected %d" % (the_exception, expected_items['exceptions'])), store_output, output_file_exists)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1444
    if the_exception != expected_items['exceptions']:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1445
        this_test_success = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1446
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1447
    # Return the result
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1448
    return this_test_success
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1449
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1450
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1451
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1452
def replace_column_variables(column, stripslashes):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1453
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1454
    This module replaces any occurences of internal Monty variables and those
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1455
    variables within the monty_cfg module in test case fields with the value of
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1456
    that variable.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1457
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1458
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1459
    column = replace_envs(column)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1460
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1461
    # Replace internal Monty variables
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1462
    value_of_idx = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1463
    for loop_idx in vars_from_monty:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1464
        statement_to_run = 'value_of_idx = str(' + loop_idx + ')'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1465
        try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1466
            if os_type == 'windows' and loop_idx == 'root_drive':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1467
                # Change drive letters to uppercase
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1468
                value_of_idx = value_of_idx.upper()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1469
            exec statement_to_run
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1470
            column = column.replace('" + ' + loop_idx + ' + "', value_of_idx)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1471
            column = column.replace('" + ' + loop_idx, value_of_idx)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1472
            column = column.replace(loop_idx + ' + "', value_of_idx)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1473
        except NameError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1474
            log_screen("ERROR: The internal variable '" + loop_idx + "' used in the test suite is undefined.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1475
            log_msg(the_output_file, "ERROR: The internal variable '" + loop_idx + "' used in the test suite is undefined.")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1476
            sys.exit(monty_returncode_if_test_suite_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1477
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1478
    # Replace the variables from the monty_cfg module
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1479
    for loop_idx in vars_from_monty_cfg:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1480
        statement_to_run = 'value_of_idx = str(' + loop_idx + ')'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1481
        try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1482
            exec statement_to_run
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1483
            column = column.replace('" + ' + loop_idx + ' + "', value_of_idx)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1484
            column = column.replace('" + ' + loop_idx, value_of_idx)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1485
            column = column.replace(loop_idx + ' + "', value_of_idx)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1486
        except NameError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1487
            log_screen("ERROR: The variable '" + loop_idx + "' used in the test suite is undefined. Check your '..._cfg.py' file.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1488
            log_msg(the_output_file, "ERROR: The variable '" + loop_idx + "' used in the test suite is undefined. Check your '..._cfg.py' file.")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1489
            sys.exit(monty_returncode_if_test_suite_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1490
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1491
    # Strip any invalid slashes
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1492
    if stripslashes == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1493
        column = column.replace('\\\\', '\\')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1494
    else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1495
        if os_type == "unix":
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1496
            column = column.replace(':\\', '\\')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1497
            column = column.replace('\\', '/')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1498
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1499
    return column
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1500
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1501
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1502
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1503
def get_tests(file_handle):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1504
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1505
    This module reads in the test case CSV file and returns a List variable
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1506
    containing the test cases to execute.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1507
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1508
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1509
    global internal_command_count, total_tests, test_cases, test_steps, meta_test_step_id, meta_test_case_id
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1510
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1511
    row_line_number = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1512
    line_errors = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1513
    tests_common = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1514
    rows = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1515
    skipped_rows = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1516
    actual_rows = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1517
    found_run_test = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1518
    run_test_dict = {}
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1519
    found_run_group_test = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1520
    run_group_test_dict = {}
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1521
    tests_in_group = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1522
    found_job_section = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1523
    run_job_test_dict = {}
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1524
    in_job_section = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1525
    number_of_columns = 14
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1526
    have_reset_tests_common = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1527
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1528
    for row in file_handle:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1529
        actual_rows += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1530
        row_line_number += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1531
        row_dict = {}
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1532
        exp_dict = {'missing': 0, 'warnings': 0, 'errors': 0, 'exceptions': 0}
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1533
        dict_index = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1534
        skip_test = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1535
        internal_command = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1536
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1537
        for column in row:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1538
            if not skip_test:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1539
                if dict_index == 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1540
                    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1541
                        row_dict['test_id'] = replace_column_variables(column, 0)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1542
                    except ValueError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1543
                        log_screen('WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: id', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1544
                        log_screen("       : Defaulting to: 'TEST-" + str(row_line_number) + "'", 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1545
                        log_msg(the_output_file, 'WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: id')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1546
                        log_msg(the_output_file, "       : Defaulting to: 'TEST-" + str(row_line_number) + "'")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1547
                        row_dict['test_id'] = 'TEST-' + str(row_line_number)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1548
                        line_errors += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1549
                    if row_dict['test_id'] == 'id':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1550
                        # User has not removed the header row from the csv file; just ignore this row
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1551
                        dict_index = number_of_columns - 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1552
                        actual_rows -= 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1553
                        skip_test = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1554
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1555
                    if job_section != '' and not skip_test:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1556
                        # Check to see if this job section is the one we're looking for
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1557
                        if row_dict['test_id'].lower() == '--job start: ' + job_section.lower() and found_job_section == False:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1558
                            # Yes, so ignore the row
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1559
                            actual_rows -= 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1560
                            dict_index = number_of_columns - 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1561
                            skip_test = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1562
                            found_job_section = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1563
                            in_job_section = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1564
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1565
                        if row_dict['test_id'].lower() == '--job end: ' + job_section.lower() and found_job_section == True:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1566
                            # This is the end of the selected job section, so ignore the row
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1567
                            actual_rows -= 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1568
                            dict_index = number_of_columns - 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1569
                            skip_test = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1570
                            in_job_section = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1571
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1572
                        if not in_job_section:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1573
                            # We aren't currently in a job section, so these are tests that might be the selected individual or group
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1574
                            if row_dict['test_id'].lower() != '--job end: ' + job_section.lower():
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1575
                                if run_test != '' and (row_dict['test_id'].lower() != run_test.lower() and row_dict['test_id'].lower() != run_test.lower() + '#' and row_dict['test_id'].lower() != run_test.lower() + '@'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1576
                                    if row_dict['test_id'].lower().startswith('--job'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1577
                                        actual_rows -= 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1578
                                    row_dict['test_id'] = '#' + row_dict['test_id']
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1579
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1580
                                elif run_group_test != '' and not row_dict['test_id'].lower().startswith(run_group_test.lower()):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1581
                                    if row_dict['test_id'].lower().startswith('--job'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1582
                                        actual_rows -= 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1583
                                    row_dict['test_id'] = '#' + row_dict['test_id']
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1584
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1585
                                elif row_dict['test_id'].startswith('#') or row_dict['test_id'].lower().startswith('--job'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1586
                                    actual_rows -= 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1587
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1588
                            skip_test = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1589
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1590
                        # Running a single test or a group of tests is possible with a job section
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1591
                        if run_test != '' and (row_dict['test_id'].lower() == run_test.lower() or row_dict['test_id'].lower() == run_test.lower() + '#' or row_dict['test_id'].lower() == run_test.lower() + '@'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1592
                            found_run_test = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1593
                            skip_test = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1594
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1595
                        if run_group_test != '' and row_dict['test_id'].lower().startswith(run_group_test.lower()):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1596
                            found_run_group_test = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1597
                            skip_test = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1598
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1599
                    else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1600
                        if not skip_test:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1601
                            if run_test != '' and (row_dict['test_id'].lower() == run_test.lower() or row_dict['test_id'].lower() == run_test.lower() + '#' or row_dict['test_id'].lower() == run_test.lower() + '@'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1602
                                found_run_test = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1603
                            if run_group_test != '' and row_dict['test_id'].lower().startswith(run_group_test.lower()):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1604
                                found_run_group_test = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1605
                            if row_dict['test_id'].startswith('#') or row_dict['test_id'].lower().startswith('--job'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1606
                                actual_rows -= 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1607
                                skip_test = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1608
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1609
                elif dict_index == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1610
                    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1611
                        row_dict['note'] = replace_column_variables(column, 0)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1612
                    except ValueError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1613
                        log_screen('WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: note', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1614
                        log_screen("       : Defaulting to: 'TEST-" + str(row_line_number) + "'", 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1615
                        log_msg(the_output_file, 'WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: note')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1616
                        log_msg(the_output_file, "       : Defaulting to: 'TEST-" + str(row_line_number) + "'")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1617
                        line_errors += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1618
                        row_dict['note'] = 'TEST-' + str(row_line_number) + "' - Note"
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1619
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1620
                elif dict_index == 2:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1621
                    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1622
                        row_dict['timed'] = int(column)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1623
                    except ValueError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1624
                        log_screen('WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: timed', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1625
                        log_screen('       : Defaulting to: 0', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1626
                        log_msg(the_output_file, 'WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: timed')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1627
                        log_msg(the_output_file, '       : Defaulting to: 0')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1628
                        line_errors += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1629
                        row_dict['timed'] = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1630
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1631
                elif dict_index == 3:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1632
                    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1633
                        row_dict['display_output'] = int(column)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1634
                    except ValueError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1635
                        log_screen('WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: display_output', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1636
                        log_screen('       : Defaulting to: 0', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1637
                        log_msg(the_output_file, 'WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: display_output')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1638
                        log_msg(the_output_file, '       : Defaulting to: 0')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1639
                        line_errors += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1640
                        row_dict['display_output'] = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1641
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1642
                elif dict_index == 4:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1643
                    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1644
                        row_dict['store_output'] = int(column)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1645
                    except ValueError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1646
                        log_screen('WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: store_output', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1647
                        log_screen('       : Defaulting to: 0', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1648
                        log_msg(the_output_file, 'WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: store_output')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1649
                        log_msg(the_output_file, '       : Defaulting to: 0')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1650
                        line_errors += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1651
                        row_dict['store_output'] = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1652
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1653
                elif dict_index == 5:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1654
                    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1655
                        row_dict['command'] = replace_column_variables(column, 0)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1656
                    except ValueError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1657
                        log_screen('ERROR  : Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: command', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1658
                        log_screen('       : Id: ' + row_dict['test_id'] + ' - This test will NOT be executed', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1659
                        log_msg(the_output_file, 'ERROR  : Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: command')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1660
                        log_msg(the_output_file, '       : Id: ' + row_dict['test_id'] + ' - This test will NOT be executed')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1661
                        line_errors += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1662
                        row_dict['command'] = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1663
                        skip_test = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1664
                    # Don't count internal commands in the test count
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1665
                    if row_dict['command'].lower() == 'monty_restore_cwd' or row_dict['command'].lower().startswith('cd ') or row_dict['command'].lower().startswith('monty_set_env ') or row_dict['command'].lower().startswith('monty_set_compiler '):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1666
                        internal_command = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1667
                        internal_command_count += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1668
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1669
                elif dict_index == 6:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1670
                    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1671
                        if column != '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1672
                            column = replace_column_variables(column, 0)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1673
                            row_dict['targets'] = column.split(',')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1674
                        else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1675
                            row_dict['targets'] = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1676
                    except ValueError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1677
                        log_screen('WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: targets', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1678
                        log_screen("       : Defaulting to: '' (no targets)", 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1679
                        log_msg(the_output_file, 'WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: targets')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1680
                        log_msg(the_output_file, "       : Defaulting to: '' (no targets)")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1681
                        line_errors += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1682
                        row_dict['targets'] = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1683
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1684
                elif dict_index == 7:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1685
                    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1686
                        if column != '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1687
                            column = replace_column_variables(column, 0)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1688
                            row_dict['expected_output'] = column.split(',')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1689
                        else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1690
                            row_dict['expected_output'] = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1691
                    except ValueError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1692
                        log_screen('WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: expected_output', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1693
                        log_screen("       : Defaulting to: '' (no expected output)", 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1694
                        log_msg(the_output_file, 'WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: expected_output')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1695
                        log_msg(the_output_file, "       : Defaulting to: '' (no expected output)")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1696
                        line_errors += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1697
                        row_dict['expected_output'] = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1698
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1699
                elif dict_index == 8:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1700
                    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1701
                        exp_dict['missing'] = int(column)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1702
                    except ValueError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1703
                        log_screen('WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: missing', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1704
                        log_screen('       : Defaulting to: 0', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1705
                        log_msg(the_output_file, 'WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: missing')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1706
                        log_msg(the_output_file, '       : Defaulting to: 0')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1707
                        line_errors += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1708
                        row_dict['missing'] = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1709
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1710
                elif dict_index == 9:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1711
                    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1712
                        exp_dict['warnings'] = int(column)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1713
                    except ValueError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1714
                        log_screen('WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: warnings', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1715
                        log_screen('       : Defaulting to: 0', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1716
                        log_msg(the_output_file, 'WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: warnings')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1717
                        log_msg(the_output_file, '       : Defaulting to: 0')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1718
                        line_errors += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1719
                        row_dict['warnings'] = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1720
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1721
                elif dict_index == 10:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1722
                    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1723
                        exp_dict['errors'] = int(column)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1724
                    except ValueError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1725
                        log_screen('WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: errors', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1726
                        log_screen('       : Defaulting to: 0', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1727
                        log_msg(the_output_file, 'WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: errors')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1728
                        log_msg(the_output_file, '       : Defaulting to: 0')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1729
                        line_errors += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1730
                        row_dict['errors'] = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1731
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1732
                elif dict_index == 11:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1733
                    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1734
                        exp_dict['exceptions'] = int(column)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1735
                    except ValueError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1736
                        log_screen('WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: exceptions', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1737
                        log_screen('       : Defaulting to: 0', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1738
                        log_msg(the_output_file, 'WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: exceptions')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1739
                        log_msg(the_output_file, '       : Defaulting to: 0')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1740
                        line_errors += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1741
                        row_dict['exceptions'] = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1742
                    row_dict['expected'] = exp_dict
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1743
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1744
                elif dict_index == 12:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1745
                    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1746
                        row_dict['return_code'] = int(column)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1747
                    except ValueError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1748
                        log_screen('WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: return_code', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1749
                        log_screen('       : Defaulting to: 0', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1750
                        log_msg(the_output_file, 'WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: return_code')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1751
                        log_msg(the_output_file, '       : Defaulting to: 0')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1752
                        line_errors += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1753
                        row_dict['return_code'] = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1754
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1755
                elif dict_index == 13:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1756
                    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1757
                        row_dict['os_types'] = column
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1758
                    except ValueError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1759
                        log_screen('WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: os_types', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1760
                        log_screen("       : Defaulting to: 'uw' (both Unix and Windows)", 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1761
                        log_msg(the_output_file, 'WARNING: Invalid value in test suite CSV file, line: ' + str(row_line_number) + ', column: os_types')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1762
                        log_msg(the_output_file, "       : Defaulting to: 'uw' (both Unix and Windows)")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1763
                        line_errors += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1764
                        row_dict['os_types'] = 'uw'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1765
                    # Should this test be run?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1766
                    if override_os_types == '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1767
                        if not os_type[0:1] in column:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1768
                            skip_test = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1769
                            if internal_command == True:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1770
                                internal_command_count -= 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1771
                    elif override_os_types == 'u':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1772
                        if not 'u' in column:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1773
                            skip_test = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1774
                            if internal_command == True:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1775
                                internal_command_count -= 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1776
                    elif override_os_types == 'w':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1777
                        if not 'w' in column:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1778
                            skip_test = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1779
                            if internal_command == True:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1780
                                internal_command_count -= 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1781
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1782
                dict_index += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1783
                if dict_index == number_of_columns:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1784
                    dict_index = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1785
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1786
                    if row_dict['test_id'] == 'id':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1787
                        # Don't do anything with this row, because it's the header row, but Python makes us do something here
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1788
                        row_dict['test_id'] == 'id'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1789
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1790
                    elif job_section == '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1791
                        if run_test == '' and run_group_test == '' and not skip_test:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1792
                            tests_common.append(row_dict)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1793
                            if internal_command or row_dict['test_id'].endswith('#'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1794
                                skipped_rows += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1795
                                meta_test_step_id.append(row_dict['test_id'])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1796
                            if not internal_command and not row_dict['test_id'].endswith('#') and not row_dict['test_id'].lower().startswith('--job'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1797
                                rows += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1798
                                meta_test_case_id.append(row_dict['test_id'])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1799
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1800
                        elif run_test != '' and (row_dict['test_id'].lower() == run_test.lower() or row_dict['test_id'].lower() == run_test.lower() + '#' or row_dict['test_id'].lower() == run_test.lower() + '@') and not row_dict['test_id'].lower().startswith('--job') and not skip_test:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1801
                            tests_common = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1802
                            tests_common.append(row_dict)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1803
                            meta_test_step_id = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1804
                            if internal_command or row_dict['test_id'].endswith('#'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1805
                                skipped_rows += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1806
                                meta_test_step_id.append(row_dict['test_id'])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1807
                            meta_test_case_id = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1808
                            if not internal_command and not row_dict['test_id'].endswith('#') and not row_dict['test_id'].lower().startswith('--job'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1809
                                rows += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1810
                                meta_test_case_id.append(row_dict['test_id'])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1811
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1812
                        elif run_group_test != '' and row_dict['test_id'].lower().startswith(run_group_test.lower()) and not skip_test:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1813
                            tests_in_group += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1814
                            if not have_reset_tests_common:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1815
                                have_reset_tests_common = True
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1816
                                meta_test_step_id = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1817
                                meta_test_case_id = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1818
                                tests_common = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1819
                            tests_common.append(row_dict)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1820
                            if internal_command or row_dict['test_id'].endswith('#'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1821
                                skipped_rows += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1822
                                meta_test_step_id.append(row_dict['test_id'])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1823
                            if not internal_command and not row_dict['test_id'].endswith('#') and not row_dict['test_id'].lower().startswith('--job'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1824
                                rows += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1825
                                meta_test_case_id.append(row_dict['test_id'])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1826
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1827
                    else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1828
                        # We're running a job section
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1829
                        if run_test != '' and (row_dict['test_id'].lower() == run_test.lower() or row_dict['test_id'].lower() == run_test.lower() + '#' or row_dict['test_id'].lower() == run_test.lower() + '@') and not row_dict['test_id'].lower().startswith('--job') and not skip_test:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1830
                            if not row_dict in tests_common:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1831
                                tests_common.append(row_dict)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1832
                            if internal_command or row_dict['test_id'].endswith('#'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1833
                                skipped_rows += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1834
                                meta_test_step_id.append(row_dict['test_id'])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1835
                            if not internal_command and not row_dict['test_id'].endswith('#') and not row_dict['test_id'].lower().startswith('--job'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1836
                                rows += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1837
                                meta_test_case_id.append(row_dict['test_id'])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1838
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1839
                        elif run_group_test != '' and row_dict['test_id'].lower().startswith(run_group_test.lower()) and not skip_test:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1840
                            tests_in_group += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1841
                            tests_common.append(row_dict)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1842
                            if internal_command or row_dict['test_id'].endswith('#'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1843
                                skipped_rows += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1844
                                meta_test_step_id.append(row_dict['test_id'])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1845
                            if not internal_command and not row_dict['test_id'].endswith('#') and not row_dict['test_id'].lower().startswith('--job'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1846
                                rows += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1847
                                meta_test_case_id.append(row_dict['test_id'])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1848
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1849
                        elif in_job_section and not row_dict['test_id'].lower().startswith('--job') and not skip_test:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1850
                            if not row_dict in tests_common:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1851
                                tests_common.append(row_dict)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1852
                            if internal_command or row_dict['test_id'].endswith('#'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1853
                                skipped_rows += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1854
                                meta_test_step_id.append(row_dict['test_id'])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1855
                            if not internal_command and not row_dict['test_id'].endswith('#') and not row_dict['test_id'].lower().startswith('--job'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1856
                                rows += 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1857
                                meta_test_case_id.append(row_dict['test_id'])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1858
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1859
    if line_errors > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1860
        log_screen('*' * line_dash_count, 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1861
        if line_errors == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1862
            csv_errors = 'was one error'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1863
            csv_errors_2 = ' has'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1864
        elif line_errors > 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1865
            csv_errors = 'were ' + str(line_errors)+ ' errors'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1866
            csv_errors_2 = 's have'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1867
        log_screen('WARNING: There ' + csv_errors + ' recorded in the CSV test suite.', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1868
        log_screen('       : You should check that the test case' + csv_errors_2 +' been executed correctly.', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1869
        log_screen('*' * line_dash_count, 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1870
        log_screen('', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1871
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1872
    if len(tests_common) == 0 and skipped_rows == 0 and job_section == '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1873
        log_screen(' ERROR: Found no executable tests in the test suite.', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1874
        log_screen(' Automated test execution abandoned.', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1875
        log_screen(line_separator, 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1876
        log_msg(the_output_file, ' Found no executable tests in the test suite.')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1877
        log_msg(the_output_file, ' Automated test execution abandoned.')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1878
        log_msg(the_output_file, line_separator + "\n")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1879
        sys.exit(monty_returncode_if_test_suite_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1880
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1881
    test_cases = len(meta_test_case_id)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1882
    test_steps = len(meta_test_step_id)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1883
    total_tests = test_cases + test_steps
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1884
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1885
    #print 'rows: ' + str(rows)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1886
    #print 'skipped_rows: ' + str(skipped_rows)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1887
    #print 'len of tests_common: ' + str(len(tests_common))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1888
    #print 'actual_rows: ' + str(actual_rows)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1889
    #print "test_cases = " + str(test_cases)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1890
    #print "test_steps = " + str(test_steps)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1891
    #print "total_tests = " + str(total_tests)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1892
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1893
    nice_test_cases = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1894
    if test_cases == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1895
        nice_test_cases = '1 test case'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1896
    elif test_cases > 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1897
        nice_test_cases = str(test_cases) + ' test cases'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1898
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1899
    nice_test_steps = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1900
    if test_steps == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1901
        nice_test_steps = '1 test step'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1902
    elif test_steps > 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1903
        nice_test_steps = str(test_steps) + ' test steps'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1904
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1905
    test_cases_and = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1906
    if test_cases > 0 and test_steps > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1907
        test_cases_and = ' and '
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1908
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1909
    nice_test_cases_count = str(nice_test_cases) + test_cases_and + nice_test_steps
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1910
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1911
    if run_test != '' and job_section == '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1912
        total_tests = 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1913
        log_screen(' Found ' + nice_test_cases_count + " in the test suite.\n Will execute only test: '" + run_test + "'.", '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1914
        log_msg(the_output_file, ' Found ' + nice_test_cases_count + " in the test suite.\n Will execute only test: '" + run_test + "'.")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1915
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1916
        if not found_run_test:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1917
            log_screen('', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1918
            log_screen(" ERROR: Could not locate the test '" + run_test + "' in the test suite.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1919
            log_screen(" Automated test execution abandoned.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1920
            log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1921
            log_msg(the_output_file, " ERROR: Could not locate the test '" + run_test + "' in the test suite.")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1922
            log_msg(the_output_file, " Automated test execution abandoned.")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1923
            log_msg(the_output_file, line_separator)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1924
            sys.exit(monty_returncode_if_test_suite_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1925
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1926
        log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1927
        log_msg(the_output_file, line_separator + "\n")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1928
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1929
    elif run_group_test != '' and job_section == '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1930
        # Go through the tests and get a count of the tests that match
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1931
        total_tests = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1932
        for current_test in tests_common:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1933
            if current_test['test_id'].lower().startswith(run_group_test.lower()):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1934
                total_tests = total_tests + 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1935
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1936
        nice_test_count = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1937
        if total_tests > 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1938
            nice_test_count = 's'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1939
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1940
        log_screen(' Found ' + nice_test_cases_count + " in the test suite.\n Will execute only tests beginning with: '" + run_group_test + "' (" + str(total_tests) + ' test' + nice_test_count + ' or step' + nice_test_count + ').', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1941
        log_msg(the_output_file, ' Found ' + nice_test_cases_count + " in the test suite.\n Will execute only tests beginning with: '" + run_group_test + "' (" + str(total_tests) + ' test' + nice_test_count + ' or step' + nice_test_count + ').')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1942
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1943
        if not found_run_group_test:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1944
            log_screen('', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1945
            log_screen(" ERROR: Could not locate tests beginning with '" + run_group_test + "' in the test suite.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1946
            log_screen(" Automated test execution abandoned.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1947
            log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1948
            log_msg(the_output_file, " ERROR: Could not locate tests beginning with '" + run_group_test + "' in the test suite.")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1949
            log_msg(the_output_file, " Automated test execution abandoned.")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1950
            log_msg(the_output_file, line_separator)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1951
            sys.exit(monty_returncode_if_test_suite_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1952
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1953
        log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1954
        log_msg(the_output_file, line_separator + "\n")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1955
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1956
    elif job_section != '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1957
        nice_test_count = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1958
        if found_job_section == False:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1959
            # Couldn't find the job section
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1960
            log_screen('', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1961
            log_screen(" ERROR: Could not locate job section '" + job_section + "' in the test suite.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1962
            log_screen(" Automated test execution abandoned.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1963
            log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1964
            log_msg(the_output_file, " ERROR: Could not locate job section '" + job_section + "' in the test suite.")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1965
            log_msg(the_output_file, " Automated test execution abandoned.")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1966
            log_msg(the_output_file, line_separator)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1967
            sys.exit(monty_returncode_if_test_suite_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1968
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1969
        if run_group_test == '' and run_test == '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1970
            # We're only running a job section
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1971
            log_screen(' Found ' + nice_test_cases_count + " in the test suite.\n Will execute job section: '" + job_section + "'", '')#"' (" + str(total_tests) + ' test' + nice_test_count + ' or step' + nice_test_count + ').', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1972
            log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1973
            log_msg(the_output_file, ' Found ' + nice_test_cases_count + " in the test suite.\n Will execute job section: '" + job_section + "'")#"' (" + str(total_tests) + ' test' + nice_test_count + ' or step' + nice_test_count + ').')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1974
            log_msg(the_output_file, line_separator + "\n")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1975
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1976
        elif run_group_test != '' and run_test == '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1977
            # We're running a job section and a group of tests
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1978
            log_screen(' Found ' + nice_test_cases_count + " in the test suite.\n Will execute job section: '" + job_section + "'", '')#"' (" + str(total_tests) + ' test' + nice_test_count + ' or step' + nice_test_count + ').', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1979
            log_msg(the_output_file, ' Found ' + nice_test_cases_count + " in the test suite.\n Will execute job section: '" + job_section + "'")#"' (" + str(total_tests) + ' test' + nice_test_count + ' or step' + nice_test_count + ').')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1980
            if found_run_group_test:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1981
                log_screen(" Will also execute tests beginning with: '" + run_group_test + "'", '')#"' (" + str(tests_in_group) + ' test' + nice_group_test_count + ' or step' + nice_group_test_count + ').', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1982
                log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1983
                log_msg(the_output_file, " Will also execute tests beginning with: '" + run_group_test + "'")#"' (" + str(tests_in_group) + ' test' + nice_group_test_count + ' or step' + nice_group_test_count + ').')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1984
                log_msg(the_output_file, line_separator + "\n")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1985
            else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1986
                log_screen(" ERROR: Could not locate tests beginning with: '" + run_group_test + "' in the test suite.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1987
                log_screen(" Automated test execution abandoned.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1988
                log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1989
                log_msg(the_output_file, " ERROR: Could not locate tests beginning with: '" + run_group_test + "' in the test suite.")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1990
                log_msg(the_output_file, " Automated test execution abandoned.")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1991
                log_msg(the_output_file, line_separator)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1992
                sys.exit(monty_returncode_if_test_suite_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1993
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1994
        elif run_group_test == '' and run_test != '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1995
            # We're running a job section and a single test
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1996
            log_screen(' Found ' + nice_test_cases_count + " in the test suite.\n Will execute job section: '" + job_section + "'", '')#"' (" + str(total_tests) + ' test' + nice_test_count + ' or step' + nice_test_count + ').', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1997
            log_msg(the_output_file, ' Found ' + nice_test_cases_count + " in the test suite.\n Will execute job section: '" + job_section + "'")#"' (" + str(total_tests) + ' test' + nice_test_count + ' or step' + nice_test_count + ').')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1998
            if found_run_test:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  1999
                log_screen(" Will also execute the test case: '" + run_test + "'", '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2000
                log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2001
                log_msg(the_output_file, " Will also execute the test: '" + run_test + "'")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2002
                log_msg(the_output_file, line_separator + "\n")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2003
            else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2004
                log_screen(" ERROR: Could not locate the test '" + run_test + "' in the test suite.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2005
                log_screen(" Automated test execution abandoned.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2006
                log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2007
                log_msg(the_output_file, " ERROR: Could not locate the test '" + run_test + "' in the test suite.")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2008
                log_msg(the_output_file, " Automated test execution abandoned.")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2009
                log_msg(the_output_file, line_separator)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2010
                sys.exit(monty_returncode_if_test_suite_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2011
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2012
    else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2013
        log_screen(' Found ' + nice_test_cases_count + ' in the test suite. Commencing execution...', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2014
        log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2015
        log_msg(the_output_file, ' Found ' + nice_test_cases_count + ' in the test suite. Commencing execution...')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2016
        log_msg(the_output_file, line_separator)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2017
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2018
    return tests_common
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2019
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2020
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2021
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2022
def show_error(resource, reason, file_handle, exit_app):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2023
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2024
    This module shows an error and, optionally, stops execution of Monty.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2025
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2026
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2027
    if resource != '' and resource != 'MONTY_END_IF_FAILED':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2028
        log_screen(" ERROR: Error accessing the file/directory: '" + resource + "' because:", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2029
    elif resource == 'MONTY_END_IF_FAILED':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2030
        log_screen(" ERROR: The following required test case/step failed:", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2031
    else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2032
        log_screen(" ERROR:", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2033
    log_screen(' ' + str(reason) + "\n", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2034
    log_screen(' Automated test execution failed.', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2035
    log_screen(line_separator, 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2036
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2037
    if store_all_output == 1 and file_handle != None:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2038
        log_msg(file_handle, " ERROR: Error accessing the file/directory: '" + resource + "' because:")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2039
        log_msg(file_handle, ' ' + str(reason) + "\n")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2040
        log_msg(file_handle, ' Automated test execution failed.')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2041
        log_msg(file_handle, line_separator)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2042
        file_handle.close()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2043
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2044
	# Close and rename the output files
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2045
        old_filename = output_log_path + d.strftime("%Y-%m-%d_%H-%M-%S") + usage_slashes + d.strftime("%Y-%m-%d_%H-%M-%S") + '_output_IN_PROGRESS.txt'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2046
        new_filename = output_log_path + d.strftime("%Y-%m-%d_%H-%M-%S") + usage_slashes + d.strftime("%Y-%m-%d_%H-%M-%S") + '_output_ERROR.txt'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2047
        if os.path.exists(old_filename):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2048
            try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2049
                os.rename(old_filename, new_filename)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2050
                log_screen("INFO: The output file has been renamed to: '" + new_filename + "'", '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2051
            except OSError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2052
                log_screen("WARNING: Couldn't rename the output log file from: '" + old_filename + "' to '" + new_filename + "'.", 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2053
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2054
        if store_csv_results == 1 and csv_results_file != None:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2055
            csv_results_file.close()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2056
            old_filename = output_log_path + d.strftime("%Y-%m-%d_%H-%M-%S") + usage_slashes + d.strftime("%Y-%m-%d_%H-%M-%S") + '_results_IN_PROGRESS.csv'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2057
            new_filename = output_log_path + d.strftime("%Y-%m-%d_%H-%M-%S") + usage_slashes + d.strftime("%Y-%m-%d_%H-%M-%S") + '_results_ERROR.csv'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2058
            if os.path.exists(old_filename):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2059
                try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2060
                    os.rename(old_filename, new_filename)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2061
                    log_screen("INFO: The csv results file has been renamed to: '" + new_filename + "'", '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2062
                except OSError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2063
                    log_screen("WARNING: Couldn't rename the CSV results file from: '" + old_filename + "' to '" + new_filename + "'.", 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2064
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2065
    if exit_app > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2066
        sys.exit(exit_app)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2067
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2068
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2069
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2070
def log_msg(file_handle, the_text):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2071
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2072
    This module simply writes out a message to the log file, if appropriate.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2073
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2074
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2075
    if store_all_output == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2076
        try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2077
            file_handle.write(the_text + "\n")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2078
        except IOError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2079
            log_screen("WARNING: Couldn't write to the log file.", 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2080
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2081
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2082
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2083
def log_msg_if_exists(file_handle, the_text, store_output, output_file_exists):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2084
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2085
    This module simply writes out a message to the log file, if it exists.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2086
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2087
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2088
    if store_output == 1 and output_file_exists:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2089
        try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2090
            file_handle.write(the_text + "\n")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2091
        except IOError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2092
            log_screen("WARNING: Couldn't write to the log file for this test case.", 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2093
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2094
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2095
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2096
def centre_line_niceness(the_string, the_char, max_size):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2097
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2098
    This module simply returns a niced-up string with repeated chars to either
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2099
    side.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2100
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2101
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2102
    str_length = len(the_string)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2103
    if str_length >= max_size:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2104
        return the_string
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2105
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2106
    str_sides = (max_size - str_length) / 2
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2107
    nice_string = (the_char * str_sides) + the_string + (the_char * str_sides)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2108
    if len(nice_string) < max_size:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2109
        nice_string = nice_string + the_char
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2110
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2111
    return nice_string
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2112
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2113
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2114
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2115
def zipdir(the_zip_path, zip_file):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2116
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2117
    This module zips up the provided directory.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2118
    """
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2119
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2120
    for each_file in os.listdir(the_zip_path):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2121
        try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2122
            zip_file.write(the_zip_path + each_file)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2123
        except IOError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2124
            log_screen("ERROR: Couldn't zip the results.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2125
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2126
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2127
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2128
################################################################################
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2129
# MAIN
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2130
################################################################################
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2131
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2132
# Check that the required command line options have been entered
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2133
if path == '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2134
    path = original_cwd + usage_slashes
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2135
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2136
if execute_file == '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2137
    log_screen('Monty ' + str(monty_version) + ' - Type monty.py -h for usage', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2138
    log_screen('ERROR: You must supply a test suite CSV file (-e)', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2139
    sys.exit(monty_returncode_if_config_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2140
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2141
if output_log_path == '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2142
    log_screen('Monty ' + str(monty_version) + ' - Type monty.py -h for usage', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2143
    log_screen('ERROR: You must supply a path for the logs (-l)', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2144
    sys.exit(monty_returncode_if_config_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2145
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2146
if os_type != 'unix' and os_type != 'windows':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2147
    log_screen('Monty ' + str(monty_version) + ' - Type monty.py -h for usage', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2148
    log_screen('WARNING: Unknown OS type! Will assume Unix-style pathnames...', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2149
    os_type = 'unix'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2150
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2151
# Correct the paths used in the commands
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2152
if ':' in unix_path:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2153
    unix_path = unix_path.replace('\\', '/')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2154
    unix_path = unix_path.replace(':', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2155
    unix_path = '/' + unix_path[0].lower() + unix_path[1:]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2156
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2157
if '\\' in unix_test_path or ':' in unix_test_path:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2158
    unix_test_path = unix_test_path.replace('\\', '/')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2159
    unix_test_path = unix_test_path.replace(':', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2160
    unix_test_path = unix_test_path[0].lower() + unix_test_path[1:]
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2161
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2162
#if not win_path.endswith('\\'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2163
#    win_path = win_path + '\\'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2164
if win_test_path:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2165
	if not win_test_path.endswith('\\'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2166
		win_test_path = win_test_path + '\\'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2167
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2168
if not unix_path.endswith('/'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2169
    unix_path = unix_path + '/'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2170
if not unix_test_path.endswith('/'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2171
    unix_test_path = unix_test_path + '/'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2172
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2173
# Check the regular expressions for the warnings, errors and tracebacks
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2174
try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2175
    logFileRegex = re.compile(log_file_output_name)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2176
except re.error:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2177
    log_screen(' Monty ' + str(monty_version) + ' - Type monty.py -h for usage', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2178
    log_screen(" ERROR: The regular expression used for the 'log_file_output_name' variable is invalid. Check your '..._cfg.py' file.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2179
    sys.exit(monty_returncode_if_config_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2180
try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2181
    determine_warning_Regex = re.compile(determine_warning)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2182
except re.error:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2183
    log_screen(' Monty ' + str(monty_version) + ' - Type monty.py -h for usage', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2184
    log_screen(" ERROR: The regular expression used for the 'determine_warning' variable is invalid. Check your '..._cfg.py' file.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2185
    sys.exit(monty_returncode_if_config_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2186
try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2187
    determine_warning_in_log_Regex = re.compile(determine_warning_in_log)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2188
except re.error:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2189
    log_screen(' Monty ' + str(monty_version) + ' - Type monty.py -h for usage', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2190
    log_screen(" ERROR: The regular expression used for the 'determine_warning_in_log' variable is invalid. Check your '..._cfg.py' file.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2191
    sys.exit(monty_returncode_if_config_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2192
try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2193
    determine_error_Regex = re.compile(determine_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2194
except re.error:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2195
    log_screen(' Monty ' + str(monty_version) + ' - Type monty.py -h for usage', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2196
    log_screen(" ERROR: The regular expression used for the 'determine_error' variable is invalid. Check your '..._cfg.py' file.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2197
    sys.exit(monty_returncode_if_config_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2198
try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2199
    determine_error_in_log_Regex = re.compile(determine_error_in_log)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2200
except re.error:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2201
    log_screen(' Monty ' + str(monty_version) + ' - Type monty.py -h for usage', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2202
    log_screen(" ERROR: The regular expression used for the 'determine_error_in_log' variable is invalid. Check your '..._cfg.py' file.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2203
    sys.exit(monty_returncode_if_config_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2204
try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2205
    determine_traceback_Regex = re.compile(determine_traceback)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2206
except re.error:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2207
    log_screen(' Monty ' + str(monty_version) + ' - Type monty.py -h for usage', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2208
    log_screen(" ERROR: The regular expression used for the 'determine_traceback' variable is invalid. Check your '..._cfg.py' file.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2209
    sys.exit(monty_returncode_if_config_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2210
if determine_traceback == 'dna':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2211
    display_stuff()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2212
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2213
# Check to see if the group and individual test choices have both been set
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2214
if run_test != '' and run_group_test != '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2215
    log_screen(' Monty ' + str(monty_version) + ' - Type monty.py -h for usage', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2216
    log_screen(' ERROR: Cannot use both the -g and -r command line options at the same time.', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2217
    sys.exit(monty_returncode_if_config_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2218
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2219
# Display the settings
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2220
current_mode = 'header'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2221
d = datetime.datetime.now()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2222
d.isoformat()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2223
log_screen("\n" + line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2224
log_screen(' Monty ' + str(monty_version) + ' - Automated test suite execution for ' + d.strftime("%Y-%m-%d %H:%M:%S") + ' commencing...', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2225
log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2226
log_screen(' Using definitions:', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2227
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2228
log_screen('               OS type = ' + os_type, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2229
log_screen('            Test suite = ' + execute_file + using_defaults[2], '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2230
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2231
if os_type == 'windows':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2232
    log_screen('                  Path = ' + win_path + using_defaults[0], '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2233
    log_screen('             Test path = ' + win_test_path + using_defaults[1], '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2234
else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2235
    log_screen('                  Path = ' + unix_path + using_defaults[0], '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2236
    log_screen('             Test path = ' + unix_test_path + using_defaults[1], '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2237
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2238
if store_all_output == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2239
    log_screen('        Storing output = Yes' + using_defaults[3], '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2240
else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2241
    log_screen('        Storing output = No' + using_defaults[3], '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2242
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2243
if store_csv_results == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2244
    log_screen('   Storing CSV results = Yes' + using_defaults[6], '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2245
else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2246
    log_screen('   Storing CSV results = No' + using_defaults[6], '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2247
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2248
if copy_log == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2249
    log_screen(' Copying make logfiles = Yes' + using_defaults[7], '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2250
else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2251
    log_screen(' Copying make logfiles = No' + using_defaults[7], '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2252
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2253
log_screen('       Output log path = ' + output_log_path + using_defaults[4], '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2254
log_screen(" Internal error string = '" + internal_error_string + "'" + using_defaults[5], '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2255
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2256
if run_test != '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2257
    log_screen("     Running only test = '" + run_test + "'", '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2258
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2259
if run_group_test != '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2260
    log_screen("    Running test group = '" + run_group_test + "'...", '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2261
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2262
if monty_config_py != '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2263
    log_screen(' Using external config = ' + monty_config_py, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2264
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2265
if override_os_types != '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2266
    log_screen('    Overriding OS type = Yes: running ' + override_os_types_dict[override_os_types] + ' tests' + using_defaults[8], '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2267
else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2268
    log_screen('    Overriding OS type = No: running ' + override_os_types_dict[os_type[0:1]] + ' tests' + using_defaults[8], '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2269
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2270
if timeout_secs > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2271
    log_screen('   Tests timeout after = ' + str(timeout_secs) + ' seconds', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2272
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2273
log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2274
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2275
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2276
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2277
# Check to see if the output log path exists
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2278
current_mode = 'logs'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2279
if not os.path.exists(output_log_path):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2280
    show_error(output_log_path, 'The output log path does not exist', None, monty_returncode_if_file_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2281
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2282
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2283
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2284
# Set up some variables
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2285
passed = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2286
script_time_taken = 0.0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2287
total_time_taken = 0.0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2288
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2289
# Create lists to store failed test case and step ids
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2290
failures = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2291
internal_error_failures = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2292
skipped_test_failures = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2293
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2294
# Create a log directory?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2295
if store_all_output == 1 or store_csv_results == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2296
    # Check to see if the path to the log directory exists
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2297
    if not os.path.exists(output_log_path):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2298
        log_screen("ERROR: The path to the logs directory doesn't exist - '" + output_log_path + "'.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2299
        log_screen("       Logs will be produced in: '" + path + "' instead.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2300
        output_log_path = path
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2301
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2302
    log_dir = output_log_path + d.strftime("%Y-%m-%d_%H-%M-%S")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2303
    # Increment the filename if it already exists
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2304
    if os.path.exists(log_dir):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2305
        log_dir_name_count = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2306
        while os.path.exists(log_dir + '_' + str(log_dir_name_count)):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2307
            log_dir_name_count = log_dir_name_count + 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2308
        log_dir = log_dir + '_' + str(log_dir_name_count)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2309
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2310
    # Make the directory
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2311
    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2312
        os.mkdir(log_dir)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2313
        log_dir = log_dir + usage_slashes
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2314
    except IOError,e:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2315
        log_screen(" ERROR: Error creating the log directory: '" + log_dir + "' because:\n " + e.strerror, 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2316
        log_screen(" INFO: Log results will be written in: '" + output_log_path + "'.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2317
        log_dir = output_log_path
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2318
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2319
# Redirect all output to a log file?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2320
if store_all_output == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2321
    log_screen(' Copying all output to file:', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2322
    log_screen(' ' + log_dir + d.strftime("%Y-%m-%d_%H-%M-%S") + '_output_IN_PROGRESS.txt', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2323
    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2324
        the_output_file = open(log_dir + d.strftime("%Y-%m-%d_%H-%M-%S") + '_output_IN_PROGRESS.txt', 'wt')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2325
    except IOError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2326
        log_screen(" ERROR: Couldn't create a log file for this test run.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2327
        log_screen(' Automated test execution failed.', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2328
        sys.exit(monty_returncode_if_file_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2329
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2330
    log_msg(the_output_file, line_separator)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2331
    log_msg(the_output_file, ' Monty ' + str(monty_version) + ' - Automated test output')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2332
    log_msg(the_output_file, line_separator)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2333
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2334
    log_msg(the_output_file, ' Using definitions:')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2335
    log_msg(the_output_file, '               OS type = ' + os_type)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2336
    log_msg(the_output_file, '            Test suite = ' + execute_file + using_defaults[2])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2337
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2338
    if os_type == 'windows':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2339
        log_msg(the_output_file, '                  Path = ' + win_path + using_defaults[0])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2340
        log_msg(the_output_file, '             Test path = ' + win_test_path + using_defaults[1])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2341
    else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2342
        log_msg(the_output_file, '                  Path = ' + unix_path + using_defaults[0])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2343
        log_msg(the_output_file, '             Test path = ' + unix_test_path + using_defaults[1])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2344
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2345
    log_msg(the_output_file, '        Storing output = Yes' + using_defaults[3])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2346
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2347
    if store_csv_results == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2348
        log_msg(the_output_file, '   Storing CSV results = Yes' + using_defaults[6])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2349
    else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2350
        log_msg(the_output_file, '   Storing CSV results = No' + using_defaults[6])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2351
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2352
    if copy_log == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2353
        log_msg(the_output_file, ' Copying make logfiles = Yes' + using_defaults[7])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2354
    else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2355
        log_msg(the_output_file, ' Copying make logfiles = No' + using_defaults[7])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2356
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2357
    log_msg(the_output_file, '       Output log path = ' + output_log_path + using_defaults[4])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2358
    log_msg(the_output_file, " Internal error string = '" + internal_error_string + "'" + using_defaults[5])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2359
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2360
    if run_test != '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2361
        log_msg(the_output_file, "     Running only test = '" + run_test + "'")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2362
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2363
    if run_group_test != '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2364
        log_msg(the_output_file, "    Running test group = '" + run_group_test + "'...")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2365
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2366
    if monty_config_py != '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2367
        log_msg(the_output_file, ' Using external config = ' + monty_config_py)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2368
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2369
    if override_os_types != '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2370
        log_msg(the_output_file, '    Overriding OS type = Yes: running ' + override_os_types_dict[override_os_types] + ' tests' + using_defaults[8])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2371
    else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2372
        log_msg(the_output_file, '    Overriding OS type = No: running ' + override_os_types_dict[os_type[0:1]] + ' tests' + using_defaults[8])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2373
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2374
    if timeout_secs > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2375
        log_msg(the_output_file, '   Tests timeout after = ' + str(timeout_secs) + ' seconds')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2376
    log_msg(the_output_file, line_separator)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2377
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2378
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2379
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2380
current_mode = 'test_suite'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2381
# Open the test file to execute
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2382
if not os.path.exists(execute_file):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2383
    csv_results_file = None
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2384
    show_error(execute_file, 'The test suite csv file does not exist', the_output_file, monty_returncode_if_file_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2385
else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2386
    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2387
        execute_file_handle = csv.reader(open(execute_file, 'rb'))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2388
    except IOError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2389
        log_screen(" ERROR: Error accessing the file/directory: '" + execute_file + "' because:", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2390
        log_screen(' The csv file with the tests to execute does not exist.', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2391
        log_screen(' Automated test execution failed.', 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2392
        if store_all_output == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2393
            log_msg(the_output_file, " ERROR: Error accessing the file/directory: '" + execute_file + "' because:")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2394
            log_msg(the_output_file, ' The csv file with the tests to execute does not exist.')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2395
            log_msg(the_output_file, ' Automated test execution failed.')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2396
            log_msg(the_output_file, line_separator)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2397
        sys.exit(monty_returncode_if_file_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2398
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2399
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2400
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2401
# Save results to a CSV file?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2402
if store_csv_results == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2403
    log_screen(' Storing test results in CSV file:', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2404
    log_screen(' ' + log_dir + d.strftime("%Y-%m-%d_%H-%M-%S") + '_results_IN_PROGRESS.csv', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2405
    csv_results_file = open(log_dir + d.strftime("%Y-%m-%d_%H-%M-%S") + '_results_IN_PROGRESS.csv', 'wt')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2406
    csv_results_file.write("TestCaseId,StartTime,EndTime,Result\n")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2407
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2408
if store_all_output == 1 or store_csv_results == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2409
    log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2410
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2411
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2412
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2413
# Get the tests and put them into the 'theTests' list
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2414
current_mode = 'get_tests'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2415
internal_command_count = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2416
test_cases = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2417
test_steps = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2418
total_tests = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2419
current_test_number = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2420
# Create lists to store the meta data
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2421
meta_test_step_id = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2422
meta_test_case_id = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2423
meta_tests_in_job_section = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2424
meta_test_step_executed = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2425
meta_test_case_executed = []
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2426
# Get the tests
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2427
theTests = get_tests(execute_file_handle)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2428
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2429
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2430
################################################################################
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2431
# RUN THE TESTS
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2432
################################################################################
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2433
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2434
current_mode = 'run_tests'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2435
if output_mode == 3:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2436
    log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2437
    log_screen('Monty ' + str(monty_version) + ' - Automated test suite execution for ' + d.strftime("%Y-%m-%d %H:%M:%S") + ' commencing...', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2438
    log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2439
skipped = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2440
skipped_count = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2441
tests_not_counted = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2442
prev_test_id = ''
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2443
prev_test_failed = False
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2444
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2445
# Start the timer
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2446
script_start_time = time.time()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2447
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2448
# Run each test
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2449
for test in theTests:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2450
    # Execute the test
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2451
    test_success = run_a_test(test)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2452
    # Determine the success or failure
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2453
    if test_success == 'FALSE-STEP':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2454
        # If the function returns "FALSE-STEP", this is a step and it failed.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2455
        # Although it was executed, it doesn't contribute to the results
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2456
        skipped_test_failures.append(test['test_id'])
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2457
        skipped_count = skipped_count + 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2458
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2459
    if test_success != 'SKIP' and test_success != 'FALSE-INTERNAL_ERROR' and test['test_id'].endswith('#'):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2460
        tests_not_counted = tests_not_counted + 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2461
    elif test_success == 'TRUE':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2462
        passed = passed + 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2463
    elif test_success == 'SKIP' and run_group_test != '':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2464
        skipped = skipped + 1
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2465
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2466
    # If the function returns "FALSE-INTERNAL_ERROR", the test failed due to
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2467
    # an internal error. Should not contribute to the results.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2468
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2469
    # If the function returns "SKIP", the test was commented out in the
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2470
    # test suite and doesn't contribute to the results.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2471
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2472
    # If the previous test failed, we have to end the loop and exit Monty.
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2473
    if prev_test_failed and test['test_id'].lower() == 'monty_end_if_failed':
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2474
        show_error('MONTY_END_IF_FAILED', "'" + prev_test_id + "'. Monty will now exit.", the_output_file, monty_returncode_if_test_failure_conditional)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2475
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2476
# End the timer and calculate the script time taken
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2477
script_end_time = time.time()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2478
script_time_taken = script_end_time - script_start_time
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2479
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2480
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2481
################################################################################
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2482
# CALCULATE THE RESULTS
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2483
################################################################################
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2484
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2485
# Calculate the final values and display them
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2486
current_mode = 'results'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2487
passed_calc = passed + 0.0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2488
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2489
test_count = len(meta_test_case_executed)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2490
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2491
if test_count <= 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2492
    test_count = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2493
    pc_calculation = 0.0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2494
else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2495
    pc_calculation = passed_calc / (test_count + 0.0)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2496
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2497
monty_returncode = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2498
log_screen('', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2499
if output_mode == 4:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2500
    log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2501
    log_screen('Monty ' + str(monty_version) + ' - Automated test suite execution results for ' + d.strftime("%Y-%m-%d %H:%M:%S") + '...', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2502
log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2503
log_screen(str("  SCRIPT TIME : %.2f" % (script_time_taken, )) + ' seconds', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2504
log_screen(str("  TIMED TESTS : %.2f" % (total_time_taken, )) + ' seconds', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2505
log_screen(' TESTS PASSED : ' + str(passed) + ' / ' + str(test_count) + (" : %.2f" % (pc_calculation * (100 + 0.0), )) + ' percent', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2506
log_msg(the_output_file, "\n" + line_separator)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2507
log_msg(the_output_file, str("  SCRIPT TIME : %.2f" % (script_time_taken, )) + ' seconds')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2508
log_msg(the_output_file, str("  TIMED TESTS : %.2f" % (total_time_taken, )) + ' seconds')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2509
log_msg(the_output_file, ' TESTS PASSED : ' + str(passed) + ' / ' + str(test_count) + str(": %.2f" % (pc_calculation * (100 + 0.0), )) + ' percent')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2510
if test_count == 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2511
    monty_returncode = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2512
    log_screen('              : There were no test cases that returned a result', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2513
    log_msg(the_output_file, '              : There were no test cases that returned a result')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2514
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2515
# Did all tests pass?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2516
zip_results_type = '_tests_'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2517
if passed == test_count:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2518
    monty_returncode = 0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2519
    if skipped_count == 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2520
        if test_count > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2521
            filename_result = '_ALL_PASSED'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2522
            log_screen('', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2523
            log_screen(' *** Congratulations! All tests passed ***', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2524
            log_msg(the_output_file, "\n *** Congratulations! All tests passed ***")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2525
        else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2526
            filename_result = '_ALL_STEPS_PASSED'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2527
            log_screen('', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2528
            log_screen(' *** All test steps passed. There were no test cases. ***', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2529
            log_msg(the_output_file, "\n *** All test steps passed. There were no test cases. ***")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2530
            zip_results_type = '_steps_'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2531
            test_count = total_tests
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2532
            pc_calculation = 1.0
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2533
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2534
    if len(skipped_test_failures) > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2535
        monty_returncode = monty_returncode_if_test_failure
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2536
        filename_result = '_SOME_STEP_FAILURES'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2537
        log_screen("\n Some steps failed and may have affected the results:", 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2538
        log_msg(the_output_file, "\n Some steps failed and may have affected the results:")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2539
        for skipped_step in range(0, len(skipped_test_failures)):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2540
            log_screen(' ' + skipped_test_failures[skipped_step], 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2541
            log_msg(the_output_file, ' ' + str(skipped_test_failures[skipped_step]))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2542
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2543
    if len(internal_error_failures) > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2544
        monty_returncode = monty_returncode_if_test_failure
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2545
        filename_result = '_PASSED_WITH_INTERNAL_ERRORS'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2546
        log_screen(line_separator, 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2547
        log_screen(' WARNING: ' + str(len(internal_error_failures)) + ' internal error(s) encountered. Please investigate the following:', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2548
        log_msg(the_output_file, line_separator)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2549
        log_msg(the_output_file, ' WARNING: ' + str(len(internal_error_failures)) + ' internal error(s) encountered. Please investigate the following:')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2550
        for failed_test in range(0, len(internal_error_failures)):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2551
            log_screen(' ' + internal_error_failures[failed_test], 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2552
            log_msg(the_output_file, ' ' + str(internal_error_failures[failed_test]))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2553
else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2554
    # Some tests failed
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2555
    monty_returncode = monty_returncode_if_test_failure
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2556
    log_screen(line_separator, 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2557
    log_msg(the_output_file, line_separator + "\n")
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2558
    filename_result = '_SOME_FAILURES'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2559
    if len(failures) > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2560
        if len(failures) == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2561
            nice_failures = ' test or step has'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2562
        else:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2563
            nice_failures = ' tests or steps have'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2564
        log_screen('', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2565
        log_screen(' WARNING: ' + str(len(failures)) + nice_failures + ' failed. Please investigate the following: (id --- note)', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2566
        log_msg(the_output_file, ' WARNING: ' + str(len(failures)) + nice_failures + ' failed. Please investigate the following: (id --- note)')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2567
        for failed_test in range(0, len(failures)):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2568
            log_screen(' ' + failures[failed_test], 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2569
            log_msg(the_output_file, ' ' + str(failures[failed_test]))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2570
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2571
    # Any internal errors?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2572
    if len(internal_error_failures) > 0:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2573
        filename_result = '_SOME_FAILURES_AND_INTERNAL_ERRORS'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2574
        nice_failures = ' was'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2575
        if len(failures) > 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2576
            nice_failures = 's were'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2577
        log_screen('', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2578
        log_screen(' WARNING: ' + str(len(internal_error_failures)) + ' internal error' + nice_failures + ' encountered. Please investigate the following:', 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2579
        log_msg(the_output_file, " WARNING: " + str(len(internal_error_failures)) + ' internal error' + nice_failures + ' encountered. Please investigate the following:')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2580
        for failed_test in range(0, len(internal_error_failures)):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2581
            log_screen(' ' + internal_error_failures[failed_test], 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2582
            log_msg(the_output_file, ' ' + str(internal_error_failures[failed_test]))
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2583
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2584
log_screen(line_separator, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2585
log_screen('', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2586
log_msg(the_output_file, line_separator)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2587
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2588
# Close and rename the output files
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2589
if store_all_output == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2590
    the_output_file.close()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2591
    the_old_filename = log_dir + d.strftime("%Y-%m-%d_%H-%M-%S") + '_output_IN_PROGRESS.txt'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2592
    the_new_filename = log_dir + d.strftime("%Y-%m-%d_%H-%M-%S") + '_output' + filename_result + '.txt'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2593
    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2594
        os.rename(the_old_filename, the_new_filename)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2595
        log_screen('INFO: The output file has been renamed to:', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2596
        log_screen(' ' + the_new_filename, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2597
    except OSError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2598
        log_screen("WARNING: Couldn't rename the output log file.", 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2599
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2600
if store_csv_results == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2601
    csv_results_file.close()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2602
    the_old_filename = log_dir + d.strftime("%Y-%m-%d_%H-%M-%S") + '_results_IN_PROGRESS.csv'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2603
    the_new_filename = log_dir + d.strftime("%Y-%m-%d_%H-%M-%S") + '_results' + filename_result + '.csv'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2604
    try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2605
        os.rename(the_old_filename, the_new_filename)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2606
        log_screen('INFO: The csv results file has been renamed to:', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2607
        log_screen(' ' + the_new_filename, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2608
    except OSError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2609
        log_screen("WARNING: Couldn't rename the CSV results file.", 'warning')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2610
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2611
# Zip up the results?
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2612
if zip_results == 1:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2613
    log_screen('', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2614
    zip_filename = 'automated_results_' + d.strftime("%Y%m%d-%H%M%S") + '-' + str(test_count) + zip_results_type + os_type + '_' + str("%.2f" % (pc_calculation * (100 + 0.0), )) + '_percent_pass.zip'
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2615
    log_screen('Zipping results to:', '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2616
    log_screen(' ' + output_log_path + zip_filename, '')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2617
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2618
    import zipfile
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2619
    the_zip_file = zipfile.ZipFile(output_log_path + zip_filename, 'w')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2620
    for each in os.listdir(log_dir):
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2621
        try:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2622
            the_zip_file.write(log_dir + each)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2623
        except IOError:
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2624
            log_screen("ERROR: Couldn't zip the results.", 'error')
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2625
            the_zip_file.close()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2626
            sys.exit(monty_returncode_if_file_error)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2627
    the_zip_file.close()
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2628
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2629
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2630
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2631
# End Monty with an appropriate returncode
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2632
sys.exit(monty_returncode)
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2633
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2634
# ------------------------------------------------------------------------------
b538b70cbe51 Move rest of the swconfigmdw package components to oss repository.
terytkon
parents:
diff changeset
  2635
# END