コード例 #1
0
 def test_compute_node_inventory_empty(self):
     uuid = uuids.compute_node
     name = 'computehost'
     compute_node = objects.ComputeNode(uuid=uuid,
                                        hypervisor_hostname=name,
                                        vcpus=0,
                                        cpu_allocation_ratio=16.0,
                                        memory_mb=0,
                                        ram_allocation_ratio=1.5,
                                        local_gb=0,
                                        disk_allocation_ratio=1.0)
     result = report._compute_node_to_inventory_dict(compute_node)
     self.assertEqual({}, result)
コード例 #2
0
ファイル: test_report.py プロジェクト: j-griffith/nova
 def test_compute_node_inventory_empty(self):
     uuid = uuids.compute_node
     name = 'computehost'
     compute_node = objects.ComputeNode(uuid=uuid,
                                        hypervisor_hostname=name,
                                        vcpus=0,
                                        cpu_allocation_ratio=16.0,
                                        memory_mb=0,
                                        ram_allocation_ratio=1.5,
                                        local_gb=0,
                                        disk_allocation_ratio=1.0)
     result = report._compute_node_to_inventory_dict(compute_node)
     self.assertEqual({}, result)
コード例 #3
0
ファイル: test_report.py プロジェクト: j-griffith/nova
 def test_update_inventory_no_update(self, mock_put, mock_get):
     uuid = uuids.compute_node
     compute_node = self.compute_node
     rp = objects.ResourceProvider(uuid=uuid, name='foo', generation=42)
     self.client._resource_providers[uuid] = rp
     mock_get.return_value.json.return_value = {
         'resource_provider_generation': 43,
         'inventories': {
             'VCPU': {
                 'total': 8,
                 'reserved': 0,
                 'min_unit': 1,
                 'max_unit': compute_node.vcpus,
                 'step_size': 1,
                 'allocation_ratio': compute_node.cpu_allocation_ratio,
             },
             'MEMORY_MB': {
                 'total': 1024,
                 'reserved': CONF.reserved_host_memory_mb,
                 'min_unit': 1,
                 'max_unit': compute_node.memory_mb,
                 'step_size': 1,
                 'allocation_ratio': compute_node.ram_allocation_ratio,
             },
             'DISK_GB': {
                 'total': 10,
                 'reserved': CONF.reserved_host_disk_mb * 1024,
                 'min_unit': 1,
                 'max_unit': compute_node.local_gb,
                 'step_size': 1,
                 'allocation_ratio': compute_node.disk_allocation_ratio,
             },
         }
     }
     inv_data = report._compute_node_to_inventory_dict(compute_node)
     result = self.client._update_inventory_attempt(
         compute_node.uuid, inv_data
     )
     self.assertTrue(result)
     exp_url = '/resource_providers/%s/inventories' % uuid
     mock_get.assert_called_once_with(exp_url)
     # No update so put should not be called
     self.assertFalse(mock_put.called)
     # Make sure we updated the generation from the inventory records
     self.assertEqual(43, rp.generation)
コード例 #4
0
ファイル: test_report.py プロジェクト: xx312022850/nova
    def test_compute_node_inventory(self):
        uuid = uuids.compute_node
        name = 'computehost'
        compute_node = objects.ComputeNode(uuid=uuid,
                                           hypervisor_hostname=name,
                                           vcpus=2,
                                           cpu_allocation_ratio=16.0,
                                           memory_mb=1024,
                                           ram_allocation_ratio=1.5,
                                           local_gb=10,
                                           disk_allocation_ratio=1.0)

        self.flags(reserved_host_memory_mb=1000)
        self.flags(reserved_host_disk_mb=2000)

        result = report._compute_node_to_inventory_dict(compute_node)

        expected = {
            'VCPU': {
                'total': compute_node.vcpus,
                'reserved': 0,
                'min_unit': 1,
                'max_unit': 1,
                'step_size': 1,
                'allocation_ratio': compute_node.cpu_allocation_ratio,
            },
            'MEMORY_MB': {
                'total': compute_node.memory_mb,
                'reserved': CONF.reserved_host_memory_mb,
                'min_unit': 1,
                'max_unit': 1,
                'step_size': 1,
                'allocation_ratio': compute_node.ram_allocation_ratio,
            },
            'DISK_GB': {
                'total': compute_node.local_gb,
                'reserved': CONF.reserved_host_disk_mb * 1024,
                'min_unit': 1,
                'max_unit': 1,
                'step_size': 1,
                'allocation_ratio': compute_node.disk_allocation_ratio,
            },
        }
        self.assertEqual(expected, result)
