• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python settings.runtime_values函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tower_cli.conf.settings.runtime_values函数的典型用法代码示例。如果您正苦于以下问题:Python runtime_values函数的具体用法?Python runtime_values怎么用?Python runtime_values使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了runtime_values函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: delete_ansible_tower_group_credential

def delete_ansible_tower_group_credential(feature):
    """
    Cleaning on the AT server after passing tests.
    Removal: group, credential, inventory.
    """
    provision_feature_list = [
        'Linux server provision with chef and ansible tower',
        'Windows server provision with chef and ansible tower'
    ]
    if feature.name in provision_feature_list:
        credentials_name = 'Revizor-windows-cred' if CONF.feature.dist.is_windows else 'Revizor-linux-cred'
        with at_settings.runtime_values(**at_config):
            res = at_get_resource('credential')
            pk = getattr(world, 'at_cred_primary_key_%s' % credentials_name)
            result = res.delete(pk=pk)
            assert result['changed'], (
                    'Credentials with name %s are not deleted from the AT server' % credentials_name)
            LOG.error('Credentials: %s  with the id: %s were not removed from the AT server' % (
                credentials_name, pk))
            res = at_get_resource('group')
            at_group_id = getattr(world, 'at_group_id')
            result = res.delete(pk=at_group_id)
            assert result['changed'], ('Group with id: %s is not deleted from the AT server' % at_group_id)
            LOG.error('Group with id: %s is not deleted from the AT server' % at_group_id)
            res = at_get_resource('inventory')
            inventory_id = getattr(world, 'at_inventory_id')
            result = res.delete(pk=inventory_id)
            assert result['changed'], ('Inventory with id: %s is not deleted from the AT server' % inventory_id)
            LOG.error('Inventory with id: %s is not deleted from the AT server' % inventory_id)
开发者ID:Scalr,项目名称:revizor-tests,代码行数:29,代码来源:provision_steps.py


示例2: test_http_contradiction_error

 def test_http_contradiction_error(self):
     """Establish that commands can not be ran with verify_ssl set
     to false and an http connection."""
     with settings.runtime_values(
             host='http://33.33.33.33', verify_ssl=True):
         with self.assertRaises(exc.TowerCLIError):
             client.get_prefix()
开发者ID:ansible,项目名称:tower-cli,代码行数:7,代码来源:test_api.py


示例3: check_hostname_exists_on_at_server

def check_hostname_exists_on_at_server(step, serv_as, negation):
    # NOTE: Migrated
    """
    You can search server name by: Public IP or Private IP or Hostname.
    Check what value is in defaults!
    If value is Hostname, then hostname = world.get_hostname_by_server_format(server)
    """
    server = getattr(world, serv_as)
    hostname = server.public_ip
    with at_settings.runtime_values(**at_config):
        res = at_get_resource('host')
        hosts_list = res.list(group=None, host_filter=None)
        for m in hosts_list['results']:
            if negation:
                if hostname not in m['name']:
                    break
                raise AssertionError(
                    'Hostname: %s was not removed from Ansible Tower server.' % hostname)
            elif hostname in m['name']:
                break
        else:
            if len(hosts_list['results']) == 10:
                raise AssertionError(
                    'License count of 10 instances has been reached. Number of hosts: %s .' % (
                        len(hosts_list['results'])))
            raise AssertionError(
                'Hostname: %s not found in Ansible Tower server.' % hostname)
开发者ID:Scalr,项目名称:revizor-tests,代码行数:27,代码来源:provision_steps.py


示例4: test_basic_launch_with_echo

    def test_basic_launch_with_echo(self):
        """Establish that we are able to run an ad hoc command and also
        print that to the command line without errors.
        """
        with client.test_mode as t:
            t.register_json('/ad_hoc_commands/42/', {'id': 42}, method='GET')
            t.register_json('/', {
                'ad_hoc_commands': '/api/v1/ad_hoc_commands/'
                }, method='GET')
            t.register_json(
                '/ad_hoc_commands/',
                {'changed': True, 'id': 42,
                    'inventory': 'foobar', 'credential': 2,
                    'name': 'ping', 'created': 1234, 'elapsed': 2352,
                    'status': 'successful', 'module_name': 'command',
                    'limit': '', }, method='POST'
            )
            result = self.res.launch(inventory="foobar", machine_credential=2)
            self.assertEqual(result['changed'], True)
            self.assertEqual(result['id'], 42)

            f = self.res.as_command()._echo_method(self.res.launch)
            with mock.patch.object(click, 'secho'):
                with settings.runtime_values(format='human'):
                    f(inventory="foobar", machine_credential=2)
开发者ID:cchurch,项目名称:tower-cli,代码行数:25,代码来源:test_resources_ad_hoc.py


