Esempio n. 1
0
def test_get_sas_component_resources_bad_params(
        report: ViyaDeploymentReport) -> None:
    """
    This test verifies that a None value is returned when a request is made for a SAS component that isn't defined
    or for a resource that is not defined for an existing component.

    :param report: The populated ViyaDeploymentReport returned by the report() fixture.
    """
    # make sure None is returned
    assert report.get_sas_component_resources(
        "sas-foo", KubernetesResource.Kinds.DEPLOYMENT) is None
    assert report.get_sas_component_resources(
        KubectlTest.Values.COMPONENT_SAS_ANNOTATIONS_NAME, "Foo") is None
Esempio n. 2
0
def test_write_report_unpopulated() -> None:
    """
    This test verifies that a None value is returned for each file when the report is unpopulated.
    """
    # create unpopulated report instance
    report = ViyaDeploymentReport()

    # write report
    data_file, html_file = report.write_report()

    # make sure None is returned
    assert data_file is None
    assert html_file is None
Esempio n. 3
0
def test_get_sas_component_unpopulated() -> None:
    """
    This test verifies that a None value is returned for a requested SAS component when the report is unpopulated.
    """
    # make sure None is returned
    assert ViyaDeploymentReport().get_sas_component(
        KubectlTest.Values.COMPONENT_SAS_ANNOTATIONS_NAME) is None
Esempio n. 4
0
def test_get_kubernetes_version_details_unpopulated() -> None:
    """
    This test verifies that a None value is returned for the kubernetes version information when the report is
    unpopulated.
    """
    # make sure None is returned
    assert ViyaDeploymentReport().get_kubernetes_version_details() is None
Esempio n. 5
0
def test_get_discovered_resources(report: ViyaDeploymentReport) -> None:
    """
    This test verifies that all expected resources discovered while gathering components are present in the
    "kubernetes.discoveredResources" dictionary in a completed report. There is also a spot-check for the correct
    structure for a value inside the dictionary using the first resource (alphabetically).

    :param report: The populated ViyaDeploymentReport returned by the report() fixture.
    """
    # get discovered resources information
    discovered_resources: Dict = report.get_discovered_resources()

    # check for expected attributes
    assert len(discovered_resources) == 11
    assert KubernetesResource.Kinds.CAS_DEPLOYMENT in discovered_resources
    assert KubernetesResource.Kinds.CRON_JOB in discovered_resources
    assert KubernetesResource.Kinds.DEPLOYMENT in discovered_resources
    assert KubernetesResource.Kinds.INGRESS in discovered_resources
    assert KubernetesResource.Kinds.JOB in discovered_resources
    assert KubernetesResource.Kinds.NODE in discovered_resources
    assert KubernetesResource.Kinds.POD in discovered_resources
    assert KubernetesResource.Kinds.REPLICA_SET in discovered_resources
    assert KubernetesResource.Kinds.SERVICE in discovered_resources
    assert KubernetesResource.Kinds.STATEFUL_SET in discovered_resources
    assert KubernetesResource.Kinds.ISTIO_VIRTUAL_SERVICE in discovered_resources

    # get details of a discovered kind
    details: Dict = discovered_resources[
        KubernetesResource.Kinds.CAS_DEPLOYMENT]

    # check for expected attributes in discovered kind
    assert details[ReportKeys.KindDetails.AVAILABLE] is True
    assert details[ReportKeys.KindDetails.COUNT] == 1
    assert details[ReportKeys.KindDetails.SAS_CRD] is True
Esempio n. 6
0
def test_get_discovered_resources_unpopulated() -> None:
    """
    This test verifies that a None value is returned for the "kubernetes.discoveredResources" dictionary in an
    unpopulated report.
    """
    # make sure None is returned
    assert ViyaDeploymentReport().get_discovered_resources() is None
Esempio n. 7
0
def test_get_namespace_provided(report: ViyaDeploymentReport) -> None:
    """
    This test verifies that the provided namespace is returned when a namespace values is passed to gather_details().

    :param report: The populated ViyaDeploymentReport returned by the report() fixture.
    """
    # check for expected attributes
    assert report.get_namespace() == KubectlTest.Values.NAMESPACE
