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
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact: bdiaz@whitestack.com or glavado@whitestack.com
24 from unittest
import mock
26 from osm_common
import dbmongo
28 from osm_mon
.core
.common_db
import CommonDbClient
31 class CommonDbClientTest(unittest
.TestCase
):
35 @mock.patch
.object(dbmongo
.DbMongo
, "db_connect", mock
.Mock())
36 @mock.patch
.object(CommonDbClient
, "get_vnfr")
37 def test_get_vim_id(self
, get_vnfr
):
38 get_vnfr
.return_value
= {'_id': 'a314c865-aee7-4d9b-9c9d-079d7f857f01',
40 'projects_read': ['admin'], 'created': 1526044312.102287,
41 'modified': 1526044312.102287, 'projects_write': ['admin']
43 'vim-account-id': 'c1740601-7287-48c8-a2c9-bce8fee459eb',
44 'nsr-id-ref': '5ec3f571-d540-4cb0-9992-971d1b08312e',
47 'internal-connection-point': [],
48 'vdu-id-ref': 'ubuntuvnf_vnfd-VM',
49 'id': 'ffd73f33-c8bb-4541-a977-44dcc3cbe28d',
50 'vim-id': '27042672-5190-4209-b844-95bbaeea7ea7',
51 'name': 'ubuntuvnf_vnfd-VM'
54 'vnfd-ref': 'ubuntuvnf_vnfd',
55 'member-vnf-index-ref': '1',
56 'created-time': 1526044312.0999322,
57 'vnfd-id': 'a314c865-aee7-4d9b-9c9d-079d7f857f01',
58 'id': 'a314c865-aee7-4d9b-9c9d-079d7f857f01'}
59 common_db_client
= CommonDbClient()
60 vim_account_id
= common_db_client
.get_vim_account_id('5ec3f571-d540-4cb0-9992-971d1b08312e', 1)
61 self
.assertEqual(vim_account_id
, 'c1740601-7287-48c8-a2c9-bce8fee459eb')
63 @mock.patch
.object(dbmongo
.DbMongo
, "db_connect", mock
.Mock())
64 @mock.patch
.object(dbmongo
.DbMongo
, "get_one")
65 def test_get_vdur(self
, get_one
):
66 get_one
.return_value
= {'_id': 'a314c865-aee7-4d9b-9c9d-079d7f857f01',
68 'projects_read': ['admin'], 'created': 1526044312.102287,
69 'modified': 1526044312.102287, 'projects_write': ['admin']
71 'vim-account-id': 'c1740601-7287-48c8-a2c9-bce8fee459eb',
72 'nsr-id-ref': '5ec3f571-d540-4cb0-9992-971d1b08312e',
75 'internal-connection-point': [],
76 'vdu-id-ref': 'ubuntuvnf_vnfd-VM',
77 'id': 'ffd73f33-c8bb-4541-a977-44dcc3cbe28d',
78 'vim-id': '27042672-5190-4209-b844-95bbaeea7ea7',
79 'name': 'ubuntuvnf_vnfd-VM'
82 'vnfd-ref': 'ubuntuvnf_vnfd',
83 'member-vnf-index-ref': '1',
84 'created-time': 1526044312.0999322,
85 'vnfd-id': 'a314c865-aee7-4d9b-9c9d-079d7f857f01',
86 'id': 'a314c865-aee7-4d9b-9c9d-079d7f857f01'}
87 common_db_client
= CommonDbClient()
88 vdur
= common_db_client
.get_vdur('5ec3f571-d540-4cb0-9992-971d1b08312e', '1', 'ubuntuvnf_vnfd-VM')
90 'internal-connection-point': [],
91 'vdu-id-ref': 'ubuntuvnf_vnfd-VM',
92 'id': 'ffd73f33-c8bb-4541-a977-44dcc3cbe28d',
93 'vim-id': '27042672-5190-4209-b844-95bbaeea7ea7',
94 'name': 'ubuntuvnf_vnfd-VM'
97 self
.assertDictEqual(vdur
, expected_vdur
)