Skip to content

Commit

Permalink
Merge pull request #39 from jframos/QA/init_automation_framework
Browse files Browse the repository at this point in the history
[QA] Monitoring Automation Framework and 'send_data_api_resource' steps implementation
  • Loading branch information
pratid committed Feb 3, 2015
2 parents 362d6a1 + 59ef096 commit 89b986a
Show file tree
Hide file tree
Showing 25 changed files with 1,316 additions and 36 deletions.
72 changes: 70 additions & 2 deletions ngsi_adapter/src/test/acceptance/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Gherkin has the purpose of serving documentation of test cases.
Test case implementation has been performed using `Python <http://www.python.org/>`_ and
`Lettuce <http://lettuce.it/>`_.

Project Structure
-----------------
Acceptance Project Structure
----------------------------
::

├───acceptance
Expand All @@ -26,3 +26,71 @@ Project Structure
│ │ └───probe_sample_data
│ └───settings


FIWARE Monitoring Automation Framework
---------------------------------------

Features:

- Lettuce-Tools support
- Settings using json files and Lettuce-Tools utility
- Test report using Lettuce-Tools XUnit output
- NGSI-Adapter Client
- Logging
- Remote NGSI-Adapter log capturing
- Test data management using templates (resources)


Acceptance test execution
-------------------------

Execute the following command in the test project root directory:

::

$> cd ngsi_adapter/src/test/acceptance
$> lettuce_tools -ft send_data_api_resource -ts comp -sd features/ --tags=-skip -en dev

With this command, you will execute:

- components Test Cases in the 'Development' environment configured in settings/dev-properties.json
- the send_data_api_resource feature
- Skipping all Scenarios with tagged with "skip"


**Prerequisites**

