示例#1
0
def verify_eds_egress_asset_tracking(fledge_url):
    conn = http.client.HTTPConnection(fledge_url)
    conn.request("GET", '/fledge/asset')
    r = conn.getresponse()
    assert 200 == r.status
    r = r.read().decode()
    retval = json.loads(r)
    assert len(retval) == 1
    assert asset_name == retval[0]["assetCode"]

    tracking_details = utils.get_asset_tracking_details(fledge_url, "Ingest")
    assert len(tracking_details["track"]), "Failed to track Ingest event"
    tracked_item = tracking_details["track"][0]
    assert "Sine" == tracked_item["service"]
    assert asset_name == tracked_item["asset"]
    assert asset_name == tracked_item["plugin"]

    egress_tracking_details = utils.get_asset_tracking_details(
        fledge_url, "Egress")
    assert len(
        egress_tracking_details["track"]), "Failed to track Egress event"
    tracked_item = egress_tracking_details["track"][0]
    assert task_name == tracked_item["service"]
    assert asset_name == tracked_item["asset"]
    assert north_plugin == tracked_item["plugin"]
示例#2
0
    def test_end_to_end(self, start_south_north, enable_schedule,
                        disable_schedule, fledge_url, read_data_from_pi,
                        pi_host, pi_admin, pi_passwd, pi_db, wait_time,
                        retries, skip_verify_north_interface, modbus_host,
                        modbus_port):
        """ Test that data is inserted in Fledge using modbus-c south plugin and sent to PI
            start_south_north: Fixture that starts Fledge with south service and north instance
            skip_verify_north_interface: Flag for assertion of data from Pi web API
            Assertions:
                on endpoint GET /fledge/asset
                on endpoint GET /fledge/asset/<asset_name> with applied data processing filter value
                data received from PI is same as data sent"""

        # self.check_connect(modbus_host, modbus_port)
        """ $ docker logs --follow modbus-device
            start listening at: port:502
            start listening at: port:503
            Quit the loop: Connection reset by peer // on check_connect
        """
        enable_schedule(fledge_url, SVC_NAME)
        time.sleep(wait_time * 2)

        ping_response = self.get_ping_status(fledge_url)
        assert 0 < ping_response["dataRead"]
        if not skip_verify_north_interface:
            assert 0 < ping_response["dataSent"]

        actual_stats_map = self.get_statistics_map(fledge_url)
        assert 0 < actual_stats_map[ASSET_NAME.upper()]
        assert 0 < actual_stats_map['READINGS']
        if not skip_verify_north_interface:
            assert 0 < actual_stats_map['Readings Sent']
            assert 0 < actual_stats_map['NorthReadingsToPI']

        conn = http.client.HTTPConnection(fledge_url)
        self._verify_ingest(conn)

        # disable schedule to stop the service and sending data
        disable_schedule(fledge_url, SVC_NAME)
        if not skip_verify_north_interface:
            self._verify_egress(read_data_from_pi, pi_host, pi_admin,
                                pi_passwd, pi_db, wait_time, retries)

        tracking_details = utils.get_asset_tracking_details(
            fledge_url, "Ingest")
        assert len(tracking_details["track"]), "Failed to track Ingest event"
        tracked_item = tracking_details["track"][0]
        assert SVC_NAME == tracked_item["service"]
        assert ASSET_NAME == tracked_item["asset"]
        assert PLUGIN_NAME == tracked_item["plugin"]

        if not skip_verify_north_interface:
            egress_tracking_details = utils.get_asset_tracking_details(
                fledge_url, "Egress")
            assert len(egress_tracking_details["track"]
                       ), "Failed to track Egress event"
            tracked_item = egress_tracking_details["track"][0]
            assert "NorthReadingsToPI" == tracked_item["service"]
            assert ASSET_NAME == tracked_item["asset"]
            assert "OMF" == tracked_item["plugin"]
