CORD-2237 update remaining synchronizer framework tests;
Cherry pick of 7347 commit 342c65f1c0b69befcd31a3cd18449340dfca4a4f
Change-Id: I59e365ca095d8eaed9a53438cc5be1b2ecd58584
diff --git a/lib/xos-genx/xosgenx/targets/mock_classes.xtarget b/lib/xos-genx/xosgenx/targets/mock_classes.xtarget
index bbc5ae2..00db7e5 100644
--- a/lib/xos-genx/xosgenx/targets/mock_classes.xtarget
+++ b/lib/xos-genx/xosgenx/targets/mock_classes.xtarget
@@ -95,7 +95,7 @@
def leaf_model(self):
return self
- def save(self):
+ def save(self, update_fields=[]):
if self.objects:
self.objects.save(self)
diff --git a/xos/synchronizers/new_base/tests/steps/__init__.py b/xos/synchronizers/new_base/tests/steps/__init__.py
new file mode 100644
index 0000000..d4e8062
--- /dev/null
+++ b/xos/synchronizers/new_base/tests/steps/__init__.py
@@ -0,0 +1,16 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# 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.
+
+
diff --git a/xos/synchronizers/new_base/tests/test_payload.py b/xos/synchronizers/new_base/tests/test_payload.py
index 56357f1..b893c85 100644
--- a/xos/synchronizers/new_base/tests/test_payload.py
+++ b/xos/synchronizers/new_base/tests/test_payload.py
@@ -13,8 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# TEST_FRAMEWORK: IGNORE
-
import json
import unittest
from mock import patch
@@ -39,7 +37,7 @@
class TestPayload(unittest.TestCase):
def setUp(self):
- global log, steps
+ global log, steps, event_loop
self.sys_path_save = sys.path
self.cwd_save = os.getcwd()
@@ -84,94 +82,100 @@
@mock.patch("steps.sync_instances.syncstep.run_template",side_effect=run_fake_ansible_template)
@mock.patch("event_loop.model_accessor")
def test_delete_record(self, mock_run_template, mock_modelaccessor):
- o = Instance()
- o.name = "Sisi Pascal"
+ with mock.patch.object(Instance, "save") as instance_save:
+ o = Instance()
+ o.name = "Sisi Pascal"
- o.synchronizer_step = steps.sync_instances.SyncInstances()
- self.synchronizer.delete_record(o, log)
+ o.synchronizer_step = steps.sync_instances.SyncInstances()
+ self.synchronizer.delete_record(o, log)
- a = get_ansible_output()
- self.assertDictContainsSubset({'delete':True, 'name':o.name}, a)
- o.save.assert_called_with(update_fields=['backend_need_reap'])
+ a = get_ansible_output()
+ self.assertDictContainsSubset({'delete':True, 'name':o.name}, a)
+ o.save.assert_called_with(update_fields=['backend_need_reap'])
@mock.patch("steps.sync_instances.syncstep.run_template",side_effect=run_fake_ansible_template)
@mock.patch("event_loop.model_accessor")
def test_sync_record(self, mock_run_template, mock_modelaccessor):
- o = Instance()
- o.name = "Sisi Pascal"
+ with mock.patch.object(Instance, "save") as instance_save:
+ o = Instance()
+ o.name = "Sisi Pascal"
- o.synchronizer_step = steps.sync_instances.SyncInstances()
- self.synchronizer.sync_record(o, log)
+ o.synchronizer_step = steps.sync_instances.SyncInstances()
+ self.synchronizer.sync_record(o, log)
- a = get_ansible_output()
- self.assertDictContainsSubset({'delete':False, 'name':o.name}, a)
- o.save.assert_called_with(update_fields=['enacted', 'backend_status', 'backend_register', 'backend_code'])
+ a = get_ansible_output()
+ self.assertDictContainsSubset({'delete':False, 'name':o.name}, a)
+ o.save.assert_called_with(update_fields=['enacted', 'backend_status', 'backend_register'])
@mock.patch("steps.sync_instances.syncstep.run_template",side_effect=run_fake_ansible_template)
@mock.patch("event_loop.model_accessor")
def test_sync_cohort(self, mock_run_template, mock_modelaccessor):
- cs = ControllerSlice()
- s = Slice(name = 'SP SP')
- cs.slice = s
+ with mock.patch.object(Instance, "save") as instance_save, \
+ mock.patch.object(ControllerSlice, "save") as controllerslice_save:
+ cs = ControllerSlice()
+ s = Slice(name = 'SP SP')
+ cs.slice = s
- o = Instance()
- o.name = "Sisi Pascal"
- o.slice = s
+ o = Instance()
+ o.name = "Sisi Pascal"
+ o.slice = s
- cohort = [cs, o]
- o.synchronizer_step = steps.sync_instances.SyncInstances()
- cs.synchronizer_step = steps.sync_controller_slices.SyncControllerSlices()
+ cohort = [cs, o]
+ o.synchronizer_step = steps.sync_instances.SyncInstances()
+ cs.synchronizer_step = steps.sync_controller_slices.SyncControllerSlices()
- self.synchronizer.sync_cohort(cohort, False)
+ self.synchronizer.sync_cohort(cohort, False)
- a = get_ansible_output()
- self.assertDictContainsSubset({'delete':False, 'name':o.name}, a)
- o.save.assert_called_with(update_fields=['enacted', 'backend_status', 'backend_register', 'backend_code'])
- cs.save.assert_called_with(update_fields=['enacted', 'backend_status', 'backend_register', 'backend_code'])
+ a = get_ansible_output()
+ self.assertDictContainsSubset({'delete':False, 'name':o.name}, a)
+ o.save.assert_called_with(update_fields=['enacted', 'backend_status', 'backend_register'])
+ cs.save.assert_called_with(update_fields=['enacted', 'backend_status', 'backend_register'])
@mock.patch("steps.sync_instances.syncstep.run_template",side_effect=run_fake_ansible_template)
@mock.patch("event_loop.model_accessor")
def test_deferred_exception(self, mock_run_template, mock_modelaccessor):
- cs = ControllerSlice()
- s = Slice(name = 'SP SP')
- cs.slice = s
- cs.force_defer = True
+ with mock.patch.object(Instance, "save") as instance_save:
+ cs = ControllerSlice()
+ s = Slice(name = 'SP SP')
+ cs.slice = s
+ cs.force_defer = True
- o = Instance()
- o.name = "Sisi Pascal"
- o.slice = s
+ o = Instance()
+ o.name = "Sisi Pascal"
+ o.slice = s
- cohort = [cs, o]
- o.synchronizer_step = steps.sync_instances.SyncInstances()
- cs.synchronizer_step = steps.sync_controller_slices.SyncControllerSlices()
+ cohort = [cs, o]
+ o.synchronizer_step = steps.sync_instances.SyncInstances()
+ cs.synchronizer_step = steps.sync_controller_slices.SyncControllerSlices()
- self.synchronizer.sync_cohort(cohort, False)
- o.save.assert_called_with(always_update_timestamp=True, update_fields=['backend_status', 'backend_code', 'backend_register'])
- self.assertEqual(cs.backend_code, 1)
+ self.synchronizer.sync_cohort(cohort, False)
+ o.save.assert_called_with(always_update_timestamp=True, update_fields=['backend_status', 'backend_register'])
+ self.assertEqual(cs.backend_code, 0)
- self.assertIn('Force', cs.backend_status)
- self.assertIn('Failed due to', o.backend_status)
+ self.assertIn('Force', cs.backend_status)
+ self.assertIn('Failed due to', o.backend_status)
@mock.patch("steps.sync_instances.syncstep.run_template",side_effect=run_fake_ansible_template)
@mock.patch("event_loop.model_accessor")
def test_backend_status(self, mock_run_template, mock_modelaccessor):
- cs = ControllerSlice()
- s = Slice(name = 'SP SP')
- cs.slice = s
- cs.force_fail = True
+ with mock.patch.object(Instance, "save") as instance_save:
+ cs = ControllerSlice()
+ s = Slice(name = 'SP SP')
+ cs.slice = s
+ cs.force_fail = True
- o = Instance()
- o.name = "Sisi Pascal"
- o.slice = s
+ o = Instance()
+ o.name = "Sisi Pascal"
+ o.slice = s
- cohort = [cs, o]
- o.synchronizer_step = steps.sync_instances.SyncInstances()
- cs.synchronizer_step = steps.sync_controller_slices.SyncControllerSlices()
+ cohort = [cs, o]
+ o.synchronizer_step = steps.sync_instances.SyncInstances()
+ cs.synchronizer_step = steps.sync_controller_slices.SyncControllerSlices()
- self.synchronizer.sync_cohort(cohort, False)
- o.save.assert_called_with(always_update_timestamp=True, update_fields=['backend_status', 'backend_code', 'backend_register'])
- self.assertIn('Force', cs.backend_status)
- self.assertIn('Failed due to', o.backend_status)
+ self.synchronizer.sync_cohort(cohort, False)
+ o.save.assert_called_with(always_update_timestamp=True, update_fields=['backend_status', 'backend_register'])
+ self.assertIn('Force', cs.backend_status)
+ self.assertIn('Failed due to', o.backend_status)
@mock.patch("steps.sync_instances.syncstep.run_template",side_effect=run_fake_ansible_template)
@mock.patch("event_loop.model_accessor")
diff --git a/xos/synchronizers/new_base/tests/test_run.py b/xos/synchronizers/new_base/tests/test_run.py
index 72167ec..c4ca3af 100644
--- a/xos/synchronizers/new_base/tests/test_run.py
+++ b/xos/synchronizers/new_base/tests/test_run.py
@@ -13,8 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# TEST_FRAMEWORK: IGNORE
-
import unittest
from mock import patch
import mock
@@ -58,6 +56,11 @@
reload(event_loop)
import backend
reload(backend)
+ from modelaccessor import model_accessor
+
+ # import all class names to globals
+ for (k, v) in model_accessor.all_model_classes.items():
+ globals()[k] = v
b = backend.Backend()
steps_dir = Config.get("steps_dir")
diff --git a/xos/synchronizers/new_base/tests/test_services.py b/xos/synchronizers/new_base/tests/test_services.py
index 4e46f38..fcfed20 100644
--- a/xos/synchronizers/new_base/tests/test_services.py
+++ b/xos/synchronizers/new_base/tests/test_services.py
@@ -13,8 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# TEST_FRAMEWORK: IGNORE
-
import unittest
from mock import patch
import mock
@@ -64,8 +62,8 @@
os.chdir(self.cwd_save)
def test_service_models(self):
- a = ONOSApp()
- s = ONOSService()
+ s = Service()
+ a = ServiceInstance(owner=s)
cohorts = self.synchronizer.compute_dependent_cohorts([a,s], False)
self.assertIn([s,a], cohorts)