- Python 2.7 or newer (2.x) (https://www.python.org/downloads/)
- pip (https://pypi.python.org/pypi/pip)
- virtualenv (https://pypi.python.org/pypi/virtualenv)
- Monitoring [NGSI-Adapter] (`Download NGSI-Adapter <https://github.com/telefonicaid/fiware-monitoring>`_)

**Test case execution using virtualenv**

1. Create a virtual environment somewhere *(virtualenv $WORKON_HOME/venv)*
#. Activate the virtual environment *(source $WORKON_HOME/venv/bin/activate)*
#. Go to *ngsi_adapter/src/test/acceptance* folder in the project
#. Install the requirements for the acceptance tests in the virtual environment *(pip install -r requirements.txt --allow-all-external)*

**Test case execution using Vagrant (optional)**

Instead of using virtualenv, you can use the provided Vagrantfile to deploy a local VM using `Vagrant <https://www.vagrantup.com/>`_,
that will provide all environment configurations for launching test cases.

1. Download and install Vagrant (https://www.vagrantup.com/downloads.html)
#. Go to *ngsi_adapter/src/test/acceptance* folder in the project
#. Execute *vagrant up* to launch a VM based on Vagrantfile provided.
#. After Vagrant provision, your VM is properly configured to launch acceptance tests. You have to access to the VM using
*vagrant ssh* and change to */vagrant* directory that will have mounted your workspace *(test/acceptance)*.

If you need more information about how to use Vagrant, you can see
`Vagrant Getting Started <https://docs.vagrantup.com/v2/getting-started/index.html>`_

**Settings**

Before executing the acceptance tests, you will need configure the properties file. To execute acceptance test on the
experimentation environment, you will have to configured the file *settings/dev-properties*.

You will need a valid private key (*private_key_location*) to connect to NGSI-Adapter Host to capture remote logs.
In this way, you will be able to execute Scenarios that require the logs capturing for test validations.
46 changes: 46 additions & 0 deletions ngsi_adapter/src/test/acceptance/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Copyright 2015 Telefonica Investigación y Desarrollo, S.A.U
#
# This file is part of FIWARE project.
#
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
#
# For those usages not covered by the Apache version 2.0 License please
# contact with opensource@tid.es

#__author__ = 'jfernandez'


# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

# Every Vagrant virtual environment requires a box to build off of.
# Box: https://atlas.hashicorp.com/hashicorp/boxes/precise32
config.vm.box = "hashicorp/precise32"

# Provision
config.vm.provision "shell", inline: "cd /home/vagrant", privileged: true
config.vm.provision "shell", inline: "wget https://bootstrap.pypa.io/get-pip.py", privileged: true
config.vm.provision "shell", inline: "python get-pip.py", privileged: true
config.vm.provision "shell", inline: "apt-get update", privileged: true
config.vm.provision "shell", inline: "apt-get -y install python-dev", privileged: true
config.vm.provision "shell", inline: "apt-get -y install git", privileged: true
config.vm.provision "shell", inline: "apt-get -y install libxml2-dev libxslt1-dev", privileged: true
config.vm.provision "shell", inline: "pip install -r /vagrant/requirements.txt", privileged: true
end
75 changes: 75 additions & 0 deletions ngsi_adapter/src/test/acceptance/commons/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# -*- coding: utf-8 -*-

# Copyright 2015 Telefonica Investigación y Desarrollo, S.A.U
#
# This file is part of FIWARE project.
#
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
#
# For those usages not covered by the Apache version 2.0 License please
# contact with opensource@tid.es

__author__ = 'jfernandez'


# HEADERS
HEADER_CONTENT_TYPE = u'content-type'
HEADER_ACCEPT = u'accept'
HEADER_REPRESENTATION_JSON = u'application/json'
HEADER_REPRESENTATION_XML = u'application/xml'
HEADER_REPRESENTATION_TEXTPLAIN = u'text/plain'
HEADER_AUTH_TOKEN = u'X-Auth-Token'
HEADER_TENANT_ID = u'Tenant-Id'
HEADER_TRANSACTION_ID = u'txid'

# HTTP VERBS
HTTP_VERB_POST = 'post'
HTTP_VERB_GET = 'get'
HTTP_VERB_PUT = 'put'
HTTP_VERB_DELETE = 'delete'
HTTP_VERB_UPDATE = 'update'

# TRANSACTION ID
TRANSACTION_ID_PATTERN = "qa/{uuid}"

# NGSI CLIENT
NGSI_ADAPTER_URI_BASE = "{api_root_url}"
NGSI_ADAPTER_URI_PARSER = NGSI_ADAPTER_URI_BASE + "/{parser_name}"
NGSI_ADAPTER_PARAMETER_ID = "id"
NGSI_ADAPTER_PARAMETER_TYPE = "type"

# CONFIGURATION PROPERTIES
PROPERTIES_FILE = "properties.json"
PROPERTIES_CONFIG_ENV = "environment"
PROPERTIES_CONFIG_ENV_NAME = "name"
PROPERTIES_CONFIG_ENV_LOGS_PATH = "log_path"
PROPERTIES_CONFIG_ENV_LOCAL_PATH_REMOTE_LOGS = "local_path_remote_logs"
MONITORING_CONFIG_ENV_DEFAULT_PARSER = "default_parser"
MONITORING_CONFIG_ENV_DEFAULT_PARSER_DATA = "default_parser_data"
MONITORING_CONFIG_ENV_DEFAULT_PARSER_PARAMS = "default_parser_parameters"
MONITORING_CONFIG_SERVICE_ADAPTER = "monitoring_adapter_service"
MONITORING_CONFIG_SERVICE_PROTOCOL = "protocol"
MONITORING_CONFIG_SERVICE_HOST = "host"
MONITORING_CONFIG_SERVICE_PORT = "port"
MONITORING_CONFIG_SERVICE_RESOURCE = "resource"
MONITORING_CONFIG_SERVICE_PRIVATEKEY = "private_key_location"
MONITORING_CONFIG_SERVICE_HOSTUSER = "host_user"
MONITORING_CONFIG_SERVICE_HOSTPASSWORD = "host_password"
MONITORING_CONFIG_SERVICE_LOG_PATH = "service_log_path"
MONITORING_CONFIG_SERVICE_LOG_FILE_NAME = "service_log_file_name"

# RESOURCES
RESOURCES_SAMPLEDATA_MODULE = "resources.probe_sample_data"
RESOURCES_PARAMETER_PATTERN = "${param_name}"
45 changes: 45 additions & 0 deletions ngsi_adapter/src/test/acceptance/commons/dataset_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-

# Copyright 2015 Telefonica Investigación y Desarrollo, S.A.U
#
# This file is part of FIWARE project.
#
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
#
# For those usages not covered by the Apache version 2.0 License please
# contact with opensource@tid.es

__author__ = 'jfernandez'


from lettuce_tools.dataset_utils.dataset_utils import DatasetUtils

dataset_utils = DatasetUtils()


def prepare_param(param):
"""
Generate a fixed length data for elements tagged with the text [LENGTH] in lettuce
Removes al the data elements tagged with the text [MISSING_PARAM] in lettuce
:param param: Lettuce parameter
:return data without not desired params
"""

if "[MISSING_PARAM]" in param:
new_param = None
else:
new_param = dataset_utils.generate_fixed_length_param(param)

return new_param
Loading

0 comments on commit 89b986a

Please sign in to comment.