示例#3
0
    def test_end_to_end(self, start_south_north, disable_schedule, fledge_url, read_data_from_pi, pi_host, pi_admin,
                        pi_passwd, pi_db, wait_time, retries, skip_verify_north_interface):
        """ Test that data is inserted in Fledge using expression south plugin & metadata filter, and sent to PI
            start_south_north: Fixture that starts Fledge with south service, add filter and north instance
            skip_verify_north_interface: Flag for assertion of data from Pi web API
            Assertions:
                on endpoint GET /fledge/asset
                on endpoint GET /fledge/asset/<asset_name> with applied data processing filter value
                data received from PI is same as data sent"""

        time.sleep(wait_time)

        ping_response = self.get_ping_status(fledge_url)
        assert 0 < ping_response["dataRead"]
        if not skip_verify_north_interface:
            assert 0 < ping_response["dataSent"]

        actual_stats_map = self.get_statistics_map(fledge_url)
        assert 0 < actual_stats_map[ASSET_NAME.upper()]
        assert 0 < actual_stats_map['READINGS']
        if not skip_verify_north_interface:
            assert 0 < actual_stats_map['Readings Sent']
            assert 0 < actual_stats_map['NorthReadingsToPI']

        conn = http.client.HTTPConnection(fledge_url)
        self._verify_ingest(conn)

        # disable schedule to stop the service and sending data
        disable_schedule(fledge_url, SVC_NAME)
        if not skip_verify_north_interface:
            self._verify_egress(read_data_from_pi, pi_host, pi_admin, pi_passwd, pi_db, wait_time, retries)

        tracking_details = utils.get_asset_tracking_details(fledge_url, "Ingest")
        assert len(tracking_details["track"]), "Failed to track Ingest event"
        tracked_item = tracking_details["track"][0]
        assert SVC_NAME == tracked_item["service"]
        assert ASSET_NAME == tracked_item["asset"]
        assert "Expression" == tracked_item["plugin"]

        tracking_details = utils.get_asset_tracking_details(fledge_url, "Filter")
        assert len(tracking_details["track"]), "Failed to track Filter event"
        tracked_item = tracking_details["track"][0]
        assert SVC_NAME == tracked_item["service"]
        assert ASSET_NAME == tracked_item["asset"]
        assert "Meta #1" == tracked_item["plugin"]

        if not skip_verify_north_interface:
            egress_tracking_details = utils.get_asset_tracking_details(fledge_url,"Egress")
            assert len(egress_tracking_details["track"]), "Failed to track Egress event"
            tracked_item = egress_tracking_details["track"][0]
            assert "NorthReadingsToPI" == tracked_item["service"]
            assert ASSET_NAME == tracked_item["asset"]
            assert "PI_Server_V2" == tracked_item["plugin"]
示例#4
0
    def test_end_to_end(self, start_south_north_with_filter, read_data_from_pi,
                        fledge_url, pi_host, pi_admin, pi_passwd, pi_db,
                        wait_time, retries, skip_verify_north_interface):

        subprocess.run([
            "cd $FLEDGE_ROOT/extras/python; python3 -m fogbench -t ../../data/template.json -p http; cd -"
        ],
                       shell=True,
                       check=True)
        # let the readings ingress
        time.sleep(wait_time * 2)

        self._verify_ping_and_statistics(
            fledge_url,
            count=1,
            skip_verify_north_interface=skip_verify_north_interface)

        self._verify_ingest(fledge_url, SENSOR_VALUE, read_count=1)

        if not skip_verify_north_interface:
            self._verify_egress(read_data_from_pi, pi_host, pi_admin,
                                pi_passwd, pi_db, wait_time, retries)

        tracking_details = utils.get_asset_tracking_details(
            fledge_url, "Ingest")
        assert len(tracking_details["track"]), "Failed to track Ingest event"
        tracked_item = tracking_details["track"][0]
        assert SVC_NAME == tracked_item["service"]
        assert "http-e1" == tracked_item["asset"]
        assert "http_south" == tracked_item["plugin"]

        tracking_details = utils.get_asset_tracking_details(
            fledge_url, "Filter")
        assert len(tracking_details["track"]), "Failed to track Filter event"
        tracked_item = tracking_details["track"][0]
        assert TASK_NAME == tracked_item["service"]
        assert "http-e1" == tracked_item["asset"]
        assert "SS #1" == tracked_item["plugin"]

        if not skip_verify_north_interface:
            egress_tracking_details = utils.get_asset_tracking_details(
                fledge_url, "Egress")
            assert len(egress_tracking_details["track"]
                       ), "Failed to track Egress event"
            tracked_item = egress_tracking_details["track"][0]
            assert TASK_NAME == tracked_item["service"]
            assert "http-e1" == tracked_item["asset"]
            assert "OMF" == tracked_item["plugin"]
