Exemple #1
0
    def test_get_all_host_states_with_not_matching_aggs(
            self, svc_get_by_binary, cn_get_all, update_from_cn,
            mock_get_by_host):
        svc_get_by_binary.return_value = [
            objects.Service(host='fake'),
            objects.Service(host='other')
        ]
        cn_get_all.return_value = [
            objects.ComputeNode(host='fake', hypervisor_hostname='fake'),
            objects.ComputeNode(host='other', hypervisor_hostname='other')
        ]
        mock_get_by_host.return_value = objects.InstanceList()
        fake_agg = objects.Aggregate(id=1)
        self.host_manager.host_aggregates_map = collections.defaultdict(
            set, {'other': set([1])})
        self.host_manager.aggs_by_id = {1: fake_agg}

        self.host_manager.get_all_host_states('fake-context')
        host_state = self.host_manager.host_state_map[('fake', 'fake')]
        self.assertEqual([], host_state.aggregates)
    def test_blazar_filter_host_in_pool_none_requested(self):

        # Given the host belongs to the 'r-fakeres' reservation pool
        self.host.aggregates = [
            objects.Aggregate(
                name='r-fakeres',
                metadata={
                    'availability_zone':
                    (cfg.CONF['blazar:physical:host'].blazar_az_prefix) + 'XX',
                    self.spec_obj.project_id:
                    True
                })
        ]

        # And the filter doesn't require any pool (using filter as in setup())

        # When the host goes through the filter
        self.host.passes = self.f.host_passes(self.host, self.spec_obj)

        # Then the host shall NOT pass
        self.assertFalse(self.host.passes)
    def _create_instance_with_availability_zone(self, zone_name):
        def create(*args, **kwargs):
            self.assertIn('availability_zone', kwargs)
            self.assertEqual('nova', kwargs['availability_zone'])
            return old_create(*args, **kwargs)

        old_create = compute_api.API.create
        self.stub_out('nova.compute.api.API.create', create)
        image_href = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
        flavor_ref = ('http://localhost' + self.base_url + 'flavors/3')
        body = {
            'server': {
                'name': 'server_test',
                'imageRef': image_href,
                'flavorRef': flavor_ref,
                'metadata': {
                    'hello': 'world',
                    'open': 'stack',
                },
                'availability_zone': zone_name,
            },
        }

        req = fakes.HTTPRequest.blank('')
        req.method = 'POST'
        req.body = jsonutils.dump_as_bytes(body)
        req.headers['content-type'] = 'application/json'

        admin_context = context.get_admin_context()
        db.service_create(admin_context, {'host': 'host1_zones',
                                          'binary': "nova-compute",
                                          'topic': 'compute',
                                          'report_count': 0})
        agg = objects.Aggregate(admin_context,
                                name='agg1',
                                uuid=uuidsentinel.agg_uuid,
                                metadata={'availability_zone': 'nova'})
        agg.create()
        agg.add_host('host1_zones')
        return req, body
    def test_blazar_filter_unicode_requested_pool(self):

        # Given the host is in a pool with unicode characters
        self.host.aggregates = [
            objects.Aggregate(
                name=U'r-fakeres',
                metadata={
                    'availability_zone':
                    (cfg.CONF['blazar:physical:host'].blazar_az_prefix),
                    self.spec_obj.project_id:
                    True
                })
        ]

        # And the filter is requesting for a host with the same name (ucode)
        self.spec_obj.scheduler_hints = {'reservation': [U'r-fakeres']}

        # When the host goes through the filter
        self.host.passes = self.f.host_passes(self.host, self.spec_obj)

        # Then the host shall pass
        self.assertTrue(self.host.passes)
    def test_host_with_agg(self):
        # host1: idle=512,  kernel=1
        # host2: idle=1024, kernel=2
        # host3: idle=3072, kernel=1
        # host4: idle=8192, kernel=0
        # so, host4 should win:
        setting = [idle + '=0.0001', kernel]
        hostinfo_list = self._get_all_hosts()
        aggs = [
            objects.Aggregate(
                id=1,
                name='foo',
                hosts=['host1', 'host2', 'host3', 'host4', 'host5', 'host6'],
                metadata={'metrics_weight_multiplier': '1.5'},
            )
        ]
        for h in hostinfo_list:
            h.aggregates = aggs
        weighed_host = self._get_weighed_host(hostinfo_list, setting)

        self.assertEqual(1.5, weighed_host.weight)
        self.assertEqual('host4', weighed_host.obj.host)
