Пример #1
0
    def test_update_cna_pvid(self):
        """Validates the update_cna_pvid method."""
        def build_mock():
            # Need to rebuild.  Since it returns itself a standard reset will
            # recurse infinitely.
            cna = mock.MagicMock()
            cna.refresh.return_value = cna
            return cna

        self._mock_feed(self.vios_feed_resp)

        # Attempt happy path
        cna = build_mock()
        utils.update_cna_pvid(cna, 5)
        self.assertEqual(5, cna.pvid)
        self.assertEqual(1, cna.update.call_count)

        # Raise an error 3 times and make sure it eventually re-raises the root
        # etag exception
        cna = build_mock()
        err_resp = mock.MagicMock()
        err_resp.status = pvm_const.HTTPStatus.ETAG_MISMATCH
        error = pvm_exc.HttpError(err_resp)

        cna.update.side_effect = [error, error, error]
        self.assertRaises(pvm_exc.HttpError, utils.update_cna_pvid, cna, 5)
        self.assertEqual(3, cna.update.call_count)
        self.assertEqual(2, cna.refresh.call_count)

        # Raise an error 2 times and then eventually works
        cna = build_mock()
        cna.update.side_effect = [error, error, None]
        utils.update_cna_pvid(cna, 5)
        self.assertEqual(3, cna.update.call_count)
        self.assertEqual(2, cna.refresh.call_count)

        # Immediate re-raise of different type of exception
        cna = build_mock()
        err_resp.status = pvm_const.HTTPStatus.UNAUTHORIZED
        cna.update.side_effect = pvm_exc.HttpError(err_resp)

        self.assertRaises(pvm_exc.HttpError, utils.update_cna_pvid, cna, 5)
        self.assertEqual(1, cna.update.call_count)
        self.assertEqual(0, cna.refresh.call_count)
Пример #2
0
    def test_update_cna_pvid(self):
        """Validates the update_cna_pvid method."""
        def build_mock():
            # Need to rebuild.  Since it returns itself a standard reset will
            # recurse infinitely.
            cna = mock.MagicMock()
            cna.refresh.return_value = cna
            return cna

        self._mock_feed(self.vios_feed_resp)

        # Attempt happy path
        cna = build_mock()
        utils.update_cna_pvid(cna, 5)
        self.assertEqual(5, cna.pvid)
        self.assertEqual(1, cna.update.call_count)

        # Raise an error 3 times and make sure it eventually re-raises the root
        # etag exception
        cna = build_mock()
        err_resp = mock.MagicMock()
        err_resp.status = pvm_const.HTTPStatus.ETAG_MISMATCH
        error = pvm_exc.HttpError(err_resp)

        cna.update.side_effect = [error, error, error]
        self.assertRaises(pvm_exc.HttpError, utils.update_cna_pvid, cna, 5)
        self.assertEqual(3, cna.update.call_count)
        self.assertEqual(2, cna.refresh.call_count)

        # Raise an error 2 times and then eventually works
        cna = build_mock()
        cna.update.side_effect = [error, error, None]
        utils.update_cna_pvid(cna, 5)
        self.assertEqual(3, cna.update.call_count)
        self.assertEqual(2, cna.refresh.call_count)

        # Immediate re-raise of different type of exception
        cna = build_mock()
        err_resp.status = pvm_const.HTTPStatus.UNAUTHORIZED
        cna.update.side_effect = pvm_exc.HttpError(err_resp)

        self.assertRaises(pvm_exc.HttpError, utils.update_cna_pvid, cna, 5)
        self.assertEqual(1, cna.update.call_count)
        self.assertEqual(0, cna.refresh.call_count)
Пример #3
0
    def _update_req(self, request, lpar_uuids):
        """Attempts to provision a given UpdateVLANRequest.

        :param request: The UpdateVLANRequest.
        :return: True if the request was successfully processed.  False if it
                 was not able to process.
        """
        # Pull the ProvisionRequest off the VLAN Update call.
        p_req = request.p_req
        client_adpts = []

        try:
            if p_req.lpar_uuid in lpar_uuids:
                # Get the adapters just for the VM that the request is for.
                client_adpts = utils.list_cnas(self.adapter, self.host_uuid,
                                               lpar_uuid=p_req.lpar_uuid)
                cna = utils.find_cna_for_mac(p_req.mac_address, client_adpts)
                if cna:
                    # If the PVID does not match, update the CNA.
                    if cna.pvid != p_req.segmentation_id:
                        utils.update_cna_pvid(cna, p_req.segmentation_id)
                    LOG.info(_LI("Sending update device for %s"),
                             p_req.mac_address)
                    self.agent.update_device_up(p_req.rpc_device)
                    self._remove_request(request)
                    return

        except Exception as e:
            LOG.warn(_LW("An error occurred while attempting to update the "
                         "PVID of the virtual NIC."))
            LOG.exception(e)

        # Increment the request count.
        request.attempt_count += 1
        if request.attempt_count >= ACONF.pvid_update_loops:
            # If it had been on the system...this is an error.
            if p_req.lpar_uuid in lpar_uuids:
                self._mark_failed(p_req, client_adpts)

            # Remove the request from the overall queue
            self._remove_request(request)