Update pep8 to 1.3.3

This is needed to update openstack.common

Change-Id: I8410f978f38b3893b71239f97f785086ca5faffe
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2013-01-08 17:47:18 +01:00
parent edd9332323
commit 51c8a8e55c
71 changed files with 331 additions and 352 deletions

View File

@ -32,5 +32,5 @@ API_SERVICE_OPTS = [
default=8777,
help='The port for the ceilometer API server',
),
]
]
cfg.CONF.register_opts(API_SERVICE_OPTS)

View File

@ -284,7 +284,7 @@ class MeterController(RestController):
_custom_actions = {
'duration': ['GET'],
}
}
def __init__(self, meter_id):
request.context['meter_id'] = meter_id
@ -304,7 +304,7 @@ class MeterController(RestController):
resource=request.context.get('resource_id'),
meter=self._id,
source=request.context.get('source_id'),
)
)
return [Event(**e)
for e in request.storage_conn.get_raw_events(f)
]
@ -445,7 +445,8 @@ class ResourcesController(RestController):
project=request.context.get('project_id'),
start_timestamp=start_timestamp,
end_timestamp=end_timestamp,
)]
)
]
return resources

View File

@ -105,7 +105,7 @@ def request_wants_html():
def _get_metaquery(args):
return dict((k, v)
for (k, v) in args.iteritems()
if k.startswith('metadata.'))
if k.startswith('metadata.'))
def check_authorized_project(project):
@ -204,7 +204,7 @@ def _list_resources(source=None, user=None, project=None):
start_timestamp=q_ts['start_timestamp'],
end_timestamp=q_ts['end_timestamp'],
metaquery=_get_metaquery(rq.args),
)
)
return flask.jsonify(resources=list(resources))
@ -371,14 +371,15 @@ def _list_events(meter,
"""Return a list of raw metering events.
"""
q_ts = _get_query_timestamps(flask.request.args)
f = storage.EventFilter(user=user,
project=project,
source=source,
meter=meter,
resource=resource,
start=q_ts['start_timestamp'],
end=q_ts['end_timestamp'],
metaquery=_get_metaquery(flask.request.args),
f = storage.EventFilter(
user=user,
project=project,
source=source,
meter=meter,
resource=resource,
start=q_ts['start_timestamp'],
end=q_ts['end_timestamp'],
metaquery=_get_metaquery(flask.request.args),
)
events = list(flask.request.storage_conn.get_raw_events(f))
jsonified = flask.jsonify(events=events)

View File

@ -26,7 +26,7 @@ OPTS = [
default=[],
help='list of central pollsters to disable',
),
]
]
cfg.CONF.register_opts(OPTS)
@ -42,7 +42,7 @@ class AgentManager(object):
self.ext_manager = extension_manager.ActivatedExtensionManager(
namespace=PLUGIN_NAMESPACE,
disabled_names=cfg.CONF.disabled_central_pollsters,
)
)
@staticmethod
def publish_counters_from_one_pollster(ext, manager, context):

View File

@ -33,7 +33,7 @@ METER_OPTS = [
default='openstack',
help='Source for counters emited on this instance',
),
]
]
def register_opts(config):

View File

@ -35,7 +35,7 @@ OPTS = [
default=[],
help='list of listener plugins to disable',
),
]
]
cfg.CONF.register_opts(OPTS)
@ -59,7 +59,7 @@ class CollectorService(service.PeriodicService):
self.ext_manager = extension_manager.ActivatedExtensionManager(
namespace=self.COLLECTOR_NAMESPACE,
disabled_names=cfg.CONF.disabled_notification_listeners,
)
)
if not list(self.ext_manager):
LOG.warning('Failed to load any notification handlers for %s',
@ -73,7 +73,7 @@ class CollectorService(service.PeriodicService):
cfg.CONF.metering_topic,
rpc_dispatcher.RpcDispatcher([self]),
'ceilometer.collector.' + cfg.CONF.metering_topic,
)
)
def _setup_subscription(self, ext, *args, **kwds):
handler = ext.obj
@ -90,7 +90,7 @@ class CollectorService(service.PeriodicService):
topic=topic,
exchange_name=exchange_topic.exchange,
callback=self.process_notification,
)
)
def process_notification(self, notification):
"""Make a notification processed by an handler."""

View File

@ -33,8 +33,7 @@ INSTANCE_PROPERTIES = [
'ephemeral_gb',
'memory_mb',
'root_gb',
'vcpus',
]
'vcpus']
def get_metadata_from_object(instance):
@ -48,8 +47,8 @@ def get_metadata_from_object(instance):
# Image properties
'image_ref': (instance.image['id'] if instance.image else None),
'image_ref_url': (instance.image['links'][0]['href']
if instance.image else None),
}
if instance.image else None),
}
for name in INSTANCE_PROPERTIES:
metadata[name] = getattr(instance, name, u'')

View File

@ -33,9 +33,8 @@ OPTS = [
),
cfg.StrOpt('hypervisor_inspector',
default='libvirt',
help='Inspector to use for inspecting the hypervisor layer',
),
]
help='Inspector to use for inspecting the hypervisor layer'),
]
cfg.CONF.register_opts(OPTS)
@ -63,7 +62,7 @@ class AgentManager(object):
self.ext_manager = extension_manager.ActivatedExtensionManager(
namespace=PLUGIN_NAMESPACE,
disabled_names=cfg.CONF.disabled_compute_pollsters,
)
)
self._inspector = get_hypervisor_inspector()
return

View File

@ -50,8 +50,7 @@ class _Base(plugin.NotificationBase):
'compute.instance.exists',
'compute.instance.delete.start',
'compute.instance.finish_resize.end',
'compute.instance.resize.revert.end',
]
'compute.instance.resize.revert.end']
@staticmethod
def get_exchange_topics(conf):
@ -80,7 +79,7 @@ class Instance(_Base):
resource_metadata=self.notification_to_metadata(
message),
),
]
]
class Memory(_Base):
@ -96,9 +95,8 @@ class Memory(_Base):
resource_id=message['payload']['instance_id'],
timestamp=message['timestamp'],
resource_metadata=self.notification_to_metadata(
message),
),
]
message)),
]
class VCpus(_Base):
@ -114,9 +112,8 @@ class VCpus(_Base):
resource_id=message['payload']['instance_id'],
timestamp=message['timestamp'],
resource_metadata=self.notification_to_metadata(
message),
),
]
message)),
]
class RootDiskSize(_Base):
@ -132,9 +129,8 @@ class RootDiskSize(_Base):
resource_id=message['payload']['instance_id'],
timestamp=message['timestamp'],
resource_metadata=self.notification_to_metadata(
message),
),
]
message)),
]
class EphemeralDiskSize(_Base):
@ -150,9 +146,8 @@ class EphemeralDiskSize(_Base):
resource_id=message['payload']['instance_id'],
timestamp=message['timestamp'],
resource_metadata=self.notification_to_metadata(
message),
),
]
message)),
]
class InstanceFlavor(_Base):

View File

@ -60,4 +60,6 @@ def notify(context, message):
instance_id = message['payload']['instance_id']
LOG.debug('polling final stats for %r', instance_id)
_agent_manager.poll_instance(context,
instance_info_source.instance_get_by_uuid(context, instance_id))
instance_info_source.instance_get_by_uuid(
context,
instance_id))

View File

