示例#1
0
    def test(self):
        """
        This test uses a simple, mock implementation of the alarm interface to
        check that create, update, delete, and list work correctly.

        """
        # In the beginning, there were no alarms
        _, alarms = self.plugin.do_alarm_list(self.account)
        self.assertEqual(0, len(alarms))

        # Create two alarms
        self.plugin.do_alarm_create(self.account, self.vim_id, RwmonYang.Alarm())
        self.plugin.do_alarm_create(self.account, self.vim_id, RwmonYang.Alarm())

        _, alarms = self.plugin.do_alarm_list(self.account)
        self.assertEqual(2, len(alarms))

        # The alarms should have no names
        alarms.sort(key=lambda a: a.alarm_id)
        self.assertEqual('test-alarm-id-1', alarms[0].alarm_id)
        self.assertEqual('test-alarm-id-2', alarms[1].alarm_id)
        self.assertTrue(all(a.name is None for a in alarms))

        # Give names to the alarms
        alarms[0].name = 'test-alarm'
        alarms[1].name = 'test-alarm'
        self.plugin.do_alarm_update(self.account, alarms[0])
        self.plugin.do_alarm_update(self.account, alarms[1])
        self.assertTrue(all(a.name == 'test-alarm' for a in alarms))

        # Delete the alarms
        self.plugin.do_alarm_delete(self.account, alarms[0].alarm_id)
        self.plugin.do_alarm_delete(self.account, alarms[1].alarm_id)
        _, alarms = self.plugin.do_alarm_list(self.account)
        self.assertEqual(0, len(alarms))
示例#2
0
    def test_null_data_source(self):
        """
        By default, the NFVI metrics plugin mock installs a 'null'
        implementation that simply returns empty NFVI structures.

        """
        status, metrics = self.plugin.nfvi_metrics(self.account, self.vim_id)
        self.assertEqual(status, RwTypes.RwStatus.SUCCESS)
        self.assertEqual(metrics,
                         RwmonYang.YangData_RwProject_Project_NfviMetrics())

        status, metrics = self.plugin.nfvi_vcpu_metrics(
            self.account, self.vim_id)
        self.assertEqual(status, RwTypes.RwStatus.SUCCESS)
        self.assertEqual(
            metrics, RwmonYang.YangData_RwProject_Project_NfviMetrics_Vcpu())

        status, metrics = self.plugin.nfvi_memory_metrics(
            self.account, self.vim_id)
        self.assertEqual(status, RwTypes.RwStatus.SUCCESS)
        self.assertEqual(
            metrics, RwmonYang.YangData_RwProject_Project_NfviMetrics_Memory())

        status, metrics = self.plugin.nfvi_storage_metrics(
            self.account, self.vim_id)
        self.assertEqual(status, RwTypes.RwStatus.SUCCESS)
        self.assertEqual(
            metrics,
            RwmonYang.YangData_RwProject_Project_NfviMetrics_Storage())

        status, result = self.plugin.nfvi_metrics_available(self.account)
        self.assertEqual(status, RwTypes.RwStatus.SUCCESS)
        self.assertTrue(result)
