Skip to content

Commit 6cbbaeb

Browse files
author
Daniel Abercrombie
authored
Merge pull request #68 from dabercro/v011
V011
2 parents e39c52f + 71bbcb0 commit 6cbbaeb

11 files changed

Lines changed: 162 additions & 42 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*~
33
build/*
44
test/*/*
5+
!test/sl?/Dockerfile
56
test/*.cache.json
67
dist/*
78
cmstoolbox.egg-info/*

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ cache: pip
33
matrix:
44
include:
55
- python: 2.6
6-
env:
7-
- nodoc=true
86
- python: 2.7
97
env:
108
- nodoc=true

Jenkinsfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
def run(os) {
2+
return {
3+
4+
docker.build("opsspace-${os}:${env.BUILD_ID}", "test/${os}").inside('-u root:root') {
5+
6+
stage("${os}: Copy Source") {
7+
sh """
8+
test ! -d ${os} || rm -rf ${os}
9+
mkdir ${os}
10+
cp --parents `git ls-files` ${os}
11+
"""
12+
}
13+
14+
stage("${os}: Installation") {
15+
sh "cd ${os}; python setup.py install"
16+
}
17+
18+
stage("${os}: Unit Tests") {
19+
sh "cd ${os}; opsspace-test"
20+
}
21+
}
22+
}
23+
}
24+
25+
def osList = ['sl6', 'sl7']
26+
27+
node {
28+
checkout scm
29+
parallel osList.collectEntries{
30+
["${it}": run(it)]
31+
}
32+
}

bin/copy-coverage-html

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#! /usr/bin/env perl
2+
3+
use strict;
4+
use warnings;
5+
6+
use v5.10;
7+
8+
use Cwd;
9+
use File::Path qw(make_path);
10+
use File::Basename;
11+
use File::Spec::Functions;
12+
use File::Find;
13+
14+
# If not in a location with a test directory, exit
15+
if (! -f 'test/.coverage') {
16+
exit 1;
17+
}
18+
19+
my $outdir = pop @ARGV or die 'Need a destination';
20+
make_path($outdir);
21+
22+
my @inits = sort { length $a <=> length $b } `find . -type f -name '__init__.py'`;
23+
24+
# Get the name of the package
25+
my ($pack) = shift @ARGV || ($inits[0] =~ m|\./(.*)/__init__\.py|);
26+
27+
# Create the htmlcov directory
28+
`cd test && coverage html`;
29+
30+
# And get all of the files that we'll want
31+
my @files = glob 'test/htmlcov/*';
32+
33+
for (@files) {
34+
35+
open(my $in_fh, '<', $_);
36+
37+
s/.*(${pack}.*)/$1/;
38+
39+
my $base = fileparse $_;
40+
41+
open(my $out_fh, '>', catfile($outdir, $base));
42+
43+
for (<$in_fh>) {
44+
if (/$pack/) {
45+
# Fix href
46+
s/(href=").*(${pack}.*?\.html)/$1$2/;
47+
# Fix text
48+
s|/.*/(${pack}.*\.py)|$1|;
49+
}
50+
print $out_fh $_;
51+
}
52+
53+
}