@ -46,7 +46,7 @@ def make_counter_from_instance(instance, name, type, unit, volume):
resource_id=instance.id,
timestamp=timeutils.isotime(),
resource_metadata=compute_instance.get_metadata_from_object(instance),
)
)
class InstancePollster(plugin.ComputePollster):
@ -56,15 +56,13 @@ class InstancePollster(plugin.ComputePollster):
name='instance',
type=counter.TYPE_GAUGE,
unit='instance',
volume=1,
)
volume=1)
yield make_counter_from_instance(instance,
name='instance:%s' %
instance.flavor['name'],
type=counter.TYPE_GAUGE,
unit='instance',
volume=1,
)
volume=1)
class DiskIOPollster(plugin.ComputePollster):
@ -194,8 +192,8 @@ class NetPollster(plugin.ComputePollster):
metadata = copy.copy(vnic_data)
resource_metadata = dict(zip(metadata._fields, metadata))
resource_metadata['instance_id'] = instance.id
resource_metadata['instance_type'] = instance.flavor['id'] if \
instance.flavor else None,
resource_metadata['instance_type'] = \
instance.flavor['id'] if instance.flavor else None,
return counter.Counter(
name=name,

View File

@ -36,7 +36,7 @@ libvirt_opts = [
default='',
help='Override the default libvirt URI '
'(which is dependent on libvirt_type)'),
]
]
CONF = cfg.CONF
CONF.register_opts(libvirt_opts)
@ -126,9 +126,10 @@ class LibvirtInspector(virt_inspector.Inspector):
def inspect_disks(self, instance_name):
domain = self._lookup_by_name(instance_name)
tree = etree.fromstring(domain.XMLDesc(0))
for device in filter(bool,
[target.get("dev")
for target in tree.findall('devices/disk/target')]):
for device in filter(
bool,
[target.get("dev")
for target in tree.findall('devices/disk/target')]):
disk = virt_inspector.Disk(device=device)
block_stats = domain.blockStats(device)
stats = virt_inspector.DiskStats(read_requests=block_stats[0],

View File

@ -38,14 +38,14 @@ def should_use_extension(namespace, ext, disabled_names):
LOG.debug(
'%s extension %r disabled through configuration setting',
namespace, ext.name,
)
)
return False
if not ext.obj.is_enabled():
LOG.debug(
'%s extension %r reported that it is disabled',
namespace,
ext.name,
)
)
return False
LOG.debug('using %s extension %r', namespace, ext.name)
return True
@ -68,4 +68,4 @@ class ActivatedExtensionManager(enabled.EnabledExtensionManager):
invoke_on_load=invoke_on_load,
invoke_args=invoke_args,
invoke_kwds=invoke_kwds,
)
)

View File

@ -61,24 +61,24 @@ class _Base(plugin.PollsterBase):
@staticmethod
def extract_image_metadata(image):
return dict((k, getattr(image, k))
for k in [
"status",
"is_public",
"name",
"deleted",
"container_format",
"created_at",
"disk_format",
"updated_at",
"properties",
"min_disk",
"protected",
"checksum",
"deleted_at",
"min_ram",
"size",
]
)
for k in
[
"status",
"is_public",
"name",
"deleted",
"container_format",
"created_at",
"disk_format",
"updated_at",
"properties",
"min_disk",
"protected",
"checksum",
"deleted_at",
"min_ram",
"size",
])
class ImagePollster(_Base):

View File

@ -47,4 +47,4 @@ class FloatingIPPollster(plugin.CentralPollster):
'host': ip.host,
'pool': ip.pool,
'auto_assigned': ip.auto_assigned
})
})

View File

@ -61,8 +61,8 @@ class Client(object):
"""Returns list of instances on particular host"""
search_opts = {'host': hostname, 'all_tenants': True}
return self._with_flavor(self.nova_client.servers.list(
detailed=True,
search_opts=search_opts))
detailed=True,
search_opts=search_opts))
@logged
def floating_ip_get_all(self):

View File

@ -36,8 +36,8 @@ LOG = log.getLogger(__name__)
OPTS = [
cfg.StrOpt('reseller_prefix',
default='AUTH_',
help="Swift reseller prefix. Must be on par with "\
"reseller_prefix in proxy-server.conf."),
help="Swift reseller prefix. Must be on par with "
"reseller_prefix in proxy-server.conf."),
]
cfg.CONF.register_opts(OPTS)

View File

@ -104,7 +104,8 @@ class CeilometerMiddleware(object):
"version": version,
"container": container,
"object": obj,
}),
},
),
cfg.CONF.metering_topic,
cfg.CONF.metering_secret,
cfg.CONF.counter_source)
@ -126,7 +127,7 @@ class CeilometerMiddleware(object):
"version": version,
"container": container,
"object": obj,
}),
}),
cfg.CONF.metering_topic,
cfg.CONF.metering_secret,
cfg.CONF.counter_source)

View File

@ -54,7 +54,7 @@ class BaseParser(object):
value = value.strip()
if ((value and value[0] == value[-1]) and
(value[0] == "\"" or value[0] == "'")):
(value[0] == "\"" or value[0] == "'")):
value = value[1:-1]
return key.strip(), [value]

View File

@ -258,7 +258,7 @@ class JSONFormatter(logging.Formatter):
class PublishErrorsHandler(logging.Handler):
def emit(self, record):
if ('ceilometer.openstack.common.notifier.log_notifier' in
CONF.notification_driver):
CONF.notification_driver):
return
notifier.api.notify(None, 'error.publisher',
'error_notification',
@ -418,7 +418,7 @@ class LegacyFormatter(logging.Formatter):
self._fmt = CONF.logging_default_format_string
if (record.levelno == logging.DEBUG and
CONF.logging_debug_format_suffix):
CONF.logging_debug_format_suffix):
self._fmt += " " + CONF.logging_debug_format_suffix
# Cache this on the record, Logger will respect our formated copy

View File

@ -31,7 +31,7 @@ OPTS = [
cfg.StrOpt('policy_default_rule',
default='default',
help='Rule checked when requested rule is not found'),
]
]
cfg.CONF.register_opts(OPTS)

View File

@ -33,7 +33,7 @@ PUBLISH_OPTS = [
cfg.StrOpt('control_exchange',
default='ceilometer',
help='AMQP exchange to connect to if using RabbitMQ or Qpid'),
]
]
def register_opts(config):
@ -59,7 +59,7 @@ def publish_counter(context, counter, topic, secret, source):
secret,
source),
},
}
}
LOG.debug('PUBLISH: %s', str(msg))
rpc.cast(context, topic, msg)
rpc.cast(context, topic + '.' + counter.name, msg)

View File

@ -66,8 +66,8 @@ class PeriodicService(rpc_service.Service):
super(PeriodicService, self).start()
admin_context = context.RequestContext('admin', 'admin', is_admin=True)
self.tg.add_timer(cfg.CONF.periodic_interval,
self.manager.periodic_tasks,
context=admin_context)
self.manager.periodic_tasks,
context=admin_context)
def _sanitize_cmd_line(argv):

View File

@ -36,7 +36,7 @@ STORAGE_OPTS = [
default='mongodb://localhost:27017/ceilometer',
help='Database connection string',
),
]
]
cfg.CONF.register_opts(STORAGE_OPTS)

View File

@ -193,17 +193,16 @@ class Connection(base.Connection):
# including both.
for primary in ['user_id', 'project_id']:
self.db.resource.ensure_index([
(primary, pymongo.ASCENDING),
('source', pymongo.ASCENDING),
], name='resource_idx')
(primary, pymongo.ASCENDING),
('source', pymongo.ASCENDING),
], name='resource_idx')
self.db.meter.ensure_index([
('resource_id', pymongo.ASCENDING),
(primary, pymongo.ASCENDING),
('counter_name', pymongo.ASCENDING),
('timestamp', pymongo.ASCENDING),
('source', pymongo.ASCENDING),
], name='meter_idx')
return
('resource_id', pymongo.ASCENDING),
(primary, pymongo.ASCENDING),
('counter_name', pymongo.ASCENDING),
('timestamp', pymongo.ASCENDING),
('source', pymongo.ASCENDING),
], name='meter_idx')
def upgrade(self, version=None):
pass
@ -249,14 +248,14 @@ class Connection(base.Connection):
},
},
upsert=True,
)
)
self.db.project.update(
{'_id': data['project_id']},
{'$addToSet': {'source': data['source'],
},
},
upsert=True,
)
)
# Record the updated resource metadata
received_timestamp = datetime.datetime.utcnow()
@ -278,7 +277,7 @@ class Connection(base.Connection):
},
},
upsert=True,
)
)
# Record the raw data for the event. Use a copy so we do not
# modify a data structure owned by our caller (the driver adds

View File

