47 Commits

Author SHA1 Message Date
Hai Shi
1a954fb177 Refactor exceptions
In order to make exceptions could be used in raas,
so we need restructure the exception.

Change-Id: I3935c93fdbc10f045e0d7fcc8f6d36c78699181b
2017-05-18 20:33:33 +08:00
Andrey Kurilin
7682d0bbb2 [cleanup] Introduce matcher for real names
Our cleanup manager is designed to accept subclass of
`RandomNameGeneratorMixin` to match names of resources to particular
task.

The new method `make_name_matcher` creates a subclass of
`RandomNameGeneratorMixin` with overriden check method to check exact
names instead of matching to specific patterns.

Also, while checking all context to port to new matcher, proper
required_platform validators were added to all contexts.

Change-Id: I42b9af878630c0e8080f50c7b489346121704255
2017-04-26 17:25:06 +03:00
Anton Studenov
67ceee27a9 [Test] Fix randomly failing unit test
Because of BackupHelper.__del__ that uses os.path.exists,
there is a probability that __del__ will happen during running
of test_generate_random_path and it will grab a value
from mock.side_effect that as a result will lead to an error.

Solution:
Replace side_effect tuple with lambda-function that will
react to a specific value instead of hard coded return values.

Change-Id: I965041049079520a0aa354ddef32aeba047195ba
2017-03-06 19:13:34 +03:00
Andrey Kurilin
76565603a4 [verification] Introduce Tempest verifier
Co-Authored-By: Yaroslav Lobankov <ylobankov@mirantis.com>
Change-Id: I06c7e1d2c7956a1ad92e62484d84141ee926be08
2016-12-28 14:13:02 +02:00
Andrey Kurilin
d4ac0351d7 [verification] Introduce BackupHelper
This helper class provides mechanism for saving data at temporary folders and
process rollback if needed.

Co-Authored-By: Yaroslav Lobankov <ylobankov@mirantis.com>

Change-Id: If3555171b429039b54661f3af9d44ee0fc679181
2016-12-21 12:31:06 +04:00
Anton Studenov
03c8740588 New plugin type - Trigger
Triggers determine when hooks should be executed.
Added event trigger.
Added utils required for implementation of hook_section spec.

implements spec: hook_section

Change-Id: I33d558468f221a7c731e4a3fd42deb4f76be671a
2016-09-16 13:40:05 +03:00
Béla Vancsics
16f2fd8acc Use more specific asserts in tests
Instead of assertTrue and assertFalse use more specific asserts.
They are compatible with Python 2.7[1] and 3.4[2]

[1]: https://docs.python.org/2.7/library/unittest.html
[2]: https://docs.python.org/3.4/library/unittest.html

Change-Id: Id839997ff21c2b1fcf6701f4bc47babe61623817
2016-08-22 13:46:50 +02:00
Roman Vasilets
ff58044892 Fix output of small floats in results
For now we have output of small floats in scientific notation:
3.79085540771e-05
Fix that to 0.000037. Also floats in fixed place will output as:
  0.0000001 -> 0.0
  0.000000 -> 0.0
  37 -> 37.0
  1.0000001 -> 1.0
  1.0000011 -> 1.000001
  1.0000019 -> 1.000002

This can be made in different ways like:
  "%f" % float(decimal.Decimal(num).normalize())
or in more weird way but I choose that one (see in the patch) like
the most flat, simple and explicit.

Change-Id: I4b9cdbb01f3f8e2eeaedc9d33e1203247ea79f89
2016-07-19 18:54:25 +03:00
Roman Vasilets
5c4956cafb Fix runner timeout
Decided to put thread instance to timeout_queue because
thread.ident in python is recycled. So this is the way to
check whether the thread alive or not.

Closes-bug: #1570798

Change-Id: I745030ec9942c37b47c6d53864ae5fc7ecae7ccd
2016-05-16 18:29:23 +03:00
Alexander Maretskiy
9ff6383ab7 [Common] Add class rally.common.utils.LockedDict
Class LockedDict represents dict which is locked for updates
by default. It will be used in cases when we want to prevent
dict modification, like context configuration.

Usage of this class will be added in further patches.

Change-Id: I782e99bbe6d9ba4463103304ba152196eddd5227
2016-05-05 18:26:34 +03:00
Chris St. Pierre
0854c087e7 Add inexact matching to name_matches_object
This will support places where we create resources with names that
start with a given name pattern, but include some additional
identifier afterwards. For instance, when bulk creating instances,
Nova appends a UUID to each instance name.

