Ejemplo n.º 1
0
def do_differ(current, desired):
    system = desired.get('system')
    if system and utils.do_differ(current.get('system'), system):
        return True

    subs = desired.get('subscriptions')
    if subs is not None and set(subs) != set(current.get('subscriptions', [])):
        return True

    return utils.do_differ(current, desired, 'system', 'subscriptions')
Ejemplo n.º 2
0
def do_differ(current, desired):
    if utils.do_differ_v1(current, desired, "client"):
        return True

    current_client = current["spec"]["client"]
    desired_client = desired["spec"]["client"]
    # Sensu Go API returns 'agent_address' field in the client spec,
    # but this field is not meant to be set via the providers API.
    if utils.do_differ(current_client, desired_client, "agent_address", "tls"):
        return True
    # Sensu Go API returns some extra fields in the tls spec.
    # We ignore them, as they are not meant to be set via the
    # providers API.
    return utils.do_differ(current_client["tls"], desired_client.get("tls") or {},
                           "insecure", "tls_server_name", "ca_path")
Ejemplo n.º 3
0
def sync(state, client, list_path, resource_path, payload, check_mode):
    datastore = _get(client, resource_path)

    # When we are deleting stores, we do not care if there is more than one
    # datastore present. We just make sure the currently manipulated store is
    # gone. This makes our module useful in "let us clean up the mess"
    # scenarios.
    if state == "absent" and datastore is None:
        return False, None

    if state == "absent":
        if not check_mode:
            utils.delete(client, resource_path)
        return True, None

    # If the store exists, update it and ignore the fact that there might be
    # more than one present.
    if datastore:
        if utils.do_differ(datastore, payload["spec"]):
            if check_mode:
                return True, payload["spec"]
            utils.put(client, resource_path, payload)
            return True, _get(client, resource_path)
        return False, datastore

    # When adding a new datastore, we first make sure there is no other
    # datastore present because we do not want to be the ones who brought
    # backends into an inconsistent state.
    if utils.get(client, list_path):
        raise errors.Error("Some other external datastore is already active.")

    if check_mode:
        return True, payload["spec"]
    utils.put(client, resource_path, payload)
    return True, _get(client, resource_path)
Ejemplo n.º 4
0
def sync(client, path, payload, check_mode):
    remote_object = get(client, path)

    if utils.do_differ(remote_object, payload):
        if check_mode:
            return True, payload
        utils.put(client, path, payload)
        return True, get(client, path)

    return False, remote_object
Ejemplo n.º 5
0
def do_proxy_requests_differ(current, desired):
    if 'proxy_requests' not in desired:
        return False

    current = current.get('proxy_requests') or {}
    desired = desired['proxy_requests']

    return (('entity_attributes' in desired
             and do_sets_differ(current, desired, 'entity_attributes'))
            or utils.do_differ(current, desired, 'entity_attributes'))
Ejemplo n.º 6
0
def sync(remote_object, state, client, path, payload, check_mode):
    if state == 'disabled' and remote_object is not None:
        if not check_mode:
            utils.delete(client, path)
        return True, utils.get(client, path)

    if utils.do_differ(remote_object, payload):
        if check_mode:
            return True, payload
        utils.put(client, path, payload)
        return True, utils.get(client, path)

    return False, remote_object
Ejemplo n.º 7
0
def do_differ(current, desired):
    return (utils.do_differ(
        current,
        desired,
        'proxy_requests',
        'subscriptions',
        'handlers',
        'runtime_assets',
        'check_hooks',
        'output_metric_handlers',
        'env_vars',
    ) or do_proxy_requests_differ(current, desired)
            or do_sets_differ(current, desired, 'subscriptions')
            or do_sets_differ(current, desired, 'handlers')
            or do_sets_differ(current, desired, 'runtime_assets')
            or do_check_hooks_differ(current, desired)
            or do_sets_differ(current, desired, 'output_metric_handlers')
            or do_sets_differ(current, desired, 'env_vars'))
Ejemplo n.º 8
0
def do_differ(current, desired):
    system = desired.get('system')
    if system and utils.do_differ(current.get('system'), system):
        return True

    return utils.do_differ(current, desired, 'system')
Ejemplo n.º 9
0
 def test_ignore_keys_do_not_mask_other_differences(self):
     assert utils.do_differ(dict(a=1, b=1), dict(a=2, b=2), "a") is True
Ejemplo n.º 10
0
 def test_ignore_keys_do_not_affect_the_outcome(self):
     assert utils.do_differ(dict(a=1), dict(a=2), "a") is False
Ejemplo n.º 11
0
 def test_metadata_detects_change_in_presence_of_created_by(self):
     assert utils.do_differ(
         dict(metadata=dict(a=1, created_by=2)),
         dict(metadata=dict(a=2)),
     ) is True
Ejemplo n.º 12
0
 def test_metadata_detects_change(self):
     assert utils.do_differ(
         dict(metadata=dict(a=1)),
         dict(metadata=dict(a=2)),
     ) is True
Ejemplo n.º 13
0
 def test_metadata_ignores_created_by(self):
     assert utils.do_differ(
         dict(metadata=dict(a=1, created_by=2)),
         dict(metadata=dict(a=1)),
     ) is False
Ejemplo n.º 14
0
def do_differ(current, desired):
    if _do_builds_differ(current['builds'], desired['builds']):
        return True

    return utils.do_differ(current, desired, 'builds')
Ejemplo n.º 15
0
 def test_detect_missing_keys_in_current(self):
     assert utils.do_differ({"a": "b"}, {"c": "d"}) is True
Ejemplo n.º 16
0
 def test_detect_different_values(self):
     assert utils.do_differ({"a": "b"}, {"a": "c"}) is True
Ejemplo n.º 17
0
def do_role_bindings_differ(current, desired):
    if _do_subjects_differ(current['subjects'], desired['subjects']):
        return True

    return utils.do_differ(current, desired, 'subjects')
Ejemplo n.º 18
0
def do_roles_differ(current, desired):
    if _do_rules_differ(current['rules'], desired['rules']):
        return True

    return utils.do_differ(current, desired, 'rules')
Ejemplo n.º 19
0
 def test_current_none_always_differ(self, desired):
     assert utils.do_differ(None, desired) is True
Ejemplo n.º 20
0
def _do_differ(remote, payload):
    return utils.do_differ(remote["spec"], payload["spec"])
Ejemplo n.º 21
0
 def test_desired_none_values_are_ignored(self):
     assert utils.do_differ({"a": "b"}, {"c": None}) is False
Ejemplo n.º 22
0
 def test_extra_keys_in_current_do_not_matter(self):
     assert utils.do_differ({"a": "b", "c": 3}, {"a": "b"}) is False
Ejemplo n.º 23
0
def do_differ(current, desired):
    return (
        utils.do_differ(current, desired, "secrets") or
        utils.do_secrets_differ(current, desired)
    )