diff options
31 files changed, 913 insertions, 295 deletions
diff --git a/docker/Dockerfile b/docker/Dockerfile index ca0fb6a70..f59e1f73c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -84,6 +84,7 @@ RUN git clone --depth 1 -b $BRANCH https://gerrit.opnfv.org/gerrit/doctor ${REPO RUN git clone --depth 1 -b $BRANCH https://gerrit.opnfv.org/gerrit/ovno ${REPOS_DIR}/ovno RUN git clone --depth 1 -b $BRANCH https://gerrit.opnfv.org/gerrit/promise ${REPOS_DIR}/promise RUN git clone --depth 1 -b $BRANCH https://gerrit.opnfv.org/gerrit/netready ${REPOS_DIR}/netready +RUN git clone --depth 1 -b $BRANCH https://gerrit.opnfv.org/gerrit/barometer ${REPOS_DIR}/barometer RUN git clone --depth 1 -b $BRANCH https://gerrit.opnfv.org/gerrit/sfc ${REPOS_DIR}/sfc RUN git clone --depth 1 -b $BRANCH https://gerrit.opnfv.org/gerrit/snaps ${REPOS_DIR}/snaps RUN git clone --depth 1 https://gerrit.opnfv.org/gerrit/securityscanning ${REPOS_DIR}/securityscanning @@ -91,7 +92,7 @@ RUN git clone --depth 1 https://gerrit.opnfv.org/gerrit/releng ${REPOS_DIR}/rele # OpenStack repositories RUN git clone --depth 1 -b $OPENSTACK_TAG https://github.com/openstack/networking-bgpvpn ${REPOS_DIR}/bgpvpn -#RUN git clone --depth 1 -b $KINGBIRD_TAG https://github.com/openstack/kingbird.git ${REPOS_DIR}/kingbird +RUN git clone --depth 1 -b $KINGBIRD_TAG https://github.com/openstack/kingbird.git ${REPOS_DIR}/kingbird RUN git clone --depth 1 -b $RALLY_TAG https://github.com/openstack/rally.git ${REPOS_DIR}/rally RUN git clone --depth 1 -b $TEMPEST_TAG https://github.com/openstack/tempest.git ${REPOS_DIR}/tempest @@ -110,6 +111,9 @@ RUN cd ${FUNCTEST_REPO_DIR} \ RUN cd ${RELENG_MODULE_DIR} \ && pip install . +RUN cd ${REPOS_DIR}/barometer \ + && pip install . + RUN find ${FUNCTEST_REPO_DIR} -name "*.py" \ -not -path "*tests/unit*" |xargs grep __main__ |cut -d\: -f 1 |xargs chmod -c 755 \ && find ${FUNCTEST_REPO_DIR} -name "*.sh" |xargs grep \#\! |cut -d\: -f 1 |xargs chmod -c 755 @@ -135,7 +139,9 @@ RUN cd ${REPOS_DIR}/sfc && pip install . RUN cd ${REPOS_DIR}/sdnvpn && pip install . RUN cd ${REPOS_DIR}/bgpvpn && pip install . -#RUN cd ${REPOS_DIR}/kingbird && pip install -e . + +# Kingbird integration +RUN cd ${REPOS_DIR}/kingbird && pip install -e . RUN /bin/bash -c ". /etc/profile.d/rvm.sh \ && cd ${REPOS_VNFS_DIR}/vims-test \ diff --git a/docker/Dockerfile.aarch64 b/docker/Dockerfile.aarch64 index fa04e8c8c..bf8e361f0 100644 --- a/docker/Dockerfile.aarch64 +++ b/docker/Dockerfile.aarch64 @@ -91,7 +91,7 @@ RUN git clone --depth 1 https://gerrit.opnfv.org/gerrit/releng ${REPOS_DIR}/rele # OpenStack repositories RUN git clone --depth 1 -b $OPENSTACK_TAG https://github.com/openstack/networking-bgpvpn ${REPOS_DIR}/bgpvpn -#RUN git clone --depth 1 -b $KINGBIRD_TAG https://github.com/openstack/kingbird.git ${REPOS_DIR}/kingbird +RUN git clone --depth 1 -b $KINGBIRD_TAG https://github.com/openstack/kingbird.git ${REPOS_DIR}/kingbird RUN git clone --depth 1 -b $RALLY_TAG https://github.com/openstack/rally.git ${REPOS_DIR}/rally RUN git clone --depth 1 -b $TEMPEST_TAG https://github.com/openstack/tempest.git ${REPOS_DIR}/tempest @@ -131,7 +131,9 @@ RUN cd ${REPOS_DIR}/sfc && pip install . RUN cd ${REPOS_DIR}/sdnvpn && pip install . RUN cd ${REPOS_DIR}/bgpvpn && pip install . -#RUN cd ${REPOS_DIR}/kingbird && pip install -e . + +# Kingbird integration +RUN cd ${REPOS_DIR}/kingbird && pip install -e . RUN /bin/bash -c ". /etc/profile.d/rvm.sh \ && cd ${REPOS_VNFS_DIR}/vims-test \ diff --git a/functest/ci/config_functest.yaml b/functest/ci/config_functest.yaml index 8fa4bd342..7beb9d4bd 100755 --- a/functest/ci/config_functest.yaml +++ b/functest/ci/config_functest.yaml @@ -21,6 +21,7 @@ general: dir_repo_onos: /home/opnfv/repos/onos repo_promise: /home/opnfv/repos/promise repo_netready: /home/opnfv/repos/netready + repo_barometer: /home/opnfv/repos/barometer repo_doctor: /home/opnfv/repos/doctor repo_copper: /home/opnfv/repos/copper dir_repo_ovno: /home/opnfv/repos/ovno @@ -44,6 +45,8 @@ general: image_name: Cirros-0.3.4 image_file_name: cirros-0.3.4-x86_64-disk.img image_disk_format: qcow2 + image_username: cirros + image_password: cubswin:) flavor_name: opnfv_flavor flavor_ram: 512 @@ -130,6 +133,7 @@ vnf: orchestra_ims: tenant_name: orchestra_ims tenant_description: ims deployed with openbaton + config: orchestra_ims.yaml opera_ims: tenant_name: opera_ims tenant_description: ims deployed with open-o diff --git a/functest/ci/installer_params.yaml b/functest/ci/installer_params.yaml new file mode 100644 index 000000000..bffa894e7 --- /dev/null +++ b/functest/ci/installer_params.yaml @@ -0,0 +1,16 @@ +apex: + ip: '' + user: 'stack' + pkey: '/root/.ssh/id_rsa' +#compass: +# ip: '' +# user: 'root' +# password: 'root' +fuel: + ip: '10.20.0.2' + user: 'root' + password: 'r00tme' +#joid: +# ip: '' +# user: '' +# password: '' diff --git a/functest/ci/prepare_env.py b/functest/ci/prepare_env.py index 6b24fe086..bec60d13e 100755 --- a/functest/ci/prepare_env.py +++ b/functest/ci/prepare_env.py @@ -1,18 +1,11 @@ #!/usr/bin/env python # -# Author: Jose Lausuch (jose.lausuch@ericsson.com) -# -# Installs the Functest framework within the Docker container -# and run the tests automatically -# -# # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 # - import argparse import json import os @@ -21,13 +14,15 @@ import subprocess import sys import yaml -from opnfv.utils import constants as opnfv_constants import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils import functest.utils.openstack_utils as os_utils from functest.utils.constants import CONST +from opnfv.utils import constants as opnfv_constants +from opnfv.deployment import factory + actions = ['start', 'check'] """ logging configuration """ @@ -42,7 +37,7 @@ with open(CONFIG_PATCH_PATH) as f: functest_patch_yaml = yaml.safe_load(f) -class PrepareEnvParser(): +class PrepareEnvParser(object): def __init__(self): self.parser = argparse.ArgumentParser() @@ -222,20 +217,19 @@ def install_rally(): "Deployment %s does not exist." % CONST.rally_deployment_name), verbose=False) + rally_conf = os_utils.get_credentials_for_rally() with open('rally_conf.json', 'w') as fp: json.dump(rally_conf, fp) cmd = ("rally deployment create " - "--file=rally_conf.json --name={}" + "--file=rally_conf.json --name={0}" .format(CONST.rally_deployment_name)) - ft_utils.execute_command(cmd, - error_msg=("Problem while creating " - "Rally deployment")) + error_msg = "Problem while creating Rally deployment" + ft_utils.execute_command_raise(cmd, error_msg=error_msg) cmd = "rally deployment check" - ft_utils.execute_command(cmd, - error_msg=("OpenStack not responding or " - "faulty Rally deployment.")) + error_msg = "OpenStack not responding or faulty Rally deployment." + ft_utils.execute_command_raise(cmd, error_msg=error_msg) cmd = "rally deployment list" ft_utils.execute_command(cmd, @@ -250,19 +244,30 @@ def install_rally(): def install_tempest(): logger.info("Installing tempest from existing repo...") - cmd = ("rally verify create-verifier --source {0} " - "--name {1} --type tempest" - .format(CONST.dir_repo_tempest, CONST.tempest_deployment_name)) - ft_utils.execute_command(cmd, - error_msg="Problem while installing Tempest.") + cmd = ("rally verify list-verifiers | " + "grep '{0}' | wc -l".format(CONST.tempest_deployment_name)) + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) + while p.poll() is None: + line = p.stdout.readline().rstrip() + if str(line) == '0': + logger.debug("Tempest %s does not exist" % + CONST.tempest_deployment_name) + cmd = ("rally verify create-verifier --source {0} " + "--name {1} --type tempest" + .format(CONST.dir_repo_tempest, + CONST.tempest_deployment_name)) + error_msg = "Problem while installing Tempest." + ft_utils.execute_command_raise(cmd, error_msg=error_msg) def create_flavor(): - os_utils.get_or_create_flavor('m1.tiny', - '512', - '1', - '1', - public=True) + _, flavor_id = os_utils.get_or_create_flavor('m1.tiny', + '512', + '1', + '1', + public=True) + if flavor_id is None: + raise Exception('Failed to create flavor') def check_environment(): @@ -278,6 +283,32 @@ def check_environment(): logger.info("Functest environment is installed.") +def print_deployment_info(): + installer_params_yaml = os.path.join(CONST.dir_repo_functest, + 'functest/ci/installer_params.yaml') + if (CONST.INSTALLER_IP and CONST.INSTALLER_TYPE and + CONST.INSTALLER_TYPE in opnfv_constants.INSTALLERS): + installer_params = ft_utils.get_parameter_from_yaml( + CONST.INSTALLER_TYPE, installer_params_yaml) + + user = installer_params.get('user', None) + password = installer_params.get('password', None) + pkey = installer_params.get('pkey', None) + + try: + handler = factory.Factory.get_handler( + installer=CONST.INSTALLER_TYPE, + installer_ip=CONST.INSTALLER_IP, + installer_user=user, + installer_pwd=password, + pkey_file=pkey) + if handler: + logger.info('\n\nDeployment information:\n%s' % + handler.get_deployment_info()) + except Exception as e: + logger.debug("Cannot get deployment information. %s" % e) + + def main(**kwargs): try: if not (kwargs['action'] in actions): @@ -296,6 +327,7 @@ def main(**kwargs): with open(CONST.env_active, "w") as env_file: env_file.write("1") check_environment() + print_deployment_info() elif kwargs['action'] == "check": check_environment() except Exception as e: diff --git a/functest/ci/run_tests.py b/functest/ci/run_tests.py index 93518de0b..f920e70d8 100755 --- a/functest/ci/run_tests.py +++ b/functest/ci/run_tests.py @@ -48,7 +48,7 @@ class BlockingTestFailed(Exception): pass -class RunTestsParser(): +class RunTestsParser(object): def __init__(self): self.parser = argparse.ArgumentParser() diff --git a/functest/ci/testcases.yaml b/functest/ci/testcases.yaml index 3a8751a85..009f9b79d 100755 --- a/functest/ci/testcases.yaml +++ b/functest/ci/testcases.yaml @@ -348,6 +348,21 @@ tiers: run: module: 'functest.opnfv_tests.features.netready' class: 'GluonVping' + - + name: barometer + criteria: 'status == "PASS"' + blocking: false + description: >- + Test suite for the Barometer project. Separate tests verify the + proper configuration and functionality of the following + collectd plugins Ceilometer, Hugepages, Memory RAS (mcelog), + and OVS Events + dependencies: + installer: 'fuel' + scenario: 'kvm_ovs_dpdk_bar' + run: + module: 'functest.opnfv_tests.features.barometer' + class: 'BarometerCollectd' - name: components order: 3 @@ -449,8 +464,8 @@ tiers: description: >- VNF deployment with OpenBaton (Orchestra) dependencies: - installer: 'unknown' - scenario: 'unknown' + installer: '' + scenario: '' run: module: 'functest.opnfv_tests.vnf.ims.orchestra_ims' class: 'ImsVnf' diff --git a/functest/ci/tier_builder.py b/functest/ci/tier_builder.py index e1c3e49e6..dae7c73e8 100755 --- a/functest/ci/tier_builder.py +++ b/functest/ci/tier_builder.py @@ -11,7 +11,7 @@ import tier_handler as th import yaml -class TierBuilder: +class TierBuilder(object): def __init__(self, ci_installer, ci_scenario, testcases_file): self.ci_installer = ci_installer diff --git a/functest/ci/tier_handler.py b/functest/ci/tier_handler.py index 1eadfba50..127986bf3 100755 --- a/functest/ci/tier_handler.py +++ b/functest/ci/tier_handler.py @@ -28,7 +28,7 @@ def split_text(text, max_len): return lines -class Tier: +class Tier(object): def __init__(self, name, order, ci_loop, description=""): self.tests_array = [] @@ -102,7 +102,7 @@ class Tier: return out -class TestCase: +class TestCase(object): def __init__(self, name, dependency, criteria, blocking, description=""): self.name = name @@ -160,7 +160,7 @@ class TestCase: return out -class Dependency: +class Dependency(object): def __init__(self, installer, scenario): self.installer = installer diff --git a/functest/cli/commands/cli_env.py b/functest/cli/commands/cli_env.py index 9423631bf..14ad01bfc 100644 --- a/functest/cli/commands/cli_env.py +++ b/functest/cli/commands/cli_env.py @@ -16,7 +16,7 @@ from functest.utils.constants import CONST import functest.utils.functest_utils as ft_utils -class CliEnv: +class CliEnv(object): def __init__(self): pass diff --git a/functest/cli/commands/cli_os.py b/functest/cli/commands/cli_os.py index aeb34974f..f85f4041f 100644 --- a/functest/cli/commands/cli_os.py +++ b/functest/cli/commands/cli_os.py @@ -18,7 +18,7 @@ import functest.utils.openstack_clean as os_clean import functest.utils.openstack_snapshot as os_snapshot -class CliOpenStack: +class CliOpenStack(object): def __init__(self): self.os_auth_url = CONST.OS_AUTH_URL diff --git a/functest/cli/commands/cli_testcase.py b/functest/cli/commands/cli_testcase.py index b6566245a..6644a0c29 100644 --- a/functest/cli/commands/cli_testcase.py +++ b/functest/cli/commands/cli_testcase.py @@ -19,7 +19,7 @@ import functest.utils.functest_utils as ft_utils import functest.utils.functest_vacation as vacation -class CliTestcase: +class CliTestcase(object): def __init__(self): self.tiers = tb.TierBuilder(CONST.INSTALLER_TYPE, diff --git a/functest/cli/commands/cli_tier.py b/functest/cli/commands/cli_tier.py index b9d25b6d0..012b11d0e 100644 --- a/functest/cli/commands/cli_tier.py +++ b/functest/cli/commands/cli_tier.py @@ -18,7 +18,7 @@ from functest.utils.constants import CONST import functest.utils.functest_utils as ft_utils -class CliTier: +class CliTier(object): def __init__(self): self.tiers = tb.TierBuilder(CONST.INSTALLER_TYPE, diff --git a/functest/core/feature_base.py b/functest/core/feature_base.py index fe9a99989..2bd1ec83d 100644 --- a/functest/core/feature_base.py +++ b/functest/core/feature_base.py @@ -7,6 +7,7 @@ from functest.utils.constants import CONST class FeatureBase(base.TestcaseBase): + def __init__(self, project='functest', case='', repo='', cmd=''): super(FeatureBase, self).__init__() self.project_name = project @@ -19,7 +20,7 @@ class FeatureBase(base.TestcaseBase): def run(self, **kwargs): self.prepare() self.start_time = time.time() - ret = ft_utils.execute_command(self.cmd, output_file=self.result_file) + ret = self.execute() self.stop_time = time.time() self.post() self.parse_results(ret) @@ -27,6 +28,13 @@ class FeatureBase(base.TestcaseBase): self.logger.info("Test result is stored in '%s'" % self.result_file) return base.TestcaseBase.EX_OK + def execute(self): + ''' + Executer method that can be overwritten + By default it executes a shell command. + ''' + return ft_utils.execute_command(self.cmd, output_file=self.result_file) + def prepare(self, **kwargs): pass diff --git a/functest/core/vnf_base.py b/functest/core/vnf_base.py index 07b64fd05..9438dca10 100644 --- a/functest/core/vnf_base.py +++ b/functest/core/vnf_base.py @@ -111,9 +111,9 @@ class VnfOnBoardingBase(base.TestcaseBase): self.keystone_client = os_utils.get_keystone_client() self.logger.info("Prepare OpenStack plateform(create tenant and user)") - user_id = os_utils.get_user_id(self.keystone_client, - self.creds['username']) - if user_id == '': + admin_user_id = os_utils.get_user_id(self.keystone_client, + self.creds['username']) + if admin_user_id == '': self.step_failure("Failed to get id of " + self.creds['username']) @@ -133,7 +133,7 @@ class VnfOnBoardingBase(base.TestcaseBase): self.logger.error("Failed to get id for %s role" % role_name) self.step_failure("Failed to get role id of " + role_name) - if not os_utils.add_role_user(self.keystone_client, user_id, + if not os_utils.add_role_user(self.keystone_client, admin_user_id, role_id, tenant_id): self.logger.error("Failed to add %s on tenant" % self.creds['username']) @@ -149,6 +149,13 @@ class VnfOnBoardingBase(base.TestcaseBase): self.logger.error("Failed to create %s user" % self.tenant_name) self.step_failure("Failed to create user ") + if not os_utils.add_role_user(self.keystone_client, user_id, + role_id, tenant_id): + self.logger.error("Failed to add %s on tenant" % + self.tenant_name) + self.step_failure("Failed to add %s on tenant" % + self.tenant_name) + self.logger.info("Update OpenStack creds informations") self.admin_creds = self.creds.copy() self.admin_creds.update({ diff --git a/functest/opnfv_tests/features/barometer.py b/functest/opnfv_tests/features/barometer.py new file mode 100644 index 000000000..aec2bce5d --- /dev/null +++ b/functest/opnfv_tests/features/barometer.py @@ -0,0 +1,28 @@ +#!/usr/bin/python +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 + + +import functest.core.feature_base as base +import functest.utils.functest_logger as ft_logger + +from baro_tests import collectd + + +class BarometerCollectd(base.FeatureBase): + ''' + Class for executing barometercollectd testcase. + ''' + + def __init__(self): + super(BarometerCollectd, self).__init__(project='barometer', + case='barometercollectd', + repo='dir_repo_barometer') + self.logger = ft_logger.Logger("BarometerCollectd").getLogger() + + def execute(self): + return collectd.main(self.logger) diff --git a/functest/opnfv_tests/openstack/vping/vping_base.py b/functest/opnfv_tests/openstack/vping/vping_base.py index a5309bd44..9d57cfaea 100644 --- a/functest/opnfv_tests/openstack/vping/vping_base.py +++ b/functest/opnfv_tests/openstack/vping/vping_base.py @@ -32,6 +32,8 @@ class VPingBase(testcase_base.TestcaseBase): self.image_name = CONST.vping_image_name self.image_filename = CONST.openstack_image_file_name self.image_format = CONST.openstack_image_disk_format + self.image_username = CONST.openstack_image_username + self.image_password = CONST.openstack_image_password self.image_path = os.path.join(CONST.dir_functest_data, self.image_filename) diff --git a/functest/opnfv_tests/openstack/vping/vping_ssh.py b/functest/opnfv_tests/openstack/vping/vping_ssh.py index b032c3087..7a58a41fa 100755 --- a/functest/opnfv_tests/openstack/vping/vping_ssh.py +++ b/functest/opnfv_tests/openstack/vping/vping_ssh.py @@ -61,8 +61,6 @@ class VPingSSH(vping_base.VPingBase): def establish_ssh(self, vm, floatip): self.logger.info("Trying to establish SSH connection to %s..." % floatip) - username = 'cirros' - password = 'cubswin:)' ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) @@ -73,8 +71,8 @@ class VPingSSH(vping_base.VPingBase): cidr_first_octet = self.private_subnet_cidr.split('.')[0] while timeout > 0: try: - ssh.connect(floatip, username=username, - password=password, timeout=2) + ssh.connect(floatip, username=self.image_username, + password=self.image_password, timeout=2) self.logger.debug("SSH connection established to %s." % floatip) break diff --git a/functest/opnfv_tests/sdn/odl/odl.py b/functest/opnfv_tests/sdn/odl/odl.py index 9bff324f1..69818f5a5 100755 --- a/functest/opnfv_tests/sdn/odl/odl.py +++ b/functest/opnfv_tests/sdn/odl/odl.py @@ -186,7 +186,7 @@ class ODLTests(testcase_base.TestcaseBase): return self.main(suites, **kwargs) -class ODLParser(): +class ODLParser(object): def __init__(self): self.parser = argparse.ArgumentParser() diff --git a/functest/opnfv_tests/sdn/onos/sfc/sfc_onos.py b/functest/opnfv_tests/sdn/onos/sfc/sfc_onos.py index 090502ba9..c21986902 100644 --- a/functest/opnfv_tests/sdn/onos/sfc/sfc_onos.py +++ b/functest/opnfv_tests/sdn/onos/sfc/sfc_onos.py @@ -10,13 +10,15 @@ from pexpect import pxssh import functest.utils.functest_logger as ft_logger +from functest.utils.constants import CONST + OK = 200 CREATED = 201 ACCEPTED = 202 NO_CONTENT = 204 -class SfcOnos: +class SfcOnos(object): """Defines all the def function of SFC.""" def __init__(self): @@ -99,6 +101,8 @@ class SfcOnos: self.ip_pool = 0 self.vm_public_ip = [] self.vm_public_id = [] + self.cirros_username = CONST.openstack_image_username + self.cirros_password = CONST.openstack_image_password self.net_id1 = 0 self.vm = [] self.address = 0 @@ -628,9 +632,7 @@ class SfcOnos: s = pxssh.pxssh() hostname = self.vm_public_ip[0] - username = "cirros" - password = "cubswin:)" - s.login(hostname, username, password) + s.login(hostname, self.cirros_username, self.cirros_password) s.sendline("ping -c 5 " + str(self.port_ip[2])) s.prompt() # match the prompt @@ -644,9 +646,7 @@ class SfcOnos: def vm1(queue1): s = pxssh.pxssh() hostname = self.vm_public_ip[1] - username = "cirros" - password = "cubswin:)" - s.login(hostname, username, password) + s.login(hostname, self.cirros_username, self.cirros_password) s.sendline('sudo ./firewall') s.prompt() output_pack = s.before diff --git a/functest/opnfv_tests/sdn/onos/teston/adapters/foundation.py b/functest/opnfv_tests/sdn/onos/teston/adapters/foundation.py index bf2c4302c..2bef5cc6e 100644 --- a/functest/opnfv_tests/sdn/onos/teston/adapters/foundation.py +++ b/functest/opnfv_tests/sdn/onos/teston/adapters/foundation.py @@ -21,7 +21,7 @@ import functest.utils.functest_constants as ft_constants import functest.utils.functest_utils as ft_utils -class Foundation: +class Foundation(object): def __init__(self): diff --git a/functest/opnfv_tests/vnf/ims/clearwater.py b/functest/opnfv_tests/vnf/ims/clearwater.py index eb0abacdc..32c6dc5c9 100644 --- a/functest/opnfv_tests/vnf/ims/clearwater.py +++ b/functest/opnfv_tests/vnf/ims/clearwater.py @@ -12,7 +12,7 @@ ######################################################################## -class Clearwater: +class Clearwater(object): def __init__(self, inputs={}, orchestrator=None, logger=None): self.config = inputs diff --git a/functest/opnfv_tests/vnf/ims/opera_ims.py b/functest/opnfv_tests/vnf/ims/opera_ims.py index 073a56c37..7ead401fe 100644 --- a/functest/opnfv_tests/vnf/ims/opera_ims.py +++ b/functest/opnfv_tests/vnf/ims/opera_ims.py @@ -8,148 +8,393 @@ # http://www.apache.org/licenses/LICENSE-2.0 import json -import os -import requests -import subprocess +import socket +import sys import time +import yaml import functest.core.vnf_base as vnf_base import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils +import functest.utils.openstack_utils as os_utils +import os from functest.utils.constants import CONST +from org.openbaton.cli.agents.agents import MainAgent +from org.openbaton.cli.errors.errors import NfvoException + + +def servertest(host, port): + args = socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_STREAM) + for family, socktype, proto, canonname, sockaddr in args: + s = socket.socket(family, socktype, proto) + try: + s.connect(sockaddr) + except socket.error: + return False + else: + s.close() + return True + +# ---------------------------------------------------------- +# +# UTILS +# +# ----------------------------------------------------------- + + +def get_config(parameter, file): + """ + Returns the value of a given parameter in file.yaml + parameter must be given in string format with dots + Example: general.openstack.image_name + """ + with open(file) as f: + file_yaml = yaml.safe_load(f) + f.close() + value = file_yaml + for element in parameter.split("."): + value = value.get(element) + if value is None: + raise ValueError("The parameter %s is not defined in" + " reporting.yaml" % parameter) + return value + + +def download_and_add_image_on_glance(glance, image_name, + image_url, data_dir): + dest_path = data_dir + if not os.path.exists(dest_path): + os.makedirs(dest_path) + file_name = image_url.rsplit('/')[-1] + if not ft_utils.download_url(image_url, dest_path): + return False + image = os_utils.create_glance_image( + glance, image_name, dest_path + file_name) + if not image: + return False + return image + class ImsVnf(vnf_base.VnfOnBoardingBase): - def __init__(self, project='functest', case='opera_ims', + def __init__(self, project='functest', case='orchestra_ims', repo='', cmd=''): super(ImsVnf, self).__init__(project, case, repo, cmd) - self.logger = ft_logger.Logger("vIMS").getLogger() - self.case_dir = os.path.join(CONST.functest_test, 'vnf/ims/') - self.data_dir = CONST.dir_vIMS_data + self.ob_password = "openbaton" + self.ob_username = "admin" + self.ob_https = False + self.ob_port = "8080" + self.ob_ip = "localhost" + self.ob_instance_id = "" + self.logger = ft_logger.Logger("orchestra_ims").getLogger() + self.case_dir = os.path.join(CONST.dir_functest_test, 'vnf/ims/') + self.data_dir = CONST.dir_ims_data self.test_dir = CONST.dir_repo_vims_test - + self.ob_projectid = "" + self.keystone_client = os_utils.get_keystone_client() + self.ob_nsr_id = "" + self.main_agent = None # vIMS Data directory creation if not os.path.exists(self.data_dir): os.makedirs(self.data_dir) + # Retrieve the configuration + try: + self.config = CONST.__getattribute__( + 'vnf_{}_config'.format(self.case_name)) + except: + raise Exception("Orchestra VNF config file not found") + config_file = self.case_dir + self.config + self.imagename = get_config("openbaton.imagename", config_file) + self.market_link = get_config("openbaton.marketplace_link", + config_file) + self.images = get_config("tenant_images", config_file) def deploy_orchestrator(self, **kwargs): - # TODO - # deploy open-O from Functest docker located on the Jumphost - # you have admin rights on OpenStack SUT - # you can cretae a VM, spawn docker on the jumphost - # spawn docker on a VM in the SUT, ..up to you - # - # note: this step can be ignored - # if Open-O is part of the installer + self.logger.info("Additional pre-configuration steps") + nova_client = os_utils.get_nova_client() + neutron_client = os_utils.get_neutron_client() + glance_client = os_utils.get_glance_client() + + # needs some images + self.logger.info("Upload some OS images if it doesn't exist") + temp_dir = os.path.join(self.data_dir, "tmp/") + for image_name, image_url in self.images.iteritems(): + self.logger.info("image: %s, url: %s" % (image_name, image_url)) + try: + image_id = os_utils.get_image_id(glance_client, + image_name) + self.logger.info("image_id: %s" % image_id) + except: + self.logger.error("Unexpected error: %s" % sys.exc_info()[0]) + + if image_id == '': + self.logger.info("""%s image doesn't exist on glance repository. Try + downloading this image and upload on glance !""" % image_name) + image_id = download_and_add_image_on_glance(glance_client, + image_name, + image_url, + temp_dir) + if image_id == '': + self.step_failure( + "Failed to find or upload required OS " + "image for this deployment") + network_dic = os_utils.create_network_full(neutron_client, + "openbaton_mgmt", + "openbaton_mgmt_subnet", + "openbaton_router", + "192.168.100.0/24") + + # orchestrator VM flavor + self.logger.info("Check medium Flavor is available, if not create one") + flavor_exist, flavor_id = os_utils.get_or_create_flavor( + "m1.medium", + "4096", + '1', + '2', + public=True) + self.logger.debug("Flavor id: %s" % flavor_id) + + if not network_dic: + self.logger.error("There has been a problem when creating the " + "neutron network") + + network_id = network_dic["net_id"] + + self.logger.info("Creating floating IP for VM in advance...") + floatip_dic = os_utils.create_floating_ip(neutron_client) + floatip = floatip_dic['fip_addr'] + + if floatip is None: + self.logger.error("Cannot create floating IP.") + + userdata = "#!/bin/bash\n" + userdata += "set -x\n" + userdata += "set -e\n" + userdata += "echo \"nameserver 8.8.8.8\" >> /etc/resolv.conf\n" + userdata += "apt-get install curl\n" + userdata += ("echo \"rabbitmq_broker_ip=%s\" > ./config_file\n" + % floatip) + userdata += "echo \"mysql=no\" >> ./config_file\n" + userdata += ("echo \"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCuPXrV3" + "geeHc6QUdyUr/1Z+yQiqLcOskiEGBiXr4z76MK4abiFmDZ18OMQlc" + "fl0p3kS0WynVgyaOHwZkgy/DIoIplONVr2CKBKHtPK+Qcme2PVnCtv" + "EqItl/FcD+1h5XSQGoa+A1TSGgCod/DPo+pes0piLVXP8Ph6QS1k7S" + "ic7JDeRQ4oT1bXYpJ2eWBDMfxIWKZqcZRiGPgMIbJ1iEkxbpeaAd9O" + "4MiM9nGCPESmed+p54uYFjwEDlAJZShcAZziiZYAvMZhvAhe6USljc" + "7YAdalAnyD/jwCHuwIrUw/lxo7UdNCmaUxeobEYyyFA1YVXzpNFZya" + "XPGAAYIJwEq/ openbaton@opnfv\" >> /home/ubuntu/.ssh/aut" + "horized_keys\n") + userdata += "cat ./config_file\n" + userdata += ("curl -s http://get.openbaton.org/bootstrap " + "> ./bootstrap\n") + userdata += "export OPENBATON_COMPONENT_AUTOSTART=false\n" + bootstrap = "sh ./bootstrap release -configFile=./config_file" + userdata += bootstrap + "\n" + + userdata += ("echo \"nfvo.plugin.timeout=300000\" >> " + "/etc/openbaton/openbaton-nfvo.properties\n") + userdata += "service openbaton-nfvo restart\n" + userdata += "service openbaton-vnfm-generic restart\n" + + sg_id = os_utils.create_security_group_full(neutron_client, + "orchestra-sec-group", + "allowall") + + os_utils.create_secgroup_rule(neutron_client, sg_id, "ingress", + "icmp", 0, 255) + os_utils.create_secgroup_rule(neutron_client, sg_id, "egress", + "icmp", 0, 255) + os_utils.create_secgroup_rule(neutron_client, sg_id, "ingress", + "tcp", 1, 65535) + os_utils.create_secgroup_rule(neutron_client, sg_id, "ingress", + "udp", 1, 65535) + os_utils.create_secgroup_rule(neutron_client, sg_id, "egress", + "tcp", 1, 65535) + os_utils.create_secgroup_rule(neutron_client, sg_id, "egress", + "udp", 1, 65535) + + self.logger.info("Security group set") + + self.logger.info("Create instance....") + self.logger.info("flavor: m1.medium\n" + "image: %s\n" + "network_id: %s\n" + "userdata: %s\n" + % (self.imagename, network_id, userdata)) + + instance = os_utils.create_instance_and_wait_for_active( + "m1.medium", + os_utils.get_image_id(glance_client, self.imagename), + network_id, + "orchestra-openbaton", + config_drive=False, + userdata=userdata) + + self.ob_instance_id = instance.id + + self.logger.info("Adding sec group to orchestra instance") + os_utils.add_secgroup_to_instance(nova_client, + self.ob_instance_id, sg_id) + + self.logger.info("Associating floating ip: '%s' to VM '%s' " + % (floatip, "orchestra-openbaton")) + if not os_utils.add_floating_ip(nova_client, instance.id, floatip): + self.logger.error("Cannot associate floating IP to VM.") + self.step_failure("Cannot associate floating IP to VM.") + + self.logger.info("Waiting for nfvo to be up and running...") + x = 0 + while x < 100: + if servertest(floatip, "8080"): + break + else: + self.logger.debug("openbaton is not started yet") + time.sleep(5) + x += 1 + + if x == 100: + self.logger.error("Openbaton is not started correctly") + self.step_failure("Openbaton is not started correctly") + + self.ob_ip = floatip + self.ob_password = "openbaton" + self.ob_username = "admin" + self.ob_https = False + self.ob_port = "8080" + self.logger.info("Deploy orchestrator: OK") def deploy_vnf(self): - # TODO - self.logger.info("Deploy VNF: OK") + self.logger.info("vIMS Deployment") + + self.main_agent = MainAgent(nfvo_ip=self.ob_ip, + nfvo_port=self.ob_port, + https=self.ob_https, + version=1, + username=self.ob_username, + password=self.ob_password) + + project_agent = self.main_agent.get_agent("project", self.ob_projectid) + for p in json.loads(project_agent.find()): + if p.get("name") == "default": + self.ob_projectid = p.get("id") + break + + self.logger.debug("project id: %s" % self.ob_projectid) + if self.ob_projectid == "": + self.logger.error("Default project id was not found!") + self.step_failure("Default project id was not found!") + + vim_json = { + "name": "vim-instance", + "authUrl": os_utils.get_credentials().get("auth_url"), + "tenant": os_utils.get_credentials().get("tenant_name"), + "username": os_utils.get_credentials().get("username"), + "password": os_utils.get_credentials().get("password"), + # "keyPair": "opnfv", + # TODO change the keypair to correct value + # or upload a correct one or remove it + "securityGroups": [ + "default", + "orchestra-sec-group" + ], + "type": "openstack", + "location": { + "name": "opnfv", + "latitude": "52.525876", + "longitude": "13.314400" + } + } + + self.logger.debug("vim: %s" % vim_json) + + self.main_agent.get_agent( + "vim", + project_id=self.ob_projectid).create(entity=json.dumps(vim_json)) + + market_agent = self.main_agent.get_agent("market", + project_id=self.ob_projectid) + + nsd = {} + try: + self.logger.info("sending: %s" % self.market_link) + nsd = market_agent.create(entity=self.market_link) + self.logger.info("Onboarded nsd: " + nsd.get("name")) + except NfvoException as e: + self.step_failure(e.message) + + nsr_agent = self.main_agent.get_agent("nsr", + project_id=self.ob_projectid) + nsd_id = nsd.get('id') + if nsd_id is None: + self.step_failure("NSD not onboarded correctly") + + nsr = None + try: + nsr = nsr_agent.create(nsd_id) + except NfvoException as e: + self.step_failure(e.message) + + if nsr.get('code') is not None: + self.logger.error( + "vIMS cannot be deployed: %s -> %s" % + (nsr.get('code'), nsr.get('message'))) + self.step_failure("vIMS cannot be deployed") + + i = 0 + self.logger.info("waiting NSR to go to active...") + while nsr.get("status") != 'ACTIVE' and nsr.get("status") != 'ERROR': + i += 1 + if i == 100: + self.step_failure("After %s sec the nsr did not go to active.." + % 5 * 100) + time.sleep(5) + nsr = json.loads(nsr_agent.find(nsr.get('id'))) + + if nsr.get("status") == 'ACTIVE': + deploy_vnf = {'status': "PASS", 'result': nsr} + self.logger.info("Deploy VNF: OK") + else: + deploy_vnf = {'status': "FAIL", 'result': nsr} + self.logger.error("Deploy VNF: ERROR") + self.step_failure("Deploy vIMS failed") + self.ob_nsr_id = nsr.get("id") + return deploy_vnf def test_vnf(self): # Adaptations probably needed # code used for cloudify_ims # ruby client on jumphost calling the vIMS on the SUT - script = "source {0}venv_cloudify/bin/activate; " - script += "cd {0}; " - script += "cfy status | grep -Eo \"([0-9]{{1,3}}\.){{3}}[0-9]{{1,3}}\"" - cmd = "/bin/bash -c '" + script.format(self.data_dir) + "'" + return - try: - self.logger.debug("Trying to get clearwater manager IP ... ") - mgr_ip = os.popen(cmd).read() - mgr_ip = mgr_ip.splitlines()[0] - except: - self.step_failure("Unable to retrieve the IP of the " - "cloudify manager server !") - - api_url = "http://" + mgr_ip + "/api/v2" - dep_outputs = requests.get(api_url + "/deployments/" + - self.vnf.deployment_name + "/outputs") - dns_ip = dep_outputs.json()['outputs']['dns_ip'] - ellis_ip = dep_outputs.json()['outputs']['ellis_ip'] - - ellis_url = "http://" + ellis_ip + "/" - url = ellis_url + "accounts" - - params = {"password": "functest", - "full_name": "opnfv functest user", - "email": "functest@opnfv.fr", - "signup_code": "secret"} - - rq = requests.post(url, data=params) - i = 20 - while rq.status_code != 201 and i > 0: - rq = requests.post(url, data=params) - i = i - 1 - time.sleep(10) - - if rq.status_code == 201: - url = ellis_url + "session" - rq = requests.post(url, data=params) - cookies = rq.cookies - - url = ellis_url + "accounts/" + params['email'] + "/numbers" - if cookies != "": - rq = requests.post(url, cookies=cookies) - i = 24 - while rq.status_code != 200 and i > 0: - rq = requests.post(url, cookies=cookies) - i = i - 1 - time.sleep(25) - - if rq.status_code != 200: - self.step_failure("Unable to create a number: %s" - % rq.json()['reason']) - - nameservers = ft_utils.get_resolvconf_ns() - resolvconf = "" - for ns in nameservers: - resolvconf += "\nnameserver " + ns - - if dns_ip != "": - script = ('echo -e "nameserver ' + dns_ip + resolvconf + - '" > /etc/resolv.conf; ') - script += 'source /etc/profile.d/rvm.sh; ' - script += 'cd {0}; ' - script += ('rake test[{1}] SIGNUP_CODE="secret"') - - cmd = ("/bin/bash -c '" + - script.format(self.data_dir, self.inputs["public_domain"]) + - "'") - output_file = "output.txt" - f = open(output_file, 'w+') - subprocess.call(cmd, shell=True, stdout=f, - stderr=subprocess.STDOUT) - f.close() - - f = open(output_file, 'r') - result = f.read() - if result != "": - self.logger.debug(result) - - vims_test_result = "" - tempFile = os.path.join(self.test_dir, "temp.json") - try: - self.logger.debug("Trying to load test results") - with open(tempFile) as f: - vims_test_result = json.load(f) - f.close() - except: - self.logger.error("Unable to retrieve test results") + def clean(self): + self.main_agent.get_agent( + "nsr", + project_id=self.ob_projectid).delete(self.ob_nsr_id) + time.sleep(5) + os_utils.delete_instance(nova_client=os_utils.get_nova_client(), + instance_id=self.ob_instance_id) + # TODO question is the clean removing also the VM? + # I think so since is goinf to remove the tenant... + super(ImsVnf, self).clean() - try: - os.remove(tempFile) - except: - self.logger.error("Deleting file failed") + def main(self, **kwargs): + self.logger.info("Orchestra IMS VNF onboarding test starting") + self.execute() + self.logger.info("Orchestra IMS VNF onboarding test executed") + if self.criteria is "PASS": + return self.EX_OK + else: + return self.EX_RUN_ERROR - if vims_test_result != '': - return {'status': 'PASS', 'result': vims_test_result} - else: - return {'status': 'FAIL', 'result': ''} + def run(self): + kwargs = {} + return self.main(**kwargs) - def clean(self): - # TODO - super(ImsVnf, self).clean() + +if __name__ == '__main__': + test = ImsVnf() + test.deploy_orchestrator() + test.deploy_vnf() + test.clean() diff --git a/functest/opnfv_tests/vnf/ims/orchestra_ims.py b/functest/opnfv_tests/vnf/ims/orchestra_ims.py index 28f37f053..352b609b0 100644 --- a/functest/opnfv_tests/vnf/ims/orchestra_ims.py +++ b/functest/opnfv_tests/vnf/ims/orchestra_ims.py @@ -8,150 +8,383 @@ # http://www.apache.org/licenses/LICENSE-2.0 import json -import os -import requests -import subprocess +import socket +import sys import time +import yaml import functest.core.vnf_base as vnf_base import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils +import functest.utils.openstack_utils as os_utils +import os from functest.utils.constants import CONST +from org.openbaton.cli.agents.agents import MainAgent +from org.openbaton.cli.errors.errors import NfvoException -class ImsVnf(vnf_base.VnfOnBoardingBase): +def servertest(host, port): + args = socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_STREAM) + for family, socktype, proto, canonname, sockaddr in args: + s = socket.socket(family, socktype, proto) + try: + s.connect(sockaddr) + except socket.error: + return False + else: + s.close() + return True + + +class ImsVnf(vnf_base.VnfOnBoardingBase): def __init__(self, project='functest', case='orchestra_ims', repo='', cmd=''): super(ImsVnf, self).__init__(project, case, repo, cmd) - self.logger = ft_logger.Logger("vIMS").getLogger() - self.case_dir = os.path.join(CONST.functest_test, 'vnf/ims/') - self.data_dir = CONST.dir_vIMS_data + self.ob_password = "openbaton" + self.ob_username = "admin" + self.ob_https = False + self.ob_port = "8080" + self.ob_ip = "localhost" + self.ob_instance_id = "" + self.logger = ft_logger.Logger("orchestra_ims").getLogger() + self.case_dir = os.path.join(CONST.dir_functest_test, 'vnf/ims/') + self.data_dir = CONST.dir_ims_data self.test_dir = CONST.dir_repo_vims_test - + self.ob_projectid = "" + self.keystone_client = os_utils.get_keystone_client() + self.ob_nsr_id = "" + self.main_agent = None # vIMS Data directory creation if not os.path.exists(self.data_dir): os.makedirs(self.data_dir) + # Retrieve the configuration + try: + self.config = CONST.__getattribute__( + 'vnf_{}_config'.format(self.case_name)) + except: + raise Exception("Orchestra VNF config file not found") + config_file = self.case_dir + self.config + self.imagename = get_config("openbaton.imagename", config_file) + self.market_link = get_config("openbaton.marketplace_link", + config_file) + self.images = get_config("tenant_images", config_file) def deploy_orchestrator(self, **kwargs): - # TODO - # put your code here to deploy openbaton - # from the functest docker located on the jumphost - # you have admin rights on OpenStack SUT - # you can cretae a VM, spawn docker on the jumphost - # spawn docker on a VM in the SUT, ..up to you - # - # note: this step can be ignored - # if OpenBaton is part of the installer + self.logger.info("Additional pre-configuration steps") + nova_client = os_utils.get_nova_client() + neutron_client = os_utils.get_neutron_client() + glance_client = os_utils.get_glance_client() + + # Import images if needed + self.logger.info("Upload some OS images if it doesn't exist") + temp_dir = os.path.join(self.data_dir, "tmp/") + for image_name, image_url in self.images.iteritems(): + self.logger.info("image: %s, url: %s" % (image_name, image_url)) + try: + image_id = os_utils.get_image_id(glance_client, + image_name) + self.logger.info("image_id: %s" % image_id) + except: + self.logger.error("Unexpected error: %s" % sys.exc_info()[0]) + + if image_id == '': + self.logger.info("""%s image doesn't exist on glance repository. Try + downloading this image and upload on glance !""" % image_name) + image_id = download_and_add_image_on_glance(glance_client, + image_name, + image_url, + temp_dir) + if image_id == '': + self.step_failure( + "Failed to find or upload required OS " + "image for this deployment") + network_dic = os_utils.create_network_full(neutron_client, + "openbaton_mgmt", + "openbaton_mgmt_subnet", + "openbaton_router", + "192.168.100.0/24") + + # orchestrator VM flavor + self.logger.info("Check medium Flavor is available, if not create one") + flavor_exist, flavor_id = os_utils.get_or_create_flavor( + "m1.medium", + "4096", + '20', + '2', + public=True) + self.logger.debug("Flavor id: %s" % flavor_id) + + if not network_dic: + self.logger.error("There has been a problem when creating the " + "neutron network") + + network_id = network_dic["net_id"] + + self.logger.info("Creating floating IP for VM in advance...") + floatip_dic = os_utils.create_floating_ip(neutron_client) + floatip = floatip_dic['fip_addr'] + + if floatip is None: + self.logger.error("Cannot create floating IP.") + + userdata = "#!/bin/bash\n" + userdata += "set -x\n" + userdata += "set -e\n" + userdata += "echo \"nameserver 8.8.8.8\" >> /etc/resolv.conf\n" + userdata += "apt-get install curl\n" + userdata += ("echo \"rabbitmq_broker_ip=%s\" > ./config_file\n" + % floatip) + userdata += "echo \"mysql=no\" >> ./config_file\n" + userdata += ("echo \"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCuPXrV3" + "geeHc6QUdyUr/1Z+yQiqLcOskiEGBiXr4z76MK4abiFmDZ18OMQlc" + "fl0p3kS0WynVgyaOHwZkgy/DIoIplONVr2CKBKHtPK+Qcme2PVnCtv" + "EqItl/FcD+1h5XSQGoa+A1TSGgCod/DPo+pes0piLVXP8Ph6QS1k7S" + "ic7JDeRQ4oT1bXYpJ2eWBDMfxIWKZqcZRiGPgMIbJ1iEkxbpeaAd9O" + "4MiM9nGCPESmed+p54uYFjwEDlAJZShcAZziiZYAvMZhvAhe6USljc" + "7YAdalAnyD/jwCHuwIrUw/lxo7UdNCmaUxeobEYyyFA1YVXzpNFZya" + "XPGAAYIJwEq/ openbaton@opnfv\" >> /home/ubuntu/.ssh/aut" + "horized_keys\n") + userdata += "cat ./config_file\n" + userdata += ("curl -s http://get.openbaton.org/bootstrap " + "> ./bootstrap\n") + userdata += "export OPENBATON_COMPONENT_AUTOSTART=false\n" + bootstrap = "sh ./bootstrap release -configFile=./config_file" + userdata += bootstrap + "\n" + + userdata += ("echo \"nfvo.plugin.timeout=300000\" >> " + "/etc/openbaton/openbaton-nfvo.properties\n") + userdata += "service openbaton-nfvo restart\n" + userdata += "service openbaton-vnfm-generic restart\n" + + sg_id = os_utils.create_security_group_full(neutron_client, + "orchestra-sec-group", + "allowall") + + os_utils.create_secgroup_rule(neutron_client, sg_id, "ingress", + "icmp", 0, 255) + os_utils.create_secgroup_rule(neutron_client, sg_id, "egress", + "icmp", 0, 255) + os_utils.create_secgroup_rule(neutron_client, sg_id, "ingress", + "tcp", 1, 65535) + os_utils.create_secgroup_rule(neutron_client, sg_id, "ingress", + "udp", 1, 65535) + os_utils.create_secgroup_rule(neutron_client, sg_id, "egress", + "tcp", 1, 65535) + os_utils.create_secgroup_rule(neutron_client, sg_id, "egress", + "udp", 1, 65535) + + self.logger.info("Security group set") + + self.logger.info("Create instance....") + self.logger.info("flavor: m1.medium\n" + "image: %s\n" + "network_id: %s\n" + "userdata: %s\n" + % (self.imagename, network_id, userdata)) + + instance = os_utils.create_instance_and_wait_for_active( + "m1.medium", + os_utils.get_image_id(glance_client, self.imagename), + network_id, + "orchestra-openbaton", + config_drive=False, + userdata=userdata) + + self.ob_instance_id = instance.id + + self.logger.info("Adding sec group to orchestra instance") + os_utils.add_secgroup_to_instance(nova_client, + self.ob_instance_id, sg_id) + + self.logger.info("Associating floating ip: '%s' to VM '%s' " + % (floatip, "orchestra-openbaton")) + if not os_utils.add_floating_ip(nova_client, instance.id, floatip): + self.logger.error("Cannot associate floating IP to VM.") + self.step_failure("Cannot associate floating IP to VM.") + + self.logger.info("Waiting for nfvo to be up and running...") + x = 0 + while x < 100: + if servertest(floatip, "8080"): + break + else: + self.logger.debug("openbaton is not started yet") + time.sleep(5) + x += 1 + + if x == 100: + self.logger.error("Openbaton is not started correctly") + self.step_failure("Openbaton is not started correctly") + + self.ob_ip = floatip + self.ob_password = "openbaton" + self.ob_username = "admin" + self.ob_https = False + self.ob_port = "8080" + self.logger.info("Deploy orchestrator: OK") def deploy_vnf(self): - # deploy the VNF - # call openbaton to deploy the vIMS + self.logger.info("vIMS Deployment") + + self.main_agent = MainAgent(nfvo_ip=self.ob_ip, + nfvo_port=self.ob_port, + https=self.ob_https, + version=1, + username=self.ob_username, + password=self.ob_password) + + project_agent = self.main_agent.get_agent("project", self.ob_projectid) + for p in json.loads(project_agent.find()): + if p.get("name") == "default": + self.ob_projectid = p.get("id") + break + + self.logger.debug("project id: %s" % self.ob_projectid) + if self.ob_projectid == "": + self.logger.error("Default project id was not found!") + self.step_failure("Default project id was not found!") + + vim_json = { + "name": "vim-instance", + "authUrl": os_utils.get_credentials().get("auth_url"), + "tenant": os_utils.get_credentials().get("tenant_name"), + "username": os_utils.get_credentials().get("username"), + "password": os_utils.get_credentials().get("password"), + "keyPair": "opnfv", + # TODO change the keypair to correct value + # or upload a correct one or remove it + "securityGroups": [ + "default", + "orchestra-sec-group" + ], + "type": "openstack", + "location": { + "name": "opnfv", + "latitude": "52.525876", + "longitude": "13.314400" + } + } + + self.logger.debug("vim: %s" % vim_json) + + self.main_agent.get_agent( + "vim", + project_id=self.ob_projectid).create(entity=json.dumps(vim_json)) + + market_agent = self.main_agent.get_agent("market", + project_id=self.ob_projectid) + + nsd = {} + try: + self.logger.info("sending: %s" % self.market_link) + nsd = market_agent.create(entity=self.market_link) + self.logger.info("Onboarded nsd: " + nsd.get("name")) + except NfvoException as e: + self.step_failure(e.message) + + nsr_agent = self.main_agent.get_agent("nsr", + project_id=self.ob_projectid) + nsd_id = nsd.get('id') + if nsd_id is None: + self.step_failure("NSD not onboarded correctly") + + nsr = None + try: + nsr = nsr_agent.create(nsd_id) + except NfvoException as e: + self.step_failure(e.message) + + if nsr is None: + self.step_failure("NSR not deployed correctly") + + i = 0 + self.logger.info("waiting NSR to go to active...") + while nsr.get("status") != 'ACTIVE': + i += 1 + if i == 100: + self.step_failure("After %s sec the nsr did not go to active.." + % 5 * 100) + time.sleep(5) + nsr = json.loads(nsr_agent.find(nsr.get('id'))) + + deploy_vnf = {'status': "PASS", 'result': nsr} + self.ob_nsr_id = nsr.get("id") self.logger.info("Deploy VNF: OK") + return deploy_vnf def test_vnf(self): # Adaptations probably needed # code used for cloudify_ims # ruby client on jumphost calling the vIMS on the SUT - script = "source {0}venv_cloudify/bin/activate; " - script += "cd {0}; " - script += "cfy status | grep -Eo \"([0-9]{{1,3}}\.){{3}}[0-9]{{1,3}}\"" - cmd = "/bin/bash -c '" + script.format(self.data_dir) + "'" + return - try: - self.logger.debug("Trying to get clearwater manager IP ... ") - mgr_ip = os.popen(cmd).read() - mgr_ip = mgr_ip.splitlines()[0] - except: - self.step_failure("Unable to retrieve the IP of the " - "cloudify manager server !") - - api_url = "http://" + mgr_ip + "/api/v2" - dep_outputs = requests.get(api_url + "/deployments/" + - self.vnf.deployment_name + "/outputs") - dns_ip = dep_outputs.json()['outputs']['dns_ip'] - ellis_ip = dep_outputs.json()['outputs']['ellis_ip'] - - ellis_url = "http://" + ellis_ip + "/" - url = ellis_url + "accounts" - - params = {"password": "functest", - "full_name": "opnfv functest user", - "email": "functest@opnfv.fr", - "signup_code": "secret"} - - rq = requests.post(url, data=params) - i = 20 - while rq.status_code != 201 and i > 0: - rq = requests.post(url, data=params) - i = i - 1 - time.sleep(10) - - if rq.status_code == 201: - url = ellis_url + "session" - rq = requests.post(url, data=params) - cookies = rq.cookies - - url = ellis_url + "accounts/" + params['email'] + "/numbers" - if cookies != "": - rq = requests.post(url, cookies=cookies) - i = 24 - while rq.status_code != 200 and i > 0: - rq = requests.post(url, cookies=cookies) - i = i - 1 - time.sleep(25) - - if rq.status_code != 200: - self.step_failure("Unable to create a number: %s" - % rq.json()['reason']) - - nameservers = ft_utils.get_resolvconf_ns() - resolvconf = "" - for ns in nameservers: - resolvconf += "\nnameserver " + ns - - if dns_ip != "": - script = ('echo -e "nameserver ' + dns_ip + resolvconf + - '" > /etc/resolv.conf; ') - script += 'source /etc/profile.d/rvm.sh; ' - script += 'cd {0}; ' - script += ('rake test[{1}] SIGNUP_CODE="secret"') - - cmd = ("/bin/bash -c '" + - script.format(self.data_dir, self.inputs["public_domain"]) + - "'") - output_file = "output.txt" - f = open(output_file, 'w+') - subprocess.call(cmd, shell=True, stdout=f, - stderr=subprocess.STDOUT) - f.close() - - f = open(output_file, 'r') - result = f.read() - if result != "": - self.logger.debug(result) - - vims_test_result = "" - tempFile = os.path.join(self.test_dir, "temp.json") - try: - self.logger.debug("Trying to load test results") - with open(tempFile) as f: - vims_test_result = json.load(f) - f.close() - except: - self.logger.error("Unable to retrieve test results") + def clean(self): + self.main_agent.get_agent( + "nsr", + project_id=self.ob_projectid).delete(self.ob_nsr_id) + time.sleep(5) + os_utils.delete_instance(nova_client=os_utils.get_nova_client(), + instance_id=self.ob_instance_id) + # TODO question is the clean removing also the VM? + # I think so since is goinf to remove the tenant... + super(ImsVnf, self).clean() - try: - os.remove(tempFile) - except: - self.logger.error("Deleting file failed") + def main(self, **kwargs): + self.logger.info("Orchestra IMS VNF onboarding test starting") + self.execute() + self.logger.info("Orchestra IMS VNF onboarding test executed") + if self.criteria is "PASS": + return self.EX_OK + else: + return self.EX_RUN_ERROR - if vims_test_result != '': - return {'status': 'PASS', 'result': vims_test_result} - else: - return {'status': 'FAIL', 'result': ''} + def run(self): + kwargs = {} + return self.main(**kwargs) - def clean(self): - # TODO - super(ImsVnf, self).clean() + +if __name__ == '__main__': + test = ImsVnf() + test.deploy_orchestrator() + test.deploy_vnf() + test.clean() + + +# ---------------------------------------------------------- +# +# UTILS +# +# ----------------------------------------------------------- +def get_config(parameter, file): + """ + Returns the value of a given parameter in file.yaml + parameter must be given in string format with dots + Example: general.openstack.image_name + """ + with open(file) as f: + file_yaml = yaml.safe_load(f) + f.close() + value = file_yaml + for element in parameter.split("."): + value = value.get(element) + if value is None: + raise ValueError("The parameter %s is not defined in" + " reporting.yaml" % parameter) + return value + + +def download_and_add_image_on_glance(glance, image_name, + image_url, data_dir): + dest_path = data_dir + if not os.path.exists(dest_path): + os.makedirs(dest_path) + file_name = image_url.rsplit('/')[-1] + if not ft_utils.download_url(image_url, dest_path): + return False + image = os_utils.create_glance_image( + glance, image_name, dest_path + file_name) + if not image: + return False + return image diff --git a/functest/opnfv_tests/vnf/ims/orchestra_ims.yaml b/functest/opnfv_tests/vnf/ims/orchestra_ims.yaml new file mode 100644 index 000000000..2fb33df5d --- /dev/null +++ b/functest/opnfv_tests/vnf/ims/orchestra_ims.yaml @@ -0,0 +1,7 @@ +tenant_images: + ubuntu_14.04: http://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img + openims: http://marketplace.openbaton.org:8082/api/v1/images/52e2ccc0-1dce-4663-894d-28aab49323aa/img +openbaton: + bootstrap: sh <(curl -s http://get.openbaton.org/bootstrap) release -configFile= + marketplace_link: http://marketplace.openbaton.org:8082/api/v1/nsds/fokus/OpenImsCore/3.2.0/json + imagename: ubuntu_14.04 diff --git a/functest/opnfv_tests/vnf/ims/orchestrator_cloudify.py b/functest/opnfv_tests/vnf/ims/orchestrator_cloudify.py index 775b71c8a..82a9dca05 100644 --- a/functest/opnfv_tests/vnf/ims/orchestrator_cloudify.py +++ b/functest/opnfv_tests/vnf/ims/orchestrator_cloudify.py @@ -21,7 +21,7 @@ from git import Repo import functest.utils.functest_logger as ft_logger -class Orchestrator: +class Orchestrator(object): def __init__(self, testcase_dir, inputs={}): self.testcase_dir = testcase_dir diff --git a/functest/utils/env.py b/functest/utils/env.py index fa5245fb6..7e4df2ea5 100644 --- a/functest/utils/env.py +++ b/functest/utils/env.py @@ -3,7 +3,7 @@ import re default_envs = { 'NODE_NAME': 'unknown_pod', - 'CI_DEBUG': 'true', + 'CI_DEBUG': 'false', 'DEPLOY_SCENARIO': 'os-nosdn-nofeature-noha', 'DEPLOY_TYPE': 'virt', 'INSTALLER_TYPE': None, diff --git a/functest/utils/functest_logger.py b/functest/utils/functest_logger.py index 0cba8c528..022211cb7 100755 --- a/functest/utils/functest_logger.py +++ b/functest/utils/functest_logger.py @@ -29,10 +29,12 @@ import json from functest.utils.constants import CONST -class Logger: +class Logger(object): + def __init__(self, logger_name): self.setup_logging() self.logger = logging.getLogger(logger_name) + logging.getLogger("paramiko").setLevel(logging.WARNING) def getLogger(self): return self.logger diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py index b2c36cff9..78831c113 100644 --- a/functest/utils/functest_utils.py +++ b/functest/utils/functest_utils.py @@ -291,6 +291,13 @@ def get_ci_envvars(): return ci_env_var +def execute_command_raise(cmd, info=False, error_msg="", + verbose=True, output_file=None): + ret = execute_command(cmd, info, error_msg, verbose, output_file) + if ret != 0: + raise Exception(error_msg) + + def execute_command(cmd, info=False, error_msg="", verbose=True, output_file=None): if not error_msg: diff --git a/functest/utils/openstack_tacker.py b/functest/utils/openstack_tacker.py index 07acc8b3a..8327fdbe2 100644 --- a/functest/utils/openstack_tacker.py +++ b/functest/utils/openstack_tacker.py @@ -176,6 +176,11 @@ def wait_for_vnf(tacker_client, vnf_id=None, vnf_name=None, timeout=60): elif vnf['status'] == 'PENDING_CREATE': time.sleep(3) timeout -= 3 + vnf = get_vnf(tacker_client, vnf_id, vnf_name) + + if (timeout < 0): + raise Exception('Timeout when booting vnf %s' % vnf['id']) + return vnf['id'] except Exception, e: logger.error("error [wait_for_vnf(tacker_client, '%s', '%s')]: %s" diff --git a/requirements.txt b/requirements.txt index b5e78bb59..68b889b35 100644 --- a/requirements.txt +++ b/requirements.txt @@ -28,4 +28,5 @@ subprocess32 shyaml dnspython Pillow==3.3.0 -click==6.6
\ No newline at end of file +click==6.6 +openbaton-cli==2.2.1-beta7 |