Browse Source

Added sanity checks and environment versioning to run_tests.sh.

Implements blueprint environment-versioning.

Fixed bug 887885. The script will bail if the seleniumrc or test scripts are missing, preventing the hang, or the possibility of bad environments.

Change-Id: I3cdeb71660c897e8b2adbf81d3794333d1847204
Gabriel Hurley 7 years ago
parent
commit
34e217b357

+ 1
- 0
.gitignore View File

@@ -1,5 +1,6 @@
1 1
 *.pyc
2 2
 *.swp
3
+.environment_version
3 4
 .selenium_log
4 5
 .coverage
5 6
 coverage.xml

+ 1
- 1
horizon/horizon/tests/testsettings.py View File

@@ -27,7 +27,7 @@ DATABASES = {
27 27
         'default': {
28 28
             'ENGINE': 'django.db.backends.sqlite3',
29 29
             'NAME': '/tmp/horizon.db',
30
-            'TEST_NAME': '/tmp/test_horizon.db',}}
30
+            'TEST_NAME': '/tmp/test_horizon.db'}}
31 31
 
32 32
 INSTALLED_APPS = (
33 33
     'django.contrib.sessions',

+ 1
- 0
openstack-dashboard/dashboard/tests.py View File

@@ -1,6 +1,7 @@
1 1
 from django import test
2 2
 from noseselenium.cases import SeleniumTestCaseMixin
3 3
 
4
+
4 5
 class SeleniumTests(test.TestCase, SeleniumTestCaseMixin):
5 6
     def test_splash(self):
6 7
         self.selenium.open("/")

+ 0
- 2
openstack-dashboard/dashboard/views.py View File

@@ -46,5 +46,3 @@ def splash(request):
46 46
         return handled
47 47
 
48 48
     return shortcuts.render(request, 'splash.html', {'form': form})
49
-
50
-

+ 89
- 33
run_tests.sh View File

@@ -1,5 +1,14 @@
1 1
 #!/bin/bash
2 2
 
3
+set -o errexit
4
+
5
+# ---------------UPDATE ME-------------------------------#
6
+# Increment me any time the environment should be rebuilt.
7
+# This includes dependncy changes, directory renames, etc.
8
+# Simple integer secuence: 1, 2, 3...
9
+environment_version=1
10
+#--------------------------------------------------------#
11
+
3 12
 function usage {
4 13
   echo "Usage: $0 [OPTION]..."
5 14
   echo "Run Horizon's test suite(s)"
@@ -14,6 +23,7 @@ function usage {
14 23
   echo "                           been added."
15 24
   echo "  -p, --pep8               Just run pep8"
16 25
   echo "  -y, --pylint             Just run pylint"
26
+  echo "  -q, --quiet              Run non-interactively. (Relatively) quiet."
17 27
   echo "  --skip-selenium          Run unit tests but skip Selenium tests"
18 28
   echo "  --runserver              Run the Django development server for"
19 29
   echo "                           openstack-dashboard in the virtual"
@@ -31,15 +41,16 @@ function usage {
31 41
 function process_option {
32 42
   case "$1" in
33 43
     -h|--help) usage;;
34
-    -V|--virtual-env) let always_venv=1; let never_venv=0;;
35
-    -N|--no-virtual-env) let always_venv=0; let never_venv=1;;
36
-    -p|--pep8) let just_pep8=1;;
37
-    -y|--pylint) let just_pylint=1;;
38
-    -f|--force) let force=1;;
39
-    -c|--coverage) let with_coverage=1;;
40
-    --skip-selenium) let selenium=-1;;
41
-    --docs) let just_docs=1;;
42
-    --runserver) let runserver=1;;
44
+    -V|--virtual-env) always_venv=1; never_venv=0;;
45
+    -N|--no-virtual-env) always_venv=0; never_venv=1;;
46
+    -p|--pep8) just_pep8=1;;
47
+    -y|--pylint) just_pylint=1;;
48
+    -f|--force) force=1;;
49
+    -q|--quiet) quiet=1;;
50
+    -c|--coverage) with_coverage=1;;
51
+    --skip-selenium) selenium=-1;;
52
+    --docs) just_docs=1;;
53
+    --runserver) runserver=1;;
43 54
     *) testargs="$testargs $1"
44 55
   esac
45 56
 }