コード例 #5
0
 def test_update_inventory_no_update(self, mock_put, mock_get):
     uuid = uuids.compute_node
     compute_node = self.compute_node
     rp = objects.ResourceProvider(uuid=uuid, name='foo', generation=42)
     self.client._resource_providers[uuid] = rp
     mock_get.return_value.json.return_value = {
         'resource_provider_generation': 43,
         'inventories': {
             'VCPU': {
                 'total': 8,
                 'reserved': 0,
                 'min_unit': 1,
                 'max_unit': compute_node.vcpus,
                 'step_size': 1,
                 'allocation_ratio': compute_node.cpu_allocation_ratio,
             },
             'MEMORY_MB': {
                 'total': 1024,
                 'reserved': CONF.reserved_host_memory_mb,
                 'min_unit': 1,
                 'max_unit': compute_node.memory_mb,
                 'step_size': 1,
                 'allocation_ratio': compute_node.ram_allocation_ratio,
             },
             'DISK_GB': {
                 'total': 10,
                 'reserved': CONF.reserved_host_disk_mb * 1024,
                 'min_unit': 1,
                 'max_unit': compute_node.local_gb,
                 'step_size': 1,
                 'allocation_ratio': compute_node.disk_allocation_ratio,
             },
         }
     }
     inv_data = report._compute_node_to_inventory_dict(compute_node)
     result = self.client._update_inventory_attempt(compute_node.uuid,
                                                    inv_data)
     self.assertTrue(result)
     exp_url = '/resource_providers/%s/inventories' % uuid
     mock_get.assert_called_once_with(exp_url)
     # No update so put should not be called
     self.assertFalse(mock_put.called)
     # Make sure we updated the generation from the inventory records
     self.assertEqual(43, rp.generation)
コード例 #6
0
ファイル: test_report.py プロジェクト: j-griffith/nova
    def test_compute_node_inventory(self):
        uuid = uuids.compute_node
        name = 'computehost'
        compute_node = objects.ComputeNode(uuid=uuid,
                                           hypervisor_hostname=name,
                                           vcpus=2,
                                           cpu_allocation_ratio=16.0,
                                           memory_mb=1024,
                                           ram_allocation_ratio=1.5,
                                           local_gb=10,
                                           disk_allocation_ratio=1.0)

        self.flags(reserved_host_memory_mb=1000)
        self.flags(reserved_host_disk_mb=2000)

        result = report._compute_node_to_inventory_dict(compute_node)

        expected = {
            'VCPU': {
                'total': compute_node.vcpus,
                'reserved': 0,
                'min_unit': 1,
                'max_unit': compute_node.vcpus,
                'step_size': 1,
                'allocation_ratio': compute_node.cpu_allocation_ratio,
            },
            'MEMORY_MB': {
                'total': compute_node.memory_mb,
                'reserved': CONF.reserved_host_memory_mb,
                'min_unit': 1,
                'max_unit': compute_node.memory_mb,
                'step_size': 1,
                'allocation_ratio': compute_node.ram_allocation_ratio,
            },
            'DISK_GB': {
                'total': compute_node.local_gb,
                'reserved': CONF.reserved_host_disk_mb * 1024,
                'min_unit': 1,
                'max_unit': compute_node.local_gb,
                'step_size': 1,
                'allocation_ratio': compute_node.disk_allocation_ratio,
            },
        }
        self.assertEqual(expected, result)
コード例 #7
0
    def test_update_inventory_unknown_response(self, mock_put, mock_get):
        # Ensure _update_inventory() returns a list of Inventories objects
        # after creating or updating the existing values
        uuid = uuids.compute_node
        compute_node = self.compute_node
        rp = objects.ResourceProvider(uuid=uuid, name='foo', generation=42)
        # Make sure the ResourceProvider exists for preventing to call the API
        self.client._resource_providers[uuid] = rp

        mock_get.return_value = {}
        mock_put.return_value.status_code = 234

        inv_data = report._compute_node_to_inventory_dict(compute_node)
        result = self.client._update_inventory_attempt(compute_node.uuid,
                                                       inv_data)
        self.assertFalse(result)

        # No cache invalidation
        self.assertIn(uuid, self.client._resource_providers)
コード例 #8
0
ファイル: test_report.py プロジェクト: j-griffith/nova
    def test_update_inventory_unknown_response(self, mock_put, mock_get):
        # Ensure _update_inventory() returns a list of Inventories objects
        # after creating or updating the existing values
        uuid = uuids.compute_node
        compute_node = self.compute_node
        rp = objects.ResourceProvider(uuid=uuid, name='foo', generation=42)
        # Make sure the ResourceProvider exists for preventing to call the API
        self.client._resource_providers[uuid] = rp

        mock_get.return_value = {}
        mock_put.return_value.status_code = 234

        inv_data = report._compute_node_to_inventory_dict(compute_node)
        result = self.client._update_inventory_attempt(
            compute_node.uuid, inv_data
        )
        self.assertFalse(result)

        # No cache invalidation
        self.assertIn(uuid, self.client._resource_providers)