Implements: blueprint cleanup-refactoring
Change-Id: Idaa8a8eb2f4edbc48cae324240623922537106a5
2016-03-16 08:47:10 -05:00
Chris St. Pierre
c948375b2e Add task_id argument to name_matches_object
This will be used to ensure that we are only deleting resources for a
particular Rally task.

Implements: blueprint cleanup-refactoring
Change-Id: I487a685987b7a5e1bae7e4695c470141ff8f6824
2016-03-08 10:01:12 -06:00
chen-li
2db0da8278 Use new-style Python classes
There are some classes in the code that didn't inherited from
nothing and this is an old-style classes. A "New Class" is the
recommended way to create a class in modern Python.A "New Class"
should always inherit from `object` or another new-style class.

Hacking rule added as well.

Change-Id: I2c72f20695e35e05435d2526d4a804196c2ab2d3
2016-02-20 00:52:43 +08:00
Jenkins
6d2184ff94 Merge "Let TempestResourcesContext implements utils.RandomNameGeneratorMixin" 2016-01-07 21:17:24 +00:00
Bo Chi
aaa561853b Let TempestResourcesContext implements utils.RandomNameGeneratorMixin
TempestResourcesContext calls NeutronWrapper.create_network, and it will
be called to generate random name, so it needs to implements
utils.RandomNameGeneratorMixin
Changed generate_random_name to use self.task["uuid"] or
self.verification["uuid"] as task_id
This patch also refactor test__create_network_resources to test the
logic correctly

Change-Id: I8c145073386cb7f668461e050fe8de75f4675def
Closes-Bug: #1530770
2016-01-07 16:02:17 -05:00
Roman Vasilets
02c4d40ad9 Fix timeout for scenario runners
Timeout for scenario runners doesn't work correctly.
To reproduce it just put in Dummy scenario args sleep bigger
then timeout and it won't fail, that will verify this bug.

Tasks are running in threads, so we need a way to kill threads.
New function `terminate_thread` added for this purpose.

Also added function that is run in separate thread and check
execution time of the threads. If they run longer then timeout
they would be terminated by terminate_thread.

Thread can not be killed during system call, so this mechanism
isn't 100% effective. Due to this interruptable_sleep method
was added in order to be used by Dummy scenarios.

Added timeout argument to constant and rps runners. Also added
two Dummy scenarios to test this.

New exception ThreadTimeoutException was added.

Closes-Bug: #1385365

Co-Authored-By: Roman Vasilets <rvasilets@mirantis.com>
Co-Authored-By: Sergey Scripnick <sskripnick@mirantis.com>

Change-Id: I2096ba6adaf81a18c80b2ae6a759ccc9e247c45a
2015-11-30 18:27:14 +02:00
Chris St. Pierre
eb8f9dc976 Remove old random name generator
Kill the old random name generator in favor of the fancy new one.

Implements blueprint: consistent-resource-names
Change-Id: Ia612ebb3ed3af27c6aaa1e35f459b7980b7a24b9
2015-11-26 15:43:50 +00:00
Jenkins
768fcbc3df Merge "Improve rally.common.utils.RAMInt code" 2015-11-12 12:05:08 +00:00
Boris Pavlovic
fdd366570d Improve rally.common.utils.RAMInt code
*) There is no need to create extra lock object. There is already
   instance of lock object in multiprocessing.Value

*) Improve the tests. Unit tests should test that method properly
   work and not mock everything to check what is in each python line
   (which is anti pattern in unit testing)

Change-Id: I7cc102aae0e083e2fccf98cbc21f8f43cef8d454
2015-11-11 18:00:52 -08:00
Jenkins
695abe2f63 Merge "Fix 'merge lists'" 2015-11-06 18:18:24 +00:00
Illia Khudoshyn
0176fb5f2d Fix 'merge lists'
rally.common.utils.merge now produces lists
of given length rather than ones with length greater or equal to.

Change-Id: I95f0eae869281b9ab65ea8e6a5b82918ed9faac6
2015-11-05 12:39:36 +00:00
Chris St. Pierre
9a2e42be28 Make name_matches_object accept list of objects
This makes it easier and more efficient to check randomly-generated
names against multiple objects to see if they could have been
generated by any of the given objects.

Implements blueprint: consistent-resource-names
Change-Id: I0c7b7bc9bd65738984bf5b156a6c249756aaf4fe
2015-11-04 21:42:03 -06:00
Illia Khudoshyn
ef656301d6 Add 'merge lists' function
The function added in the patch is to be used as an auxiliary
tool in a forthcoming implementation of distribluted load generation
functionality

