1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#!/usr/bin/python
import unittest
import common
from autotest_lib.frontend import setup_django_environment
from autotest_lib.frontend.afe import frontend_test_utils
from autotest_lib.frontend.afe import models
from autotest_lib.frontend.afe import model_logic
class AclGroupTest(unittest.TestCase,
frontend_test_utils.FrontendTestMixin):
def setUp(self):
self._frontend_common_setup()
def tearDown(self):
self._frontend_common_teardown()
def _check_acls(self, host, acl_name_list):
actual_acl_names = [acl_group.name for acl_group
in host.aclgroup_set.all()]
self.assertEquals(set(actual_acl_names), set(acl_name_list))
def test_on_host_membership_change(self):
host1, host2 = self.hosts[1:3]
everyone_acl = models.AclGroup.objects.get(name='Everyone')
host1.aclgroup_set.clear()
self._check_acls(host1, [])
host2.aclgroup_set.add(everyone_acl)
self._check_acls(host2, ['Everyone', 'my_acl'])
models.AclGroup.on_host_membership_change()
self._check_acls(host1, ['Everyone'])
self._check_acls(host2, ['my_acl'])
class SpecialTaskUnittest(unittest.TestCase,
frontend_test_utils.FrontendTestMixin):
def setUp(self):
self._frontend_common_setup()
def tearDown(self):
self._frontend_common_teardown()
def _create_task(self):
return models.SpecialTask.objects.create(
host=self.hosts[0], task=models.SpecialTask.Task.VERIFY)
def test_execution_path(self):
task = self._create_task()
self.assertEquals(task.execution_path(), 'hosts/host1/1-verify')
def test_status(self):
task = self._create_task()
self.assertEquals(task.status, 'Queued')
task.update_object(is_active=True)
self.assertEquals(task.status, 'Running')
task.update_object(is_active=False, is_complete=True)
self.assertEquals(task.status, 'Completed')
def test_activate(self):
task = self._create_task()
task.activate()
self.assertTrue(task.is_active)
self.assertFalse(task.is_complete)
def test_finish(self):
task = self._create_task()
task.activate()
task.finish()
self.assertFalse(task.is_active)
self.assertTrue(task.is_complete)
def test_prepare(self):
self.assertEqual(13, models.SpecialTask.prepare(agent=None, task=13))
class DummyAgentTask(object):
host = None
queue_entry = None
self.assertRaises(ValueError, models.SpecialTask.prepare,
DummyAgentTask(), None)
DummyAgentTask.TASK_TYPE = models.SpecialTask.Task.VERIFY
DummyAgentTask.host = models.Host.objects.create(hostname='hi')
task1 = models.SpecialTask.prepare(DummyAgentTask(), None)
task1.activate()
DummyAgentTask.TASK_TYPE = models.SpecialTask.Task.REPAIR
self.assertRaises(model_logic.ValidationError,
models.SpecialTask.prepare, DummyAgentTask(), None)
if __name__ == '__main__':
unittest.main()
|