vrops_rcvr = plugin_receiver.PluginReceiver()
-def get_vim_type(message):
+def get_vim_type(msg):
"""Get the vim type that is required by the message."""
try:
- return json.loads(message.value)["vim_type"].lower()
+ vim_uuid = json.loads(msg.value)["vim_uuid"].lower()
+ credentials = database_manager.get_credentials(vim_uuid)
+ return credentials.type
except Exception as exc:
log.warn("vim_type is not configured correctly; %s", exc)
return None
if req_type == "put":
response = requests.put(
url, data=payload, headers=headers,
- timeout=1)
+ timeout=10)
elif req_type == "get":
response = requests.get(
- url, params=params, headers=headers, timeout=1)
+ url, params=params, headers=headers, timeout=10)
elif req_type == "delete":
response = requests.delete(
- url, headers=headers, timeout=1)
+ url, headers=headers, timeout=10)
else:
response = requests.post(
url, data=payload, headers=headers,
- timeout=1)
+ timeout=10)
# Raises exception if there was an error
try:
--- /dev/null
+# -*- coding: utf-8 -*-
+
+# Copyright 2018 Whitestack, LLC
+# *************************************************************
+
+# This file is part of OSM Monitoring module
+# All Rights Reserved to Whitestack, LLC
+
+# 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 License, Version 2.0 please
+# contact: bdiaz@whitestack.com or glavado@whitestack.com
+##
+
+"""Test an end to end Openstack vim_account requests."""
+
+import json
+import logging
+import time
+import unittest
+
+from kafka import KafkaConsumer
+from kafka import KafkaProducer
+from kafka.errors import KafkaError
+
+from osm_mon.core.auth import AuthManager
+
+log = logging.getLogger(__name__)
+
+
+class VimAccountTest(unittest.TestCase):
+ def setUp(self):
+ try:
+ self.producer = KafkaProducer(bootstrap_servers='localhost:9092')
+ self.consumer = KafkaConsumer(bootstrap_servers='localhost:9092',
+ group_id='osm_mon')
+ self.consumer.subscribe(['vim_account'])
+ self.auth_manager = AuthManager()
+ except KafkaError:
+ self.skipTest('Kafka server not present.')
+
+ @unittest.skip("Correct support for functional tests is pending.")
+ # TODO: Refactor
+ def test_create_edit_delete_vim_account(self):
+ """Test vim_account creation message from KafkaProducer."""
+ # Set-up message, producer and consumer for tests
+ create_payload = {
+ "_id": "test_id",
+ "name": "test_name",
+ "vim_type": "openstack",
+ "vim_url": "auth_url",
+ "vim_user": "user",
+ "vim_password": "password",
+ "vim_tenant_name": "tenant",
+ "config":
+ {
+ "foo": "bar"
+ }
+ }
+
+ self.producer.send('vim_account', key=b'create', value=json.dumps(create_payload))
+
+ self.producer.flush()
+
+ time.sleep(1)
+ creds = self.auth_manager.get_credentials('test_id')
+ self.assertIsNotNone(creds)
+ self.assertEqual(creds.name, create_payload['name'])
+ self.assertEqual(json.loads(creds.config), create_payload['config'])
+
+ # Set-up message, producer and consumer for tests
+ edit_payload = {
+ "_id": "test_id",
+ "name": "test_name_edited",
+ "vim_type": "openstack",
+ "vim_url": "auth_url",
+ "vim_user": "user",
+ "vim_password": "password",
+ "vim_tenant_name": "tenant",
+ "config":
+ {
+ "foo_edited": "bar_edited"
+ }
+ }
+
+ self.producer.send('vim_account', key=b'edit', value=json.dumps(edit_payload))
+
+ self.producer.flush()
+
+ time.sleep(1)
+ creds = self.auth_manager.get_credentials('test_id')
+ self.assertEqual(creds.name, edit_payload['name'])
+ self.assertEqual(json.loads(creds.config), edit_payload['config'])
+
+ delete_payload = {
+ "_id": "test_id"
+ }
+
+ self.producer.send('vim_account', key=b'delete', value=json.dumps(delete_payload))
+
+ self.producer.flush()
+
+ time.sleep(1)
+ creds = self.auth_manager.get_credentials('test_id')
+ self.assertIsNone(creds)
from kafka.errors import KafkaError
from osm_mon.core.auth import AuthManager
+from osm_mon.core.database import DatabaseManager
from osm_mon.core.message_bus.producer import KafkaProducer as prod
from osm_mon.plugins.OpenStack import response
from osm_mon.plugins.OpenStack.Aodh import alarming
try:
self.producer = KafkaProducer(bootstrap_servers='localhost:9092')
self.req_consumer = KafkaConsumer(bootstrap_servers='localhost:9092',
- consumer_timeout_ms=5000)
+ auto_offset_reset='earliest',
+ consumer_timeout_ms=60000)
self.req_consumer.subscribe(['alarm_request'])
except KafkaError:
self.skipTest('Kafka server not present.')
return
self.fail("No message received in consumer")
+ @mock.patch.object(DatabaseManager, "save_alarm", mock.Mock())
@mock.patch.object(Common, "get_auth_token", mock.Mock())
@mock.patch.object(Common, "get_endpoint", mock.Mock())
@mock.patch.object(prod, "create_alarm_response")
return
self.fail("No message received in consumer")
+ @mock.patch.object(Common, "get_auth_token", mock.Mock())
+ @mock.patch.object(Common, "get_endpoint", mock.Mock())
@mock.patch.object(alarming.Alarming, "update_alarm_state")
def test_ack_alarm_req(self, ack_alarm):
"""Test Aodh acknowledge alarm request message from KafkaProducer."""
self.producer.send('alarm_request', key="acknowledge_alarm",
value=json.dumps(payload))
- self.producer.flush()
+
+ for message in self.req_consumer:
+ # Check the vim desired by the message
+ if message.key == "acknowledge_alarm":
+ self.alarms.alarming(message)
+ return
+
+ self.fail("No message received in consumer")
\ No newline at end of file
self.producer = KafkaProducer(bootstrap_servers='localhost:9092')
self.req_consumer = KafkaConsumer(bootstrap_servers='localhost:9092',
auto_offset_reset='earliest',
- consumer_timeout_ms=2000)
+ consumer_timeout_ms=60000)
self.req_consumer.subscribe(['metric_request'])
except KafkaError:
self.skipTest('Kafka server not present.')
value=json.dumps(payload))
for message in self.req_consumer:
- # Check the vim desired by the message
- vim_type = json.loads(message.value)["vim_type"].lower()
if message.key == "delete_metric_request":
# Metric has been deleted
del_metric.return_value = True
+++ /dev/null
-# -*- coding: utf-8 -*-
-
-# Copyright 2018 Whitestack, LLC
-# *************************************************************
-
-# This file is part of OSM Monitoring module
-# All Rights Reserved to Whitestack, LLC
-
-# 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 License, Version 2.0 please
-# contact: bdiaz@whitestack.com or glavado@whitestack.com
-##
-
-"""Test an end to end Openstack vim_account requests."""
-
-import json
-import logging
-import time
-import unittest
-
-from kafka import KafkaConsumer
-from kafka import KafkaProducer
-from kafka.errors import KafkaError
-
-from osm_mon.core.auth import AuthManager
-
-log = logging.getLogger(__name__)
-
-
-class VimAccountTest(unittest.TestCase):
- def setUp(self):
- try:
- self.producer = KafkaProducer(bootstrap_servers='localhost:9092')
- self.consumer = KafkaConsumer(bootstrap_servers='localhost:9092',
- group_id='osm_mon')
- self.consumer.subscribe(['vim_account'])
- self.auth_manager = AuthManager()
- except KafkaError:
- self.skipTest('Kafka server not present.')
-
- # TODO: REFACTOR. This test requires common_consumer running. Needs to be changed so it does not.
- @unittest.skip("Needs refactoring.")
- def test_create_edit_delete_vim_account(self):
- """Test vim_account creation message from KafkaProducer."""
- # Set-up message, producer and consumer for tests
- create_payload = {
- "_id": "test_id",
- "name": "test_name",
- "vim_type": "openstack",
- "vim_url": "auth_url",
- "vim_user": "user",
- "vim_password": "password",
- "vim_tenant_name": "tenant",
- "config":
- {
- "foo": "bar"
- }
- }
-
- self.producer.send('vim_account', key=b'create', value=json.dumps(create_payload))
-
- self.producer.flush()
-
- time.sleep(1)
- creds = self.auth_manager.get_credentials(create_payload['_id'])
- self.assertIsNotNone(creds)
- self.assertEqual(creds.name, create_payload['name'])
- self.assertEqual(json.loads(creds.config), create_payload['config'])
-
- # Set-up message, producer and consumer for tests
- edit_payload = {
- "_id": "test_id",
- "name": "test_name_edited",
- "vim_type": "openstack",
- "vim_url": "auth_url",
- "vim_user": "user",
- "vim_password": "password",
- "vim_tenant_name": "tenant",
- "config":
- {
- "foo_edited": "bar_edited"
- }
- }
-
- self.producer.send('vim_account', key=b'edit', value=json.dumps(edit_payload))
-
- self.producer.flush()
-
- time.sleep(1)
- creds = self.auth_manager.get_credentials(edit_payload['_id'])
- self.assertEqual(creds.name, edit_payload['name'])
- self.assertEqual(json.loads(creds.config), edit_payload['config'])
-
- delete_payload = {
- "_id": "test_id"
- }
-
- self.producer.send('vim_account', key=b'delete', value=json.dumps(delete_payload))
-
- self.producer.flush()
-
- time.sleep(1)
- creds = self.auth_manager.get_credentials(delete_payload['_id'])
- self.assertIsNone(creds)