Beispiel #1
0
def test_get_security_rules_difference_ingress_icmp_options_append():
    input_ingress_rules = get_security_rules(
        "ingress",
        "hashed",
        "10.0.0.0/0",
        "0.0.0.0/0",
        "10.0.0.0/16",
        False,
        None,
        None,
        None,
        "3",
        "4",
    )

    existing_ingress_rules = get_security_rules(
        "ingress",
        "hashed",
        "10.0.0.0/0",
        "0.0.0.0/0",
        "10.0.0.0/16",
        False,
        None,
        None,
        None,
        "3",
        None,
    )

    result, changed = oci_utils.get_component_list_difference(
        existing_ingress_rules, input_ingress_rules, False
    )

    assert changed is True
    assert result[0].source == "0.0.0.0/0"
Beispiel #2
0
def test_get_route_rules_difference_append_different_rule():
    route_table = get_route_table()
    result_rt, result = oci_utils.get_component_list_difference(
        get_hashed_route_rules(get_route_rules()),
        get_hashed_route_rules(route_table.route_rules), False)
    assert result is True
    assert len(result_rt) is 3
Beispiel #3
0
def test_get_security_rules_difference_egress_udp_options_append():
    input_egress_rules = get_security_rules(
        "egress",
        "hashed",
        None,
        None,
        None,
        False,
        "10.0.0.0/0",
        "0.0.0.0/0",
        "10.0.0.0/16",
        "3",
        "4",
    )

    existing_egress_rules = get_security_rules(
        "egress",
        "hashed",
        None,
        None,
        None,
        False,
        "10.0.0.0/0",
        "10.0.0.0/0",
        "10.0.0.0/16",
        "3",
        "4",
    )

    result, changed = oci_utils.get_component_list_difference(
        input_egress_rules, existing_egress_rules, False
    )
    assert changed is True
    assert result[0].destination == "0.0.0.0/0"
Beispiel #4
0
def test_get_security_rules_difference_egress_icmp_options_purge():
    input_egress_rules = get_security_rules(
        "egress",
        "hashed",
        None,
        None,
        None,
        False,
        "10.0.0.0/0",
        "0.0.0.0/0",
        "10.0.0.0/16",
        "3",
        "4",
    )

    existing_egress_rules = get_security_rules(
        "egress",
        "hashed",
        None,
        None,
        None,
        False,
        "10.0.0.0/0",
        "0.0.0.0/0",
        "10.0.0.0/16",
        "3",
        None,
    )

    result, changed = oci_utils.get_component_list_difference(
        input_egress_rules, existing_egress_rules, True
    )
    assert changed is True
    assert len(result) is 3
Beispiel #5
0
def test_get_security_rules_difference_ingress_same_rules_state_unchanged():
    input_ingress_rules = get_security_rules(
        "ingress",
        "hashed",
        "10.0.0.0/0",
        "0.0.0.0/0",
        "10.0.0.0/16",
        False,
        None,
        None,
        None,
        "3",
        "4",
    )

    existing_ingress_rules = get_security_rules(
        "ingress",
        "hashed",
        "10.0.0.0/0",
        "0.0.0.0/0",
        "10.0.0.0/16",
        False,
        None,
        None,
        None,
        "3",
        "4",
    )

    result, changed = oci_utils.get_component_list_difference(
        existing_ingress_rules, input_ingress_rules, False
    )

    assert changed is False
Beispiel #6
0
def test_get_route_rules_difference_no_purge_same_rule(virtual_network_client):
    route_table = get_route_table()
    _, result = oci_utils.get_component_list_difference(
        get_hashed_route_rules(route_table.route_rules),
        get_hashed_route_rules(route_table.route_rules),
        True,
    )
    assert result is False
Beispiel #7
0
def test_get_route_rules_difference_no_different_rules():
    existing_route_rules = get_route_rules() + [(get_common_route_rule())]
    _, result = oci_utils.get_component_list_difference(
        get_hashed_route_rules([get_common_route_rule()]),
        get_hashed_route_rules(existing_route_rules),
        False,
    )
    assert result is False
