Code Review
/
csit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
CSIT-748 Add K8S 2memif-2vnf topologies
[csit.git]
/
resources
/
libraries
/
python
/
KubernetesUtils.py
diff --git
a/resources/libraries/python/KubernetesUtils.py
b/resources/libraries/python/KubernetesUtils.py
index
77628b6
..
bcbb7f5
100644
(file)
--- a/
resources/libraries/python/KubernetesUtils.py
+++ b/
resources/libraries/python/KubernetesUtils.py
@@
-50,6
+50,9
@@
class KubernetesUtils(object):
raise RuntimeError('Failed to setup Kubernetes on {node}.'
.format(node=node['host']))
raise RuntimeError('Failed to setup Kubernetes on {node}.'
.format(node=node['host']))
+ KubernetesUtils.wait_for_kubernetes_pods_on_node(node,
+ nspace='kube-system')
+
@staticmethod
def setup_kubernetes_on_all_duts(nodes):
"""Set up Kubernetes on all DUTs.
@staticmethod
def setup_kubernetes_on_all_duts(nodes):
"""Set up Kubernetes on all DUTs.
@@
-244,34
+247,34
@@
class KubernetesUtils(object):
rtype)
@staticmethod
rtype)
@staticmethod
- def get_kubernetes_logs_on_node(node, n
ame
space='csit'):
+ def get_kubernetes_logs_on_node(node, nspace='csit'):
"""Get Kubernetes logs on node.
:param node: DUT node.
"""Get Kubernetes logs on node.
:param node: DUT node.
- :param n
ame
space: Kubernetes namespace.
+ :param nspace: Kubernetes namespace.
:type node: dict
:type node: dict
- :type n
ame
space: str
+ :type nspace: str
"""
ssh = SSH()
ssh.connect(node)
cmd = "for p in $(kubectl get pods -n {namespace} --no-headers"\
" | cut -f 1 -d ' '); do echo $p; kubectl logs -n {namespace} $p; "\
"""
ssh = SSH()
ssh.connect(node)
cmd = "for p in $(kubectl get pods -n {namespace} --no-headers"\
" | cut -f 1 -d ' '); do echo $p; kubectl logs -n {namespace} $p; "\
- "done".format(namespace=n
ame
space)
+ "done".format(namespace=nspace)
ssh.exec_command(cmd, timeout=120)
@staticmethod
ssh.exec_command(cmd, timeout=120)
@staticmethod
- def get_kubernetes_logs_on_all_duts(nodes, n
ame
space='csit'):
+ def get_kubernetes_logs_on_all_duts(nodes, nspace='csit'):
"""Get Kubernetes logs on all DUTs.
:param nodes: Topology nodes.
"""Get Kubernetes logs on all DUTs.
:param nodes: Topology nodes.
- :param n
ame
space: Kubernetes namespace.
+ :param nspace: Kubernetes namespace.
:type nodes: dict
:type nodes: dict
- :type n
ame
space: str
+ :type nspace: str
"""
for node in nodes.values():
if node['type'] == NodeType.DUT:
"""
for node in nodes.values():
if node['type'] == NodeType.DUT:
- KubernetesUtils.get_kubernetes_logs_on_node(node, n
ame
space)
+ KubernetesUtils.get_kubernetes_logs_on_node(node, nspace)
@staticmethod
def reset_kubernetes_on_node(node):
@staticmethod
def reset_kubernetes_on_node(node):
@@
-302,25
+305,32
@@
class KubernetesUtils(object):
KubernetesUtils.reset_kubernetes_on_node(node)
@staticmethod
KubernetesUtils.reset_kubernetes_on_node(node)
@staticmethod
- def wait_for_kubernetes_pods_on_node(node):
+ def wait_for_kubernetes_pods_on_node(node
, nspace='csit'
):
"""Wait for Kubernetes PODs to become in 'Running' state on node.
:param node: DUT node.
"""Wait for Kubernetes PODs to become in 'Running' state on node.
:param node: DUT node.
+ :param nspace: Kubernetes namespace.
:type node: dict
:type node: dict
+ :type nspace: str
:raises RuntimeError: If Kubernetes PODs are not ready.
"""
ssh = SSH()
ssh.connect(node)
:raises RuntimeError: If Kubernetes PODs are not ready.
"""
ssh = SSH()
ssh.connect(node)
- cmd = 'kubectl get -n csit pods --no-headers'
+ cmd = 'kubectl get -n {namespace} pods --no-headers'\
+ .format(namespace=nspace)
for _ in range(48):
(ret_code, stdout, _) = ssh.exec_command_sudo(cmd, timeout=120)
if int(ret_code) == 0:
for _ in range(48):
(ret_code, stdout, _) = ssh.exec_command_sudo(cmd, timeout=120)
if int(ret_code) == 0:
- ready =
Tru
e
+ ready =
Fals
e
for line in stdout.splitlines():
for line in stdout.splitlines():
- if 'Running' in line and '1/1' in line:
- ready = True
- else:
+ try:
+ state = line.split()[1].split('/')
+ ready = True if 'Running' in line and\
+ state == state[::-1] else False
+ if not ready:
+ break
+ except ValueError, IndexError:
ready = False
if ready:
break
ready = False
if ready:
break
@@
-330,15
+340,17
@@
class KubernetesUtils(object):
.format(node=node['host']))
@staticmethod
.format(node=node['host']))
@staticmethod
- def wait_for_kubernetes_pods_on_all_duts(nodes):
+ def wait_for_kubernetes_pods_on_all_duts(nodes
, nspace='csit'
):
"""Wait for Kubernetes PODs to become in Running state on all DUTs.
:param nodes: Topology nodes.
"""Wait for Kubernetes PODs to become in Running state on all DUTs.
:param nodes: Topology nodes.
+ :param nspace: Kubernetes namespace.
:type nodes: dict
:type nodes: dict
+ :type nspace: str
"""
for node in nodes.values():
if node['type'] == NodeType.DUT:
"""
for node in nodes.values():
if node['type'] == NodeType.DUT:
- KubernetesUtils.wait_for_kubernetes_pods_on_node(node)
+ KubernetesUtils.wait_for_kubernetes_pods_on_node(node
, nspace
)
@staticmethod
def create_kubernetes_vswitch_startup_config(**kwargs):
@staticmethod
def create_kubernetes_vswitch_startup_config(**kwargs):
@@
-382,10
+394,11
@@
class KubernetesUtils(object):
:param kwargs: Key-value pairs used to create configuration.
:param kwargs: dict
"""
:param kwargs: Key-value pairs used to create configuration.
:param kwargs: dict
"""
+ skip_cnt = kwargs['cpu_skip'] + (kwargs['i'] - 1) * kwargs['cpu_cnt']
cpuset_cpus = \
CpuUtils.cpu_slice_of_list_per_node(node=kwargs['node'],
cpu_node=kwargs['cpu_node'],
cpuset_cpus = \
CpuUtils.cpu_slice_of_list_per_node(node=kwargs['node'],
cpu_node=kwargs['cpu_node'],
- skip_cnt=
kwargs['cpu_skip']
,
+ skip_cnt=
skip_cnt
,
cpu_cnt=kwargs['cpu_cnt'],
smt_used=kwargs['smt_used'])
cpu_cnt=kwargs['cpu_cnt'],
smt_used=kwargs['smt_used'])