Esempio n. 8
0
def test_get_sas_component_resources_unpopulated() -> None:
    """
    This test verifies that a None value is returned for a requested component resource when the report is unpopulated.
    """
    # make sure None is returned
    assert ViyaDeploymentReport().get_sas_component_resources(
        KubectlTest.Values.COMPONENT_SAS_ANNOTATIONS_NAME,
        KubernetesResource.Kinds.DEPLOYMENT) is None
Esempio n. 9
0
def test_get_namespace_unpopulated() -> None:
    """
    This test verifies that a None value is returned for the namespace when the report is unpopulated.
    """
    # create unpopulated report instance
    report: ViyaDeploymentReport = ViyaDeploymentReport()

    # make sure None is returned
    assert report.get_namespace() is None
Esempio n. 10
0
def test_get_sas_component_bad_param(report: ViyaDeploymentReport) -> None:
    """
    This test verifies that a None value is returned when a request is made for an undefined SAS component in a
    completed report.

    :param report: The populated ViyaDeploymentReport returned by the report() fixture.
    """
    # make sure None is returned
    assert report.get_sas_component("sas-foo") is None
Esempio n. 11
0
def report() -> ViyaDeploymentReport:
    """
    This fixture method runs the report to populate data. With the "module" scope, this will only run once for this
    test file, which saves time because a generic report can be used by multiple tests.

    :return: The completed ViyaDeploymentReport object.
    """
    report: ViyaDeploymentReport = ViyaDeploymentReport()
    report.gather_details(kubectl=KubectlTest())
    return report
Esempio n. 12
0
def test_get_ingress_controller_nginx_only(
        report: ViyaDeploymentReport) -> None:
    """
    This test verifies that NGINX is returned as the ingress controller when VirtualService objects are not available
    in the api-resources.

    :param report: The populated ViyaDeploymentReport returned by the report() fixture.
    """
    # check for expected attributes
    assert report.get_ingress_controller(
    ) == ExpectedIngressController.KUBE_NGINX
Esempio n. 13
0
def test_get_sas_components(report: ViyaDeploymentReport) -> None:
    """
    This test verifies that the correct number of SAS components are returned in a completed report.

    :param report: The populated ViyaDeploymentReport returned by the report() fixture.
    """
    # get SAS components information
    sas_components: Dict = report.get_sas_components()

    # check for expected attributes
    assert len(sas_components) == 4
Esempio n. 14
0
def test_get_ingress_controller_none() -> None:
    """
    This test verifies that a None value is returned when both Ingress and VirtualService resources are unavailable.
    """
    # run the report
    report: ViyaDeploymentReport = ViyaDeploymentReport()
    report.gather_details(
        kubectl=KubectlTest(KubectlTest.IngressSimulator.NONE))

    # check for expected attributes
    assert report.get_ingress_controller() is None
Esempio n. 15
0
def test_get_ingress_controller_istio_only() -> None:
    """
    This test verifies that ISTIO is returned as the ingress controller when Ingress objects are not available in the
    api-resources.
    """
    # run the report
    report: ViyaDeploymentReport = ViyaDeploymentReport()
    report.gather_details(
        kubectl=KubectlTest(KubectlTest.IngressSimulator.ISTIO_ONLY))

    # check for expected attributes
    assert report.get_ingress_controller() == ExpectedIngressController.ISTIO
Esempio n. 16
0
def test_get_ingress_controller_both_istio_used() -> None:
    """
    This test verifies that ISTIO is returned as the ingress controller when both Ingress and VirtualService resources
    are available but VirtualService is defined for components.
    """
    # run the report
    report: ViyaDeploymentReport = ViyaDeploymentReport()
    report.gather_details(kubectl=KubectlTest(
        KubectlTest.IngressSimulator.BOTH_RESOURCES_ISTIO_USED))

    # check for expected attributes
    assert report.get_ingress_controller() is ExpectedIngressController.ISTIO
