Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
all = list(self.conn.get_alarms())
self.assertEqual(len(all), 1)
def test_delete(self):
self.add_some_alarms()
victim = list(self.conn.get_alarms(name='orange-alert'))[0]
self.conn.delete_alarm(victim.alarm_id)
survivors = list(self.conn.get_alarms())
self.assertEqual(len(survivors), 2)
for s in survivors:
self.assertNotEquals(victim.name, s.name)
class AlarmTestPagination(AlarmTestBase,
tests_db.MixinTestsWithBackendScenarios):
def test_get_alarm_all_limit(self):
self.add_some_alarms()
pagination = Pagination(limit=2)
alarms = list(self.conn.get_alarms(pagination=pagination))
self.assertEqual(len(alarms), 2)
pagination = Pagination(limit=1)
alarms = list(self.conn.get_alarms(pagination=pagination))
self.assertEqual(len(alarms), 1)
def test_get_alarm_all_marker(self):
self.add_some_alarms()
pagination = Pagination(marker_value='orange-alert')
alarms = list(self.conn.get_alarms(pagination=pagination))
'counter-3', 'counter-4', 'counter-5', 'counter-6',
'counter-7', 'counter-8']
for resource in resources:
self.assertIn(resource.metadata['tag'], expected_tags)
def test_get_resources_most_recent_metadata_single(self):
resource = list(
self.conn.get_resources(resource='resource-id-alternate')
)[0]
expected_tag = 'self.counter3'
self.assertEqual(resource.metadata['tag'], expected_tag)
class ResourceTestPagination(DBTestBase,
tests_db.MixinTestsWithBackendScenarios):
def test_get_resource_all_limit(self):
pagination = Pagination(limit=8)
results = list(self.conn.get_resources(pagination=pagination))
self.assertEqual(len(results), 8)
pagination = Pagination(limit=5)
results = list(self.conn.get_resources(pagination=pagination))
self.assertEqual(len(results), 5)
def test_get_resources_all_marker(self):
pagination = Pagination(primary_sort_dir='asc', sort_keys=['user_id'],
sort_dirs=['asc'],
marker_value='resource-id-4')
results = list(self.conn.get_resources(pagination=pagination))
self.assertEqual(len(results), 5)
'metadata_flavor': 'm1.large', 'metadata_event': 'event-2',
'source': 'source-1'},
{'volume': 4, 'user': 'user-2', 'project': 'project-2',
'resource': 'resource-2', 'timestamp': (2013, 8, 1, 17, 28),
'metadata_flavor': 'm1.large', 'metadata_event': 'event-2',
'source': 'source-1'},
{'volume': 4, 'user': 'user-3', 'project': 'project-1',
'resource': 'resource-3', 'timestamp': (2013, 8, 1, 11, 22),
'metadata_flavor': 'm1.tiny', 'metadata_event': 'event-2',
'source': 'source-3'},
)
for test_sample in test_sample_data:
c = sample.Sample(
'instance',
sample.TYPE_CUMULATIVE,
unit='s',
volume=test_sample['volume'],
user_id=test_sample['user'],
project_id=test_sample['project'],
resource_id=test_sample['resource'],
timestamp=datetime.datetime(*test_sample['timestamp']),
resource_metadata={'flavor': test_sample['metadata_flavor'],
'event': test_sample['metadata_event'], },
source=test_sample['source'],
)
msg = rpc.meter_message_from_counter(
c,
self.CONF.publisher_rpc.metering_secret,
)
self.conn.record_metering_data(msg)
def create_and_store_sample(self, timestamp=datetime.datetime.utcnow(),
metadata={
'display_name': 'test-server',
'tag': 'self.counter'
},
name='instance',
sample_type=sample.TYPE_CUMULATIVE, unit='',
volume=1, user_id='user-id',
project_id='project-id',
resource_id='resource-id', source=None):
s = sample.Sample(
name, sample_type, unit=unit, volume=volume, user_id=user_id,
project_id=project_id, resource_id=resource_id,
timestamp=timestamp,
resource_metadata=metadata, source=source
)
msg = rpc.meter_message_from_counter(
s, self.CONF.publisher_rpc.metering_secret
)
self.conn.record_metering_data(msg)
return msg
# because the notifier module messes with the import path to force
# nova's version of oslo to be used instead of ceilometer's.
from ceilometer.compute import nova_notifier
from ceilometer import sample
from ceilometer.compute.pollsters import util
LOG = logging.getLogger(__name__)
nova_CONF = config.cfg.CONF
class TestNovaNotifier(base.BaseTestCase):
class Pollster(object):
instances = []
test_data_1 = sample.Sample(
name='test1',
type=sample.TYPE_CUMULATIVE,
unit='units-go-here',
volume=1,
user_id='test',
project_id='test',
resource_id='test_run_tasks',
timestamp=datetime.datetime.utcnow().isoformat(),
resource_metadata={'name': 'Pollster',
},
)
def get_samples(self, manager, cache, instance):
self.instances.append((manager, instance))
test_data_2 = util.make_sample_from_instance(
instance,
def setUp(self):
super(TestListResourcesBase, self).setUp()
for cnt in [
sample.Sample(
'instance',
'cumulative',
'',
1,
'user-id',
'project-id',
'resource-id',
timestamp=datetime.datetime(2012, 7, 2, 10, 40),
resource_metadata={'display_name': 'test-server',
'tag': 'self.sample'},
source='test_list_resources',
),
sample.Sample(
'instance',
'cumulative',
'',
resource_id='test_run_tasks',
timestamp=datetime.datetime.utcnow().isoformat(),
resource_metadata={'name': 'TestPublish'},
),
sample.Sample(
name='test',
type=sample.TYPE_CUMULATIVE,
unit='',
volume=1,
user_id='test',
project_id='test',
resource_id='test_run_tasks',
timestamp=datetime.datetime.utcnow().isoformat(),
resource_metadata={'name': 'TestPublish'},
),
sample.Sample(
name='test2',
type=sample.TYPE_CUMULATIVE,
unit='',
volume=1,
user_id='test',
project_id='test',
resource_id='test_run_tasks',
timestamp=datetime.datetime.utcnow().isoformat(),
resource_metadata={'name': 'TestPublish'},
),
sample.Sample(
name='test2',
type=sample.TYPE_CUMULATIVE,
unit='',
volume=1,
user_id='test',
self.pipeline_cfg[0]['transformers'] = [
{
'name': 'rate_of_change',
'parameters': {
'source': {},
'target': {'name': 'cpu_util',
'unit': '%',
'type': sample.TYPE_GAUGE,
'scale': s}
}
},
]
self.pipeline_cfg[0]['counters'] = ['cpu']
now = timeutils.utcnow()
counters = [
sample.Sample(
name='cpu',
type=sample.TYPE_CUMULATIVE,
volume=120000000000,
unit='ns',
user_id='test_user',
project_id='test_proj',
resource_id='test_resource',
timestamp=now.isoformat(),
resource_metadata={'cpu_number': 4}
),
]
pipeline_manager = pipeline.PipelineManager(self.pipeline_cfg,
self.transformer_manager)
pipe = pipeline_manager.pipelines[0]
def setUp(self):
super(TestUDPCollectorService, self).setUp()
self.mox = self.useFixture(moxstubout.MoxStubout()).mox
self.srv = service.UDPCollectorService()
self.counter = sample.Sample(
name='foobar',
type='bad',
unit='F',
volume=1,
user_id='jd',
project_id='ceilometer',
resource_id='cat',
timestamp='NOW!',
resource_metadata={},
).as_dict()
resource_metadata={'name': 'TestPublish'},
source=COUNTER_SOURCE,
),
sample.Sample(
name='test2',
type=sample.TYPE_CUMULATIVE,
unit='',
volume=1,
user_id='test',
project_id='test',
resource_id='test_run_tasks',
timestamp=datetime.datetime.utcnow().isoformat(),
resource_metadata={'name': 'TestPublish'},
source=COUNTER_SOURCE,
),
sample.Sample(
name='test3',
type=sample.TYPE_CUMULATIVE,
unit='',
volume=1,
user_id='test',
project_id='test',
resource_id='test_run_tasks',
timestamp=datetime.datetime.utcnow().isoformat(),
resource_metadata={'name': 'TestPublish'},
source=COUNTER_SOURCE,
),
]
def _make_fake_socket(self, published):
def _fake_socket_socket(family, type):
def record_data(msg, dest):