aboutsummaryrefslogtreecommitdiffstats
path: root/sdv/docker/sdvstate/internal/validator/kuberef/policy_checks.py
blob: 6993fd725dbfbc559aa917792ad9494f906d9841 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
"""
Policy Checks
Checks if the policies are properly configured
"""


import ast
import logging
from tools.kube_utils import kube_api
from tools.conf import settings
from  internal.store_result import store_result

def cpu_manager_policy_check():
    """
    Checks cpu manager settings
    """
    api = kube_api()
    logger = logging.getLogger(__name__)
    node_list = api.list_node()
    nodes = []

    for node in node_list:
        nodes.append(node.metadata.name)

    result = {'category':  'compute',
              'case_name': 'cpu_manager_policy_check',
              'criteria':  'pass',
              'details': []
             }

    for node in nodes:
        configz = api.connect_get_node_proxy_with_path(node, "configz")
        configz = ast.literal_eval(configz)
        res = {
            'node': node,
            'criteria':  'pass',
            'config': []
        }

        status = []

        flag = True

        cpu_manager = settings.getValue('pdf_file')['vim_functional']['cpu_manager_policy']

        if cpu_manager['type'] == configz['kubeletconfig']['cpuManagerPolicy']:
            if cpu_manager['type'] == 'static':
                if cpu_manager['reconcile_period'] == configz['kubeletconfig']['cpuManagerReconcilePeriod']:
                    if cpu_manager['full_pcpus'] == configz['kubeletconfig']['full-pcpus-only']:
                        flag = flag and True
                else:
                    flag = flag and False
            else:
                flag = flag and True
        else:
            flag = flag and False

        if flag is False:
            res['criteria'] = 'fail'

        status.append(cpu_manager)
        res['config'] = status
        result['details'].append(res)


    if flag is False:
        result['criteria'] = 'fail'

    store_result(logger, result)
    return result

def topology_manager_policy_check():
    """
    Checks topology manager settings
    """
    api = kube_api()
    logger = logging.getLogger(__name__)
    node_list = api.list_node()
    nodes = []

    for node in node_list:
        nodes.append(node.metadata.name)


    result = {
        'category':  'compute',
        'case_name': 'topology_manager_policy_check',
        'criteria':  'pass',
        'details': []
    }

    for node in nodes:
        configz = api.connect_get_node_proxy_with_path(node, "configz")
        configz = ast.literal_eval(configz)
        res = {
            'node': node,
            'criteria':  'pass',
            'config': []
        }

        status = []

        flag = True

        topology_manager = settings.getValue('pdf_file')['undercloud_ook']['topo_manager_policy']

        if topology_manager['type'] == configz['kubeletconfig']['topologyManagerPolicy']:
            if topology_manager['scope'] == configz['kubeletconfig']['topologyManagerScope']:
                flag = flag and True
        else:
            flag = flag and False
        if flag is False:
            res['criteria'] = 'fail'

        status.append(topology_manager)
        res['config'] = status
        result['details'].append(res)

    if flag is False:
        result['criteria'] = 'fail'

    store_result(logger, result)
    return result