示例#1
0
 def test_auto_pin_caches(self, mock_get_min):
     mock_get_min.return_value = 1
     self.flags(compute='auto', group='upgrade_levels')
     compute_rpcapi.LAST_VERSION = None
     api = compute_rpcapi.ComputeAPI()
     for x in range(2):
         api._determine_version_cap(mock.Mock())
     mock_get_min.assert_called_once_with(mock.ANY, ['nova-compute'])
     self.assertEqual('4.4', compute_rpcapi.LAST_VERSION)
示例#2
0
 def __init__(self, scheduler_driver=None, *args, **kwargs):
     if not scheduler_driver:
         scheduler_driver = CONF.scheduler_driver
     self.driver = importutils.import_object(scheduler_driver)
     self.compute_rpcapi = compute_rpcapi.ComputeAPI()
     super(SchedulerManager, self).__init__(service_name='scheduler',
                                            *args,
                                            **kwargs)
     self.additional_endpoints.append(_SchedulerManagerV3Proxy(self))
示例#3
0
 def __init__(self, console_driver=None, *args, **kwargs):
     if not console_driver:
         console_driver = CONF.console_driver
     self.driver = importutils.import_object(console_driver)
     super(ConsoleProxyManager, self).__init__(service_name='console',
                                               *args,
                                               **kwargs)
     self.driver.host = self.host
     self.compute_rpcapi = compute_rpcapi.ComputeAPI()
示例#4
0
 def __init__(self, session, virtapi):
     host_ref = session.get_xenapi_host()
     host_rec = session.call_xenapi('host.get_record', host_ref)
     self._host_name = host_rec['hostname']
     self._host_addr = host_rec['address']
     self._host_uuid = host_rec['uuid']
     self._session = session
     self._virtapi = virtapi
     self.compute_rpcapi = compute_rpcapi.ComputeAPI()
示例#5
0
 def __init__(self, *args, **kwargs):
     super(FilterScheduler, self).__init__(*args, **kwargs)
     self.options = scheduler_options.SchedulerOptions()
     self.compute_rpcapi = compute_rpcapi.ComputeAPI()
     self.notifier = rpc.get_notifier('scheduler')
     self._supports_affinity = scheduler_utils.validate_filter(
         'ServerGroupAffinityFilter')
     self._supports_anti_affinity = scheduler_utils.validate_filter(
         'ServerGroupAntiAffinityFilter')
示例#6
0
 def _generate_task(self):
     return migrate.MigrationTask(self.context,
                                  self.instance,
                                  self.flavor,
                                  self.request_spec,
                                  self.clean_shutdown,
                                  compute_rpcapi.ComputeAPI(),
                                  scheduler_client.SchedulerClient(),
                                  host_list=None)
 def test_cache_image_pinned(self):
     ctxt = context.RequestContext('fake_user', 'fake_project')
     rpcapi = compute_rpcapi.ComputeAPI()
     rpcapi.router.client = mock.Mock()
     mock_client = mock.MagicMock()
     rpcapi.router.client.return_value = mock_client
     mock_client.can_send_version.return_value = False
     self.assertRaises(exception.NovaException,
                       rpcapi.cache_images, ctxt, 'host', ['image'])
示例#8
0
    def __init__(self, scheduler_driver=None, *args, **kwargs):
        super(ConsoleAuthManager, self).__init__(*args, **kwargs)

        if FLAGS.memcached_servers:
            import memcache
        else:
            from nova.common import memorycache as memcache
        self.mc = memcache.Client(FLAGS.memcached_servers, debug=0)
        self.compute_rpcapi = compute_rpcapi.ComputeAPI()
