Ejemplo n.º 1
0
    def setUp(self):
        super(BasePipelineTestCase, self).setUp()

        self.test_counter = sample.Sample(
            name='a',
            type=sample.TYPE_GAUGE,
            volume=1,
            unit='B',
            user_id="test_user",
            project_id="test_proj",
            resource_id="test_resource",
            timestamp=timeutils.utcnow().isoformat(),
            resource_metadata={})

        self.useFixture(
            mockpatch.PatchObject(transformer.TransformerExtensionManager,
                                  "__init__",
                                  side_effect=self.fake_tem_init))

        self.useFixture(
            mockpatch.PatchObject(transformer.TransformerExtensionManager,
                                  "get_ext",
                                  side_effect=self.fake_tem_get_ext))

        self.useFixture(
            mockpatch.PatchObject(publisher,
                                  'get_publisher',
                                  side_effect=self.get_publisher))

        self.transformer_manager = transformer.TransformerExtensionManager()

        self._setup_pipeline_cfg()
Ejemplo n.º 2
0
 def setUp(self):
     super(TestNovaClient, self).setUp()
     self.nv = nova_client.Client()
     self.useFixture(mockpatch.PatchObject(
         self.nv.nova_client.flavors, 'get',
         side_effect=self.fake_flavors_get))
     self.useFixture(mockpatch.PatchObject(
         self.nv.nova_client.images, 'get',
         side_effect=self.fake_images_get))
Ejemplo n.º 3
0
 def setUp(self):
     super(TestSNMPInspector, self).setUp()
     self.inspector = snmp.SNMPInspector()
     self.host = network_utils.urlsplit("snmp://localhost")
     self.useFixture(
         mockpatch.PatchObject(self.inspector._cmdGen,
                               'getCmd',
                               new=faux_getCmd))
     self.useFixture(
         mockpatch.PatchObject(self.inspector._cmdGen,
                               'nextCmd',
                               new=faux_nextCmd))
Ejemplo n.º 4
0
 def setUp(self):
     super(TestImagePollster, self).setUp()
     self.context = context.get_admin_context()
     self.manager = TestManager()
     self.useFixture(mockpatch.PatchObject(
         glance._Base, 'get_glance_client',
         side_effect=self.fake_get_glance_client))
Ejemplo n.º 5
0
    def test_metering(self):
        with mockpatch.PatchObject(self.factory,
                                   '_iter_accounts',
                                   side_effect=self.fake_iter_accounts):
            samples = list(self.pollster.get_samples(self.manager, {}))

        self.assertEqual(2, len(samples))
Ejemplo n.º 6
0
    def test_endpoint_not_exist(self):
        with mockpatch.PatchObject(kwapi._Base, 'get_kwapi_client',
                                   side_effect=self.fake_get_kwapi_client):
            pollster = kwapi.EnergyPollster()
            samples = list(pollster.get_samples(self.manager, {}))

        self.assertEqual(0, len(samples))
Ejemplo n.º 7
0
 def setUp(self):
     super(TestRPCAlarmPartitionCoordination, self).setUp()
     self.notified = []
     self.useFixture(mockpatch.PatchObject(
         rpc, 'fanout_cast',
         side_effect=self.fake_fanout_cast))
     self.ordination = rpc_alarm.RPCAlarmPartitionCoordination()
     self.alarms = [mock.MagicMock(), mock.MagicMock()]
Ejemplo n.º 8
0
    def test_endpoint_notfound(self):
        with mockpatch.PatchObject(
                self.manager.keystone.service_catalog,
                'url_for',
                side_effect=self.fake_ks_service_catalog_url_for):
            samples = list(self.pollster.get_samples(self.manager, {}))

        self.assertEqual(0, len(samples))
Ejemplo n.º 9
0
    def test_get_meter_names(self):
        with mockpatch.PatchObject(self.factory,
                                   '_iter_accounts',
                                   side_effect=self.fake_iter_accounts):
            samples = list(self.pollster.get_samples(self.manager, {}))

        self.assertEqual(set([samples[0].name]),
                         set([s.name for s in samples]))
Ejemplo n.º 10
0
 def setUp(self):
     super(TestSwiftMiddleware, self).setUp()
     self.pipeline_manager = self._faux_pipeline_manager()
     self.useFixture(
         mockpatch.PatchObject(pipeline,
                               'setup_pipeline',
                               side_effect=self._fake_setup_pipeline))
     self.CONF = self.useFixture(config.Config()).conf
     self.setup_messaging(self.CONF)
