def test_manager(self, mock_get_inst): mgr = manager.NvramManager(self.fake_store, mock.Mock(), mock.Mock()) mgr.store(powervm.TEST_INST1) mgr.store(powervm.TEST_INST2) mgr.fetch(powervm.TEST_INST2) mgr.remove(powervm.TEST_INST2) # Simulate a quick repeated stores of the same LPAR by poking the Q. mgr._queue.put(powervm.TEST_INST1) mgr._queue.put(powervm.TEST_INST1) mgr._queue.put(powervm.TEST_INST2) time.sleep(0) mgr.shutdown() self.mock_store.assert_has_calls([ mock.call(powervm.TEST_INST1, mock.ANY), mock.call(powervm.TEST_INST2, mock.ANY) ]) self.mock_fetch.assert_called_with(powervm.TEST_INST2) self.mock_remove.assert_called_with(powervm.TEST_INST2) # Test when fetch returns an exception mgr_exp = manager.NvramManager(self.fake_exp_store, mock.Mock(), mock.Mock()) self.assertRaises(api.NVRAMDownloadException, mgr_exp.fetch, powervm.TEST_INST2) # Test exception being logged but not raised during remove mgr_exp.remove(powervm.TEST_INST2) self.mock_remove.assert_called_with(powervm.TEST_INST2)
def test_store_with_not_found_exc(self, mock_get_inst, mock_log): mock_resp = mock.Mock() mock_resp.status = 404 mock_resp.reqpath = ( '/rest/api/uom/ManagedSystem/c5d782c7-44e4-3086-ad15-' 'b16fb039d63b/LogicalPartition/1B5FB633-16D1-4E10-A14' '5-E6FB905161A3?group=None') mock_get_inst.side_effect = pvm_exc.HttpError(mock_resp) mgr = manager.NvramManager(self.fake_store, mock.Mock(), mock.Mock()) mgr.store(powervm.TEST_INST1) mock_log.assert_not_called()
def test_store_with_exception(self, mock_get_inst, mock_log): mock_resp = mock.Mock() mock_resp.status = 410 mock_resp.reqpath = ( '/rest/api/uom/ManagedSystem/c5d782c7-44e4-3086-ad15-' 'b16fb039d63b/LogicalPartition/1B5FB633-16D1-4E10-A14' '5-E6FB905161A3?group=None') mock_get_inst.side_effect = pvm_exc.HttpError(mock_resp) mgr = manager.NvramManager(self.fake_store, mock.Mock(), mock.Mock()) mgr.store(powervm.TEST_INST1) mock_log.assert_called_once_with(u'Unable to store the NVRAM for ' u'instance: %s', powervm.TEST_INST1.name)
def test_store_with_not_found_exc(self, mock_get_inst, mock_log): mock_get_inst.side_effect = pvm_exc.HttpNotFound(mock.Mock()) mgr = manager.NvramManager(self.fake_store, mock.Mock(), mock.Mock()) mgr.store(powervm.TEST_INST1.uuid) self.assertEqual(0, mock_log.call_count)
def test_store_with_exception(self, mock_get_inst, mock_log): mock_get_inst.side_effect = pvm_exc.HttpError(mock.Mock()) mgr = manager.NvramManager(self.fake_store, mock.Mock(), mock.Mock()) mgr.store(powervm.TEST_INST1.uuid) self.assertEqual(1, mock_log.call_count)