You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The SDK uses `pytest` as its test framework. You can run tests against Python 2.7 Python 3.5 using the `tox` command. Note that this requires that you have those versions of Python installed,
25
+
otherwise you must pass `-e` or run tests directly:
26
+
27
+
.. code-block:: sh
28
+
29
+
# This will run tests against all configured Pythons in tox.ini (currently 2.7 and 3.5). You need to have those versions installed
30
+
tox
31
+
32
+
# This will run tests against a specific Python versions
33
+
tox -e py27
34
+
35
+
If you wish to run an individual test then you can run:
By default, the tests will look for a config file at 'tests/resources/config'
45
+
and use the ``DEFAULT`` profile. You can change this with the ``--config-file``
46
+
and ``--config-profile`` options.
47
+
48
+
.. code-block:: sh
49
+
50
+
# Use a different config file, still using the DEFAULT profile
51
+
tox -- --config-file ~/.oci/config
52
+
53
+
# Using a different profile in the default config file
54
+
tox -- --config-profile IAD_PROFILE
55
+
56
+
Specifying environment variables
57
+
--------------------------------
58
+
In addition to a valid config file for your tenancy, the tests also require the following environment
59
+
variables to be set:
60
+
61
+
* ``OCI_PYSDK_PUBLIC_SSH_KEY_FILE``: path to a public SSH key (.pub file) that will be given access to the instance launched in ``test_launch_instance_tutorial.py``.
62
+
63
+
Generating Documentation
64
+
========================
65
+
Sphinx is used for documentation. You can generate HTML locally with the following:
66
+
67
+
.. code-block:: sh
68
+
69
+
pip install -r requirements.txt
70
+
cd docs
71
+
make html
72
+
73
+
Generating the wheel
74
+
====================
75
+
The SDK is packaged as a wheel. In order to generate the wheel you can run:
The SDK uses `pytest` as its test framework. You can run tests against Python 2.7 Python 3.5 using the `tox` command. Note that this requires that you have those versions of Python installed,
73
-
otherwise you must pass `-e` or run tests directly:
74
-
75
-
.. code-block:: sh
76
-
77
-
# This will run tests against all configured Pythons in tox.ini (currently 2.7 and 3.5). You need to have those versions installed
78
-
tox
79
-
80
-
# This will run tests against a specific Python versions
81
-
tox -e py27
82
-
83
-
If you wish to run an individual test then you can run:
By default, the tests will look for a config file at 'tests/resources/config'
93
-
and use the ``DEFAULT`` profile. You can change this with the ``--config-file``
94
-
and ``--config-profile`` options.
95
-
96
-
.. code-block:: sh
97
-
98
-
# Use a different config file, still using the DEFAULT profile
99
-
tox -- --config-file ~/.oci/config
100
-
101
-
# Using a different profile in the default config file
102
-
tox -- --config-profile IAD_PROFILE
103
-
104
-
Specifying environment variables
105
-
--------------------------------
106
-
In addition to a valid config file for your tenancy, the tests also require the following environment
107
-
variables to be set:
108
-
109
-
* ``OCI_PYSDK_PUBLIC_SSH_KEY_FILE``: path to a public SSH key (.pub file) that will be given access to the instance launched in ``test_launch_instance_tutorial.py``.
110
-
111
-
Generating Documentation
112
-
========================
113
-
Sphinx is used for documentation. You can generate HTML locally with the following:
114
-
115
-
.. code-block:: sh
116
-
117
-
pip install -r requirements.txt
118
-
cd docs
119
-
make html
120
-
121
-
Generating the wheel
122
-
====================
123
-
The SDK is packaged as a wheel. In order to generate the wheel you can run:
The Python SDK uses Python's `logging <https://docs.python.org/3.6/library/logging.html>`_ module.
14
+
15
+
Loggers for the Python SDK are ordered hierarchically, with the top level being ``oci`` (or ``oraclebmc`` if you are using the legacy OracleBMC package).
16
+
17
+
Logger names are of the form ``<hierarchy>.<id>`` where the ``<hierarchy>`` is similar to ``oci.base_client`` and ``<id>`` is the result of Python's built-in ``id()`` function. The implication of this is that different instances of the same class have different loggers.
18
+
19
+
Request Logging
20
+
================
21
+
Logging of the requests which the Python SDK sends to OCI services can be enabled by setting the ``log_requests`` attribute to ``True`` in your configuration. This could be done in your configuration file, for example:
22
+
23
+
.. code-block:: text
24
+
25
+
[DEFAULT]
26
+
user = <user OCID>
27
+
fingerprint = <fingerprint>
28
+
key_file = <key file>
29
+
tenancy = <tenancy OCID>
30
+
region = us-ashburn-1
31
+
log_requests = True
32
+
33
+
Or programmatically, for example:
34
+
35
+
.. code-block:: python
36
+
37
+
config = {
38
+
"user": user_ocid,
39
+
"key_file": key_file,
40
+
"fingerprint": calc_fingerprint(key_file),
41
+
"tenancy": testrunner.tenancy,
42
+
"region": testrunner.region,
43
+
"log_requests": True
44
+
}
45
+
46
+
Once you have request logging in your config, you can create the appropriate logging handler(s) for your use case. For example to log to an output stream such as ``stderr`` you could do:
47
+
48
+
.. code-block:: python
49
+
50
+
import oci
51
+
import logging
52
+
53
+
config = oci.config.from_file()
54
+
config['log_requests'] =True
55
+
56
+
logging.basicConfig()
57
+
58
+
client = oci.identity.IdentityClient(config)
59
+
60
+
# This call will emit log information to stderr
61
+
client.list_regions()
62
+
63
+
Note that request logging occurs at the following levels:
64
+
65
+
* ``INFO``: Request method and request URL
66
+
* ``DEBUG``: Request headers and body, and response headers
0 commit comments