def manual_verification(self, cid, eid, attributes):
        # Trim off read-only attributes from ones passed in

        me_map = self._device.me_map
        ro_set = {AA.R}
        ro_attrs = {
            attr.field.name
            for attr in me_map[cid].attributes if attr.access == ro_set
        }
        attributes = {k: v for k, v in attributes.items() if k not in ro_attrs}
        attributes_to_fix = dict()

        try:
            while len(attributes):
                frame = MEFrame(me_map[cid], eid, attributes).get()
                self.strobe_watchdog()
                results = yield self._device.omci_cc.send(frame)
                omci_message = results.fields['omci_message'].fields
                status = omci_message['success_code']

                if status == RC.UnknownEntity.value:
                    self.strobe_watchdog()
                    results = yield self.create_instance(
                        me_map[cid], eid, attributes)
                    returnValue((results[0], results[1]))

                if status != RC.Success.value:
                    self.log.error('manual-check-get-failed',
                                   cid=cid,
                                   eid=eid,
                                   attributes=attributes,
                                   status=status)
                    returnValue((1, 0))

                onu_attr = {k: v for k, v in omci_message['data'].items()}
                attributes_to_fix.update({
                    k: v
                    for k, v in onu_attr.items()
                    if k in attributes and v != attributes[k]
                })
                attributes = {
                    k: v
                    for k, v in attributes if k not in onu_attr.keys()
                }

            if len(attributes_to_fix) > 0:
                try:
                    frame = MEFrame(me_map[cid], eid, attributes_to_fix).set()
                    self.strobe_watchdog()
                    yield self._device.omci_cc.send(frame)
                    returnValue((1, 0))

                except Exception as _e:
                    returnValue((0, 1))

        except Exception as e:
            self.log.exception('manual-check-failed', e=e, cid=cid, eid=eid)
            raise
Example #2
0
    def perform_test_omci(self):
        """
        Perform the initial test request
        """
        ani_g_entities = self._device.configuration.ani_g_entities
        ani_g_entities_ids = ani_g_entities.keys() if ani_g_entities \
                                                      is not None else None
        self._entity_id = ani_g_entities_ids[0]

        self.log.info('perform-test',
                      entity_class=self._entity_class,
                      entity_id=self._entity_id)
        try:
            frame = MEFrame(self._entity_class, self._entity_id, []).test()
            result = yield self._device.omci_cc.send(frame)
            if not result.fields['omci_message'].fields['success_code']:
                self.log.info(
                    'Self-Test Submitted Successfully',
                    code=result.fields['omci_message'].fields['success_code'])
            else:
                raise TestFailure('Test Failure: {}'.format(
                    result.fields['omci_message'].fields['success_code']))
        except TimeoutError as e:
            self.deferred.errback(failure.Failure(e))

        except Exception as e:
            self.log.exception('perform-test',
                               e=e,
                               class_id=self._entity_class,
                               entity_id=self._entity_id)
            self.deferred.errback(failure.Failure(e))
