SEBA-497 delayering, Makefile, and tox for fabric-synchronizer
Change-Id: I916f4b632019dddceae5a6f024a0b1c64d8188d8
diff --git a/xos/synchronizer/model_policies/__init__.py b/xos/synchronizer/model_policies/__init__.py
new file mode 100644
index 0000000..19d1424
--- /dev/null
+++ b/xos/synchronizer/model_policies/__init__.py
@@ -0,0 +1,13 @@
+# Copyright 2019-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/synchronizer/model_policies/model_policy_compute_nodes.py b/xos/synchronizer/model_policies/model_policy_compute_nodes.py
index a253a12..14044af 100644
--- a/xos/synchronizer/model_policies/model_policy_compute_nodes.py
+++ b/xos/synchronizer/model_policies/model_policy_compute_nodes.py
@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import absolute_import
+
import ipaddress
import random
from xossynchronizer.modelaccessor import NodeToSwitchPort, PortInterface, model_accessor
@@ -21,10 +23,9 @@
from xosconfig import Config
from multistructlog import create_logger
-from helpers import Helpers
-
log = create_logger(Config().get('logging'))
+
class ComputeNodePolicy(Policy):
model_name = "NodeToSwitchPort"
@@ -42,7 +43,7 @@
@staticmethod
def generateVlan(used_vlans):
- availabel_tags = range(16, 4093)
+ availabel_tags = list(range(16, 4093))
valid_tags = list(set(availabel_tags) - set(used_vlans))
if len(valid_tags) == 0:
raise Exception("No VLANs left")
@@ -65,7 +66,12 @@
return self.handle_update(node_to_port)
def handle_update(self, node_to_port):
- log.info("MODEL_POLICY: NodeToSwitchPort %s handle update" % node_to_port.id, node=node_to_port.node, port=node_to_port.port, switch=node_to_port.port.switch)
+ log.info(
+ "MODEL_POLICY: NodeToSwitchPort %s handle update" %
+ node_to_port.id,
+ node=node_to_port.node,
+ port=node_to_port.port,
+ switch=node_to_port.port.switch)
compute_node = node_to_port.node
@@ -92,9 +98,8 @@
)
interface.save()
-
- # TODO if the model is updated I need to remove the old interface, how?
+ # TODO if the model is updated I need to remove the old interface, how?
def handle_delete(self, node_to_port):
pass
diff --git a/xos/synchronizer/model_policies/test_model_policy_compute_node.py b/xos/synchronizer/model_policies/test_model_policy_compute_node.py
index 9b17d8d..4c8b41e 100644
--- a/xos/synchronizer/model_policies/test_model_policy_compute_node.py
+++ b/xos/synchronizer/model_policies/test_model_policy_compute_node.py
@@ -13,14 +13,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+#from __future__ import absolute_import
+import imp
import unittest
import ipaddress
-from mock import patch, call, Mock, PropertyMock
+from mock import patch, Mock
-import os, sys
+import os
+import sys
-test_path=os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+test_path = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+
class TestComputeNodePolicy(unittest.TestCase):
def setUp(self):
@@ -38,8 +42,8 @@
import xossynchronizer.modelaccessor
import mock_modelaccessor
- reload(mock_modelaccessor) # in case nose2 loaded it in a previous test
- reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous test
+ imp.reload(mock_modelaccessor) # in case nose2 loaded it in a previous test
+ imp.reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous test
from model_policy_compute_nodes import ComputeNodePolicy, model_accessor
@@ -51,8 +55,8 @@
for (k, v) in model_accessor.all_model_classes.items():
globals()[k] = v
- # Some of the functions we call have side-effects. For example, creating a VSGServiceInstance may lead to creation of
- # tags. Ideally, this wouldn't happen, but it does. So make sure we reset the world.
+ # Some of the functions we call have side-effects. For example, creating a VSGServiceInstance may lead to
+ # creation of tags. Ideally, this wouldn't happen, but it does. So make sure we reset the world.
model_accessor.reset_all_object_stores()
self.policy = ComputeNodePolicy
@@ -63,7 +67,7 @@
def test_getLastAddress(self):
- dataPlaneIp = unicode("10.6.1.2/24", "utf-8")
+ dataPlaneIp = u"10.6.1.2/24"
interface = ipaddress.ip_interface(dataPlaneIp)
subnet = ipaddress.ip_network(interface.network)
last_ip = self.policy.getLastAddress(subnet)
@@ -71,7 +75,7 @@
def test_generateVlan(self):
- used_vlans = range(16, 4093)
+ used_vlans = list(range(16, 4093))
used_vlans.remove(1000)
vlan = self.policy.generateVlan(used_vlans)
@@ -80,7 +84,7 @@
def test_generateVlanFail(self):
- used_vlans = range(16, 4093)
+ used_vlans = list(range(16, 4093))
with self.assertRaises(Exception) as e:
self.policy.generateVlan(used_vlans)
@@ -89,13 +93,13 @@
def test_getVlanByCidr_same_subnet(self):
- mock_pi_ip = unicode("10.6.1.2/24", "utf-8")
-
+ mock_pi_ip = u"10.6.1.2/24"
+
mock_pi = Mock()
mock_pi.vlanUntagged = 1234
mock_pi.ips = str(self.policy.getPortCidrByIp(mock_pi_ip))
- test_ip = unicode("10.6.1.1/24", "utf-8")
+ test_ip = u"10.6.1.1/24"
test_subnet = self.policy.getPortCidrByIp(test_ip)
with patch.object(PortInterface.objects, "get_items") as get_pi:
@@ -106,12 +110,12 @@
def test_getVlanByCidr_different_subnet(self):
- mock_pi_ip = unicode("10.6.1.2/24", "utf-8")
+ mock_pi_ip = u"10.6.1.2/24"
mock_pi = Mock()
mock_pi.vlanUntagged = 1234
mock_pi.ips = str(self.policy.getPortCidrByIp(mock_pi_ip))
- test_ip = unicode("192.168.1.1/24", "utf-8")
+ test_ip = u"192.168.1.1/24"
test_subnet = self.policy.getPortCidrByIp(test_ip)
with patch.object(PortInterface.objects, "get_items") as get_pi:
@@ -130,7 +134,7 @@
def test_handle_update_do_nothing(self):
- mock_pi_ip = unicode("10.6.1.2/24", "utf-8")
+ mock_pi_ip = u"10.6.1.2/24"
mock_pi = Mock()
mock_pi.port_id = 1
mock_pi.name = "test_interface"
@@ -142,8 +146,8 @@
self.model.node.dataPlaneIntf = "test_interface"
with patch.object(PortInterface.objects, "get_items") as get_pi, \
- patch.object(self.policy, "getPortCidrByIp") as get_subnet, \
- patch.object(PortInterface, 'save') as mock_save:
+ patch.object(self.policy, "getPortCidrByIp") as get_subnet, \
+ patch.object(PortInterface, 'save') as mock_save:
get_pi.return_value = [mock_pi]
get_subnet.return_value = mock_pi.ips
@@ -158,11 +162,11 @@
self.model.port.id = 1
self.model.node.dataPlaneIntf = "test_interface"
- self.model.node.dataPlaneIp = unicode("10.6.1.2/24", "utf-8")
+ self.model.node.dataPlaneIp = u"10.6.1.2/24"
with patch.object(PortInterface.objects, "get_items") as get_pi, \
- patch.object(self.policy, "getVlanByCidr") as get_vlan, \
- patch.object(PortInterface, "save", autospec=True) as mock_save:
+ patch.object(self.policy, "getVlanByCidr") as get_vlan, \
+ patch.object(PortInterface, "save", autospec=True) as mock_save:
get_pi.return_value = []
get_vlan.return_value = "1234"
@@ -181,4 +185,3 @@
if __name__ == '__main__':
sys.path.append("../steps") # so we can import helpers from steps directory
unittest.main()
-