python settings模块_Python settings.VERSION属性代码示例

# 需要导入模块: import settings [as 别名]

# 或者: from settings import VERSION [as 别名]

def test_version(self):

host_info = self.mock_servers['mynewhost']

with timed('csr', 10):

data = {

'fqdn': host_info['fqdn'],

'nodename': host_info['nodename'],

'version': '1.0',

'capabilities': ['manage_targets'],

'address': 'mynewhost',

'csr': generate_csr(host_info['fqdn']),

}

with patch(settings, VERSION='2.0'):

# Try with a mis-matched version

token = RegistrationToken.objects.create(profile=ServerProfile.objects.get())

with timed('register fail', 10):

response = Client().post("/agent/register/%s/" % token.secret, data=json.dumps(data), content_type="application/json")

self.assertEqual(response.status_code, 400)

# Try with a matching version

token = RegistrationToken.objects.create(profile=ServerProfile.objects.get())

settings.VERSION = '1.1'

with timed('register pass', 10):

response = Client().post("/agent/register/%s/" % token.secret, data=json.dumps(data), content_type="application/json")

self.assertEqual(response.status_code, 201)

content = json.loads(response.content)

# reregistration should fail with unknown serial

data = {'address': 'mynewhost', 'fqdn': 'mynewhost.newcompany.com'}

headers = {'HTTP_X_SSL_CLIENT_NAME': host_info['fqdn'], 'HTTP_X_SSL_CLIENT_SERIAL': ''}

response = Client().post('/agent/reregister/', data=json.dumps(data), content_type='application/json', **headers)

self.assertEqual(response.status_code, 403)

# reregistration should update host's domain name

headers['HTTP_X_SSL_CLIENT_SERIAL'] = Crypto().get_serial(content['certificate'])

response = Client().post('/agent/reregister/', data=json.dumps(data), content_type='application/json', **headers)

self.assertEqual(response.status_code, 200)

host = ManagedHost.objects.get(id=content['host_id'])

self.assertEqual(host.fqdn, data['fqdn'])

# TOOD: reinstate selinux check, probably within the agent itself (it should fail

# its own registration step without even talking to the manager)

# def test_selinux_detection(self):

# """Test that a host with SELinux enabled fails setup."""

# MockAgentRpc.selinux_enabled = True

# try:

# import time

# host = self._create_host('myaddress')

# self.assertTrue(Command.objects.all().order_by("-id")[0].errored)

# self.assertState(host, 'unconfigured')

# finally:

# MockAgentRpc.selinux_enabled = False

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值