Init commit for Distil UI

Some specific Catalyst Cloud stuff are here and there, they will be cleaned
up later after we migrated to Distil v2.

Change-Id: I81df0765cfc876faaa58a43469d87825d30c167e
This commit is contained in:
Fei Long Wang 2017-03-13 14:13:26 +13:00
parent 2663f43c17
commit 502b3eb286
76 changed files with 3863 additions and 0 deletions

46
.gitignore vendored Normal file
View File

@ -0,0 +1,46 @@
*.pyc
*.deb
.vagrant
work
*.swp
*~
*.swo
*.sw*
lib/
man/
build/
work-api/
work-client/
env/
dist/
include/
*.egg*/
bin/activate
bin/activate.csh
bin/activate.fish
bin/activate_this.py
bin/ceilometer
bin/easy_install
bin/easy_install-2.7
bin/keystone
bin/netaddr
bin/nosetests
bin/nosetests-2.7
bin/pip
bin/pip-2.7
bin/pybabel
bin/python
bin/python2
bin/python2.7
.project
.pydevproject
.testrepository/
.tox/
.venv/
bin/logs/
bin/waitress-serve
local/
test_vm/
env/
ChangeLog
.idea

1
AUTHORS Normal file
View File

@ -0,0 +1 @@
Fei Long Wang <flwang@catalyst.net.nz>

176
LICENSE Normal file
View File

@ -0,0 +1,176 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

1
MANIFEST.in Normal file
View File

@ -0,0 +1 @@
include setup.py

64
README.rst Normal file
View File

@ -0,0 +1,64 @@
========================
Team and repository tags
========================
.. Change things from this point on
===============================
distil-ui
===============================
Distil Dashboard
* Free software: Apache license
* Source: http://git.openstack.org/cgit/openstack/distil-ui
Enabling in DevStack
--------------------
Add this repo as an external repository into your ``local.conf`` file::
[[local|localrc]]
enable_plugin distil-ui https://github.com/openstack/distil-ui
Manual Installation
-------------------
Begin by cloning the Horizon and Distil UI repositories::
git clone https://github.com/openstack/horizon
git clone https://github.com/openstack/distil-ui
Create a virtual environment and install Horizon dependencies::
cd horizon
python tools/install_venv.py
Set up your ``local_settings.py`` file::
cp openstack_dashboard/local/local_settings.py.example openstack_dashboard/local/local_settings.py
Open up the copied ``local_settings.py`` file in your preferred text
editor. You will want to customize several settings:
- ``OPENSTACK_HOST`` should be configured with the hostname of your
OpenStack server. Verify that the ``OPENSTACK_KEYSTONE_URL`` and
``OPENSTACK_KEYSTONE_DEFAULT_ROLE`` settings are correct for your
environment. (They should be correct unless you modified your
OpenStack server to change them.)
Install Distil UI with all dependencies in your virtual environment::
tools/with_venv.sh pip install -e ../distil-ui/
And enable it in Horizon::
cp ../distil-ui/enabled/_6010_management_billing.py openstack_dashboard/local/enabled
To run horizon with the newly enabled Distil UI plugin run::
./run_tests.sh --runserver 0.0.0.0:8080
to have the application start on port 8080 and the horizon dashboard will be
available in your browser at http://localhost:8080/

5
babel-django.cfg Normal file
View File

