本文整理汇总了Python中nailgun.db.sqlalchemy.models.Task.cache方法的典型用法代码示例。如果您正苦于以下问题:Python Task.cache方法的具体用法?Python Task.cache怎么用?Python Task.cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nailgun.db.sqlalchemy.models.Task
的用法示例。
在下文中一共展示了Task.cache方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_verify_networks_resp_incomplete_network_data_on_first_node
# 需要导入模块: from nailgun.db.sqlalchemy.models import Task [as 别名]
# 或者: from nailgun.db.sqlalchemy.models.Task import cache [as 别名]
def test_verify_networks_resp_incomplete_network_data_on_first_node(self):
"""First node network data incompletion causes task fail"""
self.env.create(
cluster_kwargs={}, nodes_kwargs=[{"api": False, "name": "node1"}, {"api": False, "name": "node2"}]
)
cluster_db = self.env.clusters[0]
node1, node2 = self.env.nodes
nets_sent = [{"iface": "eth0", "vlans": range(100, 105)}]
task = Task(name="super", cluster_id=cluster_db.id)
task.cache = {"args": {"nodes": self.nodes_message((node1, node2), nets_sent), "offline": 0}}
self.db.add(task)
self.db.commit()
kwargs = {"task_uuid": task.uuid, "status": "ready", "nodes": self.nodes_message((node1, node2), [])}
kwargs["nodes"][1]["networks"] = nets_sent
self.receiver.verify_networks_resp(**kwargs)
self.db.flush()
self.db.refresh(task)
self.assertEqual(task.status, "error")
self.assertEqual(task.message, "")
error_nodes = [
{
"uid": node1.id,
"interface": "eth0",
"name": node1.name,
"mac": node1.interfaces[0].mac,
"absent_vlans": sorted(nets_sent[0]["vlans"]),
}
]
task.result[0]["absent_vlans"] = sorted(task.result[0]["absent_vlans"])
self.assertEqual(task.result, error_nodes)
示例2: test_verify_networks_resp_forgotten_node_error
# 需要导入模块: from nailgun.db.sqlalchemy.models import Task [as 别名]
# 或者: from nailgun.db.sqlalchemy.models.Task import cache [as 别名]
def test_verify_networks_resp_forgotten_node_error(self):
self.env.create(
cluster_kwargs={},
nodes_kwargs=[
{"api": False, "name": "node1"},
{"api": False, "name": "node2"},
{"api": False, "name": "node3"},
],
)
cluster_db = self.env.clusters[0]
node1, node2, node3 = self.env.nodes
nets_sent = [{"iface": "eth0", "vlans": range(100, 105)}]
task = Task(name="super", cluster_id=cluster_db.id)
task.cache = {"args": {"nodes": self.nodes_message((node1, node2, node3), nets_sent), "offline": 0}}
self.db.add(task)
self.db.commit()
kwargs = {"task_uuid": task.uuid, "status": "ready", "nodes": self.nodes_message((node1, node2), nets_sent)}
self.receiver.verify_networks_resp(**kwargs)
self.db.flush()
self.db.refresh(task)
self.assertEqual(task.status, "error")
self.assertRegexpMatches(task.message, node3.name)
self.assertEqual(task.result, {})
示例3: test_verify_networks_with_dhcp_subtask_erred
# 需要导入模块: from nailgun.db.sqlalchemy.models import Task [as 别名]
# 或者: from nailgun.db.sqlalchemy.models.Task import cache [as 别名]
def test_verify_networks_with_dhcp_subtask_erred(self):
self.env.create(cluster_kwargs={}, nodes_kwargs=[{"api": False}, {"api": False}])
cluster_db = self.env.clusters[0]
node1, node2 = self.env.nodes
nets_sent = [{"iface": "eth0", "vlans": range(100, 105)}]
task = Task(name="verify_networks", cluster_id=cluster_db.id)
task.cache = {"args": {"nodes": self.nodes_message((node1, node2), nets_sent), "offline": 0}}
self.db.add(task)
self.db.commit()
dhcp_subtask = Task(
name="check_dhcp", cluster_id=cluster_db.id, parent_id=task.id, status="error", message="DHCP ERROR"
)
self.db.add(dhcp_subtask)
self.db.commit()
kwargs = {"task_uuid": task.uuid, "status": "ready", "nodes": self.nodes_message((node1, node2), [])}
kwargs["nodes"][0]["networks"] = nets_sent
self.receiver.verify_networks_resp(**kwargs)
self.assertEqual(task.status, "error")
self.assertEqual(task.message, u"DHCP ERROR")
task.result[0]["absent_vlans"] = sorted(task.result[0]["absent_vlans"])
self.assertEqual(
task.result,
[
{
u"absent_vlans": [100, 101, 102, 103, 104],
u"interface": "eth0",
u"mac": node2.interfaces[0].mac,
u"name": "Untitled ({0})".format(node2.mac[-5:].lower()),
u"uid": node2.id,
}
],
)
示例4: test_verify_networks_resp_error_with_removed_node
# 需要导入模块: from nailgun.db.sqlalchemy.models import Task [as 别名]
# 或者: from nailgun.db.sqlalchemy.models.Task import cache [as 别名]
def test_verify_networks_resp_error_with_removed_node(self):
self.env.create(cluster_kwargs={}, nodes_kwargs=[{"api": False}, {"api": False}])
cluster_db = self.env.clusters[0]
node1, node2 = self.env.nodes
nets_sent = [{"iface": "eth0", "vlans": range(100, 105)}]
nets_resp = [{"iface": "eth0", "vlans": range(100, 104)}]
task = Task(name="super", cluster_id=cluster_db.id)
task.cache = {"args": {"nodes": self.nodes_message((node1, node2), nets_sent), "offline": 0}}
self.db.add(task)
self.db.commit()
kwargs = {"task_uuid": task.uuid, "status": "ready", "nodes": self.nodes_message((node1, node2), nets_resp)}
self.db.delete(node2)
self.db.commit()
self.receiver.verify_networks_resp(**kwargs)
self.db.flush()
resp = self.app.get(reverse("TaskHandler", kwargs={"obj_id": task.id}), headers=self.default_headers)
self.assertEqual(resp.status_code, 200)
task = resp.json_body
self.assertEqual(task["status"], "error")
error_nodes = [
{
"uid": node1.id,
"interface": "eth0",
"name": node1.name,
"absent_vlans": [104],
"mac": node1.interfaces[0].mac,
},
{"uid": node2.id, "interface": "eth0", "name": node2.name, "absent_vlans": [104], "mac": "unknown"},
]
self.assertEqual(task.get("message"), "")
self.assertEqual(task["result"], error_nodes)
示例5: test_verify_networks_resp_without_vlans_only_erred
# 需要导入模块: from nailgun.db.sqlalchemy.models import Task [as 别名]
# 或者: from nailgun.db.sqlalchemy.models.Task import cache [as 别名]
def test_verify_networks_resp_without_vlans_only_erred(self):
"""Net verification without vlans fails when not all info received"""
self.env.create(cluster_kwargs={}, nodes_kwargs=[{"api": False}, {"api": False}])
cluster_db = self.env.clusters[0]
node1, node2 = self.env.nodes
nets_sent = [{"iface": "eth0", "vlans": [0]}]
nets_resp = [{"iface": "eth0", "vlans": []}]
task = Task(name="super", cluster_id=cluster_db.id)
task.cache = {"args": {"nodes": self.nodes_message((node1, node2), nets_sent), "offline": 0}}
self.db.add(task)
self.db.commit()
kwargs = {"task_uuid": task.uuid, "status": "ready", "nodes": self.nodes_message((node1, node2), nets_resp)}
self.receiver.verify_networks_resp(**kwargs)
self.db.flush()
self.db.refresh(task)
self.assertEqual(task.status, "error")
error_nodes = [
{
"uid": node1.id,
"interface": "eth0",
"name": node1.name,
"mac": node1.interfaces[0].mac,
"absent_vlans": nets_sent[0]["vlans"],
},
{
"uid": node2.id,
"interface": "eth0",
"name": node2.name,
"mac": node2.interfaces[0].mac,
"absent_vlans": nets_sent[0]["vlans"],
},
]
self.assertEqual(task.result, error_nodes)
示例6: test_verify_networks_resp_extra_nodes_error
# 需要导入模块: from nailgun.db.sqlalchemy.models import Task [as 别名]
# 或者: from nailgun.db.sqlalchemy.models.Task import cache [as 别名]
def test_verify_networks_resp_extra_nodes_error(self):
self.env.create(
cluster_kwargs={},
nodes_kwargs=[
{"api": False},
{"api": False}
]
)
cluster_db = self.env.clusters[0]
node1, node2 = self.env.nodes
node3 = self.env.create_node(api=False)
nets_sent = [{'iface': 'eth0', 'vlans': range(100, 105)}]
task = Task(
name="super",
cluster_id=cluster_db.id
)
task.cache = {
"args": {
'nodes': self.nodes_message((node1, node2), nets_sent),
'offline': 0,
}
}
self.db.add(task)
self.db.commit()
kwargs = {'task_uuid': task.uuid,
'status': 'ready',
'nodes': self.nodes_message((node1, node2, node3),
nets_sent)}
self.receiver.verify_networks_resp(**kwargs)
self.db.flush()
self.db.refresh(task)
self.assertEqual(task.status, "ready")
self.assertEqual(task.message, '')
示例7: execute
# 需要导入模块: from nailgun.db.sqlalchemy.models import Task [as 别名]
# 或者: from nailgun.db.sqlalchemy.models.Task import cache [as 别名]
def execute(self, nodes_to_deployment):
TaskHelper.update_slave_nodes_fqdn(nodes_to_deployment)
logger.debug('Nodes to deploy: {0}'.format(
' '.join([n.fqdn for n in nodes_to_deployment])))
task_deployment = Task(name='deployment', cluster=self.cluster)
db().add(task_deployment)
db().commit()
deployment_message = self._call_silently(
task_deployment,
tasks.DeploymentTask,
nodes_to_deployment,
method_name='message')
db().refresh(task_deployment)
task_deployment.cache = deployment_message
for node in nodes_to_deployment:
node.status = 'deploying'
node.progress = 0
db().commit()
rpc.cast('naily', deployment_message)
return task_deployment
示例8: execute
# 需要导入模块: from nailgun.db.sqlalchemy.models import Task [as 别名]
# 或者: from nailgun.db.sqlalchemy.models.Task import cache [as 别名]
def execute(self, nodes_to_provision):
"""Run provisioning task on specified nodes
"""
objects.NodeCollection.update_slave_nodes_fqdn(nodes_to_provision)
logger.debug('Nodes to provision: {0}'.format(
' '.join([n.fqdn for n in nodes_to_provision])))
task_provision = Task(name='provision', cluster=self.cluster)
db().add(task_provision)
db().commit()
provision_message = self._call_silently(
task_provision,
tasks.ProvisionTask,
nodes_to_provision,
method_name='message'
)
db().refresh(task_provision)
task_provision.cache = provision_message
for node in nodes_to_provision:
node.pending_addition = False
node.status = 'provisioning'
node.progress = 0
db().commit()
rpc.cast('naily', provision_message)
return task_provision
示例9: test_verify_networks_resp
# 需要导入模块: from nailgun.db.sqlalchemy.models import Task [as 别名]
# 或者: from nailgun.db.sqlalchemy.models.Task import cache [as 别名]
def test_verify_networks_resp(self):
self.env.create(
cluster_kwargs={},
nodes_kwargs=[
{"api": False},
{"api": False}
]
)
cluster_db = self.env.clusters[0]
node1, node2 = self.env.nodes
nets = [{'iface': 'eth0', 'vlans': range(100, 105)}]
task = Task(
name="verify_networks",
cluster_id=cluster_db.id
)
task.cache = {
"args": {
"nodes": [{'uid': node1.id, 'networks': nets},
{'uid': node2.id, 'networks': nets}]
}
}
self.db.add(task)
self.db.commit()
kwargs = {'task_uuid': task.uuid,
'status': 'ready',
'nodes': [{'uid': node1.id, 'networks': nets},
{'uid': node2.id, 'networks': nets}]}
self.receiver.verify_networks_resp(**kwargs)
self.db.refresh(task)
self.assertEqual(task.status, "ready")
self.assertEqual(task.message, '')
示例10: test_verify_networks_resp_empty_nodes_custom_error
# 需要导入模块: from nailgun.db.sqlalchemy.models import Task [as 别名]
# 或者: from nailgun.db.sqlalchemy.models.Task import cache [as 别名]
def test_verify_networks_resp_empty_nodes_custom_error(self):
self.env.create(
cluster_kwargs={},
nodes_kwargs=[
{"api": False},
{"api": False}
]
)
cluster_db = self.env.clusters[0]
node1, node2 = self.env.nodes
nets_sent = [{'iface': 'eth0', 'vlans': range(100, 105)}]
task = Task(
name="super",
cluster_id=cluster_db.id
)
task.cache = {
"args": {
'nodes': [{'uid': node1.id, 'networks': nets_sent},
{'uid': node2.id, 'networks': nets_sent}]
}
}
self.db.add(task)
self.db.commit()
error_msg = 'Custom error message.'
kwargs = {'task_uuid': task.uuid,
'status': 'ready',
'nodes': [],
'error': error_msg}
self.receiver.verify_networks_resp(**kwargs)
self.db.refresh(task)
self.assertEqual(task.status, "error")
self.assertEqual(task.message, error_msg)
示例11: execute
# 需要导入模块: from nailgun.db.sqlalchemy.models import Task [as 别名]
# 或者: from nailgun.db.sqlalchemy.models.Task import cache [as 别名]
def execute(self, nodes_to_deployment):
# locking nodes for update
objects.NodeCollection.lock_nodes(nodes_to_deployment)
objects.NodeCollection.update_slave_nodes_fqdn(nodes_to_deployment)
logger.debug("Nodes to deploy: {0}".format(" ".join([n.fqdn for n in nodes_to_deployment])))
task_deployment = Task(name="deployment", cluster=self.cluster)
db().add(task_deployment)
deployment_message = self._call_silently(
task_deployment, tasks.DeploymentTask, nodes_to_deployment, method_name="message"
)
db().refresh(task_deployment)
# locking task
task_deployment = objects.Task.get_by_uid(task_deployment.id, fail_if_not_found=True, lock_for_update=True)
# locking nodes
objects.NodeCollection.lock_nodes(nodes_to_deployment)
task_deployment.cache = deployment_message
for node in nodes_to_deployment:
node.status = "deploying"
node.progress = 0
db().commit()
rpc.cast("naily", deployment_message)
return task_deployment
示例12: test_verify_networks_resp_partially_without_vlans
# 需要导入模块: from nailgun.db.sqlalchemy.models import Task [as 别名]
# 或者: from nailgun.db.sqlalchemy.models.Task import cache [as 别名]
def test_verify_networks_resp_partially_without_vlans(self):
"""Verify that network verification partially without vlans passes
"""
self.env.create(
cluster_kwargs={},
nodes_kwargs=[
{"api": False},
{"api": False}
]
)
cluster_db = self.env.clusters[0]
node1, node2 = self.env.nodes
nets_sent = [{'iface': 'eth0', 'vlans': [0]},
{'iface': 'eth1', 'vlans': range(100, 104)}]
task = Task(
name="super",
cluster_id=cluster_db.id
)
task.cache = {
"args": {
'nodes': [{'uid': node1.id, 'networks': nets_sent},
{'uid': node2.id, 'networks': nets_sent}]
}
}
self.db.add(task)
self.db.commit()
kwargs = {'task_uuid': task.uuid,
'status': 'ready',
'nodes': [{'uid': node1.id, 'networks': nets_sent},
{'uid': node2.id, 'networks': nets_sent}]}
self.receiver.verify_networks_resp(**kwargs)
self.db.refresh(task)
self.assertEqual(task.status, "ready")
示例13: test_verify_networks_resp_without_vlans_only
# 需要导入模块: from nailgun.db.sqlalchemy.models import Task [as 别名]
# 或者: from nailgun.db.sqlalchemy.models.Task import cache [as 别名]
def test_verify_networks_resp_without_vlans_only(self):
"""Verify that network verification without vlans passes
when there only iface without vlans configured
"""
self.env.create(
cluster_kwargs={},
nodes_kwargs=[
{"api": False},
{"api": False}
]
)
cluster_db = self.env.clusters[0]
node1, node2 = self.env.nodes
nets_sent = [{'iface': 'eth0', 'vlans': [0]},
{'iface': 'eth1', 'vlans': [0]}]
task = Task(
name="super",
cluster_id=cluster_db.id
)
task.cache = {
"args": {
'nodes': self.nodes_message((node1, node2), nets_sent)
}
}
self.db.add(task)
self.db.commit()
kwargs = {'task_uuid': task.uuid,
'status': 'ready',
'nodes': self.nodes_message((node1, node2), nets_sent)}
self.receiver.verify_networks_resp(**kwargs)
self.db.flush()
self.db.refresh(task)
self.assertEqual(task.status, "ready")
示例14: test_verify_networks_resp_error
# 需要导入模块: from nailgun.db.sqlalchemy.models import Task [as 别名]
# 或者: from nailgun.db.sqlalchemy.models.Task import cache [as 别名]
def test_verify_networks_resp_error(self):
self.env.create(cluster_kwargs={}, nodes_kwargs=[{"api": False}, {"api": False}])
cluster_db = self.env.clusters[0]
node1, node2 = self.env.nodes
nets_sent = [{"iface": "eth0", "vlans": range(100, 105)}]
nets_resp = [{"iface": "eth0", "vlans": range(100, 104)}]
task = Task(name="super", cluster_id=cluster_db.id)
task.cache = {"args": {"nodes": self.nodes_message((node1, node2), nets_sent), "offline": 0}}
self.db.add(task)
self.db.commit()
kwargs = {"task_uuid": task.uuid, "status": "ready", "nodes": self.nodes_message((node1, node2), nets_resp)}
self.receiver.verify_networks_resp(**kwargs)
self.db.flush()
self.db.refresh(task)
self.assertEqual(task.status, "error")
error_nodes = []
for node in self.env.nodes:
error_nodes.append(
{
"uid": node.id,
"interface": "eth0",
"name": node.name,
"absent_vlans": [104],
"mac": node.interfaces[0].mac,
}
)
self.assertEqual(task.message, "")
self.assertEqual(task.result, error_nodes)
示例15: test_verify_networks_error_and_notice_are_concatenated
# 需要导入模块: from nailgun.db.sqlalchemy.models import Task [as 别名]
# 或者: from nailgun.db.sqlalchemy.models.Task import cache [as 别名]
def test_verify_networks_error_and_notice_are_concatenated(self):
self.env.create(cluster_kwargs={}, nodes_kwargs=[{"api": False}, {"api": False}])
cluster_db = self.env.clusters[0]
node1, node2 = self.env.nodes
nets = [{"iface": "eth0", "vlans": range(100, 105)}]
task = Task(name="verify_networks", cluster_id=cluster_db.id)
task.cache = {"args": {"nodes": self.nodes_message((node1, node2), nets), "offline": 2}}
self.db.add(task)
self.db.flush()
custom_error = "CustomError"
kwargs = {
"task_uuid": task.uuid,
"status": "error",
"nodes": self.nodes_message((node1, node2), nets),
"error": custom_error,
}
self.receiver.verify_networks_resp(**kwargs)
self.db.flush()
self.db.refresh(task)
self.assertEqual(task.status, "error")
offline_notice = (
"Notice: 2 node(s) were offline during connectivity" " check so they were skipped from the check."
)
self.assertEqual(task.message, "\n".join((custom_error, offline_notice)))