Ejemplo n.º 11
0
 def setUp(self):
     super(TestRPCAlarmNotifier, self).setUp()
     self.notified = []
     self.useFixture(
         mockpatch.PatchObject(rpc, 'cast', side_effect=self.fake_cast))
     self.notifier = rpc_alarm.RPCAlarmNotifier()
     self.alarms = [
         alarms.Alarm(None,
                      info={
                          'name': 'instance_running_hot',
                          'meter_name': 'cpu_util',
                          'comparison_operator': 'gt',
                          'threshold': 80.0,
                          'evaluation_periods': 5,
                          'statistic': 'avg',
                          'state': 'ok',
                          'ok_actions': ['http://host:8080/path'],
                          'user_id': 'foobar',
                          'project_id': 'snafu',
                          'period': 60,
                          'alarm_id': str(uuid.uuid4()),
                          'matching_metadata': {
                              'resource_id': 'my_instance'
                          }
                      }),
         alarms.Alarm(None,
                      info={
                          'name':
                          'group_running_idle',
                          'meter_name':
                          'cpu_util',
                          'comparison_operator':
                          'le',
                          'threshold':
                          10.0,
                          'statistic':
                          'max',
                          'evaluation_periods':
                          4,
                          'state':
                          'insufficient data',
                          'insufficient_data_actions':
                          ['http://other_host/path'],
                          'user_id':
                          'foobar',
                          'project_id':
                          'snafu',
                          'period':
                          300,
                          'alarm_id':
                          str(uuid.uuid4()),
                          'matching_metadata': {
                              'metadata.user_metadata.AS': 'my_group'
                          }
                      }),
     ]
Ejemplo n.º 12
0
    def test_iter_accounts_tenants_cached(self):
        # Verify that if there are tenants pre-cached then the account
        # info loop iterates over those instead of asking for the list
        # again.
        ksclient = mock.Mock()
        ksclient.tenants.list.side_effect = AssertionError(
            'should not be called', )

        api_method = '%s_account' % self.pollster.METHOD
        with mockpatch.PatchObject(swift_client, api_method, new=ksclient):
            with mockpatch.PatchObject(self.factory, '_neaten_url'):
                Tenant = collections.namedtuple('Tenant', 'id')
                cache = {
                    self.pollster.CACHE_KEY_TENANT:
                    [Tenant(self.ACCOUNTS[0][0])],
                }
                data = list(self.pollster._iter_accounts(mock.Mock(), cache))
        self.assertTrue(self.pollster.CACHE_KEY_METHOD in cache)
        self.assertEqual(self.ACCOUNTS[0][0], data[0][0])
Ejemplo n.º 13
0
    def test_iter_accounts_no_cache(self):
        cache = {}
        with mockpatch.PatchObject(self.factory,
                                   '_get_account_info',
                                   return_value=[]):
            data = list(self.pollster._iter_accounts(mock.Mock(), cache))

        self.assertTrue(self.pollster.CACHE_KEY_TENANT in cache)
        self.assertTrue(self.pollster.CACHE_KEY_METHOD in cache)
        self.assertEqual([], data)
Ejemplo n.º 14
0
    def setUp(self):
        super(TestPipeline, self).setUp()

        self.test_counter = sample.Sample(
            name='a',
            type=sample.TYPE_GAUGE,
            volume=1,
            unit='B',
            user_id="test_user",
            project_id="test_proj",
            resource_id="test_resource",
            timestamp=timeutils.utcnow().isoformat(),
            resource_metadata={})

        self.useFixture(
            mockpatch.PatchObject(transformer.TransformerExtensionManager,
                                  "__init__",
                                  side_effect=self.fake_tem_init))

        self.useFixture(
            mockpatch.PatchObject(transformer.TransformerExtensionManager,
                                  "get_ext",
                                  side_effect=self.fake_tem_get_ext))

        self.useFixture(
            mockpatch.PatchObject(publisher,
                                  'get_publisher',
                                  side_effect=self.get_publisher))

        self.transformer_manager = transformer.TransformerExtensionManager()

        self.pipeline_cfg = [
            {
                'name': "test_pipeline",
                'interval': 5,
                'counters': ['a'],
                'transformers': [{
                    'name': "update",
                    'parameters': {}
                }],
                'publishers': ["test://"],
            },
        ]
Ejemplo n.º 15
0
    def test_get_cmd_error(self):
        self.useFixture(
            mockpatch.PatchObject(self.inspector,
                                  '_memory_total_oid',
                                  new='failure'))

        def get_list(func, *args, **kwargs):
            return list(func(*args, **kwargs))

        self.assertRaises(snmp.SNMPException, get_list,
                          self.inspector.inspect_memory, self.host)
Ejemplo n.º 16
0
    def setUp(self):
        super(TestRPCAlarmPartitionCoordination, self).setUp()
        messaging.setup('fake://')
        self.addCleanup(messaging.cleanup)

        self.notified = []
        self.ordination = rpc_alarm.RPCAlarmPartitionCoordination()
        self.useFixture(
            mockpatch.PatchObject(self.ordination.client,
                                  'prepare',
                                  side_effect=self.fake_prepare))
        self.alarms = [mock.MagicMock(), mock.MagicMock()]