コード例 #9
0
    def test_update_inventory_conflicts(self, mock_ensure, mock_put, mock_get):
        # Ensure _update_inventory() returns a list of Inventories objects
        # after creating or updating the existing values
        uuid = uuids.compute_node
        compute_node = self.compute_node
        rp = objects.ResourceProvider(uuid=uuid, name='foo', generation=42)
        # Make sure the ResourceProvider exists for preventing to call the API
        self.client._resource_providers[uuid] = rp

        mock_get.return_value = {}
        mock_put.return_value.status_code = 409

        inv_data = report._compute_node_to_inventory_dict(compute_node)
        result = self.client._update_inventory_attempt(compute_node.uuid,
                                                       inv_data)
        self.assertFalse(result)

        # Invalidated the cache
        self.assertNotIn(uuid, self.client._resource_providers)
        # Refreshed our resource provider
        mock_ensure.assert_called_once_with(uuid)
コード例 #10
0
    def test_update_inventory_failed(self, mock_put, mock_get):
        # Ensure _update_inventory() returns a list of Inventories objects
        # after creating or updating the existing values
        uuid = uuids.compute_node
        compute_node = self.compute_node
        rp = objects.ResourceProvider(uuid=uuid, name='foo', generation=42)
        # Make sure the ResourceProvider exists for preventing to call the API
        self.client._resource_providers[uuid] = rp

        mock_get.return_value = {}
        try:
            mock_put.return_value.__nonzero__.return_value = False
        except AttributeError:
            # Thanks py3
            mock_put.return_value.__bool__.return_value = False

        inv_data = report._compute_node_to_inventory_dict(compute_node)
        result = self.client._update_inventory_attempt(compute_node.uuid,
                                                       inv_data)
        self.assertFalse(result)

        # No cache invalidation
        self.assertIn(uuid, self.client._resource_providers)
コード例 #11
0
ファイル: test_report.py プロジェクト: j-griffith/nova
    def test_update_inventory_conflicts(self, mock_ensure,
                                        mock_put, mock_get):
        # Ensure _update_inventory() returns a list of Inventories objects
        # after creating or updating the existing values
        uuid = uuids.compute_node
        compute_node = self.compute_node
        rp = objects.ResourceProvider(uuid=uuid, name='foo', generation=42)
        # Make sure the ResourceProvider exists for preventing to call the API
        self.client._resource_providers[uuid] = rp

        mock_get.return_value = {}
        mock_put.return_value.status_code = 409

        inv_data = report._compute_node_to_inventory_dict(compute_node)
        result = self.client._update_inventory_attempt(
            compute_node.uuid, inv_data
        )
        self.assertFalse(result)

        # Invalidated the cache
        self.assertNotIn(uuid, self.client._resource_providers)
        # Refreshed our resource provider
        mock_ensure.assert_called_once_with(uuid)
コード例 #12
0
ファイル: test_report.py プロジェクト: j-griffith/nova
    def test_update_inventory_failed(self, mock_put, mock_get):
        # Ensure _update_inventory() returns a list of Inventories objects
        # after creating or updating the existing values
        uuid = uuids.compute_node
        compute_node = self.compute_node
        rp = objects.ResourceProvider(uuid=uuid, name='foo', generation=42)
        # Make sure the ResourceProvider exists for preventing to call the API
        self.client._resource_providers[uuid] = rp

        mock_get.return_value = {}
        try:
            mock_put.return_value.__nonzero__.return_value = False
        except AttributeError:
            # Thanks py3
            mock_put.return_value.__bool__.return_value = False

        inv_data = report._compute_node_to_inventory_dict(compute_node)
        result = self.client._update_inventory_attempt(
            compute_node.uuid, inv_data
        )
        self.assertFalse(result)

        # No cache invalidation
        self.assertIn(uuid, self.client._resource_providers)
