Example #1
0
def assert_false(actual, expected, message):
    try:
        assert not actual == expected, message
    except AssertionError as e:
        util.log_info(e)
        raise
    return True
Example #2
0
def cloud_acct_config_openstack(lp_addr,
                                header,
                                proj_name,
                                cloud_acct_name,
                                key,
                                secret,
                                auth_url,
                                tenant,
                                user_domain="eng",
                                proj_domain="eng",
                                region="RegionOne",
                                mgmt_net="private",
                                float_ip_pool_net="public"):
    try:
        api = rapi.cloud_acct_config_openstack(proj_name, cloud_acct_name)
        url = util.create_url_running(lp_addr, api)
        payload = pl.cloud_acct_config_openstack(key, secret, auth_url,
                                                 user_domain, proj_domain,
                                                 tenant, region, mgmt_net,
                                                 float_ip_pool_net)

        util.log_info(
            f"Adding configuration to cloud-account- {cloud_acct_name}.")
        status = util.edit_config(url, header, payload)
        time.sleep(20)
        state = util.get_rpc_state(status).upper()
        if state != "OK":
            assert state == "OK", f"RPC response: Expected- OK, Received- {state}."
    except BaseException as e:
        util.log_info(e)
        raise
Example #3
0
def vim_discovered_details(lp_addr, header, proj_name, cloud_acct_name):
    try:
        api = rapi.cloud_acct_status(proj_name, cloud_acct_name)
        url = util.create_url_operational(lp_addr, api)
        payload = ""

        status = util.get_config(url, header, payload)
        time.sleep(5)
        return status["rw-cloud:oper-state"]
    except BaseException as e:
        util.log_info(e)
        raise
Example #4
0
def get_input_param_xpath_nsr(lp_addr, header, proj_name, nsr_id):
    try:
        api = rapi.input_parameter_xpath_nsd(proj_name, nsr_id)
        url = util.create_url_running(lp_addr, api)
        payload = ""

        util.log_info(f"Fetching xPaths from NSD- {nsr_id}.")
        status = util.get_config(url, header, payload)
        return status["nsr:input-parameter-xpath"]
    except BaseException as e:
        util.log_info(e)
        raise
Example #5
0
def get_cloud_acct_type(lp_addr, header, proj_name, acct_name):
    try:
        api = rapi.cloud_acct_type(proj_name, acct_name)
        url = util.create_url_running(lp_addr, api)
        payload = ""

        util.log_info(f"Fetching account-type for cloud-account- {acct_name}.")
        status = util.get_config(url, header, payload)
        time.sleep(5)
        return status["account-type"]
    except BaseException as e:
        util.log_info(e)
        raise
Example #6
0
def get_proj_details(lp_addr, header, proj_name):
    try:
        api = rapi.proj_detail(proj_name)
        url = util.create_url_running(lp_addr, api)
        payload = ""

        util.log_info(f"Fetching project details for project- {proj_name}.")
        status = util.get_config(url, header, payload)
        time.sleep(5)
        return status
    except BaseException as e:
        util.log_info(e)
        raise
Example #7
0
def get_proj_name(lp_addr, header, proj_name):
    try:
        api = rapi.proj_name(proj_name)
        url = util.create_url_running(lp_addr, api)
        payload = ""

        util.log_info("Fetching project name.")
        status = util.get_config(url, header, payload)
        time.sleep(5)
        return status["name"]
    except BaseException as e:
        util.log_info(e)
        raise
Example #8
0
def get_lp_version(lp_addr, header):
    try:
        api = rapi.lp_version()
        url = util.create_url_operational(lp_addr, api)
        payload = ""

        util.log_info("Fetching build-version of the LP.")
        version = util.get_config(url, header, payload)
        lp_version = version["rw-base:version"]["version"]
        time.sleep(5)
        return lp_version
    except BaseException as e:
        util.log_info(e)
        raise
