def custom_resource_definition(self, request, k8s_version):
        additional_labels = None
        if len(request.param) == 2:
            fiaas_path, expected = request.param
        elif len(request.param) == 3:
            fiaas_path, expected, additional_labels = request.param

        skip_if_crd_not_supported(k8s_version)
        fiaas_yml = read_yml(
            request.fspath.dirpath().join("specs").join(fiaas_path).strpath)
        expected = {
            kind: read_yml(request.fspath.dirpath().join(path).strpath)
            for kind, path in expected.items()
        }

        name = sanitize_resource_name(fiaas_path)
        metadata = ObjectMeta(name=name,
                              namespace="default",
                              labels={"fiaas/deployment_id": DEPLOYMENT_ID1})
        spec = FiaasApplicationSpec(application=name,
                                    image=IMAGE1,
                                    config=fiaas_yml,
                                    additional_labels=additional_labels)
        request.addfinalizer(lambda: self._ensure_clean(name, expected))
        return name, FiaasApplication(metadata=metadata, spec=spec), expected
Example #2
0
    def test_multiple_ingresses(self, request, kind_logger):
        with kind_logger():
            fiaas_path = "v3/data/examples/multiple_ingress.yml"
            fiaas_yml = read_yml(request.fspath.dirpath().join("specs").join(fiaas_path).strpath)

            name = sanitize_resource_name(fiaas_path)

            expected = {
                name: read_yml(request.fspath.dirpath().join("e2e_expected/multiple_ingress1.yml").strpath),
                "{}-1".format(name): read_yml(request.fspath.dirpath().join("e2e_expected/multiple_ingress2.yml").strpath)
            }
            metadata = ObjectMeta(name=name, namespace="default", labels={"fiaas/deployment_id": DEPLOYMENT_ID1})
            spec = FiaasApplicationSpec(application=name, image=IMAGE1, config=fiaas_yml)
            fiaas_application = FiaasApplication(metadata=metadata, spec=spec)

            fiaas_application.save()
            app_uid = fiaas_application.metadata.uid

            # Check that deployment status is RUNNING
            def _assert_status():
                status = FiaasApplicationStatus.get(create_name(name, DEPLOYMENT_ID1))
                assert status.result == u"RUNNING"
                assert len(status.logs) > 0
                assert any("Saving result RUNNING for default/{}".format(name) in line for line in status.logs)

            wait_until(_assert_status, patience=PATIENCE)

            def _check_two_ingresses():
                assert Ingress.get(name)
                assert Ingress.get("{}-1".format(name))

                for ingress_name, expected_dict in expected.items():
                    actual = Ingress.get(ingress_name)
                    assert_k8s_resource_matches(actual, expected_dict, IMAGE1, None, DEPLOYMENT_ID1, None, app_uid)

            wait_until(_check_two_ingresses, patience=PATIENCE)

            # Remove 2nd ingress to make sure cleanup works
            fiaas_application.spec.config["ingress"].pop()
            fiaas_application.metadata.labels["fiaas/deployment_id"] = DEPLOYMENT_ID2
            fiaas_application.save()

            def _check_one_ingress():
                assert Ingress.get(name)
                with pytest.raises(NotFound):
                    Ingress.get("{}-1".format(name))

            wait_until(_check_one_ingress, patience=PATIENCE)

            # Cleanup
            FiaasApplication.delete(name)

            def cleanup_complete():
                for name, _ in expected.items():
                    with pytest.raises(NotFound):
                        Ingress.get(name)

            wait_until(cleanup_complete, patience=PATIENCE)
    def custom_resource_definition_test_case(self, fiaas_path, namespace, labels, expected):
        fiaas_yml = read_yml(file_relative_path(fiaas_path))
        expected = {kind: read_yml_if_exists(path) for kind, path in expected.items()}

        name = sanitize_resource_name(fiaas_path)

        metadata = ObjectMeta(name=name, namespace=namespace,
                              labels=merge_dicts(labels, {"fiaas/deployment_id": DEPLOYMENT_ID}))
        spec = FiaasApplicationSpec(application=name, image=IMAGE, config=fiaas_yml)
        return name, FiaasApplication(metadata=metadata, spec=spec), expected
Example #4
0
    def third_party_resource(self, request, k8s_version):
        fiaas_path, expected = request.param
        skip_if_tpr_not_supported(k8s_version)

        fiaas_yml = read_yml(
            request.fspath.dirpath().join("specs").join(fiaas_path).strpath)
        expected = {
            kind: read_yml(request.fspath.dirpath().join(path).strpath)
            for kind, path in expected.items()
        }

        name = sanitize_resource_name(fiaas_path)
        metadata = ObjectMeta(name=name,
                              namespace="default",
                              labels={"fiaas/deployment_id": DEPLOYMENT_ID1})
        spec = PaasbetaApplicationSpec(application=name,
                                       image=IMAGE1,
                                       config=fiaas_yml)
        request.addfinalizer(lambda: self._ensure_clean(name, expected))
        return name, PaasbetaApplication(metadata=metadata,
                                         spec=spec), expected
Example #5
0
    def __init__(self):
        creds = utils.read_yml('config.yaml')
        self.account = creds['account']
        self.username = creds['username']
        self.password = creds['password']
        warehouse = creds['warehouse']

        # Sets log location
        logging.basicConfig(filename='/tmp/snowflake_python_connector.log',
                            level=logging.INFO)

        print(">>> Establishing connection.")
        print(">>> Wating for 2FA...")
        self.conn = snowflake.connector.connect(
            user=self.username,
            password=self.password,
            account=self.account,
        )
        print(">>> Connection successful.")

        self.conn.cursor().execute("USE WAREHOUSE %s;" % warehouse)
def read_yml_if_exists(path):
    if path == SHOULD_NOT_EXIST:
        return path
    else:
        return read_yml(file_relative_path(path))