Fix indentation for the example code in documentation.
Change-Id: I454c22aaf1ffa56c37c0105ab76aa70d28983f43
This commit is contained in:
parent
d31d961110
commit
edda62ab35
doc/source
@ -126,16 +126,16 @@ For example:
|
|||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
class BaseTestCase1(api_version_utils.BaseMicroversionTest):
|
class BaseTestCase1(api_version_utils.BaseMicroversionTest):
|
||||||
|
|
||||||
[..]
|
[..]
|
||||||
@classmethod
|
@classmethod
|
||||||
def skip_checks(cls):
|
def skip_checks(cls):
|
||||||
super(BaseTestCase1, cls).skip_checks()
|
super(BaseTestCase1, cls).skip_checks()
|
||||||
api_version_utils.check_skip_with_microversion(cls.min_microversion,
|
api_version_utils.check_skip_with_microversion(cls.min_microversion,
|
||||||
cls.max_microversion,
|
cls.max_microversion,
|
||||||
CONF.compute.min_microversion,
|
CONF.compute.min_microversion,
|
||||||
CONF.compute.max_microversion)
|
CONF.compute.max_microversion)
|
||||||
|
|
||||||
Skip logic can be added in tests base class or any specific test class depends on
|
Skip logic can be added in tests base class or any specific test class depends on
|
||||||
tests class structure.
|
tests class structure.
|
||||||
|
@ -268,12 +268,12 @@ instance:
|
|||||||
|
|
||||||
class MyAPIClient(rest_client.RestClient):
|
class MyAPIClient(rest_client.RestClient):
|
||||||
|
|
||||||
def __init__(self, auth_provider, service, region,
|
def __init__(self, auth_provider, service, region,
|
||||||
my_arg, my_arg2=True, **kwargs):
|
my_arg, my_arg2=True, **kwargs):
|
||||||
super(MyAPIClient, self).__init__(
|
super(MyAPIClient, self).__init__(
|
||||||
auth_provider, service, region, **kwargs)
|
auth_provider, service, region, **kwargs)
|
||||||
self.my_arg = my_arg
|
self.my_arg = my_arg
|
||||||
self.my_args2 = my_arg
|
self.my_args2 = my_arg
|
||||||
|
|
||||||
Finally the service client should be structured in a python module, so that all
|
Finally the service client should be structured in a python module, so that all
|
||||||
service client classes are importable from it. Each major API version should
|
service client classes are importable from it. Each major API version should
|
||||||
|
@ -76,54 +76,54 @@ of these would be::
|
|||||||
|
|
||||||
class TestExampleCase(test.BaseTestCase):
|
class TestExampleCase(test.BaseTestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def skip_checks(cls):
|
def skip_checks(cls):
|
||||||
"""This section is used to evaluate config early and skip all test
|
"""This section is used to evaluate config early and skip all test
|
||||||
methods based on these checks
|
methods based on these checks
|
||||||
"""
|
"""
|
||||||
super(TestExampleCase, cls).skip_checks()
|
super(TestExampleCase, cls).skip_checks()
|
||||||
if not CONF.section.foo
|
if not CONF.section.foo
|
||||||
cls.skip('A helpful message')
|
cls.skip('A helpful message')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup_credentials(cls):
|
def setup_credentials(cls):
|
||||||
"""This section is used to do any manual credential allocation and also
|
"""This section is used to do any manual credential allocation and also
|
||||||
in the case of dynamic credentials to override the default network
|
in the case of dynamic credentials to override the default network
|
||||||
resource creation/auto allocation
|
resource creation/auto allocation
|
||||||
"""
|
"""
|
||||||
# This call is used to tell the credential allocator to not create any
|
# This call is used to tell the credential allocator to not create any
|
||||||
# network resources for this test case. It also enables selective
|
# network resources for this test case. It also enables selective
|
||||||
# creation of other neutron resources. NOTE: it must go before the
|
# creation of other neutron resources. NOTE: it must go before the
|
||||||
# super call
|
# super call
|
||||||
cls.set_network_resources()
|
cls.set_network_resources()
|
||||||
super(TestExampleCase, cls).setup_credentials()
|
super(TestExampleCase, cls).setup_credentials()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup_clients(cls):
|
def setup_clients(cls):
|
||||||
"""This section is used to setup client aliases from the manager object
|
"""This section is used to setup client aliases from the manager object
|
||||||
or to initialize any additional clients. Except in a few very
|
or to initialize any additional clients. Except in a few very
|
||||||
specific situations you should not need to use this.
|
specific situations you should not need to use this.
|
||||||
"""
|
"""
|
||||||
super(TestExampleCase, cls).setup_clients()
|
super(TestExampleCase, cls).setup_clients()
|
||||||
cls.servers_client = cls.os_primary.servers_client
|
cls.servers_client = cls.os_primary.servers_client
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def resource_setup(cls):
|
def resource_setup(cls):
|
||||||
"""This section is used to create any resources or objects which are
|
"""This section is used to create any resources or objects which are
|
||||||
going to be used and shared by **all** test methods in the
|
going to be used and shared by **all** test methods in the
|
||||||
TestCase. Note then anything created in this section must also be
|
TestCase. Note then anything created in this section must also be
|
||||||
destroyed in the corresponding resource_cleanup() method (which will
|
destroyed in the corresponding resource_cleanup() method (which will
|
||||||
be run during tearDownClass())
|
be run during tearDownClass())
|
||||||
"""
|
"""
|
||||||
super(TestExampleCase, cls).resource_setup()
|
super(TestExampleCase, cls).resource_setup()
|
||||||
cls.shared_server = cls.servers_client.create_server(...)
|
cls.shared_server = cls.servers_client.create_server(...)
|
||||||
cls.addClassResourceCleanup(waiters.wait_for_server_termination,
|
cls.addClassResourceCleanup(waiters.wait_for_server_termination,
|
||||||
cls.servers_client,
|
cls.servers_client,
|
||||||
cls.shared_server['id'])
|
cls.shared_server['id'])
|
||||||
cls.addClassResourceCleanup(
|
cls.addClassResourceCleanup(
|
||||||
test_utils.call_and_ignore_notfound_exc(
|
test_utils.call_and_ignore_notfound_exc(
|
||||||
cls.servers_client.delete_server,
|
cls.servers_client.delete_server,
|
||||||
cls.shared_server['id']))
|
cls.shared_server['id']))
|
||||||
|
|
||||||
.. _credentials:
|
.. _credentials:
|
||||||
|
|
||||||
@ -150,9 +150,9 @@ to set a class variable ``credentials`` on the TestCase directly. For example::
|
|||||||
|
|
||||||
credentials = ['primary', 'admin']
|
credentials = ['primary', 'admin']
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def skip_checks(cls):
|
def skip_checks(cls):
|
||||||
...
|
...
|
||||||
|
|
||||||
In this example the ``TestExampleAdmin`` TestCase will allocate 2 sets of
|
In this example the ``TestExampleAdmin`` TestCase will allocate 2 sets of
|
||||||
credentials, one regular user and one admin user. The corresponding manager
|
credentials, one regular user and one admin user. The corresponding manager
|
||||||
@ -225,10 +225,10 @@ in the `setup_credentials()` method before the `super()`. For example::
|
|||||||
|
|
||||||
class TestExampleCase(test.BaseTestCase):
|
class TestExampleCase(test.BaseTestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup_credentials(cls):
|
def setup_credentials(cls):
|
||||||
cls.set_network_resources(network=True, subnet=True, router=False)
|
cls.set_network_resources(network=True, subnet=True, router=False)
|
||||||
super(TestExampleCase, cls).setup_credentials()
|
super(TestExampleCase, cls).setup_credentials()
|
||||||
|
|
||||||
There are 2 quirks with the usage here. First for the set_network_resources
|
There are 2 quirks with the usage here. First for the set_network_resources
|
||||||
function to work properly it **must be called before super()**. This is so
|
function to work properly it **must be called before super()**. This is so
|
||||||
@ -242,10 +242,10 @@ any arguments. For example::
|
|||||||
|
|
||||||
class TestExampleCase(test.BaseTestCase):
|
class TestExampleCase(test.BaseTestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup_credentials(cls):
|
def setup_credentials(cls):
|
||||||
cls.set_network_resources()
|
cls.set_network_resources()
|
||||||
super(TestExampleCase, cls).setup_credentials()
|
super(TestExampleCase, cls).setup_credentials()
|
||||||
|
|
||||||
This will not allocate any networking resources. This is because by default all
|
This will not allocate any networking resources. This is because by default all
|
||||||
the arguments default to False.
|
the arguments default to False.
|
||||||
@ -282,8 +282,8 @@ call to create a server in Nova::
|
|||||||
|
|
||||||
|
|
||||||
class TestExampleCase(test.BaseTestCase):
|
class TestExampleCase(test.BaseTestCase):
|
||||||
def test_example_create_server(self):
|
def test_example_create_server(self):
|
||||||
self.os_primary.servers_client.create_server(...)
|
self.os_primary.servers_client.create_server(...)
|
||||||
|
|
||||||
is all you need to do. As described previously, in the above example the
|
is all you need to do. As described previously, in the above example the
|
||||||
``self.os_primary`` is created automatically because the base test class sets the
|
``self.os_primary`` is created automatically because the base test class sets the
|
||||||
@ -305,8 +305,8 @@ object via the manager's ``credentials`` attribute. For example::
|
|||||||
|
|
||||||
|
|
||||||
class TestExampleCase(test.BaseTestCase):
|
class TestExampleCase(test.BaseTestCase):
|
||||||
def test_example_create_server(self):
|
def test_example_create_server(self):
|
||||||
credentials = self.os_primary.credentials
|
credentials = self.os_primary.credentials
|
||||||
|
|
||||||
The credentials object provides access to all of the credential information you
|
The credentials object provides access to all of the credential information you
|
||||||
would need to make API requests. For example, building off the previous
|
would need to make API requests. For example, building off the previous
|
||||||
@ -316,9 +316,9 @@ example::
|
|||||||
|
|
||||||
|
|
||||||
class TestExampleCase(test.BaseTestCase):
|
class TestExampleCase(test.BaseTestCase):
|
||||||
def test_example_create_server(self):
|
def test_example_create_server(self):
|
||||||
credentials = self.os_primary.credentials
|
credentials = self.os_primary.credentials
|
||||||
username = credentials.username
|
username = credentials.username
|
||||||
user_id = credentials.user_id
|
user_id = credentials.user_id
|
||||||
password = credentials.password
|
password = credentials.password
|
||||||
tenant_id = credentials.tenant_id
|
tenant_id = credentials.tenant_id
|
||||||
|
Loading…
Reference in New Issue
Block a user