예제 #1
0
    def test_cinder_capacity(self):
        """test consuming capacity"""

        storage_model = self.fake_cdmc.generate_scenario_1()
        self.fake_cdmc.cluster_data_model = storage_model
        handler = cnotification.CapacityNotificationEndpoint(self.fake_cdmc)

        pool_0_name = 'host_0@backend_0#pool_0'
        pool_0 = storage_model.get_pool_by_pool_name(pool_0_name)

        # before
        self.assertEqual(pool_0_name, pool_0.name)
        self.assertEqual(420, pool_0.free_capacity_gb)
        self.assertEqual(420, pool_0.virtual_free)
        self.assertEqual(80, pool_0.allocated_capacity_gb)
        self.assertEqual(80, pool_0.provisioned_capacity_gb)

        message = self.load_message('scenario_1_capacity.json')
        handler.info(
            ctxt=self.context,
            publisher_id=message['publisher_id'],
            event_type=message['event_type'],
            payload=message['payload'],
            metadata=self.FAKE_METADATA,
        )

        # after
        self.assertEqual(pool_0_name, pool_0.name)
        self.assertEqual(460, pool_0.free_capacity_gb)
        self.assertEqual(460, pool_0.virtual_free)
        self.assertEqual(40, pool_0.allocated_capacity_gb)
        self.assertEqual(40, pool_0.provisioned_capacity_gb)
예제 #2
0
 def notification_endpoints(self):
     return [
         cnotification.CapacityNotificationEndpoint(self.fake_cdmc),
         cnotification.VolumeCreateEnd(self.fake_cdmc),
         cnotification.VolumeUpdateEnd(self.fake_cdmc),
         cnotification.VolumeDeleteEnd(self.fake_cdmc),
         cnotification.VolumeAttachEnd(self.fake_cdmc),
         cnotification.VolumeDetachEnd(self.fake_cdmc),
         cnotification.VolumeResizeEnd(self.fake_cdmc),
     ]
예제 #3
0
    def test_cinder_capacity_pool_notfound(self, m_cinder_helper):
        """test consuming capacity, new pool in existing node"""

        # storage_pool_by_name mock
        return_mock = mock.Mock()
        return_mock.configure_mock(name='host_0@backend_0#pool_2',
                                   total_volumes='2',
                                   total_capacity_gb='500',
                                   free_capacity_gb='380',
                                   provisioned_capacity_gb='120',
                                   allocated_capacity_gb='120')

        m_get_storage_pool_by_name = mock.Mock(
            side_effect=lambda name: return_mock)

        m_cinder_helper.return_value = mock.Mock(
            get_storage_pool_by_name=m_get_storage_pool_by_name)

        storage_model = self.fake_cdmc.generate_scenario_1()
        self.fake_cdmc.cluster_data_model = storage_model
        handler = cnotification.CapacityNotificationEndpoint(self.fake_cdmc)

        message = self.load_message('scenario_1_capacity_pool_notfound.json')
        handler.info(
            ctxt=self.context,
            publisher_id=message['publisher_id'],
            event_type=message['event_type'],
            payload=message['payload'],
            metadata=self.FAKE_METADATA,
        )

        # after consuming message, still pool_0 exists
        pool_0_name = 'host_0@backend_0#pool_0'
        pool_0 = storage_model.get_pool_by_pool_name(pool_0_name)
        self.assertEqual(pool_0_name, pool_0.name)
        self.assertEqual(420, pool_0.free_capacity_gb)
        self.assertEqual(420, pool_0.virtual_free)
        self.assertEqual(80, pool_0.allocated_capacity_gb)
        self.assertEqual(80, pool_0.provisioned_capacity_gb)

        # new pool was added
        pool_1_name = 'host_0@backend_0#pool_2'
        m_get_storage_pool_by_name.assert_called_once_with(pool_1_name)
        storage_node = storage_model.get_node_by_pool_name(pool_1_name)
        self.assertEqual('host_0@backend_0', storage_node.host)
        pool_1 = storage_model.get_pool_by_pool_name(pool_1_name)
        self.assertEqual(pool_1_name, pool_1.name)
        self.assertEqual(500, pool_1.total_capacity_gb)
        self.assertEqual(380, pool_1.free_capacity_gb)
        self.assertEqual(120, pool_1.allocated_capacity_gb)
예제 #4
0
    def notification_endpoints(self):
        """Associated notification endpoints

        :return: Associated notification endpoints
        :rtype: List of :py:class:`~.EventsNotificationEndpoint` instances
        """
        return [
            cinder.CapacityNotificationEndpoint(self),
            cinder.VolumeCreateEnd(self),
            cinder.VolumeDeleteEnd(self),
            cinder.VolumeUpdateEnd(self),
            cinder.VolumeAttachEnd(self),
            cinder.VolumeDetachEnd(self),
            cinder.VolumeResizeEnd(self)
        ]
예제 #5
0
    def test_cinder_capacity_node_notfound(self, m_cinder_helper):
        """test consuming capacity, new pool in new node"""

        return_pool_mock = mock.Mock()
        return_pool_mock.configure_mock(name='host_2@backend_2#pool_0',
                                        total_volumes='2',
                                        total_capacity_gb='500',
                                        free_capacity_gb='460',
                                        provisioned_capacity_gb='40',
                                        allocated_capacity_gb='40')

        m_get_storage_pool_by_name = mock.Mock(
            side_effect=lambda name: return_pool_mock)

        # storage_node_by_name mock
        return_node_mock = mock.Mock()
        return_node_mock.configure_mock(host='host_2@backend_2',
                                        zone='nova',
                                        state='up',
                                        status='enabled')

        m_get_storage_node_by_name = mock.Mock(
            side_effect=lambda name: return_node_mock)

        m_get_volume_type_by_backendname = mock.Mock(
            side_effect=lambda name: mock.Mock('backend_2'))

        m_cinder_helper.return_value = mock.Mock(
            get_storage_pool_by_name=m_get_storage_pool_by_name,
            get_storage_node_by_name=m_get_storage_node_by_name,
            get_volume_type_by_backendname=m_get_volume_type_by_backendname)

        storage_model = self.fake_cdmc.generate_scenario_1()
        self.fake_cdmc.cluster_data_model = storage_model
        handler = cnotification.CapacityNotificationEndpoint(self.fake_cdmc)

        message = self.load_message('scenario_1_capacity_node_notfound.json')
        handler.info(
            ctxt=self.context,
            publisher_id=message['publisher_id'],
            event_type=message['event_type'],
            payload=message['payload'],
            metadata=self.FAKE_METADATA,
        )

        # new pool and new node was added
        node_1_name = 'host_2@backend_2'
        pool_1_name = node_1_name + '#pool_0'
        volume_type = 'backend_2'
        m_get_storage_pool_by_name.assert_called_once_with(pool_1_name)
        m_get_storage_node_by_name.assert_called_once_with(node_1_name)
        m_get_volume_type_by_backendname.assert_called_once_with(volume_type)
        # new node was added
        storage_node = storage_model.get_node_by_pool_name(pool_1_name)
        self.assertEqual('host_2@backend_2', storage_node.host)
        # new pool was added
        pool_1 = storage_model.get_pool_by_pool_name(pool_1_name)
        self.assertEqual(pool_1_name, pool_1.name)
        self.assertEqual(500, pool_1.total_capacity_gb)
        self.assertEqual(460, pool_1.free_capacity_gb)
        self.assertEqual(40, pool_1.allocated_capacity_gb)
        self.assertEqual(40, pool_1.provisioned_capacity_gb)