def test_get_options_difference_no_existing_dns():
    dhcp_dns_options = get_options('DomainNameServer', 'VcnLocalPlusInternet',
                                   [], None)
    dhcp_search_domain = get_options('SearchDomain', None, None,
                                     ['ansibletestvcn.oraclevcn.com'])
    result, changed = oci_utils.get_component_list_difference(
        [dhcp_dns_options, dhcp_search_domain], [], True)
    assert changed is True
Beispiel #9
0
def update_route_table(virtual_network_client, existing_route_table, module):
    if existing_route_table is None:
        raise ClientError(
            Exception(
                "No Route Table with id "
                + module.params.get("rt_id")
                + " is found for update"
            )
        )
    result = dict(route_table=to_dict(existing_route_table), changed=False)
    input_route_rules = module.params.get("route_rules")
    purge_route_rules = module.params["purge_route_rules"]
    delete_route_rules = module.params["delete_route_rules"]
    name_tag_changed = False
    route_rules_changed = False
    existing_route_rules = existing_route_table.route_rules
    update_route_table_details = UpdateRouteTableDetails()
    attributes_to_compare = ["display_name", "freeform_tags", "defined_tags"]
    for attribute in attributes_to_compare:
        name_tag_changed = oci_utils.check_and_update_attributes(
            update_route_table_details,
            attribute,
            module.params.get(attribute),
            getattr(existing_route_table, attribute),
            name_tag_changed,
        )
    if input_route_rules is not None:
        if input_route_rules:
            route_rules_object_list = get_route_rules(input_route_rules)
            route_rules, route_rules_changed = oci_utils.get_component_list_difference(
                get_hashed_route_rules(route_rules_object_list),
                get_hashed_route_rules(existing_route_rules),
                purge_route_rules,
                delete_route_rules,
            )
        else:
            route_rules = []
            route_rules_changed = True
    if route_rules_changed:
        update_route_table_details.route_rules = route_rules
    else:
        update_route_table_details.route_rules = existing_route_rules

    if name_tag_changed or route_rules_changed:
        result = oci_utils.update_and_wait(
            resource_type="route_table",
            update_fn=virtual_network_client.update_route_table,
            kwargs_update={
                "rt_id": existing_route_table.id,
                "update_route_table_details": update_route_table_details,
            },
            client=virtual_network_client,
            get_fn=virtual_network_client.get_route_table,
            get_param="rt_id",
            module=module,
        )

    return result
def test_get_security_rules_difference_no_existing_rule():
    input_ingress_rules = get_security_rules(
        'ingress', 'hashed', '10.0.0.0/0', '0.0.0.0/0', '10.0.0.0/16', False, None, None, None, '3', '4')

    result, changed = oci_utils.get_component_list_difference(
        input_ingress_rules, None, True)

    assert changed is True
    assert len(result) is 3
def test_get_security_rules_difference_egress_udp_options_append():
    input_egress_rules = get_security_rules(
        'egress', 'hashed', None, None, None, False, '10.0.0.0/0', '0.0.0.0/0', '10.0.0.0/16', '3', '4')

    existing_egress_rules = get_security_rules(
        'egress', 'hashed', None,  None, None,  False, '10.0.0.0/0', '10.0.0.0/0', '10.0.0.0/16', '3', '4')

    result, changed = oci_utils.get_component_list_difference(input_egress_rules, existing_egress_rules, False)
    assert changed is True
    assert result[0].destination == '0.0.0.0/0'
def test_get_security_rules_difference_egress_icmp_options_purge():
    input_egress_rules = get_security_rules(
        'egress', 'hashed', None, None, None, False, '10.0.0.0/0', '0.0.0.0/0', '10.0.0.0/16', '3', '4')

    existing_egress_rules = get_security_rules(
        'egress', 'hashed', None,  None, None,  False, '10.0.0.0/0', '0.0.0.0/0', '10.0.0.0/16', '3', None)

    result, changed = oci_utils.get_component_list_difference(input_egress_rules, existing_egress_rules, True)
    assert changed is True
    assert len(result) is 3
