glance.tests.functional package

Submodules

glance.tests.functional.store_utils module

Utility methods to set testcases up for Swift tests.

class glance.tests.functional.store_utils.RemoteImageHandler(request, client_address, server)[source]

Bases: BaseHTTPServer.BaseHTTPRequestHandler

do_GET()[source]

Respond to an image GET request with fake image content.

do_HEAD()[source]

Respond to an image HEAD request fake metadata

log_message(format, *args)[source]

Simple override to prevent writing crap to stderr...

glance.tests.functional.store_utils.get_http_uri(test, image_id)[source]
glance.tests.functional.store_utils.setup_http(test)[source]

glance.tests.functional.test_api module

Version-independent api tests

class glance.tests.functional.test_api.TestApiPaths(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest

setUp()[source]
test_get_images_path()[source]

Assert GET /images with no Accept: header. Verify version choices returned.

test_get_images_path_with_openstack_header()[source]

Assert GET /images with a Accept: application/vnd.openstack.compute-v1 header. Verify version choices returned. Verify message in API log about unknown accept header.

test_get_images_path_with_openstack_v2_header()[source]

Assert GET /images with a Accept: application/vnd.openstack.compute-v2 header. Verify version choices returned. Verify message in API log about unknown version in accept header.

test_get_root_path()[source]

Assert GET / with no Accept: header. Verify version choices returned. Bug lp:803260 no Accept header causes a 500 in glance-api

test_get_root_path_with_openstack_header()[source]

Assert GET / with an Accept: application/vnd.openstack.images-v1 Verify empty image list returned

test_get_root_path_with_unknown_header()[source]

Assert GET / with Accept: unknown header Verify version choices returned. Verify message in API log about unknown accept header.

test_get_v10_images_path()[source]

Assert GET /v1.0/images with no Accept: header Verify version choices returned

test_get_v12_images_path()[source]

Assert GET /v1.2/images with no Accept: header Verify version choices returned

test_get_v1_images_path()[source]

GET /v1/images with no Accept: header. Verify empty images list returned.

test_get_v1_versions_path()[source]

Assert GET /v1/versions with no Accept: header Verify 404 returned

test_get_v1a_images_path()[source]

Assert GET /v1.a/images with no Accept: header Verify version choices returned

test_get_va1_images_path()[source]

Assert GET /va.1/images with no Accept: header Verify version choices returned

test_get_versions_choices()[source]

Verify version choices returned

test_get_versions_path()[source]

Assert GET /versions with no Accept: header Verify version choices returned

test_get_versions_path_with_openstack_header()[source]

Assert GET /versions with the Accept: application/vnd.openstack.images-v1 header. Verify version choices returned.

class glance.tests.functional.test_api.TestApiVersions(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest

test_v1_api_configuration()[source]
test_v2_api_configuration()[source]
test_version_configurations()[source]

Test that versioning is handled properly through all channels

glance.tests.functional.test_bin_glance_cache_manage module

Functional test case that utilizes the bin/glance-cache-manage CLI tool

class glance.tests.functional.test_bin_glance_cache_manage.TestBinGlanceCacheManage(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest

Functional tests for the bin/glance CLI tool

add_image(name)[source]

Adds an image with supplied name and returns the newly-created image identifier.

is_image_cached(image_id)[source]

Return True if supplied image ID is cached, False otherwise

iso_date(image_id)[source]

Return True if supplied image ID is cached, False otherwise

setUp()[source]
test_cache_index()[source]

Test that cache index command works

test_no_cache_enabled()[source]

Test that cache index command works

test_queue()[source]

Test that we can queue and fetch images using the CLI utility

glance.tests.functional.test_cache_middleware module

Tests a Glance API server which uses the caching middleware that uses the default SQLite cache driver. We use the filesystem store, but that is really not relevant, as the image cache is transparent to the backend store.

class glance.tests.functional.test_cache_middleware.BaseCacheManageMiddlewareTest[source]

Bases: object

Base test class for testing cache management middleware

add_image(name)[source]

Adds an image and returns the newly-added image identifier

test_cache_manage_delete_cached_images(*a, **kwargs)[source]

Tests that cached images may be deleted

test_cache_manage_delete_queued_images(*a, **kwargs)[source]

Tests that all queued images may be deleted at once

test_cache_manage_get_cached_images(*a, **kwargs)[source]

Tests that cached images are queryable

test_queue_and_prefetch(*a, **kwargs)[source]

Tests that images may be queued and prefetched

test_user_not_authorized(*a, **kwargs)[source]
verify_no_cached_images()[source]

Verify no images in the image cache

verify_no_images()[source]
class glance.tests.functional.test_cache_middleware.BaseCacheMiddlewareTest[source]

Bases: object

test_cache_middleware_trans_v1_without_download_image_policy(*a, **kwargs)[source]

Ensure the image v1 API image transfer applied ‘download_image’ policy enforcement.

test_cache_middleware_trans_v2_without_download_image_policy(*a, **kwargs)[source]

Ensure the image v2 API image transfer applied ‘download_image’ policy enforcement.

test_cache_middleware_trans_with_deactivated_image(*a, **kwargs)[source]

Ensure the image v1/v2 API image transfer forbids downloading deactivated images. Image deactivation is not available in v1. So, we’ll deactivate the image using v2 but test image transfer with both v1 and v2.

test_cache_middleware_transparent_v1(*a, **kwargs)[source]

We test that putting the cache middleware into the application pipeline gives us transparent image caching

test_cache_middleware_transparent_v2(*a, **kwargs)[source]

Ensure the v2 API image transfer calls trigger caching

test_cache_remote_image(*a, **kwargs)[source]

We test that caching is no longer broken for remote images

class glance.tests.functional.test_cache_middleware.TestImageCacheManageSqlite(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest, glance.tests.functional.test_cache_middleware.BaseCacheManageMiddlewareTest

Functional tests that exercise the image cache management using the SQLite driver

setUp()[source]

Test to see if the pre-requisites for the image cache are working (python-xattr installed and xattr support on the filesystem)

tearDown()[source]
class glance.tests.functional.test_cache_middleware.TestImageCacheManageXattr(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest, glance.tests.functional.test_cache_middleware.BaseCacheManageMiddlewareTest

Functional tests that exercise the image cache management with the Xattr cache driver

setUp()[source]

Test to see if the pre-requisites for the image cache are working (python-xattr installed and xattr support on the filesystem)

tearDown()[source]
class glance.tests.functional.test_cache_middleware.TestImageCacheSqlite(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest, glance.tests.functional.test_cache_middleware.BaseCacheMiddlewareTest

Functional tests that exercise the image cache using the SQLite driver

setUp()[source]

Test to see if the pre-requisites for the image cache are working (python-xattr installed and xattr support on the filesystem)

tearDown()[source]
class glance.tests.functional.test_cache_middleware.TestImageCacheXattr(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest, glance.tests.functional.test_cache_middleware.BaseCacheMiddlewareTest

Functional tests that exercise the image cache using the xattr driver

setUp()[source]

Test to see if the pre-requisites for the image cache are working (python-xattr installed and xattr support on the filesystem)

tearDown()[source]

glance.tests.functional.test_client_exceptions module

Functional test asserting strongly typed exceptions from glance client

class glance.tests.functional.test_client_exceptions.ExceptionTestApp[source]

Bases: object

Test WSGI application which can respond with multiple kinds of HTTP status codes

class glance.tests.functional.test_client_exceptions.TestClientExceptions(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest

setUp()[source]
test_expectation_failed()[source]

Test expectation failed response

test_rate_limited()[source]

Test rate limited response

test_rate_limited_retry()[source]

Test rate limited response with retry

test_server_error()[source]

Test server error response

test_server_traceback()[source]

Verify that the wsgi server does not return tracebacks to the client on 500 errors (bug 1192132)

test_service_unavailable()[source]

Test service unavailable response

test_service_unavailable_retry()[source]

Test service unavailable response with retry

glance.tests.functional.test_client_redirects module

Functional test cases testing glance client redirect-following.

glance.tests.functional.test_client_redirects.RedirectTestApp(name)[source]
class glance.tests.functional.test_client_redirects.TestClientRedirects(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest

setUp()[source]
test_get_with_max_redirects()[source]

Test we don’t redirect forever.

test_get_with_one_redirect()[source]

Test GET with one 302 FOUND redirect

test_get_with_one_redirect_query_string()[source]

Test GET with one 302 FOUND redirect w/ a query string

test_get_without_redirect()[source]

Test GET with no redirect

test_post_redirect()[source]

Test POST with 302 redirect

test_redirect_to_new_host()[source]

Test redirect to one host and then another.

glance.tests.functional.test_cors_middleware module

Tests cors middleware.

class glance.tests.functional.test_cors_middleware.TestCORSMiddleware(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest

Provide a basic smoke test to ensure CORS middleware is active.

The tests below provide minimal confirmation that the CORS middleware is active, and may be configured. For comprehensive tests, please consult the test suite in oslo_middleware.

setUp()[source]
test_invalid_cors_get_request()[source]
test_invalid_cors_options_request()[source]
test_valid_cors_get_request()[source]
test_valid_cors_options_request()[source]

glance.tests.functional.test_glance_manage module

Functional test cases for glance-manage

class glance.tests.functional.test_glance_manage.TestGlanceManage(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest

Functional tests for glance-manage

setUp()[source]
test_db_creation(*args, **kw)[source]

Test DB creation by db_sync on a fresh DB

glance.tests.functional.test_glance_replicator module

Functional test cases for glance-replicator

class glance.tests.functional.test_glance_replicator.TestGlanceReplicator(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest

Functional tests for glance-replicator

test_compare()[source]

glance.tests.functional.test_gzip_middleware module

Tests gzip middleware.

class glance.tests.functional.test_gzip_middleware.GzipMiddlewareTest(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest

test_gzip_requests(*a, **kwargs)[source]

glance.tests.functional.test_healthcheck_middleware module

Tests healthcheck middleware.

class glance.tests.functional.test_healthcheck_middleware.HealthcheckMiddlewareTest(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest

request()[source]
test_healthcheck_disabled()[source]
test_healthcheck_enabled(*a, **kwargs)[source]

glance.tests.functional.test_logging module

Functional test case that tests logging output

class glance.tests.functional.test_logging.TestLogging(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest

Functional tests for Glance’s logging output

assertNotEmptyFile(path)[source]
test_debug()[source]

Test logging output proper when debug is on.

test_logrotate()[source]

Test that we notice when our log file has been rotated

test_no_debug()[source]

Test logging output proper when debug is off.

glance.tests.functional.test_reload module

class glance.tests.functional.test_reload.TestReload(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest

Test configuration reload

setUp()[source]
tearDown()[source]
test_reload()[source]

Test SIGHUP picks up new config values

ticker(message, seconds=60, tick=0.01)[source]

Allows repeatedly testing for an expected result for a finite amount of time.

Parameters:
  • message – Message to display on timeout
  • seconds – Time in seconds after which we timeout
  • tick – Time to sleep before rechecking for expected result
Returns:

‘True’ or fails the test with ‘message’ on timeout

glance.tests.functional.test_reload.set_config_value(filepath, key, value)[source]

Set ‘key = value’ in config file

glance.tests.functional.test_scrubber module

class glance.tests.functional.test_scrubber.TestScrubber(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest

Test that delayed_delete works and the scrubber deletes

test_delayed_delete()[source]

test that images don’t get deleted immediately and that the scrubber scrubs them

test_delayed_delete_with_trustedauth_registry()[source]

test that images don’t get deleted immediately and that the scrubber scrubs them when registry is operating in trustedauth mode

test_scrubber_app()[source]

test that the glance-scrubber script runs successfully when not in daemon mode

test_scrubber_app_with_trustedauth_registry()[source]

test that the glance-scrubber script runs successfully when not in daemon mode and with a registry that operates in trustedauth mode

test_scrubber_delete_handles_exception()[source]

Test that the scrubber handles the case where an exception occurs when _delete() is called. The scrubber should not write out queue files in this case.

wait_for_scrub(path, headers=None)[source]

NOTE(jkoelker) The build servers sometimes take longer than 15 seconds to scrub. Give it up to 5 min, checking checking every 15 seconds. When/if it flips to deleted, bail immediately.

glance.tests.functional.test_sqlite module

Functional test cases for sqlite-specific logic

class glance.tests.functional.test_sqlite.TestSqlite(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest

Functional tests for sqlite-specific logic

test_big_int_mapping(*args, **kw)[source]

Ensure BigInteger not mapped to BIGINT

glance.tests.functional.test_ssl module

class glance.tests.functional.test_ssl.TestSSL(*args, **kwargs)[source]

Bases: glance.tests.functional.FunctionalTest

Functional tests verifying SSL communication

setUp()[source]
tearDown()[source]
test_ssl_ok()[source]

Make sure the public API works with HTTPS.

glance.tests.functional.test_wsgi module

Tests for glance.wsgi.

class glance.tests.functional.test_wsgi.TestWSGIServer(*args, **kwargs)[source]

Bases: testtools.testcase.TestCase

WSGI server tests.

test_client_socket_timeout()[source]

Module contents

Base test class for running non-stubbed tests (functional tests)

The FunctionalTest class contains helper methods for starting the API and Registry server, grabbing the logs of each, cleaning up pidfiles, and spinning down the servers.

class glance.tests.functional.ApiServer(test_dir, port, policy_file, delayed_delete=False, pid_file=None, sock=None, **kwargs)[source]

Bases: glance.tests.functional.Server

Server object that starts/stops/manages the API server

class glance.tests.functional.FunctionalTest(*args, **kwargs)[source]

Bases: glance.tests.utils.BaseTestCase

Base test class for any test that wants to test the actual servers and clients and not just the stubbed out interfaces

add_log_details(servers=None)[source]
cleanup()[source]

Makes sure anything we created or started up in the tests are destroyed or spun down

copy_data_file(file_name, dst_dir)[source]
disabled = False
inited = False
launched_servers = []
ping_server(port)[source]

Simple ping on the port. If responsive, return True, else return False.

:note We use raw sockets, not ping here, since ping uses ICMP and has no concept of ports...

run_sql_cmd(sql)[source]

Provides a crude mechanism to run manual SQL commands for backend DB verification within the functional tests. The raw result set is returned.

setUp()[source]
set_policy_rules(rules)[source]
start_server(server, expect_launch, expect_exit=True, expected_exitcode=0, **kwargs)[source]

Starts a server on an unused port.

Any kwargs passed to this method will override the configuration value in the conf file used in starting the server.

Parameters:
  • server – the server to launch
  • expect_launch – true iff the server is expected to successfully start
  • expect_exit – true iff the launched process is expected to exit in a timely fashion
  • expected_exitcode – expected exitcode from the launcher
start_servers(**kwargs)[source]

Starts the API and Registry servers (glance-control api start & glance-control registry start) on unused ports. glance-control should be installed into the python path

Any kwargs passed to this method will override the configuration value in the conf file used in starting the servers.

start_with_retry(server, port_name, max_retries, expect_launch=True, **kwargs)[source]

Starts a server, with retries if the server launches but fails to start listening on the expected port.

Parameters:
  • server – the server to launch
  • port_name – the name of the port attribute
  • max_retries – the maximum number of attempts
  • expect_launch – true iff the server is expected to successfully start
  • expect_exit – true iff the launched process is expected to exit in a timely fashion
stop_server(server, name)[source]

Called to stop a single server in a normal fashion using the glance-control stop method to gracefully shut the server down.

Parameters:server – the server to stop
stop_servers()[source]

Called to stop the started servers in a normal fashion. Note that cleanup() will stop the servers using a fairly draconian method of sending a SIGTERM signal to the servers. Here, we use the glance-control stop method to gracefully shut the server down. This method also asserts that the shutdown was clean, and so it is meant to be called during a normal test case sequence.

tearDown()[source]
wait_for_servers(servers, expect_launch=True, timeout=30)[source]

Tight loop, waiting for the given server port(s) to be available. Returns when all are pingable. There is a timeout on waiting for the servers to come up.

Parameters:
  • servers – Glance server ports to ping
  • expect_launch – Optional, true iff the server(s) are expected to successfully start
  • timeout – Optional, defaults to 30 seconds
Returns:

None if launch expectation is met, otherwise an assertion message

class glance.tests.functional.RegistryServer(test_dir, port, policy_file, sock=None)[source]

Bases: glance.tests.functional.Server

Server object that starts/stops/manages the Registry server

class glance.tests.functional.ScrubberDaemon(test_dir, policy_file, daemon=False, **kwargs)[source]

Bases: glance.tests.functional.Server

Server object that starts/stops/manages the Scrubber server

start(expect_exit=True, expected_exitcode=0, **kwargs)[source]
class glance.tests.functional.Server(test_dir, port, sock=None)[source]

Bases: object

Class used to easily manage starting and stopping a server during functional test runs.

create_database()[source]

Create database if required for this server

dump_log(name)[source]
reload(expect_exit=True, expected_exitcode=0, **kwargs)[source]

Start and stop the service to reload

Any kwargs passed to this method will override the configuration value in the conf file used in starting the servers.

start(expect_exit=True, expected_exitcode=0, **kwargs)[source]

Starts the server.

Any kwargs passed to this method will override the configuration value in the conf file used in starting the servers.

stop()[source]

Spin down the server.

write_conf(**kwargs)[source]

Writes the configuration file for the server to its intended destination. Returns the name of the configuration file and the over-ridden config content (may be useful for populating error messages).