@ -0,0 +1,5 @@
[extractors]
django = django_babel.extract:extract_django
[python: **.py]
[django: templates/**.html]

14
babel-djangojs.cfg Normal file
View File

@ -0,0 +1,14 @@
[extractors]
# We use a custom extractor to find translatable strings in AngularJS
# templates. The extractor is included in horizon.utils for now.
# See http://babel.pocoo.org/docs/messages/#referencing-extraction-methods for
# details on how this works.
angular = horizon.utils.babel_extract_angular:extract_angular
[javascript: **.js]
# We need to look into all static folders for HTML files.
# The **/static ensures that we also search within
# /openstack_dashboard/dashboards/XYZ/static which will ensure
# that plugins are also translated.
[angular: **/static/**.html]

0
distil_ui/__init__.py Normal file
View File

View File

316
distil_ui/api/distil.py Normal file
View File

@ -0,0 +1,316 @@
# Copyright (c) 2014 Catalyst IT Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import collections
import datetime
import logging
import math
import time
from django.conf import settings
import eventlet
from openstack_dashboard.api import base
LOG = logging.getLogger(__name__)
BILLITEM = collections.namedtuple('BillItem',
['id', 'resource', 'count', 'cost'])
EMPTY_BREAKDOWN = [BILLITEM(id=1, resource='N/A', count=0, cost=0)]
RES_NAME_MAPPING = {'Virtual Machine': 'Compute',
'Volume': 'Block Storage'}
KNOWN_RESOURCE_TYPE = ['Compute', 'Block Storage', 'Network', 'Router',
'Image', 'Floating IP', 'Object Storage', 'VPN',
'Inbound International Traffic',
'Outbound International Traffic',
'Inbound National Traffic',
'Outbound National Traffic']
SRV_RES_MAPPING = {'m1.tiny': 'Compute',
'm1.small': 'Compute',
'm1.mini': 'Compute',
'm1.medium': 'Compute',
'c1.small': 'Compute',
'm1.large': 'Compute',
'm1.xlarge': 'Compute',
'c1.large': 'Compute',
'c1.xlarge': 'Compute',
'c1.xxlarge': 'Compute',
'm1.2xlarge': 'Compute',
'c1.c1r1': 'Compute',
'c1.c1r2': 'Compute',
'c1.c1r4': 'Compute',
'c1.c2r1': 'Compute',
'c1.c2r2': 'Compute',
'c1.c2r4': 'Compute',
'c1.c2r8': 'Compute',
'c1.c2r16': 'Compute',
'c1.c4r2': 'Compute',
'c1.c4r4': 'Compute',
'c1.c4r8': 'Compute',
'c1.c4r16': 'Compute',
'c1.c4r32': 'Compute',
'c1.c8r4': 'Compute',
'c1.c8r8': 'Compute',
'c1.c8r16': 'Compute',
'c1.c8r32': 'Compute',
'b1.standard': 'Block Storage',
'o1.standard': 'Object Storage',
'n1.ipv4': 'Floating IP',
'n1.network': 'Network',
'n1.router': 'Router',
'n1.vpn': 'VPN',
'n1.international-in': 'Inbound International Traffic',
'n1.international-out': 'Outbound International Traffic',
'n1.national-in': 'Inbound National Traffic',
'n1.national-out': 'Outbound National Traffic'}
TRAFFIC_MAPPING = {'n1.international-in': 'Inbound International Traffic',
'n1.international-out': 'Outbound International Traffic',
'n1.national-in': 'Inbound National Traffic',
'n1.national-out': 'Outbound National Traffic'}
CACHE = {}
def distilclient(request):
try:
try:
from distilclient import client
except Exception:
from distil.client import client
auth_url = base.url_for(request, service_type='identity')
distil_url = base.url_for(request, service_type='rating')
insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
distil = client.Client(distil_url=distil_url,
os_auth_token=request.user.token.id,
os_tenant_id=request.user.tenant_id,
os_auth_url=auth_url,
os_region_name=request.user.services_region,
insecure=insecure,
os_cacert=cacert)
distil.request = request
except Exception as e:
LOG.error(e)
return
return distil
def _get_month_cost(distil_client, tenant_id, start_str, end_str,
history_cost, i):
today = datetime.datetime.today()
start = datetime.datetime.strptime(start_str, '%Y-%m-%dT%H:%M:%S')
cache_key = (distil_client.endpoint + '_' + tenant_id + '_' +
start_str + '_' + end_str)
if cache_key in CACHE:
history_cost[i] = CACHE[cache_key]
return
month_cost = distil_client.get_rated([tenant_id], start_str,
end_str)['usage']
resource_cost = collections.OrderedDict()
prices = {}
cost_details = collections.defaultdict(list)
for res in KNOWN_RESOURCE_TYPE:
cost_details[res] = []
for res_id, details in month_cost['resources'].items():
resource_type = details['type']
for s in details['services']:
if resource_type not in prices:
try:
prices[resource_type] = float(s.get('rate', 0))
except Exception as e:
LOG.error('Failed to get rate for %s since %s' % (s, e))
# Only collect service details for current month, we may support
# the details for history in the future.
if ((start.year == today.year and start.month == today.month) or
s['name'] in TRAFFIC_MAPPING):
try:
s_copy = s.copy()
s_copy['volume'] = round(float(s_copy['volume']), 4)
s_copy['resource_id'] = res_id
cd_key = ('Image' if resource_type == 'Image' else
SRV_RES_MAPPING.get(s['name'], resource_type))
if cd_key in ('Image', 'Block Storage', 'Object Storage'):
s_copy['unit'] = 'gigabyte * hour'
# NOTE(flwang): Get the related resource info
if resource_type == 'Floating IP':
s_copy['resource'] = details['ip address']
if resource_type in ('Image', 'Object Storage Container',
'Network', 'Virtual Machine',
'Router', 'VPN', 'Volume'):
s_copy['resource'] = details['name']
cost_details.get(cd_key).append(s_copy)
except Exception as e:
LOG.error('Failed to save: %s, since %s' % (s, e))
continue
res_type = (resource_type if resource_type not in
RES_NAME_MAPPING else RES_NAME_MAPPING[resource_type])
count, cost = _calculate_count_cost(list(details['services']),
res_type)
if res_type in resource_cost:
tmp_count_cost = resource_cost[res_type]
tmp_count_cost = [tmp_count_cost[0] + count,
tmp_count_cost[1] + cost]
resource_cost[res_type] = tmp_count_cost
else:
resource_cost[res_type] = [count, cost]
# NOTE(flwang): Based on current Distil API design, it's making the
# traffic data associate with floating ip and router. So we need to
# get them out and recalculate the cost of floating ip and router.
if ['admin'] in [r.values() for r in distil_client.request.user.roles]:
_calculate_traffic_cost(cost_details, resource_cost)
breakdown = []
total_cost = 0
for resource, count_cost in resource_cost.items():
rounded_cost = round(count_cost[1], 2)
breakdown.append(BILLITEM(id=len(breakdown) + 1,
resource=resource,
count=count_cost[0],
cost=rounded_cost))
total_cost += rounded_cost
if breakdown:
if start.year == today.year and start.month == today.month:
# Only apply/show the discount for current month
end_str = today.strftime('%Y-%m-%dT%H:00:00')
history_cost[i] = _apply_discount((round(total_cost, 2),
breakdown, cost_details),
start_str,
end_str,
prices)
else:
month_cost = (round(total_cost, 2), breakdown, [])
if month_cost:
CACHE[cache_key] = month_cost
history_cost[i] = month_cost
def _calculate_count_cost(service_details, resource_type):
count = 0
cost = 0
for s in service_details:
if resource_type == 'Image' and s['name'] == 'b1.standard':
count += 1
cost += float(s['cost'])
if SRV_RES_MAPPING.get(s['name'], '') == resource_type:
count += 1
cost += float(s['cost'])
return count, cost
def _calculate_traffic_cost(cost_details, resource_cost):
for resource_type in TRAFFIC_MAPPING.values():
if resource_type in cost_details:
(count, cost) = _calculate_count_cost(cost_details[resource_type],
resource_type)
if cost > 0:
resource_cost[resource_type] = (count, cost)
def _apply_discount(cost, start_str, end_str, prices):
"""Appy discount for the usage costs
For now we only show the discount info for current month cost, because
the discount for history month has shown on customer's invoice.
"""
total_cost, breakdown, cost_details = cost
start = time.mktime(time.strptime(start_str, '%Y-%m-%dT%H:%M:%S'))
end = time.mktime(time.strptime(end_str, '%Y-%m-%dT%H:%M:%S'))
# Get the integer part of the hours
free_hours = math.floor((end - start) / 3600)
free_network_cost = round(prices.get('Network', 0.0164) * free_hours, 2)
free_router_cost = round(prices.get('Router', 0.0170) * free_hours, 2)
for item in breakdown:
if item.resource == 'Network':
free_network_cost = (item.cost if item.cost <= free_network_cost
else free_network_cost)
breakdown[item.id - 1] = item._replace(cost=(item.cost -
free_network_cost))
total_cost -= free_network_cost
if item.resource == 'Router':
free_router_cost = (item.cost if item.cost <= free_router_cost
else free_router_cost)
breakdown[item.id - 1] = item._replace(cost=(item.cost -
free_router_cost))
total_cost -= free_router_cost
return (total_cost, breakdown, cost_details)
def _calculate_start_date(today):
last_year = today.year - 1 if today.month < 12 else today.year
month = ((today.month + 1) % 12 if today.month + 1 > 12
else today.month + 1)
return datetime.datetime(last_year, month, 1)
def _calculate_end_date(start):
year = start.year + 1 if start.month + 1 > 12 else start.year
month = (start.month + 1) % 12 or 12
return datetime.datetime(year, month, 1)
def get_cost(request, distil_client=None, enable_eventlet=True):
"""Get cost for the last 1atest 12 months include current month
This function will return the latest 12 months cost and their breakdown
details, which includes current month.
"""
if enable_eventlet:
eventlet.monkey_patch()
thread_pool = eventlet.GreenPool(size=12)
history_cost = [(0, EMPTY_BREAKDOWN, []) for _ in range(12)]
distil_client = distil_client or distilclient(request)
if not distil_client:
return history_cost
today = datetime.date.today()
start = _calculate_start_date(datetime.date.today())
end = _calculate_end_date(start)
final_end = datetime.datetime(today.year, today.month + 1, 1)
try:
for i in range(12):
start_str = start.strftime("%Y-%m-%dT00:00:00")
end_str = end.strftime("%Y-%m-%dT00:00:00")
thread_pool.spawn_n(_get_month_cost,
distil_client, request.user.tenant_id,
start_str, end_str,
history_cost, i)
start = end
end = _calculate_end_date(start)
if end > final_end:
break
thread_pool.waitall()
except Exception as e:
LOG.exception('Failed to get the history cost data', e)
return history_cost

View File

View File

View File

@ -0,0 +1,104 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import division
import datetime
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from horizon import forms
from horizon import messages
class BaseBilling(object):
def __init__(self, request, project_id=None):
self.project_id = project_id or request.user.tenant_id
self.request = request
self.billing_list = []
@property
def today(self):
return timezone.now()
@staticmethod
def get_start(year, month, day):
start = datetime.datetime(year, month, day, 0, 0, 0)
return timezone.make_aware(start, timezone.utc)
@staticmethod
def get_end(year, month, day):
end = datetime.datetime(year, month, day, 23, 59, 59)
return timezone.make_aware(end, timezone.utc)
def get_date_range(self):
if not hasattr(self, "start") or not hasattr(self, "end"):
args_start = (self.today.year, self.today.month, 1)
args_end = (self.today.year, self.today.month, self.today.day)
form = self.get_form()
if form.is_valid():
start = form.cleaned_data['start']
end = form.cleaned_data['end']
args_start = (start.year,
start.month,
start.day)
args_end = (end.year,
end.month,
end.day)
elif form.is_bound:
messages.error(self.request,
_("Invalid date format: "
"Using today as default."))
self.start = self.get_start(*args_start)
self.end = self.get_end(*args_end)
return self.start, self.end
def init_form(self):
today = datetime.date.today()
self.start = datetime.date(day=1, month=today.month, year=today.year)
self.end = today
return self.start, self.end
def get_form(self):
if not hasattr(self, 'form'):
req = self.request
start = req.GET.get('start', req.session.get('billing_start'))
end = req.GET.get('end', req.session.get('billing_end'))
if start and end:
# bound form
self.form = forms.DateForm({'start': start, 'end': end})
else:
# non-bound form
init = self.init_form()
start = init[0].isoformat()
end = init[1].isoformat()
self.form = forms.DateForm(initial={'start': start,
'end': end})
req.session['billing_start'] = start
req.session['billing_end'] = end
return self.form
def get_billing_list(self, start, end):
return []
def csv_link(self):
form = self.get_form()
data = {}
if hasattr(form, "cleaned_data"):
data = form.cleaned_data
if not ('start' in data and 'end' in data):
data = {"start": self.today.date(), "end": self.today.date()}
return "?start=%s&end=%s&format=csv" % (data['start'],
data['end'])

View File

@ -0,0 +1,22 @@
# Copyright (c) 2014 Catalyst IT Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
import horizon
class Billing(horizon.Panel):
name = _("Usage Costs")
slug = 'billing'

View File

@ -0,0 +1,41 @@
# Copyright (c) 2014 Catalyst IT Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
from horizon import tables
class CSVSummary(tables.LinkAction):
name = "csv_summary"
verbose_name = _("Download CSV Summary")
icon = "download"
def get_link_url(self):
return self.table.kwargs['billing'].csv_link()
class BillingTable(tables.DataTable):
resource = tables.Column("resource",
link=("#"),
verbose_name=_("Resource"))
count = tables.Column("count", verbose_name=_("Count"))
cost = tables.Column("cost", verbose_name=_("Cost"))
class Meta(object):
name = "billing"
verbose_name = _("Breakdown")
columns = ("resource", "count", "cost")
table_actions = (CSVSummary,)
multi_select = False

View File

@ -0,0 +1,3 @@
{% load i18n %}{% trans "Bill Report For Period" %}:,{{ billing.start|date:"b. d Y" }},{{ billing.end|date:"b. d Y" }}
{% trans "Project ID" %}:,{{ billing.project_id }}
Can't render this file because it contains an unexpected character in line 1 and column 25.

View File

@ -0,0 +1,190 @@
{% extends 'base.html' %}
{% load compress %}
{% load i18n %}
{% load i18n sizeformat %}
{% block title %}{% trans "Usage Costs" %}{% endblock %}
{% block css %}
{% include "_stylesheets.html" %}
<link href="{{ STATIC_URL }}catalystdashboard/nv.d3.min.css" rel="stylesheet" type="text/css">
<link href='{{ STATIC_URL }}catalystdashboard/scss/style.css' type='text/css' rel='stylesheet'>
{% endblock %}
{% block page_header %}
{% include "horizon/common/_page_header.html" with title=_("Usage Costs") %}
{% endblock page_header %}
{% block main %}
<p>Disclaimer: This is an estimate for your usage within the current region, not your final invoice. It includes the free router and network discount. All costs are in New Zealand dollars and are exclusive of GST.</p>
<div class="row-fluid">
<div class="col-md-4">
<h3 class="quota-heading dot_line">{% trans "Month to date" %}</h3>
<div id="pie_chart">
<svg class="pie"></svg>
</div>
{{table.render}}
</div>
<div class="col-md-8">
<h3 class="quota-heading dot_line">{% trans "Usage cost history" %}</h3>
<!-- Remove the date range for now
<form action="?" method="get" id="date_form" class="form-horizontal">
<h3>{% trans "Select a period of time to query its cost" %}: </h3>
<div class="datepicker">
{% blocktrans with start=form.start %}
<label>From:</label>{{ start }}{% endblocktrans %}
{% blocktrans with end=form.end %}
<label>To:</label>{{ end }}{% endblocktrans %}
<button class="btn btn-primary" type="submit">{% trans "Submit" %}</button>
<small>{% trans "The date should be in YYYY-mm-dd format." %}</small>
</div>
</form>
-->
<div id="line_chart">
<svg class="line"></svg>
</div>
<table id="service_details" class="table table-striped datatable tablesorter tablesorter-default">
<thead>
<tr class="table_caption">
<th data-column="0" class="table_header" colspan="6">
<h3 class="table_title">Usage Details</h3>
</th>
</tr>
<tr class="tablesorter-headerRow">
<th tabindex="0" data-column="0" class="sortable normal_column tablesorter-header"><div class="tablesorter-header-inner">Resource ID</div></th>
<th tabindex="0" data-column="1" class="sortable normal_column tablesorter-header"><div class="tablesorter-header-inner">Resource Name</div></th>
<th tabindex="0" data-column="2" class="sortable normal_column tablesorter-header"><div class="tablesorter-header-inner">Volume</div></th>
<th tabindex="0" data-column="3" class="sortable normal_column tablesorter-header"><div class="tablesorter-header-inner">Unit</div></th>
<th tabindex="0" data-column="4" class="sortable normal_column tablesorter-header"><div class="tablesorter-header-inner">Rate</div></th>
<th tabindex="0" data-column="5" class="sortable normal_column tablesorter-header"><div class="tablesorter-header-inner">Cost</div></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<!-- Current d3 version is 3.4.1 -->
<script type="text/javascript" src="{{ STATIC_URL }}catalystdashboard/d3.min.js" charset="utf-8"></script>
<script type="text/javascript" src="{{ STATIC_URL }}catalystdashboard/nv.d3.min.js" charset="utf-8"></script>
<script type="text/javascript">
var CHART_DATA = {{chart_data | safe}};
var AMOUNT_COST = {{amount_cost | safe}};
var COST_DETAILS = {{cost_details | safe}};
function draw_pie(where, source){
nv.addGraph(function() {
var chart = nv.models.pieChart()
.x(function(d) { return d.key })
.y(function(d) { return d.value })
.showLabels(true)
.labelType("percent")
.labelThreshold(.05)
.donut(true)
.donutRatio(0.35);
chart.tooltipContent(function(k, v, graph) {
return '<h3>' + k + '</h3>' + '<span style=\'padding:8px\'>$' + v + '</span>'
});
d3.select(where)
.datum(source)
.transition().duration(1200)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
}
function draw_line(where, source){
nv.addGraph(function() {
var months = {{x_axis_line_chart | safe}};
var chart = nv.models.lineChart()
.margin({left: 75})
.size(70);
chart.tooltipContent(function(key, x, y, graph) {
return '<h3>' + key + '</h3>' + '<span style=\'padding:8px\'>$' + y + ' at ' + x + '</span>'
});
chart.legend
.radioButtonMode(true);
chart.xAxis.axisLabel("Cost per Month")
.tickValues([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
.tickFormat(function(m){return months[m]});
chart.yAxis
.axisLabel("Cost (NZD) excl. GST")
.tickFormat(d3.format(',.2f'));
d3.select(where)
.datum(source)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
}
$(document).ready(function(){
draw_pie("#pie_chart .pie", function(){
return CHART_DATA['pie'];
})
draw_line("#line_chart .line", function(){
return CHART_DATA['line'];
})
$('#id_start').attr('disabled', true);
$('#billing tbody tr').each(function(){
$(this).find("td").eq(2).html('$' + $(this).find("td").eq(2).html());
});
$('#billing tfoot td').attr('colspan', 2);
$('#billing tfoot>tr').append('<td><span class="total">$'+AMOUNT_COST+'</span></td>');
var link_mapping = {"Compute": "/instances/",
"Image": "/images/",
"Network": "/networks/",
"Router": "/routers/",
"Block Storage": "/volumes/",
"VPN": "/vpn/vpnservice/"}
$("#billing tbody>tr a")
.click(function() {
var resource_type = $(this).html();
res_cost_details = COST_DETAILS[resource_type]
$('#service_details .table_title').html(resource_type + ' - Usage Details')
$('#service_details').show();
$('#service_details tbody').html('');
if (res_cost_details.length>0){
for (i = 0; i < res_cost_details.length; i++) {
var row_class = i%2==0? 'odd':'even';
var link = "#";
if (resource_type in link_mapping){
link = "http://127.0.0.1:9977/project" + link_mapping[resource_type] + res_cost_details[i]['resource_id'];
}
if (resource_type == 'Network'){
link += '/detail';
}
$('#service_details tbody').append('<tr class='+row_class+'><td><a href="' + link +'">' + res_cost_details[i]['resource_id'] + '</a></td><td>'+res_cost_details[i]['resource']+'</td><td>'+res_cost_details[i]['volume']+'</td><td>'+res_cost_details[i]['unit']+'</td><td>'+res_cost_details[i]['rate']+'</td><td>'+res_cost_details[i]['cost']+'</td></tr>');
}
}
})
$('#service_details').hide();
});
</script>
{% endblock %}

View File

@ -0,0 +1,287 @@
# Copyright (c) 2014 Catalyst IT Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
import math
import time
from mox3 import mox
from distil_ui.api import distil
from openstack_dashboard.test import helpers as test
class FakeUser(object):
roles = [{'name': 'admin'}]
class FakeRequest(object):
user = FakeUser()
class FakeDistilClient(object):
"""A fake distil client for unit test."""
endpoint = 'http://localhost:8788'
request = FakeRequest()
def get_rated(self, tenant, start, end):
raise NotImplemented()
class BillingTests(test.TestCase):
"""FIXME(flwang): Move this test to rest_api_tests.py
Now we're putting the api test at here, since we don't want to hack
horizon too much. That means we don't want to put the api.py under /api
folder, at least for now.
"""
def setUp(self):
super(BillingTests, self).setUp()
self.mocker = mox.Mox()
def test_calculate_end_date(self):
start = datetime.date(2015, 1, 1)
end = distil._calculate_end_date(start)
self.assertEqual((end.year, end.month, end.day), (2015, 2, 1))
start = datetime.date(2015, 6, 1)
end = distil._calculate_end_date(start)
self.assertEqual((end.year, end.month, end.day), (2015, 7, 1))
start = datetime.date(2015, 12, 1)
end = distil._calculate_end_date(start)
self.assertEqual((end.year, end.month, end.day), (2016, 1, 1))
def test_get_month_cost(self):
distilclient = self.mocker.CreateMock(FakeDistilClient)
resources = {"fake_uuid_1": {"services": [{
"volume": 2100,
"rate": 0.0005,
"cost": 1.05,
"name": "b1.standard",
"unit": "gigabyte"}],
"total_cost": 1.05,
"type": "Image",
"name": "cirros"},
"fake_uuid_2": {"services": [{
"volume": 122,
"rate": 0.048,
"cost": 5.86,
"name": "m1.tiny",
"unit": "hour"}],
"total_cost": 5.86,
"type": "Virtual Machine",
"name": "dfgh"},
"fake_uuid_3": {"services": [{
"volume": 200,
"rate": 0.048,
"cost": 9.60,
"name": "m1.tiny",
"unit": "hour"}],
"total_cost": 9.60,
"type": "Virtual Machine",
"name": "abcd"},
"fake_uuid_4": {"services": [{"volume": 20.00,
"rate": 0.016,
"cost": 0.32,
"name": "n1.network",
"unit": "hour"},
{"volume": 10.00,
"rate": 0.016,
"cost": 0.16,
"name": "n1.network",
"unit": "hour"}],
"total_cost": 0.48,
"type": "Network",
"name": "public"}
}
result = {'usage': {"end": "2011-03-01 00:00:00", "name": "openstack",
"total_cost": 7.23,
"tenant_id": "7c3c506ad4b943f5bb12b9fb69478084",
"start": "2011-02-01 00:00:00",
"resources": resources
}
}
distilclient.get_rated([self.tenant.id],
'2011-02-01T00:00:00',
'2011-03-01T00:00:00').AndReturn(result)
self.mocker.ReplayAll()
cost = [()]
distil._get_month_cost(distilclient,
self.tenant.id,
'2011-02-01T00:00:00',
'2011-03-01T00:00:00',
cost, 0)
self.assertEqual(16.99, cost[0][0])
self.assertEqual(3, len(cost[0][1]))
bill_items = {}
for b in cost[0][1]:
# Convert cost to string make sure the floating number is right
bill_items[b.resource] = (b.count, str(b.cost))
self.assertEqual((2, '0.48'), bill_items['Network'])
self.assertEqual((2, '15.46'), bill_items['Compute'])
self.assertEqual((1, '1.05'), bill_items['Image'])
def test_calculate_history_date(self):
"""Using the same algorithm to calculate the history date."""
today = datetime.date(2015, 2, 17)
start = distil._calculate_start_date(datetime.date(2015, 2, 17))
end = distil._calculate_end_date(start)
final_end = datetime.datetime(today.year, today.month + 1, 1)
history_date = [None for i in range(12)]
for i in range(12):
start_str = start.strftime("%Y-%m-%dT00:00:00")
end_str = end.strftime("%Y-%m-%dT00:00:00")
history_date[i] = (start_str, end_str)
start = end
end = distil._calculate_end_date(start)
if end > final_end:
break
self.assertEqual(('2014-03-01T00:00:00', '2014-04-01T00:00:00'),
history_date[0])
self.assertEqual(('2014-04-01T00:00:00', '2014-05-01T00:00:00'),
history_date[1])
self.assertEqual(('2014-05-01T00:00:00', '2014-06-01T00:00:00'),
history_date[2])
self.assertEqual(('2014-06-01T00:00:00', '2014-07-01T00:00:00'),
history_date[3])
self.assertEqual(('2014-07-01T00:00:00', '2014-08-01T00:00:00'),
history_date[4])
self.assertEqual(('2014-08-01T00:00:00', '2014-09-01T00:00:00'),
history_date[5])
self.assertEqual(('2014-09-01T00:00:00', '2014-10-01T00:00:00'),
history_date[6])
self.assertEqual(('2014-10-01T00:00:00', '2014-11-01T00:00:00'),
history_date[7])
self.assertEqual(('2014-11-01T00:00:00', '2014-12-01T00:00:00'),
history_date[8])
self.assertEqual(('2014-12-01T00:00:00', '2015-01-01T00:00:00'),
history_date[9])
self.assertEqual(('2015-01-01T00:00:00', '2015-02-01T00:00:00'),
history_date[10])
self.assertEqual(('2015-02-01T00:00:00', '2015-03-01T00:00:00'),
history_date[11])
def test_get_cost(self):
distilclient = self.mocker.CreateMock(FakeDistilClient)
today = datetime.date.today()
start = distil._calculate_start_date(datetime.date.today())
end = distil._calculate_end_date(start)
final_end = datetime.datetime(today.year, today.month + 1, 1)
for i in range(12):
result = {'usage': {'total_cost': (i + 1) * 100,
'resources': {'uuid': {"services": [{
"volume": 2100,
"rate": 0.0005,
"cost": 1.05,
"name": "b1.standard",
"unit": "gigabyte"}],
"total_cost": 1.05,
"type": "Image",
"name": "cirros"}}}}
start_str = start.strftime("%Y-%m-%dT00:00:00")
end_str = end.strftime("%Y-%m-%dT00:00:00")
distilclient.get_rated([self.tenant.id],
start_str,
end_str).AndReturn(result)
start = end
end = distil._calculate_end_date(start)
if end > final_end:
break
self.mocker.ReplayAll()
setattr(self.request.user, 'tenant_id', self.tenant.id)
history_cost = distil.get_cost(self.request,
distil_client=distilclient,
enable_eventlet=False)
# 2 = math.ceil(1.05)
self.assertEqual([1.05 for i in range(12)],
[c[0] for c in history_cost])
def test_apply_discount(self):
# There are 3 scenarios for current month.
cost = (47.54,
[distil.BILLITEM(id=1, resource='Compute', count=9,
cost=31.76),
distil.BILLITEM(id=2, resource=u'Network', count=3, cost=1.5),
distil.BILLITEM(id=3, resource=u'Image', count=35, cost=3.82),
distil.BILLITEM(id=4, resource=u'Router', count=2, cost=0.96),
distil.BILLITEM(id=5, resource=u'Floating IP', count=21,
cost=3.57),
distil.BILLITEM(id=6, resource='Block Storage', count=22,
cost=6.08)
], [])
prices = {u'Virtual Machine': 0.044, u'Network': 0.016,
u'Image': 0.0005, u'Volume': 0.0005,
u'Router': 0.017, u'Floating IP': 0.006}
start_str = '2015-07-01T00:00:00'
end_str = '2015-07-02T04:00:00'
cost_after_discount = distil._apply_discount(cost, start_str, end_str,
prices)
start = time.mktime(time.strptime(start_str, '%Y-%m-%dT%H:%M:%S'))
end = time.mktime(time.strptime(end_str, '%Y-%m-%dT%H:%M:%S'))
free_hours = math.floor((end - start) / 3600)
free_network_cost = round(0.016 * free_hours, 2)
free_router_cost = round(0.017 * free_hours, 2)
self.assertEqual(cost[0] - free_network_cost - free_router_cost,
cost_after_discount[0])
self.assertIn(distil.BILLITEM(id=2, resource=u'Network', count=3,
cost=1.05),
cost_after_discount[1])
self.assertIn(distil.BILLITEM(id=4, resource=u'Router', count=2,
cost=0.48),
cost_after_discount[1])
def test_get_month_cost_with_cache(self):
distil.CACHE.clear()
distilclient = self.mocker.CreateMock(FakeDistilClient)
result = {'usage': {'total_cost': 5.05,
'resources': {'uuid':
{"services": [{"volume": 2100,
"rate": 0.0005,
"cost": 5.05,
"name": "b1.standard",
"unit": "gigabyte"}],
"total_cost": 5.05,
"type": "Image",
"name": "cirros"}}}}
distilclient.get_rated([self.tenant.id],
'2011-02-01T00:00:00',
'2011-03-01T00:00:00').AndReturn(result)
self.mocker.ReplayAll()
cost = [()]
distil._get_month_cost(distilclient,
self.tenant.id,
'2011-02-01T00:00:00',
'2011-03-01T00:00:00',
cost, 0)
key = 'http://localhost:8788_1_2011-02-01T00:00:00_2011-03-01T00:00:00'
self.assertIn(key, distil.CACHE)
self.assertEqual(distil.CACHE[key][0], 5.05)

View File

@ -0,0 +1,23 @@
# Copyright (c) 2014 Catalyst IT Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from django.conf.urls import patterns # noqa
from django.conf.urls import url # noqa
from distil_ui.content.billing import views
urlpatterns = patterns(
'',
url(r'^$', views.IndexView.as_view(), name='index'),
)

View File

@ -0,0 +1,116 @@
# Copyright (c) 2014 Catalyst IT Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
import json
from django.template import defaultfilters
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import tables as horizon_tables
from horizon.utils import csvbase
from distil_ui.api import distil
from distil_ui.content.billing import base
from distil_ui.content.billing import tables
class IndexCsvRenderer(csvbase.BaseCsvResponse):
columns = [_("Resource"), _("Count"), _("Cost")]
def get_row_data(self):
for b in self.context['current_month']:
yield (b.resource,
b.count,
defaultfilters.floatformat(b.cost, 2))
class IndexView(horizon_tables.DataTableView):
table_class = tables.BillingTable
show_terminated = True
csv_template_name = 'management/billing/billing.csv'
template_name = 'management/billing/index.html'
csv_response_class = IndexCsvRenderer
def __init__(self, *args, **kwargs):
super(IndexView, self).__init__(*args, **kwargs)
def get_template_names(self):
if self.request.GET.get('format', 'html') == 'csv':
return (self.csv_template_name or
".".join((self.template_name.rsplit('.', 1)[0], 'csv')))
return self.template_name
def get_content_type(self):
if self.request.GET.get('format', 'html') == 'csv':
return "text/csv"
return "text/html"
def get_data(self):
try:
project_id = self.kwargs.get('project_id',
self.request.user.tenant_id)
self.billing = base.BaseBilling(self.request, project_id)
self.start, self.end = self.billing.get_date_range()
distil_client = distil.distilclient(self.request)
self.history = (distil.get_cost(self.request, distil_client))
self.kwargs['billing'] = self.billing
self.kwargs['current_month'] = self.history[-1][1]
self.kwargs['history'] = self.history
return self.history[-1][1]
except Exception:
exceptions.handle(self.request, _('Unable to get usage cost.'))
return []
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
context['table'].kwargs['billing'] = self.billing
context['form'] = self.billing.form
context['billing'] = self.billing
context['current_month'] = self.history[-1][1]
pie_data = [{"value": b.cost, "key": b.resource}
for b in self.history[-1][1] if b.cost >= 0]
line_data = [{"values": [{"y": m[0], "x": i}
for i, m in enumerate(self.history)],
"method": "Square Root Choice", "key": "Cost"}]
chart_data = {'pie': pie_data, 'line': line_data}
context['chart_data'] = json.dumps(chart_data)
context['amount_cost'] = self.history[-1][0]
context['cost_details'] = json.dumps(self.history[-1][2])
context['x_axis_line_chart'] = self._get_x_axis_for_line_chart()
return context
def _get_x_axis_for_line_chart(self):
today = datetime.date.today()
ordered_month = ['Jan ' + str(today.year), 'Feb', 'Mar', "Apr", 'May',
'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
return ordered_month[today.month:] + ordered_month[:today.month]
def render_to_response(self, context, **response_kwargs):
if self.request.GET.get('format', 'html') == 'csv':
render_class = self.csv_response_class
fn_template = "usage_cost_{0}_{1}.csv"
filename = fn_template.format(self.start.strftime('%Y-%m-%d'),
self.end.strftime('%Y-%m-%d'))
response_kwargs.setdefault("filename", filename)
else:
render_class = self.response_class
resp = render_class(request=self.request,
template=self.get_template_names(),
context=context,
content_type=self.get_content_type(),
**response_kwargs)
return resp

View File

View File

@ -0,0 +1,24 @@
# Copyright (c) 2014 Catalyst IT Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
import horizon
class Default(horizon.Panel):
name = _("Default")
slug = 'default'
urls = 'openstack_dashboard.contrib.management.tickets.urls'
nav = False

View File

@ -0,0 +1,3 @@
{% extends 'base.html' %}

38
distil_ui/dashboard.py Normal file
View File

@ -0,0 +1,38 @@
# Copyright (c) 2014 Catalyst IT Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
import horizon
from distil_ui.content.billing import panel as billing_panel
from distil_ui.content.default import panel as default_panel
class ManagementDashboard(horizon.Dashboard):
name = _("Management")
slug = "management"
default_panel = 'default'
try:
slugs = dict((d.slug, d) for d in horizon.get_dashboards())
except Exception:
slugs = {}
if 'management' not in slugs:
horizon.register(ManagementDashboard)
ManagementDashboard.register(default_panel.Default)
ManagementDashboard.register(billing_panel.Billing)
else:
slugs.get('management').register(billing_panel.Billing)

View File

@ -0,0 +1,7 @@
# The name of the dashboard to be added to HORIZON['dashboards']. Required.
DASHBOARD = 'management'
# A list of applications to be added to INSTALLED_APPS.
ADD_INSTALLED_APPS = [
'distil_ui.dashboard'
]

View File

@ -0,0 +1,20 @@
# Copyright 2017 Catalyst IT Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
PANEL = 'billing'
PANEL_GROUP = 'default'
PANEL_DASHBOARD = 'management'
ADD_PANEL = ('distil_ui.content.billing.panel.Billing')
ADD_INSTALLED_APPS = ['distil_ui']

View File

155
distil_ui/karma.conf.js Normal file
View File

@ -0,0 +1,155 @@
/*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
var fs = require('fs');
var path = require('path');
module.exports = function (config) {
// This tox venv is setup in the post-install npm step
var toxPath = '../.tox/py27/lib/python2.7/site-packages/';
config.set({
preprocessors: {
// Used to collect templates for preprocessing.
// NOTE: the templates must also be listed in the files section below.
'./static/**/*.html': ['ng-html2js'],
// Used to indicate files requiring coverage reports.
'./static/**/!(*.spec).js': ['coverage'],
},
// Sets up module to process templates.
ngHtml2JsPreprocessor: {
prependPrefix: '/',
moduleName: 'templates'
},
basePath: './',
// Contains both source and test files.
files: [
/*
* shim, partly stolen from /i18n/js/horizon/
* Contains expected items not provided elsewhere (dynamically by
* Django or via jasmine template.
*/
'../test-shim.js',
// from jasmine.html
toxPath + 'xstatic/pkg/jquery/data/jquery.js',
toxPath + 'xstatic/pkg/angular/data/angular.js',
toxPath + 'xstatic/pkg/angular/data/angular-route.js',
toxPath + 'xstatic/pkg/angular/data/angular-mocks.js',
toxPath + 'xstatic/pkg/angular/data/angular-cookies.js',
toxPath + 'xstatic/pkg/angular_bootstrap/data/angular-bootstrap.js',
toxPath + 'xstatic/pkg/angular_gettext/data/angular-gettext.js',
toxPath + 'xstatic/pkg/angular/data/angular-sanitize.js',
toxPath + 'xstatic/pkg/d3/data/d3.js',
toxPath + 'xstatic/pkg/rickshaw/data/rickshaw.js',
toxPath + 'xstatic/pkg/angular_smart_table/data/smart-table.js',
toxPath + 'xstatic/pkg/angular_lrdragndrop/data/lrdragndrop.js',
toxPath + 'xstatic/pkg/spin/data/spin.js',
toxPath + 'xstatic/pkg/spin/data/spin.jquery.js',
toxPath + 'xstatic/pkg/tv4/data/tv4.js',
toxPath + 'xstatic/pkg/objectpath/data/ObjectPath.js',
toxPath + 'xstatic/pkg/angular_schema_form/data/schema-form.js',
// TODO: These should be mocked.
toxPath + '/horizon/static/horizon/js/horizon.js',
/**
* Include framework source code from horizon that we need.
* Otherwise, karma will not be able to find them when testing.
* These files should be mocked in the foreseeable future.
*/
toxPath + 'horizon/static/framework/**/*.module.js',
toxPath + 'horizon/static/framework/**/!(*.spec|*.mock).js',
toxPath + 'openstack_dashboard/static/**/*.module.js',
toxPath + 'openstack_dashboard/static/**/!(*.spec|*.mock).js',
toxPath + 'openstack_dashboard/dashboards/**/static/**/*.module.js',
toxPath + 'openstack_dashboard/dashboards/**/static/**/!(*.spec|*.mock).js',
/**
* First, list all the files that defines application's angular modules.
* Those files have extension of `.module.js`. The order among them is
* not significant.
*/
'./static/**/*.module.js',
/**
* Followed by other JavaScript files that defines angular providers
* on the modules defined in files listed above. And they are not mock
* files or spec files defined below. The order among them is not
* significant.
*/
'./static/**/!(*.spec|*.mock).js',
/**
* Then, list files for mocks with `mock.js` extension. The order
* among them should not be significant.
*/
toxPath + 'openstack_dashboard/static/**/*.mock.js',
/**
* Finally, list files for spec with `spec.js` extension. The order
* among them should not be significant.
*/
'./static/**/*.spec.js',
/**
* Angular external templates
*/
'./static/**/*.html'
],
autoWatch: true,
frameworks: ['jasmine'],
browsers: ['PhantomJS'],
browserNoActivityTimeout: 60000,
phantomjsLauncher: {
// Have phantomjs exit if a ResourceError is encountered
// (useful if karma exits without killing phantom)
exitOnResourceError: true
},
reporters: ['progress', 'coverage', 'threshold'],
plugins: [
'karma-phantomjs-launcher',
'karma-jasmine',
'karma-ng-html2js-preprocessor',
'karma-coverage',
'karma-threshold-reporter'
],
// Places coverage report in HTML format in the subdirectory below.
coverageReporter: {
type: 'html',
dir: '../cover/karma/'
},
// Coverage threshold values.
thresholdReporter: {
statements: 10, // target 100
branches: 0, // target 100
functions: 10, // target 100
lines: 10 // target 100
}
});
};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,44 @@
#line_chart .nv-lineChart circle.nv-point {
fill-opacity: 1;
}
#line_chart .nvd3 .nv-legend .nv-series {
cursor:default;
}
.form-horizontal label {
display: inline;
margin-bottom: 0;
margin-right: 5px;
font-weight: normal;
}
.pie {
width:100%;
height:360px
}
.line {
width:100%;
height:360px;
}
#billing .total {
font-size: 14px;
font-weight:bold;
}
.dot_line {
padding-bottom: 6px;
border-bottom: thin dotted #666;
}
@media screen and (max-width: 1025px) {
.row-fluid > [class*="span"] {
width:100% !important;
}
body {
min-width: 700px;
}
}

