def test_instance_from_buildrequest(self): self.useFixture(nova_fixtures.AllServicesCurrent()) image_ref = fake_image.get_valid_image_id() body = { 'server': { 'name': 'foo', 'imageRef': image_ref, 'flavorRef': '1', 'networks': 'none', } } create_resp = self.api.api_post('servers', body) get_resp = self.api.api_get('servers/%s' % create_resp.body['server']['id']) flavor_get_resp = self.api.api_get('flavors/%s' % body['server']['flavorRef']) server = get_resp.body['server'] # Validate a few things self.assertEqual('foo', server['name']) self.assertEqual(image_ref, server['image']['id']) self.assertEqual(flavor_get_resp.body['flavor']['name'], server['flavor']['original_name']) self.assertEqual('', server['hostId']) self.assertIsNone(None, server['OS-SRV-USG:launched_at']) self.assertIsNone(None, server['OS-SRV-USG:terminated_at']) self.assertFalse(server['locked']) self.assertEqual([], server['tags']) self.assertEqual('scheduling', server['OS-EXT-STS:task_state']) self.assertEqual('building', server['OS-EXT-STS:vm_state']) self.assertEqual('BUILD', server['status'])
def setUp(self): self.flags(compute_driver=self.compute_driver) super(ProviderUsageBaseTestCase, self).setUp() self.policy = self.useFixture(policy_fixture.RealPolicyFixture()) self.neutron = self.useFixture(nova_fixtures.NeutronFixture(self)) self.placement = self.useFixture(func_fixtures.PlacementFixture()).api self.useFixture(nova_fixtures.AllServicesCurrent()) fake_notifier.stub_notifier(self) self.addCleanup(fake_notifier.reset) self.api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) self.admin_api = self.api_fixture.admin_api self.admin_api.microversion = self.microversion self.api = self.admin_api # the image fake backend needed for image discovery self.image_service = ( 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)
def test_instance_list_build_request_marker_ip_filter(self): """Tests listing instances with a marker that is in the build_requests table and also filtering by ip, in which case the ip filter can't possibly find anything because instances that are not yet scheduled can't have ips, but the point is to find the marker in the build requests table. """ self.useFixture(nova_fixtures.AllServicesCurrent()) # Create the server. body = { 'server': { 'name': 'test_instance_list_build_request_marker_ip_filter', 'imageRef': fake_image.get_valid_image_id(), 'flavorRef': '1', 'networks': 'none' } } server = self.api.post_server(body) # Now list servers using the one we just created as the marker and # include the ip filter (see bug 1764685). search_opts = {'marker': server['id'], 'ip': '192.168.159.150'} servers = self.api.get_servers(search_opts=search_opts) # We'll get 0 servers back because there are none with the specified # ip filter. self.assertEqual(0, len(servers))
def setUp(self): # Everything has been upgraded to the latest code to support # multiattach. self.useFixture(nova_fixtures.AllServicesCurrent()) super(TestMultiattachVolumes, self).setUp() self.useFixture(nova_fixtures.CinderFixtureNewAttachFlow(self)) self.useFixture(nova_fixtures.NeutronFixture(self))
def setUp(self): self.flags(use_neutron=True) self.flags(bdms_in_notifications='True', group='notifications') super(TestInstanceNotificationSampleWithMultipleCompute, self).setUp() self.neutron = fixtures.NeutronFixture(self) self.useFixture(self.neutron) self.cinder = fixtures.CinderFixture(self) self.useFixture(self.cinder) self.useFixture(fixtures.AllServicesCurrent())
def test_instance_list_from_buildrequests_with_tags(self): """Creates two servers with two tags each, where the 2nd tag (tag2) is the only intersection between the tags in both servers. This is used to test the various tags filters working in the BuildRequestList. """ self.useFixture(nova_fixtures.AllServicesCurrent()) image_ref = fake_image.get_valid_image_id() body = { 'server': { 'name': 'foo', 'imageRef': image_ref, 'flavorRef': '1', 'networks': 'none', 'tags': ['tag1', 'tag2'] } } inst1 = self.api.api_post('servers', body) body['server']['name'] = 'bar' body['server']['tags'] = ['tag2', 'tag3'] inst2 = self.api.api_post('servers', body) # list servers using tags=tag1,tag2 list_resp = self.api.api_get( 'servers/detail?tags=tag1,tag2') list_resp = list_resp.body['servers'] self.assertEqual(1, len(list_resp)) self.assertEqual(inst1.body['server']['id'], list_resp[0]['id']) self.assertEqual('foo', list_resp[0]['name']) # list servers using tags-any=tag1,tag3 list_resp = self.api.api_get( 'servers/detail?tags-any=tag1,tag3') list_resp = list_resp.body['servers'] self.assertEqual(2, len(list_resp)) # Default sort is created_at desc, so last created is first self.assertEqual(inst2.body['server']['id'], list_resp[0]['id']) self.assertEqual('bar', list_resp[0]['name']) self.assertEqual(inst1.body['server']['id'], list_resp[1]['id']) self.assertEqual('foo', list_resp[1]['name']) # list servers using not-tags=tag1,tag2 list_resp = self.api.api_get( 'servers/detail?not-tags=tag1,tag2') list_resp = list_resp.body['servers'] self.assertEqual(1, len(list_resp)) self.assertEqual(inst2.body['server']['id'], list_resp[0]['id']) self.assertEqual('bar', list_resp[0]['name']) # list servers using not-tags-any=tag1,tag3 list_resp = self.api.api_get( 'servers/detail?not-tags-any=tag1,tag3') list_resp = list_resp.body['servers'] self.assertEqual(0, len(list_resp))
def setUp(self): super(ServerGroupTestMultiCell, self).setUp() # Start two compute services, one per cell self.compute1 = self.start_service('compute', host='host1', cell='cell1') self.compute2 = self.start_service('compute', host='host2', cell='cell2') # This is needed to find a server that is still booting with multiple # cells, while waiting for the state change to ACTIVE. See the # _get_instance method in the compute/api for details. self.useFixture(nova_fixtures.AllServicesCurrent()) self.aggregates = {}
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 test_services_current(self, mock_db): mock_db.return_value = {'nova-compute': 123} self.assertEqual( 123, service_obj.Service.get_minimum_version(None, 'nova-compute')) mock_db.assert_called_once_with(None, ['nova-compute'], use_slave=False) mock_db.reset_mock() compute_rpcapi.LAST_VERSION = 123 self.useFixture(fixtures.AllServicesCurrent()) self.assertIsNone(compute_rpcapi.LAST_VERSION) self.assertEqual( service_obj.SERVICE_VERSION, service_obj.Service.get_minimum_version(None, 'nova-compute')) self.assertFalse(mock_db.called)
def test_delete_instance_from_buildrequest(self): self.useFixture(nova_fixtures.AllServicesCurrent()) image_ref = fake_image.get_valid_image_id() body = { 'server': { 'name': 'foo', 'imageRef': image_ref, 'flavorRef': '1', } } create_resp = self.api.api_post('servers', body) self.api.api_delete('servers/%s' % create_resp.body['server']['id']) get_resp = self.api.api_get('servers/%s' % create_resp.body['server']['id'], check_response_status=False) self.assertEqual(404, get_resp.status)
def test_delete_instance_from_buildrequest(self): self.useFixture(nova_fixtures.AllServicesCurrent()) image_ref = self.glance.auto_disk_config_enabled_image['id'] body = { 'server': { 'name': 'foo', 'imageRef': image_ref, 'flavorRef': '1', 'networks': 'none', } } create_resp = self.api.api_post('servers', body) self.api.api_delete('servers/%s' % create_resp.body['server']['id']) get_resp = self.api.api_get('servers/%s' % create_resp.body['server']['id'], check_response_status=False) self.assertEqual(404, get_resp.status)
def setUp(self): super(MultiCellSchedulerTestCase, self).setUp() self.useFixture(nova_fixtures.RealPolicyFixture()) self.useFixture(nova_fixtures.NeutronFixture(self)) self.useFixture(nova_fixtures.GlanceFixture(self)) self.useFixture(nova_fixtures.AllServicesCurrent()) self.useFixture(func_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 fake_network.set_stub_network_methods(self) self.flags(allow_resize_to_same_host=False) self.flags(enabled_filters=['AllHostsFilter'], group='filter_scheduler') self.start_service('conductor') self.start_service('scheduler')
def test_bfv_delete_build_request_pre_scheduling(self): cinder = self.useFixture( nova_fixtures.CinderFixtureNewAttachFlow(self)) # This makes the get_minimum_version_all_cells check say we're running # the latest of everything. self.useFixture(nova_fixtures.AllServicesCurrent()) volume_id = nova_fixtures.CinderFixtureNewAttachFlow.IMAGE_BACKED_VOL server = self.api.post_server({ 'server': { 'flavorRef': '1', 'name': 'test_bfv_delete_build_request_pre_scheduling', 'networks': 'none', 'block_device_mapping_v2': [ { 'boot_index': 0, 'uuid': volume_id, 'source_type': 'volume', 'destination_type': 'volume' }, ] } }) # Since _IntegratedTestBase uses the CastAsCall fixture, when we # get the server back we know all of the volume stuff should be done. self.assertIn(volume_id, cinder.volume_ids_for_instance(server['id'])) # Now delete the server, which should go through the "local delete" # code in the API, find the build request and delete it along with # detaching the volume from the instance. self.api.delete_server(server['id']) # The volume should no longer have any attachments as instance delete # should have removed them. self.assertNotIn(volume_id, cinder.volume_ids_for_instance(server['id']))
def setUp(self): self.flags(compute_driver=self.compute_driver) super(ProviderUsageBaseTestCase, self).setUp() self.policy = self.useFixture(policy_fixture.RealPolicyFixture()) self.neutron = self.useFixture(nova_fixtures.NeutronFixture(self)) self.glance = self.useFixture(nova_fixtures.GlanceFixture(self)) self.placement = self.useFixture(func_fixtures.PlacementFixture()).api self.useFixture(nova_fixtures.AllServicesCurrent()) fake_notifier.stub_notifier(self) self.addCleanup(fake_notifier.reset) self.api_fixture = self.useFixture( nova_fixtures.OSAPIFixture(api_version='v2.1')) self.admin_api = self.api_fixture.admin_api self.admin_api.microversion = self.microversion self.api = self.admin_api self.start_service('conductor') self.scheduler_service = self.start_service('scheduler')
def setUp(self): super(ServerGroupTestMultiCell, self).setUp() # Start two compute services, one per cell fake.set_nodes(['host1']) self.addCleanup(fake.restore_nodes) self.compute1 = self.start_service('compute', host='host1', cell='cell1') fake.set_nodes(['host2']) self.addCleanup(fake.restore_nodes) self.compute2 = self.start_service('compute', host='host2', cell='cell2') # This is needed to avoid a NetworkAmbiguous error during # _validate_requested_port_ids in allocate_for_instance. fake_network.set_stub_network_methods(self) # This is needed to find a server that is still booting with multiple # cells, while waiting for the state change to ACTIVE. See the # _get_instance method in the compute/api for details. self.useFixture(nova_fixtures.AllServicesCurrent()) self.aggregates = {}
def test_instance_list_from_buildrequests(self): self.useFixture(nova_fixtures.AllServicesCurrent()) self._test_instance_list_from_buildrequests()