SEBA-450 Update Kubernetes-service to use synchronizer library
Change-Id: Ica41cccd36c23601756989e7f9fc77a71dee4266
diff --git a/Dockerfile.synchronizer b/Dockerfile.synchronizer
index 6e0a773..b70169e 100644
--- a/Dockerfile.synchronizer
+++ b/Dockerfile.synchronizer
@@ -15,7 +15,7 @@
# docker build -t xosproject/kubernetes-synchronizer:candidate -f Dockerfile.synchronizer .
# xosproject/kubernetes-synchronizer
-FROM xosproject/xos-synchronizer-base:2.1.32
+FROM xosproject/xos-synchronizer-base:2.1.38
COPY xos/synchronizer /opt/xos/synchronizers/kubernetes
COPY VERSION /opt/xos/synchronizers/kubernetes/
diff --git a/VERSION b/VERSION
index 0664a8f..2bf1ca5 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.1.6
+1.1.7
diff --git a/xos/synchronizer/kubernetes-synchronizer.py b/xos/synchronizer/kubernetes-synchronizer.py
index 563f499..70866bf 100755
--- a/xos/synchronizer/kubernetes-synchronizer.py
+++ b/xos/synchronizer/kubernetes-synchronizer.py
@@ -27,6 +27,7 @@
import logging
import os
import sys
+from xossynchronizer import Synchronizer
from xosconfig import Config
base_config_file = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/config.yaml')
@@ -45,9 +46,4 @@
# init kafka producer connection
XOSKafkaProducer.init()
-synchronizer_path = os.path.join(os.path.dirname(
- os.path.realpath(__file__)), "../../synchronizers/new_base")
-sys.path.append(synchronizer_path)
-mod = importlib.import_module("xos-synchronizer")
-mod.main()
-
+Synchronizer().run()
diff --git a/xos/synchronizer/pull_steps/pull_pods.py b/xos/synchronizer/pull_steps/pull_pods.py
index 36562b3..961fdb8 100644
--- a/xos/synchronizer/pull_steps/pull_pods.py
+++ b/xos/synchronizer/pull_steps/pull_pods.py
@@ -20,8 +20,8 @@
import json
-from synchronizers.new_base.pullstep import PullStep
-from synchronizers.new_base.modelaccessor import KubernetesServiceInstance, KubernetesService, Slice, Principal, \
+from xossynchronizer.pull_steps.pullstep import PullStep
+from xossynchronizer.modelaccessor import KubernetesServiceInstance, KubernetesService, Slice, Principal, \
TrustDomain, Site, Image
from xosconfig import Config
diff --git a/xos/synchronizer/steps/sync_configmap.py b/xos/synchronizer/steps/sync_configmap.py
index 7cf373b..a9a7930 100644
--- a/xos/synchronizer/steps/sync_configmap.py
+++ b/xos/synchronizer/steps/sync_configmap.py
@@ -20,8 +20,8 @@
"""
import json
-from synchronizers.new_base.syncstep import SyncStep
-from synchronizers.new_base.modelaccessor import KubernetesConfigMap
+from xossynchronizer.steps.syncstep import SyncStep
+from xossynchronizer.modelaccessor import KubernetesConfigMap
from xosconfig import Config
from multistructlog import create_logger
diff --git a/xos/synchronizer/steps/sync_kubernetesresourceinstance.py b/xos/synchronizer/steps/sync_kubernetesresourceinstance.py
index 60174bb..a7ebf11 100644
--- a/xos/synchronizer/steps/sync_kubernetesresourceinstance.py
+++ b/xos/synchronizer/steps/sync_kubernetesresourceinstance.py
@@ -24,8 +24,8 @@
import os
import subprocess
import tempfile
-from synchronizers.new_base.syncstep import SyncStep
-from synchronizers.new_base.modelaccessor import KubernetesResourceInstance
+from xossynchronizer.steps.syncstep import SyncStep
+from xossynchronizer.modelaccessor import KubernetesResourceInstance
from xosconfig import Config
from multistructlog import create_logger
diff --git a/xos/synchronizer/steps/sync_kubernetesserviceinstance.py b/xos/synchronizer/steps/sync_kubernetesserviceinstance.py
index 21657b6..28809bb 100644
--- a/xos/synchronizer/steps/sync_kubernetesserviceinstance.py
+++ b/xos/synchronizer/steps/sync_kubernetesserviceinstance.py
@@ -23,8 +23,8 @@
container and uses one image.
"""
-from synchronizers.new_base.syncstep import SyncStep
-from synchronizers.new_base.modelaccessor import KubernetesServiceInstance
+from xossynchronizer.steps.syncstep import SyncStep
+from xossynchronizer.modelaccessor import KubernetesServiceInstance
from xosconfig import Config
from multistructlog import create_logger
diff --git a/xos/synchronizer/steps/sync_principal.py b/xos/synchronizer/steps/sync_principal.py
index ff38f4f..c238293 100644
--- a/xos/synchronizer/steps/sync_principal.py
+++ b/xos/synchronizer/steps/sync_principal.py
@@ -19,8 +19,8 @@
Synchronize Principals. Principals correspond roughly to Kubernetes ServiceAccounts.
"""
-from synchronizers.new_base.syncstep import SyncStep
-from synchronizers.new_base.modelaccessor import Principal
+from xossynchronizer.steps.syncstep import SyncStep
+from xossynchronizer.modelaccessor import Principal
from xosconfig import Config
from multistructlog import create_logger
diff --git a/xos/synchronizer/steps/sync_secret.py b/xos/synchronizer/steps/sync_secret.py
index 573a571..1300d26 100644
--- a/xos/synchronizer/steps/sync_secret.py
+++ b/xos/synchronizer/steps/sync_secret.py
@@ -20,8 +20,8 @@
"""
import json
-from synchronizers.new_base.syncstep import SyncStep
-from synchronizers.new_base.modelaccessor import KubernetesSecret
+from xossynchronizer.steps.syncstep import SyncStep
+from xossynchronizer.modelaccessor import KubernetesSecret
from xosconfig import Config
from multistructlog import create_logger
diff --git a/xos/synchronizer/steps/sync_service.py b/xos/synchronizer/steps/sync_service.py
index 230a0f4..9c483b1 100644
--- a/xos/synchronizer/steps/sync_service.py
+++ b/xos/synchronizer/steps/sync_service.py
@@ -20,8 +20,8 @@
NodePort to expose ports.
"""
-from synchronizers.new_base.syncstep import SyncStep
-from synchronizers.new_base.modelaccessor import Service
+from xossynchronizer.steps.syncstep import SyncStep
+from xossynchronizer.modelaccessor import Service
from xosconfig import Config
from multistructlog import create_logger
diff --git a/xos/synchronizer/steps/sync_trustdomain.py b/xos/synchronizer/steps/sync_trustdomain.py
index 5a326fa..fa812b4 100644
--- a/xos/synchronizer/steps/sync_trustdomain.py
+++ b/xos/synchronizer/steps/sync_trustdomain.py
@@ -19,8 +19,8 @@
Synchronize TrustDomain. TrustDomains correspond roughly to Kubernetes namespaces.
"""
-from synchronizers.new_base.syncstep import SyncStep
-from synchronizers.new_base.modelaccessor import TrustDomain
+from xossynchronizer.steps.syncstep import SyncStep
+from xossynchronizer.modelaccessor import TrustDomain
from xosconfig import Config
from multistructlog import create_logger
diff --git a/xos/synchronizer/tests/test_pull_pods.py b/xos/synchronizer/tests/test_pull_pods.py
index ff5c8f3..588e979 100644
--- a/xos/synchronizer/tests/test_pull_pods.py
+++ b/xos/synchronizer/tests/test_pull_pods.py
@@ -29,7 +29,7 @@
def setUp(self):
self.unittest_setup = setup_sync_unit_test(os.path.abspath(os.path.dirname(os.path.realpath(__file__))),
globals(),
- [("kubernetes-service", "kubernetes.proto")] )
+ [("kubernetes-service", "kubernetes.xproto")] )
self.mockxoskafka = MagicMock()
modules = {
diff --git a/xos/synchronizer/tests/test_sync_configmap.py b/xos/synchronizer/tests/test_sync_configmap.py
index efc1111..bdc98f9 100644
--- a/xos/synchronizer/tests/test_sync_configmap.py
+++ b/xos/synchronizer/tests/test_sync_configmap.py
@@ -35,7 +35,9 @@
def setUp(self):
self.unittest_setup = setup_sync_unit_test(os.path.abspath(os.path.dirname(os.path.realpath(__file__))),
globals(),
- [("kubernetes-service", "kubernetes.proto")] )
+ [("kubernetes-service", "kubernetes.xproto")] )
+
+ self.model_accessor = self.unittest_setup["model_accessor"]
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(os.path.realpath(__file__))), "../steps"))
@@ -52,7 +54,7 @@
with patch.object(self.step_class, "init_kubernetes_client", new=fake_init_kubernetes_client):
configmap = KubernetesConfigMap(trust_domain=self.trust_domain, name="test-configmap")
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
map = MagicMock()
step.v1core.read_namespaced_config_map.return_value = map
@@ -65,7 +67,7 @@
with patch.object(self.step_class, "init_kubernetes_client", new=fake_init_kubernetes_client):
configmap = KubernetesConfigMap(trust_domain=self.trust_domain, name="test-configmap")
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
map = MagicMock()
step.v1core.read_namespaced_config_map.side_effect = step.ApiException(status=404)
@@ -78,7 +80,7 @@
data = {"foo": "bar"}
configmap = KubernetesConfigMap(trust_domain=self.trust_domain, name="test-configmap", data=json.dumps(data))
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
step.v1core.read_namespaced_config_map.side_effect = step.ApiException(status=404)
map = MagicMock()
@@ -99,7 +101,7 @@
orig_map.data = {"foo": "not_bar"}
orig_map.metadata.self_link = "1234"
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
step.v1core.read_namespaced_config_map.return_value = orig_map
new_map = MagicMock()
@@ -127,7 +129,7 @@
orig_map.data = {"foo": "not_bar"}
orig_map.metadata.self_link = "1234"
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
step.v1core.read_namespaced_config_map.return_value = orig_map
step.delete_record(configmap)
diff --git a/xos/synchronizer/tests/test_sync_kubernetesresourceinstance.py b/xos/synchronizer/tests/test_sync_kubernetesresourceinstance.py
index 82d957e..25b8ae5 100644
--- a/xos/synchronizer/tests/test_sync_kubernetesresourceinstance.py
+++ b/xos/synchronizer/tests/test_sync_kubernetesresourceinstance.py
@@ -35,9 +35,10 @@
def setUp(self):
self.unittest_setup = setup_sync_unit_test(os.path.abspath(os.path.dirname(os.path.realpath(__file__))),
globals(),
- [("kubernetes-service", "kubernetes.proto")] )
+ [("kubernetes-service", "kubernetes.xproto")] )
self.MockObjectList = self.unittest_setup["MockObjectList"]
+ self.model_accessor = self.unittest_setup["model_accessor"]
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(os.path.realpath(__file__))), "../steps"))
@@ -57,7 +58,7 @@
mock_popen.return_value = proc
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
step.run_kubectl("create", "foo")
mock_popen.assert_called()
@@ -70,7 +71,7 @@
mock_popen.return_value = proc
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
with self.assertRaises(Exception) as e:
step.run_kubectl("create", "foo")
@@ -82,7 +83,7 @@
run_kubectl.return_value = None
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
step.sync_record(xos_ri)
run_kubectl.assert_called_with("apply", "foo")
@@ -95,7 +96,7 @@
run_kubectl.return_value = None
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
step.sync_record(xos_ri)
run_kubectl.assert_called_with("apply", "foo")
@@ -108,7 +109,7 @@
run_kubectl.return_value = None
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
step.delete_record(xos_ri)
run_kubectl.assert_called_with("delete", "foo")
@@ -122,7 +123,7 @@
run_kubectl.return_value = None
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
step.delete_record(xos_ri)
run_kubectl.assert_not_called()
diff --git a/xos/synchronizer/tests/test_sync_kubernetesserviceinstance.py b/xos/synchronizer/tests/test_sync_kubernetesserviceinstance.py
index 2a20868..3badbf4 100644
--- a/xos/synchronizer/tests/test_sync_kubernetesserviceinstance.py
+++ b/xos/synchronizer/tests/test_sync_kubernetesserviceinstance.py
@@ -35,9 +35,10 @@
def setUp(self):
self.unittest_setup = setup_sync_unit_test(os.path.abspath(os.path.dirname(os.path.realpath(__file__))),
globals(),
- [("kubernetes-service", "kubernetes.proto")] )
+ [("kubernetes-service", "kubernetes.xproto")] )
self.MockObjectList = self.unittest_setup["MockObjectList"]
+ self.model_accessor = self.unittest_setup["model_accessor"]
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(os.path.realpath(__file__))), "../steps"))
@@ -57,7 +58,7 @@
with patch.object(self.step_class, "init_kubernetes_client", new=fake_init_kubernetes_client):
xos_si = KubernetesServiceInstance(name="test-instance", slice=self.slice)
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
pod = MagicMock()
step.v1core.read_namespaced_pod.return_value = pod
@@ -70,7 +71,7 @@
with patch.object(self.step_class, "init_kubernetes_client", new=fake_init_kubernetes_client):
xos_si = KubernetesServiceInstance(name="test-instance", slice=self.slice)
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
step.v1core.read_namespaced_pod.side_effect = step.ApiException(status=404)
result = step.get_pod(xos_si)
@@ -83,7 +84,7 @@
xos_si.kubernetes_config_volume_mounts = self.MockObjectList([])
xos_si.kubernetes_secret_volume_mounts = self.MockObjectList([])
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
step.v1core.read_namespaced_pod.side_effect = step.ApiException(status=404)
pod = MagicMock()
@@ -101,7 +102,7 @@
xos_si.kubernetes_config_volume_mounts = self.MockObjectList([])
xos_si.kubernetes_secret_volume_mounts = self.MockObjectList([])
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
pod = MagicMock()
step.v1core.read_namespaced_pod.return_value = pod
diff --git a/xos/synchronizer/tests/test_sync_principal.py b/xos/synchronizer/tests/test_sync_principal.py
index 3a55eb4..c9dc0b2 100644
--- a/xos/synchronizer/tests/test_sync_principal.py
+++ b/xos/synchronizer/tests/test_sync_principal.py
@@ -35,7 +35,9 @@
def setUp(self):
self.unittest_setup = setup_sync_unit_test(os.path.abspath(os.path.dirname(os.path.realpath(__file__))),
globals(),
- [("kubernetes-service", "kubernetes.proto")] )
+ [("kubernetes-service", "kubernetes.xproto")] )
+
+ self.model_accessor = self.unittest_setup["model_accessor"]
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(os.path.realpath(__file__))), "../steps"))
@@ -52,7 +54,7 @@
with patch.object(self.step_class, "init_kubernetes_client", new=fake_init_kubernetes_client):
xos_principal = Principal(name="test-principal", trust_domain=self.trust_domain)
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
sa = MagicMock()
step.v1core.read_namespaced_service_account.return_value = sa
@@ -65,7 +67,7 @@
with patch.object(self.step_class, "init_kubernetes_client", new=fake_init_kubernetes_client):
xos_principal = Principal(name="test-principal", trust_domain=self.trust_domain)
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
step.v1core.read_namespaced_service_account.side_effect = step.ApiException(status=404)
result = step.get_service_account(xos_principal)
@@ -76,7 +78,7 @@
with patch.object(self.step_class, "init_kubernetes_client", new=fake_init_kubernetes_client):
xos_principal = Principal(name="test-principal", trust_domain=self.trust_domain)
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
step.v1core.read_namespaced_service_account.side_effect = step.ApiException(status=404)
sa = MagicMock()
@@ -92,7 +94,7 @@
with patch.object(self.step_class, "init_kubernetes_client", new=fake_init_kubernetes_client):
xos_principal = Principal(name="test-principal", trust_domain=self.trust_domain)
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
k8s_sa = MagicMock()
step.v1core.read_namespaced_service_account.return_value = k8s_sa
diff --git a/xos/synchronizer/tests/test_sync_secret.py b/xos/synchronizer/tests/test_sync_secret.py
index 632adf6..0010726 100644
--- a/xos/synchronizer/tests/test_sync_secret.py
+++ b/xos/synchronizer/tests/test_sync_secret.py
@@ -35,7 +35,9 @@
def setUp(self):
self.unittest_setup = setup_sync_unit_test(os.path.abspath(os.path.dirname(os.path.realpath(__file__))),
globals(),
- [("kubernetes-service", "kubernetes.proto")] )
+ [("kubernetes-service", "kubernetes.xproto")] )
+
+ self.model_accessor = self.unittest_setup["model_accessor"]
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(os.path.realpath(__file__))), "../steps"))
@@ -52,7 +54,7 @@
with patch.object(self.step_class, "init_kubernetes_client", new=fake_init_kubernetes_client):
xos_secret = KubernetesSecret(trust_domain=self.trust_domain, name="test-secret")
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
secret = MagicMock()
step.v1core.read_namespaced_secret.return_value = secret
@@ -65,7 +67,7 @@
with patch.object(self.step_class, "init_kubernetes_client", new=fake_init_kubernetes_client):
xos_secret = KubernetesSecret(trust_domain=self.trust_domain, name="test-secret")
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
secret = MagicMock()
step.v1core.read_namespaced_secret.side_effect = step.ApiException(status=404)
@@ -78,7 +80,7 @@
data = {"foo": "bar"}
xos_secret = KubernetesSecret(trust_domain=self.trust_domain, name="test-secret", data=json.dumps(data))
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
step.v1core.read_namespaced_secret.side_effect = step.ApiException(status=404)
secret = MagicMock()
@@ -99,7 +101,7 @@
orig_secret.data = {"foo": "not_bar"}
orig_secret.metadata.self_link = "1234"
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
step.v1core.read_namespaced_secret.return_value = orig_secret
new_secret = MagicMock()
@@ -127,7 +129,7 @@
orig_secret.data = {"foo": "not_bar"}
orig_secret.metadata.self_link = "1234"
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
step.v1core.read_namespaced_secret.return_value = orig_secret
step.delete_record(xos_secret)
diff --git a/xos/synchronizer/tests/test_sync_service.py b/xos/synchronizer/tests/test_sync_service.py
index 3030193..45b0bb6 100644
--- a/xos/synchronizer/tests/test_sync_service.py
+++ b/xos/synchronizer/tests/test_sync_service.py
@@ -35,7 +35,9 @@
def setUp(self):
self.unittest_setup = setup_sync_unit_test(os.path.abspath(os.path.dirname(os.path.realpath(__file__))),
globals(),
- [("kubernetes-service", "kubernetes.proto")] )
+ [("kubernetes-service", "kubernetes.xproto")] )
+
+ self.model_accessor = self.unittest_setup["model_accessor"]
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(os.path.realpath(__file__))), "../steps"))
@@ -56,7 +58,7 @@
xos_slice = Slice(service=xos_service, trust_domain=self.trust_domain)
xos_service.slices = self.MockObjectList([xos_slice])
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
service = MagicMock()
step.v1core.read_namespaced_service.return_value = service
@@ -71,7 +73,7 @@
xos_slice = Slice(service=xos_service, trust_domain=self.trust_domain)
xos_service.slices = self.MockObjectList([xos_slice])
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
step.v1core.read_namespaced_service.side_effect = step.ApiException(status=404)
result = step.get_service(xos_service, self.trust_domain.name)
@@ -88,7 +90,7 @@
protocol="TCP")
xos_service.serviceports=self.MockObjectList([xos_serviceport])
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
step.v1core.read_namespaced_service.side_effect = step.ApiException(status=404)
service = MagicMock()
@@ -110,7 +112,7 @@
protocol="TCP")
xos_service.serviceports=self.MockObjectList([xos_serviceport])
- step = self.step_class()
+ step = self.step_class(model_accessor = self.model_accessor)
k8s_service = MagicMock()
step.v1core.read_namespaced_service.return_value = k8s_service
step.v1core.delete_namespaced_service.return_value = None
diff --git a/xos/synchronizer/tests/test_sync_trustdomain.py b/xos/synchronizer/tests/test_sync_trustdomain.py
index 4b12b9a..9b3f64f 100644
--- a/xos/synchronizer/tests/test_sync_trustdomain.py
+++ b/xos/synchronizer/tests/test_sync_trustdomain.py
@@ -35,7 +35,9 @@
def setUp(self):
self.unittest_setup = setup_sync_unit_test(os.path.abspath(os.path.dirname(os.path.realpath(__file__))),
globals(),
- [("kubernetes-service", "kubernetes.proto")] )
+ [("kubernetes-service", "kubernetes.xproto")] )
+
+ self.model_accessor = self.unittest_setup["model_accessor"]
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(os.path.realpath(__file__))), "../steps"))
@@ -51,7 +53,7 @@
with patch.object(self.step_class, "init_kubernetes_client", new=fake_init_kubernetes_client):
xos_trustdomain = TrustDomain(name="test-trust")
- step = self.step_class()
+ step = self.step_class(model_accessor=self.model_accessor)
td = MagicMock()
step.v1core.read_namespace.return_value = td
@@ -64,7 +66,7 @@
with patch.object(self.step_class, "init_kubernetes_client", new=fake_init_kubernetes_client):
xos_trustdomain = TrustDomain(name="test-trust")
- step = self.step_class()
+ step = self.step_class(model_accessor=self.model_accessor)
step.v1core.read_namespace.side_effect = step.ApiException(status=404)
result = step.get_namespace(xos_trustdomain)
@@ -75,7 +77,7 @@
with patch.object(self.step_class, "init_kubernetes_client", new=fake_init_kubernetes_client):
xos_trustdomain = TrustDomain(name="test-trust")
- step = self.step_class()
+ step = self.step_class(model_accessor=self.model_accessor)
step.v1core.read_namespace.side_effect = step.ApiException(status=404)
td = MagicMock()
@@ -91,7 +93,7 @@
with patch.object(self.step_class, "init_kubernetes_client", new=fake_init_kubernetes_client):
xos_trustdomain = TrustDomain(name="test-trust")
- step = self.step_class()
+ step = self.step_class(model_accessor=self.model_accessor)
td = MagicMock()
step.v1core.read_namespace.return_value = td
diff --git a/xos/synchronizer/tests/unit_test_common.py b/xos/synchronizer/tests/unit_test_common.py
index 7ba2287..c2cdde8 100644
--- a/xos/synchronizer/tests/unit_test_common.py
+++ b/xos/synchronizer/tests/unit_test_common.py
@@ -18,15 +18,14 @@
def setup_sync_unit_test(test_path, globals_dict, models, config_fn="test_config.yaml"):
""" Perform the common steps associated with setting up a synchronizer unit test.
- 1) Add synchronizers/new_base to sys.path
- 2) Import xosconfig.Config and set it up to test_config.yaml in the current dir
- 3) Build the mock modelaccessor and import it
- 4) Import all model accessor classes into global space
+ 1) Import xosconfig.Config and set it up to test_config.yaml in the current dir
+ 2) Build the mock modelaccessor and import it
+ 3) Import all model accessor classes into global space
Arguments:
test_path - path to the test case that is being run
globals_dict - a dictionary to add global models to
- models - a list of pairs (service_name, xproto_name,
+ models - a list of pairs (service_name, xproto_name)
config_fn - filename of config file)
Returns:
@@ -37,39 +36,23 @@
xos_dir: xos directory
services_dir: services directory
"""
- def get_models_fn(services_dir, service_name, xproto_name):
- name = os.path.join(service_name, "xos", xproto_name)
- if os.path.exists(os.path.join(services_dir, name)):
- return name
- else:
- name = os.path.join(service_name, "xos", "synchronizer", "models", xproto_name)
- if os.path.exists(os.path.join(services_dir, name)):
- return name
- raise Exception("Unable to find service=%s xproto=%s" % (service_name, xproto_name))
-
sys_path_save = sys.path
- xos_dir = os.path.join(test_path, "../../..")
- if not os.path.exists(os.path.join(test_path, "new_base")):
- xos_dir = os.path.join(test_path, "../../../../../../orchestration/xos/xos")
- services_dir = os.path.join(xos_dir, "../../xos_services")
- sys.path.append(xos_dir)
- sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base'))
-
# Setting up the config module
from xosconfig import Config
config = os.path.join(test_path, config_fn)
Config.clear()
Config.init(config, "synchronizer-config-schema.yaml")
- xprotos = []
- for (service_name, xproto_name) in models:
- xprotos.append(get_models_fn(services_dir, "kubernetes-service", "kubernetes.xproto"))
+ from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config
+ mock_modelaccessor_config(test_path, models)
- from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor
- build_mock_modelaccessor(xos_dir, services_dir, xprotos)
- import synchronizers.new_base.modelaccessor
- from synchronizers.new_base.modelaccessor import model_accessor
+ import xossynchronizer.modelaccessor
+ reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous testp
+
+ from xossynchronizer.modelaccessor import model_accessor
+
+ # modelaccessor.py will have ensure mock_modelaccessor is in sys.path
from mock_modelaccessor import MockObjectList
# import all class names to globals
@@ -79,6 +62,4 @@
return {"sys_path_save": sys_path_save,
"model_accessor": model_accessor,
"Config": Config,
- "xos_dir": xos_dir,
- "services_dir": services_dir,
"MockObjectList": MockObjectList}