blob: c4b5bc5b41f7addb70e61a122a48f6220c0ec642 [file] [log] [blame]
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +02001from typing import List, Callable, Any, Dict, Optional, Set
koder aka kdanilov22d134e2016-11-08 11:33:19 +02002from concurrent.futures import ThreadPoolExecutor
3
4
5from .timeseries import SensorDatastore
koder aka kdanilov73084622016-11-16 21:51:08 +02006from .node_interfaces import NodeInfo, IRPCNode
koder aka kdanilov39e449e2016-12-17 15:15:26 +02007from .openstack_api import OSCreds, OSConnection
koder aka kdanilov3d2bc4f2016-11-12 18:31:18 +02008from .storage import Storage
koder aka kdanilov22d134e2016-11-08 11:33:19 +02009from .config import Config
koder aka kdanilov70227062016-11-26 23:23:21 +020010from .fuel_rest_api import Connection
koder aka kdanilov962ee5f2016-12-19 02:40:08 +020011from .ssh_utils import ConnCreds
koder aka kdanilov22d134e2016-11-08 11:33:19 +020012
13
koder aka kdanilov3b4da8b2016-10-17 00:17:53 +030014class TestRun:
15 """Test run information"""
koder aka kdanilov70227062016-11-26 23:23:21 +020016 def __init__(self, config: Config, storage: Storage) -> None:
koder aka kdanilov3b4da8b2016-10-17 00:17:53 +030017 # NodesInfo list
koder aka kdanilov962ee5f2016-12-19 02:40:08 +020018 self.nodes_info = {} # type: Dict[str, NodeInfo]
koder aka kdanilov3b4da8b2016-10-17 00:17:53 +030019
20 # Nodes list
koder aka kdanilov3d2bc4f2016-11-12 18:31:18 +020021 self.nodes = [] # type: List[IRPCNode]
koder aka kdanilov3b4da8b2016-10-17 00:17:53 +030022
koder aka kdanilov22d134e2016-11-08 11:33:19 +020023 self.build_meta = {} # type: Dict[str,Any]
24 self.clear_calls_stack = [] # type: List[Callable[['TestRun'], None]]
koder aka kdanilov3b4da8b2016-10-17 00:17:53 +030025
26 # openstack credentials
koder aka kdanilov22d134e2016-11-08 11:33:19 +020027 self.fuel_openstack_creds = None # type: Optional[OSCreds]
koder aka kdanilov39e449e2016-12-17 15:15:26 +020028 self.fuel_version = None # type: Optional[List[int]]
koder aka kdanilov3d2bc4f2016-11-12 18:31:18 +020029 self.os_creds = None # type: Optional[OSCreds]
koder aka kdanilov73084622016-11-16 21:51:08 +020030 self.os_connection = None # type: Optional[OSConnection]
koder aka kdanilov70227062016-11-26 23:23:21 +020031 self.fuel_conn = None # type: Optional[Connection]
32 self.rpc_code = None # type: bytes
koder aka kdanilove7e1a4d2016-12-17 20:29:52 +020033 self.default_rpc_plugins = None # type: Dict[str, bytes]
koder aka kdanilov3b4da8b2016-10-17 00:17:53 +030034
koder aka kdanilov22d134e2016-11-08 11:33:19 +020035 self.storage = storage
36 self.config = config
37 self.sensors_data = SensorDatastore()
koder aka kdanilov70227062016-11-26 23:23:21 +020038 self.sensors_run_on = set() # type: Set[str]
koder aka kdanilov39e449e2016-12-17 15:15:26 +020039 self.os_spawned_nodes_ids = None # type: List[int]
koder aka kdanilov22d134e2016-11-08 11:33:19 +020040
41 def get_pool(self):
42 return ThreadPoolExecutor(self.config.get('worker_pool_sz', 32))
koder aka kdanilov3b4da8b2016-10-17 00:17:53 +030043
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +030044 def merge_node(self, creds: ConnCreds, roles: Set[str], **params) -> NodeInfo:
45 info = NodeInfo(creds, roles, params)
koder aka kdanilov108ac362017-01-19 20:17:16 +020046 nid = info.node_id
koder aka kdanilov962ee5f2016-12-19 02:40:08 +020047
48 if nid in self.nodes_info:
49 self.nodes_info[nid].roles.update(info.roles)
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +030050 self.nodes_info[nid].params.update(info.params)
koder aka kdanilov962ee5f2016-12-19 02:40:08 +020051 return self.nodes_info[nid]
52 else:
53 self.nodes_info[nid] = info
54 return info