Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Sync with development branch #5

Merged
merged 6 commits into from
Dec 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: python
python:
- "2.7"

install:
- pip install tox

script:
- tox

env:
- TOXENV=py27
- TOXENV=pep8
- TOXENV=coveralls
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#caso
# caso [![Build Status](https://travis-ci.org/IFCA/caso)](https://travis-ci.org/IFCA/caso)

cASO is an OpenStack Accounting extractor.

Expand Down
4 changes: 3 additions & 1 deletion caso/extract/ceilometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import ceilometerclient.client
import dateutil.parser
from dateutil import tz
import glanceclient.client
from oslo.config import cfg

Expand Down Expand Up @@ -156,7 +157,8 @@ def _build_record(self, instance, users, vo, images, now):
return r

def extract_for_tenant(self, tenant, lastrun):
now = datetime.datetime.now().replace(tzinfo=None)
now = datetime.datetime.now(tz.tzutc())
now.replace(tzinfo=None)

# Try and except here
# Getting clients
Expand Down
9 changes: 7 additions & 2 deletions caso/extract/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# under the License.

import dateutil.parser
from dateutil import tz
from oslo.config import cfg
from oslo.utils import importutils
import six
Expand All @@ -38,7 +39,8 @@
cfg.StrOpt('extract_from',
help='Extract records from this date. If it is not set, '
'extract records from last run. If none are set, extract '
'records from the beginning of time.'),
'records from the beginning of time. If no time zone is '
'specified, UTC will be used.'),
cfg.StrOpt('extractor',
choices=SUPPORTED_EXTRACTORS,
default='nova',
Expand Down Expand Up @@ -75,8 +77,11 @@ def _extract(self, extract_from):
def get_records(self, lastrun="1970-01-01"):
extract_from = CONF.extract_from or lastrun

if isinstance(extract_from, six.text_type):
if isinstance(extract_from, six.string_types):
extract_from = dateutil.parser.parse(extract_from)

if extract_from.tzinfo is None:
extract_from.replace(tzinfo=tz.tzutc())
if self.records is None:
self._extract(extract_from)
return self.records
7 changes: 6 additions & 1 deletion caso/extract/nova.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import datetime

import dateutil.parser
from dateutil import tz
import novaclient.client
from oslo.config import cfg

Expand Down Expand Up @@ -45,7 +46,11 @@ def _get_conn(self, tenant):
return conn

def extract_for_tenant(self, tenant, lastrun):
now = datetime.datetime.now()
# Some API calls do not expect a TZ, so we have to remove the timezone
# from the dates. We assume that all dates coming from upstream are
# in UTC TZ.
lastrun = lastrun.replace(tzinfo=None)
now = datetime.datetime.now(tz.tzutc()).replace(tzinfo=None)
end = now + datetime.timedelta(days=1)

# Try and except here
Expand Down
3 changes: 2 additions & 1 deletion caso/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import os.path

import dateutil.parser
from dateutil import tz
from oslo.config import cfg

import caso.extract.manager
Expand Down Expand Up @@ -71,4 +72,4 @@ def run(self):
if not CONF.dry_run:
self.messenger.push_to_all(records)
with open(self.last_run_file, "w") as fd:
fd.write(str(datetime.datetime.now()))
fd.write(str(datetime.datetime.now(tz.tzutc())))
3 changes: 3 additions & 0 deletions caso/messenger/ssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def __init__(self):
utils.makedirs(CONF.ssm.output_path)

def push(self, records):
if not records:
return

entries = []
for _, record in records.iteritems():
aux = ""
Expand Down
9 changes: 5 additions & 4 deletions caso/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

import contextlib
import datetime
import StringIO

from dateutil import tz
import mock
import six

from caso import manager
from caso.tests import base
Expand Down Expand Up @@ -53,7 +54,7 @@ def test_lastrun_does_not_exist(self):

def test_lastrun_exists(self):
expected = datetime.datetime(2014, 12, 10, 13, 10, 26, 664598)
aux = StringIO.StringIO(expected)
aux = six.StringIO(expected)

with contextlib.nested(
mock.patch("os.path.exists"),
Expand All @@ -66,7 +67,7 @@ def test_lastrun_exists(self):
self.assertEqual(expected, self.manager.lastrun)

def test_lastrun_is_invalid(self):
aux = StringIO.StringIO("foo")
aux = six.StringIO("foo")

# NOTE(aloga): manager.lastrun is a property, so we need to
# create our own callable here.
Expand All @@ -89,7 +90,7 @@ def test_dry_run(self):
# https://code.google.com/p/mock/issues/detail?id=117
with mock.patch("caso.manager.Manager.lastrun",
new_callable=mock.PropertyMock) as lastrun:
lastrun.return_value = datetime.datetime.now()
lastrun.return_value = datetime.datetime.now(tz.tzutc())
mngr = manager.Manager()
mngr.messenger.push_to_all.assert_not_called()
mngr.run()
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ six

python-novaclient
python-keystoneclient
python-dateutil
python-glanceclient
python-ceilometerclient


dirq
python-dateutil
6 changes: 6 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ commands = {posargs}
[testenv:cover]
commands = python setup.py testr --coverage --testr-args='{posargs}'

[testenv:coveralls]
commands = python setup.py testr --coverage --testr-args='{posargs}'
coveralls
deps = coveralls
{[testenv]deps}

[testenv:docs]
commands = python setup.py build_sphinx

Expand Down