示例#9
0
 def test_auto_pin_with_service_version_zero(self, mock_get_min):
     mock_get_min.return_value = 0
     self.flags(compute='auto', group='upgrade_levels')
     compute_rpcapi.LAST_VERSION = None
     rpcapi = compute_rpcapi.ComputeAPI()
     history = service_obj.SERVICE_VERSION_HISTORY
     current_version = history[service_obj.SERVICE_VERSION]['compute_rpc']
     self.assertEqual(current_version, rpcapi.router.version_cap)
     mock_get_min.assert_called_once_with(mock.ANY, ['nova-compute'])
     self.assertIsNone(compute_rpcapi.LAST_VERSION)
示例#10
0
 def _generate_task(self):
     return migrate.MigrationTask(self.context,
                                  self.instance,
                                  self.flavor,
                                  self.request_spec,
                                  self.clean_shutdown,
                                  compute_rpcapi.ComputeAPI(),
                                  query.SchedulerQueryClient(),
                                  report.SchedulerReportClient(),
                                  host_list=None,
                                  network_api=self.mock_network_api)
示例#11
0
 def test_version_cap_no_computes_log_once(self, mock_allcells, mock_minver,
                                           mock_log):
     self.flags(connection=None, group='api_database')
     self.flags(compute='auto', group='upgrade_levels')
     mock_minver.return_value = 0
     api = compute_rpcapi.ComputeAPI()
     for x in range(2):
         api._determine_version_cap(mock.Mock())
     mock_allcells.assert_not_called()
     mock_minver.assert_has_calls([
         mock.call(mock.ANY, 'nova-compute'),
         mock.call(mock.ANY, 'nova-compute')])
示例#12
0
 def test_revert_snapshot_based_resize_at_dest_old_compute(self, client):
     """Tests when the dest compute service is too old to call
     revert_snapshot_based_resize_at_dest so MigrationError is raised.
     """
     client.return_value.can_send_version.return_value = False
     rpcapi = compute_rpcapi.ComputeAPI()
     ex = self.assertRaises(
         exception.MigrationError,
         rpcapi.revert_snapshot_based_resize_at_dest,
         self.context,
         instance=self.fake_instance_obj,
         migration=migration_obj.Migration(dest_compute='dest'))
     self.assertIn('Compute too old', six.text_type(ex))
示例#13
0
 def test_confirm_snapshot_based_resize_at_source_old_compute(self, client):
     """Tests when the source compute service is too old to call
     confirm_snapshot_based_resize_at_source so MigrationError is raised.
     """
     client.return_value.can_send_version.return_value = False
     rpcapi = compute_rpcapi.ComputeAPI()
     ex = self.assertRaises(
         exception.MigrationError,
         rpcapi.confirm_snapshot_based_resize_at_source,
         self.context,
         instance=self.fake_instance_obj,
         migration=migration_obj.Migration(source_compute='source'))
     self.assertIn('Compute too old', str(ex))
示例#14
0
 def __init__(self, context, instance, destination, block_migration,
              disk_over_commit):
     self.context = context
     self.instance = instance
     self.destination = destination
     self.block_migration = block_migration
     self.disk_over_commit = disk_over_commit
     self.source = instance.host
     self.migrate_data = None
     self.compute_rpcapi = compute_rpcapi.ComputeAPI()
     self.servicegroup_api = servicegroup.API()
     self.scheduler_client = scheduler_client.SchedulerClient()
     self.image_api = image.API()
示例#15
0
 def __init__(self, context, instance, destination, block_migration,
              disk_over_commit, select_hosts_callback):
     self.context = context
     self.instance = instance
     self.destination = destination
     self.block_migration = block_migration
     self.disk_over_commit = disk_over_commit
     self.select_hosts_callback = select_hosts_callback
     self.source = instance['host']
     self.migrate_data = None
     self.compute_rpcapi = compute_rpcapi.ComputeAPI()
     self.servicegroup_api = servicegroup.API()
     self.image_service = glance.get_default_image_service()
