blob: fd0410e5d25491c4090b714001afbb03dd32b711 [file] [log] [blame]
Joey Armstrong44fa7d82022-11-01 17:46:04 -04001#!/usr/bin/env python
2'''Return voltha test suites based on criteria.'''
3
4# -----------------------------------------------------------------------#
5# Copyright 2022 Open Networking Foundation (ONF) and the ONF Contributors
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18# -----------------------------------------------------------------------
19
20##-------------------##
21##---] GLOBALS [---##
22##-------------------##
23
24##-------------------##
25##---] IMPORTS [---##
26##-------------------##
27from pathlib import Path
28from flog.main import utils as main_utils
29
30
31class Utils():
32 """ . """
33
34 ## -----------------------------------------------------------------------
35 ## -----------------------------------------------------------------------
36 def __init__(self, root=None):
37 """Module constructor
38
39 :param data: A data source (often a certificate) to extract hostnames from.
40 :type data: arbitrary
41
42 :raises: ValueError
43 """
44
45 return
46
47 ## -----------------------------------------------------------------------
48 ## -----------------------------------------------------------------------
49 def filecat(self, name:str) -> list:
50 '''Slurp contents of a config file in the meta/ directory.
51
52 :param name: Config file name to read.
53 :type name: str
54
55 :return: Config file contents with comments and whitespace removed.
56 :rtype: list
57 '''
58
59 mod_path = Path(__file__).resolve().parent.as_posix()
60 meta = Path(mod_path + '/' + name)
61
62 ans = []
63 with open(meta, mode='r', encoding='utf-8') as stream:
64 for line in stream:
65 fields = line.split('#')
66 val = fields[0].strip()
67 if len(val) > 2:
68 ans += [val]
69
70 return ans
71
72 ## -----------------------------------------------------------------------
73 ## -----------------------------------------------------------------------
74 def get(self, args:list) -> list:
75 '''Retrieve a list of tests from a named config file.
76
77 :param args: Config file names to load.
78 :type args: list[str]
79
80 :return: Value(s) loaded from config files.
81 :rtype: list
82
83 ..note: Default beahavior will return an exhaustive list of tests
84 ..note: rather than an empty list due to typos.
85 '''
86
87 meta = ['olt', 'regression']
88
89 ans = []
90 for arg in args:
91 if arg in meta:
92 ans += self.filecat(arg)
93 else:
94 ans += self.filecat('all')
95
96 return ans
97
98# [EOF]