summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose Lausuch <jalausuch@suse.com>2017-11-15 17:11:41 +0100
committerJose Lausuch <jalausuch@suse.com>2017-11-22 19:48:38 +0100
commitd4996440fa16297aee7a925e6357a9cfd42d24f8 (patch)
treee2ef5c7c02eac83422848b7ce186171facf5547c
parent185dbcfb6ed774cc2f0478b05041d9e3a4e2f303 (diff)
Remove prepare_env
After moving the rally installation out of prepare_env It doesn't much sense to keep this script as it doesn't do useful things any more. Change-Id: I9ab3b2dd30c8ec0fbb825ee4302a83cce80f1cbe Signed-off-by: Jose Lausuch <jalausuch@suse.com>
-rw-r--r--docker/components/Dockerfile2
-rw-r--r--docker/features/Dockerfile2
-rw-r--r--docker/healthcheck/Dockerfile2
-rw-r--r--docker/parser/Dockerfile2
-rw-r--r--docker/smoke/Dockerfile2
-rw-r--r--docker/vnf/Dockerfile2
-rw-r--r--docs/testing/user/configguide/configguide.rst1
-rw-r--r--docs/testing/user/userguide/runfunctest.rst34
-rw-r--r--docs/testing/user/userguide/troubleshooting.rst2
-rw-r--r--functest/api/resources/v1/envs.py11
-rw-r--r--functest/api/resources/v1/testcases.py51
-rw-r--r--functest/api/swagger/envs_action.yaml18
-rw-r--r--functest/api/urls.py1
-rw-r--r--functest/ci/check_deployment.py2
-rw-r--r--functest/ci/prepare_env.py171
-rw-r--r--functest/ci/run_tests.py51
-rw-r--r--functest/cli/cli_base.py12
-rw-r--r--functest/cli/commands/cli_env.py37
-rw-r--r--functest/cli/commands/cli_testcase.py4
-rw-r--r--functest/cli/commands/cli_tier.py10
-rw-r--r--functest/tests/unit/ci/test_run_tests.py80
-rw-r--r--functest/tests/unit/cli/commands/test_cli_env.py44
-rw-r--r--functest/tests/unit/cli/commands/test_cli_testcase.py24
-rw-r--r--functest/tests/unit/cli/commands/test_cli_tier.py24
-rw-r--r--functest/tests/unit/cli/test_cli_base.py12
-rw-r--r--functest/utils/config.py4
-rw-r--r--setup.cfg1
27 files changed, 187 insertions, 419 deletions
diff --git a/docker/components/Dockerfile b/docker/components/Dockerfile
index a0f7a48eb..ce0d0c50a 100644
--- a/docker/components/Dockerfile
+++ b/docker/components/Dockerfile
@@ -30,4 +30,4 @@ RUN apk --no-cache add --virtual .build-deps --update \
mkdir -p /var/lib/rally/database && rally db create && \
apk del .build-deps
COPY testcases.yaml /usr/lib/python2.7/site-packages/functest/ci/testcases.yaml
-CMD ["bash","-c","prepare_env start && run_tests -t all"]
+CMD ["run_tests", "-t", "all"]
diff --git a/docker/features/Dockerfile b/docker/features/Dockerfile
index 1fb488297..eaf88f89c 100644
--- a/docker/features/Dockerfile
+++ b/docker/features/Dockerfile
@@ -22,4 +22,4 @@ RUN apk --no-cache add --update python3 sshpass && \
rm -r upper-constraints.txt thirdparty-requirements.txt /src/fds/.git && \
apk del .build-deps
COPY testcases.yaml /usr/lib/python2.7/site-packages/functest/ci/testcases.yaml
-CMD ["bash","-c","prepare_env start && run_tests -t all"]
+CMD ["run_tests", "-t", "all"]
diff --git a/docker/healthcheck/Dockerfile b/docker/healthcheck/Dockerfile
index 8923e4cd7..21b46ef97 100644
--- a/docker/healthcheck/Dockerfile
+++ b/docker/healthcheck/Dockerfile
@@ -1,4 +1,4 @@
FROM opnfv/functest-core
COPY testcases.yaml /usr/lib/python2.7/site-packages/functest/ci/testcases.yaml
-CMD ["bash","-c","prepare_env start && run_tests -t all"]
+CMD ["run_tests", "-t", "all"]
diff --git a/docker/parser/Dockerfile b/docker/parser/Dockerfile
index 043f214a9..bf43ac0ce 100644
--- a/docker/parser/Dockerfile
+++ b/docker/parser/Dockerfile
@@ -18,4 +18,4 @@ RUN apk --no-cache add --virtual .build-deps --update \
rm upper-constraints.txt thirdparty-requirements.txt && \
apk del .build-deps
COPY testcases.yaml /usr/lib/python2.7/site-packages/functest/ci/testcases.yaml
-CMD ["bash","-c","prepare_env start && run_tests -t all"]
+CMD ["run_tests", "-t", "all"]
diff --git a/docker/smoke/Dockerfile b/docker/smoke/Dockerfile
index 4485699c9..f8a42c491 100644
--- a/docker/smoke/Dockerfile
+++ b/docker/smoke/Dockerfile
@@ -39,4 +39,4 @@ RUN apk --no-cache add --virtual .build-deps --update \
mkdir -p /var/lib/rally/database && rally db create && \
apk del .build-deps
COPY testcases.yaml /usr/lib/python2.7/site-packages/functest/ci/testcases.yaml
-CMD ["bash","-c","prepare_env start && run_tests -t all"]
+CMD ["run_tests", "-t", "all"]
diff --git a/docker/vnf/Dockerfile b/docker/vnf/Dockerfile
index 36e80d7e2..ac3b8dab0 100644
--- a/docker/vnf/Dockerfile
+++ b/docker/vnf/Dockerfile
@@ -12,4 +12,4 @@ RUN apk --no-cache add --update \
cd /src/vims-test && bundle config build.nokogiri --use-system-libraries && bundle install --system && \
apk del .build-deps
COPY testcases.yaml /usr/lib/python2.7/site-packages/functest/ci/testcases.yaml
-CMD ["bash","-c","prepare_env start && run_tests -t all"]
+CMD ["run_tests", "-t", "all"]
diff --git a/docs/testing/user/configguide/configguide.rst b/docs/testing/user/configguide/configguide.rst
index 7da7285ed..f455d18c2 100644
--- a/docs/testing/user/configguide/configguide.rst
+++ b/docs/testing/user/configguide/configguide.rst
@@ -408,7 +408,6 @@ The structure of functest repo can be described as follows::
│   |-- config_patch.yaml
│   |-- download_images.sh
│   |-- logging.ini
- │   |-- prepare_env.py
│   |-- rally_aarch64_patch.conf
│   |-- run_tests.py
│   |-- testcases.yaml
diff --git a/docs/testing/user/userguide/runfunctest.rst b/docs/testing/user/userguide/runfunctest.rst
index db85c18ff..89580e564 100644
--- a/docs/testing/user/userguide/runfunctest.rst
+++ b/docs/testing/user/userguide/runfunctest.rst
@@ -53,40 +53,6 @@ commands::
$ source /home/opnfv/functest/conf/openstack.creds
-Prepare environment
--------------------
-Prior to commencing the Functest environment preparation, we can check
-the initial status of the environment. Issue the **functest env status**
-command at the prompt::
-
- # functest env status
- # Functest environment is not installed.
-
-To prepare the Functest docker container for test case execution, type::
-
- # functest env prepare
- # ...
- # Functest environment ready to run tests.
-
-you may also type prepare_env instead of functest env prepare.
-
-To list some basic information about an already prepared Functest
-docker container environment, issue the **functest env show** at the
-prompt::
- bash-4.3# functest env show
- +------------------------------+---------------------------------+
- | FUNCTEST ENVIRONMENT | VALUE |
- +------------------------------+---------------------------------+
- | STATUS | ready |
- | SCENARIO | os-nosdn-nofeature-noha |
- | DEBUG FLAG | false |
- | BUILD_TAG | None |
- | INSTALLER | compass |
- | POD | huawei-pod1 |
- +------------------------------+---------------------------------+
-
-See configuration guide for details on Functest environnement variables.
-
Tier
----
Each Alpine container provided on the docker hub matches with a tier.
diff --git a/docs/testing/user/userguide/troubleshooting.rst b/docs/testing/user/userguide/troubleshooting.rst
index 20879bf6e..62587de34 100644
--- a/docs/testing/user/userguide/troubleshooting.rst
+++ b/docs/testing/user/userguide/troubleshooting.rst
@@ -284,7 +284,7 @@ This is an example of running a customized list of Tempest tests in Functest::
-v $(pwd)/images:/home/opnfv/functest/images \
-v $(pwd)/my-custom-testcases.yaml:/usr/lib/python2.7/site-packages/functest/ci/testcases.yaml \
-v $(pwd)/my-custom-tempest-tests.txt:/usr/lib/python2.7/site-packages/functest/opnfv_tests/openstack/tempest/custom_tests/test_list.txt \
- opnfv/functest-components /bin/bash -c "prepare_env start && run_tests -t tempest_custom"
+ opnfv/functest-components run_tests -t tempest_custom
Rally
diff --git a/functest/api/resources/v1/envs.py b/functest/api/resources/v1/envs.py
index 65e61c4ba..3e6f05ac9 100644
--- a/functest/api/resources/v1/envs.py
+++ b/functest/api/resources/v1/envs.py
@@ -20,7 +20,6 @@ from flasgger.utils import swag_from
from functest.api.base import ApiResource
from functest.api.common import api_utils
from functest.cli.commands.cli_env import Env
-import functest.utils.functest_utils as ft_utils
ADDRESS = socket.gethostbyname(socket.gethostname())
ENDPOINT_ENVS = ('http://{}:5000/api/v1/functest/envs'.format(ADDRESS))
@@ -45,16 +44,6 @@ class V1Envs(ApiResource):
""" Used to handle post request """
return self._dispatch_post()
- def prepare(self, args): # pylint: disable=no-self-use, unused-argument
- """ Prepare environment """
-
- result_env = ft_utils.execute_command("prepare_env start")
- if not result_env == 0:
- return api_utils.result_handler(
- status=1, data="Failed to prepare env")
- return api_utils.result_handler(
- status=0, data="Prepare env successfully")
-
def update_hosts(self, hosts_info): # pylint: disable=no-self-use
""" Update hosts info """
diff --git a/functest/api/resources/v1/testcases.py b/functest/api/resources/v1/testcases.py
index 7cc70bbc9..01571548d 100644
--- a/functest/api/resources/v1/testcases.py
+++ b/functest/api/resources/v1/testcases.py
@@ -115,34 +115,31 @@ class V1Testcase(ApiResource):
case_name = args.get('testcase')
self._update_logging_ini(args.get('task_id'))
- if not os.path.isfile(CONST.__getattribute__('env_active')):
- raise Exception("Functest environment is not ready.")
+ try:
+ cmd = "run_tests -t {}".format(case_name)
+ runner = ft_utils.execute_command(cmd)
+ except Exception: # pylint: disable=broad-except
+ result = 'FAIL'
+ LOGGER.exception("Running test case %s failed!", case_name)
+ if runner == os.EX_OK:
+ result = 'PASS'
else:
- try:
- cmd = "run_tests -t {}".format(case_name)
- runner = ft_utils.execute_command(cmd)
- except Exception: # pylint: disable=broad-except
- result = 'FAIL'
- LOGGER.exception("Running test case %s failed!", case_name)
- if runner == os.EX_OK:
- result = 'PASS'
- else:
- result = 'FAIL'
-
- env_info = {
- 'installer': CONST.__getattribute__('INSTALLER_TYPE'),
- 'scenario': CONST.__getattribute__('DEPLOY_SCENARIO'),
- 'build_tag': CONST.__getattribute__('BUILD_TAG'),
- 'ci_loop': CONST.__getattribute__('CI_LOOP')
- }
- result = {
- 'task_id': args.get('task_id'),
- 'testcase': case_name,
- 'env_info': env_info,
- 'result': result
- }
-
- return {'result': result}
+ result = 'FAIL'
+
+ env_info = {
+ 'installer': CONST.__getattribute__('INSTALLER_TYPE'),
+ 'scenario': CONST.__getattribute__('DEPLOY_SCENARIO'),
+ 'build_tag': CONST.__getattribute__('BUILD_TAG'),
+ 'ci_loop': CONST.__getattribute__('CI_LOOP')
+ }
+ result = {
+ 'task_id': args.get('task_id'),
+ 'testcase': case_name,
+ 'env_info': env_info,
+ 'result': result
+ }
+
+ return {'result': result}
def _update_logging_ini(self, task_id): # pylint: disable=no-self-use
""" Update the log file for each task"""
diff --git a/functest/api/swagger/envs_action.yaml b/functest/api/swagger/envs_action.yaml
index 1add066ee..46faa6dea 100644
--- a/functest/api/swagger/envs_action.yaml
+++ b/functest/api/swagger/envs_action.yaml
@@ -1,8 +1,7 @@
-Prepare environment or Update hosts info
+Update hosts info
-This api offers the interface to prepare environment or update hosts info.
+This api offers the interface to update hosts info.
-action: prepare
action: update_hosts
---
tags:
@@ -14,11 +13,18 @@ parameters:
schema:
required:
- action
+ - args
properties:
action:
type: string
description: this is action for envs
- default: prepare
+ default: update_hosts
+ args:
+ type: string
+ description: Hosts info to be updated
+ default:
+ "identity.ac.dz.com": "8.20.11.22"
+ "image.ac.dz.com": "8.20.11.22"
definitions:
Environment:
type: object
@@ -29,9 +35,9 @@ definitions:
type: dict
responses:
200:
- description: Prepare environment
+ description: Update hosts info
schema:
$ref: '#/definitions/Environment'
examples:
'status': 0
- 'result': 'Prapare env successfully'
+ 'result': 'Update hosts info successfully' \ No newline at end of file
diff --git a/functest/api/urls.py b/functest/api/urls.py
index 0cc22f80f..10b7b2936 100644
--- a/functest/api/urls.py
+++ b/functest/api/urls.py
@@ -26,7 +26,6 @@ URLPATTERNS = [
Url('/api/v1/functest/envs', 'v1_envs'),
# POST /api/v1/functest/envs/action
- # {"action":"prepare"} => Prepare environment
# {"action":"update_hosts", "args": {}} => Update hosts info
Url('/api/v1/functest/envs/action', 'v1_envs'),
diff --git a/functest/ci/check_deployment.py b/functest/ci/check_deployment.py
index db94fd746..ae016a800 100644
--- a/functest/ci/check_deployment.py
+++ b/functest/ci/check_deployment.py
@@ -139,7 +139,7 @@ class CheckDeployment(object):
def check_all(self):
"""
Calls all the class functions and returns 0 if all of them succeed.
- This is the method called by prepare_env or CLI
+ This is the method called by CLI
"""
self.check_rc()
try:
diff --git a/functest/ci/prepare_env.py b/functest/ci/prepare_env.py
deleted file mode 100644
index 2cb705cae..000000000
--- a/functest/ci/prepare_env.py
+++ /dev/null
@@ -1,171 +0,0 @@
-#!/usr/bin/env python
-#
-# 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 logging
-import logging.config
-import os
-import pkg_resources
-import re
-import sys
-
-import yaml
-
-from functest.ci import check_deployment
-import functest.utils.functest_utils as ft_utils
-import functest.utils.openstack_utils as os_utils
-from functest.utils.constants import CONST
-
-actions = ['start', 'check']
-
-""" logging configuration """
-logger = logging.getLogger('functest.ci.prepare_env')
-handler = None
-# set the architecture to default
-pod_arch = os.getenv("POD_ARCH", None)
-arch_filter = ['aarch64']
-
-CONFIG_FUNCTEST_PATH = pkg_resources.resource_filename(
- 'functest', 'ci/config_functest.yaml')
-CONFIG_PATCH_PATH = pkg_resources.resource_filename(
- 'functest', 'ci/config_patch.yaml')
-CONFIG_AARCH64_PATCH_PATH = pkg_resources.resource_filename(
- 'functest', 'ci/config_aarch64_patch.yaml')
-
-
-class PrepareEnvParser(object):
-
- def __init__(self):
- self.parser = argparse.ArgumentParser()
- self.parser.add_argument("action", help="Possible actions are: "
- "'{d[0]}|{d[1]}' ".format(d=actions),
- choices=actions)
- self.parser.add_argument("-d", "--debug", help="Debug mode",
- action="store_true")
-
- def parse_args(self, argv=[]):
- return vars(self.parser.parse_args(argv))
-
-
-def print_separator():
- logger.info("==============================================")
-
-
-def source_rc_file():
- print_separator()
-
- logger.info("Sourcing the OpenStack RC file...")
- os_utils.source_credentials(CONST.__getattribute__('openstack_creds'))
- for key, value in os.environ.iteritems():
- if re.search("OS_", key):
- if key == 'OS_AUTH_URL':
- CONST.__setattr__('OS_AUTH_URL', value)
- elif key == 'OS_USERNAME':
- CONST.__setattr__('OS_USERNAME', value)
- elif key == 'OS_TENANT_NAME':
- CONST.__setattr__('OS_TENANT_NAME', value)
- elif key == 'OS_PASSWORD':
- CONST.__setattr__('OS_PASSWORD', value)
-
-
-def update_config_file():
- patch_file(CONFIG_PATCH_PATH)
-
- if pod_arch and pod_arch in arch_filter:
- patch_file(CONFIG_AARCH64_PATCH_PATH)
-
- if "TEST_DB_URL" in os.environ:
- update_db_url()
-
-
-def patch_file(patch_file_path):
- logger.debug('Updating file: %s', patch_file_path)
- with open(patch_file_path) as f:
- patch_file = yaml.safe_load(f)
-
- updated = False
- for key in patch_file:
- if key in CONST.__getattribute__('DEPLOY_SCENARIO'):
- new_functest_yaml = dict(ft_utils.merge_dicts(
- ft_utils.get_functest_yaml(), patch_file[key]))
- updated = True
-
- if updated:
- os.remove(CONFIG_FUNCTEST_PATH)
- with open(CONFIG_FUNCTEST_PATH, "w") as f:
- f.write(yaml.dump(new_functest_yaml, default_style='"'))
-
-
-def update_db_url():
- with open(CONFIG_FUNCTEST_PATH) as f:
- functest_yaml = yaml.safe_load(f)
-
- with open(CONFIG_FUNCTEST_PATH, "w") as f:
- functest_yaml["results"]["test_db_url"] = os.environ.get('TEST_DB_URL')
- f.write(yaml.dump(functest_yaml, default_style='"'))
-
-
-def verify_deployment():
- print_separator()
- logger.info("Verifying OpenStack deployment...")
- deployment = check_deployment.CheckDeployment()
- deployment.check_all()
-
-
-def create_flavor():
- _, 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():
- msg_not_active = "The Functest environment is not installed."
- if not os.path.isfile(CONST.__getattribute__('env_active')):
- raise Exception(msg_not_active)
-
- with open(CONST.__getattribute__('env_active'), "r") as env_file:
- s = env_file.read()
- if not re.search("1", s):
- raise Exception(msg_not_active)
-
- logger.info("Functest environment is installed.")
-
-
-def prepare_env(**kwargs):
- try:
- if not (kwargs['action'] in actions):
- logger.error('Argument not valid.')
- return -1
- elif kwargs['action'] == "start":
- logger.info("######### Preparing Functest environment #########\n")
- verify_deployment()
- source_rc_file()
- update_config_file()
- create_flavor()
- with open(CONST.__getattribute__('env_active'), "w") as env_file:
- env_file.write("1")
- check_environment()
- elif kwargs['action'] == "check":
- check_environment()
- except Exception as e:
- logger.error(e)
- return -1
- return 0
-
-
-def main():
- logging.config.fileConfig(pkg_resources.resource_filename(
- 'functest', 'ci/logging.ini'))
- logging.captureWarnings(True)
- parser = PrepareEnvParser()
- args = parser.parse_args(sys.argv[1:])
- return prepare_env(**args)
diff --git a/functest/ci/run_tests.py b/functest/ci/run_tests.py
index d4acd9c56..03d62d992 100644
--- a/functest/ci/run_tests.py
+++ b/functest/ci/run_tests.py
@@ -19,6 +19,7 @@ import sys
import textwrap
import prettytable
+import yaml
import functest.ci.tier_builder as tb
import functest.core.testcase as testcase
@@ -29,6 +30,16 @@ from functest.utils.constants import CONST
# __name__ cannot be used here
logger = logging.getLogger('functest.ci.run_tests')
+CONFIG_FUNCTEST_PATH = pkg_resources.resource_filename(
+ 'functest', 'ci/config_functest.yaml')
+CONFIG_PATCH_PATH = pkg_resources.resource_filename(
+ 'functest', 'ci/config_patch.yaml')
+CONFIG_AARCH64_PATCH_PATH = pkg_resources.resource_filename(
+ 'functest', 'ci/config_aarch64_patch.yaml')
+# set the architecture to default
+pod_arch = os.getenv("POD_ARCH", None)
+arch_filter = ['aarch64']
+
class Result(enum.Enum):
EX_OK = os.EX_OK
@@ -76,6 +87,44 @@ class Runner(object):
pkg_resources.resource_filename('functest', 'ci/testcases.yaml'))
@staticmethod
+ def update_config_file():
+ Runner.patch_file(CONFIG_PATCH_PATH)
+
+ if pod_arch and pod_arch in arch_filter:
+ Runner.patch_file(CONFIG_AARCH64_PATCH_PATH)
+
+ if "TEST_DB_URL" in os.environ:
+ Runner.update_db_url()
+
+ @staticmethod
+ def patch_file(patch_file_path):
+ logger.debug('Updating file: %s', patch_file_path)
+ with open(patch_file_path) as f:
+ patch_file = yaml.safe_load(f)
+
+ updated = False
+ for key in patch_file:
+ if key in CONST.__getattribute__('DEPLOY_SCENARIO'):
+ new_functest_yaml = dict(ft_utils.merge_dicts(
+ ft_utils.get_functest_yaml(), patch_file[key]))
+ updated = True
+
+ if updated:
+ os.remove(CONFIG_FUNCTEST_PATH)
+ with open(CONFIG_FUNCTEST_PATH, "w") as f:
+ f.write(yaml.dump(new_functest_yaml, default_style='"'))
+
+ @staticmethod
+ def update_db_url():
+ with open(CONFIG_FUNCTEST_PATH) as f:
+ functest_yaml = yaml.safe_load(f)
+
+ with open(CONFIG_FUNCTEST_PATH, "w") as f:
+ functest_yaml["results"]["test_db_url"] = os.environ.get(
+ 'TEST_DB_URL')
+ f.write(yaml.dump(functest_yaml, default_style='"'))
+
+ @staticmethod
def source_rc_file():
rc_file = CONST.__getattribute__('openstack_creds')
if not os.path.isfile(rc_file):
@@ -192,6 +241,8 @@ class Runner(object):
self.run_tier(tier)
def main(self, **kwargs):
+ Runner.update_config_file()
+
if 'noclean' in kwargs:
self.clean_flag = not kwargs['noclean']
if 'report' in kwargs:
diff --git a/functest/cli/cli_base.py b/functest/cli/cli_base.py
index 507179b17..aa8ab24bc 100644
--- a/functest/cli/cli_base.py
+++ b/functest/cli/cli_base.py
@@ -87,23 +87,11 @@ def os_show_credentials():
_openstack.show_credentials()
-@env.command('prepare', help="Prepares the Functest environment. This step is "
- "needed run the tests.")
-def env_prepare():
- _env.prepare()
-
-
@env.command('show', help="Shows information about the current environment.")
def env_show():
_env.show()
-@env.command('status', help="Checks if the Functest environment is ready to "
- "run the tests.")
-def env_status():
- _env.status()
-
-
@testcase.command('list', help="Lists the available testcases.")
def testcase_list():
_testcase.list()
diff --git a/functest/cli/commands/cli_env.py b/functest/cli/commands/cli_env.py
index 72a870b59..0e0afe529 100644
--- a/functest/cli/commands/cli_env.py
+++ b/functest/cli/commands/cli_env.py
@@ -7,13 +7,10 @@
# http://www.apache.org/licenses/LICENSE-2.0
#
-import os
-
import click
import prettytable
from functest.utils.constants import CONST
-import functest.utils.functest_utils as ft_utils
class Env(object):
@@ -21,22 +18,6 @@ class Env(object):
def __init__(self):
pass
- def prepare(self):
- if self.status(verbose=False) == 0:
- answer = raw_input("It seems that the environment has been "
- "already prepared. Do you want to do "
- "it again? [y|n]\n")
- while True:
- if answer.lower() in ["y", "yes"]:
- os.remove(CONST.__getattribute__('env_active'))
- break
- elif answer.lower() in ["n", "no"]:
- return
- else:
- answer = raw_input("Invalid answer. Please type [y|n]\n")
-
- ft_utils.execute_command("prepare_env start")
-
def show(self):
def _get_value(attr, default='Unknown'):
return attr if attr else default
@@ -52,30 +33,14 @@ class Env(object):
build_tag = build_tag.lstrip(
"jenkins-").lstrip("functest").lstrip("-")
- STATUS = "not ready"
- if self.status(verbose=False) == 0:
- STATUS = "ready"
-
env_info = {'INSTALLER': installer_info,
'SCENARIO': scenario,
'POD': node,
'DEBUG FLAG': is_debug,
- 'BUILD_TAG': build_tag,
- 'STATUS': STATUS}
+ 'BUILD_TAG': build_tag}
return env_info
- def status(self, verbose=True):
- ret_val = 0
- if not os.path.isfile(CONST.__getattribute__('env_active')):
- if verbose:
- click.echo("Functest environment is not installed.\n")
- ret_val = 1
- elif verbose:
- click.echo("Functest environment ready to run tests.\n")
-
- return ret_val
-
class CliEnv(Env):
diff --git a/functest/cli/commands/cli_testcase.py b/functest/cli/commands/cli_testcase.py
index 65dd9ab75..ee7afa5a8 100644
--- a/functest/cli/commands/cli_testcase.py
+++ b/functest/cli/commands/cli_testcase.py
@@ -9,7 +9,6 @@
""" global variables """
-import os
import pkg_resources
import click
@@ -50,9 +49,6 @@ class Testcase(object):
if testname == 'vacation':
vacation.main()
- elif not os.path.isfile(CONST.__getattribute__('env_active')):
- click.echo("Functest environment is not ready. "
- "Run first 'functest env prepare'")
else:
tests = testname.split(",")
for test in tests:
diff --git a/functest/cli/commands/cli_tier.py b/functest/cli/commands/cli_tier.py
index 995354bbd..104cf10b5 100644
--- a/functest/cli/commands/cli_tier.py
+++ b/functest/cli/commands/cli_tier.py
@@ -9,7 +9,6 @@
""" global variables """
-import os
import pkg_resources
import click
@@ -54,19 +53,14 @@ class Tier(object):
@staticmethod
def run(tiername, noclean=False, report=False):
-
flags = ""
if noclean:
flags += "-n "
if report:
flags += "-r "
- if not os.path.isfile(CONST.__getattribute__('env_active')):
- click.echo("Functest environment is not ready. "
- "Run first 'functest env prepare'")
- else:
- cmd = "run_tests {}-t {}".format(flags, tiername)
- ft_utils.execute_command(cmd)
+ cmd = "run_tests {}-t {}".format(flags, tiername)
+ ft_utils.execute_command(cmd)
class CliTier(Tier):
diff --git a/functest/tests/unit/ci/test_run_tests.py b/functest/tests/unit/ci/test_run_tests.py
index bc95f8f3d..fc689452d 100644
--- a/functest/tests/unit/ci/test_run_tests.py
+++ b/functest/tests/unit/ci/test_run_tests.py
@@ -7,6 +7,7 @@
import logging
import unittest
+import os
import mock
@@ -58,6 +59,85 @@ class RunTestsTesting(unittest.TestCase):
self.run_tests_parser = run_tests.RunTestsParser()
+ self.config_file_yaml = {'general': {
+ 'openstack': {
+ 'image_name': 'test_image_name'}},
+ 'results': {
+ 'test_db_url': 'url1'}}
+ self.config_file_patch_yaml = {'fdio': {'general': {
+ 'openstack': {
+ 'image_name':
+ 'test_image_name_2'}}}}
+ self.config_file_aarcg64_patch_yaml = {'os': {'general': {
+ 'openstack': {'image_name': 'test_image_name_3'}}}}
+
+ @mock.patch('functest.ci.run_tests.Runner.patch_file')
+ @mock.patch('functest.ci.run_tests.Runner.update_db_url')
+ def test_update_config_file_default(self, *mock_methods):
+ self.runner.update_config_file()
+ mock_methods[1].assert_called()
+ mock_methods[0].assert_not_called()
+
+ @mock.patch('functest.ci.run_tests.Runner.patch_file')
+ @mock.patch('functest.ci.run_tests.Runner.update_db_url')
+ @mock.patch.dict(os.environ, {'TEST_DB_URL': 'somevalue'})
+ def test_update_config_file_update_db(self, *mock_methods):
+ self.runner.update_config_file()
+ mock_methods[1].assert_called()
+ mock_methods[0].assert_called()
+
+ def test_patch_file_missing_file(self):
+ patch_file_path = "unexisting_file"
+ with self.assertRaises(IOError):
+ self.runner.patch_file(patch_file_path)
+
+ @mock.patch('functest.ci.run_tests.ft_utils.merge_dicts')
+ @mock.patch('functest.ci.run_tests.ft_utils.get_functest_yaml')
+ def test_patch_file_default(self, *mock_methods):
+ CONST.__setattr__('DEPLOY_SCENARIO', 'os-nosdn-nofeature-noha')
+ with mock.patch(
+ 'six.moves.builtins.open', mock.mock_open()), mock.patch(
+ 'functest.ci.run_tests.yaml.safe_load') as yaml1, mock.patch(
+ 'functest.ci.run_tests.ft_utils.get_functest_yaml') as yaml2:
+ yaml1.return_value = self.config_file_patch_yaml
+ yaml2.return_value = self.config_file_yaml
+ self.runner.patch_file(yaml1)
+ mock_methods[1].assert_not_called()
+ mock_methods[0].assert_not_called()
+
+ @mock.patch('functest.ci.run_tests.ft_utils.merge_dicts')
+ @mock.patch('functest.ci.run_tests.os.remove')
+ def test_patch_file_match_scenario(self, *mock_methods):
+ CONST.__setattr__('DEPLOY_SCENARIO', 'os-nosdn-fdio-noha')
+ with mock.patch(
+ 'six.moves.builtins.open', mock.mock_open()), mock.patch(
+ 'functest.ci.run_tests.yaml.safe_load') as yaml1, mock.patch(
+ 'functest.ci.run_tests.ft_utils.get_functest_yaml') as yaml2:
+ yaml1.return_value = self.config_file_patch_yaml
+ yaml2.return_value = self.config_file_yaml
+ self.runner.patch_file(yaml2)
+ mock_methods[1].assert_called()
+ mock_methods[0].assert_called()
+
+ def test_update_db_url_missing_file(self):
+ run_tests.CONFIG_FUNCTEST_PATH = "unexisting_file"
+ with self.assertRaises(IOError):
+ self.runner.update_db_url()
+
+ @mock.patch('functest.ci.run_tests.yaml.safe_load')
+ @mock.patch('functest.ci.run_tests.ft_utils.get_functest_yaml')
+ @mock.patch.dict(os.environ, {'TEST_DB_URL': 'url2'})
+ def test_update_db_url_default(self, *mock_methods):
+ with mock.patch(
+ 'six.moves.builtins.open', mock.mock_open()), mock.patch(
+ 'functest.ci.run_tests.yaml.safe_load') as yaml1:
+ yaml1.return_value = self.config_file_yaml
+ self.runner.update_db_url()
+ self.assertEqual(
+ yaml1.return_value['results']['test_db_url'], 'url2')
+ mock_methods[0].assert_not_called()
+ mock_methods[1].assert_not_called()
+
@mock.patch('functest.ci.run_tests.logger.error')
def test_source_rc_file_missing_file(self, mock_logger_error):
with mock.patch('functest.ci.run_tests.os.path.isfile',
diff --git a/functest/tests/unit/cli/commands/test_cli_env.py b/functest/tests/unit/cli/commands/test_cli_env.py
index ddd5d86c5..d865d3803 100644
--- a/functest/tests/unit/cli/commands/test_cli_env.py
+++ b/functest/tests/unit/cli/commands/test_cli_env.py
@@ -20,27 +20,6 @@ class CliEnvTesting(unittest.TestCase):
def setUp(self):
self.cli_environ = cli_env.CliEnv()
- @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
- return_value=False)
- @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
- def test_prepare_default(self, mock_ft_utils, mock_os):
- cmd = "prepare_env start"
- self.cli_environ.prepare()
- mock_ft_utils.assert_called_with(cmd)
-
- @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
- return_value=True)
- @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
- def test_prepare_missing_status(self, mock_ft_utils, mock_os):
- with mock.patch('__builtin__.raw_input', return_value="y"), \
- mock.patch('functest.cli.commands.cli_testcase.os.remove') \
- as mock_os_remove:
- cmd = "prepare_env start"
- self.cli_environ.prepare()
- mock_os_remove.assert_called_once_with(
- CONST.__getattribute__('env_active'))
- mock_ft_utils.assert_called_with(cmd)
-
def _test_show_missing_env_var(self, var, *args):
if var == 'INSTALLER_TYPE':
CONST.__setattr__('INSTALLER_TYPE', None)
@@ -60,8 +39,6 @@ class CliEnvTesting(unittest.TestCase):
elif var == 'DEBUG':
CONST.__setattr__('CI_DEBUG', None)
reg_string = "| DEBUG FLAG: false\s*|"
- elif var == 'STATUS':
- reg_string = "| STATUS: not ready\s*|"
with mock.patch('functest.cli.commands.cli_env.click.echo') \
as mock_click_echo:
@@ -87,27 +64,6 @@ class CliEnvTesting(unittest.TestCase):
def test_show_missing_ci_debug(self, *args):
self._test_show_missing_env_var('DEBUG', *args)
- @mock.patch('functest.cli.commands.cli_env.os.path.isfile',
- return_value=False)
- def test_show_missing_environment(self, *args):
- self._test_show_missing_env_var('STATUS', *args)
-
- @mock.patch('functest.cli.commands.cli_env.click.echo')
- @mock.patch('functest.cli.commands.cli_env.os.path.isfile',
- return_value=True)
- def test_status_environment_present(self, mock_path, mock_click_echo):
- self.assertEqual(self.cli_environ.status(), 0)
- mock_click_echo.assert_called_with("Functest environment"
- " ready to run tests.\n")
-
- @mock.patch('functest.cli.commands.cli_env.click.echo')
- @mock.patch('functest.cli.commands.cli_env.os.path.isfile',
- return_value=False)
- def test_status_environment_absent(self, mock_path, mock_click_echo):
- self.assertEqual(self.cli_environ.status(), 1)
- mock_click_echo.assert_called_with("Functest environment"
- " is not installed.\n")
-
if __name__ == "__main__":
logging.disable(logging.CRITICAL)
diff --git a/functest/tests/unit/cli/commands/test_cli_testcase.py b/functest/tests/unit/cli/commands/test_cli_testcase.py
index 9ccf4c4ac..f3648eb05 100644
--- a/functest/tests/unit/cli/commands/test_cli_testcase.py
+++ b/functest/tests/unit/cli/commands/test_cli_testcase.py
@@ -26,42 +26,26 @@ class CliTestCasesTesting(unittest.TestCase):
self.cli_tests.run('vacation')
self.assertTrue(mock_method.called)
- @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
- return_value=False)
- @mock.patch('functest.cli.commands.cli_testcase.click.echo')
- def test_run_missing_env_file(self, mock_click_echo, mock_os):
- self.cli_tests.run(self.testname)
- mock_click_echo.assert_called_with("Functest environment is not ready."
- " Run first 'functest env prepare'")
-
- @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
- return_value=True)
@mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
- def test_run_default(self, mock_ft_utils, mock_os):
+ def test_run_default(self, mock_ft_utils):
cmd = "run_tests -n -r -t {}".format(self.testname)
self.cli_tests.run(self.testname, noclean=True, report=True)
mock_ft_utils.assert_called_with(cmd)
- @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
- return_value=True)
@mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
- def test_run_noclean_missing_report(self, mock_ft_utils, mock_os):
+ def test_run_noclean_missing_report(self, mock_ft_utils):
cmd = "run_tests -n -t {}".format(self.testname)
self.cli_tests.run(self.testname, noclean=True, report=False)
mock_ft_utils.assert_called_with(cmd)
- @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
- return_value=True)
@mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
- def test_run_report_missing_noclean(self, mock_ft_utils, mock_os):
+ def test_run_report_missing_noclean(self, mock_ft_utils):
cmd = "run_tests -r -t {}".format(self.testname)
self.cli_tests.run(self.testname, noclean=False, report=True)
mock_ft_utils.assert_called_with(cmd)
- @mock.patch('functest.cli.commands.cli_testcase.os.path.isfile',
- return_value=True)
@mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command')
- def test_run_missing_noclean_report(self, mock_ft_utils, mock_os):
+ def test_run_missing_noclean_report(self, mock_ft_utils):
cmd = "run_tests -t {}".format(self.testname)
self.cli_tests.run(self.testname, noclean=False, report=False)
mock_ft_utils.assert_called_with(cmd)
diff --git a/functest/tests/unit/cli/commands/test_cli_tier.py b/functest/tests/unit/cli/commands/test_cli_tier.py
index 1bb630db4..a76d12049 100644
--- a/functest/tests/unit/cli/commands/test_cli_tier.py
+++ b/functest/tests/unit/cli/commands/test_cli_tier.py
@@ -74,42 +74,26 @@ class CliTierTesting(unittest.TestCase):
":\n %s\n" % (self.tiername,
'tiernames'))
- @mock.patch('functest.cli.commands.cli_tier.os.path.isfile',
- return_value=False)
- @mock.patch('functest.cli.commands.cli_tier.click.echo')
- def test_run_missing_env_file(self, mock_click_echo, mock_os):
- self.cli_tier.run(self.tiername)
- mock_click_echo.assert_called_with("Functest environment is not ready."
- " Run first 'functest env prepare'")
-
- @mock.patch('functest.cli.commands.cli_tier.os.path.isfile',
- return_value=True)
@mock.patch('functest.cli.commands.cli_tier.ft_utils.execute_command')
- def test_run_default(self, mock_ft_utils, mock_os):
+ def test_run_default(self, mock_ft_utils):
cmd = "run_tests -n -r -t {}".format(self.tiername)
self.cli_tier.run(self.tiername, noclean=True, report=True)
mock_ft_utils.assert_called_with(cmd)
- @mock.patch('functest.cli.commands.cli_tier.os.path.isfile',
- return_value=True)
@mock.patch('functest.cli.commands.cli_tier.ft_utils.execute_command')
- def test_run_report_missing_noclean(self, mock_ft_utils, mock_os):
+ def test_run_report_missing_noclean(self, mock_ft_utils):
cmd = "run_tests -r -t {}".format(self.tiername)
self.cli_tier.run(self.tiername, noclean=False, report=True)
mock_ft_utils.assert_called_with(cmd)
- @mock.patch('functest.cli.commands.cli_tier.os.path.isfile',
- return_value=True)
@mock.patch('functest.cli.commands.cli_tier.ft_utils.execute_command')
- def test_run_noclean_missing_report(self, mock_ft_utils, mock_os):
+ def test_run_noclean_missing_report(self, mock_ft_utils):
cmd = "run_tests -n -t {}".format(self.tiername)
self.cli_tier.run(self.tiername, noclean=True, report=False)
mock_ft_utils.assert_called_with(cmd)
- @mock.patch('functest.cli.commands.cli_tier.os.path.isfile',
- return_value=True)
@mock.patch('functest.cli.commands.cli_tier.ft_utils.execute_command')
- def test_run_missing_noclean_report(self, mock_ft_utils, mock_os):
+ def test_run_missing_noclean_report(self, mock_ft_utils):
cmd = "run_tests -t {}".format(self.tiername)
self.cli_tier.run(self.tiername, noclean=False, report=False)
mock_ft_utils.assert_called_with(cmd)
diff --git a/functest/tests/unit/cli/test_cli_base.py b/functest/tests/unit/cli/test_cli_base.py
index 61bd093e6..08c9b736a 100644
--- a/functest/tests/unit/cli/test_cli_base.py
+++ b/functest/tests/unit/cli/test_cli_base.py
@@ -62,24 +62,12 @@ class CliBaseTesting(unittest.TestCase):
self.assertEqual(result.exit_code, 0)
self.assertTrue(mock_method.called)
- def test_env_prepare(self):
- with mock.patch.object(self._env, 'prepare') as mock_method:
- result = self.runner.invoke(cli_base.env_prepare)
- self.assertEqual(result.exit_code, 0)
- self.assertTrue(mock_method.called)
-
def test_env_show(self):
with mock.patch.object(self._env, 'show') as mock_method:
result = self.runner.invoke(cli_base.env_show)
self.assertEqual(result.exit_code, 0)
self.assertTrue(mock_method.called)
- def test_env_status(self):
- with mock.patch.object(self._env, 'status') as mock_method:
- result = self.runner.invoke(cli_base.env_status)
- self.assertEqual(result.exit_code, 0)
- self.assertTrue(mock_method.called)
-
def test_testcase_list(self):
with mock.patch.object(self._testcase, 'list') as mock_method:
result = self.runner.invoke(cli_base.testcase_list)
diff --git a/functest/utils/config.py b/functest/utils/config.py
index d91f63ac2..6b5021a2c 100644
--- a/functest/utils/config.py
+++ b/functest/utils/config.py
@@ -1,6 +1,5 @@
#!/usr/bin/env python
-import os
import yaml
import six
@@ -31,7 +30,6 @@ class Config(object):
'{}_{}'.format(attr_now, next) if attr_now else next)
def _set_others(self):
- self.env_active = os.path.join(self.dir_functest_conf, "env_active")
-
+ pass
CONF = Config()
diff --git a/setup.cfg b/setup.cfg
index bf1a8bb42..30901da12 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -16,7 +16,6 @@ console_scripts =
functest_tempest_conf = functest.opnfv_tests.openstack.refstack_client.tempest_conf:main
openstack_snapshot = functest.utils.openstack_snapshot:main
openstack_clean = functest.utils.openstack_clean:main
- prepare_env = functest.ci.prepare_env:main
run_tests = functest.ci.run_tests:main
check_deployment = functest.ci.check_deployment:main
functest_restapi = functest.api.server:main