示例#5
0
def test_smoke(start_south_coap, fledge_url, wait_time, asset_name="smoke"):
    """ Test that data is inserted in Fledge
        start_south_coap: Fixture that starts Fledge with south coap plugin
        Assertions:
            on endpoint GET /fledge/asset
            on endpoint GET /fledge/asset/<asset_name>
    """

    conn = http.client.HTTPConnection(fledge_url)
    time.sleep(wait_time)
    subprocess.run([
        "cd $FLEDGE_ROOT/extras/python; python3 -m fogbench -t ../../data/{}; cd -"
        .format(TEMPLATE_NAME)
    ],
                   shell=True,
                   check=True)
    time.sleep(wait_time)

    ping_response = get_ping_status(fledge_url)
    assert 1 == ping_response["dataRead"]
    assert 0 == ping_response["dataSent"]

    actual_stats_map = get_statistics_map(fledge_url)
    assert 1 == actual_stats_map[asset_name.upper()]
    assert 1 == actual_stats_map['READINGS']

    conn.request("GET", '/fledge/asset')
    r = conn.getresponse()

    assert 200 == r.status
    r = r.read().decode()
    retval = json.loads(r)
    assert len(retval) == 1
    assert asset_name == retval[0]["assetCode"]
    assert 1 == retval[0]["count"]

    conn.request("GET", '/fledge/asset/{}'.format(asset_name))
    r = conn.getresponse()
    assert 200 == r.status
    r = r.read().decode()
    retval = json.loads(r)
    assert {'sensor': SENSOR_VALUE} == retval[0]["reading"]

    tracking_details = utils.get_asset_tracking_details(fledge_url, "Ingest")
    assert len(tracking_details["track"]), "Failed to track Ingest event"
    tracked_item = tracking_details["track"][0]
    assert "coap" == tracked_item["service"]
    assert "smoke" == tracked_item["asset"]
    assert "coap" == tracked_item["plugin"]
