Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up import of isi_sdk_7_2 and pytest #17

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ virtualenv:
system_site_packages: false

install:
- npm install -g casperjs phantomjs-prebuilt
- pip install -r requirements-dev.txt
- git clone https://github.com/Isilon/isilon_sdk_7_2_python.git
- cd isilon_sdk_7_2_python
- python setup.py install
- cd ..

script:
- make travis-ci
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ tags:
$(HEXAPARSE) stat_key_browser/data/key_cats.hexa > stat_key_browser/data/key_cats.json

lint:
$(PYLINT) -E -f colorized -r n stat_key_browser bin/ tests/
$(PYLINT) -E -f colorized -r n stat_key_browser build_stat_browser.py tests/

unittests: lint
$(PYTHON) -m pytest -v tests/unit/ *.py

coverage: lint
$(PYTHON) -m pytest -v --cov=stat_key_browser --cov-report term-missing --cov-config tests/unit/.coveragerc tests/unit/ *.py

travis-ci: tags lint
$(PYTHON) -m pytest -v tests/unit/ hexaparse.py
travis-ci: tags unittests jsunittests

check_cluster:
if [ -z $$BUILD_BROWSER_ARGS ]; then echo BUILD_BROWSER_ARGS not set, builder will pause for input; fi
Expand All @@ -47,3 +46,12 @@ dist: check_cluster clean unittests tags
cp -r stat_key_browser $(DIST_DIR)
cp -r web_app $(DIST_DIR)
zip -r isilon_stat_browser_$(BROWSER_VERS_STRING).zip dist/*

jsunittests:
casperjs test web_app/js/tests/unit_app_filter_lib.js \
--includes=web_app/js/app_filter_lib.js,web_app/js/app_lib.js
casperjs test web_app/js/tests/unit_app_lib.js --includes=web_app/js/app_lib.js
casperjs test web_app/js/tests/unit_app_papi_link.js --includes=web_app/js/app_papi_link.js

jstests: dist jsunittests
casperjs test web_app/js/tests/smoke.js
18 changes: 12 additions & 6 deletions README-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Python: 2.7, 3.3, 3.4, 3.5

Dependencies listed in requirements-dev.txt

Isilon SDK Python language bindings
Isilon SDK [Python language bindings](https://github.com/isilon)

[`https://github.com/isilon/`](https://github.com/isilon)
[CasperJS](http://casperjs.org) 1.1 or later

##Development getting started

Expand All @@ -27,6 +27,13 @@ Isilon SDK Python language bindings

`pip install -r requirements-dev.txt`

#### Install CasperJS 1.1 or later
`npm install -g casperjs phantomjs-prebuilt`

Or on Mac:

`brew install casperjs --devel`

### Run unit tests:

`make unittests`
Expand All @@ -35,10 +42,9 @@ Isilon SDK Python language bindings

`make coverage`

### Run functional tests:
The functional tests are only a stub currently.
### Run JavaScript tests:

`make functional_tests`
`make jstests`

###Run the page building tool
First, convert the tagging data to JSON. This step creates stat\_key\_browser/data/key\_tags.json and stat\_key\_browser/data/key\_cats.json
Expand Down Expand Up @@ -133,4 +139,4 @@ Contains a template representing a single key and all of its info, including its

* `web_app/index.html`

This is the file opened by the user to view the stat browser. This file is rendered by build_stat_browser.py from the templates, the definitions in key_tags.json and from the PAPI supplied list of keys.
This is the file opened by the user to view the stat browser. This file is rendered by build\_stat\_browser.py from the templates, the definitions in key_tags.json and from the PAPI supplied list of keys.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ You can also generate the stat browser from your OneFS cluster by running the bu
### Requirements
Python: 2.7, 3.3, 3.4, 3.5

Isilon SDK Python Language Bindings installed

### Generating the stat browser

Expand All @@ -60,8 +59,7 @@ The script will prompt you for a username and password, and will create the brow

You can use the SDK Python language bindings to automate the configuration, maintenance, and monitoring of your Isilon cluster. For information on how to install the Python language bindings and write Python scripts to access the OneFS API, refer to the following Github sites:

[`https://github.com/Isilon/isilon_sdk_7_2_python`](https://github.com/Isilon/isilon_sdk_7_2_python)
[`https://github.com/Isilon/isilon_sdk_8_0_python`](https://github.com/Isilon/isilon_sdk_8_0_python)
[`https://github.com/Isilon/isilon_sdk`](https://github.com/Isilon/isilon_sdk)


Copyright (c) 2016 EMC Corporation
Expand Down
4 changes: 2 additions & 2 deletions hexaparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import json
import re
import logging
import pytest


def is_new_block(line):
"""Determine whether a string marks a new block."""
Expand Down Expand Up @@ -271,12 +269,14 @@ def test_hexakey_2():

def test_hexakey_3():
"""Test non-key."""
import pytest
with pytest.raises(ValueError):
hexakey(':')


def test_hexakey_4():
"""Test non-key."""
import pytest
with pytest.raises(ValueError):
hexakey(': ')

Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ mock>=2.0.0
jinja2>=2.8
pylint>=1.5.5
urllib3 >= 1.15
isi_sdk_7_2>=0.1.2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider referencing requirements.txt instead of duplicating it here.

Suggested change
isi_sdk_7_2>=0.1.2
-r requirements.txt

3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
future>=0.15.2
jinja2>=2.8
urllib3 >= 1.15
urllib3>=1.15
isi_sdk_7_2>=0.1.2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.2.x contains backwards-incompatible changes (see #19).

Suggested change
isi_sdk_7_2>=0.1.2
isi_sdk_7_2~=0.1.2

The compatible release operator should cause the latest compatible isi_sdk_7_2 to be installed (currently, 0.1.11).

6 changes: 3 additions & 3 deletions stat_key_browser/cluster_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
try:
# Try the original SDK library name
import isi_sdk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this should be:

import isi_sdk_7_2

or

import isi_sdk_7_2 as isi_sdk

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent here is to allow functioning with either isi_sdk_7_2 or the original and now deprecated isi_sdk library.

So it first tries importing isi_sdk_7_2, if that fails then it tries for the deprecated SDK library.

except ImportError as err:
print('Unable to import isi_sdk_7_2. Please install the Isilon SDK.')
except ImportError:
print('Unable to import isi_sdk_7_2. Please install the Isilon SDK:')
print('pip install isi_sdk_7_2')
print('See https://github.com/isilon')
print(err)
sys.exit(1)


Expand Down
6 changes: 3 additions & 3 deletions stat_key_browser/key_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
try:
# Try the original SDK library name
import isi_sdk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same situation here with allowing either isi_sdk or isi_sdk_7_2

except ImportError as err:
print('Unable to import isi_sdk_7_2. Please install the Isilon SDK.')
except ImportError:
print('Unable to import isi_sdk_7_2. Please install the Isilon SDK:')
print('pip install isi_sdk_7_2')
print('See https://github.com/isilon')
print(err)
sys.exit(1)

PRIMARY = 0
Expand Down
2 changes: 1 addition & 1 deletion stat_key_browser/templates/app_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ <h1 class="col-md-12">EMC | Isilon OneFS Statistics</h1>
{% endfor %}
</ul>
</div>
<input class="btn btn-default" type="reset" value="Reset" onclick="reset_search()">
<input id="resetButton" class="btn btn-default" type="reset" value="Reset" onclick="reset_search()">
</div>
</form>
</div>
Expand Down
File renamed without changes.
Empty file added tests/functional/__init__.py
Empty file.
Empty file added tests/unit/__init__.py
Empty file.
25 changes: 10 additions & 15 deletions tests/unit/test_categorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,18 @@ def cat(self):
@pytest.fixture
def key_dict(self):
"""Return a key_dict."""
key_dict_3= {
"node.sensor.power.A": {},
"node.sensor.power.B": {},
"node.sensor.altitude.A": {},
"node.sensor.altitude.B": {},
"node.protostats.smb1": {},
"node.protostats.smb2": {},
"node.protostats.smb3": {},
"node.sensor.walrus.tusk": {}
}
key_dict_3 = {
"node.sensor.power.A": {},
"node.sensor.power.B": {},
"node.sensor.altitude.A": {},
"node.sensor.altitude.B": {},
"node.protostats.smb1": {},
"node.protostats.smb2": {},
"node.protostats.smb3": {},
"node.sensor.walrus.tusk": {}
}
return key_dict_3


def assert_is_string(self, subject):
assert isinstance(subject, (str, unicode))


def test_categorizer_init_00(self, cat):
categorizer = Categorizer(cat)
assert len(categorizer.cat_defs) == len(cat)
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_cluster_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@
class TestClusterConfig(object):

@patch('stat_key_browser.cluster_config._get_cluster_version')
def test_0_get_cluster_release(self, get_cluster_version):
def test_0_get_cluster_release_1(self, get_cluster_version):
get_cluster_version.return_value = '2.0'
results = cluster_config.get_release('4.3.2.1', 'u', 'p')
assert results == '2.0'

@patch('stat_key_browser.cluster_config._get_cluster_version')
def test_0_get_cluster_release(self, get_cluster_version):
def test_0_get_cluster_release_2(self, get_cluster_version):
get_cluster_version.return_value = '1.0'
results = cluster_config.get_release('4.3.2.1', 'u', 'p')
assert results == '1.0'


@patch('isi_sdk.ClusterApi.get_cluster_config')
@patch('isi_sdk_7_2.ClusterApi.get_cluster_config')
def test_1_get_cluster_version(self, cluster_vers):
canned = {'onefs_version': {'release': '1.0'}}
response = MockClusterVersionResponse(canned)
cluster_vers.return_value = response
results = cluster_config._get_cluster_version('4.3.2.1', 'u', 'p')
assert results == '1.0'

@patch('isi_sdk.ClusterApi.get_cluster_config')
@patch('isi_sdk_7_2.ClusterApi.get_cluster_config')
def test_3_get_cluster_versions_bug_169014(self, cluster_vers):
response = MockClusterVersionResponse({})
cluster_vers.return_value = response
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_key_collector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from mock import patch
import isi_sdk
import isi_sdk_7_2
import unittest
import stat_key_browser.key_collector as key_collector

Expand Down Expand Up @@ -115,7 +115,7 @@ def test_get_key_dict_1(self, mock_method):
assert 'a.a' in result
mock_method.assert_called_with('testing123', 'user1', 'pass1')

@patch.object(isi_sdk, 'ApiClient')
@patch.object(isi_sdk_7_2, 'ApiClient')
def test_get_key_list_1(self, mock_method):
key_collector._get_key_list('testing123', 'user', 'pass')
mock_method.assert_called_with('https://testing123:8080')
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def test_get_arb_attrs_01(self):

defin = {'re-keys': ['g', 'h'], 'tags': ['a', 'b'], 'arb': ['arbarb']}
result = tg._get_extra_attrs(defin)
assert result == {'arb': 'arbarb'}
assert result == {'arb': ['arbarb']}

def test_get_arb_attrs_01(self):
def test_get_arb_attrs_02(self):
tg = Tagger([{'re-keys': ['g', 'h'], 'tags': ['a', 'b']}])

defin = {'re-keys': ['g', 'h'], 'tags': ['a', 'b'], 'arb': ['arbarb', 'arbTWO']}
Expand Down
10 changes: 10 additions & 0 deletions web_app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@ $( document ).ready(function() {
captureLength: 2
}
$('#text_filter').typeWatch(options)

// Setup PAPI links
$('.papi_demo').click(papi_link_clicked)
$('#modal_cluster_save').click(save_cluster_ip)
$('#modal_cluster').on('shown.bs.modal', function () {$('#text_cluster').focus()})
cluster_ip = keyDict['cluster']['host']
if (cluster_ip != null) {
// Populate PAPI links if IP is known
update_papi_links(keyDict['cluster']['host'])
}
});
2 changes: 1 addition & 1 deletion web_app/js/app_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function dedupe_array(a) {
var deduped = [];
for (var i=0; i< a.length; i++) {
if (!hashes[a[i]]) {
hashes[a] = true
hashes[a[i]] = true
deduped.push(a[i])
}
}
Expand Down
13 changes: 1 addition & 12 deletions web_app/js/app_papi_link.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
var cluster_ip = null
var clicked_link = null

$(document).ready(function () {
$('.papi_demo').click(papi_link_clicked)
$('#modal_cluster_save').click(save_cluster_ip)
$('#modal_cluster').on('shown.bs.modal', function () {$('#text_cluster').focus()})
cluster_ip = keyDict['cluster']['host']
if (cluster_ip != null) {
// Populate PAPI links if IP is known
update_papi_links(keyDict['cluster']['host'])
}
});

function papi_link_clicked() {
if (cluster_ip == null) {
clicked_link = $(this)
Expand Down Expand Up @@ -52,7 +41,7 @@ function update_papi_link(endpoint) {
function antisquash_key(key) {
// If a key ends in .N, convert the N to 1
if (key.endsWith('.N')) {
key = key.replace(/\.N$/, '.1')
key = key.replace(/\.N$/, '.1')
}
return key
}
Expand Down
32 changes: 32 additions & 0 deletions web_app/js/tests/smoke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Smoke tests for Isilon Stat Browser
//
// Loads index.html into a phantomjs browser
// verify page title is set
// verify title text is displayed
// verify search box is displayed
// Verfiy reset button is displayed
// verify tags button is displayed
// verify top-level categories are visible
// verify category sub-contents are not visible
// verify individual keys are not visible

/*
To run the tests:
casperjs test web_app/js/tests/smoke.js
*/

casper.test.begin('Smoke Test', 8, function suite(test) {
casper.start('web_app/index.html', function() {
test.assertTitle('EMC | Isilon OneFS Statistics', 'page title is set')
test.assertSelectorHasText('h1.col-md-12', 'EMC | Isilon OneFS Statistics', 'title text is displayed');
test.assertVisible('#text_filter', 'search box is displayed')
test.assertVisible('#resetButton', 'reset button is displayed')
test.assertVisible('#tagDropdown', 'tags dropdown is displayed')
test.assertVisible('div.category_main', 'top-level categories are visible')
test.assertNotVisible('div.subcontents', 'category sub-contents are not visible')
test.assertNotVisible('div.key_main', 'individual keys are not visible')

}).run(function() {
test.done();
});
});
Loading