@ -252,7 +252,7 @@ class Connection(base.Connection):
if project is not None:
query = query.filter(Resource.project_id == project)
query = query.options(
sqlalchemy_session.sqlalchemy.orm.joinedload('meters'))
sqlalchemy_session.sqlalchemy.orm.joinedload('meters'))
if metaquery is not None:
raise NotImplementedError('metaquery not implemented')
@ -298,7 +298,7 @@ class Connection(base.Connection):
if project is not None:
query = query.filter(Resource.project_id == project)
query = query.options(
sqlalchemy_session.sqlalchemy.orm.joinedload('meters'))
sqlalchemy_session.sqlalchemy.orm.joinedload('meters'))
if len(metaquery) > 0:
raise NotImplementedError('metaquery not implemented')

View File

@ -21,7 +21,7 @@ def upgrade(migrate_engine):
if migrate_engine.name == "mysql":
tables = ['meter', 'user', 'resource', 'project', 'source',
'sourceassoc']
'sourceassoc']
sql = "SET foreign_key_checks = 0;"
for table in tables:
@ -36,7 +36,7 @@ def downgrade(migrate_engine):
# Operations to reverse the above upgrade go here.
if migrate_engine.name == "mysql":
tables = ['meter', 'user', 'resource', 'project', 'source',
'sourceassoc']
'sourceassoc']
sql = "SET foreign_key_checks = 0;"
for table in tables:

View File

@ -46,8 +46,8 @@ def patched_with_engine(f, *a, **kw):
# TODO(jkoelker) When migrate 0.7.3 is released and nova depends
# on that version or higher, this can be removed
MIN_PKG_VERSION = dist_version.StrictVersion('0.7.3')
if (not hasattr(migrate, '__version__') or
dist_version.StrictVersion(migrate.__version__) < MIN_PKG_VERSION):
if (not hasattr(migrate, '__version__')
or dist_version.StrictVersion(migrate.__version__) < MIN_PKG_VERSION):
migrate_util.with_engine = patched_with_engine

View File

@ -33,7 +33,7 @@ sql_opts = [
cfg.StrOpt('mysql_engine',
default='InnoDB',
help='MySQL engine')
]
]
cfg.CONF.register_opts(sql_opts)
@ -78,12 +78,16 @@ Base = declarative_base(cls=CeilometerBase)
sourceassoc = Table('sourceassoc', Base.metadata,
Column('meter_id', Integer, ForeignKey("meter.id")),
Column('project_id', String(255), ForeignKey("project.id")),
Column('resource_id', String(255), ForeignKey("resource.id")),
Column('user_id', String(255), ForeignKey("user.id")),
Column('source_id', String(255), ForeignKey("source.id"))
)
Column('meter_id', Integer,
ForeignKey("meter.id")),
Column('project_id', String(255),
ForeignKey("project.id")),
Column('resource_id', String(255),
ForeignKey("resource.id")),
Column('user_id', String(255),
ForeignKey("user.id")),
Column('source_id', String(255),
ForeignKey("source.id")))
class Source(Base):

View File

@ -41,8 +41,8 @@ sql_opts = [
help='Verbosity of SQL debugging information. 0=None, '
'100=Everything'),
cfg.BoolOpt('sql_connection_trace',
default=False,
help='Add python stack traces to SQL as comment strings'),
default=False,
help='Add python stack traces to SQL as comment strings'),
cfg.BoolOpt('sqlite_synchronous',
default=True,
help='If passed, use synchronous mode for sqlite'),
@ -56,7 +56,7 @@ sql_opts = [
cfg.IntOpt('sql_retry_interval',
default=10,
help='interval between retries of opening a sql connection'),
]
]
cfg.CONF.register_opts(sql_opts)
@ -121,7 +121,7 @@ def get_engine():
global _ENGINE
if _ENGINE is None:
connection_dict = sqlalchemy.engine.url.make_url(
cfg.CONF.database_connection)
cfg.CONF.database_connection)
engine_args = {
"pool_recycle": cfg.CONF.sql_idle_timeout,
@ -178,8 +178,8 @@ def get_engine():
_ENGINE.connect()
break
except OperationalError, e:
if (remaining != 'infinite' and remaining == 0) or \
not is_db_connection_error(e.args[0]):
if (remaining != 'infinite' and remaining == 0) \
or not is_db_connection_error(e.args[0]):
raise
return _ENGINE

View File

@ -103,7 +103,7 @@ class FunctionalTest(unittest.TestCase):
'modules': ['ceilometer.api'],
'static_root': '%s/public' % root_dir,
'template_path': '%s/ceilometer/api/templates' % root_dir,
},
},
'logging': {
'loggers': {
@ -112,22 +112,22 @@ class FunctionalTest(unittest.TestCase):
'ceilometer': {'level': 'DEBUG',
'handlers': ['console'],
},
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
}
},
}
},
'formatters': {
'simple': {
'format': ('%(asctime)s %(levelname)-5.5s [%(name)s]'
'[%(threadName)s] %(message)s')
}
},
}
},
}
},
}
self.mox = mox.Mox()
self.stubs = stubout.StubOutForTesting()

View File

@ -61,8 +61,7 @@ class _Base(plugin.NotificationBase):
def get_event_types():
return ['volume.exists',
'volume.create.end',
'volume.delete.start',
]
'volume.delete.start']
class Volume(_Base):

View File

