Skip to content

Instantly share code, notes, and snippets.

View boris-42's full-sized avatar
:octocat:

Boris Pavlovic boris-42

:octocat:
View GitHub Profile
#To add new points in code you have 4 ways:
from osprofiler import profiler
def some_func():
profiler.start("point_name", {"any_key": "with_any_value"})
# your code
profiler.stop({"any_info_about_point": "in_this_dict"})
@profiler.trace("point_name",
@boris-42
boris-42 / gist:bd81f44287a3e8c4a402
Created January 7, 2015 22:59
Python mocking 2 or more open() calls in method
import mock
@mock.patch("<path_to_module_with_function>.open", create=True)
def test_some_your_method(self, mock_open):
mock.open.side_effect = [
mock.mock_open(read_data="Data from file 1").return_value,
mock.mock_open(read_data="Data from file 2").return_value
]
@boris-42
boris-42 / gist:2d3ee67d7679b9db4565
Last active August 29, 2015 14:13
Rally templates (image tester)
---
VMTasks.boot_runcommand_delete:
{% for flavor in flavors %}
{% for image in images %}
-
args:
flavor:
name: {{flavor}}
image:
---
title: "Certification Tasks"
description: "This task allows you to certify that you cloud works"
<abbility_to_extend_with_new_keys>: <and_values>
tasks:
-
title: "First task to execute"
description: "We will use "
scenario:
---
NovaServers.boot_and_delete_server:
{% for i in range(10) %}
-
args:
flavor:
name: "m1.nano"
image:
name: "^cirros.*uec$"
force_delete: false
Dummy.dummy_exception:
-
args:
size_of_message: 5
runner:
type: "constant"
times: 20
concurrency: 5
def check_quotes(logical_line):
"""Raise lint error when using ' instead of " """
# if there is no double quote sign there's nothing to do
if not logical_line or logical_line.strip().startswith("#"):
return
in_string = False
single_quotas_are_used = False
i = 0
{
"total_size": 173,
"start": 0,
"next_collection_link": "https://blueprints.launchpad.net/api/devel/rally/all_specifications?ws.size=75&memo=75&ws.start=75",
"entries": [
{
"starter_link": "https://blueprints.launchpad.net/api/devel/~boris-42",
"linked_branches_collection_link": "https://blueprints.launchpad.net/api/devel/rally/+spec/api-base/linked_branches",
"lifecycle_status": "Started",
"title": "Base for all REST API stuff",
@boris-42
boris-42 / test.py
Last active January 8, 2016 17:46
oslo.utils testing
import time
from oslo_utils import reflection
REPEAT = 1000000
RANGE = range(REPEAT)
class A(object):
import time
from rally import consts
from rally import exceptions
from rally.task import context
@context.configure(name="sleep_context", order=100500)
class SleepContext(context.Context):
"""Dummy context."""