Exemple #6
0
    def test_host_with_agg(self):
        self.flags(cpu_weight_multiplier=-1.0, group='filter_scheduler')
        hostinfo_list = self._get_all_hosts()
        aggs = [
            objects.Aggregate(
                id=1,
                name='foo',
                hosts=['host1', 'host2', 'host3', 'host4'],
                metadata={'cpu_weight_multiplier': '1.5'},
            )]
        for h in hostinfo_list:
            h.aggregates = aggs
        # host1: vcpus_free=0
        # host2: vcpus_free=2
        # host3: vcpus_free=6
        # host4: vcpus_free=8

        # so, host4 should win
        weights = self.weight_handler.get_weighed_objects(self.weighers,
                                                          hostinfo_list, {})
        weighed_host = weights[0]
        self.assertEqual(1.5, weighed_host.weight)
        self.assertEqual('host4', weighed_host.obj.host)
    def test_blazar_filter_host_not_authorized_by_owner(self):

        # Given the host blazar owner is NOT the current project id
        # And the pool name is 'r-fakeres'
        self.host.aggregates = [
            objects.Aggregate(
                name='r-fakeres',
                metadata={
                    'availability_zone':
                    (cfg.CONF['blazar:physical:host'].blazar_az_prefix),
                    cfg.CONF['blazar:physical:host'].blazar_owner:
                    ('another_project_id')
                })
        ]

        # And the 'r-fakeres' pool is requested in the filter
        self.spec_obj.scheduler_hints = {'reservation': ['r-fakeres']}

        # When the host goes through the filter
        self.host.passes = self.f.host_passes(self.host, self.spec_obj)

        # Then the host shall NOT pass
        self.assertFalse(self.host.passes)
    def test_blazar_filter_host_auth_in_current_tenant(self):

        # Given the host is authorized in the current tenant
        # And the pool name is 'r-fakeres'
        self.host.aggregates = [
            objects.Aggregate(
                name='r-fakeres',
                metadata={
                    'availability_zone':
                    (cfg.CONF['blazar:physical:host'].blazar_az_prefix),
                    self.spec_obj.project_id:
                    True
                })
        ]

        # And the 'r-fakeres' pool is requested in the filter
        self.spec_obj.scheduler_hints = {'reservation': ['r-fakeres']}

        # When the host goes through the filter
        self.host.passes = self.f.host_passes(self.host, self.spec_obj)

        # Then the host shall pass
        self.assertTrue(self.host.passes)
    def test_host_with_agg(self):
        self.flags(pci_weight_multiplier=0.0, group='filter_scheduler')
        hosts = [
            ('host1', 'node1', [2, 2, 2]),  # 6 devs
            ('host2', 'node2', [3, 1]),  # 4 devs
        ]
        hostinfo_list = self._get_all_hosts(hosts)
        aggs = [
            objects.Aggregate(
                id=1,
                name='foo',
                hosts=['host1', 'host2'],
                metadata={'pci_weight_multiplier': '1.5'},
            )
        ]
        for h in hostinfo_list:
            h.aggregates = aggs

        spec_obj = objects.RequestSpec(pci_requests=None)

        # host2, which has the least free PCI devices, should win
        weighed_host = self._get_weighed_hosts(hostinfo_list, spec_obj)[0]
        self.assertEqual(1.5, weighed_host.weight)
        self.assertEqual('host2', weighed_host.obj.host)
