Exemplo n.º 1
0
    def update_loadbalancer_status(self, status):
        """Update load balancer status.

        :param status: dictionary defining the provisioning status and
            operating status for load balancer objects, including pools,
            members, listeners, L7 policies, and L7 rules.
            iod (string): ID for the object.
            provisioning_status (string): Provisioning status for the object.
            operating_status (string): Operating status for the object.
        :type status: dict
        :raises: UpdateStatusError
        :returns: None
        """
        try:
            response = self._send(self.status_socket, status)
        except Exception as e:
            raise driver_exceptions.UpdateStatusError(fault_string=str(e))

        if response[constants.STATUS_CODE] != constants.DRVR_STATUS_CODE_OK:
            raise driver_exceptions.UpdateStatusError(
                fault_string=response.pop(constants.FAULT_STRING, None),
                status_object=response.pop(constants.STATUS_OBJECT, None),
                status_object_id=response.pop(constants.STATUS_OBJECT_ID,
                                              None),
                status_record=response.pop(constants.STATUS_RECORD, None))
Exemplo n.º 2
0
 def _process_status_update(self,
                            repo,
                            object_name,
                            record,
                            delete_record=False):
     # Zero it out so that if the ID is missing from a record we do not
     # report the last LB as the failed record in the exception
     record_id = None
     try:
         record_id = record['id']
         record_kwargs = {}
         prov_status = record.get(consts.PROVISIONING_STATUS, None)
         if prov_status:
             if (prov_status == consts.DELETED
                     and object_name == consts.LOADBALANCERS):
                 self._check_for_lb_vip_deallocate(repo, record_id)
             elif prov_status == consts.DELETED and delete_record:
                 repo.delete(self.db_session, id=record_id)
                 return
             record_kwargs[consts.PROVISIONING_STATUS] = prov_status
         op_status = record.get(consts.OPERATING_STATUS, None)
         if op_status:
             record_kwargs[consts.OPERATING_STATUS] = op_status
         if prov_status or op_status:
             repo.update(self.db_session, record_id, **record_kwargs)
     except Exception as e:
         # We need to raise a failure here to notify the driver it is
         # sending bad status data.
         raise driver_exceptions.UpdateStatusError(
             fault_string=str(e),
             status_object_id=record_id,
             status_object=object_name)
Exemplo n.º 3
0
 def _update_status_to_octavia(self, status):
     try:
         self._octavia_driver_lib.update_loadbalancer_status(status)
     except driver_exceptions.UpdateStatusError as e:
         msg = ("Error while updating status to octavia: "
                "%s") % e.fault_string
         LOG.error(msg)
         raise driver_exceptions.UpdateStatusError(msg)
Exemplo n.º 4
0
    def test_UpdateStatusError(self):
        update_status_error = exceptions.UpdateStatusError(
            fault_string=self.user_fault_string,
            status_object=self.fault_object,
            status_object_id=self.fault_object_id,
            status_record=self.fault_record)

        self.assertEqual(self.user_fault_string,
                         update_status_error.fault_string)
        self.assertEqual(self.fault_object, update_status_error.status_object)
        self.assertEqual(self.fault_object_id,
                         update_status_error.status_object_id)
        self.assertEqual(self.fault_record, update_status_error.status_record)
 def _update_status_to_octavia(self, status):
     try:
         self._octavia_driver_lib.update_loadbalancer_status(status)
     except driver_exceptions.UpdateStatusError as e:
         msg = ("Error while updating status to octavia: "
                "%s") % e.fault_string
         LOG.error(msg)
         raise driver_exceptions.UpdateStatusError(msg)
     finally:
         # Update amphora to DELETED if LB is DELETED, so that they get cleaned up together
         amp_repo = AmphoraRepository()
         session = db_apis.get_session()
         lbs = status.get('loadbalancers') or []
         for lb in lbs:
             if lb['provisioning_status'] == lib_consts.DELETED:
                 amp_repo.update(session,
                                 lb['id'],
                                 status=lib_consts.DELETED,
                                 force_provisioning_status=True)