bin/opsspace-test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ _do_test () {
5252
_doc_test () {
5353

5454
# Check if we should test build Sphinx documentation
55-
if [ -f docs/conf.py ] && [ "$nodoc" != "true" ]
55+
if [ -f docs/conf.py ] && [ "$nodoc" != "true" ] && [ "$pyvers" != "26" ]
5656
then
5757

5858
test -f docs/requirements.txt && pip install -r docs/requirements.txt
@@ -82,14 +82,14 @@ _unit_test () {
8282

8383

8484
# Run the test for all files that start with "test_". They should be executable.
85-
for packagetest in test_*
85+
for packagetest in test_*[^~]
8686
do
8787

8888
# Run the coverage on top of the unit tests
8989
if [ ! -z $docoverage ] && [ "${packagetest##*.}" == "py" ]
9090
then
9191

92-
_do_test "coverage run --source $package -a $packagetest"
92+
_do_test "coverage run --source ${cover:-$package} -a $packagetest"
9393

9494
else
9595

cmstoolbox/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
__all__ = []
44

5-
__version__ = '0.9.8'
5+
__version__ = '0.11.2'

cmstoolbox/samstatus.py

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,29 @@
1010

1111
from .webtools import get_json
1212

13+
14+
def _is_problem(success, data):
15+
"""
16+
:param float success: the rate of success desired
17+
:param list data: Data from the WLCG SAM server
18+
:returns: True if the success rate of SAM test is below success
19+
:rtype: bool
20+
"""
21+
# if success is less then 85% call it a problem
22+
items = 0
23+
bad = 0
24+
for item in data:
25+
stat = item[1]
26+
if stat == 'WHITE':
27+
continue
28+
29+
items += 1
30+
if stat in ['CRITICAL', 'WARNING']:
31+
bad += 1
32+
33+
return float(bad)/float(items) > (1.0 - success)
34+
35+
1336
def is_sam_good(site, time_span=24, success=0.85):
1437
"""
1538
Checks the SAM tests for success rate, and returns True if SAM tests were passing
@@ -33,12 +56,18 @@ def is_sam_good(site, time_span=24, success=0.85):
3356
srm_host_name = ''
3457
ce_host_name = ''
3558
ce_flavour = ''
36-
for item in gen_json['data']['results'][0]['flavours']:
37-
if item['servicename'] == 'SRM':
38-
srm_host_name = item['hosts'][0]['hostname']
39-
else:
40-
ce_host_name = item['hosts'][0]['hostname']
41-
ce_flavour = item['servicename']
59+
60+
try:
61+
for item in gen_json['data']['results'][0]['flavours']:
62+
if item['servicename'] == 'SRM':
63+
srm_host_name = item['hosts'][0]['hostname']
64+
else:
65+
ce_host_name = item['hosts'][0]['hostname']
66+
ce_flavour = item['servicename']
67+
68+
except (KeyError, IndexError):
69+
# If there's something wrong with the JSON file, go through
70+
return True
4271

4372
get_data = lambda flav, host: get_json('wlcg-sam-cms.cern.ch',
4473
'/dashboard/request.py/getTestResults',
@@ -47,33 +76,16 @@ def is_sam_good(site, time_span=24, success=0.85):
4776
'hostname': host,
4877
'time_range': time_span_str})
4978

50-
def is_problem(success, data):
51-
"""
52-
:param float success: the rate of success desired
53-
:param list data: Data from the WLCG SAM server
54-
:returns: True if the success rate of SAM test is below success
55-
:rtype: bool
56-
"""
57-
# if success is less then 85% call it a problem
58-
items = 0
59-
bad = 0
60-
for item in data:
61-
stat = item[1]
62-
if stat == 'WHITE':
63-
continue
64-
65-
items += 1
66-
if stat in ['CRITICAL', 'WARNING']:
67-
bad += 1
68-
69-
return float(bad)/float(items) > (1.0 - success)
70-
71-
for probe in get_data('SRM', srm_host_name)['data']:
72-
if is_problem(success, probe[1]):
73-
return False
74-
75-
for probe in get_data(ce_flavour, ce_host_name)['data']:
76-
if 'WN-xrootd-access' in probe[0] and is_problem(success, probe[1]):
77-
return False
79+
try:
80+
for probe in get_data('SRM', srm_host_name)['data']:
81+
if _is_problem(success, probe[1]):
82+
return False
83+
84+
for probe in get_data(ce_flavour, ce_host_name)['data']:
85+
if 'WN-xrootd-access' in probe[0] and _is_problem(success, probe[1]):
86+
return False
87+
88+
except KeyError:
89+
pass
7890

7991
return True

cmstoolbox/webtools.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ def get_json(host, request, params='', body='', headers=None,
6060

6161
if use_https:
6262
use_port = port or 443
63-
cert_file = kwargs.get('cert_file', os.getenv('X509_USER_PROXY')) \
64-
if use_cert else None
63+
cert_file = kwargs.get(
64+
'cert_file',
65+
os.environ.get('X509_USER_PROXY',
66+
'/tmp/x509up_u%i' % os.geteuid())
67+
) if use_cert else None
6568

6669
# Python 2.7.something verifies HTTPS connections,
6770
# but earlier version of Python do not

test/requirements26.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
astroid<1.3
22
pylint<1.4
33
testfixtures<6
4+
setuptools==36.8.0

test/sl6/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM sl:6
2+
3+
RUN yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
4+
5+
RUN yum -y install \
6+
python-pip \
7+
python-devel \
8+
git perl
9+
10+
RUN pip install -U 'pip==9.0.1'

0 commit comments

Comments
 (0)