def lad(openshift: OpenShift, config: dict, factstore: list) -> list:
    """Provide deployed lad objects."""
    es_endpoint = "lad-elasticsearch-service.{}.svc:9200".format(
        openshift.namespace
    )

    if not factstore:
        host = "no-host"
    else:
        resources = openshift.extract_resource_from_response(
            resp=factstore,
            kind="Route",
        )
        template_route = resources.pop()
        route_name = template_route['metadata']['name']
        try:
            oc_fs_route = openshift.get_route_by_name(route_name)
            host = oc_fs_route['spec']['host']
        except Exception as e:
            logging.warning("Could not retrieve factstore route.")
            host = "no-host"
    factstore_url = "http://{}".format(host)

    lad = template_deployer(openshift=openshift,
                            spec=Spec.LAD,
                            config=config,
                            FACT_STORE_URL=factstore_url,
                            ES_ENDPOINT=es_endpoint)

    yield lad
    if config['openshift']['clean'].lower() == "true":
        delete_objects(openshift, config, Spec.LAD,
                       FACT_STORE_URL=factstore_url,
                       ES_ENDPOINT=es_endpoint)
        delete_template(openshift, config, Spec.LAD)
Esempio n. 2
0
def test_ad_demo_order_placement(openshift: OpenShift, ad_demo: list,
                                 config: dict):
    """Test Anomaly Detection Demo Order Placement."""
    check_skip_test(config=config,
                    spec=Spec.AD_DEMO,
                    test_name=test_ad_demo_order_placement.__name__)
    # Ensure we successfully deployed (if indicated) or retrieved template.
    assert len(ad_demo) > 0
    resources = openshift.extract_resource_from_response(
        resp=ad_demo,
        kind="Route",
    )
    resources = list(
        filter(lambda route: not route['metadata']['name'].endswith('metrics'),
               resources))
    template_route = resources.pop()
    route_name = template_route['metadata']['name']
    route = openshift.get_route_by_name(route_name)
    route_url = "http://{}/mock/orderService".format(route['spec']['host'])
    form_data = {
        "79161a98-30e0-11e7-b4e8-9801a798fc8f[id]": "1",
        "79161a98-30e0-11e7-b4e8-9801a798fc8f[image]": "bananas.jpg",
        "79161a98-30e0-11e7-b4e8-9801a798fc8f[pname]": "bananas",
        "79161a98-30e0-11e7-b4e8-9801a798fc8f[pprice]": "5",
        "79161a98-30e0-11e7-b4e8-9801a798fc8f[pquant]": "1",
        "79161a98-30e0-11e7-b4e8-9801a798fc8f[ptype]": "fruit",
        "79161a98-30e0-11e7-b4e8-9801a798fc8f[newQuant]": "1",
        "7915f0cc-30e0-11e7-91c7-9801a798fc8f[id]": "2",
        "7915f0cc-30e0-11e7-91c7-9801a798fc8f[image]": "onions.jpg",
        "7915f0cc-30e0-11e7-91c7-9801a798fc8f[pname]": "onions",
        "7915f0cc-30e0-11e7-91c7-9801a798fc8f[pprice]": "3",
        "7915f0cc-30e0-11e7-91c7-9801a798fc8f[pquant]": "1",
        "7915f0cc-30e0-11e7-91c7-9801a798fc8f[ptype]": "vegetables",
        "7915f0cc-30e0-11e7-91c7-9801a798fc8f[newQuant]": "1"
    }
    with requests.Session() as s:
        s.headers = {"User-Agent": "Mozilla/5.0"}
        res = s.post(route_url, data=form_data)
    assert res.status_code == 200