Adds agent support for Nova V3 API
Adds support and tests for the os-agents extension for the Nova V3 API Partially implements blueprint v3-api Change-Id: I53f8a1cbab6f4dee10fb823bc51ae90baa97fa7a
This commit is contained in:
parent
72b1862c97
commit
59cf27aa3f
novaclient
@ -20,25 +20,34 @@ from novaclient.tests.v1_1 import fakes
|
||||
from novaclient.v1_1 import agents
|
||||
|
||||
|
||||
cs = fakes.FakeClient()
|
||||
|
||||
|
||||
class AgentsTest(utils.TestCase):
|
||||
def setUp(self):
|
||||
super(AgentsTest, self).setUp()
|
||||
self.cs = self._get_fake_client()
|
||||
self.agent_type = self._get_agent_type()
|
||||
|
||||
def _get_fake_client(self):
|
||||
return fakes.FakeClient()
|
||||
|
||||
def _get_agent_type(self):
|
||||
return agents.Agent
|
||||
|
||||
def test_list_agents(self):
|
||||
ags = cs.agents.list()
|
||||
cs.assert_called('GET', '/os-agents')
|
||||
[self.assertTrue(isinstance(a, agents.Agent)) for a in ags]
|
||||
[self.assertEqual(a.hypervisor, 'kvm') for a in ags]
|
||||
ags = self.cs.agents.list()
|
||||
self.cs.assert_called('GET', '/os-agents')
|
||||
for a in ags:
|
||||
self.assertTrue(isinstance(a, self.agent_type))
|
||||
self.assertEqual(a.hypervisor, 'kvm')
|
||||
|
||||
def test_list_agents_with_hypervisor(self):
|
||||
ags = cs.agents.list('xen')
|
||||
cs.assert_called('GET', '/os-agents?hypervisor=xen')
|
||||
[self.assertTrue(isinstance(a, agents.Agent)) for a in ags]
|
||||
[self.assertEqual(a.hypervisor, 'xen') for a in ags]
|
||||
ags = self.cs.agents.list('xen')
|
||||
self.cs.assert_called('GET', '/os-agents?hypervisor=xen')
|
||||
for a in ags:
|
||||
self.assertTrue(isinstance(a, self.agent_type))
|
||||
self.assertEqual(a.hypervisor, 'xen')
|
||||
|
||||
def test_agents_create(self):
|
||||
ag = cs.agents.create('win', 'x86', '7.0',
|
||||
ag = self.cs.agents.create('win', 'x86', '7.0',
|
||||
'/xxx/xxx/xxx',
|
||||
'add6bb58e139be103324d04d82d8f546',
|
||||
'xen')
|
||||
@ -49,20 +58,23 @@ class AgentsTest(utils.TestCase):
|
||||
'version': '7.0',
|
||||
'architecture': 'x86',
|
||||
'os': 'win'}}
|
||||
cs.assert_called('POST', '/os-agents', body)
|
||||
self.cs.assert_called('POST', '/os-agents', body)
|
||||
self.assertEqual(1, ag._info.copy()['id'])
|
||||
|
||||
def test_agents_delete(self):
|
||||
cs.agents.delete('1')
|
||||
cs.assert_called('DELETE', '/os-agents/1')
|
||||
self.cs.agents.delete('1')
|
||||
self.cs.assert_called('DELETE', '/os-agents/1')
|
||||
|
||||
def _build_example_update_body(self):
|
||||
return {"para": {
|
||||
"url": "/yyy/yyyy/yyyy",
|
||||
"version": "8.0",
|
||||
"md5hash": "add6bb58e139be103324d04d82d8f546"}}
|
||||
|
||||
def test_agents_modify(self):
|
||||
ag = cs.agents.update('1', '8.0',
|
||||
ag = self.cs.agents.update('1', '8.0',
|
||||
'/yyy/yyyy/yyyy',
|
||||
'add6bb58e139be103324d04d82d8f546')
|
||||
body = {"para": {
|
||||
"url": "/yyy/yyyy/yyyy",
|
||||
"version": "8.0",
|
||||
"md5hash": "add6bb58e139be103324d04d82d8f546"}}
|
||||
cs.assert_called('PUT', '/os-agents/1', body)
|
||||
body = self._build_example_update_body()
|
||||
self.cs.assert_called('PUT', '/os-agents/1', body)
|
||||
self.assertEqual(1, ag.id)
|
||||
|
34
novaclient/tests/v3/test_agents.py
Normal file
34
novaclient/tests/v3/test_agents.py
Normal file
@ -0,0 +1,34 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2012 IBM Corp.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from novaclient.tests.v1_1 import test_agents
|
||||
from novaclient.tests.v3 import fakes
|
||||
from novaclient.v3 import agents
|
||||
|
||||
|
||||
class AgentsTest(test_agents.AgentsTest):
|
||||
def _build_example_update_body(self):
|
||||
return {"agent": {
|
||||
"url": "/yyy/yyyy/yyyy",
|
||||
"version": "8.0",
|
||||
"md5hash": "add6bb58e139be103324d04d82d8f546"}}
|
||||
|
||||
def _get_fake_client(self):
|
||||
return fakes.FakeClient()
|
||||
|
||||
def _get_agent_type(self):
|
||||
return agents.Agent
|
@ -42,13 +42,16 @@ class AgentsManager(base.ManagerWithFind):
|
||||
url = "/os-agents?hypervisor=%s" % hypervisor
|
||||
return self._list(url, "agents")
|
||||
|
||||
def update(self, id, version,
|
||||
url, md5hash):
|
||||
"""Update an existing agent build."""
|
||||
body = {'para': {
|
||||
def _build_update_body(self, version, url, md5hash):
|
||||
return {'para': {
|
||||
'version': version,
|
||||
'url': url,
|
||||
'md5hash': md5hash}}
|
||||
|
||||
def update(self, id, version,
|
||||
url, md5hash):
|
||||
"""Update an existing agent build."""
|
||||
body = self._build_update_body(version, url, md5hash)
|
||||
return self._update('/os-agents/%s' % id, body, 'agent')
|
||||
|
||||
def create(self, os, architecture, version,
|
||||
|
36
novaclient/v3/agents.py
Normal file
36
novaclient/v3/agents.py
Normal file
@ -0,0 +1,36 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2012 IBM Corp.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
agent interface
|
||||
"""
|
||||
|
||||
from novaclient.v1_1 import agents
|
||||
|
||||
|
||||
class Agent(agents.Agent):
|
||||
pass
|
||||
|
||||
|
||||
class AgentsManager(agents.AgentsManager):
|
||||
resource_class = Agent
|
||||
|
||||
def _build_update_body(self, version, url, md5hash):
|
||||
return {'agent': {
|
||||
'version': version,
|
||||
'url': url,
|
||||
'md5hash': md5hash}}
|
@ -15,6 +15,7 @@
|
||||
# under the License.
|
||||
|
||||
from novaclient import client
|
||||
from novaclient.v3 import agents
|
||||
from novaclient.v3 import flavor_access
|
||||
from novaclient.v3 import flavors
|
||||
from novaclient.v3 import hosts
|
||||
@ -52,6 +53,7 @@ class Client(object):
|
||||
self.tenant_id = tenant_id
|
||||
self.os_cache = os_cache or not no_cache
|
||||
#TODO(bnemec): Add back in v3 extensions
|
||||
self.agents = agents.AgentsManager(self)
|
||||
self.hosts = hosts.HostManager(self)
|
||||
self.flavors = flavors.FlavorManager(self)
|
||||
self.flavor_access = flavor_access.FlavorAccessManager(self)
|
||||
|
Loading…
x
Reference in New Issue
Block a user