[SEBA-446] Adding auth and dhcp events to xos-scale-test

Change-Id: I0c688bde996fa5efadfa4e39c0c20a838afc353f
diff --git a/src/test/cord-api/Tests/xos-scale-tests/utils/devices.py b/src/test/cord-api/Tests/xos-scale-tests/utils/devices.py
index fe93488..a9978c8 100644
--- a/src/test/cord-api/Tests/xos-scale-tests/utils/devices.py
+++ b/src/test/cord-api/Tests/xos-scale-tests/utils/devices.py
@@ -68,6 +68,7 @@
                 'switch_datapath_id': 'of:0000000000000001',
                 'switch_port': str(index),
                 'of_id': 'of:000000%s' % index,
+                'dp_id': 'of:000000%s' % index,
             }
             # logger.info('Created OLT %s' % olt, also_console=True)
             olts.append(olt)
@@ -102,9 +103,9 @@
 
         ports = []
         for olt in self.olts.all():
-            for index in range(1, int(num_pon) +1):
+            for index in range(1, int(num_pon) + 1):
                 port = {
-                    'name': 'Test PonPort %s' % index,
+                    'name': 'Test PonPort %s Olt %s' % (index, olt['id']),
                     'port_no': index,
                     'olt_device_id': olt['id']
                 }
@@ -216,6 +217,30 @@
             events.append(ev)
         return events
 
+    def generate_auth_events(self):
+        events = []
+        for onu in self.onus.all():
+            ev = {
+                'authenticationState': "APPROVED",
+                'deviceId': self._find_olt_by_onu(onu)['dp_id'],
+                'portNumber': self._find_uni_by_onu(onu)['port_no'],
+            }
+            events.append(ev)
+        return events
+
+    def generate_dhcp_events(self):
+        events = []
+        for onu in self.onus.all():
+            ev = {
+                'deviceId': self._find_olt_by_onu(onu)['dp_id'],
+                'portNumber': self._find_uni_by_onu(onu)['port_no'],
+                "macAddress": "aa:bb:cc:ee:ff",
+                "ipAddress": "10.10.10.10",
+                "messageType": "DHCPACK"
+            }
+            events.append(ev)
+        return events
+
 ###############################################################
 #                             HELPERS                         #
 ###############################################################
@@ -226,6 +251,7 @@
         return self.uni_ports.search(Uni.onu_device_id == onu['id'])[0]
 
     def _find_pon_port_by_onu(self, onu):
+        # this does not care about the olt id...
         PonPort = Query()
         return self.pon_ports.search(PonPort.id == onu['pon_port_id'])[0]
 
diff --git a/src/test/cord-api/Tests/xos-scale-tests/xos-scale-att-workflow.robot b/src/test/cord-api/Tests/xos-scale-tests/xos-scale-att-workflow.robot
index a2bae1a..47e7dfe 100644
--- a/src/test/cord-api/Tests/xos-scale-tests/xos-scale-att-workflow.robot
+++ b/src/test/cord-api/Tests/xos-scale-tests/xos-scale-att-workflow.robot
@@ -66,7 +66,6 @@
     \   Send Kafka Event    onu.events    ${e}
     ${start} =   Get Time
     Wait Until Keyword Succeeds    ${timeout}    5s    Validate ATT_SI Number    ${events}
-    # need to increase modelpolicy creation timeout
     Wait Until Keyword Succeeds    ${timeout}    5s    ModelPolicy completed
     ${end} =   Get Time
     Log To Console      Test started at: ${start}
@@ -74,6 +73,40 @@
     ${duration} =       Subtract Date From Date    ${end}   ${start}
     Log To Console      Test duration: ${duration}
 
+Authenticate Subscribers
+    [Documentation]    Send authentication events for all the ONUs and waits for the model_policies of ATT Workflow Driver Service Instances to have completed
+    ${events} =     Generate Auth Events
+    : FOR   ${e}  IN  @{events}
+    \   Send Kafka Event    authentication.events    ${e}
+    ${start} =   Get Time
+    Wait Until Keyword Succeeds    ${timeout}    5s    AuthCompleted
+    Wait Until Keyword Succeeds    ${timeout}    5s    ModelPolicy completed
+    # TODO validate that:
+    # - subscriber status has changed
+    # - vOLT SI have been created and policed (we can't test sync'ed without a backend)
+    # - fabric-xconnect have been created and policed (we can't test sync'ed without a backend)
+    ${end} =   Get Time
+    Log To Console      Test started at: ${start}
+    Log To Console      Test ended at: ${end}
+    ${duration} =       Subtract Date From Date    ${end}   ${start}
+    Log To Console      Test duration: ${duration}
+
+DHCP Subscribers
+    [Documentation]    Send dhcp events for all the ONUs and waits for the model_policies of ATT Workflow Driver Service Instances to have completed
+    ${events} =     Generate Dhcp Events
+    : FOR   ${e}  IN  @{events}
+    \   Send Kafka Event    dhcp.events    ${e}
+    ${start} =   Get Time
+    Wait Until Keyword Succeeds    ${timeout}    5s    DHCPCompleted
+    Wait Until Keyword Succeeds    ${timeout}    5s    ModelPolicy completed
+    # TODO validate that:
+    # - subscriber has an IP address
+    ${end} =   Get Time
+    Log To Console      Test started at: ${start}
+    Log To Console      Test ended at: ${end}
+    ${duration} =       Subtract Date From Date    ${end}   ${start}
+    Log To Console      Test duration: ${duration}
+
 
 *** Keywords ***
 