Exemplo n.º 6
0
    def test_update_loadbalancer_status(self, mock_status_update):
        mock_status_update.side_effect = [
            mock.DEFAULT, mock.DEFAULT, mock.DEFAULT, mock.DEFAULT,
            mock.DEFAULT, mock.DEFAULT, mock.DEFAULT,
            driver_exceptions.UpdateStatusError(
                fault_string='boom', status_object='fruit',
                status_object_id='1', status_record='grape'),
            Exception('boom')]
        lb_dict = {"id": 1, lib_consts.PROVISIONING_STATUS: lib_consts.ACTIVE,
                   lib_consts.OPERATING_STATUS: lib_consts.ONLINE}
        list_dict = {"id": 2,
                     lib_consts.PROVISIONING_STATUS: lib_consts.ACTIVE,
                     lib_consts.OPERATING_STATUS: lib_consts.ONLINE}
        pool_dict = {"id": 3,
                     lib_consts.PROVISIONING_STATUS: lib_consts.ACTIVE,
                     lib_consts.OPERATING_STATUS: lib_consts.ONLINE}
        member_dict = {"id": 4,
                       lib_consts.PROVISIONING_STATUS: lib_consts.ACTIVE,
                       lib_consts.OPERATING_STATUS: lib_consts.ONLINE}
        hm_dict = {"id": 5, lib_consts.PROVISIONING_STATUS: lib_consts.ACTIVE,
                   lib_consts.OPERATING_STATUS: lib_consts.ONLINE}
        l7p_dict = {"id": 6, lib_consts.PROVISIONING_STATUS: lib_consts.ACTIVE,
                    lib_consts.OPERATING_STATUS: lib_consts.ONLINE}
        l7r_dict = {"id": 7, lib_consts.PROVISIONING_STATUS: lib_consts.ACTIVE,
                    lib_consts.OPERATING_STATUS: lib_consts.ONLINE}
        status_dict = {lib_consts.LOADBALANCERS: [lb_dict],
                       lib_consts.LISTENERS: [list_dict],
                       lib_consts.POOLS: [pool_dict],
                       lib_consts.MEMBERS: [member_dict],
                       lib_consts.HEALTHMONITORS: [hm_dict],
                       lib_consts.L7POLICIES: [l7p_dict],
                       lib_consts.L7RULES: [l7r_dict]}

        result = self.driver_updater.update_loadbalancer_status(
            copy.deepcopy(status_dict))

        calls = [call(self.mock_member_repo, lib_consts.MEMBERS, member_dict,
                      delete_record=True),
                 call(self.mock_health_repo, lib_consts.HEALTHMONITORS,
                      hm_dict, delete_record=True),
                 call(self.mock_pool_repo, lib_consts.POOLS, pool_dict,
                      delete_record=True),
                 call(self.mock_l7r_repo, lib_consts.L7RULES, l7r_dict,
                      delete_record=True),
                 call(self.mock_l7p_repo, lib_consts.L7POLICIES, l7p_dict,
                      delete_record=True),
                 call(self.mock_list_repo, lib_consts.LISTENERS, list_dict,
                      delete_record=True),
                 call(self.mock_lb_repo, lib_consts.LOADBALANCERS,
                      lb_dict)]
        mock_status_update.assert_has_calls(calls)
        self.assertEqual(self.ref_ok_response, result)

        # Test empty status updates
        mock_status_update.reset_mock()
        result = self.driver_updater.update_loadbalancer_status({})
        mock_status_update.assert_not_called()
        self.assertEqual(self.ref_ok_response, result)

        # Test UpdateStatusError case
        ref_update_status_error = {
            lib_consts.FAULT_STRING: 'boom',
            lib_consts.STATUS_CODE: lib_consts.DRVR_STATUS_CODE_FAILED,
            lib_consts.STATUS_OBJECT: 'fruit',
            lib_consts.STATUS_OBJECT_ID: '1'}
        result = self.driver_updater.update_loadbalancer_status(
            copy.deepcopy(status_dict))
        self.assertEqual(ref_update_status_error, result)

        # Test general exceptions
        result = self.driver_updater.update_loadbalancer_status(
            copy.deepcopy(status_dict))
        self.assertEqual({
            lib_consts.STATUS_CODE: lib_consts.DRVR_STATUS_CODE_FAILED,
            lib_consts.FAULT_STRING: 'boom'}, result)