glance.tests package

Subpackages

Submodules

glance.tests.stubs module

Stubouts, mocks and fixtures for the test suite

class glance.tests.stubs.FakeRegistryConnection(registry=None)[source]

Bases: object

close()[source]
connect()[source]
getresponse()[source]
request(method, url, body=None, headers=None)[source]
glance.tests.stubs.stub_out_registry_and_store_server(stubs, base_dir, **kwargs)[source]

Mocks calls to 127.0.0.1 on 9191 and 9292 for testing.

Done so that a real Glance server does not need to be up and running

glance.tests.stubs.stub_out_registry_server(stubs, **kwargs)[source]

Mocks calls to 127.0.0.1 on 9191 for testing.

Done so that a real Glance Registry server does not need to be up and running.

glance.tests.test_hacking module

class glance.tests.test_hacking.HackingTestCase(*args, **kwargs)[source]

Bases: glance.tests.utils.BaseTestCase

test_assert_equal_none()[source]
test_assert_equal_type()[source]
test_assert_true_instance()[source]
test_check_python3_xrange()[source]
test_dict_constructor_with_list_copy()[source]
test_dict_iteritems()[source]
test_dict_iterkeys()[source]
test_dict_itervalues()[source]
test_no_contextlib_nested()[source]
test_no_direct_use_of_unicode_function()[source]
test_no_translate_debug_logs()[source]

glance.tests.utils module

Common utilities used in testing

class glance.tests.utils.BaseTestCase(*args, **kwargs)[source]

Bases: testtools.testcase.TestCase

config(**kw)[source]

Override some configuration values.

The keyword arguments are the names of configuration options to override and their values.

If a group argument is supplied, the overrides are applied to the specified configuration option group.

All overrides are automatically cleared at the end of the current test by the fixtures cleanup process.

setUp()[source]
set_policy()[source]
set_property_protection_rules(rules)[source]
set_property_protections(use_policies=False)[source]
unset_property_protections()[source]
class glance.tests.utils.FakeAuthMiddleware(app, is_admin=False)[source]

Bases: glance.common.wsgi.Middleware

process_request(req)[source]
class glance.tests.utils.FakeHTTPResponse(status=200, headers=None, data=None, *args, **kwargs)[source]

Bases: object

getheader(name, default=None)[source]
getheaders()[source]
read(amt)[source]
class glance.tests.utils.Httplib2WebobResponse(webob_resp)[source]

Bases: object

allow
get(key)[source]
status
class glance.tests.utils.Httplib2WsgiAdapter(app)[source]

Bases: object

request(uri, method='GET', body=None, headers=None)[source]
class glance.tests.utils.HttplibWsgiAdapter(app)[source]

Bases: object

getresponse()[source]
request(method, url, body=None, headers=None)[source]
class glance.tests.utils.RegistryAPIMixIn[source]

Bases: object

assertEqualImages(res, uuids, key='images', unjsonify=True)[source]
create_fixtures()[source]
destroy_fixtures()[source]
get_api_response_ext(http_resp, url='/images', headers=None, body=None, method=None, api=None, content_type=None)[source]
get_extra_fixture(id, name, **kwargs)[source]
get_fixture(**kwargs)[source]
get_minimal_fixture(**kwargs)[source]
glance.tests.utils.db_sync(version=None, engine=None)[source]

Migrate the database to version or the most recent version.

class glance.tests.utils.depends_on_exe(exe)[source]

Bases: object

Decorator to skip test if an executable is unavailable

glance.tests.utils.execute(cmd, raise_error=True, no_venv=False, exec_env=None, expect_exit=True, expected_exitcode=0, context=None)[source]

Executes a command in a subprocess. Returns a tuple of (exitcode, out, err), where out is the string output from stdout and err is the string output from stderr when executing the command.

Parameters:
  • cmd – Command string to execute
  • raise_error – If returncode is not 0 (success), then raise a RuntimeError? Default: True)
  • no_venv – Disable the virtual environment
  • exec_env – Optional dictionary of additional environment variables; values may be callables, which will be passed the current value of the named environment variable
  • expect_exit – Optional flag true iff timely exit is expected
  • expected_exitcode – expected exitcode from the launcher
  • context – additional context for error message
glance.tests.utils.find_executable(cmdname)[source]

Searches the path for a given cmdname. Returns an absolute filename if an executable with the given name exists in the path, or None if one does not.

Parameters:cmdname – The bare name of the executable to search for
glance.tests.utils.fork_exec(cmd, exec_env=None, logfile=None, pass_fds=None)[source]

Execute a command using fork/exec.

This is needed for programs system executions that need path searching but cannot have a shell as their parent process, for example: glance-api. When glance-api starts it sets itself as the parent process for its own process group. Thus the pid that a Popen process would have is not the right pid to use for killing the process group. This patch gives the test env direct access to the actual pid.

Parameters:
  • cmd – Command to execute as an array of arguments.
  • exec_env – A dictionary representing the environment with which to run the command.
  • logfile – A path to a file which will hold the stdout/err of the child process.
  • pass_fds – Sequence of file descriptors passed to the child.
glance.tests.utils.get_unused_port()[source]

Returns an unused port on localhost.

glance.tests.utils.get_unused_port_and_socket()[source]

Returns an unused port on localhost and the open socket from which it was created.

glance.tests.utils.get_unused_port_and_socket_ipv6()[source]

Returns an unused port on localhost and the open socket from which it was created, but uses IPv6 (::1).

glance.tests.utils.get_unused_port_ipv6()[source]

Returns an unused port on localhost on IPv6 (uses ::1).

glance.tests.utils.minimal_add_command(port, name, suffix='', public=True)[source]
glance.tests.utils.minimal_headers(name, public=True)[source]
class glance.tests.utils.requires(setup=None, teardown=None)[source]

Bases: object

Decorator that initiates additional test setup/teardown.

glance.tests.utils.skip_if_disabled(func)[source]

Decorator that skips a test if test case is disabled.

glance.tests.utils.start_http_server(image_id, image_data)[source]
glance.tests.utils.wait_for_fork(pid, raise_error=True, expected_exitcode=0)[source]

Wait for a process to complete

This function will wait for the given pid to complete. If the exit code does not match that of the expected_exitcode an error is raised.

glance.tests.utils.xattr_writes_supported(path)[source]

Returns True if the we can write a file to the supplied path and subsequently write a xattr to that file.

Module contents