Various cleanups

Change-Id: I311f694d2e2e92468d3345d0da3f550fffa560ee
This commit is contained in:
Boris Pavlovic 2014-11-17 23:58:44 +04:00
parent bc78823f29
commit c2e9a73b3f
5 changed files with 52 additions and 69 deletions

View File

@ -61,7 +61,7 @@ def split(text, strip=True):
return text.split(",")
def binary_encode(text, encoding='utf-8'):
def binary_encode(text, encoding="utf-8"):
"""Converts a string of into a binary type using given encoding.
Does nothing if text not unicode string.
@ -74,7 +74,7 @@ def binary_encode(text, encoding='utf-8'):
raise TypeError("Expected binary or string type")
def binary_decode(data, encoding='utf-8'):
def binary_decode(data, encoding="utf-8"):
"""Converts a binary type into a text type using given encoding.
Does nothing if data is already unicode string.
@ -133,7 +133,7 @@ def signed_unpack(data, hmac_data, hmac_keys):
try:
contents = json.loads(
binary_decode(base64.urlsafe_b64decode(data)))
contents['hmac_key'] = hmac_key
contents["hmac_key"] = hmac_key
return contents
except Exception:
return None
@ -161,12 +161,12 @@ def import_modules_from_package(package):
:param: package - Full package name. For example: rally.deploy.engines
"""
path = [os.path.dirname(__file__), '..'] + package.split('.')
path = [os.path.dirname(__file__), ".."] + package.split(".")
path = os.path.join(*path)
for root, dirs, files in os.walk(path):
for filename in files:
if filename.startswith('__') or not filename.endswith('.py'):
if filename.startswith("__") or not filename.endswith(".py"):
continue
new_package = ".".join(root.split(os.sep)).split("....")[1]
module_name = '%s.%s' % (new_package, filename[:-3])
module_name = "%s.%s" % (new_package, filename[:-3])
__import__(module_name)

View File

@ -10,27 +10,21 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.min.js"></script>
<script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.js"></script>
<style>
.trace {
min-width: 900px;
width: 100%;
}
.trace tr.active-true {
background-color: #D9EDF7!important;
}
.trace tr td {
width: 14%;
white-space: nowrap;
padding: 2px;
border-right: 1px solid #eee;
}
.trace tr td.details {
width: 10%;
@ -43,11 +37,9 @@
width: 10%;
font-weight: bold;
}
.bold {
font-weight: bold;
}
.duration {
width: 25px;
margin: 0px;
@ -55,9 +47,7 @@
background-color: #c6eff3;
border-radius: 4px;
font-size: 10px;
}
.duration div{
padding-top: 4px;
padding-bottom: 4px;
@ -91,13 +81,11 @@
</tr>
</table>
<div ng-hide="hide_children">
<div ng-repeat="data in data.children" ng-include="'tree_item_renderer.html'"> </div>
</div>
</div>
</script>
<script>
@ -170,8 +158,7 @@
'<div class="modal-header"> Trace Point Details </div>' +
'<div class="modal-body">' + trace_data + '</div>' +
'<div class="modal-footer"> <span class="glyphicon glyphicon-cloud </div>'
)
);
var modal_instance = $modal.open({
"template": output,
@ -180,7 +167,6 @@
}
$scope.tree = [convert_input(OSProfilerData)];
}
</script>
@ -188,9 +174,6 @@
<body>
<div ng-controller="ProfilerCtlr">
<table>
</table>
<table class="trace">
<tr class="bold text-left" style="border-bottom: solid 1px gray">
<td class="level">Levels</td>

View File

@ -234,7 +234,7 @@ class _Profiler(object):
self._name.append(name)
self._trace_stack.append(str(uuid.uuid4()))
self._notify('%s-start' % name, info)
self._notify("%s-start" % name, info)
def stop(self, info=None):
"""Finish latests event.
@ -248,12 +248,12 @@ class _Profiler(object):
def _notify(self, name, info):
payload = {
'name': name,
'base_id': self.get_base_id(),
'trace_id': self.get_id(),
'parent_id': self.get_parent_id()
"name": name,
"base_id": self.get_base_id(),
"trace_id": self.get_id(),
"parent_id": self.get_parent_id()
}
if info:
payload['info'] = info
payload["info"] = info
notifier.notify(payload)

View File

@ -22,8 +22,8 @@ from osprofiler import profiler
# Trace keys that are required or optional, any other
# keys that are present will cause the trace to be rejected...
_REQUIRED_KEYS = ('base_id', 'hmac_key')
_OPTIONAL_KEYS = ('parent_id',)
_REQUIRED_KEYS = ("base_id", "hmac_key")
_OPTIONAL_KEYS = ("parent_id",)
def get_trace_id_headers():

View File

