Included OpenStack integration tests.
[osm/MON.git] / osm_mon / test / integration / test_access_cred.py
1 # Copyright 2017 Intel Research and Development Ireland Limited
2 # *************************************************************
3
4 # This file is part of OSM Monitoring module
5 # All Rights Reserved to Intel Corporation
6
7 # Licensed under the Apache License, Version 2.0 (the "License"); you may
8 # not use this file except in compliance with the License. You may obtain
9 # a copy of the License at
10
11 # http://www.apache.org/licenses/LICENSE-2.0
12
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 # License for the specific language governing permissions and limitations
17 # under the License.
18
19 # For those usages not covered by the Apache License, Version 2.0 please
20 # contact: helena.mcgough@intel.com or adrian.hoban@intel.com
21
22 # __author__ = "Helena McGough"
23 """Test an end to end Openstack access_credentials requests."""
24
25 import json
26
27 import logging
28
29 from kafka import KafkaConsumer
30 from kafka import KafkaProducer
31
32 from keystoneclient.v3 import client
33
34 import mock
35
36 from osm_mon.plugins.OpenStack.common import Common
37
38 log = logging.getLogger(__name__)
39
40 # Create an instance of the common openstack class, producer and consumer
41 openstack_auth = Common()
42
43 producer = KafkaProducer(bootstrap_servers='localhost:9092')
44 req_consumer = KafkaConsumer(bootstrap_servers='localhost:9092',
45 group_id='osm_mon')
46 req_consumer.subscribe("access_credentials")
47
48
49 @mock.patch.object(client, "Client")
50 def test_access_cred_req(keyclient):
51 """Test access credentials request message from KafkaProducer."""
52 # Set-up message, producer and consumer for tests
53 payload = {"vim_type": "OpenStack",
54 "access_config":
55 {"openstack_site": "my_site",
56 "user": "my_user",
57 "password": "my_password",
58 "vim_tenant_name": "my_tenant"}}
59
60 producer.send('access_credentials', value=json.dumps(payload))
61
62 for message in req_consumer:
63 # Check the vim desired by the message
64 vim_type = json.loads(message.value)["vim_type"].lower()
65 if vim_type == "openstack":
66 openstack_auth._authenticate(message=message)
67
68 # A keystone client is created with the valid access_credentials
69 keyclient.assert_called_with(
70 auth_url="my_site", username="my_user", password="my_password",
71 tenant_name="my_tenant")
72
73 return