def test_get_security_rules_difference_ingress_same_rules_state_unchanged():
    input_ingress_rules = get_security_rules(
        'ingress', 'hashed', '10.0.0.0/0', '0.0.0.0/0', '10.0.0.0/16', False,  None, None, None, '3', '4')

    existing_ingress_rules = get_security_rules(
        'ingress', 'hashed', '10.0.0.0/0', '0.0.0.0/0', '10.0.0.0/16', False, None, None, None, '3', '4')

    result, changed = oci_utils.get_component_list_difference(
        existing_ingress_rules, input_ingress_rules, False)

    assert changed is False
def test_get_security_rules_difference_ingress_icmp_options_append():
    input_ingress_rules = get_security_rules(
        'ingress', 'hashed', '10.0.0.0/0', '0.0.0.0/0', '10.0.0.0/16',  False, None, None, None, '3', '4')

    existing_ingress_rules = get_security_rules(
        'ingress', 'hashed', '10.0.0.0/0', '0.0.0.0/0', '10.0.0.0/16', False, None, None, None, '3', None)

    result, changed = oci_utils.get_component_list_difference(
        existing_ingress_rules, input_ingress_rules, False)

    assert changed is True
    assert result[0].source == '0.0.0.0/0'
def test_update_dhcp_options_searchdomain_changed_append():
    dhcp_dns_options = get_options('DomainNameServer', 'VcnLocalPlusInternet',
                                   [], None)
    dhcp_search_domain = get_options('SearchDomain', None, None,
                                     ['ansibletestvcn.oraclevcn.com'])
    existing_options = [dhcp_dns_options, dhcp_search_domain]
    input_dhcp_dns_options = get_options('DomainNameServer',
                                         'VcnLocalPlusInternet', [], None)
    input_dhcp_search_domain = get_options('SearchDomain', None, None,
                                           ['ansiblevcn.oraclevcn.com'])
    input_options = [input_dhcp_dns_options, input_dhcp_search_domain]
    result, changed = oci_utils.get_component_list_difference(
        input_options, existing_options, False)
    assert changed is True
    assert len(result) is 3
def update_dhcp_options(virtual_network_client, existing_dhcp_options, module):
    if existing_dhcp_options is None:
        raise ClientError(
            Exception("No Dhcp Options with id " +
                      module.params.get("dhcp_id") + " is found for update"))
    result = dict(dhcp_options=to_dict(existing_dhcp_options), changed=False)
    name_tag_changed = False
    options_changed = False
    input_options = module.params.get("options")
    update_dhcp_details = UpdateDhcpDetails()
    existing_options = existing_dhcp_options.options
    attributes_to_compare = ["display_name", "freeform_tags", "defined_tags"]
    for attribute in attributes_to_compare:
        name_tag_changed = oci_utils.check_and_update_attributes(
            update_dhcp_details,
            attribute,
            module.params.get(attribute),
            getattr(existing_dhcp_options, attribute),
            name_tag_changed,
        )
    if input_options is not None:
        if input_options:
            options, options_changed = oci_utils.get_component_list_difference(
                get_options_objects(input_options),
                get_hashed_options(existing_options),
                module.params.get("purge_dhcp_options"),
                module.params.get("delete_dhcp_options"),
            )
    if options_changed:
        update_dhcp_details.options = options
    else:
        update_dhcp_details.options = existing_options

    if name_tag_changed or options_changed:
        result = oci_utils.update_and_wait(
            resource_type="dhcp_options",
            update_fn=virtual_network_client.update_dhcp_options,
            kwargs_update={
                "dhcp_id": existing_dhcp_options.id,
                "update_dhcp_details": update_dhcp_details,
            },
            client=virtual_network_client,
            get_fn=virtual_network_client.get_dhcp_options,
            get_param="dhcp_id",
            module=module,
        )

    return result
Beispiel #17
0
def test_get_route_rules_difference_no_existing_route_rule(
        virtual_network_client):
    route_table = get_route_table()
    route_table.route_rules = []
    route_rules = [{
        'cidr_block': '0.0.0.0/0',
        'network_entity_id': 'oci1.internetgateway.abcd'
    }, {
        'cidr_block': '10.0.0.4/16',
        'network_entity_id': 'oci1.internetgateway.efgh'
    }]

    result_rt, result = oci_utils.get_component_list_difference(
        route_rules, None, True)
    assert result is True
    assert len(result_rt) is 2
