Merge pull request #4 from fguillot/pep8

Convert the code to PEP8
This commit is contained in:
Maxime Belanger 2016-04-14 14:52:43 -04:00
commit ca830c05b2
19 changed files with 159 additions and 119 deletions

View File

@ -22,7 +22,7 @@ from flask import Blueprint, Response, request
from werkzeug.wrappers import BaseResponse
from almanach import config
from almanach.common.DateFormatException import DateFormatException
from almanach.common.date_format_exception import DateFormatException
api = Blueprint("api", __name__)
controller = None
@ -81,15 +81,15 @@ def create_instance(project_id):
instance = json.loads(request.data)
logging.info("Creating instance for tenant %s with data %s", project_id, instance)
controller.create_instance(
tenant_id=project_id,
instance_id=instance['id'],
create_date=instance['created_at'],
flavor=instance['flavor'],
os_type=instance['os_type'],
distro=instance['os_distro'],
version=instance['os_version'],
name=instance['name'],
metadata={}
tenant_id=project_id,
instance_id=instance['id'],
create_date=instance['created_at'],
flavor=instance['flavor'],
os_type=instance['os_type'],
distro=instance['os_distro'],
version=instance['os_version'],
name=instance['name'],
metadata={}
)
return Response(status=201)
@ -102,8 +102,8 @@ def delete_instance(instance_id):
data = json.loads(request.data)
logging.info("Deleting instance with id %s with data %s", instance_id, data)
controller.delete_instance(
instance_id=instance_id,
delete_date=data['date']
instance_id=instance_id,
delete_date=data['date']
)
return Response(status=202)
@ -116,9 +116,9 @@ def resize_instance(instance_id):
instance = json.loads(request.data)
logging.info("Resizing instance with id %s with data %s", instance_id, instance)
controller.resize_instance(
instance_id=instance_id,
resize_date=instance['date'],
flavor=instance['flavor']
instance_id=instance_id,
resize_date=instance['date'],
flavor=instance['flavor']
)
return Response(status=200)
@ -157,13 +157,13 @@ def create_volume(project_id):
volume = json.loads(request.data)
logging.info("Creating volume for tenant %s with data %s", project_id, volume)
controller.create_volume(
project_id=project_id,
volume_id=volume['volume_id'],
start=volume['start'],
volume_type=volume['volume_type'],
size=volume['size'],
volume_name=volume['volume_name'],
attached_to=volume['attached_to']
project_id=project_id,
volume_id=volume['volume_id'],
start=volume['start'],
volume_type=volume['volume_type'],
size=volume['size'],
volume_name=volume['volume_name'],
attached_to=volume['attached_to']
)
return Response(status=201)
@ -176,8 +176,8 @@ def delete_volume(volume_id):
data = json.loads(request.data)
logging.info("Deleting volume with id %s with data %s", volume_id, data)
controller.delete_volume(
volume_id=volume_id,
delete_date=data['date']
volume_id=volume_id,
delete_date=data['date']
)
return Response(status=202)
@ -190,9 +190,9 @@ def resize_volume(volume_id):
volume = json.loads(request.data)
logging.info("Resizing volume with id %s with data %s", volume_id, volume)
controller.resize_volume(
volume_id=volume_id,
size=volume['size'],
update_date=volume['date']
volume_id=volume_id,
size=volume['size'],
update_date=volume['date']
)
return Response(status=200)
@ -205,9 +205,9 @@ def attach_volume(volume_id):
volume = json.loads(request.data)
logging.info("Attaching volume with id %s with data %s", volume_id, volume)
controller.attach_volume(
volume_id=volume_id,
date=volume['date'],
attachments=volume['attachments']
volume_id=volume_id,
date=volume['date'],
attachments=volume['attachments']
)
return Response(status=200)
@ -220,9 +220,9 @@ def detach_volume(volume_id):
volume = json.loads(request.data)
logging.info("Detaching volume with id %s with data %s", volume_id, volume)
controller.detach_volume(
volume_id=volume_id,
date=volume['date'],
attachments=volume['attachments']
volume_id=volume_id,
date=volume['date'],
attachments=volume['attachments']
)
return Response(status=200)
@ -278,8 +278,8 @@ def create_volume_type():
volume_type = json.loads(request.data)
logging.info("Creating volume type with data '%s'", volume_type)
controller.create_volume_type(
volume_type_id=volume_type['type_id'],
volume_type_name=volume_type['type_name']
volume_type_id=volume_type['type_id'],
volume_type_name=volume_type['type_name']
)
return Response(status=201)