View File

View File

View File

@ -0,0 +1,28 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from openstack_dashboard.test.test_data import utils
from distil_ui.test import test_data
TEST = utils.TestData(test_data.data)
def mock_resource(resource):
"""Utility function to make mocking more DRY"""
mocked_data = \
[mock.Mock(**{'to_dict.return_value': item}) for item in resource]
return mocked_data

20
distil_ui/test/helpers.py Normal file
View File

@ -0,0 +1,20 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from openstack_dashboard.test import helpers
class APITestCase(helpers.APITestCase):
"""Extends the base Horizon APITestCase for distilclient"""
def setUp(self):
super(APITestCase, self).setUp()

View File

@ -0,0 +1,38 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Default to Horizons test settings to avoid any missing keys
from horizon.test.settings import * # noqa
from openstack_dashboard.test.settings import * # noqa
# Update the dashboards with distil_ui
import openstack_dashboard.enabled
from openstack_dashboard.utils import settings
import distil_ui.enabled
# pop these keys to avoid log warnings about deprecation
# update_dashboards will populate them anyway
HORIZON_CONFIG.pop('dashboards', None)
HORIZON_CONFIG.pop('default_dashboard', None)
settings.update_dashboards(
[
distil_ui.enabled,
openstack_dashboard.enabled,
],
HORIZON_CONFIG,
INSTALLED_APPS
)
# Ensure any duplicate apps are removed after the update_dashboards call
INSTALLED_APPS = list(set(INSTALLED_APPS))