示例#6
0
    def test_end_to_end(self,
                        start_south_north,
                        read_data_from_pi,
                        fledge_url,
                        pi_host,
                        pi_admin,
                        pi_passwd,
                        pi_db,
                        wait_time,
                        retries,
                        skip_verify_north_interface,
                        asset_name="end_to_end_coap"):
        """ Test that data is inserted in Fledge and sent to PI
            start_south_north: Fixture that starts Fledge with south and north instance
            read_data_from_pi: Fixture to read data from PI
            skip_verify_north_interface: Flag for assertion of data from Pi web API
            Assertions:
                on endpoint GET /fledge/asset
                on endpoint GET /fledge/asset/<asset_name>
                data received from PI is same as data sent"""

        conn = http.client.HTTPConnection(fledge_url)
        time.sleep(wait_time)
        subprocess.run([
            "cd $FLEDGE_ROOT/extras/python; python3 -m fogbench -t ../../data/{}; cd -"
            .format(TEMPLATE_NAME)
        ],
                       shell=True,
                       check=True)
        time.sleep(wait_time)

        ping_response = get_ping_status(fledge_url)
        assert 1 == ping_response["dataRead"]
        if not skip_verify_north_interface:
            assert 1 == ping_response["dataSent"]

        actual_stats_map = get_statistics_map(fledge_url)
        assert 1 == actual_stats_map[asset_name.upper()]
        assert 1 == actual_stats_map['READINGS']
        if not skip_verify_north_interface:
            assert 1 == actual_stats_map['Readings Sent']
            assert 1 == actual_stats_map['NorthReadingsToPI']

        conn.request("GET", '/fledge/asset')
        r = conn.getresponse()
        assert 200 == r.status
        r = r.read().decode()
        retval = json.loads(r)
        assert len(retval) == 1
        assert asset_name == retval[0]["assetCode"]
        assert 1 == retval[0]["count"]

        conn.request("GET", '/fledge/asset/{}'.format(asset_name))
        r = conn.getresponse()
        assert 200 == r.status
        r = r.read().decode()
        retval = json.loads(r)
        assert {'sensor': SENSOR_VALUE} == retval[0]["reading"]

        if not skip_verify_north_interface:
            _verify_egress(read_data_from_pi, pi_host, pi_admin, pi_passwd,
                           pi_db, wait_time, retries, asset_name)

        tracking_details = utils.get_asset_tracking_details(
            fledge_url, "Ingest")
        assert len(tracking_details["track"]), "Failed to track Ingest event"
        tracked_item = tracking_details["track"][0]
        assert "coap" == tracked_item["service"]
        assert "end_to_end_coap" == tracked_item["asset"]
        assert "coap" == tracked_item["plugin"]

        if not skip_verify_north_interface:
            egress_tracking_details = utils.get_asset_tracking_details(
                fledge_url, "Egress")
            assert len(egress_tracking_details["track"]
                       ), "Failed to track Egress event"
            tracked_item = egress_tracking_details["track"][0]
            assert "NorthReadingsToPI" == tracked_item["service"]
            assert "end_to_end_coap" == tracked_item["asset"]
            assert "PI_Server_V2" == tracked_item["plugin"]
    def test_end_to_end(self, start_south_north, disable_schedule, fledge_url,
                        read_data_from_pi, pi_host, pi_admin, pi_passwd, pi_db,
                        wait_time, retries, skip_verify_north_interface):
        """ Test that data is inserted in Fledge using playback south plugin &
            FFT filter, and sent to PI after passing through threshold filter
            start_south_north: Fixture that starts Fledge with south service, add filter and north instance
            skip_verify_north_interface: Flag for assertion of data from Pi web API
            Assertions:
                on endpoint GET /fledge/asset
                on endpoint GET /fledge/asset/<asset_name> with applied data processing filter value
                data received from PI is same as data sent"""

        time.sleep(wait_time)
        conn = http.client.HTTPConnection(fledge_url)

        self._verify_ingest(conn)

        # disable schedule to stop the service and sending data
        disable_schedule(fledge_url, SVC_NAME)

        ping_response = self.get_ping_status(fledge_url)
        assert 6 == ping_response["dataRead"]
        if not skip_verify_north_interface:
            assert 1 == ping_response["dataSent"]

        actual_stats_map = self.get_statistics_map(fledge_url)
        assert 6 == actual_stats_map[ASSET.upper() + " FFT"]
        assert 6 == actual_stats_map['READINGS']
        if not skip_verify_north_interface:
            assert 1 == actual_stats_map['Readings Sent']
            assert 1 == actual_stats_map[NORTH_TASK_NAME]

        if not skip_verify_north_interface:
            self._verify_egress(read_data_from_pi, pi_host, pi_admin,
                                pi_passwd, pi_db, wait_time, retries)

        tracking_details = utils.get_asset_tracking_details(
            fledge_url, "Ingest")
        assert len(tracking_details["track"]), "Failed to track Ingest event"
        tracked_item = tracking_details["track"][0]
        assert SVC_NAME == tracked_item["service"]
        assert "e2e_fft_threshold FFT" == tracked_item["asset"]
        assert "playback" == tracked_item["plugin"]

        # TODO: FOGL:3440,FOGL:3441 Add asset tracker entry for fft and threshold filters
        # tracking_details = self.get_asset_tracking_details(fledge_url, "Filter")
        # assert len(tracking_details["track"]), "Failed to track Ingest event"
        # tracked_item = tracking_details["track"][0]
        # assert "playfilter" == tracked_item["service"]
        # assert "e2e_fft_threshold FFT" == tracked_item["asset"]
        # assert "FFT Filter" == tracked_item["plugin"]

        if not skip_verify_north_interface:
            egress_tracking_details = utils.get_asset_tracking_details(
                fledge_url, "Egress")
            assert len(egress_tracking_details["track"]
                       ), "Failed to track Egress event"
            tracked_item = egress_tracking_details["track"][0]
            assert NORTH_TASK_NAME == tracked_item["service"]
            assert "e2e_fft_threshold FFT" == tracked_item["asset"]
            assert "OMF" == tracked_item["plugin"]
