def __init__(self): self.type_name = None self.description = None self.allowed_nodes = [] #if nodes list is empty - all nodes are allowed self.parameters = [] self.__system_api = SystemAPI()
class ClusterType: def __init__(self): self.type_name = None self.description = None self.allowed_nodes = [] #if nodes list is empty - all nodes are allowed self.parameters = [] self.__system_api = SystemAPI() def load_from_file(self, yaml_file): yaml_file = YamlFile(yaml_file) yaml_file.parse() cluster_info = yaml_file.get_object(PROP_CLUSTER_INFO) self.type_name = cluster_info[PROP_TYPE_NAME] self.description = cluster_info[PROP_DESCRIPTION] self.allowed_nodes = cluster_info.get(PROP_ALLOWED_NODES, []) params = cluster_info.get(PROP_PARAMETERS, []) self.parameters = [ParameterSpec(d_val) for d_val in params] def save_to_file(self, file_path): cluster_info = { PROP_TYPE_NAME: self.type_name, PROP_DESCRIPTION: self.description, PROP_ALLOWED_NODES: self.allowed_nodes, PROP_PARAMETERS: [p.to_dict() for p in self.parameters] } yaml_file = YamlFile(file_path) yaml_file.load_objects({PROP_CLUSTER_INFO: cluster_info}) yaml_file.save() def load_from_database(self, cluster_type): self.type_name, parameters, self.allowed_nodes, self.description = \ self.__system_api.get_cluster_type(cluster_type) self.parameters = [] for param in parameters: self.parameters.append(ParameterSpec(param)) def save_into_database(self): self.__system_api.register_cluster_type(self.type_name, \ self.allowed_nodes, self.parameters, self.description)
from blik.management.customization.cluster_type import ClusterType, ParameterSpec from blik.management.core.system_api import SystemAPI from blik.management.core.models import NmNodeType TEST_CLUSTER_1_SPEC_FILE = 'cluster01.yaml' TEST_CLUSTER_2_SPEC_FILE = 'cluster02.yaml' TEST_CLUSTER_2_SPEC_FILE_U = 'cluster02_upd.yaml' TEST_CLUSTER_3_SPEC_FILE = 'cluster03.yaml' class Session: def authorize(self, role): return True SystemAPI.init_global_session(Session()) class TestCustomClusterType(unittest.TestCase): def __check_2_specs(self, cluster_type, cluster_type2): self.assertEqual(cluster_type.type_name, cluster_type2.type_name) self.assertEqual(cluster_type.description, cluster_type2.description) self.assertEqual(cluster_type.allowed_nodes, cluster_type2.allowed_nodes) self.assertEqual(len(cluster_type.parameters), len(cluster_type2.parameters)) for i, param in enumerate(cluster_type.parameters): self.assertEqual(param.name, cluster_type2.parameters[i].name) self.assertEqual(param.type, cluster_type2.parameters[i].type) self.assertEqual(param.default, cluster_type2.parameters[i].default) self.assertEqual(param.posible_params, cluster_type2.parameters[i].posible_params) def test_yaml_load(self):