1 # -*- coding: utf-8 -*-
3 # Copyright 2018 Whitestack, LLC
4 # *************************************************************
6 # This file is part of OSM Monitoring module
7 # All Rights Reserved to Whitestack, LLC
9 # Licensed under the Apache License, Version 2.0 (the "License"); you may
10 # not use this file except in compliance with the License. You may obtain
11 # a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18 # License for the specific language governing permissions and limitations
21 # For those usages not covered by the Apache License, Version 2.0 please
22 # contact: bdiaz@whitestack.com or glavado@whitestack.com
25 """Test an end to end Openstack vim_account requests."""
32 from kafka
import KafkaConsumer
33 from kafka
import KafkaProducer
34 from kafka
.errors
import KafkaError
36 from osm_mon
.core
.auth
import AuthManager
38 log
= logging
.getLogger(__name__
)
41 class VimAccountTest(unittest
.TestCase
):
44 self
.producer
= KafkaProducer(bootstrap_servers
='localhost:9092')
45 self
.consumer
= KafkaConsumer(bootstrap_servers
='localhost:9092',
47 self
.consumer
.subscribe(['vim_account'])
48 self
.auth_manager
= AuthManager()
50 self
.skipTest('Kafka server not present.')
52 def test_create_vim_account(self
):
53 """Test vim_account creation message from KafkaProducer."""
54 # Set-up message, producer and consumer for tests
58 "vim_type": "openstack",
59 "vim_url": "auth_url",
61 "vim_password": "password",
62 "vim_tenant_name": "tenant",
69 self
.producer
.send('vim_account', key
=b
'create', value
=json
.dumps(payload
))
73 # FIXME: Create a schema for a vim_account_create_response, so we can test it
75 creds
= self
.auth_manager
.get_credentials(payload
['_id'])
76 self
.assertEqual(creds
.name
, payload
['name'])
77 self
.assertEqual(json
.loads(creds
.config
), payload
['config'])