Example #9
0
    def test08_NS_Terminate(self):
        util.log_info(f"Executing {self.test08_NS_Terminate.__name__}.")

        state = fw.get_ns_oper_status(const.lp_addr_default[0],
                                      const.header_default, self.proj_name[0],
                                      self.nsr_id[0])
        if state == "running":
            fw.ns_terminate(const.lp_addr_default[0], const.header_default,
                            self.proj_name[0], self.nsr_id[0])
            conf_state = fw.get_ns_instance_config(const.lp_addr_default[0],
                                                   const.header_default,
                                                   self.proj_name[0],
                                                   self.nsr_id[0], "status")
            state = fw.get_ns_oper_status(const.lp_addr_default[0],
                                          const.header_default,
                                          self.proj_name[0], self.nsr_id[0])
            if conf_state == "DISABLED" and state == "terminated":
                util.log_info(
                    f"NS with NSR ID- {self.nsr_id[0]} terminated successfully. Test-case Pass."
                )
            else:
                util.log_info(
                    f"Expected state- terminated, Current state- {state}. Test-case Fail."
                )
                assert conf_state == "DISABLED" and state == "terminated", \
                    f"Expected state- terminated, Current state- {state}. Test-case Fail."
        else:
            util.log_info(
                f"NS with NSR ID- {self.nsr_id[0]} is not running. Current state- {state}. Test-case Fail."
            )
            assert state == "running", f"NS with NSR ID- {self.nsr_id[0]} is not running. " \
                f"Current state- {state}. Test-case Fail."
Example #10
0
def get_proj_user_role(lp_addr, header, proj_name):
    try:
        api = rapi.proj_user_role(proj_name)
        url = util.create_url_running(lp_addr, api)
        payload = ""

        util.log_info(f"Fetching user-role for project- {proj_name}.")
        status = util.get_config(url, header, payload)
        time.sleep(10)
        role = status["rw-project:user"]["role"][0]
        return role
    except BaseException as e:
        util.log_info(e)
        raise
Example #11
0
def cloud_acct_delete(lp_addr, header, proj_name, cloud_acct_name):
    try:
        api = rapi.cloud_acct_detail(proj_name, cloud_acct_name)
        url = util.create_url_running(lp_addr, api)
        payload = ""

        status = util.delete_config(url, header, payload)
        time.sleep(15)
        state = util.get_rpc_state(status).upper()
        if state != "OK":
            assert state == "OK", f"RPC response: Expected- OK, Received- {state}."
    except BaseException as e:
        util.log_info(e)
        raise
Example #12
0
    def test11_Cloud_Account_Delete(self):
        util.log_info(
            f"Executing {self.test11_Cloud_Account_Delete.__name__}.")

        acct = fw.get_cloud_acct_details(const.lp_addr_default[0],
                                         const.header_default,
                                         self.proj_name[0],
                                         const.cloud_acct_name[0])
        if acct:
            fw.cloud_acct_delete(const.lp_addr_default[0],
                                 const.header_default, self.proj_name[0],
                                 const.cloud_acct_name[0])
            acct = fw.get_cloud_acct_details(const.lp_addr_default[0],
                                             const.header_default,
                                             self.proj_name[0],
                                             const.cloud_acct_name[0])
            if not acct:
                util.log_info(
                    f"Cloud account with name- {const.cloud_acct_name[0]} deleted successfully. "
                    f"Test-case Pass.")
            else:
                util.log_info(
                    f"Cloud account with name- {const.cloud_acct_name[0]} couldn't get deleted. "
                    f"Test-case Fail.")
                assert not acct, f"Cloud account with name- {const.cloud_acct_name[0]} couldn't get deleted. " \
                    f"Test-case Fail."
        else:
            util.log_info(
                f"Cloud account with name- {const.cloud_acct_name[0]} is not configured. Test-case Fail."
            )
            assert acct, f"Cloud account with name- {const.cloud_acct_name[0]} is not configured. Test-case Fail."