View File

@ -17,8 +17,8 @@ import pymongo
from pymongo.errors import ConfigurationError
from almanach import config
from almanach.common.AlmanachException import AlmanachException
from almanach.common.VolumeTypeNotFoundException import VolumeTypeNotFoundException
from almanach.common.almanach_exception import AlmanachException
from almanach.common.volume_type_not_found_exception import VolumeTypeNotFoundException
from almanach.core.model import build_entity_from_dict, VolumeType
from pymongomodem.utils import decode_output, encode_input
@ -55,6 +55,7 @@ def ensureindex(db):
class DatabaseAdapter(object):
def __init__(self):
self.db = None

View File

@ -20,6 +20,7 @@ from almanach import config
class RetryAdapter:
def __init__(self, connection):
self.connection = connection
retry_exchange = self._configure_retry_exchanges(self.connection)
@ -87,7 +88,8 @@ class RetryAdapter:
return dead_exchange
def error_callback(exception, interval):
logging.error('Failed to declare dead queue and exchange, retrying in %d seconds. %r' % (interval, exception))
logging.error('Failed to declare dead queue and exchange, retrying in %d seconds. %r' %
(interval, exception))
declare_dead_queue = connection.ensure(connection, declare_dead_queue, errback=error_callback,
interval_start=0, interval_step=5, interval_max=30)

View File

@ -25,6 +25,7 @@ from almanach.core.controller import Controller
class AlmanachApi(Application):
def __init__(self):
super(AlmanachApi, self).__init__()

View File

@ -26,6 +26,7 @@ from almanach.core.controller import Controller
class AlmanachCollector(object):
def __init__(self):
log_bootstrap.configure()
config.read(sys.argv)

View File

@ -1 +0,0 @@

View File

@ -12,5 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
class AlmanachException(Exception):
pass

View File

@ -12,7 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
class DateFormatException(Exception):
def __init__(self, message=None):
if not message:
message = "The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, " \

View File

@ -12,7 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
class VolumeTypeNotFoundException(Exception):
def __init__(self, volume_type_id, message=None):
if not message:
message = "Unable to find volume_type id '{volume_type_id}'".format(volume_type_id=volume_type_id)

View File

@ -16,7 +16,7 @@ import ConfigParser
import pkg_resources
import os.path as Path
from almanach.common.AlmanachException import AlmanachException
from almanach.common.almanach_exception import AlmanachException
configuration = ConfigParser.RawConfigParser()
@ -98,12 +98,15 @@ def rabbitmq_retry_return_exchange():
def rabbitmq_retry_queue():
return get("RABBITMQ", "retry.queue", default=None)
def rabbitmq_dead_queue():
return get("RABBITMQ", "dead.queue", default=None)
def rabbitmq_dead_exchange():
return get("RABBITMQ", "dead.exchange", default=None)
def rabbitmq_time_to_live():
return int(get("RABBITMQ", "retry.time.to.live", default=None))

View File

@ -19,12 +19,13 @@ from datetime import timedelta
from dateutil import parser as date_parser
from pkg_resources import get_distribution
from almanach.common.DateFormatException import DateFormatException
from almanach.common.date_format_exception import DateFormatException
from almanach.core.model import Instance, Volume, VolumeType
from almanach import config
class Controller(object):
def __init__(self, database_adapter):
self.database_adapter = database_adapter
self.metadata_whitelist = config.device_metadata_whitelist()

View File

@ -12,7 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
class Entity(object):
def __init__(self, entity_id, project_id, start, end, last_event, name, entity_type):
self.entity_id = entity_id
self.project_id = project_id
@ -52,6 +54,7 @@ class Instance(Entity):
class OS(object):
def __init__(self, os_type, distro, version):
self.os_type = os_type
self.distro = distro
@ -80,6 +83,7 @@ class Volume(Entity):
class VolumeType(object):
def __init__(self, volume_type_id, volume_type_name):
self.volume_type_id = volume_type_id
self.volume_type_name = volume_type_name

View File

@ -23,6 +23,7 @@ from almanach.adapters.bus_adapter import BusAdapter
class BusAdapterTest(unittest.TestCase):
def setUp(self):
self.controller = flexmock()
self.retry = flexmock()

