def assert_mutate_function_retries_until_success( self, mutate_callable, expected_args, success_response, expected_result): """ Assert that some CLB function that mutates the CLB will retry on pending update until the function succeeds. :param mutate_callable: a callable which takes a clb argument and a clock argument - this callable should call the CLB's mutate function with the required arguments and return the function's return value. For example: ``lambda clb, clk: clb.update_node(..., clock=clk)`` :param expected_args: What are the expected treq arguments? This should be an array of [method, url, (expected args, expected kwargs)] :param success_response: a tuple of (Response, string response body) which should be the successful response back from the API :param expected_result: What is the expected successful result of the function that is called by ``mutate_callable`` """ clock = Clock() clb = self.get_clb(*(expected_args + pending_update_response)) d = mutate_callable(clb, clock) self.assertNoResult(d) clock.pump([3]) self.assertNoResult(d) clb.treq = get_fake_treq( *([self] + expected_args + [success_response])) clock.pump([3]) self.assertEqual(self.successResultOf(d), expected_result)
def test_sequenced_behaviors(self): """ Cause a sequence of behaviors, and succeeds on 201. When a test case is provided for which a cleanup should be added, delete is added as a cleanup. """ criteria = [{"server_name": "name_criteria_.*"}] behaviors = [{"name": "behavior name", "parameters": {"behavior": "params"}}] _treq = get_fake_treq( self, "POST", "mimicnovaurl/behaviors/some_event", ( (json.dumps({"criteria": criteria, "name": "sequence", "parameters": {"behaviors": behaviors}}),), self.expected_kwargs, ), (Response(201), '{"id": "behavior_id"}'), ) test_case = _get_fake_test_case(_treq, self.delete_treq) mimic_nova = MimicNova(pool=self.pool, test_case=test_case, treq=_treq) d = mimic_nova.sequenced_behaviors(self.rcs, criteria, behaviors, event_description="some_event") self.assertEqual("behavior_id", self.successResultOf(d)) self.assertEqual("successfully deleted behavior", self.successResultOf(test_case.cleanup()))
def assert_mutate_function_retries_until_success(self, mutate_callable, expected_args, success_response, expected_result): """ Assert that some CLB function that mutates the CLB will retry on pending update until the function succeeds. :param mutate_callable: a callable which takes a clb argument and a clock argument - this callable should call the CLB's mutate function with the required arguments and return the function's return value. For example: ``lambda clb, clk: clb.update_node(..., clock=clk)`` :param expected_args: What are the expected treq arguments? This should be an array of [method, url, (expected args, expected kwargs)] :param success_response: a tuple of (Response, string response body) which should be the successful response back from the API :param expected_result: What is the expected successful result of the function that is called by ``mutate_callable`` """ clock = Clock() clb = self.get_clb(*(expected_args + pending_update_response)) d = mutate_callable(clb, clock) self.assertNoResult(d) clock.pump([3]) self.assertNoResult(d) clb.treq = get_fake_treq(*([self] + expected_args + [success_response])) clock.pump([3]) self.assertEqual(self.successResultOf(d), expected_result)
def test_sequenced_behaviors(self): """ Cause a sequence of behaviors, and succeeds on 201. When a test case is provided for which a cleanup should be added, delete is added as a cleanup. """ criteria = [{"username": "******"}] behaviors = [{'name': "behavior name", 'parameters': {"behavior": "params"}}] _treq = get_fake_treq( self, 'POST', "/mimic/v1.1/IdentityControlAPI/behaviors/some_event", ((json.dumps({'criteria': criteria, 'name': "sequence", 'parameters': {"behaviors": behaviors}}),), self.expected_kwargs), (Response(201), '{"id": "behavior_id"}')) test_case = _get_fake_test_case(_treq, self.delete_treq) mimic_identity = MimicIdentity(pool=self.pool, test_case=test_case, treq=_treq) d = mimic_identity.sequenced_behaviors( "/identity/v2.0", criteria, behaviors, event_description="some_event") self.assertEqual("behavior_id", self.successResultOf(d)) self.assertEqual("successfully deleted behavior", self.successResultOf(test_case.cleanup()))
def get_clb(self, method, url, treq_args_kwargs, response, str_body): """ Stub out treq, and return a cloud load balancer """ clb = CloudLoadBalancer( pool=self.pool, treq=get_fake_treq(self, method, url, treq_args_kwargs, (response, str_body))) clb.clb_id = 12345 return clb
def get_clb(self, method, url, treq_args_kwargs, response, str_body): """ Stub out treq, and return a cloud load balancer """ clb = CloudLoadBalancer(pool=self.pool, treq=get_fake_treq(self, method, url, treq_args_kwargs, (response, str_body))) clb.clb_id = 12345 return clb
def setUp(self): """ Set up fake pool, treq, responses, and RCS. """ self.pool = object() self.rcs = object() self.expected_kwargs = {'pool': self.pool} self.delete_treq = get_fake_treq( self, 'DELETE', "/mimic/v1.1/IdentityControlAPI/behaviors/some_event/behavior_id", ((), self.expected_kwargs), (Response(204), "successfully deleted behavior"))
def test_change_server_statuses(self): """ Change server statuses calls the right endpoint and succeeds on 201. """ _treq = get_fake_treq( self, 'POST', "mimicnovaurl/attributes", ((json.dumps({'status': {'id1': 'ERROR', 'id2': 'DELETED'}}),), self.expected_kwargs), (Response(201), "successful change response")) d = MimicNova(pool=self.pool, treq=_treq).change_server_statuses( self.rcs, {'id1': 'ERROR', 'id2': 'DELETED'}) self.assertEqual('successful change response', self.successResultOf(d))
def test_change_server_statuses(self): """ Change server statuses calls the right endpoint and succeeds on 201. """ _treq = get_fake_treq( self, "POST", "mimicnovaurl/attributes", ((json.dumps({"status": {"id1": "ERROR", "id2": "DELETED"}}),), self.expected_kwargs), (Response(201), "successful change response"), ) d = MimicNova(pool=self.pool, treq=_treq).change_server_statuses(self.rcs, {"id1": "ERROR", "id2": "DELETED"}) self.assertEqual("successful change response", self.successResultOf(d))
def setUp(self): """ Set up fake pool, treq, responses, and RCS. """ self.pool = object() class FakeRCS(object): endpoints = {'mimic_nova': 'mimicnovaurl'} self.rcs = FakeRCS() self.server_id = 'server_id' self.expected_kwargs = {'pool': self.pool} self.delete_treq = get_fake_treq( self, 'DELETE', "mimicnovaurl/behaviors/some_event/behavior_id", ((), self.expected_kwargs), (Response(204), "successfully deleted behavior"))
def test_change_server_statuses(self): """ Change server statuses calls the right endpoint and succeeds on 201. """ _treq = get_fake_treq( self, 'POST', "mimicnovaurl/attributes", ((json.dumps({'status': { 'id1': 'ERROR', 'id2': 'DELETED' }}), ), self.expected_kwargs), (Response(201), "successful change response")) d = MimicNova(pool=self.pool, treq=_treq).change_server_statuses( self.rcs, { 'id1': 'ERROR', 'id2': 'DELETED' }) self.assertEqual('successful change response', self.successResultOf(d))
def test_sequenced_behaviors(self): """ Cause a sequence of behaviors, and succeeds on 201. When a test case is provided for which a cleanup should be added, delete is added as a cleanup. """ criteria = [{"username": "******"}] behaviors = [{ 'name': "behavior name", 'parameters': { "behavior": "params" } }] _treq = get_fake_treq( self, 'POST', "/mimic/v1.1/IdentityControlAPI/behaviors/some_event", ((json.dumps({ 'criteria': criteria, 'name': "sequence", 'parameters': { "behaviors": behaviors } }), ), self.expected_kwargs), (Response(201), '{"id": "behavior_id"}')) test_case = _get_fake_test_case(_treq, self.delete_treq) mimic_identity = MimicIdentity(pool=self.pool, test_case=test_case, treq=_treq) d = mimic_identity.sequenced_behaviors("/identity/v2.0", criteria, behaviors, event_description="some_event") self.assertEqual("behavior_id", self.successResultOf(d)) self.assertEqual("successfully deleted behavior", self.successResultOf(test_case.cleanup()))