示例#8
0
    def test_end_to_end(self, start_south_north, fledge_url, wait_time,
                        kafka_host, kafka_rest_port, kafka_topic,
                        skip_verify_north_interface):
        """ Test that data is inserted in Fledge and sent to Kafka
            start_south_north: Fixture that starts Fledge with south and north instance
            skip_verify_north_interface: Flag for assertion of data from kafka rest
            Assertions:
                on endpoint GET /fledge/asset
                on endpoint GET /fledge/asset/<asset_name>
                data received from Kafka is same as data sent"""

        conn = http.client.HTTPConnection(fledge_url)
        time.sleep(wait_time)
        subprocess.run([
            "cd $FLEDGE_ROOT/extras/python; python3 -m fogbench -t ../../data/{}; cd -"
            .format(FOGBENCH_TEMPLATE)
        ],
                       shell=True,
                       check=True)
        time.sleep(wait_time)

        ping_response = self.get_ping_status(fledge_url)
        assert 1 == ping_response["dataRead"]
        if not skip_verify_north_interface:
            assert 1 == ping_response["dataSent"]

        actual_stats_map = self.get_statistics_map(fledge_url)
        assert 1 == actual_stats_map[ASSET_NAME.upper()]
        assert 1 == actual_stats_map['READINGS']
        if not skip_verify_north_interface:
            assert 1 == actual_stats_map['Readings Sent']
            assert 1 == actual_stats_map["NorthReadingsTo{}".format(
                NORTH_PLUGIN_NAME)]

        conn.request("GET", '/fledge/asset')
        r = conn.getresponse()
        assert 200 == r.status
        r = r.read().decode()
        val = json.loads(r)
        assert 1 == len(val)
        assert ASSET_NAME == val[0]["assetCode"]
        assert 1 == val[0]["count"]

        conn.request("GET", '/fledge/asset/{}'.format(ASSET_NAME))
        r = conn.getresponse()
        assert 200 == r.status
        r = r.read().decode()
        val = json.loads(r)
        assert 1 == len(val)
        assert {'sensor': SENSOR_VALUE} == val[0]["reading"]

        if not skip_verify_north_interface:
            self._read_from_kafka(kafka_host, kafka_rest_port, kafka_topic)

        tracking_details = utils.get_asset_tracking_details(
            fledge_url, "Ingest")
        assert len(tracking_details["track"]), "Failed to track Ingest event"
        tracked_item = tracking_details["track"][0]
        assert "coap" == tracked_item["service"]
        assert ASSET_NAME == tracked_item["asset"]
        assert SOUTH_PLUGIN_NAME == tracked_item["plugin"]

        if not skip_verify_north_interface:
            egress_tracking_details = utils.get_asset_tracking_details(
                fledge_url, "Egress")
            assert len(egress_tracking_details["track"]
                       ), "Failed to track Egress event"
            tracked_item = egress_tracking_details["track"][0]
            assert "NorthReadingsTo{}".format(
                NORTH_PLUGIN_NAME) == tracked_item["service"]
            assert ASSET_NAME == tracked_item["asset"]
            assert NORTH_PLUGIN_NAME == tracked_item["plugin"]
