Exemple #1
0
    def test_custom_instance_id(self):
        instance_manager = get_test_pipeline_manager()
        instance_manager.config_manager.save_pipeline_config(
            "test_pipeline", {"camera_name": "simulation"})

        instance_id, stream_address = instance_manager.create_pipeline(
            "test_pipeline", instance_id="custom_instance")

        self.assertEqual(instance_id, "custom_instance",
                         "Custom instance name was not set.")

        with self.assertRaisesRegex(
                ValueError,
                "Instance with id 'custom_instance' is already present and running. "
                "Use another instance_id or stop the current instance "
                "if you want to reuse the same instance_id."):
            instance_manager.create_pipeline("test_pipeline",
                                             instance_id="custom_instance")

        instance_manager.stop_instance("custom_instance")

        instance_id, stream_address = instance_manager.create_pipeline(
            configuration={"camera_name": "simulation"},
            instance_id="custom_instance")

        self.assertEqual(instance_id, "custom_instance",
                         "Custom instance name was not set.")

        instance_manager.stop_all_instances()
Exemple #2
0
    def test_reload_after_stop(self):
        instance_manager = get_test_pipeline_manager()

        instance_id = "trying_to_test"

        initial_config = {"camera_name": "simulation"}

        instance_manager.config_manager.save_pipeline_config(
            instance_id, initial_config)
        instance_manager.get_instance_stream(instance_id)

        self.assertEqual(
            instance_manager.get_instance(instance_id).get_configuration()
            ["image_threshold"], None)

        updated_config = {"camera_name": "simulation", "image_threshold": 9999}

        instance_manager.config_manager.save_pipeline_config(
            instance_id, updated_config)

        self.assertEqual(
            instance_manager.get_instance(instance_id).get_configuration()
            ["image_threshold"], None, "It should not change at this point.")

        instance_manager.stop_instance(instance_id)
        instance_manager.get_instance_stream(instance_id)

        self.assertEqual(
            instance_manager.get_instance(
                instance_id).get_configuration()["image_threshold"], 9999,
            "It should have changed now - reload should happen.")

        instance_manager.stop_all_instances()
    def test_get_set_delete_pipeline_config(self):
        instance_manager = get_test_pipeline_manager()

        pipelines = instance_manager.config_manager.get_pipeline_list()
        self.assertIsNot(pipelines,
                         "Pipelines should be empty at the beginning.")

        example_pipeline_config = {"camera_name": "simulation"}

        instance_manager.config_manager.save_pipeline_config(
            "simulation_pipeline", example_pipeline_config)
        self.assertListEqual(
            ["simulation_pipeline"],
            instance_manager.config_manager.get_pipeline_list(),
            "Pipeline not added.")

        expected_config = deepcopy(PipelineConfig.DEFAULT_CONFIGURATION)
        expected_config.update(example_pipeline_config)

        self.assertDictEqual(
            expected_config,
            instance_manager.config_manager.get_pipeline_config(
                "simulation_pipeline"),
            "Saved and retrieved pipeline configs are not the same.")

        instance_manager.config_manager.delete_pipeline_config(
            "simulation_pipeline")
        self.assertIsNot(instance_manager.config_manager.get_pipeline_list(),
                         "Pipeline config should be empty.")

        with self.assertRaisesRegex(
                ValueError,
                "Pipeline 'non_existing_pipeline' does not exist."):
            instance_manager.config_manager.delete_pipeline_config(
                "non_existing_pipeline")