@@ -65,13 +76,14 @@ function run_pylint {
65 76
 
66 77
 function run_pep8 {
67 78
   echo "Running pep8 ..."
79
+  rm -f pep8.txt
68 80
   PEP8_EXCLUDE=vcsversion.py
69 81
   PEP8_OPTIONS="--exclude=$PEP8_EXCLUDE --repeat"
70 82
   PEP8_INCLUDE="openstack-dashboard/dashboard horizon/horizon"
71 83
   echo "${django_wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE > pep8.txt"
72 84
   #${django_wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE > pep8.txt
73 85
   #perl string strips out the [ and ] characters
74
-  ${django_wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE | perl -ple 's/: ([WE]\d+)/: [$1]/' > pep8.txt
86
+  ${django_wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE > pep8.txt
75 87
 }
76 88
 
77 89
 function run_sphinx {
@@ -99,12 +111,64 @@ just_pep8=0
99 111
 just_pylint=0
100 112
 just_docs=0
101 113
 runserver=0
114
+quiet=0
102 115
 
103 116
 # PROCESS ARGUMENTS, OVERRIDE DEFAULTS
104 117
 for arg in "$@"; do
105 118
     process_option $arg
106 119
 done
107 120
 
121
+function environment_check {
122
+  echo "Checking environment."
123
+  if [ -f .environment_version ]; then
124
+    ENV_VERS=`cat .environment_version`
125
+    if [ $ENV_VERS -eq $environment_version ]; then
126
+      echo "Environment is up to date."
127
+      return 0
128
+    fi
129
+  fi
130
+  if [ $quiet -eq 1 ]; then
131
+    install_venv
132
+  else
133
+    # If we didn't pass our check, ask about upgrading the environment.
134
+    echo -e "Your environment appears to be out of date. Update? (Y/n) \c"
135
+    read update_env
136
+    if [ "x$update_env" = "xY" -o "x$update_env" = "x" -o "x$update_env" = "xy" ]; then
137
+      install_venv
138
+    fi
139
+  fi
140
+}
141
+
142
+function sanity_check {
143
+  # Anything that should be determined prior to running the tests, server, etc.
144
+  if [ ! -f horizon/bin/test ]; then
145
+    echo "Error: Test script not found at horizon/bin/test. Did buildout succeed?"
146
+    exit 1
147
+  fi
148
+  if [ ! -f horizon/bin/coverage ]; then
149
+    echo "Error: Coverage script not found at horizon/bin/coverage. Did buildout succeed?"
150
+    exit 1
151
+  fi
152
+  if [ ! -f horizon/bin/seleniumrc ]; then
153
+    echo "Error: Selenium script not found at horizon/bin/seleniumrc. Did buildout succeed?"
154
+    exit 1
155
+  fi
156
+}
157
+
158
+function install_venv {
159
+  cd openstack-dashboard
160
+  python tools/install_venv.py
161
+  cd ..
162
+  cd horizon
163
+  python bootstrap.py
164
+  bin/buildout
165
+  cd ..
166
+  django_wrapper="${django_with_venv}"
167
+  dashboard_wrapper="${dashboard_with_venv}"
168
+  sanity_check
169
+  echo $environment_version > .environment_version
170
+}
171
+
108 172
 if [ $never_venv -eq 0 ]
109 173
 then
110 174
   # Remove the virtual environment if --force used
@@ -118,29 +182,17 @@ then
118 182
   else
119 183
     if [ $always_venv -eq 1 ]; then
120 184
       # Automatically install the virtualenv
121
-      cd openstack-dashboard
122
-      python tools/install_venv.py
123
-      cd ..
124
-      cd horizon
125
-      python bootstrap.py
126
-      bin/buildout
127
-      cd ..
128
-      django_wrapper="${django_with_venv}"
129
-      dashboard_wrapper="${dashboard_with_venv}"
185
+      install_venv
130 186
     else
131
-      echo -e "No virtual environment found...create one? (Y/n) \c"
132
-      read use_ve
133
-      if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
134
-        # Install the virtualenv and run the test suite in it
135
-        cd openstack-dashboard
136
-        python tools/install_venv.py
137
-        cd ..
138
-        cd horizon
139
-        python bootstrap.py
140
-        bin/buildout
141
-        cd ..
142
-        django_wrapper="${django_with_venv}"
143
-        dashboard_wrapper="${dashboard_with_venv}"
187
+      if [ $quiet -eq 1 ]; then
188
+        echo -e "No virtual environment found...create one? (Y/n) \c"
189
+        read use_ve
190
+        if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
191
+          # Install the virtualenv and run the test suite in it
192
+          install_venv
193
+        fi
194
+      else
195
+        install_venv
144 196
       fi
145 197
     fi
146 198
   fi
@@ -159,6 +211,8 @@ function wait_for_selenium {
159 211
 }
160 212
 
161 213
 function run_tests {
214
+  sanity_check
215
+
162 216
   if [ $selenium -eq 0 ]; then
163 217
     echo "Starting Selenium server..."
164 218
     ${django_wrapper} horizon/bin/seleniumrc > .selenium_log &
@@ -208,12 +262,14 @@ function run_tests {
208 262
         kill `echo "${SELENIUM_JOB}" | awk '{print $4}'`
209 263
         echo "Selenium process stopped."
210 264
       else
211
-        echo "Selenium process not found. This may require manual claenup."
265
+        echo "Selenium process not found. This may require manual cleanup."
212 266
     fi
213 267
     rm -f .selenium_log
214 268
   fi
215 269
 }
216 270
 
271
+environment_check
272
+
217 273
 if [ $just_docs -eq 1 ]; then
218 274
     run_sphinx
219 275
     exit $?

Loading…
Cancel
Save