Ejemplo n.º 17
0
 def patch_publishers(self):
     cast_ctxt = mock.Mock()
     cast_ctxt.cast.side_effect = self.fake_cast
     found = False
     pipeline_hook = self.app.app.application.app.hooks[2]
     for pipeline in pipeline_hook.pipeline_manager.pipelines:
         for publisher in pipeline.publishers:
             if hasattr(publisher, 'rpc_client'):
                 self.useFixture(
                     mockpatch.PatchObject(publisher.rpc_client,
                                           'prepare',
                                           return_value=cast_ctxt))
                 found = True
     if not found:
         raise Exception('fail to patch the rpc publisher')
Ejemplo n.º 18
0
    def setUp(self):
        super(TestRunTasks, self).setUp()

        # Set up a fake instance value to be returned by
        # instance_get_all_by_host() so when the manager gets the list
        # of instances to poll we can control the results.
        self.instance = self._fake_instance('faux', 'active')
        stillborn_instance = self._fake_instance('stillborn', 'error')

        def instance_get_all_by_host(*args):
            return [self.instance, stillborn_instance]

        self.useFixture(mockpatch.PatchObject(
            nova_client.Client,
            'instance_get_all_by_host',
            side_effect=lambda *x: [self.instance, stillborn_instance]))
Ejemplo n.º 19
0
    def setUp(self):
        super(TestCollector, self).setUp()
        self.CONF = self.useFixture(config.Config()).conf
        self.CONF.import_opt("connection",
                             "ceilometer.openstack.common.db.options",
                             group="database")
        self.CONF.set_override("connection", "log://", group='database')
        self.CONF.set_override('metering_secret',
                               'not-so-secret',
                               group='publisher')
        self._setup_messaging()

        self.counter = sample.Sample(
            name='foobar',
            type='bad',
            unit='F',
            volume=1,
            user_id='jd',
            project_id='ceilometer',
            resource_id='cat',
            timestamp=timeutils.utcnow().isoformat(),
            resource_metadata={},
        ).as_dict()

        self.utf8_msg = utils.meter_message_from_counter(
            sample.Sample(
                name=u'test',
                type=sample.TYPE_CUMULATIVE,
                unit=u'',
                volume=1,
                user_id=u'test',
                project_id=u'test',
                resource_id=u'test_run_tasks',
                timestamp=timeutils.utcnow().isoformat(),
                resource_metadata={u'name': [([u'TestPublish'])]},
                source=u'testsource',
            ), 'not-so-secret')

        self.srv = collector.CollectorService()

        self.useFixture(
            mockpatch.PatchObject(
                self.srv.tg,
                'add_thread',
                side_effect=self._dummy_thread_group_add_thread))
Ejemplo n.º 20
0
    def setUp(self):
        self.source_resources = False
        super(TestRunTasks, self).setUp()

        # Set up a fake instance value to be returned by
        # instance_get_all_by_host() so when the manager gets the list
        # of instances to poll we can control the results.
        self.instances = [
            self._fake_instance('doing', 'active'),
            self._fake_instance('resting', 'paused')
        ]
        stillborn_instance = self._fake_instance('stillborn', 'error')

        self.useFixture(
            mockpatch.PatchObject(
                nova_client.Client,
                'instance_get_all_by_host',
                side_effect=lambda *x: self.instances + [stillborn_instance]))
Ejemplo n.º 21
0
 def setUp(self):
     super(BaseAgentManagerTestCase, self).setUp()
     self.mgr = self.create_manager()
     self.mgr.pollster_manager = self.create_pollster_manager()
     self.pipeline_cfg = [{
         'name': "test_pipeline",
         'interval': 60,
         'counters': ['test'],
         'resources': ['test://'] if self.source_resources else [],
         'transformers': [],
         'publishers': ["test"],
     }, ]
     self.setup_pipeline()
     self.CONF = self.useFixture(config.Config()).conf
     self.CONF.set_override(
         'pipeline_cfg_file',
         self.path_get('etc/ceilometer/pipeline.yaml')
     )
     self.useFixture(mockpatch.PatchObject(
         publisher, 'get_publisher', side_effect=self.get_publisher))
Ejemplo n.º 22
0
 def setUp(self):
     super(TestQueryToKwArgs, self).setUp()
     self.useFixture(mockpatch.PatchObject(
         api, '_sanitize_query', side_effect=lambda x, y, **z: x))
     self.useFixture(mockpatch.PatchObject(
         api, '_verify_query_segregation', side_effect=lambda x, **z: x))
Ejemplo n.º 23
0
 def setUp(self):
     super(TestEnergyPollster, self).setUp()
     self.context = context.get_admin_context()
     self.manager = TestManager()
     self.useFixture(mockpatch.PatchObject(
         kwapi._Base, '_iter_probes', side_effect=self.fake_iter_probes))