コード例 #1
0
    def test_cli(self, mocked):
        # the test creates .releases file locally
        # this context manager cleans it in the end
        with FakeProjectDirectory():
            runner = CliRunner()
            result = runner.invoke(cli, [])
            assert result.exit_code == \
                shub_exceptions.NotFoundException.exit_code
            deploy_id1 = utils.store_status_url('http://linkA', 2)
            deploy_id2 = utils.store_status_url('http://linkB', 2)
            utils.store_status_url('http://linkC', 2)

            # get latest (deploy 3)
            result = runner.invoke(cli, [])
            assert result.exit_code == 0
            mocked.assert_called_with('http://linkC', timeout=300)

            # get deploy by id
            result = runner.invoke(cli, ["--id", deploy_id2])
            assert result.exit_code == 0
            mocked.assert_called_with('http://linkB', timeout=300)

            # get non-existing deploy
            result = runner.invoke(cli, ["--id", deploy_id1])
            assert result.exit_code == \
                shub_exceptions.NotFoundException.exit_code
コード例 #2
0
ファイル: test_check.py プロジェクト: scrapinghub/shub
    def test_cli(self, mocked):
        # the test creates .releases file locally
        # this context manager cleans it in the end
        with FakeProjectDirectory():
            runner = CliRunner()
            result = runner.invoke(cli, [])
            assert result.exit_code == \
                shub_exceptions.NotFoundException.exit_code
            deploy_id1 = utils.store_status_url('http://linkA', 2)
            deploy_id2 = utils.store_status_url('http://linkB', 2)
            utils.store_status_url('http://linkC', 2)

            # get latest (deploy 3)
            result = runner.invoke(cli, [])
            assert result.exit_code == 0
            mocked.assert_called_with('http://linkC', timeout=300)

            # get deploy by id
            result = runner.invoke(cli, ["--id", deploy_id2])
            assert result.exit_code == 0
            mocked.assert_called_with('http://linkB', timeout=300)

            # get non-existing deploy
            result = runner.invoke(cli, ["--id", deploy_id1])
            assert result.exit_code == \
                shub_exceptions.NotFoundException.exit_code
コード例 #3
0
ファイル: deploy.py プロジェクト: Kryndex/shub
def deploy_cmd(target, version, username, password, email, apikey, insecure,
               async):
    config = load_shub_config()
    target_conf = config.get_target_conf(target)
    endpoint, target_apikey = target_conf.endpoint, target_conf.apikey
    image = config.get_image(target)
    version = version or config.get_version()
    image_name = utils.format_image_name(image, version)
    username, password = utils.get_credentials(username=username,
                                               password=password,
                                               insecure=insecure,
                                               apikey=apikey,
                                               target_apikey=target_apikey)

    apikey = apikey or target_apikey
    params = _prepare_deploy_params(target_conf.project_id, version,
                                    image_name, endpoint, apikey, username,
                                    password, email)

    utils.debug_log('Deploy with params: {}'.format(params))
    req = requests.post(urljoin(endpoint, '/api/releases/deploy.json'),
                        data=params,
                        auth=(apikey, ''),
                        timeout=300,
                        allow_redirects=False)
    try:
        req.raise_for_status()
    except requests.exceptions.HTTPError:
        _handle_deploy_errors(req)

    click.echo("Deploy task results: {}".format(req))
    status_url = req.headers['location']

    status_id = utils.store_status_url(status_url,
                                       limit=STORE_N_LAST_STATUS_URLS)
    click.echo("You can check deploy results later with "
               "'shub image check --id {}'.".format(status_id))

    click.echo("Deploy results:")
    actual_state = _check_status_url(status_url)
    click.echo(" {}".format(actual_state))

    if not async:
        status = actual_state['status']
        while status in SYNC_DEPLOY_WAIT_STATUSES:
            time.sleep(SYNC_DEPLOY_REFRESH_TIMEOUT)
            actual_state = _check_status_url(status_url)
            if actual_state['status'] != status:
                click.echo(" {}".format(actual_state))
                status = actual_state['status']