def test_update_dhcp_options_searchdomain_changed_purged():
    dhcp_dns_options = get_options('DomainNameServer', 'VcnLocalPlusInternet',
                                   [], None)
    dhcp_search_domain = get_options('SearchDomain', None, None,
                                     ['ansibletestvcn.oraclevcn.com'])
    existing_options = [dhcp_dns_options, dhcp_search_domain]
    input_dhcp_dns_options = get_options('DomainNameServer',
                                         'VcnLocalPlusInternet', [], None)
    input_dhcp_search_domain = get_options('SearchDomain', None, None,
                                           ['ansiblevcn.oraclevcn.com'])
    input_options = [input_dhcp_dns_options, input_dhcp_search_domain]
    result, changed = oci_utils.get_component_list_difference(
        input_options, existing_options, True)
    assert changed is True
    for option in result:
        if option.type == 'SearchDomain':
            assert option.search_domain_names[0] == 'ansiblevcn.oraclevcn.com'
Beispiel #19
0
def test_update_dhcp_options_dns_changed_append():
    dhcp_dns_options = get_options("DomainNameServer", "VcnLocalPlusInternet", [], None)
    dhcp_search_domain = get_options(
        "SearchDomain", None, None, ["ansibletestvcn.oraclevcn.com"]
    )
    existing_options = [dhcp_dns_options, dhcp_search_domain]
    input_dhcp_dns_options = get_options(
        "DomainNameServer", "CustomDnsServer", ["10.0.0.8"], None
    )
    input_dhcp_search_domain = get_options(
        "SearchDomain", None, None, ["ansibletestvcn.oraclevcn.com"]
    )
    input_options = [input_dhcp_dns_options, input_dhcp_search_domain]
    result, changed = oci_utils.get_component_list_difference(
        input_options, existing_options, False
    )
    assert changed is True
    assert len(result) is 3
Beispiel #20
0
def test_get_route_rules_difference_no_existing_route_rule(
        virtual_network_client):
    route_table = get_route_table()
    route_table.route_rules = []
    route_rules = [
        {
            "cidr_block": "0.0.0.0/0",
            "network_entity_id": "oci1.internetgateway.abcd"
        },
        {
            "cidr_block": "10.0.0.4/16",
            "network_entity_id": "oci1.internetgateway.efgh"
        },
    ]

    result_rt, result = oci_utils.get_component_list_difference(
        route_rules, None, True)
    assert result is True
    assert len(result_rt) is 2
Beispiel #21
0
def test_get_security_rules_difference_no_existing_rule():
    input_ingress_rules = get_security_rules(
        "ingress",
        "hashed",
        "10.0.0.0/0",
        "0.0.0.0/0",
        "10.0.0.0/16",
        False,
        None,
        None,
        None,
        "3",
        "4",
    )

    result, changed = oci_utils.get_component_list_difference(
        input_ingress_rules, None, True)

    assert changed is True
    assert len(result) is 3