@ -136,4 +136,4 @@ setuptools.setup(
[paste.filter_factory]
swift=ceilometer.objectstore.swift_middleware:filter_factory
"""),
)
)

View File

@ -36,17 +36,17 @@ class TestComputeDurationByResource(tests_api.TestBase):
# Create events relative to the range and pretend
# that the intervening events exist.
self.early1 = datetime.datetime(2012, 8, 27, 7, 0)
self.early1 = datetime.datetime(2012, 8, 27, 7, 0)
self.early2 = datetime.datetime(2012, 8, 27, 17, 0)
self.start = datetime.datetime(2012, 8, 28, 0, 0)
self.middle1 = datetime.datetime(2012, 8, 28, 8, 0)
self.middle1 = datetime.datetime(2012, 8, 28, 8, 0)
self.middle2 = datetime.datetime(2012, 8, 28, 18, 0)
self.end = datetime.datetime(2012, 8, 28, 23, 59)
self.late1 = datetime.datetime(2012, 8, 29, 9, 0)
self.late1 = datetime.datetime(2012, 8, 29, 9, 0)
self.late2 = datetime.datetime(2012, 8, 29, 19, 0)
def _set_interval(self, start, end):
@ -62,7 +62,7 @@ class TestComputeDurationByResource(tests_api.TestBase):
start_timestamp=self.start.isoformat(),
end_timestamp=self.end.isoformat(),
search_offset=10, # this value doesn't matter, db call is mocked
)
)
def test_before_range(self):
self._set_interval(self.early1, self.early2)
@ -118,7 +118,7 @@ class TestComputeDurationByResource(tests_api.TestBase):
'/resources/resource-id/meters/instance:m1.tiny/duration',
start_timestamp=self.late1.isoformat(),
search_offset=10, # this value doesn't matter, db call is mocked
)
)
self._assert_times_match(data['start_timestamp'], self.late1)
self._assert_times_match(data['end_timestamp'], self.late2)
@ -130,6 +130,6 @@ class TestComputeDurationByResource(tests_api.TestBase):
'/resources/resource-id/meters/instance:m1.tiny/duration',
end_timestamp=self.early2.isoformat(),
search_offset=10, # this value doesn't matter, db call is mocked
)
)
self._assert_times_match(data['start_timestamp'], self.early1)
self._assert_times_match(data['end_timestamp'], self.early2)

View File

@ -46,8 +46,7 @@ class TestListEvents(tests_api.TestBase):
'resource-id',
timestamp=datetime.datetime(2012, 7, 2, 10, 40),
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}
'tag': 'self.counter'}
),
counter.Counter(
'instance',
@ -59,8 +58,7 @@ class TestListEvents(tests_api.TestBase):
'resource-id',
timestamp=datetime.datetime(2012, 7, 2, 10, 41),
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}
'tag': 'self.counter'}
),
counter.Counter(
'instance',
@ -72,8 +70,7 @@ class TestListEvents(tests_api.TestBase):
'resource-id-alternate',
timestamp=datetime.datetime(2012, 7, 2, 10, 42),
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter2',
}
'tag': 'self.counter2'}
),
]:
msg = meter.meter_message_from_counter(cnt,
@ -116,14 +113,14 @@ class TestListEvents(tests_api.TestBase):
def test_by_resource_non_admin(self):
data = self.get('/resources/resource-id-alternate/meters/instance',
headers={"X-Roles": "Member",
"X-Tenant-Id": "project2"})
headers={"X-Roles": "Member",
"X-Tenant-Id": "project2"})
self.assertEquals(1, len(data['events']))
def test_by_resource_some_tenant(self):
data = self.get('/resources/resource-id/meters/instance',
headers={"X-Roles": "Member",
"X-Tenant-Id": "project2"})
headers={"X-Roles": "Member",
"X-Tenant-Id": "project2"})
self.assertEquals(0, len(data['events']))
def test_empty_source(self):
@ -168,7 +165,7 @@ class TestListEvents(tests_api.TestBase):
def test_by_user_with_timestamps(self):
data = self.get('/users/user-id/meters/instance',
start_timestamp=datetime.datetime(2012, 7, 2, 10, 41),
end_timestamp=datetime.datetime(2012, 7, 2, 10, 42))
end_timestamp=datetime.datetime(2012, 7, 2, 10, 42))
self.assertEquals(1, len(data['events']))
def test_metaquery1(self):
@ -203,6 +200,6 @@ class TestListEvents(tests_api.TestBase):
def test_metaquery3_with_project(self):
q = '/sources/source1/meters/instance'
data = self.get('%s?metadata.display_name=test-server' % q,
headers={"X-Roles": "Member",
"X-Tenant-Id": "project2"})
headers={"X-Roles": "Member",
"X-Tenant-Id": "project2"})
self.assertEquals(1, len(data['events']))

View File

@ -54,8 +54,7 @@ class TestListMeters(tests_api.TestBase):
'resource-id',
timestamp=datetime.datetime(2012, 7, 2, 10, 40),
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}),
'tag': 'self.counter'}),
counter.Counter(
'meter.test',
'cumulative',
@ -66,8 +65,7 @@ class TestListMeters(tests_api.TestBase):
'resource-id',
timestamp=datetime.datetime(2012, 7, 2, 11, 40),
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}),
'tag': 'self.counter'}),
counter.Counter(
'meter.mine',
'gauge',
@ -78,8 +76,7 @@ class TestListMeters(tests_api.TestBase):
'resource-id2',
timestamp=datetime.datetime(2012, 7, 2, 10, 41),
resource_metadata={'display_name': 'test-server',
'tag': 'two.counter',
}),
'tag': 'two.counter'}),
counter.Counter(
'meter.test',
'cumulative',
@ -90,8 +87,7 @@ class TestListMeters(tests_api.TestBase):
'resource-id3',
timestamp=datetime.datetime(2012, 7, 2, 10, 42),
resource_metadata={'display_name': 'test-server',
'tag': 'three.counter',
}),
'tag': 'three.counter'}),
counter.Counter(
'meter.mine',
'gauge',
@ -102,8 +98,7 @@ class TestListMeters(tests_api.TestBase):
'resource-id4',
timestamp=datetime.datetime(2012, 7, 2, 10, 43),
resource_metadata={'display_name': 'test-server',
'tag': 'four.counter',
})]:
'tag': 'four.counter'})]:
msg = meter.meter_message_from_counter(cnt,
cfg.CONF.metering_secret,
'test_list_resources')

View File

@ -52,9 +52,8 @@ class TestListProjects(tests_api.TestBase):
'resource-id',
timestamp=datetime.datetime(2012, 7, 2, 10, 40),
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}
)
'tag': 'self.counter'}
)
msg = meter.meter_message_from_counter(counter1,
cfg.CONF.metering_secret,
'test_list_projects',
@ -71,9 +70,8 @@ class TestListProjects(tests_api.TestBase):
'resource-id-alternate',
timestamp=datetime.datetime(2012, 7, 2, 10, 41),
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter2',
}
)
'tag': 'self.counter2'}
)
msg2 = meter.meter_message_from_counter(counter2,
cfg.CONF.metering_secret,
'test_list_users',

View File

@ -54,8 +54,8 @@ class TestListResources(tests_api.TestBase):
'resource-id',
timestamp=datetime.datetime(2012, 7, 2, 10, 40),
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}),
'tag': 'self.counter'},
),
counter.Counter(
'instance',
'cumulative',
@ -66,8 +66,8 @@ class TestListResources(tests_api.TestBase):
'resource-id-alternate',
timestamp=datetime.datetime(2012, 7, 2, 10, 41),
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter2',
}),
'tag': 'self.counter2'},
),
counter.Counter(
'instance',
'cumulative',
@ -78,8 +78,8 @@ class TestListResources(tests_api.TestBase):
'resource-id2',
timestamp=datetime.datetime(2012, 7, 2, 10, 42),
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter3',
}),
'tag': 'self.counter3'},
),
counter.Counter(
'instance',
'cumulative',
@ -90,8 +90,8 @@ class TestListResources(tests_api.TestBase):
'resource-id',
timestamp=datetime.datetime(2012, 7, 2, 10, 43),
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter4',
})]:
'tag': 'self.counter4'}
)]:
msg = meter.meter_message_from_counter(cnt,
cfg.CONF.metering_secret,
'test_list_resources')

View File

@ -55,7 +55,7 @@ class TestListUsers(tests_api.TestBase):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}
)
)
msg = meter.meter_message_from_counter(counter1,
cfg.CONF.metering_secret,
'test_list_users',
@ -74,7 +74,7 @@ class TestListUsers(tests_api.TestBase):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter2',
}
)
)
msg2 = meter.meter_message_from_counter(counter2,
cfg.CONF.metering_secret,
'not-test',

View File

@ -49,7 +49,7 @@ class TestMaxProjectVolume(tests_api.TestBase):
resource_metadata={'display_name': 'test-volume',
'tag': 'self.counter',
}
)
)
self.counters.append(c)
msg = meter.meter_message_from_counter(c,
cfg.CONF.metering_secret,

View File

@ -48,7 +48,7 @@ class TestMaxResourceVolume(tests_api.TestBase):
resource_metadata={'display_name': 'test-volume',
'tag': 'self.counter',
}
)
)
self.counters.append(c)
msg = meter.meter_message_from_counter(c,
cfg.CONF.metering_secret,

View File

@ -49,7 +49,7 @@ class TestSumProjectVolume(tests_api.TestBase):
resource_metadata={'display_name': 'test-volume',
'tag': 'self.counter',
}
)
)
self.counters.append(c)
msg = meter.meter_message_from_counter(c,
cfg.CONF.metering_secret,

View File

@ -49,7 +49,7 @@ class TestSumResourceVolume(tests_api.TestBase):
resource_metadata={'display_name': 'test-volume',
'tag': 'self.counter',
}
)
)
self.counters.append(c)
msg = meter.meter_message_from_counter(c,
cfg.CONF.metering_secret,

View File

@ -51,10 +51,11 @@ class TestAPIACL(FunctionalTest):
response = self.get_json('/sources',
expect_errors=True,
headers={
"X-Roles": "Member",
"X-Tenant-Name": "admin",
"X-Tenant-Id": "bc23a9d531064583ace8f67dad60f6bb",
})
"X-Roles": "Member",
"X-Tenant-Name": "admin",
"X-Tenant-Id":
"bc23a9d531064583ace8f67dad60f6bb",
})
self.assertEqual(response.status_int, 401)
# FIXME(dhellmann): This test is not properly looking at the tenant
@ -76,8 +77,9 @@ class TestAPIACL(FunctionalTest):
response = self.get_json('/sources',
expect_errors=True,
headers={
"X-Roles": "admin",
"X-Tenant-Name": "admin",
"X-Tenant-Id": "bc23a9d531064583ace8f67dad60f6bb",
})
"X-Roles": "admin",
"X-Tenant-Name": "admin",
"X-Tenant-Id":
"bc23a9d531064583ace8f67dad60f6bb",
})
self.assertEqual(response.status_int, 200)

View File

@ -36,17 +36,17 @@ class TestComputeDurationByResource(FunctionalTest):
# Create events relative to the range and pretend
# that the intervening events exist.
self.early1 = datetime.datetime(2012, 8, 27, 7, 0)
self.early1 = datetime.datetime(2012, 8, 27, 7, 0)
self.early2 = datetime.datetime(2012, 8, 27, 17, 0)
self.start = datetime.datetime(2012, 8, 28, 0, 0)
self.middle1 = datetime.datetime(2012, 8, 28, 8, 0)
self.middle1 = datetime.datetime(2012, 8, 28, 8, 0)
self.middle2 = datetime.datetime(2012, 8, 28, 18, 0)
self.end = datetime.datetime(2012, 8, 28, 23, 59)
self.late1 = datetime.datetime(2012, 8, 29, 9, 0)
self.late1 = datetime.datetime(2012, 8, 29, 9, 0)
self.late2 = datetime.datetime(2012, 8, 29, 19, 0)
def _stub_interval_func(self, func):

View File

@ -46,7 +46,7 @@ class DateRangeTest(unittest.TestCase):
'query_start': datetime.datetime(2012, 9, 20, 12, 13, 14),
'query_end': None,
'search_offset': 0,
}
}
assert result == expected
@ -59,7 +59,7 @@ class DateRangeTest(unittest.TestCase):
'query_end': datetime.datetime(2012, 9, 20, 12, 13, 14),
'query_start': None,
'search_offset': 0,
}
}
assert result == expected
@ -68,13 +68,13 @@ class DateRangeTest(unittest.TestCase):
end=datetime.datetime(2012, 9, 20, 13, 24, 25),
start=datetime.datetime(2012, 9, 20, 12, 13, 14),
search_offset=20,
).to_dict()
).to_dict()
expected = {
'query_end': datetime.datetime(2012, 9, 20, 13, 44, 25),
'query_start': datetime.datetime(2012, 9, 20, 11, 53, 14),
'end_timestamp': datetime.datetime(2012, 9, 20, 13, 24, 25),
'start_timestamp': datetime.datetime(2012, 9, 20, 12, 13, 14),
'search_offset': 20,
}
}
assert result == expected

View File

@ -48,7 +48,7 @@ class TestListEvents(FunctionalTest):
'ignored_dict': {'key': 'value'},
'ignored_list': ['not-returned'],
}
)
)
msg = meter.meter_message_from_counter(self.counter1,
cfg.CONF.metering_secret,
'test_source',
@ -67,7 +67,7 @@ class TestListEvents(FunctionalTest):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter2',
}
)
)
msg2 = meter.meter_message_from_counter(self.counter2,
cfg.CONF.metering_secret,
'source2',

View File

@ -53,8 +53,7 @@ class TestListMeters(FunctionalTest):
'resource-id',
timestamp=datetime.datetime(2012, 7, 2, 10, 40),
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}),
'tag': 'self.counter'}),
counter.Counter(
'meter.test',
'cumulative',
@ -65,8 +64,7 @@ class TestListMeters(FunctionalTest):
'resource-id',
timestamp=datetime.datetime(2012, 7, 2, 11, 40),
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}),
'tag': 'self.counter'}),
counter.Counter(
'meter.mine',
'gauge',
@ -77,8 +75,7 @@ class TestListMeters(FunctionalTest):
'resource-id2',
timestamp=datetime.datetime(2012, 7, 2, 10, 41),
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter2',
}),
'tag': 'self.counter2'}),
counter.Counter(
'meter.test',
'cumulative',
@ -89,8 +86,7 @@ class TestListMeters(FunctionalTest):
'resource-id3',
timestamp=datetime.datetime(2012, 7, 2, 10, 42),
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter3',
}),
'tag': 'self.counter3'}),
counter.Counter(
'meter.mine',
'gauge',
@ -101,8 +97,7 @@ class TestListMeters(FunctionalTest):
'resource-id4',
timestamp=datetime.datetime(2012, 7, 2, 10, 43),
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter4',
})]:
'tag': 'self.counter4'})]:
msg = meter.meter_message_from_counter(cnt,
cfg.CONF.metering_secret,
'test_source')

View File

@ -50,7 +50,7 @@ class TestListProjects(FunctionalTest):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}
)
)
msg = meter.meter_message_from_counter(counter1,
cfg.CONF.metering_secret,
'test_source',
@ -69,7 +69,7 @@ class TestListProjects(FunctionalTest):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter2',
}
)
)
msg2 = meter.meter_message_from_counter(counter2,
cfg.CONF.metering_secret,
'test_source',
@ -92,7 +92,7 @@ class TestListProjects(FunctionalTest):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}
)
)
msg = meter.meter_message_from_counter(counter1,
cfg.CONF.metering_secret,
'test_source',
@ -111,7 +111,7 @@ class TestListProjects(FunctionalTest):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter2',
}
)
)
msg2 = meter.meter_message_from_counter(counter2,
cfg.CONF.metering_secret,
'not-test',

View File

@ -51,7 +51,7 @@ class TestListResources(FunctionalTest):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}
)
)
msg = meter.meter_message_from_counter(counter1,
cfg.CONF.metering_secret,
'test',
@ -70,7 +70,7 @@ class TestListResources(FunctionalTest):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter2',
}
)
)
msg2 = meter.meter_message_from_counter(counter2,
cfg.CONF.metering_secret,
'test',
@ -93,7 +93,7 @@ class TestListResources(FunctionalTest):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}
)
)
msg = meter.meter_message_from_counter(counter1,
cfg.CONF.metering_secret,
'test_list_resources',
@ -112,7 +112,7 @@ class TestListResources(FunctionalTest):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter2',
}
)
)
msg2 = meter.meter_message_from_counter(counter2,
cfg.CONF.metering_secret,
'not-test',
@ -136,7 +136,7 @@ class TestListResources(FunctionalTest):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}
)
)
msg = meter.meter_message_from_counter(counter1,
cfg.CONF.metering_secret,
'test_list_resources',
@ -155,7 +155,7 @@ class TestListResources(FunctionalTest):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter2',
}
)
)
msg2 = meter.meter_message_from_counter(counter2,
cfg.CONF.metering_secret,
'not-test',
@ -179,7 +179,7 @@ class TestListResources(FunctionalTest):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}
)
)
msg = meter.meter_message_from_counter(counter1,
cfg.CONF.metering_secret,
'test_list_resources',
@ -198,7 +198,7 @@ class TestListResources(FunctionalTest):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter2',
}
)
)
msg2 = meter.meter_message_from_counter(counter2,
cfg.CONF.metering_secret,
'not-test',
@ -224,7 +224,7 @@ class TestListResources(FunctionalTest):
'ignored_dict': {'key': 'value'},
'ignored_list': ['not-returned'],
}
)
)
msg = meter.meter_message_from_counter(counter1,
cfg.CONF.metering_secret,
'test',

View File

@ -50,9 +50,8 @@ class TestListUsers(FunctionalTest):
'resource-id',
timestamp=datetime.datetime(2012, 7, 2, 10, 40),
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}
)
'tag': 'self.counter'}
)
msg = meter.meter_message_from_counter(counter1,
cfg.CONF.metering_secret,
'test_list_users',
@ -71,7 +70,7 @@ class TestListUsers(FunctionalTest):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter2',
}
)
)
msg2 = meter.meter_message_from_counter(counter2,
cfg.CONF.metering_secret,
'test_list_users',
@ -94,7 +93,7 @@ class TestListUsers(FunctionalTest):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}
)
)
msg = meter.meter_message_from_counter(counter1,
cfg.CONF.metering_secret,
'test_list_users',
@ -113,7 +112,7 @@ class TestListUsers(FunctionalTest):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter2',
}
)
)
msg2 = meter.meter_message_from_counter(counter2,
cfg.CONF.metering_secret,
'not-test',

View File

@ -51,7 +51,7 @@ class TestMaxProjectVolume(FunctionalTest):
resource_metadata={'display_name': 'test-volume',
'tag': 'self.counter',
}
)
)
self.counters.append(c)
msg = meter.meter_message_from_counter(c,
cfg.CONF.metering_secret,

View File

@ -50,7 +50,7 @@ class TestMaxResourceVolume(FunctionalTest):
resource_metadata={'display_name': 'test-volume',
'tag': 'self.counter',
}
)
)
self.counters.append(c)
msg = meter.meter_message_from_counter(c,
cfg.CONF.metering_secret,

View File

@ -50,7 +50,7 @@ class TestSumProjectVolume(FunctionalTest):
resource_metadata={'display_name': 'test-volume',
'tag': 'self.counter',
}
)
)
self.counters.append(c)
msg = meter.meter_message_from_counter(c,
cfg.CONF.metering_secret,

View File

@ -50,7 +50,7 @@ class TestSumResourceVolume(FunctionalTest):
resource_metadata={'display_name': 'test-volume',
'tag': 'self.counter',
}
)
)
self.counters.append(c)
msg = meter.meter_message_from_counter(c,
cfg.CONF.metering_secret,

View File

@ -80,7 +80,7 @@ TEST_NOTICE = {
u'priority': u'INFO',
u'publisher_id': u'compute.vagrant-precise',
u'timestamp': u'2012-05-08 20:23:48.028195',
}
}
class TestCollectorService(tests_base.TestCase):
@ -107,7 +107,7 @@ class TestCollectorService(tests_base.TestCase):
msg['message_signature'] = meter.compute_signature(
msg,
cfg.CONF.metering_secret,
)
)
self.srv.storage_conn = self.mox.CreateMock(base.Connection)
self.srv.storage_conn.record_metering_data(msg)
@ -146,7 +146,7 @@ class TestCollectorService(tests_base.TestCase):
msg['message_signature'] = meter.compute_signature(
msg,
cfg.CONF.metering_secret,
)
)
expected = {}
expected.update(msg)
@ -168,7 +168,7 @@ class TestCollectorService(tests_base.TestCase):
msg['message_signature'] = meter.compute_signature(
msg,
cfg.CONF.metering_secret,
)
)
expected = {}
expected.update(msg)

View File

@ -145,7 +145,7 @@ TEST_NOTICE = {
u'priority': u'INFO',
u'publisher_id': u'compute.vagrant-precise',
u'timestamp': u'2012-05-08 20:23:48.028195',
}
}
def test_meter_message_from_counter_signed():

View File

@ -50,25 +50,24 @@ class TestLocationMetadata(unittest.TestCase):
# Mimics an instance returned from nova api call
self.INSTANCE_PROPERTIES = {'name': 'display name',
'OS-EXT-SRV-ATTR:instance_name': 'instance-000001',
'reservation_id': 'reservation id',
'architecture': 'x86_64',
'availability_zone': 'zone1',
'kernel_id': 'kernel id',
'os_type': 'linux',
'ramdisk_id': 'ramdisk id',
'disk_gb': 10,
'ephemeral_gb': 7,
'memory_mb': 2048,
'root_gb': 3,
'vcpus': 1,
'image': {'id': 1,
'links': [{"rel": "bookmark",
'href': 2}],
},
'flavor': {'id': 1},
'hostId': '1234-5678',
}
'OS-EXT-SRV-ATTR:instance_name':
'instance-000001',
'reservation_id': 'reservation id',
'architecture': 'x86_64',
'availability_zone': 'zone1',
'kernel_id': 'kernel id',
'os_type': 'linux',
'ramdisk_id': 'ramdisk id',
'disk_gb': 10,
'ephemeral_gb': 7,
'memory_mb': 2048,
'root_gb': 3,
'vcpus': 1,
'image': {'id': 1,
'links': [{"rel": "bookmark",
'href': 2}]},
'flavor': {'id': 1},
'hostId': '1234-5678'}
self.instance = FauxInstance(**self.INSTANCE_PROPERTIES)
self.instance.host = 'made-up-hostname'
@ -101,5 +100,5 @@ class TestLocationMetadata(unittest.TestCase):
self.INSTANCE_PROPERTIES['image'] = ''
self.instance = FauxInstance(**self.INSTANCE_PROPERTIES)
md = instance.get_metadata_from_object(self.instance)
assert md['image_ref'] == None
assert md['image_ref_url'] == None
self.assertEqual(md['image_ref'], None)
self.assertEqual(md['image_ref_url'], None)

View File

@ -51,9 +51,8 @@ class TestRunTasks(base.TestCase):
project_id='test',
resource_id='test_run_tasks',
timestamp=datetime.datetime.utcnow().isoformat(),
resource_metadata={'name': 'Pollster',
},
)
resource_metadata={'name': 'Pollster'},
)
def get_counters(self, manager, instance):
self.counters.append((manager, instance))
@ -98,5 +97,4 @@ class TestRunTasks(base.TestCase):
assert list(actual[0]) == [self.Pollster.test_data,
cfg.CONF.metering_topic,
cfg.CONF.metering_secret,
cfg.CONF.counter_source,
]
cfg.CONF.counter_source]

View File

@ -71,7 +71,7 @@ INSTANCE_CREATE_END = {
u'priority': u'INFO',
u'publisher_id': u'compute.vagrant-precise',
u'timestamp': u'2012-05-08 20:23:48.028195',
}
}
INSTANCE_DELETE_START = {
u'_context_auth_token': u'3d8b13de1b7d499587dfc69b77dc09c2',
@ -115,7 +115,7 @@ INSTANCE_DELETE_START = {
u'priority': u'INFO',
u'publisher_id': u'compute.vagrant-precise',
u'timestamp': u'2012-05-08 20:24:14.824743',
}
}
INSTANCE_EXISTS = {
u'_context_auth_token': None,
@ -162,7 +162,7 @@ INSTANCE_EXISTS = {
u'priority': u'INFO',
u'publisher_id': u'compute.vagrant-precise',
u'timestamp': u'2012-05-08 16:03:44.122481',
}
}
INSTANCE_FINISH_RESIZE_END = {
u'_context_roles': [u'admin'],
@ -208,7 +208,7 @@ INSTANCE_FINISH_RESIZE_END = {
u'host': u'ip-10-147-132-184.ec2.internal',
u'display_name': u's1',
u'image_ref_url': u'http://10.147.132.184:9292/images/'
'a130b9d9-e00e-436e-9782-836ccef06e8a',
'a130b9d9-e00e-436e-9782-836ccef06e8a',
u'root_gb': 20,
u'tenant_id': u'cea4b25edb484e5392727181b7721d29',
u'created_at': u'2013-01-04T11:21:48.000000',
@ -216,17 +216,16 @@ INSTANCE_FINISH_RESIZE_END = {
u'instance_type': u'm1.small',
u'vcpus': 1,
u'image_meta': {u'kernel_id':
u'571478e0-d5e7-4c2e-95a5-2bc79443c28a',
u'571478e0-d5e7-4c2e-95a5-2bc79443c28a',
u'ramdisk_id':
u'5f23128e-5525-46d8-bc66-9c30cd87141a',
u'5f23128e-5525-46d8-bc66-9c30cd87141a',
u'base_image_ref':
u'a130b9d9-e00e-436e-9782-836ccef06e8a'
},
u'a130b9d9-e00e-436e-9782-836ccef06e8a'},
u'architecture': None,
u'os_type': None
},
u'priority': u'INFO'
}
}
INSTANCE_RESIZE_REVERT_END = {
u'_context_roles': [u'admin'],
@ -266,7 +265,7 @@ INSTANCE_RESIZE_REVERT_END = {
u'host': u'ip-10-147-132-184.ec2.internal',
u'display_name': u's1',
u'image_ref_url': u'http://10.147.132.184:9292/images/'
'a130b9d9-e00e-436e-9782-836ccef06e8a',
'a130b9d9-e00e-436e-9782-836ccef06e8a',
u'root_gb': 0,
u'tenant_id': u'cea4b25edb484e5392727181b7721d29',
u'created_at': u'2013-01-04T11:21:48.000000',
@ -274,23 +273,23 @@ INSTANCE_RESIZE_REVERT_END = {
u'instance_type': u'm1.tiny',
u'vcpus': 1,
u'image_meta': {u'kernel_id':
u'571478e0-d5e7-4c2e-95a5-2bc79443c28a',
u'571478e0-d5e7-4c2e-95a5-2bc79443c28a',
u'ramdisk_id':
u'5f23128e-5525-46d8-bc66-9c30cd87141a',
u'5f23128e-5525-46d8-bc66-9c30cd87141a',
u'base_image_ref':
u'a130b9d9-e00e-436e-9782-836ccef06e8a'
},
u'a130b9d9-e00e-436e-9782-836ccef06e8a'},
u'architecture': None,
u'os_type': None
},
u'priority': u'INFO'
}
}
class TestNotifications(unittest.TestCase):
def test_process_notification(self):
info = notifications.Instance.process_notification(
INSTANCE_CREATE_END)[0]
INSTANCE_CREATE_END
)[0]
for name, actual, expected in [
('counter_name', info.name, 'instance'),
@ -306,7 +305,7 @@ class TestNotifications(unittest.TestCase):
INSTANCE_CREATE_END['payload']['instance_type_id']),
('host', info.resource_metadata['host'],
INSTANCE_CREATE_END['publisher_id']),
]:
]:
yield compare, name, actual, expected
@staticmethod

View File

@ -67,7 +67,7 @@ class TestNovaNotifier(base.TestCase):
timestamp=datetime.datetime.utcnow().isoformat(),
resource_metadata={'name': 'Pollster',
},
)
)
def get_counters(self, manager, instance):
self.counters.append((manager, instance))
@ -111,7 +111,7 @@ class TestNovaNotifier(base.TestCase):
"vcpus": 1,
"host": "fakehost",
"availability_zone":
"1e3ce043029547f1a61c1996d1a531a4",
"1e3ce043029547f1a61c1996d1a531a4",
"created_at": '2012-05-08 20:23:41',
"os_type": "linux",
"kernel_id": "kernelid",
@ -140,7 +140,7 @@ class TestNovaNotifier(base.TestCase):
None,
self.Pollster(),
),
])
])
nova_notifier.initialize_manager(agent_manager)
def tearDown(self):
@ -157,9 +157,9 @@ class TestNovaNotifier(base.TestCase):
# call this method directly, but not safe to mock it
# because mock.patch() fails to find the original.
self.stubs.Set(db, 'instance_get_by_uuid',
self.fake_db_instance_get)
self.fake_db_instance_get)
self.compute.terminate_instance(self.context,
instance=self.instance)
instance=self.instance)
else:
# Under Grizzly, Nova has moved to no-db access on the
# compute node. The compute manager uses RPC to talk to

View File

@ -69,11 +69,11 @@ class TestDiskIOPollster(TestPollsterBase):
def test_get_counters(self):
disks = [
(virt_inspector.Disk(device='vda'),
virt_inspector.DiskStats(read_bytes=1L, read_requests=2L,
write_bytes=3L, write_requests=4L,
errors=-1L))
]
(virt_inspector.Disk(device='vda'),
virt_inspector.DiskStats(read_bytes=1L, read_requests=2L,
write_bytes=3L, write_requests=4L,
errors=-1L))
]
self.inspector.inspect_disks(self.instance.name).AndReturn(disks)
self.mox.ReplayAll()
@ -100,22 +100,24 @@ class TestNetPollster(TestPollsterBase):
super(TestNetPollster, self).setUp()
def test_get_counters(self):
vnic0 = virt_inspector.Interface(name='vnet0',
fref='fa163e71ec6e',
mac='fa:16:3e:71:ec:6d',
parameters=dict(ip='10.0.0.2',
projmask='255.255.255.0',
projnet='proj1',
dhcp_server='10.0.0.1'))
vnic0 = virt_inspector.Interface(
name='vnet0',
fref='fa163e71ec6e',
mac='fa:16:3e:71:ec:6d',
parameters=dict(ip='10.0.0.2',
projmask='255.255.255.0',
projnet='proj1',
dhcp_server='10.0.0.1'))
stats0 = virt_inspector.InterfaceStats(rx_bytes=1L, rx_packets=2L,
tx_bytes=3L, tx_packets=4L)
vnic1 = virt_inspector.Interface(name='vnet1',
fref='fa163e71ec6f',
mac='fa:16:3e:71:ec:6e',
parameters=dict(ip='192.168.0.3',
projmask='255.255.255.0',
projnet='proj2',
dhcp_server='10.0.0.2'))
vnic1 = virt_inspector.Interface(
name='vnet1',
fref='fa163e71ec6f',
mac='fa:16:3e:71:ec:6e',
parameters=dict(ip='192.168.0.3',
projmask='255.255.255.0',
projnet='proj2',
dhcp_server='10.0.0.2'))
stats1 = virt_inspector.InterfaceStats(rx_bytes=5L, rx_packets=6L,
tx_bytes=7L, tx_packets=8L)
vnics = [(vnic0, stats0), (vnic1, stats1)]

View File

@ -37,7 +37,7 @@ class TestLibvirtInspection(test_base.TestCase):
self.inspector.connection.getCapabilities()
self.domain = self.mox.CreateMockAnything()
self.inspector.connection.lookupByName(self.instance_name).AndReturn(
self.domain)
self.domain)
def test_inspect_cpus(self):
self.domain.info().AndReturn((0L, 0L, 0L, 2L, 999999L))

View File

@ -110,4 +110,4 @@ class TestImagePollster(base.TestCase):
for image in IMAGE_LIST:
self.assert_(
any(map(lambda counter: counter.volume == image.size,
counters)))
counters)))

View File

@ -30,8 +30,10 @@ class FakeApp(object):
self.body = body
def __call__(self, env, start_response):
start_response('200 OK', [('Content-Type', 'text/plain'),
('Content-Length', str(sum(map(len, self.body))))])
start_response('200 OK', [
('Content-Type', 'text/plain'),
('Content-Length', str(sum(map(len, self.body))))
])
while env['wsgi.input'].read(5):
pass
return self.body

View File

@ -82,7 +82,7 @@ class MongoDBEngineTestBase(unittest.TestCase):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}
)
)
self.msg = meter.meter_message_from_counter(self.counter,
'not-so-secret',
'test-1')
@ -100,7 +100,7 @@ class MongoDBEngineTestBase(unittest.TestCase):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter2',
}
)
)
self.msg2 = meter.meter_message_from_counter(self.counter2,
'not-so-secret',
'test-2')
@ -118,7 +118,7 @@ class MongoDBEngineTestBase(unittest.TestCase):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter3',
}
)
)
self.msg3 = meter.meter_message_from_counter(self.counter3,
'not-so-secret',
'test-3')
@ -137,7 +137,7 @@ class MongoDBEngineTestBase(unittest.TestCase):
resource_metadata={'display_name': 'test-server',
'tag': 'counter-%s' % i,
}
)
)
msg = meter.meter_message_from_counter(c, 'not-so-secret', 'test')
self.conn.record_metering_data(msg)
@ -264,8 +264,7 @@ class ResourceTest(MongoDBEngineTestBase):
start_ts = datetime.datetime(2012, 7, 2, 10, 42)
end_ts = datetime.datetime(2012, 7, 2, 10, 43)
resources = list(self.conn.get_resources(start_timestamp=start_ts,
end_timestamp=end_ts)
)
end_timestamp=end_ts))
resource_ids = [r['resource_id'] for r in resources]
expected = set(['resource-id-2'])
assert set(resource_ids) == expected
@ -334,7 +333,7 @@ class MeterTest(MongoDBEngineTestBase):
f = storage.EventFilter(
user='user-id',
start=datetime.datetime(2012, 7, 2, 10, 41),
)
)
results = list(self.conn.get_raw_events(f))
length = len(results)
assert length == 1
@ -344,7 +343,7 @@ class MeterTest(MongoDBEngineTestBase):
f = storage.EventFilter(
user='user-id',
end=datetime.datetime(2012, 7, 2, 10, 41),
)
)
results = list(self.conn.get_raw_events(f))
length = len(results)
assert length == 1
@ -354,7 +353,7 @@ class MeterTest(MongoDBEngineTestBase):
f = storage.EventFilter(
start=datetime.datetime(2012, 7, 2, 10, 42),
end=datetime.datetime(2012, 7, 2, 10, 43),
)
)
results = list(self.conn.get_raw_events(f))
length = len(results)
assert length == 1
@ -364,7 +363,7 @@ class MeterTest(MongoDBEngineTestBase):
f = storage.EventFilter(
user='user-id',
meter='no-such-meter',
)
)
results = list(self.conn.get_raw_events(f))
assert not results
@ -372,7 +371,7 @@ class MeterTest(MongoDBEngineTestBase):
f = storage.EventFilter(
user='user-id',
meter='instance',
)
)
results = list(self.conn.get_raw_events(f))
assert results
@ -393,7 +392,7 @@ class SumTest(MongoDBEngineTestBase):
f = storage.EventFilter(
user='user-id',
meter='instance',
)
)
results = list(self.conn.get_volume_sum(f))
assert results
counts = dict((r['resource_id'], r['value'])
@ -407,7 +406,7 @@ class SumTest(MongoDBEngineTestBase):
f = storage.EventFilter(
project='project-id',
meter='instance',
)
)
results = list(self.conn.get_volume_sum(f))
assert results
counts = dict((r['resource_id'], r['value'])
@ -422,7 +421,7 @@ class SumTest(MongoDBEngineTestBase):
user='user-id',
meter='instance',
resource='resource-id',
)
)
results = list(self.conn.get_volume_sum(f))
assert results
counts = dict((r['resource_id'], r['value'])
@ -457,7 +456,7 @@ class TestGetEventInterval(MongoDBEngineTestBase):
meter='instance',
start=self.start,
end=self.end,
)
)
def _make_events(self, *timestamps):
for t in timestamps:
@ -472,7 +471,7 @@ class TestGetEventInterval(MongoDBEngineTestBase):
timestamp=t,
resource_metadata={'display_name': 'test-server',
}
)
)
msg = meter.meter_message_from_counter(counter=c,
secret='not-so-secret',
source='test',

View File

@ -106,7 +106,7 @@ class SQLAlchemyEngineTestBase(SQLAlchemyEngineSubBase):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter',
}
)
)
self.msg1 = meter.meter_message_from_counter(self.counter,
cfg.CONF.metering_secret,
'test-1',
@ -125,7 +125,7 @@ class SQLAlchemyEngineTestBase(SQLAlchemyEngineSubBase):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter2',
}
)
)
self.msg2 = meter.meter_message_from_counter(self.counter2,
cfg.CONF.metering_secret,
'test-2',
@ -144,7 +144,7 @@ class SQLAlchemyEngineTestBase(SQLAlchemyEngineSubBase):
resource_metadata={'display_name': 'test-server',
'tag': 'self.counter3',
}
)
)
self.msg3 = meter.meter_message_from_counter(self.counter3,
cfg.CONF.metering_secret,
'test-3',
@ -162,9 +162,8 @@ class SQLAlchemyEngineTestBase(SQLAlchemyEngineSubBase):
resource_id='resource-id-%s' % i,
timestamp=datetime.datetime(2012, 7, 2, 10, 40 + i),
resource_metadata={'display_name': 'test-server',
'tag': 'counter-%s' % i,
}
)
'tag': 'counter-%s' % i},
)
msg = meter.meter_message_from_counter(c, cfg.CONF.metering_secret,
'test')
self.conn.record_metering_data(msg)
@ -230,8 +229,8 @@ class ResourceTest(SQLAlchemyEngineTestBase):
def test_new_resource_meter(self):
resource = self.session.query(Resource).filter_by(id='resource-id').\
filter(Meter.counter_name == 'instance').\
filter(Meter.counter_type == 'cumulative').first()
filter(Meter.counter_name == 'instance').\
filter(Meter.counter_type == 'cumulative').first()
assert len(set(resource.meters)) == 1
foo = map(lambda x: [x.counter_name, x.counter_type], resource.meters)
assert ['instance', 'cumulative'] in foo
@ -278,8 +277,7 @@ class ResourceTest(SQLAlchemyEngineTestBase):
start_ts = datetime.datetime(2012, 7, 2, 10, 42)
end_ts = datetime.datetime(2012, 7, 2, 10, 43)
resources = list(self.conn.get_resources(start_timestamp=start_ts,
end_timestamp=end_ts)
)
end_timestamp=end_ts))
resource_ids = [r['resource_id'] for r in resources]
assert set(resource_ids) == set(['resource-id-2'])
@ -396,7 +394,7 @@ class MeterTest(SQLAlchemyEngineTestBase):
f = storage.EventFilter(
user='user-id',
start=datetime.datetime(2012, 7, 2, 10, 41),
)
)
results = list(self.conn.get_raw_events(f))
assert len(results) == 1
assert results[0]['timestamp'] == datetime.datetime(2012, 7, 2, 10, 41)
@ -405,7 +403,7 @@ class MeterTest(SQLAlchemyEngineTestBase):
f = storage.EventFilter(
user='user-id',
end=datetime.datetime(2012, 7, 2, 10, 41),
)
)
results = list(self.conn.get_raw_events(f))
length = len(results)
assert length == 1
@ -415,7 +413,7 @@ class MeterTest(SQLAlchemyEngineTestBase):
f = storage.EventFilter(
start=datetime.datetime(2012, 7, 2, 10, 42),
end=datetime.datetime(2012, 7, 2, 10, 43),
)
)
results = list(self.conn.get_raw_events(f))
length = len(results)
assert length == 1
@ -463,7 +461,7 @@ class TestGetEventInterval(SQLAlchemyEngineTestBase):
meter='instance',
start=self.start,
end=self.end,
)
)
def _make_events(self, *timestamps):
for t in timestamps:
@ -478,7 +476,7 @@ class TestGetEventInterval(SQLAlchemyEngineTestBase):
timestamp=t,
resource_metadata={'display_name': 'test-server',
}
)
)
msg = meter.meter_message_from_counter(c, cfg.CONF.metering_secret,
'test')
self.conn.record_metering_data(msg)
@ -542,7 +540,7 @@ class SumTest(SQLAlchemyEngineTestBase):
f = storage.EventFilter(
user='user-id',
meter='instance',
)
)
results = list(self.conn.get_volume_sum(f))
counts = dict((r['resource_id'], r['value'])
for r in results)
@ -555,7 +553,7 @@ class SumTest(SQLAlchemyEngineTestBase):
f = storage.EventFilter(
project='project-id',
meter='instance',
)
)
results = list(self.conn.get_volume_sum(f))
assert results
counts = dict((r['resource_id'], r['value'])
@ -570,7 +568,7 @@ class SumTest(SQLAlchemyEngineTestBase):
user='user-id',
meter='instance',
resource='resource-id',
)
)
results = list(self.conn.get_volume_sum(f))
assert results
counts = dict((r['resource_id'], r['value'])
@ -598,7 +596,7 @@ class MaxProjectTest(SQLAlchemyEngineSubBase):
resource_metadata={'display_name': 'test-volume',
'tag': 'self.counter',
}
)
)
self.counters.append(c)
msg = meter.meter_message_from_counter(c,
cfg.CONF.metering_secret,
@ -677,7 +675,7 @@ class MaxResourceTest(SQLAlchemyEngineSubBase):
resource_metadata={'display_name': 'test-volume',
'tag': 'self.counter',
}
)
)
self.counters.append(c)
msg = meter.meter_message_from_counter(c,
cfg.CONF.metering_secret,

View File

@ -38,9 +38,8 @@ class TestPublish(base.TestCase):
project_id='test',
resource_id='test_run_tasks',
timestamp=datetime.datetime.utcnow().isoformat(),
resource_metadata={'name': 'TestPublish',
},
)
resource_metadata={'name': 'TestPublish'},
)
def faux_notify(self, context, topic, msg):
self.notifications.append((topic, msg))

View File

@ -1,6 +1,5 @@
nose
coverage
pep8>=1.0
mock
mox
Babel>=0.9.6

View File

@ -1,7 +1,6 @@
http://tarballs.openstack.org/nova/nova-stable-folsom.tar.gz
nose
coverage
pep8>=1.0
mock
mox
# NOTE(dhellmann): Ming is necessary to provide the Mongo-in-memory

View File

@ -20,7 +20,7 @@ setenv=CEILOMETER_TEST_LIVE=1
commands = {toxinidir}/run_tests.sh --no-path-adjustment --with-coverage --cover-erase --cover-package=ceilometer --cover-inclusive []
[testenv:pep8]
deps = pep8==1.1
deps = pep8==1.3.3
commands = pep8 --repeat --show-source ceilometer setup.py bin/ceilometer-agent-central bin/ceilometer-agent-compute bin/ceilometer-collector bin/ceilometer-api tests
[testenv:venv]