コード例 #4
0
def deploy_cmd(target, version, username, password, email,
               apikey, insecure, async_):
    config = load_shub_config()
    target_conf = config.get_target_conf(target)
    endpoint, target_apikey = target_conf.endpoint, target_conf.apikey
    image = config.get_image(target)
    version = version or config.get_version()
    image_name = utils.format_image_name(image, version)
    username, password = utils.get_credentials(
        username=username, password=password, insecure=insecure,
        apikey=apikey, target_apikey=target_apikey)

    apikey = apikey or target_apikey
    params = _prepare_deploy_params(
        target_conf.project_id, version, image_name, endpoint, apikey,
        username, password, email)

    click.echo("Deploying {}".format(image_name))
    utils.debug_log('Deploy parameters: {}'.format(params))
    req = requests.post(
        urljoin(endpoint, '/api/releases/deploy.json'),
        data=params,
        auth=(apikey, ''),
        timeout=300,
        allow_redirects=False
    )
    if req.status_code == 400:
        reason = req.json().get('non_field_errors')
        raise ShubException('\n'.join(reason) if reason else req.text)
    req.raise_for_status()
    status_url = req.headers['location']
    status_id = utils.store_status_url(
        status_url, limit=STORE_N_LAST_STATUS_URLS)
    click.echo(
        "You can check deploy results later with "
        "'shub image check --id {}'.".format(status_id))
    if async_:
        return
    if utils.is_verbose():
        deploy_progress_cls = _LoggedDeployProgress
    else:
        deploy_progress_cls = _DeployProgress
    events = _convert_status_requests_to_events(status_url)
    deploy_progress = deploy_progress_cls(events)
    deploy_progress.show()
コード例 #5
0
ファイル: deploy.py プロジェクト: scrapinghub/shub
def deploy_cmd(target, version, username, password, email,
               apikey, insecure, async_):
    config = load_shub_config()
    target_conf = config.get_target_conf(target)
    endpoint, target_apikey = target_conf.endpoint, target_conf.apikey
    image = config.get_image(target)
    version = version or config.get_version()
    image_name = utils.format_image_name(image, version)
    username, password = utils.get_credentials(
        username=username, password=password, insecure=insecure,
        apikey=apikey, target_apikey=target_apikey)

    apikey = apikey or target_apikey
    params = _prepare_deploy_params(
        target_conf.project_id, version, image_name, endpoint, apikey,
        username, password, email)

    click.echo("Deploying {}".format(image_name))
    utils.debug_log('Deploy parameters: {}'.format(params))
    req = requests.post(
        urljoin(endpoint, '/api/releases/deploy.json'),
        data=params,
        auth=(apikey, ''),
        timeout=300,
        allow_redirects=False
    )
    if req.status_code == 400:
        reason = req.json().get('non_field_errors')
        raise ShubException('\n'.join(reason) if reason else req.text)
    req.raise_for_status()
    status_url = req.headers['location']
    status_id = utils.store_status_url(
        status_url, limit=STORE_N_LAST_STATUS_URLS)
    click.echo(
        "You can check deploy results later with "
        "'shub image check --id {}'.".format(status_id))
    if async_:
        return
    if utils.is_verbose():
        deploy_progress_cls = _LoggedDeployProgress
    else:
        deploy_progress_cls = _DeployProgress
    events = _convert_status_requests_to_events(status_url)
    deploy_progress = deploy_progress_cls(events)
    deploy_progress.show()
コード例 #6
0
ファイル: test_utils.py プロジェクト: rowhit/shub
 def test_store_status_url(self):
     assert not os.path.exists(self.status_file)
     # create and add first entry
     store_status_url('http://test0', 2)
     assert os.path.exists(self.status_file)
     with open(self.status_file, 'r') as f:
         assert f.read() == '0: http://test0\n'
     # add another one
     store_status_url('http://test1', 2)
     with open(self.status_file, 'r') as f:
         assert f.read() == '0: http://test0\n1: http://test1\n'
     # replacement
     assert store_status_url('http://test2', 2) == 2
     with open(self.status_file, 'r') as f:
         assert f.read() == '1: http://test1\n2: http://test2\n'
     # existing
     assert store_status_url('http://test1', 2) == 1
     with open(self.status_file, 'r') as f:
         assert f.read() == '1: http://test1\n2: http://test2\n'