예제 #1
0
def get_node(nodes_so_far: List[NodeConfig]) -> Optional[NodeConfig]:
    # Get node's name
    node_names_so_far = [n.node_name for n in nodes_so_far]
    while True:
        node_name = input('Unique node name:\n')
        if node_name in node_names_so_far:
            print('Node name must be unique.')
        else:
            break

    # Get node's RPC url
    while True:
        rpc_url = input('Node\'s RPC url (typically http://NODE_IP:26657):\n')
        print('Trying to connect to endpoint {}/health'.format(rpc_url))
        try:
            get_json(rpc_url + '/health', DUMMY_LOGGER)
            print('Success.')
            break
        except Exception:
            if not yn_prompt('Failed to connect to endpoint. Do '
                             'you want to try again? (Y/n)\n'):
                return None

    # Ask if node is a validator
    node_is_validator = yn_prompt('Is this node a validator? (Y/n)\n')

    # Return node
    return NodeConfig(node_name, rpc_url, node_is_validator, True, True)
예제 #2
0
def get_repo() -> Optional[RepoConfig]:
    # Get repo name
    repo_name = input('GitHub repository name (to know which repository '
                      'triggered an alert, example: Cosmos SDK):\n')

    # Get repo page
    while True:
        repo_page = input('Official GitHub repository (example: '
                          'cosmos/cosmos-sdk/):\n')
        if not repo_page.endswith('/'):
            repo_page = repo_page + '/'

        releases_page = InternalConf.github_releases_template.format(repo_page)
        print('Trying to connect to {}'.format(releases_page))
        try:
            releases = get_json(releases_page, DUMMY_LOGGER)
            if 'message' in releases and releases['message'] == 'Not Found':
                if not yn_prompt('Connection successful, but URL is not valid.'
                                 'Do you want to try again? (Y/n)\n'):
                    return None
            else:
                break  # success message left to setup_repos function
        except Exception:
            if not yn_prompt('Failed to connect to page. Do '
                             'you want to try again? (Y/n)\n'):
                return None

    # Return node
    return RepoConfig(repo_name, repo_page, True)
예제 #3
0
def test_connection_to_github_page(repo: RepoConfig):
    # Get releases page
    releases_page = InternalConf.github_releases_template.format(
        repo.repo_page)

    # Test connection
    log_and_print('Trying to connect to {}'.format(releases_page))
    try:
        releases = get_json(releases_page, logger_general)
        if 'message' in releases and releases['message'] == 'Not Found':
            raise InitialisationException(
                'Successfully reached {} but URL '
                'is not valid.'.format(releases_page))
        else:
            log_and_print('Success.')
    except Exception:
        raise InitialisationException('Could not reach {}.'
                                      ''.format(releases_page))
예제 #4
0
파일: github.py 프로젝트: yn-alex/panic
    def monitor(self) -> None:
        # Get list of releases
        releases = get_json(self.releases_page, self._logger)

        # If response contains a message, skip monitoring this time round
        if 'message' in releases:
            self.logger.warning('GitHub message: %s', releases['message'])
            return

        # Check that number of releases has not changed
        no_of_releases = len(releases)
        if self._prev_no_of_releases not in [None, no_of_releases]:
            if self._prev_no_of_releases < no_of_releases:
                self.channels.alert_info(
                    NewGitHubReleaseAlert(releases[0]['name'], self.repo_name))
            else:
                # Something went wrong; reset number of releases
                self.logger.error('The number of releases decreased from {} '
                                  'to {}: {}'.format(self._prev_no_of_releases,
                                                     no_of_releases, releases))
                self._prev_no_of_releases = None

        self._prev_no_of_releases = no_of_releases
예제 #5
0
 def test_get_json_with_no_params_works_just_the_same(self, _):
     self.assertEqual(TestGetJson.DummyGetReturn.CONTENT_DICT,
                      get_json(ENDPOINT, LOGGER))
예제 #6
0
 def test_get_json_accesses_content_and_parses_bytes_to_dict(self, _):
     self.assertEqual(TestGetJson.DummyGetReturn.CONTENT_DICT,
                      get_json(ENDPOINT, LOGGER))