Esempio n. 17
0
def test_get_kubernetes_version_details(report: ViyaDeploymentReport) -> None:
    """
    This test verifies that the kubernetes version information is returned correctly in a completed report.

    :param report: The populated ViyaDeploymentReport returned by the report() fixture.
    """
    # get Kubernetes version information
    kube_ver_details: Dict = report.get_kubernetes_version_details()

    # check for expected attributes
    assert len(kube_ver_details) == 2
    assert "clientVersion" in kube_ver_details
    assert "serverVersion" in kube_ver_details
Esempio n. 18
0
def test_gather_details_basic_user_valid_namespace_from_command_line() -> None:
    """
    In the event that a user without the ability to see non-namespaced resources passes a valid namespace on the
    command line, kubectl won't be able to verify that value as valid or invalid and will pass it along to the report.
    If this occurs, the gather_details() method should not throw an error when listing pods as the request should be
    allowed with a valid namespace.
    """
    try:
        report: ViyaDeploymentReport = ViyaDeploymentReport()
        report.gather_details(kubectl=KubectlTest(
            include_non_namespaced_resources=False, namespace="test"))
    except KubectlRequestForbiddenError as e:
        pytest.fail(f"An unexpected error was raised: {e}")
Esempio n. 19
0
def test_get_node_details(report: ViyaDeploymentReport) -> None:
    """
    This test verifies that node details are correctly returned in a completed report.

    :param report: The populated ViyaDeploymentReport returned by the report() fixture.
    """
    # get node information
    node_details: Dict = report.get_node_details()

    # check for expected attributes
    assert len(node_details) == 3
    assert node_details[ReportKeys.KindDetails.AVAILABLE] is True
    assert node_details[ReportKeys.KindDetails.COUNT] == 1
    assert len(node_details[ITEMS_KEY]) == 1
    assert KubectlTest.Values.RESOURCE_NODE_1_NAME in node_details[ITEMS_KEY]
Esempio n. 20
0
def test_gather_details_basic_user_invalid_namespace_from_command_line(
) -> None:
    """
    In the event that a user without the ability to see non-namespaced resources passes an invalid namespace on the
    command line, kubectl won't be able to verify that value as valid or invalid and will pass it along to the report.
    If this occurs, the gather_details() method should throw an error when listing pods is forbidden.
    """
    with pytest.raises(KubectlRequestForbiddenError) as exec_info:
        report: ViyaDeploymentReport = ViyaDeploymentReport()
        report.gather_details(kubectl=KubectlTest(
            include_non_namespaced_resources=False, namespace="Foo"))

    assert (
        "Listing pods is forbidden in namespace [Foo]. Make sure KUBECONFIG is correctly set and that the correct "
        "namespace is being targeted. A namespace can be given on the command line using the \"--namespace=\" "
        "option.") in str(exec_info.value)
Esempio n. 21
0
def test_get_sas_component_resources(report: ViyaDeploymentReport) -> None:
    """
    This test verifies that the resources from the given SAS Component is correctly returned from a completed report.

    :param report: The populated ViyaDeploymentReport returned by the report() fixture.
    """
    # get component resource details
    component_resource_details: Dict = report.get_sas_component_resources(
        KubectlTest.Values.COMPONENT_SAS_ANNOTATIONS_NAME,
        KubernetesResource.Kinds.DEPLOYMENT)

    # check for expected attributes
    assert len(component_resource_details) == 1
    assert KubectlTest.Values.COMPONENT_SAS_ANNOTATIONS_NAME in component_resource_details
    assert component_resource_details[KubectlTest.Values.COMPONENT_SAS_ANNOTATIONS_NAME][
               ReportKeys.ResourceDetails.RESOURCE_DEFINITION][KubernetesResource.Keys.KIND] == \
        KubernetesResource.Kinds.DEPLOYMENT
Esempio n. 22
0
def test_get_sas_component(report: ViyaDeploymentReport) -> None:
    """
    This test verifies that an existing SAS component is correctly returned from the gathered components.

    :param report: The populated ViyaDeploymentReport returned by the report() fixture.
    """
    # get SAS component information
    component: Dict = report.get_sas_component(
        KubectlTest.Values.COMPONENT_SAS_ANNOTATIONS_NAME)

    # check for expected attributes
    assert len(component) == 5
    assert KubernetesResource.Kinds.DEPLOYMENT in component
    assert KubernetesResource.Kinds.INGRESS in component
    assert KubernetesResource.Kinds.POD in component
    assert KubernetesResource.Kinds.REPLICA_SET in component
    assert KubernetesResource.Kinds.SERVICE in component