View File

@ -21,14 +21,15 @@ from hamcrest import assert_that, contains_inanyorder
from pymongo import MongoClient
from almanach.adapters.database_adapter import DatabaseAdapter
from almanach.common.VolumeTypeNotFoundException import VolumeTypeNotFoundException
from almanach.common.AlmanachException import AlmanachException
from almanach.common.volume_type_not_found_exception import VolumeTypeNotFoundException
from almanach.common.almanach_exception import AlmanachException
from almanach import config
from almanach.core.model import todict
from tests.builder import a, instance, volume, volume_type
class DatabaseAdapterTest(unittest.TestCase):
def setUp(self):
config.read(config_file="resources/config/test.cfg")
mongo_connection = mongomock.Connection()
@ -103,18 +104,23 @@ class DatabaseAdapterTest(unittest.TestCase):
def test_list_instances(self):
fake_instances = [
a(instance().with_id("id1").with_start(2014, 1, 1, 7, 0, 0).with_end(2014, 1, 1, 8, 0, 0).with_project_id("project_id").with_metadata({})),
a(instance().with_id("id2").with_start(2014, 1, 1, 1, 0, 0).with_no_end().with_project_id("project_id").with_metadata({})),
a(instance().with_id("id3").with_start(2014, 1, 1, 8, 0, 0).with_no_end().with_project_id("project_id").with_metadata({})),
a(instance().with_id("id1").with_start(2014, 1, 1, 7, 0, 0).with_end(
2014, 1, 1, 8, 0, 0).with_project_id("project_id").with_metadata({})),
a(instance().with_id("id2").with_start(2014, 1, 1, 1, 0,
0).with_no_end().with_project_id("project_id").with_metadata({})),
a(instance().with_id("id3").with_start(2014, 1, 1, 8, 0,
0).with_no_end().with_project_id("project_id").with_metadata({})),
]
fake_volumes = [
a(volume().with_id("id1").with_start(2014, 1, 1, 7, 0, 0).with_end(2014, 1, 1, 8, 0, 0).with_project_id("project_id")),
a(volume().with_id("id1").with_start(2014, 1, 1, 7, 0, 0).with_end(
2014, 1, 1, 8, 0, 0).with_project_id("project_id")),
a(volume().with_id("id2").with_start(2014, 1, 1, 1, 0, 0).with_no_end().with_project_id("project_id")),
a(volume().with_id("id3").with_start(2014, 1, 1, 8, 0, 0).with_no_end().with_project_id("project_id")),
]
[self.db.entity.insert(todict(fake_entity)) for fake_entity in fake_instances + fake_volumes]
entities = self.adapter.list_entities("project_id", datetime(2014, 1, 1, 0, 0, 0), datetime(2014, 1, 1, 12, 0, 0), "instance")
entities = self.adapter.list_entities("project_id", datetime(
2014, 1, 1, 0, 0, 0), datetime(2014, 1, 1, 12, 0, 0), "instance")
assert_that(entities, contains_inanyorder(*fake_instances))
def test_list_instances_with_decode_output(self):
@ -148,28 +154,37 @@ class DatabaseAdapterTest(unittest.TestCase):
.with_no_end()
.with_project_id("project_id")
.with_metadata({"a_metadata.to_sanitize": "this.sanitize"})),
]
]
[self.db.entity.insert(todict(fake_entity)) for fake_entity in fake_instances]
entities = self.adapter.list_entities("project_id", datetime(2014, 1, 1, 0, 0, 0), datetime(2014, 1, 1, 12, 0, 0), "instance")
entities = self.adapter.list_entities("project_id", datetime(
2014, 1, 1, 0, 0, 0), datetime(2014, 1, 1, 12, 0, 0), "instance")
assert_that(entities, contains_inanyorder(*expected_instances))
self.assert_entities_metadata_have_been_sanitize(entities)
def test_list_entities_in_period(self):
fake_entities_in_period = [
a(instance().with_id("in_the_period").with_start(2014, 1, 1, 7, 0, 0).with_end(2014, 1, 1, 8, 0, 0).with_project_id("project_id")),
a(instance().with_id("running_has_started_before").with_start(2014, 1, 1, 1, 0, 0).with_no_end().with_project_id("project_id")),
a(instance().with_id("running_has_started_during").with_start(2014, 1, 1, 8, 0, 0).with_no_end().with_project_id("project_id")),
a(instance().with_id("in_the_period").with_start(2014, 1, 1, 7, 0,
0).with_end(2014, 1, 1, 8, 0, 0).with_project_id("project_id")),
a(instance().with_id("running_has_started_before").with_start(
2014, 1, 1, 1, 0, 0).with_no_end().with_project_id("project_id")),
a(instance().with_id("running_has_started_during").with_start(
2014, 1, 1, 8, 0, 0).with_no_end().with_project_id("project_id")),
]
fake_entities_out_period = [
a(instance().with_id("before_the_period").with_start(2014, 1, 1, 0, 0, 0).with_end(2014, 1, 1, 1, 0, 0).with_project_id("project_id")),
a(instance().with_id("after_the_period").with_start(2014, 1, 1, 10, 0, 0).with_end(2014, 1, 1, 11, 0, 0).with_project_id("project_id")),
a(instance().with_id("running_has_started_after").with_start(2014, 1, 1, 10, 0, 0).with_no_end().with_project_id("project_id")),
a(instance().with_id("before_the_period").with_start(2014, 1, 1, 0,
0, 0).with_end(2014, 1, 1, 1, 0, 0).with_project_id("project_id")),
a(instance().with_id("after_the_period").with_start(2014, 1, 1, 10,
0, 0).with_end(2014, 1, 1, 11, 0, 0).with_project_id("project_id")),
a(instance().with_id("running_has_started_after").with_start(
2014, 1, 1, 10, 0, 0).with_no_end().with_project_id("project_id")),
]
[self.db.entity.insert(todict(fake_entity)) for fake_entity in fake_entities_in_period + fake_entities_out_period]
[self.db.entity.insert(todict(fake_entity))
for fake_entity in fake_entities_in_period + fake_entities_out_period]
entities = self.adapter.list_entities("project_id", datetime(2014, 1, 1, 6, 0, 0), datetime(2014, 1, 1, 9, 0, 0))
entities = self.adapter.list_entities("project_id", datetime(
2014, 1, 1, 6, 0, 0), datetime(2014, 1, 1, 9, 0, 0))
assert_that(entities, contains_inanyorder(*fake_entities_in_period))
def test_update_entity(self):
@ -190,7 +205,8 @@ class DatabaseAdapterTest(unittest.TestCase):
self.adapter.update_active_entity(fake_entity)
self.assertEqual(self.db.entity.find_one({"entity_id": fake_entity.entity_id})["os"]["distro"], fake_entity.os.distro)
self.assertEqual(self.db.entity.find_one({"entity_id": fake_entity.entity_id})[
"os"]["distro"], fake_entity.os.distro)
def test_insert_volume(self):
count = self.db.entity.count()
@ -259,4 +275,3 @@ class DatabaseAdapterTest(unittest.TestCase):
for key in entity.metadata:
self.assertTrue(key.find("^") == -1,
"The metadata key %s contains carret" % (key))

