def de_assign_default_ip_on_rg(self): statusLines = testCaseUtils.get_fields_from_grep_command( self, 'inet', self.CHECK_IP_FILENAME) if statusLines: process_output = open( '%s/%s' % (testCaseUtils.get_dir( self, 'log'), self.DE_ASSIGN_IP_FILENAME), 'w') os.system( '/usr/bin/kubectl exec -n voltha %s -- bash -c "ifconfig eth0 0.0.0.0"' % self.__rgName) ifconfigDeassign1 = subprocess.Popen([ '/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'bash', '-c', 'ifconfig' ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) ifconfigDeassign2 = subprocess.Popen( ['grep', '-e', 'eth0', '-A1'], stdin=ifconfigDeassign1.stdout, stdout=process_output, stderr=process_output) ifconfigDeassign1.wait() ifconfigDeassign1.stdout.close() ifconfigDeassign2.wait() process_output.close() statusLines = testCaseUtils.get_fields_from_grep_command( self, 'inet', self.DE_ASSIGN_IP_FILENAME) assert not statusLines, 'IP addr not de-assigned' else: logging.info('No default IP addr assigned to eth0')
def onu_discovery(self): logging.info('Onu Discovery') statusLines = testCaseUtils.get_fields_from_grep_command( self, self.__onuType, 'voltha_devices_after_enable.log') assert statusLines, 'No Onu listed under devices' lines = statusLines.splitlines() assert len( lines ) == self.__onuCount, 'Onu count mismatch found: %s, should be: %s' % ( len(lines), self.__onuCount) for line in lines: self.__fields = testCaseUtils.parse_fields(line, '|') onuDeviceId = self.__fields[1].strip() self.__onuDeviceIds.append(onuDeviceId) testCaseUtils.send_command_to_voltha_cli( testCaseUtils.get_dir(self, 'log'), 'voltha_onu_device_' + str(self.__onuDeviceIds.index(onuDeviceId)) + '.log', 'device ' + onuDeviceId, 'voltha_onu_ports_' + str(self.__onuDeviceIds.index(onuDeviceId)) + '.log', 'ports', 'voltha_onu_flows_' + str(self.__onuDeviceIds.index(onuDeviceId)) + '.log', 'flows') testCaseUtils.print_log_file( self, 'voltha_onu_ports_' + str(self.__onuDeviceIds.index(onuDeviceId)) + '.log') testCaseUtils.print_log_file( self, 'voltha_onu_flows_' + str(self.__onuDeviceIds.index(onuDeviceId)) + '.log')
def should_have_dhcp_assigned_ip(self): process_output = open( '%s/%s' % (testCaseUtils.get_dir( self, 'log'), self.CHECK_ASSIGNED_IP_FILENAME), 'w') ifConfigCheck1 = subprocess.Popen([ '/usr/bin/kubectl', 'exec', '-n', 'voltha', self.__rgName, '--', 'bash', '-c', 'ifconfig' ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) ifConfigCheck2 = subprocess.Popen(['grep', '-e', 'eth0', '-A1'], stdin=ifConfigCheck1.stdout, stdout=process_output, stderr=process_output) ifConfigCheck1.wait() ifConfigCheck1.stdout.close() ifConfigCheck2.wait() process_output.close() testCaseUtils.print_log_file(self, self.CHECK_ASSIGNED_IP_FILENAME) statusLines = testCaseUtils.get_fields_from_grep_command( self, 'inet', self.CHECK_ASSIGNED_IP_FILENAME) assert statusLines, 'DHCP IP addr not assigned'
def should_have_q_in_q_vlan_tagging(self): statusLines = testCaseUtils.get_fields_from_grep_command( self, '"Request who-has"', self.TCPDUMP_FILENAME) assert statusLines, 'tcpdump contains no ping packets' lines = statusLines.splitlines() for line in lines: tagCount = line.count('802.1Q') assert tagCount == 2, 'Found a non double tagged packet'
def deactivate_aaa_app_in_onos(self): logging.info('Deactivating AAA Application on Onos') testCaseUtils.send_command_to_onos_cli( testCaseUtils.get_dir(self, 'log'), 'voltha_aaa_application_deactivate.log', 'app deactivate aaa') statusLines = testCaseUtils.get_fields_from_grep_command( self, 'Deactivated', 'voltha_aaa_application_deactivate.log') assert statusLines, 'AAA Application failed to be Deactivated'
def deactivate_dhcp_server_in_onos(self): logging.info('Deactivating DHCP server on Onos') testCaseUtils.send_command_to_onos_cli( testCaseUtils.get_dir(self, 'log'), 'voltha_dhcp_server_deactivate.log', 'app deactivate dhcp') statusLines = testCaseUtils.get_fields_from_grep_command( self, 'Deactivated', 'voltha_dhcp_server_deactivate.log') assert statusLines, 'DHCP server failed to be Deactivated'
def check_olt_fields_after_enabling(self): statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltType, 'voltha_devices_after_enable.log') assert statusLines, 'No Olt listed under devices' self.__fields = testCaseUtils.parse_fields(statusLines, '|') assert self.check_states(self.__oltType), 'States of %s does match expected' % self.__oltType for field in self.__fields: if field.strip() == self.__oltIpAddress + ':' + str(self.__oltPort): hostPortCount = True assert hostPortCount, 'hostPort field is empty or Olt IP and/or Port does not match'
def should_have_all_onus_authenticated(self): testCaseUtils.send_command_to_onos_cli( testCaseUtils.get_dir(self, 'log'), 'voltha_onu_auth.log', 'aaa-users') statusLines = testCaseUtils.get_fields_from_grep_command( self, 'AUTHORIZED', 'voltha_onu_auth.log') lines = statusLines.splitlines() auth_count = len(lines) assert self.__onuCount == auth_count, 'There are only %s ONUS Authenticated' % auth_count
def check_onu_fields_after_enabling(self): statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__onuType, 'voltha_devices_after_enable.log') assert statusLines, 'No Onu listed under devices' lines = statusLines.splitlines() lenLines = len(lines) assert lenLines == 1, 'Fixed single onu does not match, ONU Count was %d' % lenLines for line in lines: self.__fields = testCaseUtils.parseFields(line) assert self.check_states(self.__onuType) == True, 'States of %s does match expected' % self.__onuType
def check_onu_fields_after_enabling(self): statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__onuType, 'voltha_devices_after_enable.log') assert statusLines, 'No Onu listed under devices' lines = statusLines.splitlines() lenLines = len(lines) assert lenLines == self.__onuCount, ' Discovered onu(s) does not match, ONU Count was %d' % lenLines for line in lines: self.__fields = testCaseUtils.parse_fields(line, '|') assert (self.check_states(self.__onuType) is True), 'States of %s does match expected' % self.__onuType
def logical_device_should_have_at_least_one_flow(self): statusLines = testCaseUtils.get_fields_from_grep_command( self, 'Flows', 'voltha_logical_device_flows.log') assert statusLines, 'No Logical device flows listed for logical device' before, flows, numFlows = statusLines.partition('Flows') plainNumber = numFlows.strip().strip('():') if plainNumber.isdigit(): assert int( plainNumber) > 0, 'Zero number of flows for logical device'
def logical_device_ports_should_exist(self): statusLines = testCaseUtils.get_fields_from_grep_command( self, self.__oltDeviceId, 'voltha_logical_device_ports.log') assert statusLines, 'No Olt ports listed under logical device ports' self.__fields = testCaseUtils.parse_fields(statusLines, '|') portType = self.__fields[1].strip() assert portType.count( 'nni' ) == 1, 'Port type for %s does not match expected nni' % self.__oltDeviceId for onuDeviceId in self.__onuDeviceIds: statusLines = testCaseUtils.get_fields_from_grep_command( self, onuDeviceId, 'voltha_logical_device_ports.log') assert statusLines, 'No Onu device %s listed under logical device ports' % onuDeviceId self.__fields = testCaseUtils.parse_fields(statusLines, '|') portType = self.__fields[1].strip() assert portType.count( 'uni' ) == 1, 'Port type for %s does not match expected uni' % onuDeviceId
def olt_should_have_at_least_one_flow(self): statusLines = testCaseUtils.get_fields_from_grep_command( self, 'Flows', 'voltha_olt_flows.log') assert statusLines, 'No Olt flows under device %s' % self.__oltDeviceId before, flows, numFlows = statusLines.partition('Flows') plainNumber = numFlows.strip().strip('():') if plainNumber.isdigit(): assert int( plainNumber ) > 0, 'Zero number of flows for Olt %s' % self.__oltDeviceId
def check_olt_fields_after_enabling(self): statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltType, 'voltha_devices_after_enable.log') assert statusLines, 'No Olt listed under devices' self.__fields = testCaseUtils.parseFields(statusLines) assert self.check_states(self.__oltType), 'States of %s does match expected' % self.__oltType hostPort = self.__fields[11].strip() assert hostPort, 'hostPort field is empty' hostPortFields = hostPort.split(":") assert hostPortFields[0] == self.__oltIpAddress or hostPortFields[1] == str(self.__oltPort), \ 'Olt IP or Port does not match'
def ping_test_should_have_failed(self): statusLines = testCaseUtils.get_fields_from_grep_command( self, 'Destination Host Unreachable', self.PING_TEST_FILENAME) assert statusLines, 'Ping Test Issue, no Destination Host Unreachable' lineCount = 0 lines = statusLines.splitlines() for line in lines: logging.debug(line) lineCount += 1 if lineCount > 1: # Must have 2 or more instances return True
def retrieve_authorized_users_device_id_and_port_number(self): statusLines = testCaseUtils.get_fields_from_grep_command( self, 'AUTHORIZED', 'voltha_onos_users.log') assert statusLines, 'No Users Authorized' self.__fields = testCaseUtils.parse_fields(statusLines, ',') deviceField = self.__fields[2].strip() deviceStr, equal, deviceId = deviceField.partition('=') self.__deviceId = deviceId portField = self.__fields[4].strip() portNumStr, equal, portNum = portField.partition('=') self.__portNumber = portNum
def onu_should_have_at_least_one_flow(self): for onuDeviceId in self.__onuDeviceIds: statusLines = testCaseUtils.get_fields_from_grep_command(self, 'Flows', 'voltha_onu_flows_' + \ str(self.__onuDeviceIds.index(onuDeviceId)) + '.log') assert statusLines, 'No Onu flows under device %s' % onuDeviceId before, flows, numFlows = statusLines.partition('Flows') plainNumber = numFlows.strip().strip('():') if plainNumber.isdigit(): assert int( plainNumber ) > 0, 'Zero number of flows for Onu %s' % onuDeviceId
def olt_discovery(self): logging.info('Olt Discovery') statusLines = testCaseUtils.get_fields_from_grep_command( self, self.__oltType, 'voltha_devices_after_enable.log') assert statusLines, 'No Olt listed under devices' self.__fields = testCaseUtils.parse_fields(statusLines, '|') self.__oltDeviceId = self.__fields[1].strip() testCaseUtils.send_command_to_voltha_cli( testCaseUtils.get_dir(self, 'log'), 'voltha_olt_device.log', 'device ' + self.__oltDeviceId, 'voltha_olt_ports.log', 'ports', 'voltha_olt_flows.log', 'flows') testCaseUtils.print_log_file(self, 'voltha_olt_ports.log') testCaseUtils.print_log_file(self, 'voltha_olt_flows.log')
def check_olt_fields_before_enabling(self): statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltType, 'voltha_devices_before_enable.log') assert statusLines, 'No Olt listed under devices' self.__fields = testCaseUtils.parse_fields(statusLines, '|') self.__oltDeviceId = self.__fields[1].strip() logging.debug("OLT device id = %s" % self.__oltDeviceId) adminState = self.__fields[3].strip() assert adminState == 'PREPROVISIONED', 'Admin State not PREPROVISIONED' hostPort = self.__fields[4].strip() assert hostPort, 'hostPort field is empty' hostPortFields = hostPort.split(":") assert hostPortFields[0].strip() == self.__oltIpAddress or hostPortFields[1] == str(self.__oltPort), \ 'Olt IP or Port does not match'
def proceed(self): logging.info('Pre-provisioning hold') onuOnline = 0 if self.__oltType == 'ponsim_olt': portType = 'PON_OLT' while onuOnline < self.__onuCount: testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'), 'voltha_olt_device.log', 'device ' + self.__oltDeviceId, 'voltha_olt_ports.log', 'ports') statusLines = testCaseUtils.get_fields_from_grep_command(self, portType, 'voltha_olt_ports.log') lines = statusLines.splitlines() onuOnline = len(lines) time.sleep(5) logging.info('All ONUs now Online!') elif self.__oltType == 'openolt': while onuOnline < self.__onuCount: testCaseUtils.send_command_to_onos_cli(testCaseUtils.get_dir(self, 'log'), 'voltha_onu_auth.log', 'aaa-users') statusLines = testCaseUtils.get_fields_from_grep_command(self, 'AUTHORIZED', 'voltha_onu_auth.log') lines = statusLines.splitlines() onuOnline = len(lines) time.sleep(5) logging.info('All ONUs now AUTHORIZED')
def retrieve_onu_serial_numbers(self): logging.info('Onu Serial Number Discovery') statusLines = testCaseUtils.get_fields_from_grep_command( self, self.__onuType, 'voltha_devices_after_enable.log') assert statusLines, 'No Onu listed under devices' lines = statusLines.splitlines() assert len( lines ) == self.__onuCount, 'Onu count mismatch found: %s, should be: %s' % ( len(lines), self.__onuCount) for line in lines: self.__fields = testCaseUtils.parse_fields(line, '|') onuSerialNum = self.__fields[5].strip() self.__onuSerialNum.append(onuSerialNum)
def stag_and_ctag_should_match_sadis_entry(self): logging.info('Evaluating sTag and cTag in each packet') statusLines = testCaseUtils.get_fields_from_grep_command( self, '802.1Q', self.TCPDUMP_FILENAME) assert statusLines, 'tcpdump contains no 802.1Q tagged packets' lines = statusLines.splitlines() for line in lines: header, tagId, after = line.partition('802.1Q') self.__fields = testCaseUtils.parse_fields(after, ',') stag = self.__fields[1].strip().split( ':')[1].strip().split()[1].strip() before, tagId, after = line.rpartition('802.1Q') self.__fields = testCaseUtils.parse_fields(after, ',') ctag = self.__fields[1].strip().split()[1].strip() self.stag_and_ctag_should_match_sadis_file(ctag, stag)
def should_have_ips_assigned_to_all_onus(self): logging.info('Verifying IP Address assignment on all ONUs') testCaseUtils.send_command_to_onos_cli( testCaseUtils.get_dir(self, 'log'), '_voltha_onos_dhcpl2relay_allocations.log', 'dhcpl2relay-allocations') statusLines = testCaseUtils.get_fields_from_grep_command( self, 'DHCPACK', '_voltha_onos_dhcpl2relay_allocations.log') assert statusLines, 'No DHCP addresses allocated' lines = statusLines.splitlines() assert len( lines ) == self.__onuCount, 'Allocated IPs does not match ONU count but result was %s' % len( lines) for line in lines: self.__fields = testCaseUtils.parse_fields(line, ',') allocIp = self.__fields[5].strip() allocated, delimiter, ipAddr = allocIp.partition('=') assert ipAddr != '0.0.0.0', 'Invalid IP Address Allocated'
def should_now_have_two_dhcp_flows(self): testCaseUtils.send_command_to_onos_cli( testCaseUtils.get_dir(self, 'log'), 'voltha_onos_flows.log', 'flows -s') statusLines = testCaseUtils.get_fields_from_grep_command( self, 'IP_PROTO:17', 'voltha_onos_flows.log') assert statusLines, 'No DHCP Detection flows' lines = statusLines.splitlines() assert len( lines ) >= 2, 'Expected at least 2 DHCP Detection Flows but result was %s' % len( lines) for line in lines: self.__fields = testCaseUtils.parse_fields(line, ',') inPortStr = self.__fields[5].strip() selector, delimiter, inPort = inPortStr.partition('=[') assert ( inPort == 'IN_PORT:2' or inPort == 'IN_PORT:128' ), 'DHCP detection flows not associated with expected ports'
def olt_ports_should_be_enabled_and_active(self): statusLines = testCaseUtils.get_fields_from_grep_command( self, self.__oltDeviceId, 'voltha_olt_ports.log') assert statusLines, 'No Olt device listed under ports' lines = statusLines.splitlines() for line in lines: self.__fields = testCaseUtils.parse_fields(line, '|') assert (self.check_states(self.__oltDeviceId) is True ), 'States of %s does match expected ' % self.__oltDeviceId portType = self.__fields[3].strip() assert (portType == 'ETHERNET_NNI' or portType == 'PON_OLT' or portType == 'ETHERNET_UNI'),\ 'Port type for %s does not match expected ETHERNET_NNI or PON_OLT' % self.__oltDeviceId if portType == 'PON_OLT': self.__peers = self.__fields[7].strip() peerFields = self.__peers.split(',') peerDevices = peerFields[1::2] for peerDevice in peerDevices: deviceFields = peerDevice.split(':') deviceId = deviceFields[1].replace("'", "").replace( 'u', '').rstrip("}]").strip() assert deviceId in self.__onuDeviceIds, 'ONU Device %s not found as Peer' % deviceId
def logical_device(self): logging.info('Logical Device Info') testCaseUtils.send_command_to_voltha_cli( testCaseUtils.get_dir(self, 'log'), 'voltha_logical_devices.log', 'logical_devices') testCaseUtils.print_log_file(self, 'voltha_logical_devices.log') statusLines = testCaseUtils.get_fields_from_grep_command( self, '-i olt', 'voltha_logical_devices.log') assert statusLines, 'No Logical Device listed under logical devices' self.__fields = testCaseUtils.parse_fields(statusLines, '|') self.__logicalDeviceId = self.__fields[1].strip() testCaseUtils.send_command_to_voltha_cli( testCaseUtils.get_dir(self, 'log'), 'voltha_logical_device.log', 'logical_device ' + self.__logicalDeviceId, 'voltha_logical_device_ports.log', 'ports', 'voltha_logical_device_flows.log', 'flows') assert os.path.exists(testCaseUtils.get_dir(self, 'log') + '/voltha_logical_device.log') and \ (os.path.getsize(testCaseUtils.get_dir(self, 'log') + '/voltha_logical_device.log') is 0), \ 'voltha_logical_device.log is not 0 length' testCaseUtils.print_log_file(self, 'voltha_logical_device_ports.log') testCaseUtils.print_log_file(self, 'voltha_logical_device_flows.log')
def onu_ports_should_be_enabled_and_active(self): for onuDeviceId in self.__onuDeviceIds: statusLines = testCaseUtils.get_fields_from_grep_command(self, onuDeviceId, 'voltha_onu_ports_' + \ str(self.__onuDeviceIds.index(onuDeviceId)) + '.log') assert statusLines, 'No Onu device listed under ports' lines = statusLines.splitlines() for line in lines: self.__fields = testCaseUtils.parseFields(line) assert self.check_states( onuDeviceId ) == True, 'States of %s does match expected ' % onuDeviceId portType = self.__fields[3].strip() assert (portType == 'ETHERNET_UNI' or portType == 'PON_ONU'),\ 'Port type for %s does not match expected ETHERNET_UNI or PON_ONU' % onuDeviceId if portType == 'PON_ONU': self.__peers = self.__fields[7].strip() peerFields = self.__peers.split(',') peerDevice = peerFields[1] deviceFields = peerDevice.split(':') deviceId = deviceFields[1].replace("'", "").replace( 'u', '').rstrip("}]").strip() assert deviceId == self.__oltDeviceId, 'OLT Device %s not found as Peer' % deviceId
def onuDiscovery(self): logging.info('Onu Discovery') statusLines = testCaseUtils.get_fields_from_grep_command( self, self.__onuType, 'voltha_devices_after_enable.log') assert statusLines, 'No Onu listed under devices' lines = statusLines.splitlines() for line in lines: self.__fields = testCaseUtils.parseFields(line) onuDeviceId = self.__fields[1].strip() self.__onuDeviceIds.append(onuDeviceId) testCaseUtils.send_command_to_voltha_cli( testCaseUtils.getDir(self, 'log'), 'voltha_onu_device_' + str(self.__onuDeviceIds.index(onuDeviceId)) + '.log', 'device ' + onuDeviceId, 'voltha_onu_ports_' + str(self.__onuDeviceIds.index(onuDeviceId)) + '.log', 'ports', 'voltha_onu_flows_' + str(self.__onuDeviceIds.index(onuDeviceId)) + '.log', 'flows') testCaseUtils.printLogFile( self, 'voltha_onu_ports_' + str(self.__onuDeviceIds.index(onuDeviceId)) + '.log') testCaseUtils.printLogFile( self, 'voltha_onu_flows_' + str(self.__onuDeviceIds.index(onuDeviceId)) + '.log')
def status_should_be_success_after_preprovision_command(self): statusLines = testCaseUtils.get_fields_from_grep_command(self, 'success', 'voltha_preprovision_olt.log') assert statusLines, 'Preprovision Olt command should have returned success but did not'
def status_should_be_success_after_enable_command(self): statusLines = testCaseUtils.get_fields_from_grep_command(self, 'success', 'voltha_enable.log') assert statusLines, 'Enable command should have returned success but did not'