示例5: launch_ansible_tower_job

def launch_ansible_tower_job(step, job_name, credentials_name, job_result, serv_as):
    # NOTE: Migrated
    inventory_id = getattr(world, 'at_inventory_id')

    pk = getattr(world, 'at_cred_primary_key_%s' % credentials_name)
    at_python_path = ''
    if not CONF.feature.dist.is_windows:
        at_python_path = getattr(world, 'at_python_path')
    with at_settings.runtime_values(**at_config):
        res = at_get_resource('job')
        job_settings = {
            "credential_id": pk,
            "extra_credentials": [],
            "extra_vars": [at_python_path],
            "inventory": inventory_id
        }
        my_job = res.launch(job_template=job_name,
                            monitor=False,
                            wait=True,
                            timeout=None,
                            no_input=True,
                            **job_settings)
        for _ in range(10):
            job_info = res.get(pk=my_job['id'])
            if job_info['status'] not in ['waiting', 'running', 'pending']:
                break
            time.sleep(5)
        else:
            raise AssertionError('Job #%s has not finished in 50s' % my_job['id'])
        assert job_info['status'] == job_result, (my_job['id'], job_info['status'])
开发者ID:Scalr,项目名称:revizor-tests,代码行数:30,代码来源:provision_steps.py


示例6: set_at_job_template_id

def set_at_job_template_id(context: dict, job_template_name: str):
    with at_settings.runtime_values(**AT_CONFIG):
        res = at_get_resource('job_template')
        job_template_info = res.get(name=job_template_name)
        assert job_template_name in job_template_info['name'], \
            f'Job template {job_template_name}: not found in Ansible Tower.\nResponse from server: {job_template_info}.'
        context['job_template_id'] = job_template_info['id']
开发者ID:Scalr,项目名称:revizor-tests,代码行数:7,代码来源:provision.py


示例7: main

def main():
    argument_spec = tower_argument_spec()
    argument_spec.update(dict(
        job_id=dict(type='int', required=True),
        fail_if_not_running=dict(type='bool', default=False),
    ))

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
    )

    if not HAS_TOWER_CLI:
        module.fail_json(msg='ansible-tower-cli required for this module')

    job_id = module.params.get('job_id')
    json_output = {}

    tower_auth = tower_auth_config(module)
    with settings.runtime_values(**tower_auth):
        tower_check_mode(module)
        job = tower_cli.get_resource('job')
        params = module.params.copy()

        try:
            result = job.cancel(job_id, **params)
            json_output['id'] = job_id
        except (exc.ConnectionError, exc.BadRequest, exc.TowerCLIError) as excinfo:
            module.fail_json(msg='Unable to cancel job_id/{0}: {1}'.format(job_id, excinfo), changed=False)

    json_output['changed'] = result['changed']
    json_output['status'] = result['status']
    module.exit_json(**json_output)
开发者ID:awiddersheim,项目名称:ansible,代码行数:33,代码来源:tower_job_cancel.py


示例8: launch_ansible_tower_job

def launch_ansible_tower_job(context: dict, job_name: str, job_result: str):
    inventory_id = context['at_inventory_id']
    credentials_name = context['credentials_name']
    pk = context[f'at_cred_primary_key_{credentials_name}']
    at_python_path = ''
    if not CONF.feature.dist.is_windows:
        at_python_path = context['at_python_path']
    with at_settings.runtime_values(**AT_CONFIG):
        res = at_get_resource('job')
        job_settings = {
            "credential_id": pk,
            "extra_credentials": [],
            "extra_vars": [at_python_path],
            "inventory": inventory_id
        }
        my_job = res.launch(job_template=job_name,
                            monitor=False,
                            wait=True,
                            timeout=None,
                            no_input=True,
                            **job_settings)
        for _ in range(10):
            job_info = res.get(pk=my_job['id'])
            if job_info['status'] not in ['waiting', 'running', 'pending']:
                break
            time.sleep(5)
        else:
            raise AssertionError(f"Job #{my_job['id']} has not finished in 50s")
        assert job_info['status'] == job_result, (my_job['id'], job_info['status'])
开发者ID:Scalr,项目名称:revizor-tests,代码行数:29,代码来源:provision.py


示例9: assert_at_group_exists_in_inventory

def assert_at_group_exists_in_inventory(group_id: str):
    with at_settings.runtime_values(**AT_CONFIG):
        res = at_get_resource('group')
        pk = group_id
        find_group = res.get(pk=pk)
        assert find_group['id'] == pk, \
            f'Group with id: {pk} not found in Ansible Tower. Response from server: {find_group}.'
开发者ID:Scalr,项目名称:revizor-tests,代码行数:7,代码来源:provision.py


示例10: main

