Exemplo n.º 1
0
    def test_require_tenant_aggregate(self, mock_log, getmd):
        getmd.return_value = [
            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'}),
        ]
        reqspec = objects.RequestSpec(project_id='owner')
        request_filter.require_tenant_aggregate(self.context, reqspec)
        self.assertEqual(
            ','.join(sorted([uuids.agg1, uuids.agg2])),
            ','.join(sorted(
                reqspec.requested_destination.aggregates[0].split(','))))
        # Make sure we called with the request spec's tenant and not
        # necessarily just the one from context.
        getmd.assert_called_once_with(self.context, value='owner')

        log_lines = [c[0][0] for c in mock_log.debug.call_args_list]
        self.assertIn('filter added aggregates', log_lines[0])
        self.assertIn('took %.1f seconds', log_lines[1])
Exemplo n.º 2
0
 def test_require_tenant_aggregate(self, getmd):
     getmd.return_value = [
         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'}),
     ]
     reqspec = objects.RequestSpec(project_id='owner')
     request_filter.require_tenant_aggregate(self.context, reqspec)
     self.assertEqual(
         ','.join(sorted([uuids.agg1, uuids.agg2])), ','.join(
             sorted(
                 reqspec.requested_destination.aggregates[0].split(','))))
     # Make sure we called with the request spec's tenant and not
     # necessarily just the one from context.
     getmd.assert_called_once_with(self.context, value='owner')
Exemplo n.º 3
0
 def test_require_tenant_aggregate(self, getmd):
     getmd.return_value = [
         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'}),
     ]
     reqspec = objects.RequestSpec(project_id='owner')
     request_filter.require_tenant_aggregate(self.context, reqspec)
     self.assertEqual(
         ','.join(sorted([uuids.agg1, uuids.agg2])),
         ','.join(sorted(
             reqspec.requested_destination.aggregates[0].split(','))))
     # Make sure we called with the request spec's tenant and not
     # necessarily just the one from context.
     getmd.assert_called_once_with(self.context, value='owner')
Exemplo n.º 4
0
 def test_require_tenant_aggregate_no_match_not_required(self, getmd):
     getmd.return_value = []
     request_filter.require_tenant_aggregate(
         self.context, mock.MagicMock())
Exemplo n.º 5
0
 def test_require_tenant_aggregate_disabled(self, getmd):
     self.flags(limit_tenants_to_placement_aggregate=False,
                group='scheduler')
     reqspec = mock.MagicMock()
     request_filter.require_tenant_aggregate(self.context, reqspec)
     self.assertFalse(getmd.called)