Skip to content

Commit b4d69fa

Browse files
author
msrba
committed
add get_workloads to utils
1 parent 5e667af commit b4d69fa

File tree

6 files changed

+37
-0
lines changed

6 files changed

+37
-0
lines changed

scotty/core/components.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ def __init__(self):
7272
self.module = None
7373
self.parent_module_name = 'scotty.workload'
7474
self.state = WorkloadState.PREPARE
75+
self.result = None
7576
self._setaccess('params')
7677
self._setaccess('resources')
78+
self._setaccess('result')
7779

7880
@property
7981
def module_path(self):
@@ -143,6 +145,8 @@ def __init__(self):
143145
self.module = None
144146
self.parent_module_name = 'scotty.systemcollector'
145147
self.state = CommonComponentState.PREPARE
148+
self.result = None
149+
self._setaccess('result')
146150

147151
@property
148152
def module_path(self):

scotty/core/executor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ def submit_systemcollectors(self, experiment):
110110
logger.info(msg.format(systemcollector.name))
111111
self.submit(experiment, systemcollector, 'collect')
112112

113+
def collect_results(self):
114+
for future in as_completed(self._future_to_component):
115+
systemcollector = self._future_to_component[future]
116+
systemcollector.result = future.result()
117+
113118

114119
class ResultStoreSubmitExecutor(ComponentExecutor):
115120
def submit_resultstores(self, experiment):

scotty/tests/unit/__init__.py

Whitespace-only changes.

scotty/tests/unit/core/__init__.py

Whitespace-only changes.

scotty/tests/unit/test_utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import unittest
2+
import mock
3+
4+
from scotty.core.executor import ComponentExecutor
5+
from scotty import utils
6+
7+
class ExperimentHelperTest(unittest.TestCase):
8+
9+
@mock.patch('scotty.core.context.Context')
10+
def test_get_workloads(self, context_mock):
11+
experiment = mock.Mock()
12+
experiment.components = {
13+
"workload":{
14+
"wl_1":mock.Mock(),
15+
"wl_2":mock.Mock()
16+
}
17+
}
18+
context_mock.v1._ContextV1__experiment = experiment
19+
experiment_helper = utils.ExperimentHelper(context_mock)
20+
workloads = experiment_helper.get_workloads()
21+
self.assertEqual(workloads, experiment.components['workload'])

scotty/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
class ExperimentHelper(object):
1111
def __init__(self, context):
12+
# TODO validate context - is from scotty and not a fake from customer component
1213
self.context = context
1314
self.__experiment = context.v1._ContextV1__experiment
1415

@@ -26,3 +27,9 @@ def get_resource(self, resource_name):
2627
raise ScottyException(
2728
'Can not find resource ({})'.format(resource_name))
2829
return resource
30+
31+
# restrict function to a list of context types (component list)
32+
# @restrict_to(component, component2, ...)
33+
def get_workloads(self):
34+
workloads = self.__experiment.components['workload']
35+
return workloads

0 commit comments

Comments
 (0)