def main():
    argument_spec = tower_argument_spec()
    argument_spec.update(dict(
        name=dict(required=True),
        description=dict(),
        state=dict(choices=['present', 'absent'], default='present'),
    ))

    module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

    if not HAS_TOWER_CLI:
        module.fail_json(msg='ansible-tower-cli required for this module')

    name = module.params.get('name')
    description = module.params.get('description')
    state = module.params.get('state')

    json_output = {'organization': name, 'state': state}

    tower_auth = tower_auth_config(module)
    with settings.runtime_values(**tower_auth):
        tower_check_mode(module)
        organization = tower_cli.get_resource('organization')
        try:
            if state == 'present':
                result = organization.modify(name=name, description=description, create_on_missing=True)
                json_output['id'] = result['id']
            elif state == 'absent':
                result = organization.delete(name=name)
        except (exc.ConnectionError, exc.BadRequest) as excinfo:
            module.fail_json(msg='Failed to update the organization: {0}'.format(excinfo), changed=False)

    json_output['changed'] = result['changed']
    module.exit_json(**json_output)
开发者ID:awiddersheim,项目名称:ansible,代码行数:34,代码来源:tower_organization.py


示例11: test_oauth_bearer_token

 def test_oauth_bearer_token(self):
     token = 'Azly3WBiYWeGKfImK25ftpJR1nvn6JABC123'
     with settings.runtime_values(oauth_token=token):
         auth = BasicTowerAuth(None, None, client)
         auth(self.req)
         assert self.req.headers == {
             'Authorization': 'Bearer {}'.format(token)
         }
开发者ID:ansible,项目名称:tower-cli,代码行数:8,代码来源:test_api.py


示例12: test_not_verbose_mode

 def test_not_verbose_mode(self):
     """Establish that this method does nothing if we are not in
     verbose mode.
     """
     with settings.runtime_values(verbose=False):
         with mock.patch.object(click, 'secho') as secho:
             debug.log('foo bar baz')
             self.assertEqual(secho.call_count, 0)
开发者ID:Robinjtu,项目名称:tower-cli,代码行数:8,代码来源:test_utils_debug.py


示例13: test_echo_id

 def test_echo_id(self):
     for input_format in [{'id': 5}, {'count': 1, 'results': [{'id': 5}]}]:
         func = self.command._echo_method(lambda: input_format)
         with mock.patch.object(click, 'secho') as secho:
             with settings.runtime_values(format='id'):
                 func()
             output = secho.mock_calls[-1][1][0]
         self.assertEqual('5', output)
开发者ID:ansible,项目名称:tower-cli,代码行数:8,代码来源:test_cli_resource.py


示例14: test_color_false

 def test_color_false(self):
     """Establish that when the color setting is false, that color
     data is stripped.
     """
     with settings.runtime_values(color=False):
         with mock.patch.object(click, 'secho') as click_secho:
             secho('foo bar baz', fg='green')
             click_secho.assert_called_once_with('foo bar baz')
开发者ID:ansible,项目名称:tower-cli,代码行数:8,代码来源:test_utils.py


示例15: main

def main():
    argument_spec = tower_argument_spec()
    argument_spec.update(dict(
        name=dict(required=True),
        description=dict(),
        job_type=dict(choices=['run', 'check', 'scan'], required=True),
        inventory=dict(),
        project=dict(required=True),
        playbook=dict(required=True),
        machine_credential=dict(),
        cloud_credential=dict(),
        network_credential=dict(),
        forks=dict(type='int'),
        limit=dict(),
        verbosity=dict(choices=['verbose', 'debug']),
        job_tags=dict(),
        skip_tags=dict(),
        host_config_key=dict(),
        extra_vars_path=dict(type='path', required=False),
        ask_extra_vars=dict(type='bool', default=False),
        ask_limit=dict(type='bool', default=False),
        ask_tags=dict(type='bool', default=False),
        ask_job_type=dict(type='bool', default=False),
        ask_inventory=dict(type='bool', default=False),
        ask_credential=dict(type='bool', default=False),
        become_enabled=dict(type='bool', default=False),
        state=dict(choices=['present', 'absent'], default='present'),
    ))

    module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

    if not HAS_TOWER_CLI:
        module.fail_json(msg='ansible-tower-cli required for this module')

    name = module.params.get('name')
    state = module.params.get('state')
    json_output = {'job_template': name, 'state': state}

    tower_auth = tower_auth_config(module)
    with settings.runtime_values(**tower_auth):
        tower_check_mode(module)
        jt = tower_cli.get_resource('job_template')

        params = update_resources(module, module.params)
        params = update_fields(params)
        params['create_on_missing'] = True

        try:
            if state == 'present':
                result = jt.modify(**params)
                json_output['id'] = result['id']
            elif state == 'absent':
                result = jt.delete(**params)
        except (exc.ConnectionError, exc.BadRequest, exc.NotFound) as excinfo:
            module.fail_json(msg='Failed to update job template: {0}'.format(excinfo), changed=False)

    json_output['changed'] = result['changed']
    module.exit_json(**json_output)