Example #13
0
    def test10_Package_Delete(self):
        util.log_info(f"Executing {self.test10_Package_Delete.__name__}.")

        pkg_catalog = fw.get_pkg_catalog(const.lp_addr_default[0],
                                         const.header_default,
                                         self.proj_name[0])
        if pkg_catalog:
            fw.pkg_delete(const.lp_addr_default[0], const.header_default,
                          self.proj_name[0], "nsd", "ping_pong_nsd")
            fw.pkg_delete(const.lp_addr_default[0], const.header_default,
                          self.proj_name[0], "vnfd", "pong_vnfd")
            fw.pkg_delete(const.lp_addr_default[0], const.header_default,
                          self.proj_name[0], "vnfd", "ping_vnfd")

            pkg_catalog = fw.get_pkg_catalog(const.lp_addr_default[0],
                                             const.header_default,
                                             self.proj_name[0])
            if pkg_catalog is None:
                util.log_info("Packages deleted successfully. Test-case Pass.")
            else:
                util.log_info(
                    "Packages couldn't delete successfully. Test-case Fail.")
                assert pkg_catalog is None, "Packages couldn't delete successfully. Test-case Fail."
        else:
            util.log_info(f"Packages not available to delete. Test-case Fail.")
            assert pkg_catalog, f"Packages not available to delete. Test-case Fail."
Example #14
0
    def test09_NS_Delete(self):
        util.log_info(f"Executing {self.test09_NS_Delete.__name__}.")

        conf_state = fw.get_ns_instance_config(const.lp_addr_default[0],
                                               const.header_default,
                                               self.proj_name[0],
                                               self.nsr_id[0], "status")
        state = fw.get_ns_oper_status(const.lp_addr_default[0],
                                      const.header_default, self.proj_name[0],
                                      self.nsr_id[0])
        if conf_state == "DISABLED" or state == "terminated":
            fw.ns_delete(const.lp_addr_default[0], const.header_default,
                         self.proj_name[0], self.nsr_id[0])
            conf_state = fw.get_ns_instance_config(const.lp_addr_default[0],
                                                   const.header_default,
                                                   self.proj_name[0],
                                                   self.nsr_id[0])
            if not conf_state:
                util.log_info(
                    f"NS with NSR ID- {self.nsr_id[0]} deleted successfully. Test-case Pass."
                )
            else:
                util.log_info(
                    f"NS with NSR ID- {self.nsr_id[0]} is not deleted. "
                    f"NS still has config-data- {conf_state}. Test-case Fail.")
                assert not conf_state, f"NS with NSR ID- {self.nsr_id[0]} is not deleted. " \
                    f"NS still has config-data- {conf_state}. Test-case Fail."
        else:
            util.log_info(
                f"NS with NSR ID- {self.nsr_id[0]} is not terminated. Current state- {state}. "
                f"Test-case Fail.")
            assert conf_state == "DISABLED" or state == "terminated",\
                f"NS with NSR ID- {self.nsr_id[0]} is not terminated. Current state- {state}. Test-case Fail."
Example #15
0
def proj_add(lp_addr, header, proj_name, proj_desc):
    try:
        api = rapi.proj_add()
        url = util.create_url_running(lp_addr, api)
        payload = pl.proj_add(proj_name, proj_desc)

        util.log_info(f"Adding project with name- {proj_name}.")
        status = util.add_config(url, header, payload)
        state = util.get_rpc_state(status).upper()
        if state != "OK":
            assert state == "OK", f"RPC response: Expected- OK, Received- {state}."
        time.sleep(15)
    except BaseException as e:
        util.log_info(e)
        raise
Example #16
0
def get_cloud_acct_details(lp_addr, header, proj_name, cloud_acct_name):
    try:
        api = rapi.cloud_acct_detail(proj_name, cloud_acct_name)
        url = util.create_url_running(lp_addr, api)
        payload = ""

        util.log_info(
            f"Fetching cloud-account details for account with name- {cloud_acct_name}."
        )
        status = util.get_config(url, header, payload)
        time.sleep(5)
        return status
    except BaseException as e:
        util.log_info(e)
        raise