Example #3
0
    def perform_get_omci(self):
        """
        Perform the initial get request
        """
        self.log.info('perform-get')

        try:
            frame = MEFrame(self._entity_class, self._entity_id,
                            self._attributes).get()
            self.strobe_watchdog()
            results = yield self._device.omci_cc.send(frame)

            status = results.fields['omci_message'].fields['success_code']
            self.log.info('perform-get-status', status=status)

            # Success?
            if status == RC.Success.value:
                self._results = results
                results_omci = results.fields['omci_message'].fields

                # Were all attributes fetched?
                missing_attr = frame.fields['omci_message'].fields['attributes_mask'] ^ \
                    results_omci['attributes_mask']

                if missing_attr > 0:
                    self.strobe_watchdog()
                    self._local_deferred = reactor.callLater(
                        0, self.perform_get_missing_attributes, missing_attr)
                    returnValue(self._local_deferred)

            elif status == RC.AttributeFailure.value:
                # What failed?  Note if only one attribute was attempted, then
                # that is an overall failure

                if not self._allow_failure or len(self._attributes) <= 1:
                    raise GetException(
                        'Get failed with status code: {}'.format(
                            RC.AttributeFailure.value))

                self.strobe_watchdog()
                self._local_deferred = reactor.callLater(
                    0, self.perform_get_failed_attributes, results,
                    self._attributes)
                returnValue(self._local_deferred)

            else:
                raise GetException(
                    'Get failed with status code: {}'.format(status))

            self.log.info('get-completed')
            self.deferred.callback(self)

        except Exception as e:
            self.log.exception('perform-get',
                               e=e,
                               class_id=self._entity_class,
                               entity_id=self._entity_id,
                               attributes=self._attributes)
            self.deferred.errback(failure.Failure(e))
    def perform_get_failed_attributes(self, tmp_results, attributes):
        """

        :param tmp_results:
        :param attributes:
        :return:
        """
        self.log.debug('perform-get-failed', attrs=attributes)

        for attr in attributes:
            try:
                frame = MEFrame(self._entity_class, self._entity_id,
                                {attr}).get()

                self.strobe_watchdog()
                results = yield self._device.omci_cc.send(frame)

                status = results.fields['omci_message'].fields['success_code']

                if status == RC.AttributeFailure.value:
                    self.log.debug('unknown-or-invalid-attribute',
                                   attr=attr,
                                   status=status)
                    self._failed_or_unknown_attributes.add(attr)

                elif status != RC.Success.value:
                    self.log.warn('invalid-get',
                                  class_id=self._entity_class,
                                  attribute=attr,
                                  status=status)
                    self._failed_or_unknown_attributes.add(attr)

                else:
                    # Add to partial results and correct the status
                    tmp_results.fields['omci_message'].fields[
                        'success_code'] = status
                    tmp_results.fields['omci_message'].fields['attributes_mask'] |= \
                        results.fields['omci_message'].fields['attributes_mask']

                    if tmp_results.fields['omci_message'].fields.get(
                            'data') is None:
                        tmp_results.fields['omci_message'].fields[
                            'data'] = dict()

                    tmp_results.fields['omci_message'].fields['data'][attr] = \
                        results.fields['omci_message'].fields['data'][attr]

            except TimeoutError as e:
                self.log.debug('attr-timeout')

            except Exception as e:
                self.log.exception('attr-failure', e=e)

        self._results = tmp_results
        self.deferred.callback(self)
    def create_instance(self, cid, eid, attributes):
        try:
            me_map = self._device.me_map
            frame = MEFrame(me_map[cid], eid, attributes).create()

            self.strobe_watchdog()
            results = yield self._device.omci_cc.send(frame)
            status = results.fields['omci_message'].fields['success_code']
            if status == RC.Success.value or status == RC.InstanceExists.value:
                returnValue((1, 0))

            self.log.error('manual-check-create-failed',
                           cid=cid,
                           eid=eid,
                           attributes=attributes,
                           status=status)
            returnValue((0, 1))

        except Exception as e:
            self.log.exception('manual-check-failed', e=e, cid=cid, eid=eid)
            raise
Example #6
0
    def perform_get_omci(self):
        """
        Perform the initial get request
        """
        self.log.info('perform-get', entity_class=self._entity_class,
                      entity_id=self._entity_id, attributes=self._attributes)
        try:
            # If one or more attributes is a table attribute, get it separately
            first_attributes = self.select_first_attributes()
            table_attributes = {attr for attr in self._attributes if self.is_table_attr(attr)}

            if len(first_attributes):
                frame = MEFrame(self._entity_class, self._entity_id, first_attributes).get()
                self.strobe_watchdog()
                results = yield self._device.omci_cc.send(frame)

                status = results.fields['omci_message'].fields['success_code']
                self.log.debug('perform-get-status', status=status)

                if status == RC.AttributeFailure.value:
                    # What failed?  Note if only one attribute was attempted, then
                    # that is an overall failure

                    if not self._allow_failure or len(self._attributes) <= 1:
                        raise GetException('Get failed with status code: {}'.
                                           format(RC.AttributeFailure.value))

                    self.strobe_watchdog()
                    # TODO: update failed & unknown attributes set

                # Success?
                if status in {RC.Success.value, RC.AttributeFailure.value}:
                    self._results = results
                    results_omci = results.fields['omci_message'].fields

                    # Were all attributes fetched?
                    requested_attr = frame.fields['omci_message'].fields['attributes_mask']
                    retrieved_attr = results_omci['attributes_mask']
                    unsupported_attr = results_omci.get('unsupported_attributes_mask', 0) or 0
                    failed_attr = results_omci.get('failed_attributes_mask', 0) or 0
                    not_avail_attr = unsupported_attr | failed_attr
                    missing_attr = requested_attr & ~(retrieved_attr | not_avail_attr)

                    if missing_attr != 0 or len(table_attributes) > 0:
                        self.log.info('perform-get-missing', num_missing=missing_attr,
                                      table_attr=table_attributes)
                        self.strobe_watchdog()
                        self._local_deferred = reactor.callLater(0,
                                                                 self.perform_get_missing_attributes,
                                                                 missing_attr, table_attributes)
                        returnValue(self._local_deferred)

                else:
                    raise GetException('Get failed with status code: {}'.format(status))

                self.log.debug('get-completed')
                self.deferred.callback(self)

            elif len(table_attributes) > 0:
                # Here if only table attributes were requested
                self.log.info('perform-get-table', table_attr=table_attributes)
                self.strobe_watchdog()
                self._local_deferred = reactor.callLater(0,
                                                         self.process_get_table,
                                                         table_attributes)
                returnValue(self._local_deferred)

        except TimeoutError as e:
            self.deferred.errback(failure.Failure(e))

        except Exception as e:
            self.log.exception('perform-get', e=e, class_id=self._entity_class,
                               entity_id=self._entity_id, attributes=self._attributes)
            self.deferred.errback(failure.Failure(e))