View File

@ -0,0 +1,18 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from openstack_dashboard.test.test_data import utils
def data(TEST):
# Test Data Container in Horizon
TEST.queues = utils.TestDataContainer()

15
distil_ui/version.py Normal file
View File

@ -0,0 +1,15 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import pbr.version
version_info = pbr.version.VersionInfo('distil-ui')

153
doc/Makefile Normal file
View File

@ -0,0 +1,153 @@
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = build
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
-rm -rf $(BUILDDIR)/*
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Cisco.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Cisco.qhc"
devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/Cisco"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Cisco"
@echo "# devhelp"
epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."
man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
texinfo:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."
info:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."

441
doc/source/conf.py Normal file
View File

@ -0,0 +1,441 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# Horizon documentation build configuration file, created by
# sphinx-quickstart on Thu Oct 27 11:38:59 2011.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
from __future__ import print_function
import os
import subprocess
import sys
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.abspath(os.path.join(BASE_DIR, "..", ".."))
sys.path.insert(0, ROOT)
# This is required for ReadTheDocs.org, but isn't a bad idea anyway.
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
'openstack_dashboard.test.settings')
from distil_ui \
import version as distilui_ver
def write_autodoc_index():
def find_autodoc_modules(module_name, sourcedir):
"""returns a list of modules in the SOURCE directory."""
modlist = []
os.chdir(os.path.join(sourcedir, module_name))
print("SEARCHING %s" % sourcedir)
for root, dirs, files in os.walk("."):
for filename in files:
if filename == 'tests.py':
continue
if filename.endswith(".py"):
# remove the pieces of the root
elements = root.split(os.path.sep)
# replace the leading "." with the module name
elements[0] = module_name
# and get the base module name
base, extension = os.path.splitext(filename)
if not (base == "__init__"):
elements.append(base)
result = ".".join(elements)
# print result
modlist.append(result)
return modlist
RSTDIR = os.path.abspath(os.path.join(BASE_DIR, "sourcecode"))
SRCS = [('distil_ui', ROOT), ]
EXCLUDED_MODULES = ()
CURRENT_SOURCES = {}
if not(os.path.exists(RSTDIR)):
os.mkdir(RSTDIR)
CURRENT_SOURCES[RSTDIR] = ['autoindex.rst']
INDEXOUT = open(os.path.join(RSTDIR, "autoindex.rst"), "w")
INDEXOUT.write("""
=================
Source Code Index
=================
.. contents::
:depth: 1
:local:
""")
for modulename, path in SRCS:
sys.stdout.write("Generating source documentation for %s\n" %
modulename)
INDEXOUT.write("\n%s\n" % modulename.capitalize())
INDEXOUT.write("%s\n" % ("=" * len(modulename),))
INDEXOUT.write(".. toctree::\n")
INDEXOUT.write(" :maxdepth: 1\n")
INDEXOUT.write("\n")
MOD_DIR = os.path.join(RSTDIR, modulename)
CURRENT_SOURCES[MOD_DIR] = []
if not(os.path.exists(MOD_DIR)):
os.mkdir(MOD_DIR)
for module in find_autodoc_modules(modulename, path):
if any([module.startswith(exclude) for exclude
in EXCLUDED_MODULES]):
print("Excluded module %s." % module)
continue
mod_path = os.path.join(path, *module.split("."))
generated_file = os.path.join(MOD_DIR, "%s.rst" % module)
INDEXOUT.write(" %s/%s\n" % (modulename, module))
# Find the __init__.py module if this is a directory
if os.path.isdir(mod_path):
source_file = ".".join((os.path.join(mod_path, "__init__"),
"py",))
else:
source_file = ".".join((os.path.join(mod_path), "py"))
CURRENT_SOURCES[MOD_DIR].append("%s.rst" % module)
# Only generate a new file if the source has changed or we don't
# have a doc file to begin with.
if not os.access(generated_file, os.F_OK) or (
os.stat(generated_file).st_mtime <
os.stat(source_file).st_mtime):
print("Module %s updated, generating new documentation."
% module)
FILEOUT = open(generated_file, "w")
header = "The :mod:`%s` Module" % module
FILEOUT.write("%s\n" % ("=" * len(header),))
FILEOUT.write("%s\n" % header)
FILEOUT.write("%s\n" % ("=" * len(header),))
FILEOUT.write(".. automodule:: %s\n" % module)
FILEOUT.write(" :members:\n")
FILEOUT.write(" :undoc-members:\n")
FILEOUT.write(" :show-inheritance:\n")
FILEOUT.write(" :noindex:\n")
FILEOUT.close()
INDEXOUT.close()
# Delete auto-generated .rst files for sources which no longer exist
for directory, subdirs, files in list(os.walk(RSTDIR)):
for old_file in files:
if old_file not in CURRENT_SOURCES.get(directory, []):
print("Removing outdated file for %s" % old_file)
os.remove(os.path.join(directory, old_file))
write_autodoc_index()
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# sys.path.insert(0, os.path.abspath('.'))
# -- General configuration ----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
# needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings.
# They can be extensions coming with Sphinx (named 'sphinx.ext.*')
# or your custom ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.viewcode',
'oslosphinx',
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
# source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'Distil UI'
copyright = u'2017, Catalyst IT Ltd'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = distilui_ver.version_info.version_string()
# The full version, including alpha/beta/rc tags.
release = distilui_ver.version_info.release_string()
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
# language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
# today = ''
# Else, today_fmt is used as the format for a strftime call.
# today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['**/#*', '**~', '**/#*#']
# The reST default role (used for this markup: `text`)
# to use for all documents.
# default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
# add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
# add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
primary_domain = 'py'
nitpicky = False
# -- Options for HTML output --------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
# html_theme_path = ['.']
# html_theme = '_theme'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
"nosidebar": "false"
}
# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
# html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
# html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
# html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
# html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
# html_last_updated_fmt = '%b %d, %Y'
git_cmd = ["git", "log", "--pretty=format:'%ad, commit %h'", "--date=local",
"-n1"]
html_last_updated_fmt = subprocess.check_output(git_cmd,
stdin=subprocess.PIPE)
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
# html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
# html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
# html_additional_pages = {}
# If false, no module index is generated.
# html_domain_indices = True
# If false, no index is generated.
# html_use_index = True
# If true, the index is split into individual pages for each letter.
# html_split_index = False
# If true, links to the reST sources are added to the pages.
# html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
# html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
# html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
# html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
# html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'Horizondoc'
# -- Options for LaTeX output -------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
# 'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass
# [howto/manual]).
latex_documents = [
('index', 'Horizon.tex', u'Horizon Documentation',
u'OpenStack Foundation', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
# latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
# latex_use_parts = False
# If true, show page references after internal links.
# latex_show_pagerefs = False
# If true, show URL addresses after external links.
# latex_show_urls = False
# Documents to append as an appendix to all manuals.
# latex_appendices = []
# If false, no module index is generated.
# latex_domain_indices = True
# -- Options for manual page output -------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', u'Distil UI Documentation',
'Documentation for the Distil UI plugin to the OpenStack\
Dashboard (Horizon)',
[u'OpenStack'], 1)
]
# If true, show URL addresses after external links.
# man_show_urls = False
# -- Options for Texinfo output -----------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'Horizon', u'Horizon Documentation', u'OpenStack',
'Horizon', 'One line description of project.', 'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
# texinfo_appendices = []
# If false, no module index is generated.
# texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
# texinfo_show_urls = 'footnote'
# -- Options for Epub output --------------------------------------------------
# Bibliographic Dublin Core info.
epub_title = u'Horizon'
epub_author = u'OpenStack'
epub_publisher = u'OpenStack'
epub_copyright = u'2012, OpenStack'
# The language of the text. It defaults to the language option
# or en if the language is not set.
# epub_language = ''
# The scheme of the identifier. Typical schemes are ISBN or URL.
# epub_scheme = ''
# The unique identifier of the text. This can be an ISBN number
# or the project homepage.
# epub_identifier = ''
# A unique identification for the text.
# epub_uid = ''
# A tuple containing the cover image and cover page html template filenames.
# epub_cover = ()
# HTML files that should be inserted before the pages created by sphinx.
# The format is a list of tuples containing the path and title.
# epub_pre_files = []
# HTML files shat should be inserted after the pages created by sphinx.
# The format is a list of tuples containing the path and title.
# epub_post_files = []
# A list of files that should not be packed into the epub file.
# epub_exclude_files = []
# The depth of the table of contents in toc.ncx.
# epub_tocdepth = 3
# Allow duplicate toc entries.
# epub_tocdup = True