Example #17
0
def download_system_log(lp_addr, header):
    try:
        api = rapi.get_log()
        url = util.api_url(lp_addr, api)
        payload = ""

        util.log_info("Fetching system logs.")
        #status = util.generate_log(url, header, payload)
        abs_path = f"{const.running_dir[0]}/artifacts/traces/system.log"
        with open(abs_path, "w+") as log_file:
            log_file.write(util.generate_log(url, header, payload))
        time.sleep(15)
    except BaseException as e:
        util.log_info(e)
        raise
Example #18
0
def cloud_acct_status(lp_addr, header, proj_name, cloud_acct_name):
    try:
        api = rapi.cloud_acct_status(proj_name, cloud_acct_name)
        url = util.create_url_operational(lp_addr, api)
        payload = ""

        status = util.get_config(url, header, payload)
        time.sleep(10)
        return status["rw-cloud:oper-state"]["status"]

        #state = list(status.values())
        #return state[0]
    except BaseException as e:
        util.log_info(e)
        raise
Example #19
0
def proj_config(lp_addr, header, proj_name, user_name, user_domain, role,
                event_publish):
    try:
        api = rapi.proj_config(proj_name)
        url = util.create_url_running(lp_addr, api)
        payload = pl.proj_config(user_name, user_domain, role, event_publish)

        util.log_info(f"Configuring project- {proj_name}.")
        status = util.add_config(url, header, payload)
        state = util.get_rpc_state(status).upper()
        if state != "OK":
            assert state == "OK", f"RPC response: Expected- OK, Received- {state}."
        time.sleep(20)
    except BaseException as e:
        util.log_info(e)
        raise
Example #20
0
def cloud_acct_add(lp_addr, header, proj_name, acct_name, acct_type, timeout):
    try:
        api = rapi.cloud_acct_add(proj_name)
        url = util.create_url_running(lp_addr, api)
        payload = pl.cloud_acct_add(acct_name, acct_type, timeout)

        util.log_info(
            f"Adding cloud account- {acct_type} with name- {acct_name} to project- {proj_name}."
        )
        status = util.add_config(url, header, payload)
        time.sleep(10)
        state = util.get_rpc_state(status).upper()
        if state != "OK":
            assert state == "OK", f"RPC response: Expected- OK, Received- {state}."
    except BaseException as e:
        util.log_info(e)
        raise
Example #21
0
def delete_input_param_xpath_nsd(lp_addr, header, proj_name, nsd_id, xpath):
    try:
        api = rapi.input_parameter_xpath_nsd(proj_name, nsd_id)
        url = util.create_url_running(lp_addr, api)
        payload = ""

        util.log_info(f"Deleting xPath- {xpath} from NSD- {nsd_id}.")
        encoded_uri = util.get_encoded_url(xpath)
        url = f"{url}/{encoded_uri}"
        print(url)
        status = util.delete_config(url, header, payload)
        time.sleep(10)
        state = util.get_rpc_state(status).upper()
        if state != "OK":
            assert state == "OK", f"RPC response: Expected- OK, Received- {state}."
    except BaseException as e:
        util.log_info(e)
        raise
Example #22
0
def add_input_param_xpath_nsr(lp_addr, header, proj_name, nsr_id, xpath,
                              value):
    try:
        api = rapi.input_parameter_xpath_nsr(proj_name, nsr_id)
        url = util.create_url_running(lp_addr, api)
        payload = pl.input_parameter_xpath_nsd(xpath, value)

        util.log_info(
            f"Adding xPath- \"{xpath}\" with value- \"{value}\" to NSR ID- \"{nsr_id}\"."
        )
        status = util.add_config(url, header, payload)
        time.sleep(10)
        state = util.get_rpc_state(status).upper()
        if state != "OK":
            assert state == "OK", f"RPC response: Expected- OK, Received- {state}."
    except BaseException as e:
        util.log_info(e)
        raise
