forked from HewlettPackard/oneview-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_oneview_managed_san_facts.py
121 lines (94 loc) · 3.88 KB
/
test_oneview_managed_san_facts.py
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/python
# -*- coding: utf-8 -*-
###
# Copyright (2016-2019) Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###
import pytest
from hpe_test_utils import OneViewBaseFactsTest
from oneview_module_loader import ManagedSanFactsModule
ERROR_MSG = 'Fake message error'
MANAGED_SAN_NAME = 'SAN1_0'
MANAGED_SAN_URI = '/rest/fc-sans/managed-sans/cc64ee18-8f7d-4cdf-9bf8-a68f00e4af9c'
MANAGED_SAN_WWN = '20:00:4A:2B:21:E0:00:01'
PARAMS_GET_ALL = dict(
config='config.json',
name=None,
wwn=None
)
PARAMS_GET_BY_NAME = dict(
config='config.json',
name=MANAGED_SAN_NAME,
options=[]
)
PARAMS_GET_BY_NAME_WITH_OPTIONS = dict(
config='config.json',
name=MANAGED_SAN_NAME,
options=['endpoints']
)
PARAMS_GET_ASSOCIATED_WWN = dict(
config='config.json',
name=MANAGED_SAN_NAME,
options=[{'wwn': {'locate': MANAGED_SAN_WWN}}]
)
MANAGED_SAN = dict(name=MANAGED_SAN_NAME, uri=MANAGED_SAN_URI)
ALL_MANAGED_SANS = [MANAGED_SAN,
dict(name='SAN1_1', uri='/rest/fc-sans/managed-sans/928374892-asd-34234234-asd23')]
@pytest.mark.resource(TestManagedSanFactsModule='managed_sans')
class TestManagedSanFactsModule(OneViewBaseFactsTest):
"""
FactsParamsTestCase has common tests for the parameters support.
"""
def test_should_get_all(self):
self.resource.get_all.return_value = ALL_MANAGED_SANS
self.mock_ansible_module.params = PARAMS_GET_ALL
ManagedSanFactsModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
ansible_facts=dict(managed_sans=ALL_MANAGED_SANS)
)
def test_should_get_by_name(self):
self.resource.data = MANAGED_SAN
self.mock_ansible_module.params = PARAMS_GET_BY_NAME
ManagedSanFactsModule().run()
self.resource.get_by_name.assert_called_once_with(MANAGED_SAN_NAME)
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
ansible_facts=dict(managed_sans=[MANAGED_SAN])
)
def test_should_get_by_name_with_options(self):
endpoints = [dict(uri='/rest/fc-sans/endpoints/20:00:00:02:AC:00:08:E2'),
dict(uri='/rest/fc-sans/endpoints/20:00:00:02:AC:00:08:FF')]
self.resource.data = MANAGED_SAN
self.resource.get_endpoints.return_value = endpoints
self.mock_ansible_module.params = PARAMS_GET_BY_NAME_WITH_OPTIONS
ManagedSanFactsModule().run()
self.resource.get_by_name.assert_called_once_with(MANAGED_SAN_NAME)
self.resource.get_endpoints.assert_called_once_with()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
ansible_facts=dict(managed_sans=[MANAGED_SAN], managed_san_endpoints=endpoints)
)
def test_should_get_managed_san_for_an_associated_wwn(self):
self.resource.data = MANAGED_SAN
self.resource.get_wwn.return_value = MANAGED_SAN
self.mock_ansible_module.params = PARAMS_GET_ASSOCIATED_WWN
ManagedSanFactsModule().run()
self.resource.get_wwn.assert_called_once_with(MANAGED_SAN_WWN)
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
ansible_facts=dict(managed_sans=[MANAGED_SAN], wwn_associated_sans=MANAGED_SAN)
)
if __name__ == '__main__':
pytest.main([__file__])