Readds plugins code and respective tests
[osm/MON.git] / osm_mon / tests / plugins / OpenStack / integration / test_vim_account.py
1 # -*- coding: utf-8 -*-
2
3 # Copyright 2018 Whitestack, LLC
4 # *************************************************************
5
6 # This file is part of OSM Monitoring module
7 # All Rights Reserved to Whitestack, LLC
8
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
12
13 # http://www.apache.org/licenses/LICENSE-2.0
14
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
19 # under the License.
20
21 # For those usages not covered by the Apache License, Version 2.0 please
22 # contact: bdiaz@whitestack.com or glavado@whitestack.com
23 ##
24
25 """Test an end to end Openstack vim_account requests."""
26
27 import json
28 import logging
29 import unittest
30
31 from peewee import SqliteDatabase
32
33 from osm_mon.core import database
34 from osm_mon.core.auth import AuthManager
35 from osm_mon.core.database import DatabaseManager, VimCredentials, Alarm
36
37 log = logging.getLogger(__name__)
38
39 test_db = SqliteDatabase(':memory:')
40
41 MODELS = [VimCredentials, Alarm]
42
43
44 class VimAccountTest(unittest.TestCase):
45 def setUp(self):
46 super().setUp()
47 database.db = test_db
48 test_db.bind(MODELS)
49 test_db.connect()
50 test_db.drop_tables(MODELS)
51 test_db.create_tables(MODELS)
52 self.auth_manager = AuthManager()
53 self.database_manager = DatabaseManager()
54 self.database_manager.create_tables()
55
56 def tearDown(self):
57 super().tearDown()
58 test_db.close()
59
60 def test_create_edit_delete_vim_account(self):
61 """Test vim_account creation message from KafkaProducer."""
62 # Set-up message, producer and consumer for tests
63 create_payload = {
64 "_id": "test_id",
65 "name": "test_name",
66 "vim_type": "openstack",
67 "vim_url": "auth_url",
68 "vim_user": "user",
69 "vim_password": "password",
70 "vim_tenant_name": "tenant",
71 "config":
72 {
73 "foo": "bar"
74 }
75 }
76 self.auth_manager.store_auth_credentials(create_payload)
77
78 creds = self.auth_manager.get_credentials('test_id')
79
80 self.assertIsNotNone(creds)
81 self.assertEqual(creds.name, create_payload['name'])
82 self.assertEqual(json.loads(creds.config), create_payload['config'])
83
84 # Set-up message, producer and consumer for tests
85 edit_payload = {
86 "_id": "test_id",
87 "name": "test_name_edited",
88 "vim_type": "openstack",
89 "vim_url": "auth_url",
90 "vim_user": "user",
91 "vim_password": "password",
92 "vim_tenant_name": "tenant",
93 "config":
94 {
95 "foo_edited": "bar_edited"
96 }
97 }
98
99 self.auth_manager.store_auth_credentials(edit_payload)
100
101 creds = self.auth_manager.get_credentials('test_id')
102
103 self.assertEqual(creds.name, edit_payload['name'])
104 self.assertEqual(json.loads(creds.config), edit_payload['config'])
105
106 delete_payload = {
107 "_id": "test_id"
108 }
109
110 self.auth_manager.delete_auth_credentials(delete_payload)
111
112 creds = self.auth_manager.get_credentials('test_id')
113 self.assertIsNone(creds)