Exemplo n.º 1
0
 def test_update_admin_status_for_missing_measurement_group(self):
     try:
         measurement_group_service.update_admin_status(None, 'UNLOCKED')
     except InvalidDataException as e:
         self.assertEqual(
             e.args[0], 'Requested measurement group not available '
             'for admin status update')
Exemplo n.º 2
0
 def test_update_admin_status_to_locking(self):
     super().setUp()
     sub = create_subscription_data('sub')
     nf_list = create_multiple_network_function_data(['pnf_101', 'pnf_102'])
     db.session.add(sub)
     for nf in nf_list:
         nf_service.save_nf(nf)
         measurement_group_service. \
             apply_nf_status_to_measurement_group(nf.nf_name, sub.measurement_groups[0].
                                                  measurement_group_name,
                                                  MgNfState.CREATED.value)
     db.session.commit()
     measurement_group_service.update_admin_status(
         sub.measurement_groups[0], 'LOCKED')
     meas_grp = measurement_group_service.query_meas_group_by_name(
         'sub', 'MG1')
     self.assertEqual(meas_grp.subscription_name, 'sub')
     self.assertEqual(meas_grp.measurement_group_name, 'MG1')
     self.assertEqual(meas_grp.administrative_state, 'LOCKING')
     meas_group_nfs = db.session.query(NfMeasureGroupRelationalModel).filter(
         NfMeasureGroupRelationalModel.measurement_grp_name == meas_grp.measurement_group_name)\
         .all()
     for nf in meas_group_nfs:
         self.assertEqual(nf.nf_measure_grp_status,
                          MgNfState.PENDING_DELETE.value)
Exemplo n.º 3
0
 def test_update_admin_status_for_same_state(self):
     super().setUp()
     sub = create_subscription_data('sub1')
     try:
         measurement_group_service.update_admin_status(
             sub.measurement_groups[0], 'UNLOCKED')
     except InvalidDataException as e:
         self.assertEqual(
             e.args[0], 'Measurement group is already in UNLOCKED '
             'state for sub name: sub1  and meas group '
             'name: MG1')
Exemplo n.º 4
0
 def test_update_admin_status_to_locked(self):
     super().setUp()
     sub = create_subscription_data('sub')
     db.session.add(sub)
     measurement_group_service.update_admin_status(
         sub.measurement_groups[0], 'LOCKED')
     meas_grp = measurement_group_service.query_meas_group_by_name(
         'sub', 'MG1')
     self.assertEqual(meas_grp.subscription_name, 'sub')
     self.assertEqual(meas_grp.measurement_group_name, 'MG1')
     self.assertEqual(meas_grp.administrative_state, 'LOCKED')
Exemplo n.º 5
0
 def test_update_admin_status_for_data_conflict(self):
     super().setUp()
     sub = create_subscription_data('sub1')
     sub.measurement_groups[0].administrative_state = 'LOCKING'
     try:
         measurement_group_service.update_admin_status(
             sub.measurement_groups[0], 'LOCKED')
     except DataConflictException as e:
         self.assertEqual(
             e.args[0], 'Cannot update admin status as Locked request'
             ' is in progress for sub name: sub1  and '
             'meas group name: MG1')
Exemplo n.º 6
0
def update_admin_state(subscription_name, measurement_group_name, body):
    """
    Performs administrative state update for the respective subscription
    and measurement group name

    Args:
        subscription_name (String): Name of the subscription.
        measurement_group_name (String): Name of the measurement group
        body (dict): Request body with admin state to update.
    Returns:
       string, HTTPStatus: Successfully updated admin state, 200
       string, HTTPStatus: Invalid request details, 400
       string, HTTPStatus: Cannot update as Locked request is in progress, 409
       string, HTTPStatus: Exception details of server failure, 500
    """
    logger.info(
        'Performing administration status update for measurement group '
        f'with sub name: {subscription_name} and measurement '
        f'group name: {measurement_group_name} to {body["administrativeState"]} status'
    )
    response = 'Successfully updated admin state', HTTPStatus.OK.value
    try:
        meas_group = measurement_group_service.query_meas_group_by_name(
            subscription_name, measurement_group_name)
        measurement_group_service.update_admin_status(
            meas_group, body["administrativeState"])
    except InvalidDataException as exception:
        logger.error(exception.args[0])
        response = exception.args[0], HTTPStatus.BAD_REQUEST.value
    except DataConflictException as exception:
        logger.error(exception.args[0])
        response = exception.args[0], HTTPStatus.CONFLICT.value
    except Exception as exception:
        logger.error(
            'Update admin status request was not processed for sub name: '
            f'{subscription_name} and meas group name: '
            f'{measurement_group_name} due to Exception : {exception}')
        response = 'Update admin status request was not processed for sub name: '\
                   f'{subscription_name} and meas group name: {measurement_group_name}'\
                   f' due to Exception : {exception}', HTTPStatus.INTERNAL_SERVER_ERROR

    return response
Exemplo n.º 7
0
 def test_update_admin_status_to_unlocking(self, mock_filter_call,
                                           mock_model_aai, mock_aai):
     mock_aai.return_value = json.loads(self.aai_response_data)
     mock_model_aai.return_value = json.loads(self.good_model_info)
     super().setUp()
     sub = create_subscription_data('sub')
     db.session.add(sub)
     db.session.commit()
     mock_filter_call.return_value = NetworkFunctionFilter.get_network_function_filter(
         'sub')
     measurement_group_service.update_admin_status(
         sub.measurement_groups[1], 'UNLOCKED')
     meas_grp = measurement_group_service.query_meas_group_by_name(
         'sub', 'MG2')
     self.assertEqual(meas_grp.subscription_name, 'sub')
     self.assertEqual(meas_grp.measurement_group_name, 'MG2')
     self.assertEqual(meas_grp.administrative_state, 'UNLOCKED')
     meas_group_nfs = db.session.query(NfMeasureGroupRelationalModel).filter(
         NfMeasureGroupRelationalModel.measurement_grp_name == meas_grp.measurement_group_name)\
         .all()
     for nf in meas_group_nfs:
         self.assertEqual(nf.nf_measure_grp_status,
                          MgNfState.PENDING_CREATE.value)