Exemple #10
0
    def test_cache_image(self):
        """Test caching images by injecting the request directly to
        the conductor service and making sure it fans out and calls
        the expected nodes.
        """

        aggregate = objects.Aggregate(
            name='test',
            uuid=uuids.aggregate,
            id=1,
            hosts=['compute1', 'compute3', 'compute4', 'compute5'])
        self.conductor.compute_task_mgr.cache_images(self.context, aggregate,
                                                     ['an-image'])

        # NOTE(danms): We expect only three image cache attempts because
        # compute5 is marked as forced-down and compute2 is not in the
        # requested aggregate.
        for host in ['compute1', 'compute3', 'compute4']:
            mgr = getattr(self, host)
            self.assertEqual(set(['an-image']), mgr.driver.cached_images)
        for host in ['compute2', 'compute5']:
            mgr = getattr(self, host)
            self.assertEqual(set(), mgr.driver.cached_images)

        fake_notifier.wait_for_versioned_notifications(
            'aggregate.cache_images.start')
        fake_notifier.wait_for_versioned_notifications(
            'aggregate.cache_images.end')

        logtext = self.stdlog.logger.output

        self.assertIn(
            '3 cached, 0 existing, 0 errors, 0 unsupported, 1 skipped',
            logtext)
        self.assertNotIn('Image pre-cache operation for image an-image failed',
                         logtext)
Exemple #11
0
    def test_host_with_agg(self):
        self.flags(disk_weight_multiplier=-1.0, group='filter_scheduler')
        hostinfo_list = self._get_all_hosts()
        aggs = [
            objects.Aggregate(
                id=1,
                name='foo',
                hosts=['host1', 'host2', 'host3', 'host4'],
                metadata={'disk_weight_multiplier': '1.5'},
            )
        ]
        for h in hostinfo_list:
            h.aggregates = aggs
        # host1: free_disk_mb=5120
        # host2: free_disk_mb=10240
        # host3: free_disk_mb=30720
        # host4: free_disk_mb=81920

        # so, host4 should win:
        weights = self.weight_handler.get_weighed_objects(
            self.weighers, hostinfo_list, {})
        weighed_host = weights[0]
        self.assertEqual(1.0 * 1.5, weighed_host.weight)
        self.assertEqual('host4', weighed_host.obj.host)
Exemple #12
0
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from nova import objects
from nova.scheduler.filters import utils
from nova import test
from nova.tests.unit.scheduler import fakes
from nova.tests import uuidsentinel as uuids

