diff options
Diffstat (limited to 'test')
-rwxr-xr-x | test/vcpe/vcpe.py | 6 | ||||
-rwxr-xr-x | test/vcpe/vcpecommon.py | 57 |
2 files changed, 51 insertions, 12 deletions
diff --git a/test/vcpe/vcpe.py b/test/vcpe/vcpe.py index 460cb56de..8a46e359f 100755 --- a/test/vcpe/vcpe.py +++ b/test/vcpe/vcpe.py @@ -192,6 +192,10 @@ def tmp_sniro(): # Setting up SNIRO config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg']) +def test(): + vcpecommon = VcpeCommon() + print("sdnc_oam_ip: %s" % (vcpecommon.sdnc_oam_ip)) + if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG, format='%(message)s') @@ -228,4 +232,6 @@ if __name__ == '__main__': deploy_brg_only() elif sys.argv[1] == 'sniro': tmp_sniro() + elif sys.argv[1] == 'test': + test() diff --git a/test/vcpe/vcpecommon.py b/test/vcpe/vcpecommon.py index b45f10e91..e3d2641c1 100755 --- a/test/vcpe/vcpecommon.py +++ b/test/vcpe/vcpecommon.py @@ -10,7 +10,7 @@ import mysql.connector import requests import commands import time - +from kubernetes import client, config class VcpeCommon: ############################################################################################# @@ -70,13 +70,13 @@ class VcpeCommon: # CHANGEME: vgw_VfModuleModelInvariantUuid is in rescust service csar, look in service-VcpesvcRescust1118-template.yml for groups vgw module metadata. TODO: read this value automcatically self.vgw_VfModuleModelInvariantUuid = '26d6a718-17b2-4ba8-8691-c44343b2ecd2' # CHANGEME: OOM: this is the address that the brg and bng will nat for sdnc access - 10.0.0.x address of k8 host for sdnc-0 container - self.sdnc_oam_ip = '10.0.0.18' + self.sdnc_oam_ip = self.get_pod_node_oam_ip('sdnc-sdnc-0') # CHANGEME: OOM: this is a k8s host external IP, e.g. oom-k8s-01 IP - self.oom_so_sdnc_aai_ip = '10.12.6.236' + self.oom_so_sdnc_aai_ip = self.get_pod_node_public_ip('sdnc-sdnc-0') # CHANGEME: OOM: this is a k8s host external IP, e.g. oom-k8s-01 IP - self.oom_dcae_ves_collector = '10.12.6.236' + self.oom_dcae_ves_collector = self.get_pod_node_public_ip('sdnc-sdnc-0') # CHANGEME: OOM: this is a k8s host external IP, e.g. oom-k8s-01 IP - self.mr_ip_addr = '10.12.6.236' + self.mr_ip_addr = self.get_pod_node_public_ip('sdnc-sdnc-0') self.mr_ip_port = '30227' self.so_nbi_port = '30277' if self.oom_mode else '8080' self.sdnc_preloading_port = '30202' if self.oom_mode else '8282' @@ -321,13 +321,46 @@ class VcpeCommon: def get_pod_node_oam_ip(self, pod): """ - :Assuming kubectl is available - :param pod: pod name as a string, e.g. 'dev-sdnc-sdnc-0' - :return pod's node oam ip (10.0.0.0/16) + :Assuming kubectl is available and configured by default config (~/.kube/config) + :param pod: pod name substring, e.g. 'sdnc-sdnc-0' + :return pod's cluster node oam ip (10.0.0.0/16) + """ + ret = None + config.load_kube_config() + api = client.CoreV1Api() + kslogger = logging.getLogger('kubernetes') + kslogger.setLevel(logging.INFO) + res = api.list_pod_for_all_namespaces() + for i in res.items: + if pod in i.metadata.name: + self.logger.debug("found %s\t%s\t%s", i.metadata.name, i.status.host_ip, i.spec.node_name) + ret = i.status.host_ip + break + + if ret is None: + ret = raw_input("Enter sdnc-sdnc-0 pod cluster node OAM IP address(10.0.0.0/16): ") + return ret + + def get_pod_node_public_ip(self, pod): + """ + :Assuming kubectl is available and configured by default config (~/.kube/config) + :param pod: pod name substring, e.g. 'sdnc-sdnc-0' + :return pod's cluster node public ip (i.e. 10.12.0.0/16) """ - cmd = "kubectl -n onap describe pod {0} |grep Node:|cut -d'/' -f2".format(pod) - ret = commands.getstatusoutput(cmd) - self.logger.debug("cmd = %s, ret = %s", cmd, ret) + ret = None + config.load_kube_config() + api = client.CoreV1Api() + kslogger = logging.getLogger('kubernetes') + kslogger.setLevel(logging.INFO) + res = api.list_pod_for_all_namespaces() + for i in res.items: + if pod in i.metadata.name: + self.logger.debug("found node %s public ip: %s", i.spec.node_name, self.get_vm_ip([i.spec.node_name])[i.spec.node_name]) + ret = self.get_vm_ip([i.spec.node_name])[i.spec.node_name] + break + + if ret is None: + ret = raw_input("Enter sdnc-sdnc-0 pod cluster node public IP address(i.e. 10.12.0.0/16): ") return ret def get_vm_ip(self, keywords, net_addr=None, net_addr_len=None): @@ -358,7 +391,7 @@ class VcpeCommon: if len(ip_dict) != len(keywords): self.logger.error('Cannot find all desired IP addresses for %s.', keywords) self.logger.error(json.dumps(ip_dict, indent=4, sort_keys=True)) - self.logger.error('Temporarily continue.. remember to check back vcpecommon.py line: 316') + self.logger.error('Temporarily continue.. remember to check back vcpecommon.py line: 396') # sys.exit() return ip_dict |