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")
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")
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)
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?")
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) + "]")
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)
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))
def command(self, tb_config, arguments): if len(arguments) != 0: raise ToolbeltException("Not expecting any arguments") self._display_version(tb_config)
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)
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")