_AGGREGATE_FIXTURES = [
    objects.Aggregate(
        id=1,
        name='foo',
        hosts=['fake-host'],
        metadata={
            'k1': '1',
            'k2': '2'
        },
    ),
    objects.Aggregate(
        id=2,
        name='bar',
        hosts=['fake-host'],
        metadata={
            'k1': '3',
            'k2': '4'
        },
    ),
    objects.Aggregate(
        id=3,
Exemple #13
0
 def test_update_aggregates(self):
     fake_agg = objects.Aggregate(id=1, hosts=['fake-host'])
     self.host_manager.update_aggregates([fake_agg])
     self.assertEqual({1: fake_agg}, self.host_manager.aggs_by_id)
     self.assertEqual({'fake-host': set([1])},
                      self.host_manager.host_aggregates_map)
def _make_agg_obj(agg_dict):
    return objects.Aggregate(**agg_dict)
Exemple #15
0
 def test_update_aggregates(self, mock_update_aggs):
     aggregates = [objects.Aggregate(id=1)]
     self.client.update_aggregates(context=self.context,
                                   aggregates=aggregates)
     mock_update_aggs.assert_called_once_with(self.context, aggregates)
Exemple #16
0
 def test_delete_aggregate(self, mock_delete_agg):
     aggregate = objects.Aggregate(id=1)
     self.client.delete_aggregate(context='context', aggregate=aggregate)
     mock_delete_agg.assert_called_once_with('context', aggregate)
Exemple #17
0
 def test_map_az(self, getmd):
     getmd.return_value = [objects.Aggregate(uuid=uuids.agg1)]
     reqspec = objects.RequestSpec(availability_zone='fooaz')
     request_filter.map_az_to_placement_aggregate(self.context, reqspec)
     self.assertEqual([uuids.agg1],
                      reqspec.requested_destination.aggregates)
Exemple #18
0
    def test_with_tenant_and_az_and_traits(self, mock_getmd, mock_getnotmd):
        mock_getmd.side_effect = [
            # Tenant filter
            [
                objects.Aggregate(uuid=uuids.agg1,
                                  metadata={'filter_tenant_id': 'owner'}),
                objects.Aggregate(uuid=uuids.agg2,
                                  metadata={'filter_tenant_id:12': 'owner'}),
                objects.Aggregate(uuid=uuids.agg3,
                                  metadata={'other_key': 'owner'})
            ],
            # AZ filter
            [
                objects.Aggregate(uuid=uuids.agg4,
                                  metadata={'availability_zone': 'myaz'})
            ],
        ]

        mock_getnotmd.side_effect = [
            # isolate_aggregates filter
            [
                objects.Aggregate(uuid=uuids.agg1,
                                  metadata={
                                      'trait:CUSTOM_WINDOWS_LICENSED_TRAIT':
                                      'required'
                                  }),
                objects.Aggregate(uuid=uuids.agg2,
                                  metadata={
                                      'trait:CUSTOM_WINDOWS_LICENSED_TRAIT':
                                      'required',
                                      'trait:CUSTOM_XYZ_TRAIT': 'required'
                                  }),
                objects.Aggregate(
                    uuid=uuids.agg3,
                    metadata={'trait:CUSTOM_XYZ_TRAIT': 'required'}),
            ],
        ]

        traits = set(['HW_GPU_API_DXVA', 'HW_NIC_DCB_ETS'])
        fake_flavor = objects.Flavor(
            vcpus=1,
            memory_mb=1024,
            root_gb=10,
            ephemeral_gb=5,
            swap=0,
            extra_specs={'trait:' + trait: 'required'
                         for trait in traits})
        fake_image = objects.ImageMeta(properties=objects.ImageMetaProps(
            traits_required=[]))
        reqspec = objects.RequestSpec(project_id='owner',
                                      availability_zone='myaz',
                                      flavor=fake_flavor,
                                      image=fake_image)
        request_filter.process_reqspec(self.context, reqspec)
        self.assertEqual(
            ','.join(sorted([uuids.agg1, uuids.agg2])), ','.join(
                sorted(
                    reqspec.requested_destination.aggregates[0].split(','))))
        self.assertEqual(
            ','.join(sorted([uuids.agg4])), ','.join(
                sorted(
                    reqspec.requested_destination.aggregates[1].split(','))))
        self.assertItemsEqual(
            set([uuids.agg1, uuids.agg2, uuids.agg3]),
            reqspec.requested_destination.forbidden_aggregates)
        mock_getmd.assert_has_calls([
            mock.call(self.context, value='owner'),
            mock.call(self.context, key='availability_zone', value='myaz')
        ])

        keys = ['trait:%s' % trait for trait in traits]
        mock_getnotmd.assert_called_once_with(self.context,
                                              utils.ItemsMatcher(keys),
                                              'trait:',
                                              value='required')
Exemple #19
0
 def test_aggregate_not_migrated(self):
     agg = objects.Aggregate(context=self.context, name='foo')
     agg.create()
     db_api.aggregate_update(self.context, agg.id, {'uuid': None})
     self.assertRaises(exception.ValidationError, self.migration.upgrade,
                       self.engine)