-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CTS v3 query traces implemented (#487)
CTS v3 query traces implemented Reviewed-by: Vineet Pruthi
- Loading branch information
1 parent
c878261
commit 57fe026
Showing
9 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ CTS Resources | |
v1/trace | ||
v1/tracker | ||
v3/key_event | ||
v3/trace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
otcextensions.sdk.ctsv3.v3.trace | ||
================================ | ||
|
||
.. automodule:: otcextensions.sdk.ctsv3.v3.trace | ||
|
||
The CTS Trace Class | ||
----------------------- | ||
|
||
The ``Trace`` class inherits from | ||
:class:`~otcextensions.sdk.sdk_resource.Resource`. | ||
|
||
.. autoclass:: otcextensions.sdk.ctsv3.v3.trace.Trace | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
""" | ||
List Cloud Trace Service Traces | ||
""" | ||
|
||
import openstack | ||
|
||
openstack.enable_logging(True) | ||
conn = openstack.connect(cloud='otc') | ||
attrs = { | ||
'trace_type': 'system', | ||
'limit': 2 | ||
} | ||
traces = list(conn.ctsv3.traces(**attrs)) | ||
print(traces) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from openstack import resource | ||
|
||
|
||
class BaseUserSpec(resource.Resource): | ||
id = resource.Body('id') | ||
name = resource.Body('name') | ||
|
||
|
||
class UserInfoSpec(resource.Resource): | ||
id = resource.Body('id') | ||
name = resource.Body('name') | ||
domain = resource.Body('domain', type=BaseUserSpec) | ||
|
||
|
||
class MetaDataSpec(resource.Resource): | ||
count = resource.Body('count', type=int) | ||
marker = resource.Body('marker') | ||
|
||
|
||
class Trace(resource.Resource): | ||
base_path = '/traces' | ||
resources_key = 'traces' | ||
|
||
allow_list = True | ||
|
||
_query_mapping = resource.QueryParameters( | ||
'trace_type', 'limit', 'from', 'next', 'to', 'tracker_name', | ||
'service_type', 'user', 'resource_id', 'resource_name', | ||
'resource_type', 'trace_id', 'trace_name', 'trace_rating') | ||
|
||
resource_id = resource.Body('resource_id') | ||
trace_name = resource.Body('trace_name') | ||
trace_rating = resource.Body('trace_rating') | ||
trace_type = resource.Body('trace_type') | ||
request = resource.Body('request') | ||
response = resource.Body('response') | ||
code = resource.Body('code') | ||
api_version = resource.Body('api_version') | ||
message = resource.Body('message') | ||
record_time = resource.Body('record_time') | ||
trace_id = resource.Body('trace_id') | ||
time = resource.Body('time') | ||
user = resource.Body('user', type=UserInfoSpec) | ||
service_type = resource.Body('service_type') | ||
resource_type = resource.Body('resource_type') | ||
source_ip = resource.Body('source_ip') | ||
resource_name = resource.Body('resource_name') | ||
request_id = resource.Body('request_id') | ||
location_info = resource.Body('location_info') | ||
endpoint = resource.Body('endpoint') | ||
resource_url = resource.Body('resource_url') |
24 changes: 24 additions & 0 deletions
24
otcextensions/tests/functional/sdk/ctsv3/v3/test_traces.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from otcextensions.tests.functional.sdk.ctsv3 import TestCtsv3 | ||
|
||
|
||
class TestTraces(TestCtsv3): | ||
|
||
def test_01_list_traces(self): | ||
attrs = { | ||
'trace_type': 'system', | ||
'limit': 2 | ||
} | ||
traces = list(self.conn.ctsv3.traces(**attrs)) | ||
self.assertGreater(len(traces), 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from openstack.tests.unit import base | ||
from otcextensions.sdk.ctsv3.v3 import trace | ||
|
||
EXAMPLE = { | ||
"time": 1472148708232, | ||
"user": { | ||
"name": "xxx", | ||
"domain": { | ||
"name": "xxx", | ||
"id": "ded649d814464428ba89d04d7955c93e" | ||
} | ||
}, | ||
"response": { | ||
"code": "VPC.0514", | ||
"message": "Update port fail." | ||
}, | ||
"code": 200, | ||
"service_type": "VPC", | ||
"resource_type": "eip", | ||
"resource_name": "192.144.163.1", | ||
"resource_id": "d502809d-0d1d-41ce-9690-784282142ccc", | ||
"trace_name": "deleteEip", | ||
"trace_rating": "warning", | ||
"trace_type": "ConsoleAction", | ||
"api_version": "2.0", | ||
"record_time": 1481066128032, | ||
"trace_id": "e001ccb9-bc09-11e6-b00b-4b2a61338db6" | ||
} | ||
|
||
|
||
class TestTrace(base.TestCase): | ||
def test_basic(self): | ||
sot = trace.Trace() | ||
self.assertEqual('/traces', sot.base_path) | ||
self.assertTrue(sot.allow_list) | ||
|
||
def test_make_it(self): | ||
sot = trace.Trace(**EXAMPLE) | ||
self.assertEqual(EXAMPLE['time'], sot.time) | ||
self.assertEqual(EXAMPLE['user']['name'], sot.user.name) |