Change-Id: I482d0e81a92eb9e783b73120478f98149fbcba96
2015-11-02 11:35:19 +00:00
Bo Chi
4bfbeb271d Refactoring log utils
* Moved log functions from rally/common/utils.py #L137-L234 to rally/common/log.y
* Moved test tunctions form test/unit/common/test_utils.py to test/unit/common/test_log.py

Change-Id: Icac3e87d507a3cf90e27071cb26bc871dac78514
2015-11-01 01:40:30 -05:00
Chris St. Pierre
9ff41768a8 Fix random name bug if task uuid is too short
If the task UUID passed to generate_random_name() was shorter than the
first set of Xs in the pattern, the UUID would be used which would
result in a random name that was too short and thus didn't match the
pattern. This fixes that.

Implements blueprint: consistent-resource-names
Closes-Bug: 1509402
Change-Id: I4f8a4415d565dbf737588a4db56fc2a6dfe893cc
2015-10-26 17:49:04 -05:00
Chris St. Pierre
dca522a99e Enable ddt on random name generator tests
It was already trying to use DDT, it just wasn't enabled for the
class.

Implements blueprint: consistent-resource-names
Change-Id: Ie9c4f59951e4e2e0d82c5aa9b493668f38ea30e6
2015-10-23 10:21:24 -05:00
Andrey Kurilin
2644c666c6 Change message of log_deprecated decorator
It is unclear what is deprecated in current message.

For example, methods `wait_for`, `wait_is_ready` and `wait_for_delete` were
deprecated in https://review.openstack.org/#/c/232438 . Deprecation
messages are equal, so logs are equal too:

    Deprecated, use wait_for_status instead. (deprecated in Rally v0.1.2)

This patch adds deprecated method's name, so it is easier to determine what
method produces deprecation log message.

Also, this patch adds ability to print warning message once, which can be
helpful for deprecated methods used in scenarios.

Change-Id: Id86e984986ecb61e7b92cc61882382179fc8a74b
2015-10-09 17:09:56 +03:00
Chris St. Pierre
18141cb71c Better random resource name generator
This adds a new random name generator that will make it easier to do
out-of-band cleanup of Rally-created resources. It eliminates the
ability for scenarios to specify a custom random name length and
prefix; adds a task-specific portion to the random name; and improves
configurability of random name patterns.

Subsequent commits will implement the new generator.

Implements: blueprint consistent-resource-names
Change-Id: I189474fbb185ab402e3b248421b4188b7ccde7f4
2015-10-07 16:15:08 -05:00
Boris Pavlovic
0ad839d19e [cli] Introduce "rally plugin" show and list commands
This patch does a few things

- Introduce rally.common.plugin.info.InfoMixin
  and adds it to plugin base. It adds method get_info()
  to all plugins. This method returns information about plugin
  such like title, description, arguments, plugin module

- Introduce rally plugin show and list commands that returns
  information about all plugins

- Moves info related methods from rally.common.utils to
  rally.common.plugin.info module

Related-Bug: #1470895
Change-Id: I8db12e3017d241a2b8bc549a817dad817f922437
2015-09-16 14:22:16 -07:00
Yuki Nishiwaki
86e8f94763 Add unit test for common.utils.EnumMixin
Add following unit test for common.utils.EnumMixin
 - Check if the name of variable start underscore (like _a), don't return value in iterate

Change-Id: Ief17f1012a0fd6b7917d5a031e03f45e5d963123
Closes-Bug: #1473331
2015-07-10 18:08:02 +09:00
Jenkins
ac31a82f2d Merge "unit-tests: fix mocks' naming" 2015-06-22 19:56:33 +00:00
Jenkins
e908c5ef25 Merge "utils: make parse_docstring respect multi-line" 2015-06-20 03:47:44 +00:00
Pavel Boldin
9076679fef unit-tests: fix mocks' naming
Fix mocks' argument/decorator naming.

Partial-Bug: #1462956
Change-Id: I8366736f3bc7088f867eec1fc72630dbe1bcf19e
2015-06-19 22:57:34 +03:00
Boris Pavlovic
2aadcf4ebe Add rally.common.plugin.discover module
Move all related to plugins from utils to discover module
and fix the code and tests to make it work