Exemple #4
0
    def test_get_pipeline_list(self):
        pipeline_manager = get_test_pipeline_manager()
        self.assertEqual(len(pipeline_manager.get_pipeline_list()), 0,
                         "Pipeline manager should be empty by default.")

        initial_config = {"test_pipeline1": {}, "test_pipeline2": {}}

        pipeline_manager.config_manager.config_provider.configs = initial_config

        self.assertListEqual(sorted(list(initial_config.keys())),
                             sorted(pipeline_manager.get_pipeline_list()),
                             "Set and received lists are not the same.")
    def test_invalid_config(self):
        instance_manager = get_test_pipeline_manager()

        invalid_pipeline_config = {
            # Wrong attribute name - should be "camera_name".
            "camera": "simulation"
        }

        with self.assertRaisesRegex(
                ValueError, "Camera name not specified in configuration."):
            instance_manager.config_manager.save_pipeline_config(
                "invalid_pipeline", invalid_pipeline_config)
Exemple #6
0
    def test_delete_pipeline(self):
        instance_manager = get_test_pipeline_manager()
        self.assertEqual(len(instance_manager.get_pipeline_list()), 0,
                         "Pipeline should be empty")

        instance_manager.config_manager.save_pipeline_config(
            "test", {"camera_name": "simulation"})
        self.assertEqual(len(instance_manager.get_pipeline_list()), 1,
                         "Pipeline should not be empty")

        instance_manager.config_manager.delete_pipeline_config("test")
        self.assertEqual(len(instance_manager.get_pipeline_list()), 0,
                         "Pipeline should be empty")
    def test_load_pipeline(self):
        instance_manager = get_test_pipeline_manager()

        example_pipeline_config = {"camera_name": "simulation"}

        instance_manager.config_manager.save_pipeline_config(
            "pipeline_simulation", example_pipeline_config)

        expected_config = deepcopy(PipelineConfig.DEFAULT_CONFIGURATION)
        expected_config.update(example_pipeline_config)

        pipeline = instance_manager.config_manager.load_pipeline(
            "pipeline_simulation")
        self.assertDictEqual(pipeline.get_configuration(), expected_config,
                             "Saved and loaded pipelines are not the same.")
Exemple #8
0
    def test_multiple_get_stream(self):
        instance_manager = get_test_pipeline_manager()
        instance_manager.config_manager.save_pipeline_config(
            "simulation", {"camera_name": "simulation"})

        stream_address_1 = instance_manager.get_instance_stream("simulation")
        stream_address_2 = instance_manager.get_instance_stream("simulation")

        self.assertEqual(stream_address_1, stream_address_2)
        self.assertTrue(instance_manager.is_instance_present("simulation"))

        instance_port = instance_manager.get_instance(
            "simulation").get_stream_port()

        self.assertEqual(instance_manager._used_ports[instance_port],
                         "simulation")

        instance_manager.stop_instance("simulation")

        self.assertEqual(len(instance_manager._used_ports), 0)

        self.assertFalse(instance_manager.is_instance_present("simulation"),
                         "Instance should have been deleted.")

        stream_address_3 = instance_manager.get_instance_stream("simulation")

        self.assertNotEqual(
            stream_address_1, stream_address_3,
            "The instance was stopped, the stream should have changed.")

        instance_manager.create_pipeline(
            configuration={"camera_name": "simulation"})
        instance_manager.create_pipeline(
            configuration={"camera_name": "simulation"})
        instance_manager.create_pipeline(
            configuration={"camera_name": "simulation"})

        self.assertEqual(len(instance_manager._used_ports), 4,
                         "There should be 4 used ports.")

        instance_manager.stop_all_instances()

        self.assertEqual(len(instance_manager._used_ports), 0,
                         "All ports should be free now.")
Exemple #9
0
    def test_update_stopped_instance(self):
        instance_manager = get_test_pipeline_manager()
        instance_id, _ = instance_manager.create_pipeline(
            configuration={"camera_name": "simulation"})
        instance_manager.update_instance_config(instance_id, {
            "camera_name": "simulation",
            "image_threshold": 9999
        })

        instance_manager.stop_instance(instance_id)

        with self.assertRaisesRegex(
                ValueError, "Instance '%s' does not exist." % instance_id):
            instance_manager.update_instance_config(instance_id, {
                "camera_name": "simulation",
                "image_threshold": 9999
            })

        instance_manager.stop_all_instances()
