Esempio n. 1
0
    def _parse_resource_selection(self, component, variable, index, data):
        path = [
            Keys.COMPONENTS, component, Keys.VARIABLES, variable,
            Keys.REALIZATION,
            "#%d" % index
        ]

        destination = None
        resources = []
        for key, item in data.items():
            if key == Keys.SELECT:
                if not isinstance(item, list):
                    self._wrong_type(list, type(item), *(path + [key]))
                    continue
                resources = item

            elif key == Keys.AS:
                if not isinstance(item, str):
                    self._wrong_type(str, type(item), *(path + [key]))
                    continue
                destination = item

            else:
                self._ignore(*(path + [key]))

        if not resources:
            self._missing([Keys.SELECT], *path)

        return ResourceSelection(destination, resources)
Esempio n. 2
0
 def test_given_a_component_with_a_variable_with_resource_selection(self):
     self.assert_complete(
         "components:\n"
         "   server:\n"
         "      provides_services: [ Wonderful ]\n"
         "      variables:\n"
         "        memory:\n"
         "          type: Text\n"
         "          values: [apache, nginx]\n"
         "          realization:\n"
         "             - select: \n"
         "                - apache_config.ini\n"
         "                - nginx_config.ini\n"
         "               as: config.ini\n"
         "goals:\n"
         "   running:\n"
         "      - Wonderful\n",
         expectations={
             "services": ["Wonderful"],
             "features": [],
             "components": {
                 "server": {
                     "provided_services": ["Wonderful"],
                     "required_services": [],
                     "provided_features": [],
                     "required_features": [],
                     "implementation": None,
                     "variables": {
                         "memory": {
                             "values": ["apache", "nginx"],
                             "realization": [
                                 ResourceSelection("config.ini", [
                                     "apache_config.ini", "nginx_config.ini"
                                 ])
                             ]
                         }
                     }
                 }
             },
             "goals": {
                 "services": ["Wonderful"],
                 "features": []
             }
         })
    def test_select_a_specifc_resource(self):
        self.create_template_file(component="server",
                                  resource="apache_config.ini")
        self.create_template_file(component="server",
                                  resource="nginx_config.ini")

        model = Model(
            components=[
                Component(name="server",
                          provided_services=[Service("Awesome")],
                          variables=[
                              Variable(
                                  name="provider",
                                  value_type=str,
                                  values=["apache", "nginx"],
                                  realization=[
                                      ResourceSelection(
                                          "server/config.ini",
                                          [
                                              "server/apache_config.ini",
                                              "server/nginx_config.ini"
                                          ]
                                      )
                                  ])
                          ],
                          implementation=DockerFile("server/Dockerfile"))
            ],
            goals=Goals(services=[Service("Awesome")]))

        server = model.resolve("server")
        configuration = Configuration(
            model,
            instances = [
                Instance(name="server_0",
                         definition=server,
                         configuration=[(server.variables[0], "nginx")])
            ])

        self.realize(configuration)

        self.assert_exists("config_1/images/server_0/config.ini")
        self.assert_does_not_exist("config_1/images/server_0/apache_config.ini")
Esempio n. 4
0
 def test_have_a_different_hash_from_a_selection_with_a_different_destination(
         self):
     other = ResourceSelection("something_different.txt", self._resources)
     self.assertNotEqual(hash(self._selection), hash(other))
Esempio n. 5
0
 def test_have_a_different_hash_from_a_selection_with_different_resource(
         self):
     other = ResourceSelection(self._destination,
                               ["resource_1.txt", "resource_2.txt"])
     self.assertNotEqual(hash(self._selection), hash(other))
Esempio n. 6
0
 def test_have_the_same_hash_than_an_identical_resource(self):
     twin = ResourceSelection(self._destination, self._resources)
     self.assertEqual(hash(self._selection), hash(twin))
Esempio n. 7
0
 def test_equal_another_identical_selection(self):
     twin = ResourceSelection(self._destination, self._resources)
     self.assertEqual(self._selection, twin)
Esempio n. 8
0
 def test_differ_from_a_selection_with_a_different_resources(self):
     other = ResourceSelection(self._destination,
                               ["resource_1.txt", "resource_2.txt"])
     self.assertNotEqual(self._selection, other)
Esempio n. 9
0
 def setUp(self):
     self._destination = "file.txt"
     self._resources = ["whatever.txt", "doesnt_matter.ini"]
     self._selection = ResourceSelection(self._destination, self._resources)