コード例 #13
0
    def test_update_inventory(self, mock_put, mock_get):
        # Ensure _update_inventory() returns a list of Inventories objects
        # after creating or updating the existing values
        uuid = uuids.compute_node
        compute_node = self.compute_node
        rp = objects.ResourceProvider(uuid=uuid, name='foo', generation=42)
        # Make sure the ResourceProvider exists for preventing to call the API
        self.client._resource_providers[uuid] = rp

        mock_get.return_value.json.return_value = {
            'resource_provider_generation': 43,
            'inventories': {
                'VCPU': {
                    'total': 16
                },
                'MEMORY_MB': {
                    'total': 1024
                },
                'DISK_GB': {
                    'total': 10
                },
            }
        }
        mock_put.return_value.status_code = 200
        mock_put.return_value.json.return_value = {
            'resource_provider_generation': 44,
            'inventories': {
                'VCPU': {
                    'total': 16
                },
                'MEMORY_MB': {
                    'total': 1024
                },
                'DISK_GB': {
                    'total': 10
                },
            }
        }

        inv_data = report._compute_node_to_inventory_dict(compute_node)
        result = self.client._update_inventory_attempt(compute_node.uuid,
                                                       inv_data)
        self.assertTrue(result)

        exp_url = '/resource_providers/%s/inventories' % uuid
        mock_get.assert_called_once_with(exp_url)
        # Updated with the new inventory from the PUT call
        self.assertEqual(44, rp.generation)
        expected = {
            # Called with the newly-found generation from the existing
            # inventory
            'resource_provider_generation': 43,
            'inventories': {
                'VCPU': {
                    'total': 8,
                    'reserved': 0,
                    'min_unit': 1,
                    'max_unit': compute_node.vcpus,
                    'step_size': 1,
                    'allocation_ratio': compute_node.cpu_allocation_ratio,
                },
                'MEMORY_MB': {
                    'total': 1024,
                    'reserved': CONF.reserved_host_memory_mb,
                    'min_unit': 1,
                    'max_unit': compute_node.memory_mb,
                    'step_size': 1,
                    'allocation_ratio': compute_node.ram_allocation_ratio,
                },
                'DISK_GB': {
                    'total': 10,
                    'reserved': CONF.reserved_host_disk_mb * 1024,
                    'min_unit': 1,
                    'max_unit': compute_node.local_gb,
                    'step_size': 1,
                    'allocation_ratio': compute_node.disk_allocation_ratio,
                },
            }
        }
        mock_put.assert_called_once_with(exp_url, expected)
コード例 #14
0
ファイル: test_report.py プロジェクト: j-griffith/nova
    def test_update_inventory(self, mock_put, mock_get):
        # Ensure _update_inventory() returns a list of Inventories objects
        # after creating or updating the existing values
        uuid = uuids.compute_node
        compute_node = self.compute_node
        rp = objects.ResourceProvider(uuid=uuid, name='foo', generation=42)
        # Make sure the ResourceProvider exists for preventing to call the API
        self.client._resource_providers[uuid] = rp

        mock_get.return_value.json.return_value = {
            'resource_provider_generation': 43,
            'inventories': {
                'VCPU': {'total': 16},
                'MEMORY_MB': {'total': 1024},
                'DISK_GB': {'total': 10},
            }
        }
        mock_put.return_value.status_code = 200
        mock_put.return_value.json.return_value = {
            'resource_provider_generation': 44,
            'inventories': {
                'VCPU': {'total': 16},
                'MEMORY_MB': {'total': 1024},
                'DISK_GB': {'total': 10},
            }
        }

        inv_data = report._compute_node_to_inventory_dict(compute_node)
        result = self.client._update_inventory_attempt(
            compute_node.uuid, inv_data
        )
        self.assertTrue(result)

        exp_url = '/resource_providers/%s/inventories' % uuid
        mock_get.assert_called_once_with(exp_url)
        # Updated with the new inventory from the PUT call
        self.assertEqual(44, rp.generation)
        expected = {
            # Called with the newly-found generation from the existing
            # inventory
            'resource_provider_generation': 43,
            'inventories': {
                'VCPU': {
                    'total': 8,
                    'reserved': 0,
                    'min_unit': 1,
                    'max_unit': compute_node.vcpus,
                    'step_size': 1,
                    'allocation_ratio': compute_node.cpu_allocation_ratio,
                },
                'MEMORY_MB': {
                    'total': 1024,
                    'reserved': CONF.reserved_host_memory_mb,
                    'min_unit': 1,
                    'max_unit': compute_node.memory_mb,
                    'step_size': 1,
                    'allocation_ratio': compute_node.ram_allocation_ratio,
                },
                'DISK_GB': {
                    'total': 10,
                    'reserved': CONF.reserved_host_disk_mb * 1024,
                    'min_unit': 1,
                    'max_unit': compute_node.local_gb,
                    'step_size': 1,
                    'allocation_ratio': compute_node.disk_allocation_ratio,
                },
            }
        }
        mock_put.assert_called_once_with(exp_url, expected)