1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#!/usr/bin/env python
#
# Copyright (c) 2018 mokats@intracom-telecom.com and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##
import unittest
from mock import patch
import munch
import os_client_config
import shade
import dovetail.utils.openstack_utils as os_dovetail_utils
__author__ = 'Stamatis Katsaounis <mokats@intracom-telecom.com>'
class OpenStackUtilsTesting(unittest.TestCase):
def setUp(self):
self.patcher1 = patch.object(shade,
'OperatorCloud', autospec=True)
self.patcher2 = patch.object(os_client_config,
'get_config', autospec=True)
self.cloud = self.patcher1.start().return_value
self.os_client_config = self.patcher2.start().return_value
self.os_dovetail = os_dovetail_utils.OS_Utils()
def tearDown(self):
self.patcher1.stop()
self.patcher2.stop()
def test_search_endpoints(self):
endpoint = munch.Munch({u'region_id': u'RegionOne',
u'url': u'http://127.0.0.1:8977/',
u'region': u'RegionOne',
u'enabled': True,
u'interface': u'public',
u'service_id': u'123456',
u'id': u'123456'})
endpoints = [endpoint]
self.cloud.search_endpoints.return_value = endpoints
expected = (True, endpoints)
result = self.os_dovetail.search_endpoints()
self.assertEqual(expected, result)
def test_search_endpoints_raised_exception(self):
errorMSG = 'Exception was raised'
exception = shade.exc.OpenStackCloudException(errorMSG)
self.cloud.search_endpoints.side_effect = exception
expected = (False, errorMSG)
result = self.os_dovetail.search_endpoints()
self.assertEqual(expected, result)
def test_search_services(self):
service = munch.Munch({'description': u'OpenStack Identity Service',
'service_type': u'identity',
'type': u'identity',
'enabled': True,
'id': u'1bd26028c8714f3bb726126dc1ea62fc',
'name': u'keystone'})
services = [service]
self.cloud.search_services.return_value = services
expected = (True, services)
result = self.os_dovetail.search_services()
self.assertEqual(expected, result)
def test_search_services_raised_exception(self):
errorMSG = 'Exception was raised'
exception = shade.exc.OpenStackCloudException(errorMSG)
self.cloud.search_services.side_effect = exception
expected = (False, errorMSG)
result = self.os_dovetail.search_services()
self.assertEqual(expected, result)
|