示例#3
0
    def test_mock_data_source(self):
        """
        This test installs a mock data source implementation in the plugin,
        which returns known values. This test simply checks the expected values
        are indeed returned.

        """
        expected_vcpu_metrics = RwmonYang.NfviMetrics_Vcpu()
        expected_vcpu_metrics.utilization = 50.0
        expected_vcpu_metrics.total = 100

        status, metrics = self.plugin.nfvi_vcpu_metrics(self.account, self.vim_id)
        self.assertEqual(status, RwTypes.RwStatus.SUCCESS)
        self.assertEqual(metrics.total, expected_vcpu_metrics.total)
        self.assertEqual(metrics.utilization, expected_vcpu_metrics.utilization)

        expected_memory_metrics = RwmonYang.NfviMetrics_Memory()
        expected_memory_metrics.used = 90
        expected_memory_metrics.total = 100
        expected_memory_metrics.utilization = 90/100

        status, metrics = self.plugin.nfvi_memory_metrics(self.account, self.vim_id)
        self.assertEqual(status, RwTypes.RwStatus.SUCCESS)
        self.assertEqual(metrics.used, expected_memory_metrics.used)
        self.assertEqual(metrics.total, expected_memory_metrics.total)
        self.assertEqual(metrics.utilization, expected_memory_metrics.utilization)

        expected_storage_metrics = RwmonYang.NfviMetrics_Storage()
        expected_storage_metrics.used = 300
        expected_storage_metrics.total = 500
        expected_storage_metrics.utilization = 300/500

        status, metrics = self.plugin.nfvi_storage_metrics(self.account, self.vim_id)
        self.assertEqual(status, RwTypes.RwStatus.SUCCESS)
        self.assertEqual(metrics.used, expected_storage_metrics.used)
        self.assertEqual(metrics.total, expected_storage_metrics.total)
        self.assertEqual(metrics.utilization, expected_storage_metrics.utilization)

        status, metrics = self.plugin.nfvi_metrics(self.account, self.vim_id)
        self.assertEqual(status, RwTypes.RwStatus.SUCCESS)
        self.assertEqual(metrics.vcpu.total, expected_vcpu_metrics.total)
        self.assertEqual(metrics.vcpu.utilization, expected_vcpu_metrics.utilization)
        self.assertEqual(metrics.storage.used, expected_storage_metrics.used)
        self.assertEqual(metrics.storage.total, expected_storage_metrics.total)
        self.assertEqual(metrics.storage.utilization, expected_storage_metrics.utilization)
        self.assertEqual(metrics.memory.used, expected_memory_metrics.used)
        self.assertEqual(metrics.memory.total, expected_memory_metrics.total)
        self.assertEqual(metrics.memory.utilization, expected_memory_metrics.utilization)

        status, result = self.plugin.nfvi_metrics_available(self.account)
        self.assertEqual(status, RwTypes.RwStatus.SUCCESS)
        self.assertTrue(result)
示例#4
0
    def do_nfvi_metrics(self, account, vm_id):
        try:
            samples = self._get_driver(account).ceilo_nfvi_metrics(vm_id)

            metrics = RwmonYang.YangData_RwProject_Project_NfviMetrics()

            vcpu = samples.get("cpu_util", {})
            memory = samples.get("memory_usage", {})
            storage = samples.get("disk_usage", {})

            metrics.vcpu.utilization = vcpu.get("volume", 0)
            metrics.memory.used = memory.get("volume", 0)
            metrics.storage.used = storage.get("volume", 0)

            def convert_timestamp(t):
                return dateutil.parser.parse(t).timestamp()

            timestamps = []
            if 'timestamp' in vcpu:
                timestamps.append(convert_timestamp(vcpu['timestamp']))
            if 'timestamp' in memory:
                timestamps.append(convert_timestamp(memory['timestamp']))
            if 'timestamp' in storage:
                timestamps.append(convert_timestamp(storage['timestamp']))

            metrics.timestamp = max(timestamps) if timestamps else 0.0

            return metrics

        except Exception as e:
            logger.exception(e)
示例#5
0
    def setUp(self):
        plugin = rw_peas.PeasPlugin("rwmon_mock", 'RwMon-1.0')

        self.mock = MockAlarmInterface()
        self.plugin = plugin.get_interface("Monitoring")
        self.plugin.set_impl(self.mock)

        self.account = RwcalYang.CloudAccount()
        self.alarm = RwmonYang.Alarm(name='test-alarm')
        self.vim_id = 'test-vim-id'
示例#6
0
    def do_nfvi_memory_metrics(self, account, vm_id):
        try:
            samples = self._get_driver(account).ceilo_nfvi_metrics(vm_id)

            metrics = RwmonYang.YangData_RwProject_Project_NfviMetrics_Memory()
            metrics.used = samples.get("memory_usage", 0)

            return metrics

        except Exception as e:
            logger.exception(e)