示例#16
0
    def test_supports_numa_live_migration(self):
        mock_client = mock.MagicMock()
        rpcapi = compute_rpcapi.ComputeAPI()
        rpcapi.router.client = mock.Mock()
        rpcapi.router.client.return_value = mock_client

        ctxt = context.RequestContext('fake_user', 'fake_project'),
        mock_client.can_send_version.return_value = False
        self.assertFalse(rpcapi.supports_numa_live_migration(ctxt))
        mock_client.can_send_version.return_value = True
        self.assertTrue(rpcapi.supports_numa_live_migration(ctxt))
        mock_client.can_send_version.assert_has_calls(
            [mock.call('5.3'), mock.call('5.3')])
示例#17
0
 def test_prep_snapshot_based_resize_at_source_old_compute(
         self, mock_client):
     """Tests when the source compute service is too old to call
     prep_snapshot_based_resize_at_source so MigrationError is raised.
     """
     mock_client.return_value.can_send_version.return_value = False
     rpcapi = compute_rpcapi.ComputeAPI()
     ex = self.assertRaises(exception.MigrationError,
                            rpcapi.prep_snapshot_based_resize_at_source,
                            self.context,
                            instance=self.fake_instance_obj,
                            migration=migration_obj.Migration(),
                            snapshot_id=uuids.snapshot_id)
     self.assertIn('Compute too old', six.text_type(ex))
示例#18
0
    def test_find_destination_works_with_no_request_spec(self):
        task = live_migrate.LiveMigrationTask(
            self.context,
            self.instance,
            self.destination,
            self.block_migration,
            self.disk_over_commit,
            self.migration,
            compute_rpcapi.ComputeAPI(),
            servicegroup.API(),
            scheduler_client.SchedulerClient(),
            request_spec=None)
        another_spec = objects.RequestSpec()
        self.instance.flavor = objects.Flavor()
        self.instance.numa_topology = None
        self.instance.pci_requests = None

        @mock.patch('nova.objects.Instance.is_volume_backed')
        @mock.patch.object(task, '_call_livem_checks_on_host')
        @mock.patch.object(task, '_check_compatible_with_source_hypervisor')
        @mock.patch.object(task.scheduler_client, 'select_destinations')
        @mock.patch.object(objects.RequestSpec, 'from_components')
        @mock.patch.object(scheduler_utils, 'setup_instance_group')
        @mock.patch.object(utils, 'get_image_from_system_metadata')
        def do_test(get_image, setup_ig, from_components, select_dest,
                    check_compat, call_livem_checks, is_volume_backed):
            get_image.return_value = "image"
            from_components.return_value = another_spec
            select_dest.return_value = [{
                'host': 'host1',
                'nodename': 'node1',
                'limits': 'fake-limits'
            }]
            is_volume_backed.return_value = False

            self.assertEqual(("host1", 'fake-limits'),
                             task._find_destination())

            get_image.assert_called_once_with(self.instance.system_metadata)
            setup_ig.assert_called_once_with(self.context, another_spec)
            select_dest.assert_called_once_with(self.context, another_spec,
                                                [self.instance.uuid])
            # Make sure the request_spec was updated to include the cell
            # mapping.
            self.assertIsNotNone(another_spec.requested_destination.cell)
            check_compat.assert_called_once_with("host1")
            call_livem_checks.assert_called_once_with("host1",
                                                      limits='fake-limits')

        do_test()
示例#19
0
 def __init__(self, context, instance, destination, block_migration,
              disk_over_commit, pclm):
     self.context = context
     self.instance = instance
     self.destination = destination
     self.block_migration = block_migration
     self.disk_over_commit = disk_over_commit
     self.source = instance.host
     self.migrate_data = None
     self.compute_rpcapi = compute_rpcapi.ComputeAPI()
     self.servicegroup_api = servicegroup.API()
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
     self.image_service = glance.get_default_image_service()
     self.pclm = pclm