63
doc/source/index.rst Normal file
View File

@ -0,0 +1,63 @@
===============================
distil-ui
===============================
Distil Dashboard
* Free software: Apache license
* Source: http://git.openstack.org/cgit/openstack/distil-ui
Installation instructions
=========================
Begin by cloning the Horizon and Distil UI repositories::
git clone https://github.com/openstack/horizon
git clone https://github.com/openstack/distil-ui
Create a virtual environment and install Horizon dependencies::
cd horizon
python tools/install_venv.py
Set up your ``local_settings.py`` file::
cp openstack_dashboard/local/local_settings.py.example openstack_dashboard/local/local_settings.py
Open up the copied ``local_settings.py`` file in your preferred text
editor. You will want to customize several settings:
- ``OPENSTACK_HOST`` should be configured with the hostname of your
OpenStack server. Verify that the ``OPENSTACK_KEYSTONE_URL`` and
``OPENSTACK_KEYSTONE_DEFAULT_ROLE`` settings are correct for your
environment. (They should be correct unless you modified your
OpenStack server to change them.)
Install Distil UI with all dependencies in your virtual environment::
tools/with_venv.sh pip install -e ../distil-ui/
And enable it in Horizon::
cp ../distil-ui/enabled/_6010_management_billing.py openstack_dashboard/local/enabled
Release Notes
=============
.. toctree::
:glob:
:maxdepth: 1
releases/*
Source Code Reference
=====================
.. toctree::
:glob:
:maxdepth: 1
sourcecode/autoindex

View File

@ -0,0 +1,35 @@
=================
Source Code Index
=================
.. contents::
:depth: 1
:local:
Distil_ui
=========
.. toctree::
:maxdepth: 1
distil_ui/distil_ui.version
distil_ui/distil_ui
distil_ui/distil_ui.content
distil_ui/distil_ui.content.billing.urls
distil_ui/distil_ui.content.billing.panel
distil_ui/distil_ui.content.billing.tables
distil_ui/distil_ui.content.billing.base
distil_ui/distil_ui.content.billing
distil_ui/distil_ui.content.billing.views
distil_ui/distil_ui.api.distil
distil_ui/distil_ui.api
distil_ui/distil_ui.enabled._6010_management_billing
distil_ui/distil_ui.enabled
distil_ui/distil_ui.test.helpers
distil_ui/distil_ui.test.test_data
distil_ui/distil_ui.test.settings
distil_ui/distil_ui.test
distil_ui/distil_ui.test.integration_tests
distil_ui/distil_ui.test.api_tests
distil_ui/distil_ui.test.api_tests.rest_api_tests

View File

@ -0,0 +1,8 @@
======================================
The :mod:`distil_ui.api.distil` Module
======================================
.. automodule:: distil_ui.api.distil
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
===============================
The :mod:`distil_ui.api` Module
===============================
.. automodule:: distil_ui.api
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
================================================
The :mod:`distil_ui.content.billing.base` Module
================================================
.. automodule:: distil_ui.content.billing.base
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
=================================================
The :mod:`distil_ui.content.billing.panel` Module
=================================================
.. automodule:: distil_ui.content.billing.panel
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
===========================================
The :mod:`distil_ui.content.billing` Module
===========================================
.. automodule:: distil_ui.content.billing
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
==================================================
The :mod:`distil_ui.content.billing.tables` Module
==================================================
.. automodule:: distil_ui.content.billing.tables
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
================================================
The :mod:`distil_ui.content.billing.urls` Module
================================================
.. automodule:: distil_ui.content.billing.urls
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
=================================================
The :mod:`distil_ui.content.billing.views` Module
=================================================
.. automodule:: distil_ui.content.billing.views
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
===================================
The :mod:`distil_ui.content` Module
===================================
.. automodule:: distil_ui.content
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
============================================================
The :mod:`distil_ui.enabled._6010_management_billing` Module
============================================================
.. automodule:: distil_ui.enabled._6010_management_billing
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
===================================
The :mod:`distil_ui.enabled` Module
===================================
.. automodule:: distil_ui.enabled
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
===========================
The :mod:`distil_ui` Module
===========================
.. automodule:: distil_ui
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
=========================================================
The :mod:`distil_ui.test.api_tests.rest_api_tests` Module
=========================================================
.. automodule:: distil_ui.test.api_tests.rest_api_tests
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
==========================================
The :mod:`distil_ui.test.api_tests` Module
==========================================
.. automodule:: distil_ui.test.api_tests
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
========================================
The :mod:`distil_ui.test.helpers` Module
========================================
.. automodule:: distil_ui.test.helpers
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
==================================================
The :mod:`distil_ui.test.integration_tests` Module
==================================================
.. automodule:: distil_ui.test.integration_tests
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
================================
The :mod:`distil_ui.test` Module
================================
.. automodule:: distil_ui.test
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
=========================================
The :mod:`distil_ui.test.settings` Module
=========================================
.. automodule:: distil_ui.test.settings
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
==========================================
The :mod:`distil_ui.test.test_data` Module
==========================================
.. automodule:: distil_ui.test.test_data
:members:
:undoc-members:
:show-inheritance:
:noindex:

View File

@ -0,0 +1,8 @@
===================================
The :mod:`distil_ui.version` Module
===================================
.. automodule:: distil_ui.version
:members:
:undoc-members:
:show-inheritance:
:noindex:

23
manage.py Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import sys
from django.core.management import execute_from_command_line # noqa
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE",
"openstack_dashboard.settings")
execute_from_command_line(sys.argv)

35
package.json Normal file
View File

@ -0,0 +1,35 @@
{
"name": "distil-ui",
"description": "Distil UI JavaScript tests",
"repository": {
"type": "git",
"url": "git://git.openstack.org/openstack/distil-ui"
},
"version": "0.0.0",
"private": true,
"license": "Apache 2.0",
"author": "Openstack <openstack-dev@lists.openstack.org>",
"devDependencies": {
"eslint": "^1.10.3",
"eslint-config-openstack": "^1.2.4",
"eslint-plugin-angular": "1.0.1",
"jasmine-core": "2.4.1",
"karma": "1.1.2",
"karma-chrome-launcher": "1.0.1",
"karma-cli": "1.0.1",
"karma-coverage": "1.1.1",
"karma-jasmine": "1.0.2",
"karma-ng-html2js-preprocessor": "1.0.0",
"karma-phantomjs-launcher": "0.2.0",
"karma-threshold-reporter": "0.1.15",
"phantomjs": "1.9.17"
},
"dependencies": {},
"scripts": {
"postinstall": "if [ ! -d .tox ] || [ ! -d .tox/py27 ]; then tox -epy27 --notest; fi",
"lint": "eslint --no-color distil_ui/static",
"lintq": "eslint --quiet distil_ui/static",
"test": "karma start distil_ui/karma.conf.js --single-run"
}
}

17
requirements.txt Normal file
View File

@ -0,0 +1,17 @@
# The order of packages is significant, because pip processes them in the order
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
# Order matters to the pip dependency resolver, so sorting this file
# changes how packages are installed. New dependencies should be
# added in alphabetical order, however, some dependencies may need to
# be installed in a specific order.
#
# PBR should always appear first
pbr>=2.0.0 # Apache-2.0
Babel>=2.3.4,!=2.4.0 # BSD
Django<1.9,>=1.8 # BSD
django-babel>=0.5.1 # BSD
# NOTE(flwang): We can use this after distilclient is added into
# openstack-requirements.
#python-distilclient>=0.2.0 # Apache-2.0

583
run_tests.sh Executable file
View File

@ -0,0 +1,583 @@
#!/bin/bash
set -o errexit
function usage {
echo "Usage: $0 [OPTION]..."
echo "Run Horizon's test suite(s)"
echo ""
echo " -V, --virtual-env Always use virtualenv. Install automatically"
echo " if not present"
echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local"
echo " environment"
echo " -c, --coverage Generate reports using Coverage"
echo " -f, --force Force a clean re-build of the virtual"
echo " environment. Useful when dependencies have"
echo " been added."
echo " -m, --manage Run a Django management command."
echo " --makemessages Create/Update English translation files."
echo " --compilemessages Compile all translation files."
echo " --check-only Do not update translation files (--makemessages only)."
echo " --pseudo Pseudo translate a language."
echo " -p, --pep8 Just run pep8"
echo " -8, --pep8-changed [<basecommit>]"
echo " Just run PEP8 and HACKING compliance check"
echo " on files changed since HEAD~1 (or <basecommit>)"
echo " -P, --no-pep8 Don't run pep8 by default"
echo " -t, --tabs Check for tab characters in files."
echo " -y, --pylint Just run pylint"
echo " -e, --eslint Just run eslint"
echo " -k, --karma Just run karma"
echo " -q, --quiet Run non-interactively. (Relatively) quiet."
echo " Implies -V if -N is not set."
echo " --only-selenium Run only the Selenium unit tests"
echo " --with-selenium Run unit tests including Selenium tests"
echo " --selenium-headless Run Selenium tests headless"
echo " --integration Run the integration tests (requires a running "
echo " OpenStack environment)"
echo " --runserver Run the Django development server for"
echo " openstack_dashboard in the virtual"
echo " environment."
echo " --docs Just build the documentation"
echo " --backup-environment Make a backup of the environment on exit"
echo " --restore-environment Restore the environment before running"
echo " --destroy-environment Destroy the environment and exit"
echo " -h, --help Print this usage message"
echo ""
echo "Note: with no options specified, the script will try to run the tests in"
echo " a virtual environment, If no virtualenv is found, the script will ask"
echo " if you would like to create one. If you prefer to run tests NOT in a"
echo " virtual environment, simply pass the -N option."
exit
}
# DEFAULTS FOR RUN_TESTS.SH
#
root=`pwd -P`
venv=$root/.venv
venv_env_version=$venv/environments
with_venv=tools/with_venv.sh
included_dirs="distil_ui"
always_venv=0
backup_env=0
command_wrapper=""
destroy=0
force=0
just_pep8=0
just_pep8_changed=0
no_pep8=0
just_pylint=0
just_docs=0
just_tabs=0
just_eslint=0
just_karma=0
never_venv=0
quiet=0
restore_env=0
runserver=0
only_selenium=0
with_selenium=0
selenium_headless=0
integration=0
testopts=""
testargs=""
with_coverage=0
makemessages=0
compilemessages=0
check_only=0
pseudo=0
manage=0
# Jenkins sets a "JOB_NAME" variable, if it's not set, we'll make it "default"
[ "$JOB_NAME" ] || JOB_NAME="default"
function process_option {
# If running manage command, treat the rest of options as arguments.
if [ $manage -eq 1 ]; then
testargs="$testargs $1"
return 0
fi
case "$1" in
-h|--help) usage;;
-V|--virtual-env) always_venv=1; never_venv=0;;
-N|--no-virtual-env) always_venv=0; never_venv=1;;
-p|--pep8) just_pep8=1;;
-8|--pep8-changed) just_pep8_changed=1;;
-P|--no-pep8) no_pep8=1;;
-y|--pylint) just_pylint=1;;
-e|--eslint) just_eslint=1;;
-k|--karma) just_karma=1;;
-f|--force) force=1;;
-t|--tabs) just_tabs=1;;
-q|--quiet) quiet=1;;
-c|--coverage) with_coverage=1;;
-m|--manage) manage=1;;
--makemessages) makemessages=1;;
--compilemessages) compilemessages=1;;
--check-only) check_only=1;;
--pseudo) pseudo=1;;
--only-selenium) only_selenium=1;;
--with-selenium) with_selenium=1;;
--selenium-headless) selenium_headless=1;;
--integration) integration=1;;
--docs) just_docs=1;;
--runserver) runserver=1;;
--backup-environment) backup_env=1;;
--restore-environment) restore_env=1;;
--destroy-environment) destroy=1;;
-*) testopts="$testopts $1";;
*) testargs="$testargs $1"
esac
}
function run_management_command {
${command_wrapper} python $root/manage.py $testopts $testargs
}
function run_server {
echo "Starting Django development server..."
${command_wrapper} python $root/manage.py runserver $testopts $testargs
echo "Server stopped."
}
function run_pylint {
echo "Running pylint ..."
PYTHONPATH=$root ${command_wrapper} pylint --rcfile=.pylintrc -f parseable $included_dirs > pylint.txt || true
CODE=$?
grep Global -A2 pylint.txt
if [ $CODE -lt 32 ]; then
echo "Completed successfully."
exit 0
else
echo "Completed with problems."
exit $CODE
fi
}
function run_eslint {
echo "Running eslint ..."
if [ "`which npm`" == '' ] ; then
echo "npm is not present; please install, e.g. sudo apt-get install npm"
else
npm install
npm run lint
fi
}
function run_karma {
echo "Running karma ..."
npm install
npm run test
}
function warn_on_flake8_without_venv {
set +o errexit
${command_wrapper} python -c "import hacking" 2>/dev/null
no_hacking=$?
set -o errexit
if [ $never_venv -eq 1 -a $no_hacking -eq 1 ]; then
echo "**WARNING**:" >&2
echo "OpenStack hacking is not installed on your host. Its detection will be missed." >&2
echo "Please install or use virtual env if you need OpenStack hacking detection." >&2
fi
}
function run_pep8 {
echo "Running flake8 ..."
warn_on_flake8_without_venv
DJANGO_SETTINGS_MODULE=openstack_dashboard.test.settings ${command_wrapper} flake8
}
function run_pep8_changed {
# NOTE(gilliard) We want use flake8 to check the entirety of every file that has
# a change in it. Unfortunately the --filenames argument to flake8 only accepts
# file *names* and there are no files named (eg) "nova/compute/manager.py". The
# --diff argument behaves surprisingly as well, because although you feed it a
# diff, it actually checks the file on disk anyway.
local base_commit=${testargs:-HEAD~1}
files=$(git diff --name-only $base_commit | tr '\n' ' ')
echo "Running flake8 on ${files}"
warn_on_flake8_without_venv
diff -u --from-file /dev/null ${files} | DJANGO_SETTINGS_MODULE=openstack_dashboard.test.settings ${command_wrapper} flake8 --diff
exit
}
function run_sphinx {
echo "Building sphinx..."
DJANGO_SETTINGS_MODULE=openstack_dashboard.test.settings ${command_wrapper} python setup.py build_sphinx
echo "Build complete."
}
function tab_check {
TAB_VIOLATIONS=`find $included_dirs -type f -regex ".*\.\(css\|js\|py\|html\)" -print0 | xargs -0 awk '/\t/' | wc -l`
if [ $TAB_VIOLATIONS -gt 0 ]; then
echo "TABS! $TAB_VIOLATIONS of them! Oh no!"
HORIZON_FILES=`find $included_dirs -type f -regex ".*\.\(css\|js\|py|\html\)"`
for TABBED_FILE in $HORIZON_FILES
do
TAB_COUNT=`awk '/\t/' $TABBED_FILE | wc -l`
if [ $TAB_COUNT -gt 0 ]; then
echo "$TABBED_FILE: $TAB_COUNT"
fi
done
fi
return $TAB_VIOLATIONS;
}
function destroy_venv {
echo "Cleaning environment..."
echo "Removing virtualenv..."
rm -rf $venv
echo "Virtualenv removed."
}
function environment_check {
echo "Checking environment."
if [ -f $venv_env_version ]; then
set +o errexit
cat requirements.txt test-requirements.txt | cmp $venv_env_version - > /dev/null
local env_check_result=$?
set -o errexit
if [ $env_check_result -eq 0 ]; then
# If the environment exists and is up-to-date then set our variables
command_wrapper="${root}/${with_venv}"
echo "Environment is up to date."
return 0
fi
fi
if [ $always_venv -eq 1 ]; then
install_venv
else
if [ ! -e ${venv} ]; then
echo -e "Environment not found. Install? (Y/n) \c"
else
echo -e "Your environment appears to be out of date. Update? (Y/n) \c"
fi
read update_env
if [ "x$update_env" = "xY" -o "x$update_env" = "x" -o "x$update_env" = "xy" ]; then
install_venv
else
# Set our command wrapper anyway.
command_wrapper="${root}/${with_venv}"
fi
fi
}
function sanity_check {
# Anything that should be determined prior to running the tests, server, etc.
# Don't sanity-check anything environment-related in -N flag is set
if [ $never_venv -eq 0 ]; then
if [ ! -e ${venv} ]; then
echo "Virtualenv not found at $venv. Did install_venv.py succeed?"
exit 1
fi
fi
# Remove .pyc files. This is sanity checking because they can linger
# after old files are deleted.
find . -name "*.pyc" -exec rm -rf {} \;
}
function backup_environment {
if [ $backup_env -eq 1 ]; then
echo "Backing up environment \"$JOB_NAME\"..."
if [ ! -e ${venv} ]; then
echo "Environment not installed. Cannot back up."
return 0
fi
if [ -d /tmp/.horizon_environment/$JOB_NAME ]; then
mv /tmp/.horizon_environment/$JOB_NAME /tmp/.horizon_environment/$JOB_NAME.old
rm -rf /tmp/.horizon_environment/$JOB_NAME
fi
mkdir -p /tmp/.horizon_environment/$JOB_NAME
cp -r $venv /tmp/.horizon_environment/$JOB_NAME/
# Remove the backup now that we've completed successfully
rm -rf /tmp/.horizon_environment/$JOB_NAME.old
echo "Backup completed"
fi
}
function restore_environment {
if [ $restore_env -eq 1 ]; then
echo "Restoring environment from backup..."
if [ ! -d /tmp/.horizon_environment/$JOB_NAME ]; then
echo "No backup to restore from."
return 0
fi
cp -r /tmp/.horizon_environment/$JOB_NAME/.venv ./ || true
echo "Environment restored successfully."
fi
}
function install_venv {
# Install with install_venv.py
export PIP_DOWNLOAD_CACHE=${PIP_DOWNLOAD_CACHE-/tmp/.pip_download_cache}
export PIP_USE_MIRRORS=true
if [ $quiet -eq 1 ]; then
export PIP_NO_INPUT=true
fi
echo "Fetching new src packages..."
rm -rf $venv/src
python tools/install_venv.py
command_wrapper="$root/${with_venv}"
# Make sure it worked and record the environment version
sanity_check
chmod -R 754 $venv
cat requirements.txt test-requirements.txt > $venv_env_version
}
function run_tests {
sanity_check
if [ $with_selenium -eq 1 ]; then
export WITH_SELENIUM=1
elif [ $only_selenium -eq 1 ]; then
export WITH_SELENIUM=1
export SKIP_UNITTESTS=1
fi
if [ $with_selenium -eq 0 -a $integration -eq 0 ]; then
testopts="$testopts --exclude-dir=distil_ui/test/integration_tests"
fi
if [ $selenium_headless -eq 1 ]; then
export SELENIUM_HEADLESS=1
fi
if [ -z "$testargs" ]; then
run_tests_all
else
run_tests_subset
fi
}
function run_tests_subset {
project=`echo $testargs | awk -F. '{print $1}'`
${command_wrapper} python $root/manage.py test --settings=$project.test.settings $testopts $testargs
}
function run_tests_all {
echo "Running Distil UI tests"
export NOSE_XUNIT_FILE=distil_ui/nosetests.xml
if [ "$NOSE_WITH_HTML_OUTPUT" = '1' ]; then
export NOSE_HTML_OUT_FILE='dashboard_nose_results.html'
fi
${command_wrapper} ${coverage_run} $root/manage.py test distil_ui --settings=openstack_dashboard.test.settings $testopts
# get results of the openstack_dashboard tests
DASHBOARD_RESULT=$?
if [ $with_coverage -eq 1 ]; then
echo "Generating coverage reports"
${command_wrapper} python -m coverage.__main__ combine
${command_wrapper} python -m coverage.__main__ xml -i --include="horizon/*,openstack_dashboard/*" --omit='/usr*,setup.py,*egg*,.venv/*'
${command_wrapper} python -m coverage.__main__ html -i --include="horizon/*,openstack_dashboard/*" --omit='/usr*,setup.py,*egg*,.venv/*' -d reports
fi
# Remove the leftover coverage files from the -p flag earlier.
rm -f .coverage.*
PEP8_RESULT=0
if [ $no_pep8 -eq 0 ] && [ $only_selenium -eq 0 ]; then
run_pep8
PEP8_RESULT=$?
fi
TEST_RESULT=$(($DASHBOARD_RESULT || $PEP8_RESULT))
if [ $TEST_RESULT -eq 0 ]; then
echo "Tests completed successfully."
else
echo "Tests failed."
fi
exit $TEST_RESULT
}
function run_integration_tests {
export INTEGRATION_TESTS=1
if [ $selenium_headless -eq 1 ]; then
export SELENIUM_HEADLESS=1
fi
echo "Running Horizon integration tests..."
if [ -z "$testargs" ]; then
${command_wrapper} nosetests openstack_dashboard/test/integration_tests/tests
else
${command_wrapper} nosetests $testargs
fi
exit 0
}
function babel_extract {
DOMAIN=$1
KEYWORDS="-k gettext_noop -k gettext_lazy -k ngettext_lazy:1,2"
KEYWORDS+=" -k ugettext_noop -k ugettext_lazy -k ungettext_lazy:1,2"
KEYWORDS+=" -k npgettext:1c,2,3 -k pgettext_lazy:1c,2 -k npgettext_lazy:1c,2,3"
mkdir -p locale
${command_wrapper} pybabel extract -F ../babel-${DOMAIN}.cfg -o locale/${DOMAIN}.pot $KEYWORDS .
}
function run_makemessages {
echo -n "distil ui: "
cd distil_ui
babel_extract django
DISTIL_PY_RESULT=$?
echo -n "distil ui javascript: "
babel_extract djangojs
DISTIL_JS_RESULT=$?
cd ../
if [ $check_only -eq 1 ]; then
rm -f distil_ui/locale/django*.pot
fi
exit $(($DISTIL_PY_RESULT || $DISTIL_JS_RESULT))
}
function run_compilemessages {
cd horizon
${command_wrapper} $root/manage.py compilemessages
HORIZON_PY_RESULT=$?
cd ../openstack_dashboard
${command_wrapper} $root/manage.py compilemessages
DASHBOARD_RESULT=$?
exit $(($HORIZON_PY_RESULT || $DASHBOARD_RESULT))
}
function run_pseudo {
for lang in $testargs
# Use English pot file as the source file/pot file just like real Horizon translations
do
${command_wrapper} $root/tools/pseudo.py openstack_dashboard/locale/django.pot openstack_dashboard/locale/$lang/LC_MESSAGES/django.po $lang
${command_wrapper} $root/tools/pseudo.py openstack_dashboard/locale/djangojs.pot openstack_dashboard/locale/$lang/LC_MESSAGES/djangojs.po $lang
${command_wrapper} $root/tools/pseudo.py horizon/locale/django.pot horizon/locale/$lang/LC_MESSAGES/django.po $lang
${command_wrapper} $root/tools/pseudo.py horizon/locale/djangojs.pot horizon/locale/$lang/LC_MESSAGES/djangojs.po $lang
done
exit $?
}
# ---------PREPARE THE ENVIRONMENT------------ #
# PROCESS ARGUMENTS, OVERRIDE DEFAULTS
for arg in "$@"; do
process_option $arg
done
if [ $quiet -eq 1 ] && [ $never_venv -eq 0 ] && [ $always_venv -eq 0 ]
then
always_venv=1
fi
# If destroy is set, just blow it away and exit.
if [ $destroy -eq 1 ]; then
destroy_venv
exit 0
fi
# Ignore all of this if the -N flag was set
if [ $never_venv -eq 0 ]; then
# Restore previous environment if desired
if [ $restore_env -eq 1 ]; then
restore_environment
fi
# Remove the virtual environment if --force used
if [ $force -eq 1 ]; then
destroy_venv
fi
# Then check if it's up-to-date
environment_check
# Create a backup of the up-to-date environment if desired
if [ $backup_env -eq 1 ]; then
backup_environment
fi
fi
# ---------EXERCISE THE CODE------------ #
# Run management commands
if [ $manage -eq 1 ]; then
run_management_command
exit $?
fi
# Build the docs
if [ $just_docs -eq 1 ]; then
run_sphinx
exit $?
fi
# Update translation files
if [ $makemessages -eq 1 ]; then
run_makemessages
exit $?
fi
# Compile translation files
if [ $compilemessages -eq 1 ]; then
run_compilemessages
exit $?
fi
# Generate Pseudo translation
if [ $pseudo -eq 1 ]; then
run_pseudo
exit $?
fi
# PEP8
if [ $just_pep8 -eq 1 ]; then
run_pep8
exit $?
fi
if [ $just_pep8_changed -eq 1 ]; then
run_pep8_changed
exit $?
fi
# Pylint
if [ $just_pylint -eq 1 ]; then
run_pylint
exit $?
fi
# ESLint
if [ $just_eslint -eq 1 ]; then
run_eslint
exit $?
fi
# Karma
if [ $just_karma -eq 1 ]; then
run_karma
exit $?
fi
# Tab checker
if [ $just_tabs -eq 1 ]; then
tab_check
exit $?
fi
# Integration tests
if [ $integration -eq 1 ]; then
run_integration_tests
exit $?
fi
# Django development server
if [ $runserver -eq 1 ]; then
run_server
exit $?
fi
# Full test suite
run_tests || exit

30
setup.cfg Normal file
View File

@ -0,0 +1,30 @@
[metadata]
name = distil-ui
summary = Distil User Interface
description-file =
README.rst
author = OpenStack
author-email = openstack-dev@lists.openstack.org
home-page = http://docs.openstack.org/developer/distil/
classifier =
Environment :: OpenStack
Framework :: Django
Intended Audience :: Information Technology
Intended Audience :: System Administrators
License :: OSI Approved :: Apache Software License
Operating System :: POSIX :: Linux
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.4
[files]
packages =
distil_ui
[build_sphinx]
all_files = 1
build-dir = doc/build
source-dir = doc/source

29
setup.py Normal file
View File

@ -0,0 +1,29 @@
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT
import setuptools
# In python < 2.7.4, a lazy loading of package `pbr` will break
# setuptools if some other modules registered functions in `atexit`.
# solution from: http://bugs.python.org/issue15881#msg170215
try:
import multiprocessing # noqa
except ImportError:
pass
setuptools.setup(
setup_requires=['pbr>=1.8'],
pbr=True)

29
test-requirements.txt Normal file
View File

@ -0,0 +1,29 @@
# The order of packages is significant, because pip processes them in the order
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
# Order matters to the pip dependency resolver, so sorting this file
# changes how packages are installed. New dependencies should be
# added in alphabetical order, however, some dependencies may need to
# be installed in a specific order.
#
# Hacking should appear first in case something else depends on pep8
hacking>=0.12.0,!=0.13.0,<0.14 # Apache-2.0
coverage>=4.0 # Apache-2.0
django-nose>=1.4.4 # BSD
mock>=2.0 # BSD
mox3!=0.19.0,>=0.7.0 # Apache-2.0
nodeenv>=0.9.4 # BSD
nose # LGPL
nose-exclude # LGPL
nosehtmloutput>=0.0.3 # Apache-2.0
nosexcover # BSD
openstack.nose-plugin>=0.7 # Apache-2.0
oslosphinx>=4.7.0 # Apache-2.0
reno>=1.8.0 # Apache-2.0
selenium>=2.50.1 # Apache-2.0
sphinx>=1.5.1 # BSD
testtools>=1.4.0 # MIT
# This also needs xvfb library installed on your OS
xvfbwrapper>=0.1.3 #license: MIT
# Include horizon as test requirement
http://tarballs.openstack.org/horizon/horizon-master.tar.gz#egg=horizon

97
test-shim.js Normal file
View File

@ -0,0 +1,97 @@
/*
* Shim for Javascript unit tests; supplying expected global features.
* This should be removed from the codebase once i18n services are provided.
* Taken from default i18n file provided by Django.
*/
var horizonPlugInModules = [];
(function (globals) {
var django = globals.django || (globals.django = {});
django.pluralidx = function (count) { return (count == 1) ? 0 : 1; };
/* gettext identity library */
django.gettext = function (msgid) { return msgid; };
django.ngettext = function (singular, plural, count) { return (count == 1) ? singular : plural; };
django.gettext_noop = function (msgid) { return msgid; };
django.pgettext = function (context, msgid) { return msgid; };
django.npgettext = function (context, singular, plural, count) { return (count == 1) ? singular : plural; };
django.interpolate = function (fmt, obj, named) {
if (named) {
return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])});
} else {
return fmt.replace(/%s/g, function(match){return String(obj.shift())});
}
};
/* formatting library */
django.formats = {
"DATETIME_FORMAT": "N j, Y, P",
"DATETIME_INPUT_FORMATS": [
"%Y-%m-%d %H:%M:%S",
"%Y-%m-%d %H:%M:%S.%f",
"%Y-%m-%d %H:%M",
"%Y-%m-%d",
"%m/%d/%Y %H:%M:%S",
"%m/%d/%Y %H:%M:%S.%f",
"%m/%d/%Y %H:%M",
"%m/%d/%Y",
"%m/%d/%y %H:%M:%S",
"%m/%d/%y %H:%M:%S.%f",
"%m/%d/%y %H:%M",
"%m/%d/%y"
],
"DATE_FORMAT": "N j, Y",
"DATE_INPUT_FORMATS": [
"%Y-%m-%d",
"%m/%d/%Y",
"%m/%d/%y"
],
"DECIMAL_SEPARATOR": ".",
"FIRST_DAY_OF_WEEK": "0",
"MONTH_DAY_FORMAT": "F j",
"NUMBER_GROUPING": "3",
"SHORT_DATETIME_FORMAT": "m/d/Y P",
"SHORT_DATE_FORMAT": "m/d/Y",
"THOUSAND_SEPARATOR": ",",
"TIME_FORMAT": "P",
"TIME_INPUT_FORMATS": [
"%H:%M:%S",
"%H:%M:%S.%f",
"%H:%M"
],
"YEAR_MONTH_FORMAT": "F Y"
};
django.get_format = function (format_type) {
var value = django.formats[format_type];
if (typeof(value) == 'undefined') {
return format_type;
} else {
return value;
}
};
/* add to global namespace */
globals.pluralidx = django.pluralidx;
globals.gettext = django.gettext;
globals.ngettext = django.ngettext;
globals.gettext_noop = django.gettext_noop;
globals.pgettext = django.pgettext;
globals.npgettext = django.npgettext;
globals.interpolate = django.interpolate;
globals.get_format = django.get_format;
globals.STATIC_URL = '/static/';
globals.WEBROOT = '/';
}(this));

