summaryrefslogtreecommitdiff
path: root/novaclient/tests/unit/v2/test_agents.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/tests/unit/v2/test_agents.py')
-rw-r--r--novaclient/tests/unit/v2/test_agents.py104
1 files changed, 104 insertions, 0 deletions
diff --git a/novaclient/tests/unit/v2/test_agents.py b/novaclient/tests/unit/v2/test_agents.py
new file mode 100644
index 0000000..e7fa7d6
--- /dev/null
+++ b/novaclient/tests/unit/v2/test_agents.py
@@ -0,0 +1,104 @@
1# Copyright 2012 IBM Corp.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from novaclient.tests.unit.fixture_data import agents as data
17from novaclient.tests.unit.fixture_data import client
18from novaclient.tests.unit import utils
19from novaclient.v2 import agents
20
21
22class AgentsTest(utils.FixturedTestCase):
23
24 data_fixture_class = data.Fixture
25
26 scenarios = [('original', {'client_fixture_class': client.V1}),
27 ('session', {'client_fixture_class': client.SessionV1})]
28
29 def stub_hypervisors(self, hypervisor='kvm'):
30 get_os_agents = {
31 'agents': [
32 {
33 'hypervisor': hypervisor,
34 'os': 'win',
35 'architecture': 'x86',
36 'version': '7.0',
37 'url': 'xxx://xxxx/xxx/xxx',
38 'md5hash': 'add6bb58e139be103324d04d82d8f545',
39 'id': 1
40 },
41 {
42 'hypervisor': hypervisor,
43 'os': 'linux',
44 'architecture': 'x86',
45 'version': '16.0',
46 'url': 'xxx://xxxx/xxx/xxx1',
47 'md5hash': 'add6bb58e139be103324d04d82d8f546',
48 'id': 2
49 },
50 ]
51 }
52
53 headers = {'Content-Type': 'application/json'}
54 self.requests.register_uri('GET', self.data_fixture.url(),
55 json=get_os_agents,
56 headers=headers)
57
58 def test_list_agents(self):
59 self.stub_hypervisors()
60 ags = self.cs.agents.list()
61 self.assert_called('GET', '/os-agents')
62 for a in ags:
63 self.assertIsInstance(a, agents.Agent)
64 self.assertEqual('kvm', a.hypervisor)
65
66 def test_list_agents_with_hypervisor(self):
67 self.stub_hypervisors('xen')
68 ags = self.cs.agents.list('xen')
69 self.assert_called('GET', '/os-agents?hypervisor=xen')
70 for a in ags:
71 self.assertIsInstance(a, agents.Agent)
72 self.assertEqual('xen', a.hypervisor)
73
74 def test_agents_create(self):
75 ag = self.cs.agents.create('win', 'x86', '7.0',
76 '/xxx/xxx/xxx',
77 'add6bb58e139be103324d04d82d8f546',
78 'xen')
79 body = {'agent': {'url': '/xxx/xxx/xxx',
80 'hypervisor': 'xen',
81 'md5hash': 'add6bb58e139be103324d04d82d8f546',
82 'version': '7.0',
83 'architecture': 'x86',
84 'os': 'win'}}
85 self.assert_called('POST', '/os-agents', body)
86 self.assertEqual(1, ag._info.copy()['id'])
87
88 def test_agents_delete(self):
89 self.cs.agents.delete('1')
90 self.assert_called('DELETE', '/os-agents/1')
91
92 def _build_example_update_body(self):
93 return {"para": {
94 "url": "/yyy/yyyy/yyyy",
95 "version": "8.0",
96 "md5hash": "add6bb58e139be103324d04d82d8f546"}}
97
98 def test_agents_modify(self):
99 ag = self.cs.agents.update('1', '8.0',
100 '/yyy/yyyy/yyyy',
101 'add6bb58e139be103324d04d82d8f546')
102 body = self._build_example_update_body()
103 self.assert_called('PUT', '/os-agents/1', body)
104 self.assertEqual(1, ag.id)