示例#9
0
    def test_e2e_csv_pi(self,
                        start_south_north,
                        read_data_from_pi,
                        fledge_url,
                        pi_host,
                        pi_admin,
                        pi_passwd,
                        pi_db,
                        wait_time,
                        retries,
                        skip_verify_north_interface,
                        asset_name="end_to_end_csv"):
        """ Test that data is inserted in Fledge and sent to PI
            start_south_north: Fixture that starts Fledge with south and north instance
            read_data_from_pi: Fixture to read data from PI
            skip_verify_north_interface: Flag for assertion of data from Pi web API
            Assertions:
                on endpoint GET /fledge/asset
                on endpoint GET /fledge/asset/<asset_name>
                data received from PI is same as data sent"""

        conn = http.client.HTTPConnection(fledge_url)
        time.sleep(wait_time)

        ping_response = get_ping_status(fledge_url)
        assert len(CSV_DATA) == ping_response["dataRead"]
        if not skip_verify_north_interface:
            assert len(CSV_DATA) == ping_response["dataSent"]

        actual_stats_map = get_statistics_map(fledge_url)
        assert len(CSV_DATA) == actual_stats_map[asset_name.upper()]
        assert len(CSV_DATA) == actual_stats_map['READINGS']
        if not skip_verify_north_interface:
            assert len(CSV_DATA) == actual_stats_map['Readings Sent']
            assert len(CSV_DATA) == actual_stats_map['NorthReadingsToPI']

        conn.request("GET", '/fledge/asset')
        r = conn.getresponse()
        assert 200 == r.status
        r = r.read().decode()
        retval = json.loads(r)
        assert len(retval) == 1
        assert asset_name == retval[0]["assetCode"]
        assert len(CSV_DATA) == retval[0]["count"]

        for _head in CSV_HEADERS.split(","):
            conn.request("GET",
                         '/fledge/asset/{}/{}'.format(asset_name, _head))
            r = conn.getresponse()
            assert 200 == r.status
            r = r.read().decode()
            retval = json.loads(r)
            _actual_read_list = []
            for _el in retval:
                _actual_read_list.append(_el[_head])
            assert Counter(_actual_read_list) == Counter(_data_str[_head])

        if not skip_verify_north_interface:
            _verify_egress(read_data_from_pi, pi_host, pi_admin, pi_passwd,
                           pi_db, wait_time, retries, asset_name)

        tracking_details = utils.get_asset_tracking_details(
            fledge_url, "Ingest")
        assert len(tracking_details["track"]), "Failed to track Ingest event"
        tracked_item = tracking_details["track"][0]
        assert "play" == tracked_item["service"]
        assert asset_name == tracked_item["asset"]
        assert "playback" == tracked_item["plugin"]

        if not skip_verify_north_interface:
            egress_tracking_details = utils.get_asset_tracking_details(
                fledge_url, "Egress")
            assert len(egress_tracking_details["track"]
                       ), "Failed to track Egress event"
            tracked_item = egress_tracking_details["track"][0]
            assert "NorthReadingsToPI" == tracked_item["service"]
            assert asset_name == tracked_item["asset"]
            assert "OMF" == tracked_item["plugin"]