View File

@ -24,6 +24,7 @@ from almanach.adapters.retry_adapter import RetryAdapter
class BusAdapterTest(unittest.TestCase):
def setUp(self):
self.setup_connection_mock()
self.setup_config_mock()
@ -116,4 +117,4 @@ class BusAdapterTest(unittest.TestCase):
class MyObject(object):
pass
pass

View File

@ -22,14 +22,15 @@ from flexmock import flexmock, flexmock_teardown
from hamcrest import assert_that, has_key, equal_to, has_length, has_entry, has_entries
from almanach import config
from almanach.common.DateFormatException import DateFormatException
from almanach.common.AlmanachException import AlmanachException
from almanach.common.date_format_exception import DateFormatException
from almanach.common.almanach_exception import AlmanachException
from almanach.adapters import api_route_v1 as api_route
from tests.builder import a, instance, volume_type
class ApiTest(TestCase):
def setUp(self):
self.controller = flexmock()
api_route.controller = self.controller
@ -83,7 +84,7 @@ class ApiTest(TestCase):
.with_args(
instance_id="INSTANCE_ID",
start_date=data["start_date"],
).and_return(a(instance().with_id('INSTANCE_ID')))
).and_return(a(instance().with_id('INSTANCE_ID')))
code, result = self.api_update(
'/entity/instance/INSTANCE_ID',
@ -194,8 +195,8 @@ class ApiTest(TestCase):
def test_successful_volume_type_create(self):
self.having_config('api_auth_token', 'some token value')
data = dict(
type_id='A_VOLUME_TYPE_ID',
type_name="A_VOLUME_TYPE_NAME"
type_id='A_VOLUME_TYPE_ID',
type_name="A_VOLUME_TYPE_NAME"
)
self.controller.should_receive('create_volume_type') \
@ -317,10 +318,10 @@ class ApiTest(TestCase):
headers={'X-Auth-Token': 'some token value'}
)
assert_that(result, has_entries(
{
{
"error": "The provided date has an invalid format. "
"Format should be of yyyy-mm-ddThh:mm:ss.msZ, ex: 2015-01-31T18:24:34.1523Z"
}
}
))
assert_that(code, equal_to(400))
@ -375,10 +376,10 @@ class ApiTest(TestCase):
code, result = self.api_delete('/volume/VOLUME_ID', data=data, headers={'X-Auth-Token': 'some token value'})
assert_that(result, has_entries(
{
{
"error": "The provided date has an invalid format. "
"Format should be of yyyy-mm-ddThh:mm:ss.msZ, ex: 2015-01-31T18:24:34.1523Z"
}
}
))
assert_that(code, equal_to(400))
@ -428,10 +429,10 @@ class ApiTest(TestCase):
code, result = self.api_put('/volume/VOLUME_ID/resize', data=data, headers={'X-Auth-Token': 'some token value'})
assert_that(result, has_entries(
{
{
"error": "The provided date has an invalid format. "
"Format should be of yyyy-mm-ddThh:mm:ss.msZ, ex: 2015-01-31T18:24:34.1523Z"
}
}
))
assert_that(code, equal_to(400))
@ -488,10 +489,10 @@ class ApiTest(TestCase):
code, result = self.api_put('/volume/VOLUME_ID/attach', data=data, headers={'X-Auth-Token': 'some token value'})
assert_that(result, has_entries(
{
{
"error": "The provided date has an invalid format. "
"Format should be of yyyy-mm-ddThh:mm:ss.msZ, ex: 2015-01-31T18:24:34.1523Z"
}
}
))
assert_that(code, equal_to(400))
@ -544,10 +545,10 @@ class ApiTest(TestCase):
code, result = self.api_put('/volume/VOLUME_ID/detach', data=data, headers={'X-Auth-Token': 'some token value'})
assert_that(result, has_entries(
{
{
"error": "The provided date has an invalid format. "
"Format should be of yyyy-mm-ddThh:mm:ss.msZ, ex: 2015-01-31T18:24:34.1523Z"
}
}
))
assert_that(code, equal_to(400))
@ -636,10 +637,10 @@ class ApiTest(TestCase):
headers={'X-Auth-Token': 'some token value'}
)
assert_that(result, has_entries(
{
{
"error": "The provided date has an invalid format. "
"Format should be of yyyy-mm-ddThh:mm:ss.msZ, ex: 2015-01-31T18:24:34.1523Z"
}
}
))
assert_that(code, equal_to(400))
@ -717,10 +718,10 @@ class ApiTest(TestCase):
code, result = self.api_delete('/instance/INSTANCE_ID', data=data, headers={'X-Auth-Token': 'some token value'})
assert_that(result, has_entries(
{
{
"error": "The provided date has an invalid format. "
"Format should be of yyyy-mm-ddThh:mm:ss.msZ, ex: 2015-01-31T18:24:34.1523Z"
}
}
))
assert_that(code, equal_to(400))
@ -764,10 +765,10 @@ class ApiTest(TestCase):
headers={'X-Auth-Token': 'some token value'}
)
assert_that(result, has_entries(
{
{
"error": "The provided date has an invalid format. "
"Format should be of yyyy-mm-ddThh:mm:ss.msZ, ex: 2015-01-31T18:24:34.1523Z"
}
}
))
assert_that(code, equal_to(400))
@ -891,6 +892,7 @@ class ApiTest(TestCase):
class DateMatcher(object):
def __init__(self, date):
self.date = date

