[SEBA-176] Starting point (rename done)
Change-Id: I4df4c9d39a84252d8b431313c2e8184731eca4ec
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9cff527
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,8 @@
+.idea/
+*.pyc
+
+.coverage
+htmlcov
+coverage.xml
+nose2-junit.xml
+
diff --git a/.gitreview b/.gitreview
new file mode 100644
index 0000000..97703b1
--- /dev/null
+++ b/.gitreview
@@ -0,0 +1,5 @@
+[gerrit]
+host=gerrit.opencord.org
+port=29418
+project=att-workflow-driver.git
+defaultremote=origin
diff --git a/Dockerfile.synchronizer b/Dockerfile.synchronizer
new file mode 100644
index 0000000..5fa9a25
--- /dev/null
+++ b/Dockerfile.synchronizer
@@ -0,0 +1,57 @@
+# 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.
+
+# docker build -t xosproject/att-workflow-driver-synchronizer:candidate -f Dockerfile.synchronizer .
+
+# xosproject/att-workflow-driver-synchronizer
+
+FROM xosproject/xos-synchronizer-base:master
+
+COPY xos/synchronizer /opt/xos/synchronizers/att-workflow-driver
+COPY VERSION /opt/xos/synchronizers/att-workflow-driver/
+COPY samples/auth_event_sample.py /opt/xos/synchronizers/att-workflow-driver/
+COPY samples/auth_event_sample_fail.py /opt/xos/synchronizers/att-workflow-driver/
+
+WORKDIR "/opt/xos/synchronizers/att-workflow-driver"
+
+# Label image
+ARG org_label_schema_schema_version=1.0
+ARG org_label_schema_name=att-workflow-driver-synchronizer
+ARG org_label_schema_version=unknown
+ARG org_label_schema_vcs_url=unknown
+ARG org_label_schema_vcs_ref=unknown
+ARG org_label_schema_build_date=unknown
+ARG org_opencord_vcs_commit_date=unknown
+ARG org_opencord_component_chameleon_version=unknown
+ARG org_opencord_component_chameleon_vcs_url=unknown
+ARG org_opencord_component_chameleon_vcs_ref=unknown
+ARG org_opencord_component_xos_version=unknown
+ARG org_opencord_component_xos_vcs_url=unknown
+ARG org_opencord_component_xos_vcs_ref=unknown
+
+LABEL org.label-schema.schema-version=$org_label_schema_schema_version \
+ org.label-schema.name=$org_label_schema_name \
+ org.label-schema.version=$org_label_schema_version \
+ org.label-schema.vcs-url=$org_label_schema_vcs_url \
+ org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
+ org.label-schema.build-date=$org_label_schema_build_date \
+ org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \
+ org.opencord.component.chameleon.version=$org_opencord_component_chameleon_version \
+ org.opencord.component.chameleon.vcs-url=$org_opencord_component_chameleon_vcs_url \
+ org.opencord.component.chameleon.vcs-ref=$org_opencord_component_chameleon_vcs_ref \
+ org.opencord.component.xos.version=$org_opencord_component_xos_version \
+ org.opencord.component.xos.vcs-url=$org_opencord_component_xos_vcs_url \
+ org.opencord.component.xos.vcs-ref=$org_opencord_component_xos_vcs_ref
+
+CMD ["/usr/bin/python", "/opt/xos/synchronizers/att-workflow-driver/att-workflow-driver-synchronizer.py"]
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..d9d9d30
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright 2016 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/README.md b/README.md
new file mode 100644
index 0000000..1725dda
--- /dev/null
+++ b/README.md
@@ -0,0 +1,26 @@
+# AT&T Workflow Driver
+
+This service is intended to be an example implementation of a service that integrates XOS with an external OSS system.
+As the name suggests this service will be very welcoming and validate any ONU that is connected to the system.
+
+Peace and Love
+
+> NOTE: This service depends on RCORDSubscriber and ONUDevice so make sure that the `rcord-synchronizer` and `volt-synchronzier` are running
+
+## How to install this service
+
+Make sure you have `xos-core`, `rcord-lite` and `kafka` running.
+
+To install from master:
+
+```bash
+helm install -n att-workflow xos-services/att-workflow-driver/
+```
+
+To install from the local `docker` daemon in minikube:
+
+```bash
+helm install -n att-workflow xos-services/att-workflow-driver/ -f examples/image-tag-candidate.yaml -f examples/imagePullPolicy-IfNotPresent.yaml
+```
+
+## Configure this service
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..05639a5
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+1.0.0-dev
diff --git a/docs/README.md b/docs/README.md
new file mode 100644
index 0000000..1725dda
--- /dev/null
+++ b/docs/README.md
@@ -0,0 +1,26 @@
+# AT&T Workflow Driver
+
+This service is intended to be an example implementation of a service that integrates XOS with an external OSS system.
+As the name suggests this service will be very welcoming and validate any ONU that is connected to the system.
+
+Peace and Love
+
+> NOTE: This service depends on RCORDSubscriber and ONUDevice so make sure that the `rcord-synchronizer` and `volt-synchronzier` are running
+
+## How to install this service
+
+Make sure you have `xos-core`, `rcord-lite` and `kafka` running.
+
+To install from master:
+
+```bash
+helm install -n att-workflow xos-services/att-workflow-driver/
+```
+
+To install from the local `docker` daemon in minikube:
+
+```bash
+helm install -n att-workflow xos-services/att-workflow-driver/ -f examples/image-tag-candidate.yaml -f examples/imagePullPolicy-IfNotPresent.yaml
+```
+
+## Configure this service
diff --git a/samples/auth_event_sample.py b/samples/auth_event_sample.py
new file mode 100644
index 0000000..a43090e
--- /dev/null
+++ b/samples/auth_event_sample.py
@@ -0,0 +1,29 @@
+
+# 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.
+
+# Manually send the event
+
+import json
+from kafka import KafkaProducer
+
+event = json.dumps({
+ 'authentication_state': "APPROVED", #there will be a bunch of possible states here, actual values TBD, e.g. STARTED, REQUESTED, APPROVED, DENIED
+ 'device_id': "of:0000000ce2314000",
+ 'port_number': "101",
+ # possibly other fields that we get from RADIUS/EAPOL relating to the subscriber
+})
+producer = KafkaProducer(bootstrap_servers="cord-kafka")
+producer.send("authentication.events", event)
+producer.flush()
\ No newline at end of file
diff --git a/samples/auth_event_sample_fail.py b/samples/auth_event_sample_fail.py
new file mode 100644
index 0000000..9095101
--- /dev/null
+++ b/samples/auth_event_sample_fail.py
@@ -0,0 +1,29 @@
+
+# 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.
+
+# Manually send the event
+
+import json
+from kafka import KafkaProducer
+
+event = json.dumps({
+ 'authentication_state': "DENIED", #there will be a bunch of possible states here, actual values TBD, e.g. STARTED, REQUESTED, APPROVED, DENIED
+ 'device_id': "of:0000000ce2314000",
+ 'port_number': "101",
+ # possibly other fields that we get from RADIUS/EAPOL relating to the subscriber
+})
+producer = KafkaProducer(bootstrap_servers="cord-kafka")
+producer.send("authentication.events", event)
+producer.flush()
\ No newline at end of file
diff --git a/samples/oss-service.yaml b/samples/oss-service.yaml
new file mode 100644
index 0000000..c24b306
--- /dev/null
+++ b/samples/oss-service.yaml
@@ -0,0 +1,27 @@
+# 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.
+
+# curl -H "xos-username: admin@opencord.org" -H "xos-password: letmein" -X POST --data-binary @oss-service.yaml http://192.168.99.100:30007/run
+
+tosca_definitions_version: tosca_simple_yaml_1_0
+imports:
+ - custom_types/attworkflowservice.yaml
+description: Create an instance of the OSS Service and connect it to the vOLT Service
+topology_template:
+ node_templates:
+ service#oss:
+ type: tosca.nodes.ATTWorkflowService
+ properties:
+ name: workflow
+ kind: control
diff --git a/xos/synchronizer/att-workflow-driver-synchronizer.py b/xos/synchronizer/att-workflow-driver-synchronizer.py
new file mode 100755
index 0000000..f9ea235
--- /dev/null
+++ b/xos/synchronizer/att-workflow-driver-synchronizer.py
@@ -0,0 +1,37 @@
+
+# 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.
+
+
+#!/usr/bin/env python
+
+# This imports and runs ../../xos-observer.py
+
+import importlib
+import os
+import sys
+from xosconfig import Config
+
+base_config_file = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/config.yaml')
+mounted_config_file = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/mounted_config.yaml')
+
+if os.path.isfile(mounted_config_file):
+ Config.init(base_config_file, 'synchronizer-config-schema.yaml', mounted_config_file)
+else:
+ Config.init(base_config_file, 'synchronizer-config-schema.yaml')
+
+observer_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),"../../synchronizers/new_base")
+sys.path.append(observer_path)
+mod = importlib.import_module("xos-synchronizer")
+mod.main()
diff --git a/xos/synchronizer/config.yaml b/xos/synchronizer/config.yaml
new file mode 100644
index 0000000..90c0dbf
--- /dev/null
+++ b/xos/synchronizer/config.yaml
@@ -0,0 +1,42 @@
+
+# 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.
+
+
+name: att-workflow-driver
+required_models:
+ - AttWorkflowDriverService
+ - AttWorkflowDriverServiceInstance
+ - RCORDSubscriber
+ - ONUDevice
+model_policies_dir: "/opt/xos/synchronizers/att-workflow-driver/model_policies"
+models_dir: "/opt/xos/synchronizers/att-workflow-driver/models"
+steps_dir: "/opt/xos/synchronizers/att-workflow-driver/steps"
+event_steps_dir: "/opt/xos/synchronizers/att-workflow-driver/event_steps"
+logging:
+ version: 1
+ handlers:
+ console:
+ class: logging.StreamHandler
+ file:
+ class: logging.handlers.RotatingFileHandler
+ filename: /var/log/xos.log
+ maxBytes: 10485760
+ backupCount: 5
+ loggers:
+ 'multistructlog':
+ handlers:
+ - console
+ - file
+ level: DEBUG
diff --git a/xos/synchronizer/event_steps/auth_event.py b/xos/synchronizer/event_steps/auth_event.py
new file mode 100644
index 0000000..5713f9f
--- /dev/null
+++ b/xos/synchronizer/event_steps/auth_event.py
@@ -0,0 +1,66 @@
+
+# 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.
+
+import json
+import time
+import os
+import sys
+from synchronizers.new_base.eventstep import EventStep
+from synchronizers.new_base.modelaccessor import VOLTService, AttWorkflowDriverServiceInstance, model_accessor
+
+class SubscriberAuthEventStep(EventStep):
+ topics = ["authentication.events"]
+ technology = "kafka"
+
+ def __init__(self, *args, **kwargs):
+ super(SubscriberAuthEventStep, self).__init__(*args, **kwargs)
+
+ def get_onu_sn(self, event):
+ olt_service = VOLTService.objects.first()
+ onu_sn = olt_service.get_onu_sn_from_openflow(event["deviceId"], event["portNumber"])
+ if not onu_sn or onu_sn is None:
+ self.log.exception("authentication.events: Cannot find onu serial number for this event", kafka_event=event)
+ raise Exception("authentication.events: Cannot find onu serial number for this event")
+
+ return onu_sn
+
+ def get_hippie_oss_si_by_sn(self, serial_number):
+ try:
+ return AttWorkflowDriverServiceInstance.objects.get(serial_number=serial_number)
+ except IndexError:
+ self.log.exception("authentication.events: Cannot find hippie-oss service instance for this event", kafka_event=value)
+ raise Exception("authentication.events: Cannot find hippie-oss service instance for this event")
+
+
+ def activate_subscriber(self, subscriber):
+ subscriber.status = 'enabled'
+ subscriber.save()
+
+ def disable_subscriber(self, subscriber):
+ subscriber.status = 'auth-failed'
+ subscriber.save()
+
+ def process_event(self, event):
+ value = json.loads(event.value)
+
+ onu_sn = self.get_onu_sn(value)
+ si = self.get_hippie_oss_si_by_sn(onu_sn)
+ if not si:
+ self.log.exception("authentication.events: Cannot find hippie-oss service instance for this event", kafka_event=value)
+ raise Exception("authentication.events: Cannot find hippie-oss service instance for this event")
+
+ si.authentication_state = value["authenticationState"];
+ si.no_sync = True
+ si.save(update_fields=["authentication_state", "no_sync", "updated"], always_update_timestamp=True)
diff --git a/xos/synchronizer/event_steps/dhcp_event.py b/xos/synchronizer/event_steps/dhcp_event.py
new file mode 100644
index 0000000..2483e46
--- /dev/null
+++ b/xos/synchronizer/event_steps/dhcp_event.py
@@ -0,0 +1,50 @@
+
+# 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.
+
+import json
+import time
+import os
+import sys
+from synchronizers.new_base.eventstep import EventStep
+from synchronizers.new_base.modelaccessor import VOLTService, RCORDSubscriber, model_accessor
+
+class SubscriberDhcpEventStep(EventStep):
+ topics = ["dhcp.events"]
+ technology = "kafka"
+
+ def __init__(self, *args, **kwargs):
+ super(SubscriberDhcpEventStep, self).__init__(*args, **kwargs)
+
+ def get_onu_sn(self, event):
+ olt_service = VOLTService.objects.first()
+ onu_sn = olt_service.get_onu_sn_from_openflow(event["deviceId"], event["portNumber"])
+ if not onu_sn or onu_sn is None:
+ self.log.exception("dhcp.events: Cannot find onu serial number for this event", kafka_event=event)
+ raise Exception("dhcp.events: Cannot find onu serial number for this event")
+
+ return onu_sn
+
+ def process_event(self, event):
+ value = json.loads(event.value)
+
+ onu_sn = self.get_onu_sn(value)
+
+ subscriber = RCORDSubscriber.objects.get(onu_device=onu_sn)
+
+ self.log.debug("dhcp.events: Got event for subscriber", subscriber=subscriber, event_value=value, onu_sn=onu_sn)
+
+ subscriber.ip_address = value["ipAddress"]
+ subscriber.mac_address = value["macAddress"]
+ subscriber.save()
diff --git a/xos/synchronizer/event_steps/test_auth_event.py b/xos/synchronizer/event_steps/test_auth_event.py
new file mode 100644
index 0000000..08887dd
--- /dev/null
+++ b/xos/synchronizer/event_steps/test_auth_event.py
@@ -0,0 +1,111 @@
+# 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.
+
+import unittest
+from mock import patch, call, Mock, PropertyMock
+import json
+
+import os, sys
+
+# Hack to load synchronizer framework
+test_path=os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+service_dir=os.path.join(test_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")
+# END Hack to load synchronizer framework
+
+# generate model from xproto
+def get_models_fn(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))
+# END generate model from xproto
+
+class TestSubscriberAuthEvent(unittest.TestCase):
+
+ def setUp(self):
+
+ self.sys_path_save = sys.path
+ 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, "../test_config.yaml")
+ Config.clear()
+ Config.init(config, "synchronizer-config-schema.yaml")
+ from multistructlog import create_logger
+ log = create_logger(Config().get('logging'))
+ # END Setting up the config module
+
+ from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor
+ # build_mock_modelaccessor(xos_dir, services_dir, [get_models_fn("olt-service", "volt.xproto")])
+
+ build_mock_modelaccessor(xos_dir, services_dir, [
+ get_models_fn("att-workflow-driver", "att-workflow-driver.xproto"),
+ get_models_fn("olt-service", "volt.xproto"),
+ get_models_fn("../profiles/rcord", "rcord.xproto")
+ ])
+ import synchronizers.new_base.modelaccessor
+ from auth_event import SubscriberAuthEventStep, model_accessor
+
+ # import all class names to globals
+ for (k, v) in model_accessor.all_model_classes.items():
+ globals()[k] = v
+
+ self.log = log
+
+ self.event_step = SubscriberAuthEventStep(self.log)
+
+ self.event = Mock()
+
+ self.volt = Mock()
+ self.volt.name = "vOLT"
+ self.volt.leaf_model = Mock()
+
+ self.hippie_si = AttWorkflowDriverServiceInstance()
+ self.hippie_si.serial_number = "BRCM1234"
+ self.hippie_si.save = Mock()
+
+
+ def tearDown(self):
+ sys.path = self.sys_path_save
+
+ def test_authenticate_subscriber(self):
+
+ self.event.value = json.dumps({
+ 'authenticationState': "APPROVED",
+ 'deviceId': "of:0000000ce2314000",
+ 'portNumber': "101",
+ })
+
+ with patch.object(VOLTService.objects, "get_items") as volt_service_mock, \
+ patch.object(AttWorkflowDriverServiceInstance.objects, "get_items") as hippie_si_mock, \
+ patch.object(self.volt, "get_onu_sn_from_openflow") as get_onu_sn:
+
+ volt_service_mock.return_value = [self.volt]
+ get_onu_sn.return_value = "BRCM1234"
+ hippie_si_mock.return_value = [self.hippie_si]
+
+ self.event_step.process_event(self.event)
+
+ self.hippie_si.save.assert_called_with(always_update_timestamp=True, update_fields=['authentication_state', 'no_sync', 'updated'])
+ self.assertEqual(self.hippie_si.authentication_state, 'APPROVED')
diff --git a/xos/synchronizer/event_steps/test_dhcp_event.py b/xos/synchronizer/event_steps/test_dhcp_event.py
new file mode 100644
index 0000000..70258a9
--- /dev/null
+++ b/xos/synchronizer/event_steps/test_dhcp_event.py
@@ -0,0 +1,116 @@
+# 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.
+
+import unittest
+from mock import patch, call, Mock, PropertyMock
+import json
+
+import os, sys
+
+# Hack to load synchronizer framework
+test_path=os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+service_dir=os.path.join(test_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")
+# END Hack to load synchronizer framework
+
+# generate model from xproto
+def get_models_fn(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))
+# END generate model from xproto
+
+class TestSubscriberAuthEvent(unittest.TestCase):
+
+ def setUp(self):
+
+ self.sys_path_save = sys.path
+ 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, "../test_config.yaml")
+ Config.clear()
+ Config.init(config, "synchronizer-config-schema.yaml")
+ from multistructlog import create_logger
+ log = create_logger(Config().get('logging'))
+ # END Setting up the config module
+
+ from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor
+ # build_mock_modelaccessor(xos_dir, services_dir, [get_models_fn("olt-service", "volt.xproto")])
+
+ build_mock_modelaccessor(xos_dir, services_dir, [
+ get_models_fn("att-workflow-driver", "att-workflow-driver.xproto"),
+ get_models_fn("olt-service", "volt.xproto"),
+ get_models_fn("../profiles/rcord", "rcord.xproto")
+ ])
+ import synchronizers.new_base.modelaccessor
+ from dhcp_event import SubscriberDhcpEventStep, model_accessor
+
+ # import all class names to globals
+ for (k, v) in model_accessor.all_model_classes.items():
+ globals()[k] = v
+
+ self.log = log
+
+ self.event_step = SubscriberDhcpEventStep(self.log)
+
+ self.event = Mock()
+
+ self.volt = Mock()
+ self.volt.name = "vOLT"
+ self.volt.leaf_model = Mock()
+
+ self.subscriber = RCORDSubscriber()
+ self.subscriber.onu_device = "BRCM1234"
+ self.subscriber.save = Mock()
+
+ self.mac_address = "aa:bb:cc:dd:ee"
+ self.ip_address = "192.168.3.5"
+
+
+ def tearDown(self):
+ sys.path = self.sys_path_save
+
+ def test_dhcp_subscriber(self):
+
+ self.event.value = json.dumps({
+ "deviceId" : "of:0000000000000001",
+ "portNumber" : "1",
+ "macAddress" : self.mac_address,
+ "ipAddress" : self.ip_address
+ })
+
+ with patch.object(VOLTService.objects, "get_items") as volt_service_mock, \
+ patch.object(RCORDSubscriber.objects, "get_items") as subscriber_mock, \
+ patch.object(self.volt, "get_onu_sn_from_openflow") as get_onu_sn:
+
+ volt_service_mock.return_value = [self.volt]
+ get_onu_sn.return_value = "BRCM1234"
+ subscriber_mock.return_value = [self.subscriber]
+
+ self.event_step.process_event(self.event)
+
+ self.subscriber.save.assert_called()
+ self.assertEqual(self.subscriber.mac_address, self.mac_address)
+ self.assertEqual(self.subscriber.ip_address, self.ip_address)
diff --git a/xos/synchronizer/model_policies/model_policy_att_workflow_driver_service.py b/xos/synchronizer/model_policies/model_policy_att_workflow_driver_service.py
new file mode 100644
index 0000000..5fb076c
--- /dev/null
+++ b/xos/synchronizer/model_policies/model_policy_att_workflow_driver_service.py
@@ -0,0 +1,46 @@
+
+# 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.
+
+
+from synchronizers.new_base.modelaccessor import AttWorkflowDriverServiceInstance, model_accessor
+from synchronizers.new_base.policy import Policy
+
+class AttWorkflowDriverServicePolicy(Policy):
+ model_name = "AttWorkflowDriverService"
+
+ def handle_update(self, service):
+ self.logger.debug("MODEL_POLICY: handle_update for AttWorkflowDriverService", oss=service)
+
+ sis = AttWorkflowDriverServiceInstance.objects.all()
+
+ # TODO(smbaker): This is redudant with AttWorkflowDriverWhiteListEntry model policy, though etaining this does provide
+ # a handy way to trigger a full reexamination of the whitelist.
+
+ whitelist = [x.serial_number for x in service.whitelist_entries.all()]
+
+ for si in sis:
+ if si.serial_number in whitelist and not si.valid == "valid":
+ self.logger.debug("MODEL_POLICY: activating AttWorkflowDriverServiceInstance because of change in the whitelist", si=si)
+ si.valid = "valid"
+ si.save(update_fields=["valid", "no_sync", "updated"], always_update_timestamp=True)
+ if si.serial_number not in whitelist and not si.valid == "invalid":
+ self.logger.debug(
+ "MODEL_POLICY: disabling AttWorkflowDriverServiceInstance because of change in the whitelist", si=si)
+ si.valid = "invalid"
+ si.save(update_fields=["valid", "no_sync", "updated"], always_update_timestamp=True)
+
+
+ def handle_delete(self, si):
+ pass
diff --git a/xos/synchronizer/model_policies/model_policy_att_workflow_driver_serviceinstance.py b/xos/synchronizer/model_policies/model_policy_att_workflow_driver_serviceinstance.py
new file mode 100644
index 0000000..25d824a
--- /dev/null
+++ b/xos/synchronizer/model_policies/model_policy_att_workflow_driver_serviceinstance.py
@@ -0,0 +1,109 @@
+
+# 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.
+
+
+from synchronizers.new_base.modelaccessor import RCORDSubscriber, ONUDevice, model_accessor
+from synchronizers.new_base.policy import Policy
+
+class AttWorkflowDriverServiceInstancePolicy(Policy):
+ model_name = "AttWorkflowDriverServiceInstance"
+
+ def handle_create(self, si):
+ self.logger.debug("MODEL_POLICY: handle_create for AttWorkflowDriverServiceInstance %s " % si.id)
+ self.handle_update(si)
+
+ def update_and_save_subscriber(self, subscriber, si, update_timestamp=False):
+ if si.authentication_state == "STARTED":
+ subscriber.status = "awaiting-auth"
+ elif si.authentication_state == "REQUESTED":
+ subscriber.status = "awaiting-auth"
+ elif si.authentication_state == "APPROVED":
+ subscriber.status = "enabled"
+ elif si.authentication_state == "DENIED":
+ subscriber.status = "auth-failed"
+
+ # If the OSS returns a c_tag use that one
+ if si.c_tag:
+ subscriber.c_tag = si.c_tag
+
+ subscriber.save(always_update_timestamp=update_timestamp)
+
+ def create_subscriber(self, si):
+ subscriber = RCORDSubscriber()
+ subscriber.onu_device = si.serial_number
+ subscriber.status == "awaiting-auth"
+
+ return subscriber
+
+ def handle_update(self, si):
+ self.logger.debug("MODEL_POLICY: handle_update for AttWorkflowDriverServiceInstance %s, valid=%s " % (si.id, si.valid))
+
+ # Check to make sure the object has been synced. This is to cover a race condition where the model_policy
+ # runs, is interrupted by the sync step, the sync step completes, and then the model policy ends up saving
+ # a policed_timestamp that is later the updated timestamp set by the sync_step.
+ if (si.backend_code!=1):
+ raise Exception("MODEL_POLICY: AttWorkflowDriverServiceInstance %s has not been synced yet" % si.id)
+
+ if not hasattr(si, 'valid') or si.valid is "awaiting":
+ self.logger.debug("MODEL_POLICY: skipping handle_update for AttWorkflowDriverServiceInstance %s as not validated yet" % si.id)
+ return
+ if si.valid == "invalid":
+ self.logger.debug("MODEL_POLICY: disabling ONUDevice [%s] for AttWorkflowDriverServiceInstance %s" % (si.serial_number, si.id))
+ onu = ONUDevice.objects.get(serial_number=si.serial_number)
+ onu.admin_state = "DISABLED"
+ onu.save(always_update_timestamp=True)
+ return
+ if si.valid == "valid":
+
+ # reactivating the ONUDevice
+ try:
+ onu = ONUDevice.objects.get(serial_number=si.serial_number)
+ except IndexError:
+ raise Exception("MODEL_POLICY: cannot find ONUDevice [%s] for AttWorkflowDriverServiceInstance %s" % (si.serial_number, si.id))
+ if onu.admin_state == "DISABLED":
+ self.logger.debug("MODEL_POLICY: enabling ONUDevice [%s] for AttWorkflowDriverServiceInstance %s" % (si.serial_number, si.id))
+ onu.admin_state = "ENABLED"
+ onu.save(always_update_timestamp=True)
+
+ # handling the subscriber status
+
+ subscriber = None
+ try:
+ subscriber = RCORDSubscriber.objects.get(onu_device=si.serial_number)
+ except IndexError:
+ # we just want to find out if it exists or not
+ pass
+
+ # if subscriber does not exist
+ self.logger.debug("MODEL_POLICY: handling subscriber", onu_device=si.serial_number, create_on_discovery=si.owner.leaf_model.create_on_discovery)
+ if not subscriber:
+ # and create_on_discovery is false
+ if not si.owner.leaf_model.create_on_discovery:
+ # do not create the subscriber, unless it has been approved
+ if si.authentication_state == "APPROVED":
+ self.logger.debug("MODEL_POLICY: creating subscriber as authentication_sate=APPROVED")
+ subscriber = self.create_subscriber(si)
+ self.update_and_save_subscriber(subscriber, si)
+ else:
+ self.logger.debug("MODEL_POLICY: creating subscriber")
+ subscriber = self.create_subscriber(si)
+ self.update_and_save_subscriber(subscriber, si)
+ # if the subscriber is there and authentication is complete, update its state
+ elif subscriber and si.authentication_state == "APPROVED":
+ self.logger.debug("MODEL_POLICY: updating subscriber status")
+ self.update_and_save_subscriber(subscriber, si, update_timestamp=True)
+
+ def handle_delete(self, si):
+ pass
diff --git a/xos/synchronizer/model_policies/model_policy_att_workflow_driver_whitelistentry.py b/xos/synchronizer/model_policies/model_policy_att_workflow_driver_whitelistentry.py
new file mode 100644
index 0000000..c38e7ec
--- /dev/null
+++ b/xos/synchronizer/model_policies/model_policy_att_workflow_driver_whitelistentry.py
@@ -0,0 +1,59 @@
+
+# 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.
+
+
+from synchronizers.new_base.modelaccessor import AttWorkflowDriverServiceInstance, AttWorkflowDriverWhiteListEntry, model_accessor
+from synchronizers.new_base.policy import Policy
+
+class AttWorkflowDriverWhiteListEntryPolicy(Policy):
+ model_name = "AttWorkflowDriverWhiteListEntry"
+
+ def handle_create(self, whitelist):
+ self.handle_update(whitelist)
+
+ def handle_update(self, whitelist):
+ self.logger.debug("MODEL_POLICY: handle_update for AttWorkflowDriverWhiteListEntry", whitelist=whitelist)
+
+ sis = AttWorkflowDriverServiceInstance.objects.filter(serial_number = whitelist.serial_number,
+ owner_id = whitelist.owner.id)
+
+ for si in sis:
+ if si.valid != "valid":
+ self.logger.debug("MODEL_POLICY: activating AttWorkflowDriverServiceInstance because of change in the whitelist", si=si)
+ si.valid = "valid"
+ si.save(update_fields=["valid", "no_sync", "updated"], always_update_timestamp=True)
+
+ whitelist.backend_need_delete_policy=True
+ whitelist.save(update_fields=["backend_need_delete_policy"])
+
+ def handle_delete(self, whitelist):
+ self.logger.debug("MODEL_POLICY: handle_delete for AttWorkflowDriverWhiteListEntry", whitelist=whitelist)
+
+ # BUG: Sometimes the delete policy is not called, because the reaper deletes
+
+ assert(whitelist.owner)
+
+ sis = AttWorkflowDriverServiceInstance.objects.filter(serial_number = whitelist.serial_number,
+ owner_id = whitelist.owner.id)
+
+ for si in sis:
+ if si.valid != "invalid":
+ self.logger.debug(
+ "MODEL_POLICY: disabling AttWorkflowDriverServiceInstance because of change in the whitelist", si=si)
+ si.valid = "invalid"
+ si.save(update_fields=["valid", "no_sync", "updated"], always_update_timestamp=True)
+
+ whitelist.backend_need_reap=True
+ whitelist.save(update_fields=["backend_need_reap"])
diff --git a/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_service.py b/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_service.py
new file mode 100644
index 0000000..3af7cfe
--- /dev/null
+++ b/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_service.py
@@ -0,0 +1,130 @@
+
+# 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.
+
+
+import unittest
+from mock import patch, call, Mock, PropertyMock
+
+import os, sys
+
+test_path=os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+service_dir=os.path.join(test_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")
+
+def get_models_fn(service_name, xproto_name):
+ 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))
+
+class TestModelPolicyAttWorkflowDriverService(unittest.TestCase):
+ def setUp(self):
+ self.sys_path_save = sys.path
+ sys.path.append(xos_dir)
+ sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base'))
+
+ config = os.path.join(test_path, "../test_config.yaml")
+ from xosconfig import Config
+ Config.clear()
+ Config.init(config, 'synchronizer-config-schema.yaml')
+
+ from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor
+ build_mock_modelaccessor(xos_dir, services_dir, [
+ get_models_fn("att-workflow-driver", "att-workflow-driver.xproto"),
+ get_models_fn("olt-service", "volt.xproto"),
+ get_models_fn("../profiles/rcord", "rcord.xproto")
+ ])
+
+ import synchronizers.new_base.modelaccessor
+ from model_policy_att_workflow_driver_service import AttWorkflowDriverServicePolicy, model_accessor
+
+ from mock_modelaccessor import MockObjectList
+ self.MockObjectList = MockObjectList
+
+ # import all class names to globals
+ 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.
+ model_accessor.reset_all_object_stores()
+
+ self.policy = AttWorkflowDriverServicePolicy()
+
+ self.service = AttWorkflowDriverService(
+ id = 5367,
+ whitelist_entries = [],
+ )
+
+ # needs to be enabled
+ self.si1 = AttWorkflowDriverServiceInstance(
+ valid="awaiting",
+ serial_number="BRCM111"
+ )
+
+ # needs to be enabled
+ self.si2 = AttWorkflowDriverServiceInstance(
+ valid="invalid",
+ serial_number="BRCM222"
+ )
+
+ # remains disabled
+ self.si3 = AttWorkflowDriverServiceInstance(
+ valid="invalid",
+ serial_number="BRCM333"
+ )
+
+ # needs to be disabled
+ self.si4 = AttWorkflowDriverServiceInstance(
+ valid="valid",
+ serial_number="BRCM444"
+ )
+
+ def tearDown(self):
+ sys.path = self.sys_path_save
+ self.service = None
+
+ def test_whitelist_update(self):
+ """
+ When the whitelist is updated, check for added ONU to be enabled and for removed ONU to be disabled
+ """
+ with patch.object(AttWorkflowDriverServiceInstance.objects, "get_items") as oss_si, \
+ patch.object(self.si1, "save") as si1_save, \
+ patch.object(self.si2, "save") as si2_save, \
+ patch.object(self.si3, "save") as si3_save, \
+ patch.object(self.si4, "save") as si4_save:
+ oss_si.return_value = [self.si1, self.si2, self.si3, self.si4]
+
+ wle1 = AttWorkflowDriverWhiteListEntry(owner_id=self.service.id, serial_number="BRCM111")
+ wle2 = AttWorkflowDriverWhiteListEntry(owner_id=self.service.id, serial_number="BRCM222")
+ self.service.whitelist_entries = self.MockObjectList([wle1, wle2])
+
+ self.policy.handle_update(self.service)
+
+ self.si1.save.assert_called_with(always_update_timestamp=True, update_fields=['valid', 'no_sync', 'updated'])
+ self.assertEqual(self.si1.valid, "valid")
+ self.si2.save.assert_called_with(always_update_timestamp=True, update_fields=['valid', 'no_sync', 'updated'])
+ self.assertEqual(self.si2.valid, "valid")
+ self.si3.save.assert_not_called()
+ self.assertEqual(self.si3.valid, "invalid")
+ self.si4.save.assert_called_with(always_update_timestamp=True, update_fields=['valid', 'no_sync', 'updated'])
+ self.assertEqual(self.si4.valid, "invalid")
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_serviceinstance.py b/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_serviceinstance.py
new file mode 100644
index 0000000..a34fedc
--- /dev/null
+++ b/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_serviceinstance.py
@@ -0,0 +1,284 @@
+
+# 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.
+
+
+import unittest
+from mock import patch, call, Mock, PropertyMock
+
+import os, sys
+
+test_path=os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+service_dir=os.path.join(test_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")
+
+def get_models_fn(service_name, xproto_name):
+ 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))
+
+class TestModelPolicyAttWorkflowDriverServiceInstance(unittest.TestCase):
+ def setUp(self):
+
+ self.sys_path_save = sys.path
+ sys.path.append(xos_dir)
+ sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base'))
+
+ config = os.path.join(test_path, "../test_config.yaml")
+ from xosconfig import Config
+ Config.clear()
+ Config.init(config, 'synchronizer-config-schema.yaml')
+
+ from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor
+ build_mock_modelaccessor(xos_dir, services_dir, [
+ get_models_fn("att-workflow-driver", "att-workflow-driver.xproto"),
+ get_models_fn("olt-service", "volt.xproto"),
+ get_models_fn("../profiles/rcord", "rcord.xproto")
+ ])
+
+ import synchronizers.new_base.modelaccessor
+ from model_policy_att_workflow_driver_serviceinstance import AttWorkflowDriverServiceInstancePolicy, model_accessor
+
+ from mock_modelaccessor import MockObjectList
+
+ # import all class names to globals
+ 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.
+ model_accessor.reset_all_object_stores()
+
+ self.policy = AttWorkflowDriverServiceInstancePolicy()
+ self.si = AttWorkflowDriverServiceInstance()
+ self.si.owner = AttWorkflowDriverService()
+
+ def tearDown(self):
+ sys.path = self.sys_path_save
+ self.si = None
+
+ def test_not_synced(self):
+ self.si.valid = "awaiting"
+ self.si.backend_code = 0
+
+ with patch.object(RCORDSubscriber, "save") as subscriber_save, \
+ patch.object(ONUDevice, "save") as onu_save:
+
+ with self.assertRaises(Exception) as e:
+ self.policy.handle_update(self.si)
+
+ self.assertIn("has not been synced yet", e.exception.message)
+
+ def test_skip_update(self):
+ self.si.valid = "awaiting"
+ self.si.backend_code = 1
+
+ with patch.object(RCORDSubscriber, "save") as subscriber_save, \
+ patch.object(ONUDevice, "save") as onu_save:
+
+ self.policy.handle_update(self.si)
+ subscriber_save.assert_not_called()
+ onu_save.assert_not_called()
+
+ def test_disable_onu(self):
+ self.si.valid = "invalid"
+ self.si.serial_number = "BRCM1234"
+ self.si.backend_code = 1
+
+ onu = ONUDevice(
+ serial_number=self.si.serial_number
+ )
+
+ with patch.object(ONUDevice.objects, "get_items") as onu_objects, \
+ patch.object(RCORDSubscriber, "save") as subscriber_save, \
+ patch.object(ONUDevice, "save") as onu_save:
+
+ onu_objects.return_value = [onu]
+
+ self.policy.handle_update(self.si)
+ subscriber_save.assert_not_called()
+ self.assertEqual(onu.admin_state, "DISABLED")
+ onu_save.assert_called()
+
+ def test_enable_onu(self):
+ self.si.valid = "valid"
+ self.si.serial_number = "BRCM1234"
+ self.si.c_tag = None
+ self.si.backend_code = 1
+
+ onu = ONUDevice(
+ serial_number=self.si.serial_number,
+ admin_state="DISABLED"
+ )
+
+ subscriber = RCORDSubscriber(
+ onu_device=self.si.serial_number,
+ status='pre-provisioned'
+ )
+
+ with patch.object(ONUDevice.objects, "get_items") as onu_objects, \
+ patch.object(RCORDSubscriber.objects, "get_items") as subscriber_objects, \
+ patch.object(ONUDevice, "save") as onu_save:
+
+ onu_objects.return_value = [onu]
+ subscriber_objects.return_value = [subscriber]
+
+ self.policy.handle_update(self.si)
+ self.assertEqual(onu.admin_state, "ENABLED")
+ onu_save.assert_called()
+
+ def test_do_not_create_subscriber(self):
+ self.si.valid = "valid"
+ self.si.backend_code = 1
+ self.si.serial_number = "BRCM1234"
+ self.si.authentication_state = "DENIEND"
+ self.si.owner.leaf_model.create_on_discovery = False
+
+ onu = ONUDevice(
+ serial_number=self.si.serial_number,
+ admin_state="DISABLED"
+ )
+
+ with patch.object(ONUDevice.objects, "get_items") as onu_objects, \
+ patch.object(RCORDSubscriber, "save", autospec=True) as subscriber_save, \
+ patch.object(ONUDevice, "save") as onu_save:
+
+ onu_objects.return_value = [onu]
+
+ self.policy.handle_update(self.si)
+
+ self.assertEqual(onu.admin_state, "ENABLED")
+ onu_save.assert_called()
+ self.assertEqual(subscriber_save.call_count, 0)
+
+ def test_create_subscriber(self):
+ self.si.valid = "valid"
+ self.si.serial_number = "BRCM1234"
+ self.si.backend_code = 1
+
+ onu = ONUDevice(
+ serial_number=self.si.serial_number,
+ admin_state="ENABLED"
+ )
+
+ with patch.object(ONUDevice.objects, "get_items") as onu_objects, \
+ patch.object(RCORDSubscriber, "save", autospec=True) as subscriber_save, \
+ patch.object(ONUDevice, "save") as onu_save:
+
+ onu_objects.return_value = [onu]
+
+ self.policy.handle_update(self.si)
+ self.assertEqual(subscriber_save.call_count, 1)
+
+ subscriber = subscriber_save.call_args[0][0]
+ self.assertEqual(subscriber.onu_device, self.si.serial_number)
+
+ onu_save.assert_not_called()
+
+ def test_create_subscriber_no_create_on_discovery(self):
+ """
+ test_create_subscriber_no_create_on_discovery
+ When si.owner.create_on_discovery = False we still need to create the subscriber after authentication
+ """
+
+ self.si.valid = "valid"
+ self.si.serial_number = "BRCM1234"
+ self.si.backend_code = 1
+ self.si.owner.leaf_model.create_on_discovery = False
+ self.si.authentication_state = "APPROVED"
+
+ onu = ONUDevice(
+ serial_number=self.si.serial_number,
+ admin_state="ENABLED"
+ )
+
+ with patch.object(ONUDevice.objects, "get_items") as onu_objects, \
+ patch.object(RCORDSubscriber, "save", autospec=True) as subscriber_save, \
+ patch.object(ONUDevice, "save") as onu_save:
+
+ onu_objects.return_value = [onu]
+
+ self.policy.handle_update(self.si)
+ self.assertEqual(subscriber_save.call_count, 1)
+
+ subscriber = subscriber_save.call_args[0][0]
+ self.assertEqual(subscriber.onu_device, self.si.serial_number)
+
+ onu_save.assert_not_called()
+
+ def test_create_subscriber_with_ctag(self):
+ self.si.valid = "valid"
+ self.si.serial_number = "BRCM1234"
+ self.si.c_tag = 111
+ self.si.backend_code = 1
+
+ onu = ONUDevice(
+ serial_number=self.si.serial_number,
+ admin_state="ENABLED"
+ )
+
+ with patch.object(ONUDevice.objects, "get_items") as onu_objects, \
+ patch.object(RCORDSubscriber, "save", autospec=True) as subscriber_save, \
+ patch.object(ONUDevice, "save") as onu_save:
+
+ onu_objects.return_value = [onu]
+
+ self.policy.handle_update(self.si)
+ self.assertEqual(subscriber_save.call_count, 1)
+
+ subscriber = subscriber_save.call_args[0][0]
+ self.assertEqual(subscriber.onu_device, self.si.serial_number)
+ self.assertEqual(subscriber.c_tag, self.si.c_tag)
+
+ onu_save.assert_not_called()
+
+ def _test_add_c_tag_to_pre_provisioned_subscriber(self):
+ self.si.valid = "valid"
+ self.si.serial_number = "BRCM1234"
+ self.si.c_tag = 111
+ self.si.backend_code = 1
+
+ onu = ONUDevice(
+ serial_number=self.si.serial_number,
+ admin_state="ENABLED"
+ )
+
+ subscriber = RCORDSubscriber(
+ onu_device=self.si.serial_number,
+ )
+
+ with patch.object(ONUDevice.objects, "get_items") as onu_objects, \
+ patch.object(RCORDSubscriber.objects, "get_items") as subscriber_objects, \
+ patch.object(RCORDSubscriber, "save", autospec=True) as subscriber_save, \
+ patch.object(ONUDevice, "save") as onu_save:
+
+ onu_objects.return_value = [onu]
+ subscriber_objects.return_value = [subscriber]
+
+ self.policy.handle_update(self.si)
+ self.assertEqual(subscriber_save.call_count, 1)
+
+ subscriber = subscriber_save.call_args[0][0]
+ self.assertEqual(subscriber.onu_device, self.si.serial_number)
+ self.assertEqual(subscriber.c_tag, self.si.c_tag)
+
+ onu_save.assert_not_called()
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_whitelistentry.py b/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_whitelistentry.py
new file mode 100644
index 0000000..73c077a
--- /dev/null
+++ b/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_whitelistentry.py
@@ -0,0 +1,106 @@
+
+# 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.
+
+
+import unittest
+from mock import patch, call, Mock, PropertyMock
+
+import os, sys
+
+test_path=os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+service_dir=os.path.join(test_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")
+
+def get_models_fn(service_name, xproto_name):
+ 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))
+
+class TestModelPolicyAttWorkflowDriverWhiteListEntry(unittest.TestCase):
+ def setUp(self):
+ self.sys_path_save = sys.path
+ sys.path.append(xos_dir)
+ sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base'))
+
+ config = os.path.join(test_path, "../test_config.yaml")
+ from xosconfig import Config
+ Config.clear()
+ Config.init(config, 'synchronizer-config-schema.yaml')
+
+ from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor
+ build_mock_modelaccessor(xos_dir, services_dir, [
+ get_models_fn("att-workflow-driver", "att-workflow-driver.xproto"),
+ get_models_fn("olt-service", "volt.xproto"),
+ get_models_fn("../profiles/rcord", "rcord.xproto")
+ ])
+
+ import synchronizers.new_base.modelaccessor
+ from model_policy_att_workflow_driver_whitelistentry import AttWorkflowDriverWhiteListEntryPolicy, model_accessor
+
+ from mock_modelaccessor import MockObjectList
+ self.MockObjectList = MockObjectList
+
+ # import all class names to globals
+ 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.
+ model_accessor.reset_all_object_stores()
+
+ self.policy = AttWorkflowDriverWhiteListEntryPolicy()
+
+ self.service = AttWorkflowDriverService()
+
+
+ def tearDown(self):
+ sys.path = self.sys_path_save
+ self.service = None
+
+ def test_whitelist_update(self):
+ """
+ When a whitelist entry is added, see that the AttWorkflowDriverIServicenstance was set to valid
+ """
+ with patch.object(AttWorkflowDriverServiceInstance.objects, "get_items") as oss_si_items:
+ si = AttWorkflowDriverServiceInstance(serial_number="BRCM333", owner_id=self.service.id, valid="invalid")
+ oss_si_items.return_value = [si]
+
+ wle = AttWorkflowDriverWhiteListEntry(serial_number="BRCM333", owner_id=self.service.id, owner=self.service)
+
+ self.policy.handle_update(wle)
+
+ self.assertEqual(si.valid, "valid")
+
+ def test_whitelist_delete(self):
+ """
+ When a whitelist entry is deleted, see that the AttWorkflowDriverIServicenstance was set to invalid
+ """
+ with patch.object(AttWorkflowDriverServiceInstance.objects, "get_items") as oss_si_items:
+ si = AttWorkflowDriverServiceInstance(serial_number="BRCM333", owner_id=self.service.id, valid="valid")
+ oss_si_items.return_value = [si]
+
+ wle = AttWorkflowDriverWhiteListEntry(serial_number="BRCM333", owner_id=self.service.id, owner=self.service)
+
+ self.policy.handle_delete(wle)
+
+ self.assertEqual(si.valid, "invalid")
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/xos/synchronizer/models/att-workflow-driver.xproto b/xos/synchronizer/models/att-workflow-driver.xproto
new file mode 100644
index 0000000..046e7f5
--- /dev/null
+++ b/xos/synchronizer/models/att-workflow-driver.xproto
@@ -0,0 +1,28 @@
+option name = "att-workflow-driver";
+option app_label = "att-workflow-driver";
+
+message AttWorkflowDriverService (Service){
+ option verbose_name = "AttWorkflowDriver Service";
+ option kind = "OSS";
+
+ required bool create_on_discovery = 2 [help_text = "Whether to create the subscriber when an ONU is discovered", null = False, db_index = False, blank = False, default = True];
+}
+
+message AttWorkflowDriverServiceInstance (ServiceInstance){
+ option owner_class_name = "AttWorkflowDriverService";
+ option verbose_name = "AttWorkflowDriver Service Instance";
+
+ required string valid = 1 [default = "awaiting", choices = "(('awaiting', 'Awaiting Validation'), ('valid', 'Valid'), ('invalid', 'Invalid'))", help_text = "Wether this ONU has been validated by the external OSS", null = False, blank = False];
+ required string serial_number = 2 [max_length = 254, null = False, db_index = False, blank = False, tosca_key=True, unique = True];
+ required string authentication_state = 3 [default = "AWAITING", choices = "(('AWAITING', 'Awaiting'), ('STARTED', 'Started'), ('REQUESTED', 'Requested'), ('APPROVED', 'Approved'), ('DENIED', 'Denied'), )", max_length = 50, null = False, db_index = False, blank = False];
+ required string of_dpid = 4 [max_length = 254, null = False, db_index = False, blank = False];
+ optional int32 c_tag = 5 [null = True, db_index = False, blank = False, unique = True, feedback_state = True];
+}
+
+message AttWorkflowDriverWhiteListEntry (XOSBase) {
+ option verbose_name = "Whitelist";
+ option plural = "attworkflowdriverwhitelistentries";
+
+ required manytoone owner->AttWorkflowDriverService:whitelist_entries = 1 [db_index = True, null = False, blank = False, tosca_key=True];
+ required string serial_number = 2 [max_length = 254, null = False, db_index = False, blank = False, tosca_key=True, unique_with = "owner"];
+}
diff --git a/xos/synchronizer/steps/sync_att_workflow_driver_service_instance.py b/xos/synchronizer/steps/sync_att_workflow_driver_service_instance.py
new file mode 100644
index 0000000..d2fdeeb
--- /dev/null
+++ b/xos/synchronizer/steps/sync_att_workflow_driver_service_instance.py
@@ -0,0 +1,63 @@
+# 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.
+
+import json
+from synchronizers.new_base.syncstep import SyncStep, model_accessor
+from synchronizers.new_base.modelaccessor import AttWorkflowDriverServiceInstance, AttWorkflowDriverWhiteListEntry
+
+from xosconfig import Config
+from multistructlog import create_logger
+
+log = create_logger(Config().get('logging'))
+
+class SyncAttWorkflowDriverServiceInstance(SyncStep):
+ provides = [AttWorkflowDriverServiceInstance]
+ observes = AttWorkflowDriverServiceInstance
+
+ def validate_in_external_oss(self, si):
+ # This is where you may want to call your OSS Database to verify if this ONU can be activated
+ oss_service = si.owner.leaf_model
+
+ # See if there is a matching entry in the whitelist.
+
+ matching_entries = AttWorkflowDriverWhiteListEntry.objects.filter(owner_id=oss_service.id,
+ serial_number=si.serial_number)
+
+ return len(matching_entries)>0
+
+ def get_suscriber_c_tag(self, serial_number):
+ # If it's up to your OSS to generate c_tags, fetch them here
+ # otherwise XOS will generate one for your subscriber
+ return None
+
+ def sync_record(self, o):
+ log.info("synching AttWorkflowDriverServiceInstance", object=str(o), **o.tologdict())
+
+ if not self.validate_in_external_oss(o):
+ log.error("ONU with serial number %s is not valid in the OSS Database" % o.serial_number)
+ o.valid = "invalid"
+ else:
+ if self.get_suscriber_c_tag(o.serial_number):
+ self.c_tag = self.get_suscriber_c_tag(o.serial_number)
+
+ o.valid = "valid"
+
+ # Set no_sync=True to prevent the syncstep from running again, and set alway_update_timestamp=True to cause
+ # the model_policy to run again.
+ # TODO(smbaker): Revisit this after fixing this issue in the core.
+ o.no_sync = True
+ o.save(update_fields=["valid", "no_sync", "updated"], always_update_timestamp=True)
+
+ def delete_record(self, o):
+ pass
diff --git a/xos/synchronizer/steps/test_sync_att_workflow_driver_service_instance.py b/xos/synchronizer/steps/test_sync_att_workflow_driver_service_instance.py
new file mode 100644
index 0000000..db168f7
--- /dev/null
+++ b/xos/synchronizer/steps/test_sync_att_workflow_driver_service_instance.py
@@ -0,0 +1,114 @@
+# 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.
+
+import unittest
+
+import functools
+from mock import patch, call, Mock, PropertyMock
+import requests_mock
+import multistructlog
+from multistructlog import create_logger
+
+import os, sys
+
+# Hack to load synchronizer framework
+test_path=os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+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'))
+# END Hack to load synchronizer framework
+
+# generate model from xproto
+def get_models_fn(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))
+# END generate model from xproto
+
+class TestSyncAttWorkflowDriverServiceInstance(unittest.TestCase):
+
+ def setUp(self):
+
+ self.sys_path_save = sys.path
+ 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, "../test_config.yaml")
+ Config.clear()
+ Config.init(config, "synchronizer-config-schema.yaml")
+ # END Setting up the config module
+
+ from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor
+ build_mock_modelaccessor(xos_dir, services_dir, [
+ get_models_fn("att-workflow-driver", "att-workflow-driver.xproto"),
+ get_models_fn("olt-service", "volt.xproto"),
+ get_models_fn("../profiles/rcord", "rcord.xproto")
+ ])
+ import synchronizers.new_base.modelaccessor
+
+ from sync_att_workflow_driver_service_instance import SyncAttWorkflowDriverServiceInstance, model_accessor
+
+ # import all class names to globals
+ for (k, v) in model_accessor.all_model_classes.items():
+ globals()[k] = v
+
+
+ self.sync_step = SyncAttWorkflowDriverServiceInstance
+
+ self.oss = Mock()
+ self.oss.name = "oss"
+ self.oss.id = 5367
+
+ # create a mock AttWorkflowDriverServiceInstance instance
+ self.o = Mock()
+ self.o.serial_number = "BRCM1234"
+ self.o.of_dpid = "of:109299321"
+ self.o.owner.leaf_model = self.oss
+ self.o.tologdict.return_value = {}
+
+ def tearDown(self):
+ self.o = None
+ sys.path = self.sys_path_save
+
+ def test_sync_valid(self):
+ with patch.object(AttWorkflowDriverWhiteListEntry.objects, "get_items") as whitelist_items:
+ # Create a whitelist entry for self.o's serial number
+ whitelist_entry = AttWorkflowDriverWhiteListEntry(owner_id=self.oss.id, serial_number=self.o.serial_number)
+ whitelist_items.return_value = [whitelist_entry]
+
+ self.sync_step().sync_record(self.o)
+
+ self.assertEqual(self.o.valid, "valid")
+ self.assertTrue(self.o.no_sync)
+ self.o.save.assert_called()
+
+ def test_sync_rejected(self):
+ self.sync_step().sync_record(self.o)
+
+ self.assertEqual(self.o.valid, "invalid")
+ self.assertTrue(self.o.no_sync)
+ self.o.save.assert_called()
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/xos/synchronizer/test_config.yaml b/xos/synchronizer/test_config.yaml
new file mode 100644
index 0000000..dfb11c7
--- /dev/null
+++ b/xos/synchronizer/test_config.yaml
@@ -0,0 +1,31 @@
+
+# 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.
+
+
+name: test-AttWorkflowDriverService-config
+accessor:
+ username: xosadmin@opencord.org
+ password: "sample"
+ kind: "testframework"
+logging:
+ version: 1
+ handlers:
+ console:
+ class: logging.StreamHandler
+ loggers:
+ 'multistructlog':
+ handlers:
+ - console
+# level: DEBUG
diff --git a/xos/unittest.cfg b/xos/unittest.cfg
new file mode 100644
index 0000000..3db2d53
--- /dev/null
+++ b/xos/unittest.cfg
@@ -0,0 +1,14 @@
+[unittest]
+plugins=nose2.plugins.junitxml
+code-directories=synchronizer
+ model_policies
+ steps
+ pull_steps
+ event_steps
+
+[coverage]
+always-on = True
+coverage = synchronizer
+coverage-report = term
+coverage-report = html
+coverage-report = xml