def setUp(self): super(TestListServersIpFilter, self).setUp() self.useFixture(policy_fixture.RealPolicyFixture()) self.neutron = self.useFixture( nova_fixtures.NeutronFixture(self, multiple_ports=True)) api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) self.api = api_fixture.api # the image fake backend needed for image discovery nova.tests.unit.image.fake.stub_out_image_service(self) self.useFixture(nova_fixtures.PlacementFixture()) self.start_service('conductor') self.flags(enabled_filters=['ComputeFilter'], group='filter_scheduler') self.start_service('scheduler') self.start_service('compute') self.start_service('consoleauth') self.useFixture(cast_as_call.CastAsCall(self)) self.useFixture(nova_fixtures.PlacementFixture()) self.image_id = self.api.get_images()[0]['id'] self.flavor_id = self.api.get_flavors()[0]['id']
def test_local_delete_removes_allocations_after_compute_restart(self): """Tests that allocations are removed after a local delete. This tests the scenario where a server is local deleted (because the compute host is down) and we want to make sure that its allocations have been cleaned up once the nova-compute service restarts. In this scenario we conditionally use the PlacementFixture to simulate the case that nova-api isn't configured to talk to placement. """ # Get allocations, make sure they are 0. with nova_fixtures.PlacementFixture() as placement: compute = self.start_service('compute') placement_api = placement.api resp = placement_api.get('/resource_providers') rp_uuid = resp.body['resource_providers'][0]['uuid'] usages_before = self._get_usages(placement_api, rp_uuid) for usage in usages_before.values(): self.assertEqual(0, usage) # Create a server. server = self._build_minimal_create_server_request( self.api, 'local-delete-test', self.image_id, self.flavor_id, 'none') server = self.admin_api.post_server({'server': server}) server = self._wait_for_state_change(self.api, server, 'ACTIVE') # Assert usages are non zero now. usages_during = self._get_usages(placement_api, rp_uuid) for usage in usages_during.values(): self.assertNotEqual(0, usage) # Force-down compute to trigger local delete. compute.stop() compute_service_id = self.admin_api.get_services( host=compute.host, binary='nova-compute')[0]['id'] self.admin_api.put_service(compute_service_id, {'forced_down': True}) # Delete the server (will be a local delete because compute is down). self.api.delete_server(server['id']) self._wait_until_deleted(server) with nova_fixtures.PlacementFixture() as placement: placement_api = placement.api # Assert usages are still non-zero. usages_during = self._get_usages(placement_api, rp_uuid) for usage in usages_during.values(): self.assertNotEqual(0, usage) # Start the compute service again. Before it comes up, it will # call the update_available_resource code in the ResourceTracker # which is what "heals" the allocations for the deleted instance. compute.start() # Get the allocations again to check against the original. usages_after = self._get_usages(placement_api, rp_uuid) # They should match. self.assertEqual(usages_before, usages_after)
def setUp(self): super(_LibvirtEvacuateTest, self).setUp() self.useFixture(nova_fixtures.NeutronFixture(self)) fake_network.set_stub_network_methods(self) self.useFixture(nova_fixtures.PlacementFixture()) api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) self.api = api_fixture.admin_api # force_down and evacuate without onSharedStorage self.api.microversion = '2.14' fake_image.stub_out_image_service(self) self.addCleanup(fake_image.FakeImageService_reset) fake_notifier.stub_notifier(self) self.addCleanup(fake_notifier.reset) self.useFixture(fakelibvirt.FakeLibvirtFixture()) self.start_service('conductor') self.start_service('scheduler') self.flags(compute_driver='libvirt.LibvirtDriver') self.compute0 = self._start_compute('compute0') # Choice of image id and flavor are arbitrary. Fixed for consistency. self.image_id = fake_image.AUTO_DISK_CONFIG_ENABLED_IMAGE_UUID self.flavor_id = next(flavor for flavor in self.api.get_flavors() if flavor['name'] == 'm1.tiny')['id']
def setUp(self): super(NotificationSampleTestBase, self).setUp() api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) self.api = api_fixture.api self.admin_api = api_fixture.admin_api max_version = self.MAX_MICROVERSION self.api.microversion = max_version self.admin_api.microversion = max_version fake_notifier.stub_notifier(self) self.addCleanup(fake_notifier.reset) self.useFixture(utils_fixture.TimeFixture(test_services.fake_utcnow())) # the image fake backend needed for image discovery nova.tests.unit.image.fake.stub_out_image_service(self) self.addCleanup(nova.tests.unit.image.fake.FakeImageService_reset) self.useFixture(nova_fixtures.PlacementFixture()) context_patcher = self.mock_gen_request_id = mock.patch( 'oslo_context.context.generate_request_id', return_value='req-5b6c791d-5709-4f36-8fbe-c3e02869e35d') self.mock_gen_request_id = context_patcher.start() self.addCleanup(context_patcher.stop) self.start_service('conductor') self.start_service('scheduler') self.start_service('network', manager=CONF.network_manager) self.compute = self.start_service('compute') # Reset the service create notifications fake_notifier.reset()
def setUp(self): super(TestResizeWithCachingScheduler, self).setUp() self.useFixture(policy_fixture.RealPolicyFixture()) self.useFixture(nova_fixtures.NeutronFixture(self)) self.useFixture(nova_fixtures.PlacementFixture()) api_fixture = self.useFixture(nova_fixtures.OSAPIFixture( api_version='v2.1')) self.api = api_fixture.admin_api self.api.microversion = self.microversion nova.tests.unit.image.fake.stub_out_image_service(self) self.addCleanup(nova.tests.unit.image.fake.FakeImageService_reset) self.start_service('conductor') # Configure the CachingScheduler. self.flags(driver='caching_scheduler', group='scheduler') self.start_service('scheduler') # Create two compute nodes/services. for host in ('host1', 'host2'): fake.set_nodes([host]) self.addCleanup(fake.restore_nodes) self.start_service('compute', host=host) flavors = self.api.get_flavors() self.old_flavor = flavors[0] self.new_flavor = flavors[1]
def setUp(self): super(ColdMigrateTargetHostThenLiveMigrateTest, self).setUp() self.useFixture(policy_fixture.RealPolicyFixture()) self.useFixture(nova_fixtures.NeutronFixture(self)) self.useFixture(nova_fixtures.PlacementFixture()) api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) # The admin API is used to get the server details to verify the # host on which the server was built and cold/live migrate it. self.admin_api = api_fixture.admin_api self.api = api_fixture.api # Use the latest microversion available to make sure something does # not regress in new microversions; cap as necessary. self.admin_api.microversion = 'latest' self.api.microversion = 'latest' image_fake.stub_out_image_service(self) self.addCleanup(image_fake.FakeImageService_reset) self.start_service('conductor') self.start_service('scheduler') for host in ('host1', 'host2'): fake.set_nodes([host]) self.addCleanup(fake.restore_nodes) self.start_service('compute', host=host)
def setUp(self): super(NotificationSampleTestBase, self).setUp() api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) self.api = api_fixture.api self.admin_api = api_fixture.admin_api max_version = self.MAX_MICROVERSION self.api.microversion = max_version self.admin_api.microversion = max_version fake_notifier.stub_notifier(self) self.addCleanup(fake_notifier.reset) self.useFixture(utils_fixture.TimeFixture(test_services.fake_utcnow())) # the image fake backend needed for image discovery nova.tests.unit.image.fake.stub_out_image_service(self) self.addCleanup(nova.tests.unit.image.fake.FakeImageService_reset) self.useFixture(nova_fixtures.PlacementFixture()) self.start_service('conductor') self.start_service('scheduler') self.start_service('network', manager=CONF.network_manager) self.compute = self.start_service('compute')
def setUp(self): super(FailedEvacuateStateTests, self).setUp() self.useFixture(policy_fixture.RealPolicyFixture()) self.useFixture(nova_fixtures.NeutronFixture(self)) self.useFixture(nova_fixtures.PlacementFixture()) api_fixture = self.useFixture(nova_fixtures.OSAPIFixture( api_version='v2.1')) self.api = api_fixture.admin_api self.api.microversion = self.microversion nova.tests.unit.image.fake.stub_out_image_service(self) self.start_service('conductor') self.start_service('scheduler') self.addCleanup(nova.tests.unit.image.fake.FakeImageService_reset) self.hostname = 'host1' self.compute1 = self.start_service('compute', host=self.hostname) fake_network.set_stub_network_methods(self) flavors = self.api.get_flavors() self.flavor1 = flavors[0]
def setUp(self): white_list = ['{"vendor_id":"8086","product_id":"1528"}', '{"vendor_id":"8086","product_id":"1515"}'] self.flags(passthrough_whitelist=white_list, group='pci') # PFs will be removed from pools, unless these has been specifically # requested. This is especially needed in cases where PFs and VFs have # the same vendor/product id pci_alias = ['{"vendor_id":"8086", "product_id":"1528", "name":"%s",' ' "device_type":"%s"}' % (self.pfs_alias_name, fields.PciDeviceType.SRIOV_PF), '{"vendor_id":"8086", "product_id":"1515", "name":"%s"}' % self.vfs_alias_name] self.flags(alias=pci_alias, group='pci') super(SRIOVServersTest, self).setUp() # Replace libvirt with fakelibvirt self.useFixture(fixtures.MonkeyPatch( 'nova.virt.libvirt.driver.libvirt_utils', fake_libvirt_utils)) self.useFixture(fixtures.MonkeyPatch( 'nova.virt.libvirt.driver.libvirt', fakelibvirt)) self.useFixture(fixtures.MonkeyPatch( 'nova.virt.libvirt.host.libvirt', fakelibvirt)) self.useFixture(fixtures.MonkeyPatch( 'nova.virt.libvirt.guest.libvirt', fakelibvirt)) self.useFixture(fakelibvirt.FakeLibvirtFixture()) self.useFixture(nova_fixtures.PlacementFixture()) self.compute_started = False
def setUp(self): super(TestLocalDeleteAttachedVolumes, self).setUp() self.useFixture(policy_fixture.RealPolicyFixture()) # We need the CinderFixture to stub out the volume API. self.cinder = self.useFixture(nova_fixtures.CinderFixture(self)) # The NeutronFixture is needed to stub out validate_networks in API. self.useFixture(nova_fixtures.NeutronFixture(self)) # Use the PlacementFixture to avoid annoying warnings in the logs. self.useFixture(nova_fixtures.PlacementFixture()) api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) self.api = api_fixture.api # We want to use 2.37 for passing networks='none' on server create. # We also need this since you can only attach a volume to a # shelved-offloaded server in microversion 2.20+. self.api.microversion = 'latest' # the image fake backend needed for image discovery nova.tests.unit.image.fake.stub_out_image_service(self) self.start_service('conductor') self.start_service('scheduler') self.start_service('compute') # The consoleauth service is needed for deleting console tokens. self.start_service('consoleauth') self.useFixture(cast_as_call.CastAsCall(self)) self.flavor_id = self.api.get_flavors()[0]['id']
def setUp(self): super(TestAvailabilityZoneScheduling, self).setUp() self.useFixture(policy_fixture.RealPolicyFixture()) self.useFixture(nova_fixtures.NeutronFixture(self)) self.useFixture(nova_fixtures.PlacementFixture()) api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) self.api = api_fixture.admin_api self.api.microversion = 'latest' fake_image.stub_out_image_service(self) self.addCleanup(fake_image.FakeImageService_reset) self.start_service('conductor') self.start_service('scheduler') # Start two compute services in separate zones. self._start_host_in_zone('host1', 'zone1') self._start_host_in_zone('host2', 'zone2') flavors = self.api.get_flavors() self.flavor1 = flavors[0]['id'] self.flavor2 = flavors[1]['id']
def setUp(self): super(ServerGroupTestBase, self).setUp() self.flags(enabled_filters=self._enabled_filters, group='filter_scheduler') # NOTE(sbauza): Don't verify VCPUS and disks given the current nodes. self.flags(cpu_allocation_ratio=9999.0) self.flags(disk_allocation_ratio=9999.0) self.flags(weight_classes=self._get_weight_classes(), group='filter_scheduler') self.flags(service_down_time=self._service_down_time) self.flags(report_interval=self._report_interval) self.useFixture(policy_fixture.RealPolicyFixture()) self.useFixture(nova_fixtures.NeutronFixture(self)) self.useFixture(nova_fixtures.PlacementFixture()) api_fixture = self.useFixture(nova_fixtures.OSAPIFixture( api_version='v2.1')) self.api = api_fixture.api self.api.microversion = self.microversion self.admin_api = api_fixture.admin_api self.admin_api.microversion = self.microversion # the image fake backend needed for image discovery nova.tests.unit.image.fake.stub_out_image_service(self) self.start_service('conductor') self.start_service('scheduler') self.addCleanup(nova.tests.unit.image.fake.FakeImageService_reset)
def setUp(self): super(NotificationSampleTestBase, self).setUp() api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) self.api = api_fixture.api self.admin_api = api_fixture.admin_api # NOTE(gibi): Notification payloads always reflect the data needed # for every supported API microversion so we can safe to use the latest # API version in the tests. This helps the test to use the new API # features too. max_version = 'latest' self.api.microversion = max_version self.admin_api.microversion = max_version fake_notifier.stub_notifier(self) self.addCleanup(fake_notifier.reset) self.useFixture(utils_fixture.TimeFixture(test_services.fake_utcnow())) self.flags(driver='chance_scheduler', group='scheduler') # the image fake backend needed for image discovery nova.tests.unit.image.fake.stub_out_image_service(self) self.addCleanup(nova.tests.unit.image.fake.FakeImageService_reset) self.useFixture(nova_fixtures.PlacementFixture()) self.start_service('conductor') self.start_service('scheduler') self.start_service('network', manager=CONF.network_manager) self.compute = self.start_service('compute')
def setUp(self): self.flags(compute_driver=self.compute_driver) super(ProviderUsageBaseTestCase, self).setUp() self.useFixture(policy_fixture.RealPolicyFixture()) self.useFixture(nova_fixtures.NeutronFixture(self)) self.useFixture(nova_fixtures.AllServicesCurrent()) placement = self.useFixture(nova_fixtures.PlacementFixture()) self.placement_api = placement.api api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) self.admin_api = api_fixture.admin_api self.admin_api.microversion = self.microversion self.api = self.admin_api # the image fake backend needed for image discovery nova.tests.unit.image.fake.stub_out_image_service(self) self.start_service('conductor') self.scheduler_service = self.start_service('scheduler') self.addCleanup(nova.tests.unit.image.fake.FakeImageService_reset) self.computes = {}
def setUp(self): super(ServersTestBase, self).setUp() # Replace libvirt with fakelibvirt self.useFixture(fake_imagebackend.ImageBackendFixture()) self.useFixture(fixtures.MonkeyPatch( 'nova.virt.libvirt.driver.libvirt_utils', fake_libvirt_utils)) self.useFixture(fixtures.MonkeyPatch( 'nova.virt.libvirt.driver.libvirt', fakelibvirt)) self.useFixture(fixtures.MonkeyPatch( 'nova.virt.libvirt.host.libvirt', fakelibvirt)) self.useFixture(fixtures.MonkeyPatch( 'nova.virt.libvirt.guest.libvirt', fakelibvirt)) self.useFixture(fakelibvirt.FakeLibvirtFixture()) self.useFixture(nova_fixtures.PlacementFixture()) # Mock the 'get_connection' function, as we're going to need to provide # custom capabilities for each test _p = mock.patch('nova.virt.libvirt.host.Host.get_connection') self.mock_conn = _p.start() self.addCleanup(_p.stop)
def setUp(self): super(TestEvacuationWithSourceReturningDuringRebuild, self).setUp() self.useFixture(policy_fixture.RealPolicyFixture()) # The NeutronFixture is needed to stub out validate_networks in API. self.useFixture(nova_fixtures.NeutronFixture(self)) # This stubs out the network allocation in compute. fake_network.set_stub_network_methods(self) # We need the computes reporting into placement for the filter # scheduler to pick a host. self.useFixture(nova_fixtures.PlacementFixture()) api_fixture = self.useFixture(nova_fixtures.OSAPIFixture( api_version='v2.1')) self.api = api_fixture.admin_api # 2.11 is needed for force_down # 2.14 is needed for evacuate without onSharedStorage flag self.api.microversion = '2.14' # the image fake backend needed for image discovery nova.tests.unit.image.fake.stub_out_image_service(self) self.addCleanup(nova.tests.unit.image.fake.FakeImageService_reset) self.start_service('conductor') self.start_service('scheduler') # Start two computes self.computes = {} fake.set_nodes(['host1']) self.addCleanup(fake.restore_nodes) self.computes['host1'] = self.start_service('compute', host='host1') fake.set_nodes(['host2']) self.addCleanup(fake.restore_nodes) self.computes['host2'] = self.start_service('compute', host='host2') self.image_id = self.api.get_images()[0]['id'] self.flavor_id = self.api.get_flavors()[0]['id'] self.addCleanup(fake_notifier.reset) # Stub out rebuild with a slower method allowing the src compute to be # restarted once the migration hits pre-migrating after claiming # resources on the dest. manager_class = nova.compute.manager.ComputeManager original_rebuild = manager_class._do_rebuild_instance def start_src_rebuild(self_, context, instance, *args, **kwargs): server = self.api.get_server(instance.uuid) # Start the src compute once the migration is pre-migrating. self._wait_for_migration_status(server, ['pre-migrating']) self.computes.get(self.source_compute).start() original_rebuild(self_, context, instance, *args, **kwargs) self.stub_out('nova.compute.manager.ComputeManager.' '_do_rebuild_instance', start_src_rebuild)
def setUp(self): super(MissingReqSpecInstanceGroupUUIDTestCase, self).setUp() # Stub out external dependencies. self.useFixture(nova_fixtures.NeutronFixture(self)) self.useFixture(nova_fixtures.PlacementFixture()) fake_image.stub_out_image_service(self) self.addCleanup(fake_image.FakeImageService_reset) # Configure the API to allow resizing to the same host so we can keep # the number of computes down to two in the test. self.flags(allow_resize_to_same_host=True) # Start nova controller services. api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) self.api = api_fixture.admin_api self.start_service('conductor') # Use our custom weigher defined above to make sure that we have # a predictable scheduling sort order. self.flags(weight_classes=[__name__ + '.HostNameWeigher'], group='filter_scheduler') self.start_service('scheduler') # Start two computes, one where the server will be created and another # where we'll cold migrate it. self.addCleanup(fake_virt.restore_nodes) self.computes = {} # keep track of the compute services per host name for host in ('host1', 'host2'): fake_virt.set_nodes([host]) compute_service = self.start_service('compute', host=host) self.computes[host] = compute_service
def setUp(self): super(TestListServersIpFilter, self).setUp() self.useFixture(policy_fixture.RealPolicyFixture()) self.neutron = self.useFixture( nova_fixtures.NeutronFixture(self, multiple_ports=True)) api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) self.api = api_fixture.api # the image fake backend needed for image discovery nova.tests.unit.image.fake.stub_out_image_service(self) self.start_service('conductor') # Use the chance scheduler to bypass filtering and just pick the single # compute host that we have. self.flags(driver='chance_scheduler', group='scheduler') self.start_service('scheduler') self.start_service('compute') self.start_service('consoleauth') self.useFixture(cast_as_call.CastAsCall(self.stubs)) self.useFixture(nova_fixtures.PlacementFixture()) self.image_id = self.api.get_images()[0]['id'] self.flavor_id = self.api.get_flavors()[0]['id']
def setUp(self): super(InstanceListWithDeletedServicesTestCase, self).setUp() self.useFixture(policy_fixture.RealPolicyFixture()) # The NeutronFixture is needed to stub out validate_networks in API. self.useFixture(nova_fixtures.NeutronFixture(self)) # We need the computes reporting into placement for the filter # scheduler to pick a host. self.useFixture(nova_fixtures.PlacementFixture()) api_fixture = self.useFixture(nova_fixtures.OSAPIFixture( api_version='v2.1')) self.api = api_fixture.api self.admin_api = api_fixture.admin_api self.admin_api.microversion = 'latest' # the image fake backend needed for image discovery fake_image.stub_out_image_service(self) self.addCleanup(fake_image.FakeImageService_reset) # Get the image before we set the microversion to latest to avoid # the proxy issues with GET /images in 2.36. self.image_id = self.api.get_images()[0]['id'] self.api.microversion = 'latest' self.start_service('conductor') self.start_service('scheduler')
def test_create_volume_backed_server_with_zero_disk_allowed(self): """Tests that creating a volume-backed server with a zero-root disk flavor will be allowed for admins. """ # For this test, we want to start conductor and the scheduler but # we don't start compute so that scheduling fails; we don't really # care about successfully building an active server here. self.useFixture(nova_fixtures.PlacementFixture()) self.useFixture(nova_fixtures.CinderFixture(self)) self.start_service('conductor') self.start_service('scheduler') server_req = self._build_minimal_create_server_request( self.api, 'test_create_volume_backed_server_with_zero_disk_allowed', flavor_id=self.zero_disk_flavor['id']) server_req.pop('imageRef', None) server_req['block_device_mapping_v2'] = [{ 'uuid': nova_fixtures.CinderFixture.IMAGE_BACKED_VOL, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0 }] server = self.admin_api.post_server({'server': server_req}) server = self._wait_for_state_change(self.api, server, 'ERROR') self.assertIn('No valid host', server['fault']['message'])
def setUp(self): super(TestResizeWithNoAllocationScheduler, self).setUp() self.useFixture(policy_fixture.RealPolicyFixture()) self.useFixture(nova_fixtures.NeutronFixture(self)) self.useFixture(nova_fixtures.PlacementFixture()) api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) self.api = api_fixture.admin_api self.api.microversion = self.microversion nova.tests.unit.image.fake.stub_out_image_service(self) self.addCleanup(nova.tests.unit.image.fake.FakeImageService_reset) self.start_service('conductor') # Create two compute nodes/services. for host in ('host1', 'host2'): fake.set_nodes([host]) self.addCleanup(fake.restore_nodes) self.start_service('compute', host=host) scheduler_service = self.start_service('scheduler') # We need to mock the FilterScheduler to not use Placement so that # allocations won't be created during scheduling. scheduler_service.manager.driver.USES_ALLOCATION_CANDIDATES = False flavors = self.api.get_flavors() self.old_flavor = flavors[0] self.new_flavor = flavors[1]
def setUp(self): super(TestLocalDeleteAllocations, self).setUp() self.useFixture(policy_fixture.RealPolicyFixture()) # The NeutronFixture is needed to show security groups for a server. self.useFixture(nova_fixtures.NeutronFixture(self)) # We need the computes reporting into placement for the filter # scheduler to pick a host. placement = self.useFixture(nova_fixtures.PlacementFixture()) self.placement_api = placement.api api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) self.api = api_fixture.api self.admin_api = api_fixture.admin_api # We need the latest microversion to force-down the compute service self.admin_api.microversion = 'latest' # the image fake backend needed for image discovery nova.tests.unit.image.fake.stub_out_image_service(self) self.start_service('conductor') self.start_service('consoleauth') self.start_service('scheduler') self.compute = self.start_service('compute') self.useFixture(cast_as_call.CastAsCall(self)) self.image_id = self.api.get_images()[0]['id'] self.flavor_id = self.api.get_flavors()[0]['id']
def setUp(self): super(TestRescheduleWithServerGroup, self).setUp() self.useFixture(policy_fixture.RealPolicyFixture()) # The NeutronFixture is needed to stub out validate_networks in API. self.useFixture(nova_fixtures.NeutronFixture(self)) # This stubs out the network allocation in compute. fake_network.set_stub_network_methods(self) # We need the computes reporting into placement for the filter # scheduler to pick a host. self.useFixture(nova_fixtures.PlacementFixture()) api_fixture = self.useFixture(nova_fixtures.OSAPIFixture( api_version='v2.1')) self.api = api_fixture.api # The admin API is used to get the server details to verify the # host on which the server was built. self.admin_api = api_fixture.admin_api # the image fake backend needed for image discovery nova.tests.unit.image.fake.stub_out_image_service(self) self.addCleanup(nova.tests.unit.image.fake.FakeImageService_reset) self.start_service('conductor') self.start_service('scheduler') # We start two compute services because we're going to fake one raising # RescheduledException to trigger a retry to the other compute host. fake.set_nodes(['host1']) self.addCleanup(fake.restore_nodes) self.start_service('compute', host='host1') fake.set_nodes(['host2']) self.addCleanup(fake.restore_nodes) self.start_service('compute', host='host2') self.image_id = self.api.get_images()[0]['id'] self.flavor_id = self.api.get_flavors()[0]['id'] # This is our flag that we set when we hit the first host and # made it fail. self.failed_host = None self.attempts = 0 def fake_validate_instance_group_policy(_self, *args, **kwargs): self.attempts += 1 if self.failed_host is None: # Set the failed_host value to the ComputeManager.host value. self.failed_host = _self.host raise exception.RescheduledException(instance_uuid='fake', reason='Policy violated') self.stub_out('nova.compute.manager.ComputeManager.' '_validate_instance_group_policy', fake_validate_instance_group_policy)
def setUp(self): super(_IntegratedTestBase, self).setUp() # TODO(mriedem): Fix the functional tests to work with Neutron. self.flags(use_neutron=self.USE_NEUTRON) nova.tests.unit.image.fake.stub_out_image_service(self) self._setup_services() self.useFixture(cast_as_call.CastAsCall(self.stubs)) self.useFixture(nova_fixtures.PlacementFixture()) self.addCleanup(nova.tests.unit.image.fake.FakeImageService_reset)
def setUp(self): self.flags(compute_driver=self.compute_driver) super(AggregateRequestFiltersTest, self).setUp() self.useFixture(policy_fixture.RealPolicyFixture()) self.useFixture(nova_fixtures.NeutronFixture(self)) self.useFixture(nova_fixtures.AllServicesCurrent()) placement = self.useFixture(nova_fixtures.PlacementFixture()) self.placement_api = placement.api api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) self.admin_api = api_fixture.admin_api self.admin_api.microversion = self.microversion self.api = self.admin_api # the image fake backend needed for image discovery nova.tests.unit.image.fake.stub_out_image_service(self) self.start_service('conductor') self.scheduler_service = self.start_service('scheduler') self.computes = {} self.aggregates = {} self._start_compute('host1') self._start_compute('host2') self.context = nova_context.get_admin_context() self.report_client = report.SchedulerReportClient() self.flavors = self.api.get_flavors() # Aggregate with only host1 self._create_aggregate('only-host1') self._add_host_to_aggregate('only-host1', 'host1') # Aggregate with only host2 self._create_aggregate('only-host2') self._add_host_to_aggregate('only-host2', 'host2') # Aggregate with neither host self._create_aggregate('no-hosts') # Default to enabling the filter and making it mandatory self.flags(limit_tenants_to_placement_aggregate=True, group='scheduler') self.flags(placement_aggregate_required_for_tenants=True, group='scheduler')
def setUp(self): super(ServersPreSchedulingTestCase, self).setUp() fake_image.stub_out_image_service(self) self.useFixture(policy_fixture.RealPolicyFixture()) self.useFixture(nova_fixtures.NoopConductorFixture()) self.useFixture(nova_fixtures.NeutronFixture(self)) self.useFixture(nova_fixtures.PlacementFixture()) api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) self.api = api_fixture.api self.api.microversion = 'latest' self.useFixture( nova_fixtures.SingleCellSimple(instances_created=False))
def setUp(self): super(ServerTagsFilteringTest, self).setUp() self.useFixture(policy_fixture.RealPolicyFixture()) # The NeutronFixture is needed to stub out validate_networks in API. self.useFixture(nova_fixtures.NeutronFixture(self)) # Use the PlacementFixture to avoid annoying warnings in the logs. self.useFixture(nova_fixtures.PlacementFixture()) api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) self.api = api_fixture.api # the image fake backend needed for image discovery image_fake.stub_out_image_service(self) self.addCleanup(image_fake.FakeImageService_reset) # We have to get the image before we use 2.latest otherwise we'll get # a 404 on the /images proxy API because of 2.36. image_id = self.api.get_images()[0]['id'] # Use the latest microversion available to make sure something does # not regress in new microversions; cap as necessary. self.api.microversion = 'latest' self.start_service('conductor') self.flags(driver='chance_scheduler', group='scheduler') self.start_service('scheduler') self.start_service('compute') # The consoleauth service is needed for deleting console tokens when # the server is deleted. self.start_service('consoleauth') # create two test servers self.servers = [] for x in range(2): server = self.api.post_server( dict(server=self._build_minimal_create_server_request( self.api, 'test-list-server-tag-filters%i' % x, image_id, networks='none'))) self.addCleanup(self.api.delete_server, server['id']) server = self._wait_for_state_change(self.api, server, 'ACTIVE') self.servers.append(server) # now apply two tags to the first server self.two_tag_server = self.servers[0] self.api.put_server_tags(self.two_tag_server['id'], ['foo', 'bar']) # apply one tag to the second server which intersects with one tag # from the first server self.one_tag_server = self.servers[1] self.api.put_server_tags(self.one_tag_server['id'], ['foo'])
def setUp(self): super(TestRequestSpecRetryReschedule, self).setUp() self.useFixture(policy_fixture.RealPolicyFixture()) # The NeutronFixture is needed to stub out validate_networks in API. self.useFixture(nova_fixtures.NeutronFixture(self)) # We need the computes reporting into placement for the filter # scheduler to pick a host. self.useFixture(nova_fixtures.PlacementFixture()) api_fixture = self.useFixture(nova_fixtures.OSAPIFixture( api_version='v2.1')) # The admin API is used to get the server details to verify the # host on which the server was built. self.admin_api = api_fixture.admin_api self.api = api_fixture.api # the image fake backend needed for image discovery image_fake.stub_out_image_service(self) self.addCleanup(image_fake.FakeImageService_reset) self.start_service('conductor') # We have to get the image before we use 2.latest otherwise we'll get # a 404 on the /images proxy API because of 2.36. self.image_id = self.api.get_images()[0]['id'] # Use the latest microversion available to make sure something does # not regress in new microversions; cap as necessary. self.admin_api.microversion = 'latest' self.api.microversion = 'latest' # The consoleauth service is needed for deleting console tokens when # the server is deleted. self.start_service('consoleauth') # Use our custom weigher defined above to make sure that we have # a predictable scheduling sort order. self.flags(weight_classes=[__name__ + '.HostNameWeigher'], group='filter_scheduler') self.start_service('scheduler') # Let's now start three compute nodes as we said above. for host in ['host1', 'host2', 'host3']: fake.set_nodes([host]) self.addCleanup(fake.restore_nodes) self.start_service('compute', host=host)
def test_responds_to_version(self): """Ensure the Placement server responds to calls sensibly.""" placement_fixture = self.useFixture(fixtures.PlacementFixture()) # request the API root, which provides us the versions of the API resp = placement_fixture._fake_get(None, '/') self.assertEqual(200, resp.status_code) # request a known bad url, and we should get a 404 resp = placement_fixture._fake_get(None, '/foo') self.assertEqual(404, resp.status_code) # unsets the token so we fake missing it placement_fixture.token = None resp = placement_fixture._fake_get(None, '/foo') self.assertEqual(401, resp.status_code)
def setUp(self): super(TestSerialConsoleLiveMigrate, self).setUp() self.useFixture(policy_fixture.RealPolicyFixture()) self.useFixture(nova_fixtures.NeutronFixture(self)) self.useFixture(nova_fixtures.PlacementFixture()) api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) # Replace libvirt with fakelibvirt self.useFixture( fixtures.MonkeyPatch('nova.virt.libvirt.driver.libvirt_utils', fake_libvirt_utils)) self.useFixture( fixtures.MonkeyPatch('nova.virt.libvirt.driver.libvirt', fakelibvirt)) self.useFixture( fixtures.MonkeyPatch('nova.virt.libvirt.host.libvirt', fakelibvirt)) self.useFixture( fixtures.MonkeyPatch('nova.virt.libvirt.guest.libvirt', fakelibvirt)) self.useFixture(fakelibvirt.FakeLibvirtFixture()) self.admin_api = api_fixture.admin_api self.api = api_fixture.api # the image fake backend needed for image discovery nova.tests.unit.image.fake.stub_out_image_service(self) nova.tests.unit.fake_network.set_stub_network_methods(self) self.flags(compute_driver='libvirt.LibvirtDriver') self.flags(enabled=True, group="serial_console") self.flags(enabled=False, group="vnc") self.flags(enabled=False, group="spice") self.flags(use_usb_tablet=False, group="libvirt") self.flags(host="test_compute1") self.start_service('conductor') self.flags(driver='chance_scheduler', group='scheduler') self.start_service('scheduler') self.compute = self.start_service('compute', host='test_compute1') self.consoleauth = self.start_service('consoleauth') self.useFixture(cast_as_call.CastAsCall(self)) self.addCleanup(nova.tests.unit.image.fake.FakeImageService_reset) self.image_id = self.api.get_images()[0]['id'] self.flavor_id = self.api.get_flavors()[0]['id']