Ejemplo n.º 1
0
    def test_init(self):
        """``PerfCollector`` the init parameters have not changed"""
        counter = 'some_vmware_stat'
        perfc = vsphere_collectors.PerfCollector(self.vcenter, self.entity,
                                                 counter)

        self.assertTrue(perfc.vcenter is self.vcenter)
        self.assertTrue(perfc.entity is self.entity)
        self.assertTrue(perfc.counter_name is counter)
Ejemplo n.º 2
0
    def test_perf_manager(self):
        """``PerfCollector`` the 'perf_manager' object is obtained form the vcenter content"""
        fake_perf_mgr = MagicMock()
        self.vcenter.content.perfManager = fake_perf_mgr
        perfc = vsphere_collectors.PerfCollector(self.vcenter, self.entity,
                                                 'some_vmware_stat')

        perf_mgr = perfc.perf_manager

        self.assertTrue(perf_mgr is fake_perf_mgr)
Ejemplo n.º 3
0
    def test_repr(self):
        """``PerfCollector`` the __repr__ contains metric context"""
        self.entity.name = 'someStat'
        perfc = vsphere_collectors.PerfCollector(self.vcenter, self.entity,
                                                 'some_vmware_stat')
        time_val = perfc.last_collected.strftime('%Y/%m/%d %H:%M:%S')

        repr = '{}'.format(perfc)
        expected = 'PerfCollector(name=someStat, stat=some_vmware_stat, last={})'.format(
            time_val)

        self.assertEqual(repr, expected)
Ejemplo n.º 4
0
    def test_query_no_data(self, fake_QuerySpec):
        """``PerfCollector`` the 'query' method returns an empty dictionary if no data is available"""
        fake_perf_mgr = MagicMock()
        fake_perf_mgr.QueryPerf.return_value = []
        self.vcenter.content.perfManager = fake_perf_mgr
        perfc = vsphere_collectors.PerfCollector(
            self.vcenter, self.entity, 'someGrp.someStat.someCategory')
        perfc._metric_id = ['someGrp.someStat.someCategory']

        stats = perfc.query()
        expected = {}

        self.assertEqual(stats, expected)
Ejemplo n.º 5
0
    def test_metric_id(self, fake_MetricId):
        """``PerfCollector`` the 'metric_id' property is only generated once"""
        fake_counter = MagicMock()
        fake_counter.key = 42
        fake_counter.groupInfo.key = 'someGrp'
        fake_counter.nameInfo.key = 'someStat'
        fake_counter.rollupType = 'someCategory'
        self.vcenter.content.perfManager.perfCounter = [fake_counter]
        perfc = vsphere_collectors.PerfCollector(
            self.vcenter, self.entity, 'someGrp.someStat.someCategory')

        perfc.metric_id
        perfc.metric_id

        self.assertEqual(fake_MetricId.call_count, 1)
Ejemplo n.º 6
0
    def test_counters(self):
        """``PerfCollector`` the 'counters' property returns a dictionary"""
        fake_counter = MagicMock()
        fake_counter.key = 42
        fake_counter.groupInfo.key = 'someGrp'
        fake_counter.nameInfo.key = 'someStat'
        fake_counter.rollupType = 'someCategory'
        self.vcenter.content.perfManager.perfCounter = [fake_counter]
        perfc = vsphere_collectors.PerfCollector(self.vcenter, self.entity,
                                                 'some_vmware_stat')

        counters = perfc.counters
        expected = {'someGrp.someStat.someCategory': 42}

        self.assertEqual(counters, expected)
Ejemplo n.º 7
0
    def test_query(self, fake_QuerySpec):
        """``PerfCollector`` the 'query' method returns a sane datastructure"""
        fake_data_value = MagicMock()
        fake_data_value.value = [42]
        fake_data_time = MagicMock()
        fake_data_time.timestamp = datetime.datetime.now()
        fake_data = MagicMock()
        fake_data.sampleInfo = [fake_data_time]
        fake_data.value = [fake_data_value]
        fake_perf_mgr = MagicMock()
        fake_perf_mgr.QueryPerf.return_value = [fake_data]
        self.vcenter.content.perfManager = fake_perf_mgr
        perfc = vsphere_collectors.PerfCollector(
            self.vcenter, self.entity, 'someGrp.someStat.someCategory')
        perfc._metric_id = ['someGrp.someStat.someCategory']

        stats = perfc.query()
        time_in_seconds = int(fake_data_time.timestamp.strftime('%s'))
        epoch = time_in_seconds - time.timezone
        expected = {epoch: 42}

        self.assertEqual(stats, expected)
Ejemplo n.º 8
0
    def test_query_index_error(self, fake_QuerySpec):
        """``PerfCollector`` the 'query' handles the shit partial response from pyVmomi"""
        fake_data_value = MagicMock()
        fake_data_value.value = [42]  # one value, but two time stamps...
        fake_data_time = MagicMock()
        fake_data_time.timestamp = datetime.datetime.now()
        fake_data = MagicMock()
        fake_data.sampleInfo = [fake_data_time, fake_data_time
                                ]  # two time stamps, but only 1 value...
        fake_data.value = [fake_data_value]
        fake_perf_mgr = MagicMock()
        fake_perf_mgr.QueryPerf.return_value = [fake_data]
        self.vcenter.content.perfManager = fake_perf_mgr
        perfc = vsphere_collectors.PerfCollector(
            self.vcenter, self.entity, 'someGrp.someStat.someCategory')
        perfc._metric_id = ['someGrp.someStat.someCategory']

        stats = perfc.query()
        time_in_seconds = int(fake_data_time.timestamp.strftime('%s'))
        epoch = time_in_seconds - time.timezone
        expected = {epoch: 42}

        self.assertEqual(stats, expected)