koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 1 | from typing import List, Callable, Any, Dict, Optional, Set |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 2 | from concurrent.futures import ThreadPoolExecutor |
| 3 | |
| 4 | |
| 5 | from .timeseries import SensorDatastore |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 6 | from .node_interfaces import NodeInfo, IRPCNode |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 7 | from .openstack_api import OSCreds, OSConnection |
koder aka kdanilov | 3d2bc4f | 2016-11-12 18:31:18 +0200 | [diff] [blame] | 8 | from .storage import Storage |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 9 | from .config import Config |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 10 | from .fuel_rest_api import Connection |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 11 | from .ssh_utils import ConnCreds |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 12 | |
| 13 | |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 14 | class TestRun: |
| 15 | """Test run information""" |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 16 | def __init__(self, config: Config, storage: Storage) -> None: |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 17 | # NodesInfo list |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 18 | self.nodes_info = {} # type: Dict[str, NodeInfo] |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 19 | |
| 20 | # Nodes list |
koder aka kdanilov | 3d2bc4f | 2016-11-12 18:31:18 +0200 | [diff] [blame] | 21 | self.nodes = [] # type: List[IRPCNode] |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 22 | |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 23 | self.build_meta = {} # type: Dict[str,Any] |
| 24 | self.clear_calls_stack = [] # type: List[Callable[['TestRun'], None]] |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 25 | |
| 26 | # openstack credentials |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 27 | self.fuel_openstack_creds = None # type: Optional[OSCreds] |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 28 | self.fuel_version = None # type: Optional[List[int]] |
koder aka kdanilov | 3d2bc4f | 2016-11-12 18:31:18 +0200 | [diff] [blame] | 29 | self.os_creds = None # type: Optional[OSCreds] |
koder aka kdanilov | 7308462 | 2016-11-16 21:51:08 +0200 | [diff] [blame] | 30 | self.os_connection = None # type: Optional[OSConnection] |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 31 | self.fuel_conn = None # type: Optional[Connection] |
| 32 | self.rpc_code = None # type: bytes |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 33 | self.default_rpc_plugins = None # type: Dict[str, bytes] |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 34 | |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 35 | self.storage = storage |
| 36 | self.config = config |
| 37 | self.sensors_data = SensorDatastore() |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 38 | self.sensors_run_on = set() # type: Set[str] |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 39 | self.os_spawned_nodes_ids = None # type: List[int] |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 40 | |
| 41 | def get_pool(self): |
| 42 | return ThreadPoolExecutor(self.config.get('worker_pool_sz', 32)) |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 43 | |
kdanylov aka koder | cdfcdaf | 2017-04-29 10:03:39 +0300 | [diff] [blame] | 44 | def merge_node(self, creds: ConnCreds, roles: Set[str], **params) -> NodeInfo: |
| 45 | info = NodeInfo(creds, roles, params) |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 46 | nid = info.node_id |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 47 | |
| 48 | if nid in self.nodes_info: |
| 49 | self.nodes_info[nid].roles.update(info.roles) |
kdanylov aka koder | cdfcdaf | 2017-04-29 10:03:39 +0300 | [diff] [blame] | 50 | self.nodes_info[nid].params.update(info.params) |
koder aka kdanilov | 962ee5f | 2016-12-19 02:40:08 +0200 | [diff] [blame] | 51 | return self.nodes_info[nid] |
| 52 | else: |
| 53 | self.nodes_info[nid] = info |
| 54 | return info |