Example #23
0
def get_vnfd_name(lp_addr, header, proj_name):
    try:
        vnfd_name = []

        api = rapi.vnfd_catalog(proj_name)
        url = util.create_url_running(lp_addr, api)
        payload = ""

        util.log_info(f"Fetching VNFD name(s) from project- {proj_name}.")
        status = util.get_config(url, header, payload)
        vnfd_catalog = status['project-vnfd:vnfd']
        for i in range(len(vnfd_catalog)):
            vnfd_name.append(vnfd_catalog[i]['name'])
        time.sleep(5)
        return vnfd_name
    except BaseException as e:
        util.log_info(e)
        raise
Example #24
0
def get_vdur_vim_id(lp_addr, header, proj_name, vnfr_id):
    try:
        vdur_vim_id = []

        api = rapi.vdur_detail(proj_name, vnfr_id)
        url = util.create_url_operational(lp_addr, api)
        payload = ""

        util.log_info(f"Fetching VDUR details.")
        status = util.get_config(url, header, payload)
        if status is not None:
            vdur_catalog = status["vnfr:vdur"]
            for items in vdur_catalog:
                vdur_vim_id.append(items["vim-id"])
            return vdur_vim_id
        else:
            assert status, "VDUR details not available."
    except BaseException as e:
        util.log_info(e)
        raise
Example #25
0
    def test05_Package_Onboard(self):
        util.log_info(f"Executing {self.test05_Package_Onboard.__name__}.")

        transac_id = fw.pkg_onboard(const.lp_addr_default[0],
                                    const.header_default, self.proj_name[0],
                                    const.ping_vnfd_ext_url)
        state1 = fw.pkg_upload_status(const.lp_addr_default[0],
                                      const.header_default, self.proj_name[0],
                                      transac_id)
        transac_id = fw.pkg_onboard(const.lp_addr_default[0],
                                    const.header_default, self.proj_name[0],
                                    const.pong_vnfd_ext_url)
        state2 = fw.pkg_upload_status(const.lp_addr_default[0],
                                      const.header_default, self.proj_name[0],
                                      transac_id)
        transac_id = fw.pkg_onboard(const.lp_addr_default[0],
                                    const.header_default, self.proj_name[0],
                                    const.ping_pong_nsd_ext_url)
        state3 = fw.pkg_upload_status(const.lp_addr_default[0],
                                      const.header_default, self.proj_name[0],
                                      transac_id)

        if state1 and state2 and state3 == "COMPLETED":
            util.log_info(
                f"Ping VNFD, Pong VNFD & Ping_Pong NSD are uploaded in project- {self.proj_name[0]}. "
                f"Test-case Pass.")
        else:
            util.log_info(
                f"Expected- COMPLETED, Received- {state1, state2, state3}. Test-case Fail."
            )
            assert state1 and state2 and state3 == "COMPLETED", \
                f"Expected- COMPLETED, Received- {state1, state2, state3}. Test-case Fail."
Example #26
0
    def test06_NS_Create(self):
        util.log_info(f"Executing {self.test06_NS_Create.__name__}.")

        ns_name = "AutoTest"
        nsd = fw.get_nsd_name_id(const.lp_addr_default[0],
                                 const.header_default, self.proj_name[0])
        nsd_id = nsd["ping_pong_nsd"]
        nsr_id = fw.ns_create(const.lp_addr_default[0], const.header_default,
                              self.proj_name[0], ns_name, nsd_id)
        self.nsr_id.append(nsr_id)

        conf_name = fw.get_ns_instance_config(const.lp_addr_default[0],
                                              const.header_default,
                                              self.proj_name[0],
                                              self.nsr_id[0], "name")
        conf_state = fw.get_ns_instance_config(const.lp_addr_default[0],
                                               const.header_default,
                                               self.proj_name[0],
                                               self.nsr_id[0], "status")

        if conf_name == ns_name and conf_state == "DISABLED":
            util.log_info(
                f"NS is created with name- {conf_name} and current state is- {conf_state}. Test-case Pass."
            )
        else:
            util.log_info(
                f"Expected name- {ns_name}, Configured name- {conf_name}. Test-case Fail."
            )
            assert conf_name == ns_name and conf_state == "DISABLED", \
                f"Expected name- {ns_name}, Configured name- {conf_name}. Test-case Fail."