示例#20
0
    def test_find_destination_works_with_no_request_spec(self):
        task = live_migrate.LiveMigrationTask(
            self.context,
            self.instance,
            self.destination,
            self.block_migration,
            self.disk_over_commit,
            self.migration,
            compute_rpcapi.ComputeAPI(),
            servicegroup.API(),
            scheduler_client.SchedulerClient(),
            request_spec=None)
        another_spec = objects.RequestSpec()
        self.instance.flavor = objects.Flavor()
        self.instance.numa_topology = None
        self.instance.pci_requests = None

        @mock.patch.object(task, '_call_livem_checks_on_host')
        @mock.patch.object(task, '_check_compatible_with_source_hypervisor')
        @mock.patch.object(task.scheduler_client, 'select_destinations')
        @mock.patch.object(objects.RequestSpec, 'from_components')
        @mock.patch.object(scheduler_utils, 'setup_instance_group')
        @mock.patch.object(utils, 'get_image_from_system_metadata')
        def do_test(get_image, setup_ig, from_components, select_dest,
                    check_compat, call_livem_checks):
            get_image.return_value = "image"
            from_components.return_value = another_spec
            select_dest.return_value = [[fake_selection1]]

            self.assertEqual(("host1", "node1"), task._find_destination())

            get_image.assert_called_once_with(self.instance.system_metadata)
            setup_ig.assert_called_once_with(self.context, another_spec)
            self.ensure_network_metadata_mock.assert_called_once_with(
                self.instance)
            self.heal_reqspec_is_bfv_mock.assert_called_once_with(
                self.context, another_spec, self.instance)
            select_dest.assert_called_once_with(self.context,
                                                another_spec,
                                                [self.instance.uuid],
                                                return_objects=True,
                                                return_alternates=False)
            # Make sure the request_spec was updated to include the cell
            # mapping.
            self.assertIsNotNone(another_spec.requested_destination.cell)
            check_compat.assert_called_once_with("host1")
            call_livem_checks.assert_called_once_with("host1")

        do_test()
示例#21
0
 def test_finish_snapshot_based_resize_at_dest_old_compute(self, client):
     """Tests when the dest compute service is too old to call
     finish_snapshot_based_resize_at_dest so MigrationError is raised.
     """
     client.return_value.can_send_version.return_value = False
     rpcapi = compute_rpcapi.ComputeAPI()
     ex = self.assertRaises(
         exception.MigrationError,
         rpcapi.finish_snapshot_based_resize_at_dest,
         self.context,
         instance=self.fake_instance_obj,
         migration=migration_obj.Migration(dest_compute='dest'),
         snapshot_id=uuids.snapshot_id,
         request_spec=objects.RequestSpec())
     self.assertIn('Compute too old', str(ex))
示例#22
0
    def _test_simple_call(self, method, inargs, callargs, callret,
                               calltype='call', can_send=False):
        rpc = compute_rpcapi.ComputeAPI()

        @mock.patch.object(rpc, 'client')
        @mock.patch.object(compute_rpcapi, '_compute_host')
        def _test(mock_ch, mock_client):
            mock_client.can_send_version.return_value = can_send
            call = getattr(mock_client.prepare.return_value, calltype)
            call.return_value = callret
            ctxt = mock.MagicMock()
            result = getattr(rpc, method)(ctxt, **inargs)
            call.assert_called_once_with(ctxt, method, **callargs)
            return result

        return _test()
示例#23
0
 def test_prep_snapshot_based_resize_at_dest_old_compute(self, mock_client):
     """Tests when the destination compute service is too old to call
     prep_snapshot_based_resize_at_dest so MigrationPreCheckError is
     raised.
     """
     mock_client.return_value.can_send_version.return_value = False
     rpcapi = compute_rpcapi.ComputeAPI()
     ex = self.assertRaises(exception.MigrationPreCheckError,
                            rpcapi.prep_snapshot_based_resize_at_dest,
                            self.context,
                            instance=self.fake_instance_obj,
                            flavor=self.fake_flavor_obj,
                            nodename='node',
                            migration=migration_obj.Migration(),
                            limits={},
                            request_spec=objects.RequestSpec(),
                            destination='dest')
     self.assertIn('Compute too old', six.text_type(ex))
