1 # Copyright 2017 Intel Research and Development Ireland Limited
2 # *************************************************************
4 # This file is part of OSM Monitoring module
5 # All Rights Reserved to Intel Corporation
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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
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
22 # __author__ = "Helena McGough"
23 """Test an end to end Openstack access_credentials requests."""
29 from kafka
import KafkaConsumer
30 from kafka
import KafkaProducer
32 from keystoneclient
.v3
import client
36 from osm_mon
.plugins
.OpenStack
.common
import Common
38 log
= logging
.getLogger(__name__
)
40 # Create an instance of the common openstack class, producer and consumer
41 openstack_auth
= Common()
43 producer
= KafkaProducer(bootstrap_servers
='localhost:9092')
44 req_consumer
= KafkaConsumer(bootstrap_servers
='localhost:9092',
46 req_consumer
.subscribe("access_credentials")
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",
55 {"openstack_site": "my_site",
57 "password": "my_password",
58 "vim_tenant_name": "my_tenant"}}
60 producer
.send('access_credentials', value
=json
.dumps(payload
))
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
)
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")