Adds support for vdu_name, ns_id and vnf_member_index
[osm/MON.git] / osm_mon / test / core / test_common_consumer.py
1 import unittest
2
3 import mock
4
5 from osm_mon.core.database import VimCredentials
6 from osm_mon.core.message_bus.common_consumer import *
7
8
9 class CommonConsumerTest(unittest.TestCase):
10 @mock.patch.object(DatabaseManager, "get_credentials")
11 def test_get_vim_type(self, get_creds):
12 mock_creds = VimCredentials()
13 mock_creds.id = 'test_id'
14 mock_creds.user = 'user'
15 mock_creds.url = 'url'
16 mock_creds.password = 'password'
17 mock_creds.tenant_name = 'tenant_name'
18 mock_creds.type = 'openstack'
19
20 get_creds.return_value = mock_creds
21
22 db_manager = DatabaseManager()
23 vim_type = get_vim_type(db_manager, 'test_id')
24
25 self.assertEqual(vim_type, 'openstack')
26
27 @mock.patch.object(dbmongo.DbMongo, "get_one")
28 def test_get_vdur(self, get_one):
29 get_one.return_value = {'_id': 'a314c865-aee7-4d9b-9c9d-079d7f857f01',
30 '_admin': {
31 'projects_read': ['admin'], 'created': 1526044312.102287,
32 'modified': 1526044312.102287, 'projects_write': ['admin']
33 },
34 'vim-account-id': 'c1740601-7287-48c8-a2c9-bce8fee459eb',
35 'nsr-id-ref': '5ec3f571-d540-4cb0-9992-971d1b08312e',
36 'vdur': [
37 {
38 'internal-connection-point': [],
39 'vdu-id-ref': 'ubuntuvnf_vnfd-VM',
40 'id': 'ffd73f33-c8bb-4541-a977-44dcc3cbe28d',
41 'vim-id': '27042672-5190-4209-b844-95bbaeea7ea7'
42 }
43 ],
44 'vnfd-ref': 'ubuntuvnf_vnfd',
45 'member-vnf-index-ref': '1',
46 'created-time': 1526044312.0999322,
47 'vnfd-id': 'a314c865-aee7-4d9b-9c9d-079d7f857f01',
48 'id': 'a314c865-aee7-4d9b-9c9d-079d7f857f01'}
49
50 common_db = dbmongo.DbMongo()
51 vdur = get_vdur(common_db, '5ec3f571-d540-4cb0-9992-971d1b08312e', '1', 'ubuntuvnf_vnfd-VM')
52 expected_vdur = {
53 'internal-connection-point': [],
54 'vdu-id-ref': 'ubuntuvnf_vnfd-VM',
55 'id': 'ffd73f33-c8bb-4541-a977-44dcc3cbe28d',
56 'vim-id': '27042672-5190-4209-b844-95bbaeea7ea7'
57 }
58
59 self.assertDictEqual(vdur, expected_vdur)
60
61
62 if __name__ == '__main__':
63 unittest.main()