示例#24
0
    def test_execute_reschedule(self, mock_elevated, mock_claim,
                                mock_fill_provider_mapping):
        report_client = report.SchedulerReportClient()
        # setup task for re-schedule
        alloc_req = {
            "allocations": {
                uuids.host1: {
                    "resources": {
                        "VCPU": 1,
                        "MEMORY_MB": 1024,
                        "DISK_GB": 100
                    }
                }
            }
        }
        alternate_selection = objects.Selection(
            service_host="host1",
            nodename="node1",
            cell_uuid=uuids.cell1,
            allocation_request=jsonutils.dumps(alloc_req),
            allocation_request_version='1.19')
        task = migrate.MigrationTask(self.context,
                                     self.instance,
                                     self.flavor,
                                     self.request_spec,
                                     self.clean_shutdown,
                                     compute_rpcapi.ComputeAPI(),
                                     query.SchedulerQueryClient(),
                                     report_client,
                                     host_list=[alternate_selection],
                                     network_api=self.mock_network_api)
        mock_claim.return_value = True

        actual_selection = task._reschedule()

        self.assertIs(alternate_selection, actual_selection)
        mock_claim.assert_called_once_with(mock_elevated.return_value,
                                           report_client, self.request_spec,
                                           self.instance.uuid, alloc_req,
                                           '1.19')
        mock_fill_provider_mapping.assert_called_once_with(
            self.context, report_client, self.request_spec,
            alternate_selection)
示例#25
0
 def test_live_migration_force_complete(self):
     migration = migration_obj.Migration()
     migration.id = 1
     migration.source_compute = 'fake'
     ctxt = context.RequestContext('fake_user', 'fake_project')
     version = '4.12'
     rpcapi = compute_rpcapi.ComputeAPI()
     mock_client = mock.MagicMock()
     rpcapi.client = mock_client
     mock_client.can_send_version.return_value = True
     mock_cctx = mock.MagicMock()
     mock_client.prepare.return_value = mock_cctx
     rpcapi.live_migration_force_complete(ctxt, self.fake_instance_obj,
                                          migration)
     mock_client.prepare.assert_called_with(server=migration.source_compute,
                                            version=version)
     mock_cctx.cast.assert_called_with(ctxt,
                                       'live_migration_force_complete',
                                       instance=self.fake_instance_obj)
示例#26
0
    def test_find_destination_works_with_no_request_spec(self):
        task = live_migrate.LiveMigrationTask(
            self.context,
            self.instance,
            self.destination,
            self.block_migration,
            self.disk_over_commit,
            self.migration,
            compute_rpcapi.ComputeAPI(),
            servicegroup.API(),
            scheduler_client.SchedulerClient(),
            request_spec=None)
        another_spec = objects.RequestSpec()
        self.instance.flavor = objects.Flavor()
        self.instance.numa_topology = None
        self.instance.pci_requests = None

        @mock.patch.object(task, '_call_livem_checks_on_host')
        @mock.patch.object(task, '_check_compatible_with_source_hypervisor')
        @mock.patch.object(task.scheduler_client, 'select_destinations')
        @mock.patch.object(objects.RequestSpec, 'from_components')
        @mock.patch.object(scheduler_utils, 'setup_instance_group')
        @mock.patch.object(utils, 'get_image_from_system_metadata')
        def do_test(get_image, setup_ig, from_components, select_dest,
                    check_compat, call_livem_checks):
            get_image.return_value = "image"
            from_components.return_value = another_spec
            select_dest.return_value = [{'host': 'host1'}]

            self.assertEqual("host1", task._find_destination())

            get_image.assert_called_once_with(self.instance.system_metadata)
            fake_props = {'instance_properties': {'uuid': self.instance_uuid}}
            setup_ig.assert_called_once_with(
                self.context, fake_props,
                {'ignore_hosts': [self.instance_host]})
            select_dest.assert_called_once_with(self.context, another_spec,
                                                [self.instance.uuid])
            check_compat.assert_called_once_with("host1")
            call_livem_checks.assert_called_once_with("host1")

        do_test()
