Esempio n. 1
0
    def test_when_a_component_is_implemented_by_a_docker_file(self):
        model = Model(
            [
                Component("server",
                          provided_services=[Service("Awesome")],
                          required_features=[Feature("JDK")],
                          implementation=DockerFile("server/Dockerfile")),
                Component("jdk",
                          provided_features=[Feature("JDK")],
                          implementation=DockerFile("jdk/Dockerfile"))

            ],
            Goals(services=[Service("Awesome")])
        )

        server_0 = Instance("server_0", model.resolve("server"))
        jdk_0 = Instance("jdk_0", model.resolve("jdk"))

        server_0.feature_provider = jdk_0
        configuration = Configuration(model, [server_0, jdk_0])

        self.build(configuration)

        self.assert_generated(
            "config_0/images/build_images.sh",
             with_patterns=[
                 "docker build -t camp-server_0 ./server",
                 "docker build -t camp-jdk_0 ./jdk_0"
                 ])
Esempio n. 2
0
    def test_when_a_component_host_is_implemented_by_a_docker_image(self):
        model = Model(
            [
                Component("server",
                          provided_services=[Service("Awesome")],
                          required_features=[Feature("JDK")],
                          implementation=DockerFile("server/Dockerfile")),
                Component("jdk",
                          provided_features=[Feature("JDK")],
                          implementation=DockerImage("fchauvel/test:1.0.1")),
            ],
            Goals(services=[Service("Awesome")])
        )

        server_0 = Instance("server_0", model.resolve("server"))
        jdk_0 = Instance("jdk_0", model.resolve("jdk"))
        server_0.feature_provider = jdk_0

        configuration = Configuration( model, [ server_0,
                                                jdk_0 ])
        self.build(configuration)

        self.assert_generated(
            "config_0/images/server_0/Dockerfile",
            with_patterns=[
                "FROM fchauvel/test:1.0.1"
            ])
    def test_when_no_one_provides_a_required_feature(self):
        self._components.append(
            Component(name="c2", required_features=[Feature("Awesome")]))

        self._validate_model()

        self._verify_errors(NoFeatureProvider)
 def setUp(self):
     self._components = [
         Component(name="c1",
                   provided_services=[Service("S1")],
                   provided_features=[Feature("F1")])
     ]
     self._goals = Goals(services=[Service("S1")])
     self._errors = []
    def test_when_a_variable_has_no_value(self):
        self._components = [
            Component(name="c1",
                      provided_services=[Service("S1")],
                      provided_features=[Feature("F1")],
                      variables=[Variable("memory", str, [])])
        ]

        self._validate_model()

        self._verify_errors(EmptyVariableDomain)
    def setUp(self):
        super().setUp()
        self.model = Model([
            Component("server",
                      provided_services=[Service("Awesome")],
                      required_features=[Feature("ServletContainer")],
                      implementation=DockerFile("server/Dockerfile")),
            Component("tomcat",
                      provided_features=[Feature("ServletContainer")],
                      required_features=[Feature("JDK")],
                      implementation=DockerFile("tomcat/Dockerfile")),
            Component("jdk",
                      provided_features=[Feature("JDK")],
                      implementation=DockerFile("jdk/Dockerfile"))
        ], Goals(services=[Service("Awesome")]))

        self.server_0 = Instance("server_0", self.model.resolve("server"))
        self.tomcat_0 = Instance("tomcat_0", self.model.resolve("tomcat"))
        self.jdk_0 = Instance("jdk_0", self.model.resolve("jdk"))

        self.server_0.feature_provider = self.tomcat_0
        self.tomcat_0.feature_provider = self.jdk_0
Esempio n. 7
0
 def setUp(self):
     start_over()
     self._context = Context()
     components = [
         Component(
             "c1",
             provided_services=[Service("S1")],
             provided_features=[Feature("F1")],
             variables=[Variable("memory", str, values=["1GB", "2GB"])])
     ]
     self._model = Model(components, Goals(services=[Service("S1")]))
     self._context.load_metamodel()
     self._context.load_model(self._model)
Esempio n. 8
0
    def _parse_component(self, name, data):
        provided_services = []
        required_services = []
        provided_features = []
        required_features = []
        variables = []
        implementation = None
        test_settings = None

        for key, item in data.items():

            if key == Keys.PROVIDES_SERVICES:
                if not isinstance(item, list):
                    self._wrong_type(list, type(item), Keys.COMPONENTS, name,
                                     key)
                    continue
                for each_name in item:
                    provided_services.append(Service(self._escape(each_name)))

            elif key == Keys.REQUIRES_SERVICES:
                if not isinstance(item, list):
                    self._wrong_type(list, type(item), Keys.COMPONENTS, name,
                                     key)
                    continue
                for each_name in item:
                    required_services.append(Service(self._escape(each_name)))

            elif key == Keys.PROVIDES_FEATURES:
                if not isinstance(item, list):
                    self._wrong_type(list, type(item), Keys.COMPONENTS, name,
                                     key)
                    continue
                for each_name in item:
                    provided_features.append(Feature(self._escape(each_name)))

            elif key == Keys.REQUIRES_FEATURES:
                if not isinstance(item, list):
                    self._wrong_type(list, type(item), Keys.COMPONENTS, name,
                                     key)
                    continue
                for each_name in item:
                    required_features.append(Feature(self._escape(each_name)))

            elif key == Keys.VARIABLES:
                if not isinstance(item, dict):
                    self._wrong_type(dict, type(item), Keys.COMPONENTS, name,
                                     key)
                    continue
                variables = self._parse_variables(name, item)

            elif key == Keys.IMPLEMENTATION:
                if not isinstance(item, dict):
                    self._wrong_type(dict, type(item), Keys.COMPONENTS, name,
                                     key)
                    continue
                implementation = self._parse_implementation(name, item)

            elif key == Keys.TEST_SETTINGS:
                if not isinstance(item, dict):
                    self._wrong_type(dict, type(item), Keys.COMPONENTS, name,
                                     key)
                    continue
                test_settings = self._parse_test_settings(name, item)

            else:
                self._ignore(Keys.COMPONENTS, name, key)

        return Component(name,
                         provided_services=provided_services,
                         required_services=required_services,
                         provided_features=provided_features,
                         required_features=required_features,
                         variables=variables,
                         implementation=implementation,
                         test_settings=test_settings)