-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD fiware-cloto rest client for testing purposes and Context Update …
…test feature
- Loading branch information
Showing
15 changed files
with
406 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
tests/acceptance/features/component/context_update.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
Feature: Receive context update requests | ||
As a scalability manager user | ||
I want to receive data from the monitoring architecture through Context Broker notifications | ||
In order to manage facts, and group and send them to be processed. | ||
|
||
@basic | ||
Scenario Outline: Receive a context update notification with all parameters | ||
Given the tenant-id registered in CLOTO component | ||
When a context notification is received for "<server_id>" with values: | ||
| cpuLoadPct | usedMemPct | freeSpacePct | netLoadPct | | ||
| <cpu> | <memory> | <disk> | <network> | | ||
Then the context is updated | ||
|
||
Examples: | ||
|
||
| server_id | cpu | memory | disk | network | | ||
| qatest | 0.75 | 0.8 | 0.1 | 0.15 | | ||
| qatest | 0.00 | 0.8 | 0.1 | 0.15 | | ||
| qatest | 0.75 | 0.0 | 0.1 | 0.15 | | ||
| qatest | 0.75 | 0.8 | 0.0 | 0.15 | | ||
| qatest | 0 | 0.8 | 0.1 | 0.0 | | ||
| qatest | 0.75 | 0 | 0.1 | 0.15 | | ||
| qatest | 0.75 | 0.8 | 0 | 0.15 | | ||
| qatest | 0.75 | 0.8 | 0.1 | 0 | | ||
| qatest | 0.752 | 0.8 | 0.1 | 0.15 | | ||
| qatest | 0.75 | 0.857 | 0.1 | 0.15 | | ||
| qatest | 0.75 | 0.8 | 0.123 | 0.15 | | ||
| qatest | 0.75 | 0.8 | 0.1 | 0.151 | | ||
| qatest | 0.75 | 0.8 | 0.1 | 1 | | ||
| qatest | 0.75 | 0.8 | 1 | 0.151 | | ||
| qatest | 0.75 | 1 | 0.1 | 0.151 | | ||
| qatest | 1 | 0.8 | 0.1 | 0.151 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
__author__ = 'Javier' | ||
75 changes: 75 additions & 0 deletions
75
tests/acceptance/features/component/steps/context_update.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U | ||
# | ||
# This file is part of FI-WARE 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__ = "@jframos" | ||
|
||
import behave | ||
from behave import step | ||
from hamcrest import assert_that | ||
import uuid | ||
from qautils.dataset.dataset_utils import DatasetUtils | ||
import qautils.configuration.configuration_utils as config_utils | ||
from qautils.configuration.configuration_properties import PROPERTIES_CONFIG_SERVICE_OS_TENANT_ID | ||
from commons.constants import PROPERTIES_CONFIG_FACTS_SERVICE | ||
|
||
behave.use_step_matcher("re") | ||
dataset_utils = DatasetUtils() | ||
|
||
|
||
@step(u'the tenant-id registered in CLOTO component') | ||
def tenant_id_is_registered_in_cloto(context): | ||
|
||
# A GET request is executed to CLOTO component, to init all data about that tenant in its system. | ||
context.tenant_id_facts = config_utils.config[PROPERTIES_CONFIG_FACTS_SERVICE][PROPERTIES_CONFIG_SERVICE_OS_TENANT_ID] | ||
_, response = context.cloto_client.get_tenant_id_resource_client().get_tenant_id(context.tenant_id_facts) | ||
|
||
assert_that(response.ok, | ||
"TenantId '{}' for testing cannot be retrieved from CLOTO: Message: {}".format(context.tenant_id_facts, | ||
response.text)) | ||
|
||
|
||
@step(u'a context notification is received for "(?P<server_id>.*)" with values') | ||
def a_context_update_is_received(context, server_id): | ||
|
||
testdata = dataset_utils.prepare_data(context.table) | ||
attribute_list = list() | ||
for header in context.table.headings: | ||
attribute_list.append({"name": header, "type": "string", "value": testdata.rows[0][header]}) | ||
|
||
|
||
context.response = context.facts_client.send_monitored_data(subscription_id = str(uuid.uuid1()), | ||
originator=server_id, | ||
status_code="200", | ||
details="OK", type="vm", | ||
is_pattern="false", | ||
id=server_id, | ||
attribute_list=attribute_list, | ||
tenant_id=context.tenant_id_facts, | ||
server_id=server_id) | ||
|
||
@step(u'the context is updated') | ||
def the_context_is_updated(context): | ||
|
||
assert_that(context.response.ok, | ||
"Response to CB notification is not the expected one: Message: {}".format(context.response.text)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# -*- 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__ = "@jframos" | ||
|
||
|
||
from qautils.http.headers_utils import set_representation_headers, HEADER_REPRESENTATION_JSON | ||
from qautils.logger.logger_utils import get_logger | ||
from keystoneclient.v2_0 import Client as KeystoneClient | ||
from fiwarecloto_client.tenantid_resource import TenantIdResourceClient | ||
|
||
__logger__ = get_logger(__name__) | ||
|
||
|
||
# HEADERS | ||
X_AUTH_TOKEN = "X-Auth-Token" | ||
TENANT_ID = "Tenant-Id" | ||
|
||
|
||
class ClotoClient(): | ||
|
||
def __init__(self, username, password, tenant_id, auth_url, api_protocol, api_host, api_port, api_resource): | ||
""" | ||
Init a new Client for CLOTO component. | ||
:param username (string): The username (OpenStack) | ||
:param password (string): The password | ||
:param tenant_id (string): TenantID | ||
:param auth_url (string): Keystone/IdM auth URL | ||
:param api_protocol (string): API protocol | ||
:param api_host (string): API host | ||
:param api_port (string): API port | ||
:param api_resource (string): API base resource | ||
:return: None | ||
""" | ||
|
||
__logger__.info("Init CLOTO Client") | ||
__logger__.debug("Client parameters: Username: %s, Password: %s, TenantId: %s, API protocol: %s, API host: %s, " | ||
"API port: %s, Base resource: %s", username, password, tenant_id, api_protocol, api_host, | ||
api_port, api_resource) | ||
|
||
self.headers = dict() | ||
self.api_protocol = api_protocol | ||
self.api_host = api_host | ||
self.api_port = api_port | ||
self.api_resource = api_resource | ||
|
||
set_representation_headers(self.headers, content_type=HEADER_REPRESENTATION_JSON, | ||
accept=HEADER_REPRESENTATION_JSON) | ||
|
||
self._init_keystone_client(username, password, tenant_id, auth_url) | ||
self.token = self._get_auth_token() | ||
__logger__.debug("Token: %s", self.token) | ||
|
||
self.headers.update({X_AUTH_TOKEN: self.token}) | ||
self.headers.update({TENANT_ID: tenant_id}) | ||
__logger__.debug("Headers with OpenStack credentials: %s", self.headers) | ||
|
||
def _init_keystone_client(self, username, password, tenant_id, auth_url): | ||
""" | ||
Init the keystone client to request token and endpoint data | ||
:param string username: Username for authentication. | ||
:param string password: Password for authentication. | ||
:param string tenant_id: Tenant id. | ||
:param string auth_url: Keystone service endpoint for authorization. | ||
:param string region_name: Name of a region to select when choosing an | ||
endpoint from the service catalog. | ||
:return None | ||
""" | ||
|
||
__logger__.debug("Init Keystone Client") | ||
self.keystone_client = KeystoneClient(username=username, password=password, tenant_id=tenant_id, | ||
auth_url=auth_url) | ||
|
||
def _get_auth_token(self): | ||
""" | ||
Get token from Keystone | ||
:return: Token (String) | ||
""" | ||
|
||
__logger__.debug("Getting auth Token") | ||
return self.keystone_client.auth_ref['token']['id'] | ||
|
||
def get_tenant_id_resource_client(self): | ||
""" | ||
Create an API resource REST client | ||
:return: Rest client for 'TenantId' API resource | ||
""" | ||
|
||
__logger__.info("Creating TenantIdResource") | ||
|
||
return TenantIdResourceClient(protocol=self.api_protocol, host=self.api_host, | ||
port=self.api_port, resource=self.api_resource, headers=self.headers) |
Oops, something went wrong.