示例#27
0
 def test_version_cap_all_cells_no_access(self, mock_allcells, mock_minver,
                                          mock_log_error):
     """Tests a scenario where nova-compute is configured with a connection
     to the API database and fails trying to get the minium nova-compute
     service version across all cells because nova-compute is configured to
     not allow direct database access.
     """
     self.flags(connection='sqlite:///', group='api_database')
     self.assertRaises(exception.DBNotAllowed,
                       compute_rpcapi.ComputeAPI()._determine_version_cap,
                       mock.Mock())
     mock_allcells.assert_called_once_with(mock.ANY, ['nova-compute'])
     mock_minver.assert_not_called()
     # Make sure the expected error was logged.
     mock_log_error.assert_called_once_with(
         'This service is configured for access to the '
         'API database but is not allowed to directly '
         'access the database. You should run this '
         'service without the [api_database]/connection '
         'config option.')
示例#28
0
 def test_reserve_block_device_name_raises(self):
     ctxt = context.RequestContext('fake_user', 'fake_project')
     instance = self.fake_instance_obj
     rpcapi = compute_rpcapi.ComputeAPI()
     cctxt_mock = mock.Mock()
     mock_client = mock.Mock()
     rpcapi.router.client = mock.Mock()
     rpcapi.router.client.return_value = mock_client
     with test.nested(
         mock.patch.object(mock_client, 'can_send_version',
                           return_value=False),
         mock.patch.object(mock_client, 'prepare',
                           return_value=cctxt_mock)
     ) as (
         can_send_mock, prepare_mock
     ):
         self.assertRaises(exception.TaggedAttachmentNotSupported,
                           rpcapi.reserve_block_device_name, ctxt, instance,
                           'fake_device', 'fake_volume_id', tag='foo')
     can_send_mock.assert_called_once_with('4.15')
示例#29
0
 def test_swap_volume_cannot_send_version_4_17(self):
     """Tests that if the RPC client cannot send version 4.17 we drop back
     to version 4.0 and don't send the new_attachment_id kwarg.
     """
     rpcapi = compute_rpcapi.ComputeAPI()
     fake_context = mock.Mock()
     fake_client = mock.Mock()
     fake_client.can_send_version.return_value = False
     fake_client.prepare.return_value = fake_context
     with mock.patch.object(rpcapi.router, 'client',
                            return_value=fake_client):
         rpcapi.swap_volume(self.context, self.fake_instance_obj,
                            uuids.old_volume_id, uuids.new_volume_id,
                            uuids.new_attachment_id)
         fake_client.prepare.assert_called_once_with(
             server=self.fake_instance_obj.host, version='4.0')
         fake_context.cast.assert_called_once_with(
             self.context, 'swap_volume', instance=self.fake_instance_obj,
             old_volume_id=uuids.old_volume_id,
             new_volume_id=uuids.new_volume_id)
示例#30
0
    def test_unshelve_instance_old_compute(self):
        ctxt = context.RequestContext('fake_user', 'fake_project')
        rpcapi = compute_rpcapi.ComputeAPI()
        rpcapi.router.client = mock.Mock()
        mock_client = mock.MagicMock()
        rpcapi.router.client.return_value = mock_client
        # So we expect that the messages is backported therefore the
        # request_spec is dropped
        mock_client.can_send_version.return_value = False
        mock_cctx = mock.MagicMock()
        mock_client.prepare.return_value = mock_cctx
        rpcapi.unshelve_instance(
            ctxt, instance=self.fake_instance_obj,
            host='host', request_spec=self.fake_request_spec_obj,
            image='image')

        mock_client.can_send_version.assert_called_once_with('5.2')
        mock_client.prepare.assert_called_with(
            server='host', version='5.0')
        mock_cctx.cast.assert_called_with(
            ctxt, 'unshelve_instance', instance=self.fake_instance_obj,
            image='image', filter_properties=None, node=None)