def test_helm_values_try_set_by_list_index():
    helm_values = HelmValues(BASE_HELM_VALUES)
    try:
        helm_values.set("nested_list[0]", 4)
    except ValueError:
        return
    assert False, "expected 'ValueError' exception was not raised"
def test_helm_values_set_nested_override():
    helm_values = HelmValues(BASE_HELM_VALUES)
    helm_values.set("nested_dict.first_nested_dict_key", "new_value")
    data = helm_values.as_dict()
    assert "nested_dict" in data
    assert "first_nested_dict_key" in data["nested_dict"]
    assert data["nested_dict"]["first_nested_dict_key"] == "new_value"
def test_helm_values_set_nested_new():
    helm_values = HelmValues(BASE_HELM_VALUES)
    helm_values.set("nested_dict.third_nested_dict_key",
                    "third_nested_dict_value")
    data = helm_values.as_dict()
    assert "nested_dict" in data
    assert "third_nested_dict_key" in data["nested_dict"]
    assert data["nested_dict"][
        "third_nested_dict_key"] == "third_nested_dict_value"

    assert "first_nested_dict_key" in data["nested_dict"]
    assert data["nested_dict"][
        "first_nested_dict_key"] == "first_nested_dict_value"

    assert "second_nested_dict_key" in data["nested_dict"]
    assert data["nested_dict"][
        "second_nested_dict_key"] == "second_nested_dict_value"
Example #4
0
def reinstall_scylla_manager(db_cluster: ScyllaPodCluster,
                             manager_version: str):
    values = HelmValues(
        yaml.safe_load(
            db_cluster.k8s_cluster.helm("get values scylla-manager -o yaml",
                                        namespace=SCYLLA_MANAGER_NAMESPACE)))
    if values.get("image.tag") != manager_version:
        log.info(
            "Scylla Manager '%s' is going to be installed instead of the '%s' one.",
            manager_version, values.get("image.tag"))
        values.set('image.tag', manager_version)
        values.set('scylla.agentImage.tag', manager_version)

        # Delete the current scylla-manager completely because otherwise
        # we won't be able to migrate DB state from a newer version to older one.
        db_cluster.k8s_cluster.helm("uninstall scylla-manager --wait",
                                    namespace=SCYLLA_MANAGER_NAMESPACE)
        wait_for_resource_absence(db_cluster=db_cluster,
                                  step=1,
                                  timeout=120,
                                  resource_name="",
                                  resource_type="pod",
                                  namespace=SCYLLA_MANAGER_NAMESPACE)
        db_cluster.k8s_cluster.kubectl("delete pvc --all --wait=true",
                                       namespace=SCYLLA_MANAGER_NAMESPACE)

        # Deploy Scylla Manager of the specified version
        log.debug(
            db_cluster.k8s_cluster.helm_install(
                target_chart_name="scylla-manager",
                source_chart_name="scylla-operator/scylla-manager",
                version=db_cluster.k8s_cluster._scylla_operator_chart_version,  # pylint: disable=protected-access
                use_devel=True,
                values=values,
                namespace=SCYLLA_MANAGER_NAMESPACE,
            ))
        time.sleep(5)
        db_cluster.k8s_cluster.kubectl_wait("--all --for=condition=Ready pod",
                                            namespace=SCYLLA_MANAGER_NAMESPACE,
                                            timeout=600)
        log.info("Scylla Manager '%s' has successfully been installed",
                 manager_version)