Esempio n. 23
0
def test_write_report_data_only(report: ViyaDeploymentReport) -> None:
    """
    This test verifies that only the JSON data file is written to disk when requested from a completed report.

    :param report: The populated ViyaDeploymentReport returned by the report() fixture.
    """
    # write data file only
    data_file, html_file = report.write_report(data_file_only=True)

    # make sure HTML report is None
    assert html_file is None

    # check for expected file
    assert os.path.exists(data_file)
    assert os.path.isfile(data_file)

    # clean up file
    os.remove(data_file)
Esempio n. 24
0
def test_write_report(report: ViyaDeploymentReport) -> None:
    """
    This test verifies that a completed report is correctly written to disk as both an HTML report and a JSON data file.

    :param report: The populated ViyaDeploymentReport returned by the report() fixture.
    """
    # write the report and data file
    data_file, html_file = report.write_report()

    # check for expected files
    assert os.path.exists(data_file)
    assert os.path.isfile(data_file)
    assert os.path.exists(html_file)
    assert os.path.exists(html_file)

    # clean up files
    os.remove(data_file)
    os.remove(html_file)
Esempio n. 25
0
def test_get_kubernetes_details(report: ViyaDeploymentReport) -> None:
    """
    This test verifies that the "kubernetes" dictionary in a report is populated with all of the expected keys.

    :param report: The populated ViyaDeploymentReport returned by the report() fixture.
    """
    # get the kubernetes details
    kube_details: Dict = report.get_kubernetes_details()

    # check for all expected entries
    assert len(kube_details) == 7
    assert ReportKeys.Kubernetes.API_RESOURCES_DICT in kube_details
    assert ReportKeys.Kubernetes.API_VERSIONS_LIST in kube_details
    assert ReportKeys.Kubernetes.DISCOVERED_KINDS_DICT in kube_details
    assert ReportKeys.Kubernetes.INGRESS_CTRL in kube_details
    assert ReportKeys.Kubernetes.NAMESPACE in kube_details
    assert ReportKeys.Kubernetes.NODES_DICT in kube_details
    assert ReportKeys.Kubernetes.VERSIONS_DICT in kube_details
Esempio n. 26
0
def test_get_sas_components_statefulset_owned(
        report: ViyaDeploymentReport) -> None:
    """
    This test verifies that the component owned by a StatefulSet object is correctly collected in a completed report.
    Test the collection of: (1) Pod, (2) Service, (3) StatefulSet

    :param report: The populated ViyaDeploymentReport returned by the report() fixture.
    """
    # get SAS components information
    sas_components: Dict = report.get_sas_components()

    # check for expected attributes
    assert KubectlTest.Values.COMPONENT_SAS_CACHE_SERVER_NAME in sas_components
    assert KubernetesResource.Kinds.POD in sas_components[
        KubectlTest.Values.COMPONENT_SAS_CACHE_SERVER_NAME]
    assert KubernetesResource.Kinds.SERVICE in \
        sas_components[KubectlTest.Values.COMPONENT_SAS_CACHE_SERVER_NAME]
    assert KubernetesResource.Kinds.STATEFUL_SET in \
        sas_components[KubectlTest.Values.COMPONENT_SAS_CACHE_SERVER_NAME]