示例#7
0
    def do_nfvi_vcpu_metrics(self, account, vm_id):
        try:
            samples = self._get_driver(account).ceilo_nfvi_metrics(vm_id)

            metrics = RwmonYang.YangData_RwProject_Project_NfviMetrics_Vcpu()
            metrics.utilization = samples.get("cpu_util", 0)

            return metrics

        except Exception as e:
            logger.exception(e)
示例#8
0
    def do_nfvi_storage_metrics(self, account, vm_id):
        try:
            samples = self._get_driver(account).ceilo_nfvi_metrics(vm_id)

            metrics = RwmonYang.NfviMetrics_Storage()
            metrics.used = samples.get("disk_usage", 0)

            return metrics

        except Exception as e:
            logger.exception(e)
示例#9
0
 def nfvi_metrics(self, account, vm_id):
     metrics = RwmonYang.YangData_RwProject_Project_NfviMetrics()
     metrics.vcpu = self.nfvi_vcpu_metrics(account, vm_id)
     metrics.memory = self.nfvi_memory_metrics(account, vm_id)
     metrics.storage = self.nfvi_storage_metrics(account, vm_id)
     return metrics
示例#10
0
 def nfvi_storage_metrics(self, account, vm_id):
     return rwmon.YangData_RwProject_Project_NfviMetrics_Storage()
示例#11
0
 def nfvi_storage_metrics(self, account, vm_id):
     metrics = RwmonYang.YangData_RwProject_Project_NfviMetrics_Storage()
     metrics.used = 300
     metrics.total = 500
     metrics.utilization = 300 / 500
     return metrics
示例#12
0
 def nfvi_memory_metrics(self, account, vm_id):
     return rwmon.YangData_RwProject_Project_NfviMetrics_Memory()
示例#13
0
 def __init__(self):
     self.metrics = RwmonYang.NfviMetrics()
示例#14
0
 def __init__(self):
     self._metrics = dict()
     self._metrics['test-vim-id-1'] = RwmonYang.YangData_RwProject_Project_NfviMetrics()
     self._metrics['test-vim-id-2'] = RwmonYang.YangData_RwProject_Project_NfviMetrics()
示例#15
0
 def nfvi_metrics(self, account, vim_id):
     metrics = RwmonYang.YangData_RwProject_Project_NfviMetrics()
     metrics.vcpu.utilization = 0.5
     return metrics
示例#16
0
 def nfvi_storage_metrics(self, account, vm_id):
     return rwmon.NfviMetrics_Storage()
示例#17
0
 def nfvi_memory_metrics(self, account, vm_id):
     return rwmon.NfviMetrics_Memory()
示例#18
0
 def nfvi_vcpu_metrics(self, account, vm_id):
     return rwmon.NfviMetrics_Vcpu()
示例#19
0
 def __init__(self):
     self.metrics = RwmonYang.YangData_RwProject_Project_NfviMetrics()
示例#20
0
 def nfvi_vcpu_metrics(self, account, vm_id):
     metrics = RwmonYang.YangData_RwProject_Project_NfviMetrics_Vcpu()
     metrics.total = 100
     metrics.utilization = 50.0
     return metrics
示例#21
0
 def nfvi_metrics(self, account, vim_id):
     metrics = RwmonYang.NfviMetrics()
     metrics.vcpu.utilization = 0.5
     return metrics
示例#22
0
 def nfvi_memory_metrics(self, account, vm_id):
     metrics = RwmonYang.YangData_RwProject_Project_NfviMetrics_Memory()
     metrics.used = 90
     metrics.total = 100
     metrics.utilization = 90 / 100
     return metrics
示例#23
0
 def __init__(self):
     self._metrics = dict()
     self._metrics['test-vim-id-1'] = RwmonYang.NfviMetrics()
     self._metrics['test-vim-id-2'] = RwmonYang.NfviMetrics()
示例#24
0
 def nfvi_vcpu_metrics(self, account, vm_id):
     return rwmon.YangData_RwProject_Project_NfviMetrics_Vcpu()