View File

@ -22,11 +22,13 @@ from almanach.core.model import build_entity_from_dict, Instance, Volume, Volume
class Builder(object):
def __init__(self, dict_object):
self.dict_object = dict_object
class EntityBuilder(Builder):
def build(self):
return build_entity_from_dict(self.dict_object)
@ -73,6 +75,7 @@ class EntityBuilder(Builder):
class VolumeBuilder(EntityBuilder):
def with_attached_to(self, attached_to):
self.dict_object["attached_to"] = attached_to
return self
@ -91,6 +94,7 @@ class VolumeBuilder(EntityBuilder):
class VolumeTypeBuilder(Builder):
def build(self):
return VolumeType(**self.dict_object)

View File

@ -21,7 +21,7 @@ from flexmock import flexmock, flexmock_teardown
from nose.tools import assert_raises
from almanach import config
from almanach.common.DateFormatException import DateFormatException
from almanach.common.date_format_exception import DateFormatException
from almanach.core.controller import Controller
from almanach.core.model import Instance, Volume
from tests.builder import a, instance, volume, volume_type
@ -64,8 +64,8 @@ class ControllerTest(unittest.TestCase):
.once())
self.controller.create_instance(fake_instance.entity_id, fake_instance.project_id, fake_instance.start,
fake_instance.flavor, fake_instance.os.os_type, fake_instance.os.distro,
fake_instance.os.version, fake_instance.name, fake_instance.metadata)
fake_instance.flavor, fake_instance.os.os_type, fake_instance.os.distro,
fake_instance.os.version, fake_instance.name, fake_instance.metadata)
def test_resize_instance(self):
fake_instance = a(instance())
@ -123,9 +123,9 @@ class ControllerTest(unittest.TestCase):
.once())
self.controller.create_instance(fake_instance.entity_id, fake_instance.project_id,
'2015-10-21T16:25:00.000000Z',
fake_instance.flavor, fake_instance.os.os_type, fake_instance.os.distro,
fake_instance.os.version, fake_instance.name, fake_instance.metadata)
'2015-10-21T16:25:00.000000Z',
fake_instance.flavor, fake_instance.os.os_type, fake_instance.os.distro,
fake_instance.os.version, fake_instance.name, fake_instance.metadata)
def test_instance_created_but_find_garbage(self):
fake_instance = a(instance().with_all_dates_in_string())
@ -147,8 +147,8 @@ class ControllerTest(unittest.TestCase):
.once())
self.controller.create_instance(fake_instance.entity_id, fake_instance.project_id, fake_instance.start,
fake_instance.flavor, fake_instance.os.os_type, fake_instance.os.distro,
fake_instance.os.version, fake_instance.name, fake_instance.metadata)
fake_instance.flavor, fake_instance.os.os_type, fake_instance.os.distro,
fake_instance.os.version, fake_instance.name, fake_instance.metadata)
def test_instance_deleted(self):
(flexmock(self.database_adapter)
@ -250,7 +250,8 @@ class ControllerTest(unittest.TestCase):
.with_args("project_id", "start", "end")
.and_return(["volume2", "volume3", "instance1"]))
self.assertEqual(self.controller.list_entities("project_id", "start", "end"), ["volume2", "volume3", "instance1"])
self.assertEqual(self.controller.list_entities(
"project_id", "start", "end"), ["volume2", "volume3", "instance1"])
def test_create_volume(self):
some_volume_type = a(volume_type().with_volume_type_name("some_volume_type_name"))
@ -280,22 +281,22 @@ class ControllerTest(unittest.TestCase):
.once())
self.controller.create_volume(some_volume.entity_id, some_volume.project_id, some_volume.start,
some_volume_type.volume_type_id, some_volume.size, some_volume.name,
some_volume.attached_to)
some_volume_type.volume_type_id, some_volume.size, some_volume.name,
some_volume.attached_to)
def test_create_volume_raises_bad_date_format(self):
some_volume = a(volume())
assert_raises(
DateFormatException,
self.controller.create_volume,
some_volume.entity_id,
some_volume.project_id,
'bad_date_format',
some_volume.volume_type,
some_volume.size,
some_volume.name,
some_volume.attached_to
DateFormatException,
self.controller.create_volume,
some_volume.entity_id,
some_volume.project_id,
'bad_date_format',
some_volume.volume_type,
some_volume.size,
some_volume.name,
some_volume.attached_to
)
def test_create_volume_insert_none_volume_type_as_type(self):
@ -324,8 +325,8 @@ class ControllerTest(unittest.TestCase):
.once())
self.controller.create_volume(some_volume.entity_id, some_volume.project_id, some_volume.start,
some_volume_type.volume_type_id, some_volume.size, some_volume.name,
some_volume.attached_to)
some_volume_type.volume_type_id, some_volume.size, some_volume.name,
some_volume.attached_to)
def test_create_volume_with_invalid_volume_type(self):
some_volume_type = a(volume_type())
@ -350,8 +351,8 @@ class ControllerTest(unittest.TestCase):
with self.assertRaises(KeyError):
self.controller.create_volume(some_volume.entity_id, some_volume.project_id, some_volume.start,
some_volume_type.volume_type_id, some_volume.size, some_volume.name,
some_volume.attached_to)
some_volume_type.volume_type_id, some_volume.size, some_volume.name,
some_volume.attached_to)
def test_create_volume_but_its_an_old_event(self):
some_volume = a(volume().with_last_event(pytz.utc.localize(datetime(2015, 10, 21, 16, 29, 0))))
@ -362,7 +363,7 @@ class ControllerTest(unittest.TestCase):
.once())
self.controller.create_volume(some_volume.entity_id, some_volume.project_id, '2015-10-21T16:25:00.000000Z',
some_volume.volume_type, some_volume.size, some_volume.name, some_volume.attached_to)
some_volume.volume_type, some_volume.size, some_volume.name, some_volume.attached_to)
def test_volume_updated(self):
fake_volume = a(volume())
@ -406,9 +407,9 @@ class ControllerTest(unittest.TestCase):
.with_args(fake_volume))
self.controller.attach_volume(
fake_volume.entity_id,
date.strftime("%Y-%m-%dT%H:%M:%S.%f"),
["new_attached_to"]
fake_volume.entity_id,
date.strftime("%Y-%m-%dT%H:%M:%S.%f"),
["new_attached_to"]
)
self.assertEqual(fake_volume.attached_to, ["new_attached_to"])
@ -430,9 +431,9 @@ class ControllerTest(unittest.TestCase):
.with_args(fake_volume))
self.controller.attach_volume(
fake_volume.entity_id,
date.strftime("%Y-%m-%dT%H:%M:%S.%f"),
["existing_attached_to", "new_attached_to"]
fake_volume.entity_id,
date.strftime("%Y-%m-%dT%H:%M:%S.%f"),
["existing_attached_to", "new_attached_to"]
)
self.assertEqual(fake_volume.attached_to, ["existing_attached_to", "new_attached_to"])
@ -468,9 +469,9 @@ class ControllerTest(unittest.TestCase):
.once())
self.controller.attach_volume(
fake_volume.entity_id,
date.strftime("%Y-%m-%dT%H:%M:%S.%f"),
["new_attached_to"]
fake_volume.entity_id,
date.strftime("%Y-%m-%dT%H:%M:%S.%f"),
["new_attached_to"]
)
def test_volume_detach_with_two_attachments(self):
@ -631,4 +632,3 @@ class ControllerTest(unittest.TestCase):
.once())
self.assertEqual(len(self.controller.list_volume_types()), 2)