Exemple #10
0
    def test_update_instance_config_without_running(self):
        pipeline_manager = get_test_pipeline_manager()

        instance_id, _ = pipeline_manager.create_pipeline(
            configuration={"camera_name": "simulation"})

        config_updates = {
            "camera_name": "different_name",
        }

        with self.assertRaisesRegex(
                ValueError,
                "Cannot change the camera name on a running instance. "
                "Stop the instance first."):
            pipeline_manager.update_instance_config(instance_id,
                                                    config_updates)

        config_updates = {
            "camera_name": "simulation",
            "camera_calibration": {
                "reference_marker": [1, 2, 3, 4],
                "reference_marker_width": 5.0,
                "reference_marker_height": 6.0,
                "angle_horizontal": 7.0,
                "angle_vertical": 8.0
            },
            "image_background": None,
            "image_background_enable": False,
            "image_threshold": 2,
            "image_region_of_interest": [3, 4, 5, 6],
            "image_good_region": {
                "threshold": 0.9,
                "gfscale": 3.6
            },
            "image_slices": {
                "number_of_slices": 6,
                "scale": 7,
                "orientation": "vertical"
            },
            "pipeline_type": "processing"
        }

        pipeline_manager.update_instance_config(instance_id, config_updates)

        self.assertDictEqual(
            pipeline_manager.get_instance(instance_id).get_configuration(),
            config_updates, "Update was not successful.")

        self.assertDictEqual(
            pipeline_manager.get_instance(
                instance_id).get_configuration()["camera_calibration"],
            config_updates["camera_calibration"], "Update was not successful.")

        self.assertDictEqual(
            pipeline_manager.get_instance(
                instance_id).get_configuration()["image_good_region"],
            config_updates["image_good_region"], "Update was not successful.")

        self.assertDictEqual(
            pipeline_manager.get_instance(
                instance_id).get_configuration()["image_slices"],
            config_updates["image_slices"], "Update was not successful.")

        pipeline_manager.update_instance_config(
            instance_id, {"image_background_enable": True})
        with self.assertRaisesRegex(
                ValueError,
                "Requested background 'non_existing' does not exist."):
            pipeline_manager.update_instance_config(
                instance_id, {"image_background": "non_existing"})

        pipeline_manager.background_manager.save_background(
            "non_existing", None, append_timestamp=False)
        pipeline_manager.update_instance_config(
            instance_id, {"image_background": "non_existing"})

        self.assertEqual(
            pipeline_manager.get_instance(instance_id).get_configuration()
            ["image_background"], "non_existing", "Background not updated.")

        pipeline_manager.update_instance_config(instance_id,
                                                {"image_background": None})
        self.assertIsNone(
            pipeline_manager.get_instance(instance_id).get_configuration()
            ["image_background"], "Background should be None.")

        pipeline_manager.update_instance_config(instance_id,
                                                {"image_slices": None})
        self.assertIsNone(
            pipeline_manager.get_instance(instance_id).get_configuration()
            ["image_slices"], "Sub dictionary not set to None.")

        pipeline_manager.update_instance_config(
            instance_id, {"image_good_region": {
                "gfscale": None
            }})
        self.assertEqual(
            pipeline_manager.get_instance(instance_id).get_configuration()
            ["image_good_region"]["gfscale"],
            PipelineConfig.DEFAULT_IMAGE_GOOD_REGION["gfscale"],
            "Default value not set correctly.")

        pipeline_manager.update_instance_config(instance_id,
                                                {"pipeline_type": None})
        self.assertEqual(
            pipeline_manager.get_instance(
                instance_id).get_configuration()["pipeline_type"],
            PipelineConfig.DEFAULT_CONFIGURATION["pipeline_type"],
            "Default value not set correctly.")

        pipeline_manager.stop_all_instances()