@@ -86,16 +119,33 @@
     Log To Console      ${length} Service Instances created, expecting ${total}
     Should Be Equal    ${length}    ${total}
 
-ModelPolicy completed
-    [Documentation]     Check that model_policies had run for all the items in the list
-    # TODO print something to the console to notify the user that this test is still running
+DHCPCompleted
+    [Documentation]     Check that all ATT_SI have an ip address
     ${res} =   CORD Get    /xosapi/v1/att-workflow-driver/attworkflowdriverserviceinstances
     ${jsondata} =    To Json    ${res.content}
+    Log To Console      Checking DHCP
     : FOR   ${i}  IN  @{jsondata['items']}
-    \   Should Be Equal As Integers     ${i['policy_code']}     1
-    \   Log To Console    \n Waiting for model_policies to run for all Service Instance
+    \   Should Not Be Empty     ${i['ip_address']}
+
+AuthCompleted
+    [Documentation]     Check that all ATT_SI have status=authenticated
+    ${res} =   CORD Get    /xosapi/v1/att-workflow-driver/attworkflowdriverserviceinstances
+    ${jsondata} =    To Json    ${res.content}
+    Log To Console      Checking Authentication
+    : FOR   ${i}  IN  @{jsondata['items']}
+    \   Should Be Equal     ${i['authentication_state']}     APPROVED
+
+ModelPolicy completed
+    # TODO make this method configurable to check model_policies on arbitrary models
+    [Documentation]    Check that model_policies had run for all the items in the list
+    ${res} =   CORD Get    /xosapi/v1/att-workflow-driver/attworkflowdriverserviceinstances
+    ${jsondata} =    To Json    ${res.content}
+    Log To Console      Checking ModelPolicy
+    : FOR   ${i}  IN  @{jsondata['items']}
+    \   Should Be True      ${i['policed']} >= ${i['updated']}
 
 Setup
+    # TODO remove all JSON files that a previous run may have left around
     ${target} =     Evaluate    ${num_olts} * ${num_pon_ports} * ${num_onus}
     Log     Testing with ${target} ONUs
     Log To Console      Testing with ${target} ONUs
@@ -113,6 +163,7 @@
 Teardown
     [Documentation]    Delete all models created
     Log     Teardown
+    Log To Console      Teardown
     Delete OLTs
     Delete Whitelist
     Delete ServiceInstances
@@ -136,6 +187,7 @@
     ${olts} =   Get Rest Olts
     : FOR   ${OLT}  IN  @{olts}
     \   Log     ${OLT}
+    \   Log To Console      Creating OLT ${OLT['name']}
     \   ${res} =    CORD Post   /xosapi/v1/volt/oltdevices    ${OLT}
     \   ${jsondata} =    To Json    ${res.content}
     \   Update Olt Id       ${OLT}  ${jsondata['id']}
@@ -144,6 +196,7 @@
     ${pon_ports} =   Get Rest Pon Ports
     : FOR   ${port}  IN  @{pon_ports}
     \   Log     ${port}
+    \   Log To Console      Creating PON Port ${port['name']}
     \   ${res} =    CORD Post   /xosapi/v1/volt/ponports    ${port}
     \   ${jsondata} =    To Json    ${res.content}
     \   Update Pon Port Id       ${port}  ${jsondata['id']}
@@ -152,6 +205,7 @@
     ${onus} =   Get Rest Onus
     : FOR   ${onu}  IN  @{onus}
     \   Log     ${onu}
+    \   Log To Console      Creating ONU ${onu['serial_number']}
     \   ${res} =    CORD Post   /xosapi/v1/volt/onudevices    ${onu}
     \   ${jsondata} =    To Json    ${res.content}
     \   Update Onu Id       ${onu}  ${jsondata['id']}
@@ -160,6 +214,7 @@
     ${unis} =   Get Rest Unis
     : FOR   ${uni}  IN  @{unis}
     \   Log     ${uni}
+    \   Log To Console      Creating UNI ${uni['name']}
     \   ${res} =    CORD Post   /xosapi/v1/volt/uniports    ${uni}
     \   ${jsondata} =    To Json    ${res.content}
     \   Update Uni Id       ${uni}  ${jsondata['id']}
@@ -169,6 +224,7 @@
     ${whitelist} =      Create Mock Whitelist   ${attworkflowservice_id}
     : FOR   ${e}  IN  @{whitelist}
     \   Log     ${e}
+    \   Log To Console      Creating Whitelist Entry ${e['serial_number']}
     \   ${res} =    CORD Post   /xosapi/v1/att-workflow-driver/attworkflowdriverwhitelistentries    ${e}
 
 Delete Olts