71
tools/install_venv.py Normal file
View File

@ -0,0 +1,71 @@
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
# Copyright 2010 OpenStack Foundation
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import sys
import install_venv_common as install_venv # noqa
def print_help(venv, root):
help = """
OpenStack development environment setup is complete.
OpenStack development uses virtualenv to track and manage Python
dependencies while in development and testing.
To activate the OpenStack virtualenv for the extent of your current shell
session you can run:
$ source %s/bin/activate
Or, if you prefer, you can run commands in the virtualenv on a case by case
basis by running:
$ %s/tools/with_venv.sh <your command>
Also, make test will automatically use the virtualenv.
"""
print(help % (venv, root))
def main(argv):
root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
if os.environ.get('tools_path'):
root = os.environ['tools_path']
venv = os.path.join(root, '.venv')
if os.environ.get('venv'):
venv = os.environ['venv']
pip_requires = os.path.join(root, 'requirements.txt')
test_requires = os.path.join(root, 'test-requirements.txt')
py_version = "python%s.%s" % (sys.version_info[0], sys.version_info[1])
project = 'OpenStack'
install = install_venv.InstallVenv(root, venv, pip_requires, test_requires,
py_version, project)
options = install.parse_args(argv)
install.check_python_version()
install.check_dependencies()
install.create_virtualenv(no_site_packages=options.no_site_packages)
install.install_dependencies()
print_help(venv, root)
if __name__ == '__main__':
main(sys.argv)

