blob: 5140ea661c59b06d8fe94967b605547fb68d5179 [file] [log] [blame]
Scott Bakera6c687c2018-07-16 15:08:49 -07001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import unittest
16
17import functools
18from mock import patch, call, Mock, PropertyMock
19import requests_mock
20import multistructlog
21from multistructlog import create_logger
22
23import os, sys
24
25# Hack to load synchronizer framework
26test_path=os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
27xos_dir=os.path.join(test_path, "../../..")
28if not os.path.exists(os.path.join(test_path, "new_base")):
29 xos_dir=os.path.join(test_path, "../../../../../../orchestration/xos/xos")
30 services_dir = os.path.join(xos_dir, "../../xos_services")
31sys.path.append(xos_dir)
32sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base'))
33# END Hack to load synchronizer framework
34
35# generate model from xproto
36def get_models_fn(service_name, xproto_name):
37 name = os.path.join(service_name, "xos", xproto_name)
38 if os.path.exists(os.path.join(services_dir, name)):
39 return name
40 else:
41 name = os.path.join(service_name, "xos", "synchronizer", "models", xproto_name)
42 if os.path.exists(os.path.join(services_dir, name)):
43 return name
44 raise Exception("Unable to find service=%s xproto=%s" % (service_name, xproto_name))
45# END generate model from xproto
46
47def mock_get_westbound_service_instance_properties(prop):
48 if prop == "status":
49 return "enabled"
50 return prop
51
52def match_json(desired, req):
53 if desired!=req.json():
54 raise Exception("Got request %s, but body is not matching" % req.url)
55 return False
56 return True
57
58class TestSyncOLTDevice(unittest.TestCase):
59
60 def setUp(self):
61 global DeferredException
62
63 self.sys_path_save = sys.path
64 sys.path.append(xos_dir)
65 sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base'))
66
67 # Setting up the config module
68 from xosconfig import Config
69 config = os.path.join(test_path, "../test_fabric_crossconnect_config.yaml")
70 Config.clear()
71 Config.init(config, "synchronizer-config-schema.yaml")
72 # END Setting up the config module
73
74 from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor
75 build_mock_modelaccessor(xos_dir, services_dir, [get_models_fn("fabric-crossconnect", "fabric-crossconnect.xproto")])
76 import synchronizers.new_base.modelaccessor
77
78 from sync_fabric_crossconnect_service_instance import SyncFabricCrossconnectServiceInstance, model_accessor, DeferredException
79
80 # import all class names to globals
81 for (k, v) in model_accessor.all_model_classes.items():
82 globals()[k] = v
83
84
85 self.sync_step = SyncFabricCrossconnectServiceInstance
86 self.sync_step.log = Mock()
87
88 # TODO: stuff
89
90 def test_sync(self):
91 pass
92
93 def tearDown(self):
94 self.o = None
95 sys.path = self.sys_path_save
96
97if __name__ == '__main__':
98 unittest.main()