Change-Id: Ifaed1fadfa0760f121cb1584cb4d8ae3fee8768d
2015-06-17 11:19:05 +00:00
Pavel Boldin
eee3cf1ae9 utils: make parse_docstring respect multi-line
Make `parse_docstring' respect multi-line param docs and fix it not matching
the **kwargs.

Change-Id: Ic6cd6e89f94ff0656126b08b4fe563562cbd655c
2015-06-11 01:14:04 +03:00
Ilya Shakhat
71d01a6a23 Make plugins location configurable
The patch introduces CLI option --plugin-paths to specify the list of
folders with plugins.

Co-Authored-By: Roman Vasilets <rvasilets@mirantis.com>
Co-Authored-By: Ilya Shakhat <ishakhat@mirantis.com>

Change-Id: Iee39217bfe3e5c77e6925910f3998942541387a3
2015-06-05 01:21:24 +03:00
Jenkins
5101f71c94 Merge "Add function decorator `log_deprecated_args'" 2015-04-22 22:33:18 +00:00
Pavel Boldin
3db7200ab6 Add function decorator `log_deprecated_args'
Add decorator `log_deprecated_args' that issues a message whenever
the decorated function is called with deprecated keyword arguments
supplied.  Message is issued only once or per each call depending
on the configuration.

Change-Id: Icedf72c40d9255f8d82233ebf640165d4827d53b
2015-04-22 17:11:23 +03:00
Hugh Ma
98cde5e8c5 Data structs declared with constructor replaced with literal
Changes:
  - list() declarations replaced with []
  - dict() declarations replaced with {}
  - Added N351 to hacking for literal rule along with checks, test hacking, and to readme
  - Minor fix to incorrect path in hacking guidelines pointing to test_hacking.py

Change-Id: Ie7b9201d61b6f2024217b6f4117605eb52fa916a
Closes-Bug: #1437515
2015-04-14 10:49:17 -07:00
Boris Pavlovic
7ce9ec92b4 Improve hacking and remove useless unit tests
* Remove tests/unit/aas and test/unit/fixture
  fixtures are not used so just remove them
  aas - didn't have __init__.py files so these
  tests were not executed at all. By the way
  code related to this tests was removed earlier
  in this patch:
  https://review.openstack.org/#/c/152847/

* Remove all old py3 related hacking rules
  Now we have unit & functional jobs that checks them

* Add new hacking rule that protect us from usage of '

* Unified signature of all hacking methods
  (otherwise we are not able to make decorator)

* Add hacking rules decorator for skiping 3 types of lines:
  empty, commented, and with # noqa comment

Change-Id: I6bf2cc123325a4980edeb066a6c31aa685858f5b
2015-03-16 14:55:17 +03:00
Jenkins
14fa3bd655 Merge "Replace ' with " in tests/unit/[common,deploy,doc,fixtures]" 2015-02-04 10:07:33 +00:00
jacobliberman
3498071401 Replace ' with " in tests/unit/[common,deploy,doc,fixtures]
Partial bug: 1405884

Change-Id: I0100649c32bb911dab345c40492aa148ed1832c6
2015-02-03 10:48:15 -06:00
Mikhail Dubov
e2a204d35b Refactor rally.api
* Move API methods to classes, make them @classmethod
* s/deploy/deployment

Also modify unit tests.

We leave the old API methods for compability, but they are going to be
deprecated in Rally v0.0.2.

Change-Id: I44155575621c715af1109690ed2788663a4c36c3
2015-02-03 15:34:49 +03:00
Andrey Kurilin
712a6fa482 Fix all py3 related issues
This patch makes output of `tox -epy34` to finish with following message:
>  py34: commands succeeded
>  congratulations :)