View File

@ -272,7 +272,7 @@ def _get_instance_payload(event_type, instance_id=None, tenant_id=None, hostname
def _get_volume_icehouse_payload(event_type, volume_id=None, tenant_id=None, display_name=None, volume_type=None,
volume_size=None, timestamp=None, created_at=None, launched_at=None, status=None, attached_to=None):
volume_size=None, timestamp=None, created_at=None, launched_at=None, status=None, attached_to=None):
volume_id = volume_id or "64a0ca7f-5f5a-4dc5-a1e1-e04e89eb95ed"
tenant_id = tenant_id or "46eeb8e44298460899cf4b3554bfe11f"
display_name = display_name or "mytenant-0001-myvolume"
@ -312,7 +312,7 @@ def _get_volume_icehouse_payload(event_type, volume_id=None, tenant_id=None, dis
def _get_volume_kilo_payload(event_type, volume_id=None, tenant_id=None, display_name=None, volume_type=None,
timestamp=None, attached_to=None, volume_size=1):
timestamp=None, attached_to=None, volume_size=1):
volume_id = volume_id or "64a0ca7f-5f5a-4dc5-a1e1-e04e89eb95ed"
tenant_id = tenant_id or "46eeb8e44298460899cf4b3554bfe11f"
display_name = display_name or "mytenant-0001-myvolume"