-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from knikolla/outages
Add support for not billing during outages
- Loading branch information
Showing
8 changed files
with
105 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import uuid | ||
from datetime import datetime, timedelta | ||
|
||
from openstack_billing_db import billing | ||
from openstack_billing_db.model import Instance, InstanceEvent | ||
from openstack_billing_db.tests.unit.utils import FLAVORS, MINUTE, HOUR, DAY, MONTH | ||
|
||
|
||
def test_instance_simple_runtime(): | ||
time = datetime(year=2000, month=1, day=1, hour=0, minute=0, second=0) | ||
events = [ | ||
InstanceEvent(time=time, name="create", message=""), | ||
InstanceEvent(time=time + timedelta(days=15), name="delete", message=""), | ||
] | ||
i = Instance( | ||
uuid=uuid.uuid4().hex, name=uuid.uuid4().hex, flavor=FLAVORS[1], events=events | ||
) | ||
|
||
r = billing.get_runtime_for_instance( | ||
i, | ||
datetime(year=2000, month=1, day=1, hour=0, minute=0, second=0), | ||
datetime(year=2000, month=2, day=1, hour=0, minute=0, second=0), | ||
excluded_intervals=[ | ||
["2000-01-07", "2000-01-08"], | ||
["2000-01-01", "2000-01-02"], | ||
], | ||
) | ||
assert r.total_seconds_running == (15 * DAY) - (DAY * 2) | ||
assert r.total_seconds_stopped == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/openstack_billing_db/tests/unit/test_instance_runtime.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from openstack_billing_db.model import InstanceRuntime | ||
|
||
|
||
def test_instance_runtime_subtract(): | ||
a = InstanceRuntime(total_seconds_running=1000, total_seconds_stopped=1000) | ||
b = InstanceRuntime(total_seconds_running=100, total_seconds_stopped=200) | ||
c = a - b | ||
assert c.total_seconds_running == 900 | ||
assert c.total_seconds_running == a.total_seconds_running - b.total_seconds_running | ||
assert c.total_seconds_stopped == 800 | ||
assert c.total_seconds_stopped == a.total_seconds_stopped - b.total_seconds_stopped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from openstack_billing_db import model | ||
|
||
FLAVORS = {1: model.Flavor(id=1, name="TestFlavor", vcpus=1, memory=4096, storage=10)} | ||
|
||
MINUTE = 60 | ||
HOUR = 60 * MINUTE | ||
DAY = HOUR * 24 | ||
MONTH = 31 * DAY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from datetime import datetime | ||
|
||
|
||
def parse_time_from_string(time_str: str) -> datetime: | ||
return datetime.strptime(time_str, "%Y-%m-%d") |