示例#10
0
    def test_end_to_end(self, start_south_north, read_data_from_pi, fledge_url,
                        pi_host, pi_admin, pi_passwd, pi_db, wait_time,
                        retries, skip_verify_north_interface):
        """ Test that data is inserted in Fledge and sent to PI
            start_south_north: Fixture that starts Fledge with south and north instance
            read_data_from_pi: Fixture to read data from PI
            skip_verify_north_interface: Flag for assertion of data from Pi web API
            Assertions:
                on endpoint GET /fledge/asset
                on endpoint GET /fledge/asset/<asset_name>
                data received from PI is same as data sent"""

        # Allow http_south service to come up and register before sending data
        time.sleep(wait_time)
        conn = http.client.HTTPConnection(fledge_url)

        # Send data to fledge-south-http
        conn_http_south = http.client.HTTPConnection("localhost:6683")

        asset_name = "e2e_varying"
        # 2 list having mixed data simulating different sensors
        # (sensors coming up and down, sensors throwing int and float data)
        sensor_data = [{"a": 1}, {"a": 2, "b": 3}, {"b": 4}]
        sensor_data_2 = [{"b": 1.1}, {"a2": 2, "b2": 3}, {"a": 4.0}]
        for d in sensor_data + sensor_data_2:
            tm = str(datetime.now(timezone.utc).astimezone())
            data = [{
                "asset": "{}".format(asset_name),
                "timestamp": "{}".format(tm),
                "key": str(uuid.uuid4()),
                "readings": d
            }]
            conn_http_south.request("POST", '/sensor-reading',
                                    json.dumps(data))
            r = conn_http_south.getresponse()
            assert 200 == r.status
            r = r.read().decode()
            jdoc = json.loads(r)
            assert {'result': 'success'} == jdoc

        # Allow some buffer so that data is ingested before retrieval
        time.sleep(wait_time)

        ping_response = self.get_ping_status(fledge_url)
        assert 6 == ping_response["dataRead"]
        if not skip_verify_north_interface:
            assert 6 == ping_response["dataSent"]

        actual_stats_map = self.get_statistics_map(fledge_url)
        assert 6 == actual_stats_map[asset_name.upper()]
        assert 6 == actual_stats_map['READINGS']
        if not skip_verify_north_interface:
            assert 6 == actual_stats_map['Readings Sent']
            assert 6 == actual_stats_map['NorthReadingsToPI']

        conn.request("GET", '/fledge/asset')
        r = conn.getresponse()
        assert 200 == r.status
        r = r.read().decode()
        retval = json.loads(r)
        assert len(retval) == 1
        assert asset_name == retval[0]["assetCode"]
        assert 6 == retval[0]["count"]

        conn.request("GET", '/fledge/asset/{}'.format(asset_name))
        r = conn.getresponse()
        assert 200 == r.status
        r = r.read().decode()
        retval = json.loads(r)

        assert sensor_data_2[2] == retval[0]["reading"]
        assert sensor_data_2[1] == retval[1]["reading"]
        assert sensor_data_2[0] == retval[2]["reading"]
        assert sensor_data[2] == retval[3]["reading"]
        assert sensor_data[1] == retval[4]["reading"]
        assert sensor_data[0] == retval[5]["reading"]

        if not skip_verify_north_interface:
            # Allow some buffer so that data is ingested in PI before fetching using PI Web API
            time.sleep(wait_time)
            self._verify_egress(read_data_from_pi, pi_host, pi_admin,
                                pi_passwd, pi_db, wait_time, retries,
                                asset_name, sensor_data, sensor_data_2)

        tracking_details = utils.get_asset_tracking_details(
            fledge_url, "Ingest")
        assert len(tracking_details["track"]), "Failed to track Ingest event"
        tracked_item = tracking_details["track"][0]
        assert "http_south" == tracked_item["service"]
        assert asset_name == tracked_item["asset"]
        assert "http_south" == tracked_item["plugin"]

        if not skip_verify_north_interface:
            egress_tracking_details = utils.get_asset_tracking_details(
                fledge_url, "Egress")
            assert len(egress_tracking_details["track"]
                       ), "Failed to track Egress event"
            tracked_item = egress_tracking_details["track"][0]
            assert "NorthReadingsToPI" == tracked_item["service"]
            assert asset_name == tracked_item["asset"]
            assert "OMF" == tracked_item["plugin"]
