Exemplo n.º 1
0
    def command(self, tb_config, arguments):
        try:
            if len(arguments) > 1:
                raise ToolbeltException("Too many arguments")

            port = 80
            if len(arguments) == 1:
                port = int(arguments[0])

            self._pull_latest_image()
            self._run_jekyll(tb_config, port)
        except ValueError:
            raise ToolbeltException("Port must be integer number")
Exemplo n.º 2
0
    def verify_config_version(self, config):
        config_version = "NA"
        if 'version' in config:
            config_version = config['version']

        if config_version != "1.0":
            raise ToolbeltException("module config version " + config_version +
                                    " not supported")
Exemplo n.º 3
0
    def test_that_image_exist_returns_raises_exception(self):
        # Fixture
        name = "theName"
        self.sub_proc_mock.check_output.side_effect = ToolbeltException(
                'Other message')

        # Test
        # Assert
        with self.assertRaises(ToolbeltException):
            self.sut.image_exists(name)
Exemplo n.º 4
0
    def read_config(self, module_root):
        try:
            module_config = self.file_wrapper.json_load(
                module_root + "/" + self.MODULE_CONFIG_FILE)

            self.verify_config_version(module_config)
            return module_config
        except IOError:
            raise ToolbeltException("Could not find module configuration. Are "
                                    "you sure you are located in a module?")
Exemplo n.º 5
0
 def _find_image_for_environment(self, module_config, tb_config):
     environment_requirements = module_config['environmentReq']
     environments = tb_config['environments']
     requirements = set(environment_requirements)
     for image_name, properties in environments.items():
         if len(set(properties) & requirements) == len(requirements):
             return image_name
     raise ToolbeltException("Did not find a matching environment for the "
                             "requirements [" + ", ".join(requirements) +
                             "]")
Exemplo n.º 6
0
    def test_that_image_exist_returns_false_when_image_is_not_found(self):
        # Fixture
        name = "theName"
        self.sub_proc_mock.check_output.side_effect = ToolbeltException(
                'Error: image library/undefined not found')

        # Test
        actual = self.sut.image_exists(name)

        # Assert
        self.assertFalse(actual)
Exemplo n.º 7
0
    def _api_get(self, url):
        try:
            result = []
            current_url = url

            while current_url is not None:
                response = urllib.request.urlopen(current_url)
                body = response.read()
                result.extend(json.loads(str(body, 'utf-8')))
                link = response.getheader("Link")
                current_url = self._get_url_from_link(link)

            return result
        except urllib.error.HTTPError as e:
            raise ToolbeltException(
                "Failed to access github API for url {}. ({})".format(url, e))
Exemplo n.º 8
0
 def command(self, tb_config, arguments):
     if len(arguments) != 0:
         raise ToolbeltException("Not expecting any arguments")
     self._display_version(tb_config)
Exemplo n.º 9
0
 def command(self, tb_config, arguments):
     if len(arguments) != 2:
         raise ToolbeltException("Expecting 2 arguments")
     repo = arguments[0]
     milestone = arguments[1]
     self._display_release_notes(tb_config, repo, milestone)
Exemplo n.º 10
0
 def _find_milestone_id(self, all_milestones, milestone):
     for candidate in all_milestones:
         if candidate["title"] == milestone:
             return candidate["number"]
     raise ToolbeltException("Milestone " + milestone + " not found")