Esempio n. 27
0
def test_get_sas_components_cronjob_owned(
        report: ViyaDeploymentReport) -> None:
    """
    This test verifies that the component owned by a CronJob object is correctly collected in a completed report.
    Tests the collection of: (1) CronJob, (2) Job, (3) Pod

    :param report: The populated ViyaDeploymentReport returned by the report() fixture.
    """
    # get SAS components information
    sas_components: Dict = report.get_sas_components()

    # check for expected attributes
    assert KubectlTest.Values.COMPONENT_SAS_SCHEDULED_BACKUP_JOB_NAME in sas_components
    assert KubernetesResource.Kinds.CRON_JOB in \
        sas_components[KubectlTest.Values.COMPONENT_SAS_SCHEDULED_BACKUP_JOB_NAME]
    assert KubernetesResource.Kinds.JOB in sas_components[
        KubectlTest.Values.COMPONENT_SAS_SCHEDULED_BACKUP_JOB_NAME]
    assert KubernetesResource.Kinds.POD in sas_components[
        KubectlTest.Values.COMPONENT_SAS_SCHEDULED_BACKUP_JOB_NAME]
Esempio n. 28
0
def test_get_other_components(report: ViyaDeploymentReport) -> None:
    """
    This test verifies that the non-SAS component is correctly collected in a completed report.

    :param report: The populated ViyaDeploymentReport returned by the report() fixture.
    """
    # get other components information
    other_components: Dict = report.get_other_components()

    # check for expected attributes
    assert len(other_components) == 1
    assert KubectlTest.Values.COMPONENT_PROMETHEUS_NAME in other_components
    assert KubernetesResource.Kinds.DEPLOYMENT in other_components[
        KubectlTest.Values.COMPONENT_PROMETHEUS_NAME]
    assert KubernetesResource.Kinds.POD in other_components[
        KubectlTest.Values.COMPONENT_PROMETHEUS_NAME]
    assert KubernetesResource.Kinds.REPLICA_SET in other_components[
        KubectlTest.Values.COMPONENT_PROMETHEUS_NAME]
    assert KubernetesResource.Kinds.SERVICE in other_components[
        KubectlTest.Values.COMPONENT_PROMETHEUS_NAME]
Esempio n. 29
0
def test_get_api_versions(report: ViyaDeploymentReport) -> None:
    """
    This test verifies that all expected api-versions values from the KubectlTest implementation are present in the
    "kubernetes.apiVersions" list in the completed report.

    :param report: The populated ViyaDeploymentReport returned by the report() fixture.
    """
    # get the static api-versions list
    test_data_file: Text = os.path.join(
        os.path.dirname(os.path.abspath(__file__)),
        f"..{os.sep}..{os.sep}..{os.sep}viya_ark_library{os.sep}k8s{os.sep}test_impl"
        f"{os.sep}response_data{os.sep}api_versions.json")
    with open(test_data_file, "r") as test_data_file_pointer:
        expected_api_versions: List = json.load(test_data_file_pointer)

    # get API versions information
    api_versions: List = report.get_api_versions()

    # check for expected attributes
    assert len(api_versions) == len(expected_api_versions)
    for api_version in expected_api_versions:
        assert api_version in api_versions
Esempio n. 30
0
def test_get_sas_components_deployment_owned(
        report: ViyaDeploymentReport) -> None:
    """
    This test verifies that the component owned by a Deployment object is correctly collected in a completed report.
    Tests the collection of: (1) Deployment, (2) Ingress, (3) Pod, (4) ReplicaSet, (5) Service

    :param report: The populated ViyaDeploymentReport returned by the report() fixture.
    """
    # get SAS components information
    sas_components: Dict = report.get_sas_components()

    # check for expected attributes
    assert KubectlTest.Values.COMPONENT_SAS_ANNOTATIONS_NAME in sas_components
    assert KubernetesResource.Kinds.DEPLOYMENT in sas_components[
        KubectlTest.Values.COMPONENT_SAS_ANNOTATIONS_NAME]
    assert KubernetesResource.Kinds.INGRESS in sas_components[
        KubectlTest.Values.COMPONENT_SAS_ANNOTATIONS_NAME]
    assert KubernetesResource.Kinds.POD in sas_components[
        KubectlTest.Values.COMPONENT_SAS_ANNOTATIONS_NAME]
    assert KubernetesResource.Kinds.REPLICA_SET in sas_components[
        KubectlTest.Values.COMPONENT_SAS_ANNOTATIONS_NAME]
    assert KubernetesResource.Kinds.SERVICE in sas_components[
        KubectlTest.Values.COMPONENT_SAS_ANNOTATIONS_NAME]