示例#11
0
    def test_end_to_end(self, start_south_north, disable_schedule, fledge_url, read_data_from_pi, pi_host, pi_admin,
                        pi_passwd, pi_db, wait_time, retries, skip_verify_north_interface):
        """ Test that data is inserted in Fledge using playback south plugin &
            Delta, RMS, Rate, Scale, Asset & Metadata filters, and sent to PI
            start_south_north: Fixture that starts Fledge with south service, add filter and north instance
            skip_verify_north_interface: Flag for assertion of data from Pi web API
            Assertions:
                on endpoint GET /fledge/asset
                on endpoint GET /fledge/asset/<asset_name> with applied data processing filter value
                data received from PI is same as data sent"""

        time.sleep(wait_time)
        conn = http.client.HTTPConnection(fledge_url)
        self._verify_ingest(conn)

        # disable schedule to stop the service and sending data
        disable_schedule(fledge_url, SVC_NAME)

        ping_response = self.get_ping_status(fledge_url)
        assert 1 == ping_response["dataRead"]
        if not skip_verify_north_interface:
            assert 1 == ping_response["dataSent"]

        actual_stats_map = self.get_statistics_map(fledge_url)
        assert 1 == actual_stats_map["e2e_filters_RMS".upper()]
        assert 1 == actual_stats_map['READINGS']
        if not skip_verify_north_interface:
            assert 1 == actual_stats_map['Readings Sent']
            assert 1 == actual_stats_map['NorthReadingsToPI']

        if not skip_verify_north_interface:
            self._verify_egress(read_data_from_pi, pi_host, pi_admin, pi_passwd, pi_db, wait_time, retries)

        tracking_details = utils.get_asset_tracking_details(fledge_url, "Ingest")
        assert len(tracking_details["track"]), "Failed to track Ingest event"
        tracked_item = tracking_details["track"][0]
        assert SVC_NAME == tracked_item["service"]
        assert "e2e_filters_RMS" == tracked_item["asset"]
        assert "playback" == tracked_item["plugin"]

        tracking_details = utils.get_asset_tracking_details(fledge_url, "Filter")
        assert len(tracking_details["track"]), "Failed to track Filter event"
        tracked_item = tracking_details["track"][0]
        assert SVC_NAME == tracked_item["service"]
        assert "e2e_csv_filter_pi" == tracked_item["asset"]
        assert "fscale" == tracked_item["plugin"]

        tracked_item = tracking_details["track"][1]
        assert SVC_NAME == tracked_item["service"]
        assert "e2e_csv_filter_pi" == tracked_item["asset"]
        assert "fasset" == tracked_item["plugin"]

        tracked_item = tracking_details["track"][2]
        assert SVC_NAME == tracked_item["service"]
        assert "e2e_filters" == tracked_item["asset"]
        assert "fasset" == tracked_item["plugin"]

        tracked_item = tracking_details["track"][3]
        assert SVC_NAME == tracked_item["service"]
        assert "e2e_filters" == tracked_item["asset"]
        assert "frate" == tracked_item["plugin"]

        tracked_item = tracking_details["track"][4]
        assert SVC_NAME == tracked_item["service"]
        assert "e2e_filters" == tracked_item["asset"]
        assert "fdelta" == tracked_item["plugin"]

        tracked_item = tracking_details["track"][5]
        assert SVC_NAME == tracked_item["service"]
        assert "e2e_filters_RMS" == tracked_item["asset"]
        assert "frms" == tracked_item["plugin"]

        tracked_item = tracking_details["track"][6]
        assert SVC_NAME == tracked_item["service"]
        assert "e2e_filters_RMS" == tracked_item["asset"]
        assert "fmeta" == tracked_item["plugin"]

        if not skip_verify_north_interface:
            egress_tracking_details = utils.get_asset_tracking_details(fledge_url,"Egress")
            assert len(egress_tracking_details["track"]), "Failed to track Egress event"
            tracked_item = egress_tracking_details["track"][0]
            assert "NorthReadingsToPI" == tracked_item["service"]
            assert "e2e_filters_RMS" == tracked_item["asset"]
            assert "OMF" == tracked_item["plugin"]