开发者ID:awiddersheim,项目名称:ansible,代码行数:58,代码来源:tower_job_template.py


示例16: test_key_and_no_value

 def test_key_and_no_value(self):
     """Establish that if we are given a key and no value, that the
     setting's value is printed.
     """
     with settings.runtime_values(password='This is the best wine.'):
         result = self.runner.invoke(config, ['password'])
     self.assertEqual(result.exit_code, 0)
     self.assertEqual(result.output.strip(),
                      'password: This is the best wine.')
开发者ID:ansible,项目名称:tower-cli,代码行数:9,代码来源:test_cli_misc.py


示例17: test_connection_error

 def test_connection_error(self):
     """Establish that if we get a ConnectionError back from requests,
     that we deal with it nicely.
     """
     with settings.runtime_values(verbose=False):
         with mock.patch.object(Session, 'request') as req:
             req.side_effect = requests.exceptions.ConnectionError
             with self.assertRaises(exc.ConnectionError):
                 r = client.get('/ping/')
开发者ID:Robinjtu,项目名称:tower-cli,代码行数:9,代码来源:test_api.py


示例18: main

def main():
    module = AnsibleModule(
        argument_spec=dict(
            name=dict(required=True),
            description=dict(),
            inventory=dict(required=True),
            enabled=dict(type='bool', default=True),
            variables=dict(),
            tower_host=dict(),
            tower_username=dict(),
            tower_password=dict(no_log=True),
            tower_verify_ssl=dict(type='bool', default=True),
            tower_config_file=dict(type='path'),
            state=dict(choices=['present', 'absent'], default='present'),
        ),
        supports_check_mode=True
    )

    if not HAS_TOWER_CLI:
        module.fail_json(msg='ansible-tower-cli required for this module')

    name = module.params.get('name')
    description = module.params.get('description')
    inventory = module.params.get('inventory')
    enabled = module.params.get('enabled')
    state = module.params.get('state')

    variables = module.params.get('variables')
    if variables:
        if variables.startswith('@'):
            filename = os.path.expanduser(variables[1:])
            variables = module.contents_from_file(filename)

    json_output = {'host': name, 'state': state}

    tower_auth = tower_auth_config(module)
    with settings.runtime_values(**tower_auth):
        tower_check_mode(module)
        host = tower_cli.get_resource('host')

        try:
            inv_res = tower_cli.get_resource('inventory')
            inv = inv_res.get(name=inventory)

            if state == 'present':
                result = host.modify(name=name, inventory=inv['id'], enabled=enabled,
                                     variables=variables, description=description, create_on_missing=True)
                json_output['id'] = result['id']
            elif state == 'absent':
                result = host.delete(name=name, inventory=inv['id'])
        except (exc.NotFound) as excinfo:
            module.fail_json(msg='Failed to update host, inventory not found: {0}'.format(excinfo), changed=False)
        except (exc.ConnectionError, exc.BadRequest) as excinfo:
            module.fail_json(msg='Failed to update host: {0}'.format(excinfo), changed=False)

    json_output['changed'] = result['changed']
    module.exit_json(**json_output)
开发者ID:ernstp,项目名称:ansible,代码行数:57,代码来源:tower_host.py


示例19: test_echo_method

 def test_echo_method(self):
     """Establish that the _echo_method subcommand class works in the
     way we expect.
     """
     func = self.command._echo_method(lambda: {'foo': 'bar'})
     with mock.patch.object(click, 'secho') as secho:
         with settings.runtime_values(format='json'):
             func()
         secho.assert_called_once_with(json.dumps({'foo': 'bar'}, indent=2))
开发者ID:ghjm,项目名称:tower-cli,代码行数:9,代码来源:test_models_base.py


示例20: test_failed_suggestion_protocol

 def test_failed_suggestion_protocol(self):
     """Establish that if connection fails and protocol not given,
     tower-cli suggests that to the user."""
     with settings.runtime_values(verbose=False, host='foo.co'):
         with mock.patch.object(Session, 'request') as req:
             req.side_effect = requests.exceptions.SSLError
             with mock.patch.object(click, 'secho') as secho:
                 with self.assertRaises(exc.ConnectionError):
                     client.get('/ping/')
                 self.assertTrue(secho.called)
开发者ID:ansible,项目名称:tower-cli,代码行数:10,代码来源:test_api.py



注:本文中的tower_cli.conf.settings.runtime_values函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python debug.log函数代码示例发布时间:2022-05-27
下一篇:
Python client.post函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap