-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
648 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,3 +61,4 @@ target/ | |
#Ipython Notebook | ||
.ipynb_checkpoints | ||
.pypirc | ||
.DS_Store |
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 |
---|---|---|
@@ -1 +1,6 @@ | ||
# BreakingPoint-Controller-Shell | ||
# BreakingPoint-Controller-Shell | ||
![alt tag](https://travis-ci.org/QualiSystems/BreakingPoint-Controller-Shell.svg?branch=dev) | ||
[![Coverage Status](https://coveralls.io/repos/github/QualiSystems/BreakingPoint-Controller-Shell/badge.svg?branch=dev)](https://coveralls.io/github/QualiSystems/BreakingPoint-Controller-Shell?branch=dev) | ||
[![PyPI version](https://badge.fury.io/py/BreakingPoint-Controller-Shell.svg)](https://badge.fury.io/py/BreakingPoint-Controller-Shell) | ||
[![Dependency Status](https://dependencyci.com/github/QualiSystems/BreakingPoint-Controller-Shell/badge)](https://dependencyci.com/github/QualiSystems/BreakingPoint-Controller-Shell) | ||
[![Stories in Ready](https://badge.waffle.io/QualiSystems/BreakingPoint-Controller-Shell.svg?label=ready&title=Ready)](http://waffle.io/QualiSystems/BreakingPoint-Controller-Shell) |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
portalocker==1.1.0 | ||
cloudshell-shell-core>=3.1,<3.2 | ||
-e git+https://github.com/QualiSystems/cloudshell-tg-breaking-point.git@dev#egg=cloudshell-tg-breaking-point |
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,16 +1,12 @@ | ||
import os | ||
import portalocker | ||
|
||
|
||
class FileBasedLock(object): | ||
def __init__(self, lock_file_path): | ||
if os.path.exists(lock_file_path): | ||
self.__file_descriptor = open(lock_file_path, 'r') | ||
else: | ||
self.__file_descriptor = open(lock_file_path, 'w') | ||
self._file_descriptor = open(lock_file_path, 'w') | ||
|
||
def __enter__(self): | ||
portalocker.lock(self.__file_descriptor, portalocker.LOCK_EX) | ||
portalocker.lock(self._file_descriptor, portalocker.LOCK_EX) | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
self.__file_descriptor.close() | ||
self._file_descriptor.close() |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
portalocker==1.1.0 | ||
cloudshell-tg-breaking-point>=1.0,<1.1 | ||
cloudshell-shell-core>=3.1,<3.2 | ||
cloudshell-automation-api>=7.0,<7.1 | ||
cloudshell-shell-core>=3.1,<3.2 |
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,4 @@ | ||
nose | ||
coverage | ||
unittest2 | ||
mock |
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,2 @@ | ||
from pkgutil import extend_path | ||
__path__ = extend_path(__path__, __name__) |
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,2 @@ | ||
from pkgutil import extend_path | ||
__path__ = extend_path(__path__, __name__) |
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,96 @@ | ||
from mock import Mock, patch | ||
from unittest2 import TestCase | ||
|
||
from bp_controller.runners.bp_runner_pool import InstanceLocker, BPRunnersPool | ||
|
||
|
||
class TestInstanceLocker(TestCase): | ||
def setUp(self): | ||
self._lock = Mock() | ||
self._locked_instance = Mock() | ||
self._instance = self._create_instance() | ||
|
||
@patch('bp_controller.runners.bp_runner_pool.Lock') | ||
def _create_instance(self, lock_class): | ||
lock_class.return_value = self._lock | ||
instance = InstanceLocker(self._locked_instance) | ||
lock_class.assert_called_once_with() | ||
return instance | ||
|
||
def test_init(self): | ||
self.assertIs(self._instance._instance, self._locked_instance) | ||
|
||
def test_instance_prop(self): | ||
self.assertIs(self._instance.instance, self._locked_instance) | ||
|
||
def test_enter_exit(self): | ||
with self._instance as instance: | ||
self.assertIs(instance, self._locked_instance) | ||
self._lock.acquire.assert_called_once_with() | ||
self._lock.release.assert_called_once_with() | ||
|
||
|
||
class TestBPRunnersPool(TestCase): | ||
def setUp(self): | ||
self._context = Mock() | ||
self._instance = BPRunnersPool() | ||
|
||
def test_init(self): | ||
self.assertEqual(self._instance._runners, {}) | ||
|
||
@patch('bp_controller.runners.bp_runner_pool.InstanceLocker') | ||
@patch('bp_controller.runners.bp_runner_pool.BPTestRunner') | ||
@patch('bp_controller.runners.bp_runner_pool.get_logger_with_thread_id') | ||
@patch('bp_controller.runners.bp_runner_pool.get_api') | ||
def test_actual_runner_call_logger_and_api(self, get_api_func, get_logger_func, test_runner_class, | ||
instance_locker_class): | ||
actual_runner = self._instance.actual_runner(self._context) | ||
get_api_func.assert_called_once_with(self._context) | ||
get_logger_func.assert_called_once_with(self._context) | ||
|
||
@patch('bp_controller.runners.bp_runner_pool.InstanceLocker') | ||
@patch('bp_controller.runners.bp_runner_pool.BPTestRunner') | ||
@patch('bp_controller.runners.bp_runner_pool.get_logger_with_thread_id') | ||
@patch('bp_controller.runners.bp_runner_pool.get_api') | ||
def test_actual_runner_new_instance(self, get_api_func, get_logger_func, test_runner_class, | ||
instance_locker_class): | ||
logger_instance = Mock() | ||
api_instance = Mock() | ||
get_logger_func.return_value = logger_instance | ||
get_api_func.return_value = api_instance | ||
instance_locker_inst = Mock() | ||
test_runner_inst = Mock() | ||
instance_locker_class.return_value = instance_locker_inst | ||
test_runner_class.return_value = test_runner_inst | ||
reservation_id = Mock() | ||
self._context.reservation.reservation_id = reservation_id | ||
self.assertIs(self._instance.actual_runner(self._context), instance_locker_inst) | ||
instance_locker_class.assert_called_once_with(test_runner_inst) | ||
test_runner_class.assert_called_once_with(self._context, logger_instance, api_instance) | ||
self.assertIs(self._instance._runners[reservation_id], instance_locker_inst) | ||
|
||
@patch('bp_controller.runners.bp_runner_pool.InstanceLocker') | ||
@patch('bp_controller.runners.bp_runner_pool.BPTestRunner') | ||
@patch('bp_controller.runners.bp_runner_pool.get_logger_with_thread_id') | ||
@patch('bp_controller.runners.bp_runner_pool.get_api') | ||
def test_actual_runner_existing_instance(self, get_api_func, get_logger_func, test_runner_class, | ||
instance_locker_class): | ||
logger_instance = Mock() | ||
api_instance = Mock() | ||
get_logger_func.return_value = logger_instance | ||
get_api_func.return_value = api_instance | ||
reservation_id = Mock() | ||
self._context.reservation.reservation_id = reservation_id | ||
runner_instance = Mock() | ||
self._instance._runners[reservation_id] = runner_instance | ||
runner_locker = self._instance.actual_runner(self._context) | ||
self.assertIs(runner_locker, runner_instance) | ||
self.assertIs(runner_locker.instance.logger, logger_instance) | ||
self.assertIs(runner_locker.instance.api, api_instance) | ||
self.assertIs(runner_locker.instance.context, self._context) | ||
|
||
def test_class_all_runners(self): | ||
runner = Mock() | ||
self._instance._runners[Mock()] = runner | ||
self._instance.close_all_runners() | ||
runner.close.assert_called_once_with() |
Oops, something went wrong.