Example #5
0
def test_check_operator_operability_when_scylla_crd_is_incorrect(db_cluster):
    """Covers https://github.com/scylladb/scylla-operator/issues/447"""

    # NOTE: Create invalid ScyllaCluster which must be failed but not block operator.
    log.info("DEBUG: test_check_operator_operability_when_scylla_crd_is_incorrect")
    cluster_name, target_chart_name, namespace = ("test-empty-storage-capacity",) * 3
    values = HelmValues({
        'nameOverride': '',
        'fullnameOverride': cluster_name,
        'scyllaImage': {
            'repository': db_cluster.k8s_cluster.params.get('docker_image'),
            'tag': db_cluster.k8s_cluster.params.get('scylla_version'),
        },
        'agentImage': {
            'repository': 'scylladb/scylla-manager-agent',
            'tag': db_cluster.k8s_cluster.params.get('scylla_mgmt_agent_version'),
        },
        'serviceAccount': {
            'create': True,
            'annotations': {},
            'name': f"{cluster_name}-member"
        },
        'developerMode': True,
        'sysctls': ["fs.aio-max-nr=1048576"],
        'serviceMonitor': {'create': False},
        'datacenter': db_cluster.k8s_cluster.params.get('k8s_scylla_datacenter'),
        'racks': [{
            'name': db_cluster.k8s_cluster.params.get('k8s_scylla_rack'),
            'members': 1,
            'storage': {},
            'resources': {
                'limits': {'cpu': 1, 'memory': "200Mi"},
                'requests': {'cpu': 1, 'memory': "200Mi"},
            },
        }]
    })
    db_cluster.k8s_cluster.kubectl(f"create namespace {namespace}", ignore_status=True)
    db_cluster.k8s_cluster.helm_install(
        target_chart_name=target_chart_name,
        source_chart_name="scylla-operator/scylla",
        version=db_cluster.k8s_cluster._scylla_operator_chart_version,  # pylint: disable=protected-access
        use_devel=True,
        values=values,
        namespace=namespace)
    try:
        db_cluster.k8s_cluster.wait_till_cluster_is_operational()

        # NOTE: Check that new cluster is non-working. Statefulset must be absent always.
        #       So, sleep for some time and make sure that it is absent.
        time.sleep(30)
        invalid_cluster_sts = db_cluster.k8s_cluster.kubectl(
            f"get sts -n {namespace} -l scylla/cluster={cluster_name}",
            ignore_status=True)
        assert 'No resources found' in invalid_cluster_sts.stderr, (
            f"Expected {cluster_name} not to have statefulset created.\n"
            f"stdout: {invalid_cluster_sts.stdout}\n"
            f"stderr: {invalid_cluster_sts.stderr}")

        # NOTE: Any change to the working ScyllaCluster going to trigger rollout.
        #       And rollout is enough for us to make sure that operator still works
        #       having invalid clusters. So, just run rollout restart which updates
        #       ScyllaCluster CRD.
        db_cluster.restart_scylla()
    finally:
        db_cluster.k8s_cluster.helm(
            f"uninstall {target_chart_name}", namespace=namespace)
def test_helm_values_get_list():
    helm_values = HelmValues(BASE_HELM_VALUES)
    assert helm_values.get("nested_list") == [1, 2, 3]
def test_helm_values_set_override():
    helm_values = HelmValues(BASE_HELM_VALUES)
    helm_values.set("no_nesting_key", "custom_value")
    assert helm_values.get("no_nesting_key") == "custom_value"
def test_helm_values_get_nonexistent():
    helm_values = HelmValues(BASE_HELM_VALUES)
    assert helm_values.get("fake_key") is None
def test_helm_values_set_new():
    helm_values = HelmValues(BASE_HELM_VALUES)
    helm_values.set("new_key", "new_value")
    assert helm_values.get("new_key") == "new_value"
def test_helm_values_get():
    helm_values = HelmValues(BASE_HELM_VALUES)
    assert helm_values.get("no_nesting_key") == "no_nesting_value"
def test_helm_values_init_with_kwargs():
    helm_values = HelmValues(**BASE_HELM_VALUES)
    assert helm_values.as_dict() == BASE_HELM_VALUES
Example #12
0
def test_helm_delete_from_dict():
    helm_values = HelmValues(deepcopy(BASE_HELM_VALUES))
    match = deepcopy(BASE_HELM_VALUES)
    del match['nested_dict']['first_nested_dict_key']
    helm_values.delete("nested_dict.first_nested_dict_key")
    assert helm_values == match
Example #13
0
def test_helm_delete_from_list():
    helm_values = HelmValues(deepcopy(BASE_HELM_VALUES))
    match = deepcopy(BASE_HELM_VALUES)
    del match['nested_list'][0]
    helm_values.delete("nested_list.[0]")
    assert helm_values == match
Example #14
0
def test_helm_values_get_by_list_index():
    helm_values = HelmValues(BASE_HELM_VALUES)
    assert helm_values.get("nested_list.[0]") == 1