def __init__(self, conf, logger): """ Constructor for PutRequestBuilder. """ self.logger = logger #self.logger.debug("AccountReport constructed") self.__account_service_communicator = AccountServiceCommunicator(conf, self.logger)
class TestAccountServiceCommunicator(unittest.TestCase): @mock.patch("osd.common.ring.ring.Req", mockReq) @mock.patch("osd.common.ring.ring.Resp", mockResp) @mock.patch("osd.common.ring.ring.RingFileReadHandler", FakeRingFileReadHandler) @mock.patch("osd.common.ring.ring.ServiceInfo", mockServiceInfo) @mock.patch("osd.common.ring.ring.ContainerRing.get_directory_by_hash", fake_get_directory_by_hash) @mock.patch("osd.accountUpdaterService.communicator.ConnectionCreator", FakeConnectionCreator) def setUp(self): self.account_service_communicator = AccountServiceCommunicator(conf, logger) def test_update_container_stat_info_with_202(self): with mock.patch('osd.accountUpdaterService.unitTests.FakeConnectionCreator.get_http_connection_instance', return_value=FakeConnection(202)): self.assertEquals(self.account_service_communicator.update_container_stat_info("acc", "stat_info"), True) def test_update_container_stat_info_with_404(self): with mock.patch('osd.accountUpdaterService.unitTests.FakeConnectionCreator.get_http_connection_instance', return_value=FakeConnection(404)): self.assertEquals(self.account_service_communicator.update_container_stat_info("acc", "stat_info"), True) def test_update_container_stat_info_with_500(self): with mock.patch('osd.accountUpdaterService.unitTests.FakeConnectionCreator.get_http_connection_instance', return_value=FakeConnection(500)): self.assertEquals(self.account_service_communicator.update_container_stat_info("acc", "stat_info"), False) @mock.patch("osd.accountUpdaterService.monitor.GlobalVariables", FakeGlobalVariables) def test_update_container_stat_info_with_301(self): with mock.patch('osd.accountUpdaterService.unitTests.FakeConnectionCreator.get_http_connection_instance', return_value=FakeConnection(301)): self.assertEquals(self.account_service_communicator.update_container_stat_info("acc", "stat_info"), False)
class AccountReport: """ Club the multiple container stat info together. Send the stat info the account service. """ def __init__(self, conf, logger): """ Constructor for PutRequestBuilder. """ self.logger = logger #self.logger.debug("AccountReport constructed") self.__account_service_communicator = AccountServiceCommunicator(conf, self.logger) def container_report_to_account_service(self, account_instance): """ Build the put request. :param account_instance: instance of AccountInfo class """ self.logger.debug('Enter in container_report_to_account_service') account_instance.acc_update_failed = False self.container_stat_info = [] for reader in account_instance.record_instance: self.container_stat_info.append(reader.stat_info) ret = self.__account_service_communicator.update_container_stat_info(\ account_instance.account_name, self.container_stat_info) if ret: for reader in account_instance.record_instance: reader.stat_info = {} account_instance.record_instance = [] else: account_instance.acc_update_failed = True return ret
def setUp(self): self.account_service_communicator = AccountServiceCommunicator( conf, logger)