def test_list_load_balancer_listeners_all_listeners(lb_client): module = get_module(dict({'load_balancer_id': 'ocid1.lodbalancer.xcds'})) load_balancer = LoadBalancer() load_balancer.listeners = dict({'ansible_listener': get_listener()}) lb_client.get_load_balancer.return_value = get_response( 200, None, load_balancer, None) result = oci_load_balancer_listener_facts.list_load_balancer_listeners( lb_client, module) assert result['listeners'][0]['name'] == 'ansible_listener'
def test_create_load_balancer(lb_client, create_or_update_lb_resources_and_wait_patch): module = get_module(dict()) load_balancer = LoadBalancer() load_balancer.id = "ocid.loadbalancer.cvghs" create_or_update_lb_resources_and_wait_patch.return_value = dict( load_balancer=to_dict(load_balancer), changed=True) result = oci_load_balancer.create_load_balancer(lb_client, module) assert result["load_balancer"]["id"] == load_balancer.id
def test_update_load_balancer(lb_client, create_or_update_lb_resources_and_wait_patch): module = get_module(dict()) load_balancer = LoadBalancer() load_balancer.id = "ocid.loadbalancer.cvghs" load_balancer.display_name = "ansible_lb_updated" create_or_update_lb_resources_and_wait_patch.return_value = dict( load_balancer=to_dict(load_balancer), changed=True) oci_load_balancer.update_load_balancer(lb_client, module, load_balancer) assert create_or_update_lb_resources_and_wait_patch.called
def test_list_load_balancer_listeners_all_listeners(lb_client): module = get_module(dict({"load_balancer_id": "ocid1.lodbalancer.xcds"})) load_balancer = LoadBalancer() load_balancer.listeners = dict({"ansible_listener": get_listener()}) lb_client.get_load_balancer.return_value = get_response( 200, None, load_balancer, None ) result = oci_load_balancer_listener_facts.list_load_balancer_listeners( lb_client, module ) assert result["listeners"][0]["name"] == "ansible_listener"
def test_list_load_balancers_load_balancer_id(lb_client): module = get_module( dict({ 'compartment_id': None, 'load_balancer_id': 'ocid1.lodbalancer.xcds' })) load_balancer = LoadBalancer() load_balancer.id = 'ocid.loadbalancer.cvghs' load_balancer.display_name = 'ansible_lb' lb_client.get_load_balancer.return_value = get_response( 200, None, load_balancer, None) result = oci_load_balancer_facts.list_load_balancers(lb_client, module) assert result['load_balancers'][0]['id'] == load_balancer.id
def test_list_load_balancers_compartment_id(lb_client, list_all_resources_patch): module = get_module( dict({ 'compartment_id': 'ocid1.compartment.xscf', 'load_balancer_id': None })) load_balancer = LoadBalancer() load_balancer.id = 'ocid.loadbalancer.cvghs' load_balancer.display_name = 'ansible_lb' list_all_resources_patch.return_value = [load_balancer] result = oci_load_balancer_facts.list_load_balancers(lb_client, module) assert result['load_balancers'][0]['id'] == load_balancer.id
def test_list_load_balancer_health_checker_list_all_health_checkers(lb_client): module = get_module(dict({'load_balancer_id': 'ocid1.lodbalancer.xcds'})) health_checker = get_health_checker() load_balancer = LoadBalancer() backend_set = BackendSet() health_checker = get_health_checker() backend_set.health_checker = health_checker load_balancer.backend_sets = dict({'backend_set': backend_set}) lb_client.get_load_balancer.return_value = get_response( 200, None, load_balancer, None) result = oci_load_balancer_health_checker_facts.list_load_balancer_health_checker( lb_client, module) assert result['health_checkers'][0]['protocol'] == health_checker.protocol
def test_create_or_update_listener_create(lb_client, check_and_create_resource_patch): module = get_module() load_balancer = LoadBalancer() load_balancer.listeners = dict() lb_client.get_load_balancer.return_value = get_response( 200, None, load_balancer, None) check_and_create_resource_patch.return_value = { "listener": to_dict(get_listener()), "changed": True, } result = oci_load_balancer_listener.create_or_update_listener( lb_client, module) assert result["listener"]["name"] == module.params.get("name")
def test_create_or_update_listener_client_error( lb_client, check_and_create_resource_patch): error_message = "Work Request Failed" module = get_module() load_balancer = LoadBalancer() load_balancer.listeners = dict() lb_client.get_load_balancer.return_value = get_response( 200, None, load_balancer, None) check_and_create_resource_patch.side_effect = ClientError( Exception("Work Request Failed")) try: oci_load_balancer_listener.create_or_update_listener(lb_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_create_or_update_listener_service_error( lb_client, check_and_create_resource_patch): error_message = "Internal Server Error" module = get_module() load_balancer = LoadBalancer() load_balancer.listeners = dict() lb_client.get_load_balancer.return_value = get_response( 200, None, load_balancer, None) check_and_create_resource_patch.side_effect = ServiceError( 500, "InternalServerError", dict(), error_message) try: oci_load_balancer_listener.create_or_update_listener(lb_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_list_load_balancer_listeners_service_error(lb_client): error_message = "Internal Server Error" module = get_module( dict({"name": "ansible_listener", "load_balancer_id": "ocid1.lodbalancer.xcds"}) ) load_balancer = LoadBalancer() load_balancer.listeners = dict({"ansible_listener": get_listener()}) lb_client.get_load_balancer.side_effect = ServiceError( 499, "InternalServerError", dict(), error_message ) try: oci_load_balancer_listener_facts.list_load_balancer_listeners(lb_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_create_or_update_listener_create(lb_client, check_and_create_resource_patch): module = get_module() load_balancer = LoadBalancer() load_balancer.listeners = dict() lb_client.get_load_balancer.return_value = get_response( 200, None, load_balancer, None) check_and_create_resource_patch.return_value = { 'listener': to_dict(get_listener()), 'changed': True } result = oci_load_balancer_listener.create_or_update_listener( lb_client, module) assert result['listener']['name'] == module.params.get('name')
def test_create_load_balancer(lb_client, oci_wait_until_patch): module = get_module(dict()) work_request_response_header = dict({'opc-work-request-id': 'ABE00987F'}) work_request = WorkRequest() work_request.load_balancer_id = 'ocid.loadbalancer.cvghs' work_request.lifecycle_state = 'SUCCEEDED' lb_client.create_load_balancer.return_value = get_response( 204, work_request_response_header, work_request, None) lb_client.get_work_request.return_value = get_response( 200, None, work_request, None) load_balancer = LoadBalancer() load_balancer.id = 'ocid.loadbalancer.cvghs' lb_client.get_load_balancer.return_value = get_response( 200, None, load_balancer, None) result = oci_load_balancer.create_load_balancer(lb_client, module) assert result['load_balancer']['id'] == load_balancer.id
def test_update_load_balancer(lb_client, oci_wait_until_patch): module = get_module(dict()) work_request_response_header = dict({'opc-work-request-id': 'ABE00987F'}) work_request = WorkRequest() work_request.load_balancer_id = 'ocid.loadbalancer.cvghs' work_request.lifecycle_state = 'SUCCEEDED' lb_client.update_load_balancer.return_value = get_response( 204, work_request_response_header, work_request, None) lb_client.get_work_request.return_value = get_response( 200, None, work_request, None) load_balancer = LoadBalancer() load_balancer.id = 'ocid.loadbalancer.cvghs' load_balancer.display_name = 'ansible_lb_updated' lb_client.get_load_balancer.return_value = get_response( 200, None, load_balancer, None) changed, result = oci_load_balancer.update_load_balancer( lb_client, module, load_balancer) assert result.display_name == load_balancer.display_name
def get_load_balancer(): load_balancer = LoadBalancer() load_balancer.id = 'ocid.loadbalancer.cvghs' load_balancer.display_name = 'ansible_lb' return load_balancer
def get_load_balancer(): load_balancer = LoadBalancer() load_balancer.id = "ocid.loadbalancer.cvghs" load_balancer.display_name = "ansible_lb" return load_balancer