View File

@ -0,0 +1,172 @@
# Copyright 2013 OpenStack Foundation
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Provides methods needed by installation script for OpenStack development
virtual environments.
Since this script is used to bootstrap a virtualenv from the system's Python
environment, it should be kept strictly compatible with Python 2.6.
Synced in from openstack-common
"""
from __future__ import print_function
import optparse
import os
import subprocess
import sys
class InstallVenv(object):
def __init__(self, root, venv, requirements,
test_requirements, py_version,
project):
self.root = root
self.venv = venv
self.requirements = requirements
self.test_requirements = test_requirements
self.py_version = py_version
self.project = project
def die(self, message, *args):
print(message % args, file=sys.stderr)
sys.exit(1)
def check_python_version(self):
if sys.version_info < (2, 6):
self.die("Need Python Version >= 2.6")
def run_command_with_code(self, cmd, redirect_output=True,
check_exit_code=True):
"""Runs a command in an out-of-process shell.
Returns the output of that command. Working directory is self.root.
"""
if redirect_output:
stdout = subprocess.PIPE
else:
stdout = None
proc = subprocess.Popen(cmd, cwd=self.root, stdout=stdout)
output = proc.communicate()[0]
if check_exit_code and proc.returncode != 0:
self.die('Command "%s" failed.\n%s', ' '.join(cmd), output)
return (output, proc.returncode)
def run_command(self, cmd, redirect_output=True, check_exit_code=True):
return self.run_command_with_code(cmd, redirect_output,
check_exit_code)[0]
def get_distro(self):
if (os.path.exists('/etc/fedora-release') or
os.path.exists('/etc/redhat-release')):
return Fedora(
self.root, self.venv, self.requirements,
self.test_requirements, self.py_version, self.project)
else:
return Distro(
self.root, self.venv, self.requirements,
self.test_requirements, self.py_version, self.project)
def check_dependencies(self):
self.get_distro().install_virtualenv()
def create_virtualenv(self, no_site_packages=True):
"""Creates the virtual environment and installs PIP.
Creates the virtual environment and installs PIP only into the
virtual environment.
"""
if not os.path.isdir(self.venv):
print('Creating venv...', end=' ')
if no_site_packages:
self.run_command(['virtualenv', '-q', '--no-site-packages',
self.venv])
else:
self.run_command(['virtualenv', '-q', self.venv])
print('done.')
else:
print("venv already exists...")
pass
def pip_install(self, *args):
self.run_command(['tools/with_venv.sh',
'pip', 'install', '--upgrade'] + list(args),
redirect_output=False)
def install_dependencies(self):
print('Installing dependencies with pip (this can take a while)...')
# First things first, make sure our venv has the latest pip and
# setuptools and pbr
self.pip_install('pip>=1.4')
self.pip_install('setuptools')
self.pip_install('pbr')
self.pip_install('-r', self.requirements, '-r', self.test_requirements)
def parse_args(self, argv):
"""Parses command-line arguments."""
parser = optparse.OptionParser()
parser.add_option('-n', '--no-site-packages',
action='store_true',
help="Do not inherit packages from global Python "
"install.")
return parser.parse_args(argv[1:])[0]
class Distro(InstallVenv):
def check_cmd(self, cmd):
return bool(self.run_command(['which', cmd],
check_exit_code=False).strip())
def install_virtualenv(self):
if self.check_cmd('virtualenv'):
return
if self.check_cmd('easy_install'):
print('Installing virtualenv via easy_install...', end=' ')
if self.run_command(['easy_install', 'virtualenv']):
print('Succeeded')
return
else:
print('Failed')
self.die('ERROR: virtualenv not found.\n\n%s development'
' requires virtualenv, please install it using your'
' favorite package management tool' % self.project)
class Fedora(Distro):
"""This covers all Fedora-based distributions.
Includes: Fedora, RHEL, CentOS, Scientific Linux
"""
def check_pkg(self, pkg):
return self.run_command_with_code(['rpm', '-q', pkg],
check_exit_code=False)[1] == 0
def install_virtualenv(self):
if self.check_cmd('virtualenv'):
return
if not self.check_pkg('python-virtualenv'):
self.die("Please install 'python-virtualenv'.")
super(Fedora, self).install_virtualenv()

13
tools/with_venv.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
TOOLS_PATH=${TOOLS_PATH:-$(dirname $0)}
VENV_PATH=${VENV_PATH:-${TOOLS_PATH}}
VENV_DIR=${VENV_NAME:-/../.venv}
TOOLS=${TOOLS_PATH}
VENV=${VENV:-${VENV_PATH}/${VENV_DIR}}
HORIZON_DIR=${TOOLS%/tools}
# This horrible mangling of the PYTHONPATH is required to get the
# babel-angular-gettext extractor to work. To fix this the extractor needs to
# be packaged on pypi and added to global requirements. That work is in progress.
export PYTHONPATH="$HORIZON_DIR"
source ${VENV}/bin/activate && "$@"

81
tox.ini Normal file
View File

@ -0,0 +1,81 @@
[tox]
envlist = py27,py27dj18,pep8,py35
minversion = 1.6
skipsdist = True
[testenv]
usedevelop = True
setenv = VIRTUAL_ENV={envdir}
NOSE_WITH_OPENSTACK=1
NOSE_OPENSTACK_COLOR=1
NOSE_OPENSTACK_RED=0.05
NOSE_OPENSTACK_YELLOW=0.025
NOSE_OPENSTACK_SHOW_ELAPSED=1
DJANGO_SETTINGS_MODULE=distil_ui.test.settings
install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} -U {opts} {packages}
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands = python manage.py test {posargs}
[testenv:pep8]
commands = flake8 {posargs}
[testenv:venv]
commands = {posargs}
[testenv:cover]
commands =
coverage erase
coverage run {toxinidir}/manage.py test distil_ui
coverage xml --omit '.tox/cover/*' -o 'cover/coverage.xml'
coverage html --omit '.tox/cover/*' -d 'cover/htmlcov'
[testenv:py27dj18]
basepython = python2.7
commands =
pip install git+https://github.com/openstack/python-distilclient.git
python manage.py test {posargs}
[testenv:eslint]
whitelist_externals = npm
commands =
npm install
npm run {posargs:postinstall}
npm run {posargs:lint}
[testenv:karma]
whitelist_externals = npm
commands =
npm install
npm run {posargs:postinstall}
npm run {posargs:test}
[testenv:docs]
commands = python setup.py build_sphinx
[flake8]
exclude = .venv,.git,.tox,dist,*lib/python*,*egg,build,panel_template,dash_template,local_settings.py,*/local/*,*/test/test_plugins/*,.ropeproject,node_modules
max-complexity = 20
[hacking]
import_exceptions = collections.defaultdict,
django.conf.settings,
django.conf.urls.include,
django.conf.urls.patterns,
django.conf.urls.url,
django.core.urlresolvers.reverse,
django.core.urlresolvers.reverse_lazy,
django.template.loader.render_to_string,
django.test.utils.override_settings,
django.utils.datastructures.SortedDict,
django.utils.encoding.force_text,
django.utils.html.conditional_escape,
django.utils.html.escape,
django.utils.http.urlencode,
django.utils.safestring.mark_safe,
django.utils.translation.npgettext_lazy,
django.utils.translation.pgettext_lazy,
django.utils.translation.ugettext_lazy,
django.utils.translation.ungettext_lazy,
operator.attrgetter,
StringIO.StringIO