Example #27
0
def cloud_acct_config_vcd(lp_addr, header, proj_name, cloud_acct_name, user,
                          passwd, auth_url, tenant, mgmt_net, org, admin_user,
                          admin_passwd, nsx_auth_url, nsx_user, nsx_passwd,
                          vc_host, vc_port, vc_user, vc_passwd):
    try:
        api = rapi.cloud_acct_config_vcd(proj_name, cloud_acct_name)
        url = util.create_url_running(lp_addr, api)
        payload = pl.cloud_acct_config_vcd(user, passwd, auth_url, tenant,
                                           mgmt_net, org, admin_user,
                                           admin_passwd, nsx_auth_url,
                                           nsx_user, nsx_passwd, vc_host,
                                           vc_port, vc_user, vc_passwd)
        util.log_info(
            f"Adding configuration to cloud-account- {cloud_acct_name}.")
        status = util.edit_config(url, header, payload)
        time.sleep(20)
        state = util.get_rpc_state(status).upper()
        if state != "OK":
            assert state == "OK", f"RPC response: Expected- OK, Received- {state}."
    except BaseException as e:
        util.log_info(e)
        raise
Example #28
0
def get_pkg_catalog(lp_addr, header, proj_name, value=None):
    try:
        prod_name = []

        api = rapi.pkg_catalog(proj_name)
        url = util.create_url_running(lp_addr, api)
        payload = ""

        status = util.get_config(url, header, payload)
        if status:
            pkgs = (list(status.values())[0])
            if value is None:
                return pkgs
            elif value == "name":
                for pkg in pkgs:
                    prod_name.append(pkg["product-name"])
                return prod_name
        else:
            return None
            #assert status, f"Packages not available."
    except BaseException as e:
        util.log_info(e)
        raise
Example #29
0
def generate_system_log(lp_addr, header):
    try:
        api = rapi.gen_log()
        url = util.api_url(lp_addr, api)
        payload = ""

        util.log_info("Generating system logs.")
        status = util.generate_log(url, header, payload)
        if status == "Download initiated":
            util.log_info("Log file is ready to be downloaded.")
        else:
            util.log_info(
                f"RPC response: Expected- Download initiated, Received- {status}."
            )
            assert status == "Download initiated", f"RPC response: Expected- Download initiated, Received- {status}."
        time.sleep(15)
    except BaseException as e:
        util.log_info(e)
        raise
Example #30
0
def get_vdu_name_id(lp_addr, header, proj_name):
    try:
        vdur_vim_id = []
        util.log_info("Mapping VDUR VIM-ID with VNFR-Name.")
        vnfr_ids = get_vnfr_id(lp_addr, header, proj_name)
        for ids in vnfr_ids:
            vdu_vim_ids = get_vdur_vim_id(lp_addr, header, proj_name, ids)
            for ids in vdu_vim_ids:
                vdur_vim_id.append(ids)
        vnfr_name = get_vnfd_name(lp_addr, header, proj_name)
        if vdur_vim_id and vnfr_name:
            vdu = dict(zip(vnfr_name, vdur_vim_id))
            util.log_info(f"Available VDUR(s)- {list(vdu.keys())}.")
            return vdu
        else:
            util.log_info("VDUR VIM-ID & VNFR-Name couldn't map.")
    except BaseException as e:
        util.log_info(e)
        raise