@ -30,34 +30,34 @@ class ShellTestCase(test.TestCase):
super(ShellTestCase, self).setUp()
self.old_environment = os.environ.copy()
os.environ = {
'OS_USERNAME': 'username',
'OS_USER_ID': 'user_id',
'OS_PASSWORD': 'password',
'OS_USER_DOMAIN_ID': 'user_domain_id',
'OS_USER_DOMAIN_NAME': 'user_domain_name',
'OS_PROJECT_DOMAIN_ID': 'project_domain_id',
'OS_PROJECT_DOMAIN_NAME': 'project_domain_name',
'OS_PROJECT_ID': 'project_id',
'OS_PROJECT_NAME': 'project_name',
'OS_TENANT_ID': 'tenant_id',
'OS_TENANT_NAME': 'tenant_name',
'OS_AUTH_URL': 'http://127.0.0.1:5000/v3/',
'OS_AUTH_TOKEN': 'pass',
'OS_CACERT': '/path/to/cacert',
'OS_SERVICE_TYPE': 'service_type',
'OS_ENDPOINT_TYPE': 'public',
'OS_REGION_NAME': 'test'
"OS_USERNAME": "username",
"OS_USER_ID": "user_id",
"OS_PASSWORD": "password",
"OS_USER_DOMAIN_ID": "user_domain_id",
"OS_USER_DOMAIN_NAME": "user_domain_name",
"OS_PROJECT_DOMAIN_ID": "project_domain_id",
"OS_PROJECT_DOMAIN_NAME": "project_domain_name",
"OS_PROJECT_ID": "project_id",
"OS_PROJECT_NAME": "project_name",
"OS_TENANT_ID": "tenant_id",
"OS_TENANT_NAME": "tenant_name",
"OS_AUTH_URL": "http://127.0.0.1:5000/v3/",
"OS_AUTH_TOKEN": "pass",
"OS_CACERT": "/path/to/cacert",
"OS_SERVICE_TYPE": "service_type",
"OS_ENDPOINT_TYPE": "public",
"OS_REGION_NAME": "test"
}
self.ceiloclient = mock.MagicMock()
sys.modules['ceilometerclient'] = self.ceiloclient
self.addCleanup(sys.modules.pop, 'ceilometerclient', None)
ceilo_modules = ['client', 'exc', 'shell']
sys.modules["ceilometerclient"] = self.ceiloclient
self.addCleanup(sys.modules.pop, "ceilometerclient", None)
ceilo_modules = ["client", "exc", "shell"]
for module in ceilo_modules:
sys.modules['ceilometerclient.%s' % module] = getattr(
sys.modules["ceilometerclient.%s" % module] = getattr(
self.ceiloclient, module)
self.addCleanup(
sys.modules.pop, 'ceilometerclient.%s' % module, None)
sys.modules.pop, "ceilometerclient.%s" % module, None)
def tearDown(self):
super(ShellTestCase, self).tearDown()
@ -66,9 +66,9 @@ class ShellTestCase(test.TestCase):
@mock.patch("sys.stdout", six.StringIO())
@mock.patch("osprofiler.cmd.shell.OSProfilerShell")
def test_shell_main(self, mock_shell):
mock_shell.side_effect = exc.CommandError('some_message')
mock_shell.side_effect = exc.CommandError("some_message")
shell.main()
self.assertEqual('some_message\n', sys.stdout.getvalue())
self.assertEqual("some_message\n", sys.stdout.getvalue())
def run_command(self, cmd):
shell.OSProfilerShell(cmd.split())
@ -80,8 +80,8 @@ class ShellTestCase(test.TestCase):
self.assertEqual(str(actual_error), expected_message)
else:
raise ValueError(
'Expected: `osprofiler.cmd.exc.CommandError` is raised with '
'message: "%s".' % expected_message)
"Expected: `osprofiler.cmd.exc.CommandError` is raised with "
"message: '%s'." % expected_message)
def test_username_is_not_presented(self):
os.environ.pop("OS_USERNAME")
@ -117,13 +117,13 @@ class ShellTestCase(test.TestCase):
self._test_with_command_error("trace show fake-uuid", msg)
def test_trace_show_ceilometrclient_is_missed(self):
sys.modules['ceilometerclient'] = None
sys.modules['ceilometerclient.client'] = None
sys.modules['ceilometerclient.exc'] = None
sys.modules['ceilometerclient.shell'] = None
sys.modules["ceilometerclient"] = None
sys.modules["ceilometerclient.client"] = None
sys.modules["ceilometerclient.exc"] = None
sys.modules["ceilometerclient.shell"] = None
self.assertRaises(ImportError, shell.main,
'trace show fake_uuid'.split())
"trace show fake_uuid".split())
def test_trace_show_unauthorized(self):
class FakeHTTPUnauthorized(Exception):
@ -169,8 +169,8 @@ class ShellTestCase(test.TestCase):
def test_trace_show_in_json(self, mock_notifications, mock_get):
mock_get.return_value = "some notification"
notifications = {
'info': {
'started': 0, 'finished': 0, 'name': 'total'}, 'children': []}
"info": {
"started": 0, "finished": 0, "name": "total"}, "children": []}
mock_notifications.return_value = notifications
self.run_command("trace show fake_id --json")
@ -184,8 +184,8 @@ class ShellTestCase(test.TestCase):
mock_get.return_value = "some notification"
notifications = {
'info': {
'started': 0, 'finished': 0, 'name': 'total'}, 'children': []}
"info": {
"started": 0, "finished": 0, "name": "total"}, "children": []}
mock_notifications.return_value = notifications
#NOTE(akurilin): to simplify assert statement, html-template should be
@ -216,8 +216,8 @@ class ShellTestCase(test.TestCase):
def test_trace_show_write_to_file(self, mock_notifications, mock_get):
mock_get.return_value = "some notification"
notifications = {
'info': {
'started': 0, 'finished': 0, 'name': 'total'}, 'children': []}
"info": {
"started": 0, "finished": 0, "name": "total"}, "children": []}
mock_notifications.return_value = notifications
with mock.patch("osprofiler.cmd.commands.open",