Issues:
 * module "__builtin__" was renamed to "builtins" in Python 3

   Related modules:
    - rally.api
    - tests.unit.benchmark.scenarios.vm.test_utils

 * function "map"/"filter" returns "builtins.map"/"builtins.filter" object
   in Python 3 instead of list in Python 2. "builtins.map" and
   "builtins.filter" object is not subscriptable and has no len(), so list
   comprehension is preferable to use and py2/py3 compatible way.

   Related modules:
    - rally.benchmark.context.sahara.sahara_edp
    - rally.benchmark.processing.plot
    - rally.benchmark.sla.base
    - rally.benchmark.types
    - rally.cmd.commands.task
    - rally.cmd.commands.verify
    - tests.unit.benchmark.scenarios.test_base
    - tests.unit.benchmark.wrappers.test_keystone
    - tests.unit.cmd.commands.test_task
    - tests.unit.cmd.commands.test_verify

 * dict.keys()/dict.values() returns "dict_keys"/"dict_values" object in
   Python 3 instead of list in Python 2. so list(dict) and
   list(dict.values()) should be used instead.

   Related modules:
    - rally.benchmark.scenarios.utils
    - rally.benchmark.scenarios.vm.vmtasks
    - tests.unit.cmd.commands.test_show
    - tests.unit.common.test_broker
    - tests.unit.deploy.engines.test_fuel
    - tests.unit.fakes

 * Some changes was made in Python 3 related to data model, so we should
   change our inspect code. See code changes for more details

   Related modules:
    - rally.cmd.cliutils
    - rally.common.utils

 * ConfigParser is more strict for duplicate items in Python 3, so
   duplicates are removed

   Related files:
    - rally/verification/tempest/config.ini

 * Exception object doesn't have "message" attribute in Python 3, so
   if we want to get it, the most proper way is using "getattr"

   Related modules:
    - rally.verification.tempest.config

 * "mock.MagicMock" is not sortable in Python 3, so we should add required
   attributes to fix that.

   Related modules:
    - tests.unit.benchmark.context.test_base

 * assertSequenceEqual assertation method was added in tests.unit.test to
   compare sequence objects

   Related modules:
    - tests.unit.benchmark.context.cleanup.test_resources
    - tests.unit.benchmark.scenarios.nova.test_utils

 * function "range" returns "range" object in Python 3 instead of list
   in Python 2.

   Related modules:
    - tests.unit.benchmark.processing.test_utils

 * keyword arguments should be transmitted to self.assertRaises as kwargs,
   not like a dict

   Related modules:
    - tests.unit.benchmark.scenarios.dummy.test_dummy

Additional changes:
 * Python 2.6 was added to setup.cfg, since Rally supports it.
 * py33, py34 environments were added to tox.ini
 * wrong ignore path was removed from tox.ini
 * made items of bash complition sorted

Several tests are skipped in Python 3 env. For more details see notes in code:
 - tests.unit.benchmark.processing.test_plot.PlotTestCase.test__process_main_time
 - tests.unit.benchmark.processing.test_plot.PlotTestCase.test__process_atomic_time
 - tests.unit.common.test_utils.MethodClassTestCase.test_method_class_for_class_level_method

During porting Rally to Python3, several issues found and fixed in
TempestContext and its unit tests:

 - If process of cleanup is failed, exception is handled and cleanup is
   marked as successfull. This issue was fixed and CleanUpException was
   added to rally.exception module
 - Cleanup was called with wrong path.

Change-Id: If04e873790dcb4c9c882d4be4bf40479deedd36d
2015-01-26 15:18:36 +00:00
Andrey Kurilin
0f7c504bee Fix py3k issues
1) Module urllib2 is missed in Python 3, so it should be replaced by other
   http lib. "requests" is good library for such stuff, which supports both
   Python 2.* and Python 3.*

2) Function 'rally.common.utils.parse_docstring' uses built-in function
   'filter'. This function returns different types in Python 2.* and
   Python 3.*. Since results are used as a list, 'filter' should be replaced
   by list comprehension.

3) Extend H330 hacking rule to chech 'dict.iterkeys()', 'dict.itervalues()'
   and 'dict.iterlist()'. Also, fixed all places, which are failed in terms
   of this rule.

4) Function object does not have 'func_code' attribute in Python 3, but
   '__code__' attribute exist in both Python 2 and Python 3

Also, 3 tests are broken due to new release(1.6.0) of oslo.config, so we
need to skip them to unblock our gates until new version of oslo.config will
be released with appropriate fix.

Closes-Bug: #1405919

Change-Id: Icc42e220ac3f15ae6c838a4698b3c9578177513c
2015-01-06 13:01:30 +02:00
li,chen
63378f526d use function next() instead of next() method on iterator objects
Python 3 introduced a next() function to replace the next() method on
iterator objects. Rather than calling the method on the iterator, the next()
function is called with the iterable object as it's sole parameter, which
calls the underlying __next__() method.

The next() function was backported to Python 2.6 which allows us to use either
the 2.x or 3.x way simultaneously.

Change-Id: I945225b1b0c6c39842a77f4a136e9431b798229f
Closes-Bug: #1403074
2015-01-02 15:41:25 +02:00
liyingjun
a7e2a8e4f5 Move files to common lib(Part 3)
Move utils to common directory.

Change-Id: Ifaf71ea4a2a1acc85ceb2af6ed978d3e08666b41
2014-12-31 09:21:14 +08:00