def update_db_system(db_client, module, db_system_id):
    result = dict()
    changed = False
    db_system = oci_utils.get_existing_resource(
        db_client.get_db_system,
        module,
        db_system_id=module.params.get("db_system_id"))
    if db_system is None:
        raise ClientError(
            Exception("No DB System with id " + db_system_id +
                      " is found for update"))

    existing_ssh_public_keys = db_system.ssh_public_keys
    last_patch_history_entry_id = db_system.last_patch_history_entry_id
    purge_ssh_public_keys = module.params.get("purge_ssh_public_keys")
    delete_ssh_public_keys = module.params.get("delete_ssh_public_keys")
    update_db_system_details = UpdateDbSystemDetails()

    primitive_attributes = [
        "cpu_core_count",
        "data_storage_size_in_gbs",
        "freeform_tags",
        "defined_tags",
    ]
    for attribute in primitive_attributes:
        changed = oci_utils.check_and_update_attributes_if_changed(
            update_db_system_details,
            attribute,
            module.params.get(attribute, None),
            getattr(db_system, attribute),
            changed,
        )

    input_ssh_public_keys = create_ssh_public_keys(
        module.params.get("ssh_public_keys", None))
    ssh_public_keys_changed = False
    if input_ssh_public_keys is not None:
        (
            ssh_public_keys,
            ssh_public_keys_changed,
        ) = oci_utils.get_component_list_difference(
            input_ssh_public_keys,
            existing_ssh_public_keys,
            purge_ssh_public_keys,
            delete_ssh_public_keys,
        )
    if ssh_public_keys_changed:
        update_db_system_details.ssh_public_keys = ssh_public_keys

    input_version_dict = module.params.get("version", None)
    version_changed, patch_details = oci_db_utils.is_version_changed(
        db_client.get_db_system_patch_history_entry,
        db_client.get_db_system_patch,
        db_system.version,
        input_version_dict,
        last_patch_history_entry_id,
        db_system_id=db_system_id,
    )
    if version_changed:
        update_db_system_details.version = patch_details
    changed = changed or ssh_public_keys_changed or version_changed
    if changed:
        result = oci_utils.update_and_wait(
            resource_type="db_system",
            update_fn=db_client.update_db_system,
            kwargs_update={
                "db_system_id": db_system_id,
                "update_db_system_details": update_db_system_details,
            },
            client=db_client,
            get_fn=db_client.get_db_system,
            get_param="db_system_id",
            module=module,
        )
    else:
        result["db_system"] = to_dict(db_system)
        result["changed"] = False
    return result
Beispiel #23
0
def update_db_system(db_client, module, db_system_id):
    result = dict()
    changed = False
    db_system = oci_utils.get_existing_resource(
        db_client.get_db_system,
        module,
        db_system_id=module.params.get('db_system_id'))
    if db_system is None:
        raise ClientError(
            Exception("No DB System with id " + db_system_id +
                      " is found for update"))
    primitive_attributes = [
        'cpu_core_count', 'data_storage_size_in_gbs', 'freeform_tags',
        'defined_tags'
    ]
    existing_ssh_public_keys = db_system.ssh_public_keys
    last_patch_history_entry_id = db_system.last_patch_history_entry_id
    purge_ssh_public_keys = module.params.get('purge_ssh_public_keys')
    update_db_system_details = UpdateDbSystemDetails()

    for attribute in primitive_attributes:
        changed = oci_utils.check_and_update_attributes(
            update_db_system_details, attribute,
            module.params.get(attribute, None), getattr(db_system, attribute),
            changed)

    input_ssh_public_keys = create_ssh_public_keys(
        module.params.get('ssh_public_keys', None))
    ssh_public_keys_changed = False
    if input_ssh_public_keys is not None:
        ssh_public_keys, ssh_public_keys_changed = oci_utils.get_component_list_difference(
            input_ssh_public_keys, existing_ssh_public_keys,
            purge_ssh_public_keys)
    if ssh_public_keys_changed:
        update_db_system_details.ssh_public_keys = ssh_public_keys
    else:
        update_db_system_details.ssh_public_keys = existing_ssh_public_keys

    input_version_dict = module.params.get('version', None)
    version_changed, patch_details = oci_db_utils.is_version_changed(
        db_client.get_db_system_patch_history_entry,
        db_client.get_db_system_patch,
        db_system.version,
        input_version_dict,
        last_patch_history_entry_id,
        db_system_id=db_system_id)
    if version_changed:
        update_db_system_details.version = patch_details
    changed = changed or ssh_public_keys_changed or version_changed
    if changed:
        result = oci_utils.update_and_wait(
            resource_type='db_system',
            update_fn=db_client.update_db_system,
            kwargs_update={
                'db_system_id': db_system_id,
                'update_db_system_details': update_db_system_details
            },
            client=db_client,
            get_fn=db_client.get_db_system,
            get_param='db_system_id',
            module=module)
    else:
        result['db_system'] = to_dict(db_system)
        result['changed'] = False
    return result
Beispiel #24
0
def get_route_rules_difference_append_only_different_rules():
    route_table = get_route_table()
    result_rt, result = oci_utils.get_component_list_difference(
        get_route_rules(), route_table.route_rules, False)
    assert result is True
    assert len(result_rt) is 3