Skip to content

Commit

Permalink
Merge "Add unit tests for create/update/delete_agent"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Jul 31, 2015
2 parents 9311268 + 14bf424 commit 02753ee
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
3 changes: 2 additions & 1 deletion tempest/services/compute/json/agents_client.py
Expand Up @@ -52,4 +52,5 @@ def update_agent(self, agent_id, **kwargs):
"""Update an agent build."""
put_body = json.dumps({'para': kwargs})
resp, body = self.put('os-agents/%s' % agent_id, put_body)
return service_client.ResponseBody(resp, self._parse_resp(body))
body = json.loads(body)
return service_client.ResponseBody(resp, body['agent'])
61 changes: 58 additions & 3 deletions tempest/tests/services/compute/test_agents_client.py
Expand Up @@ -14,36 +14,91 @@

import httplib2

from oslo_serialization import jsonutils as json
from oslotest import mockpatch

from tempest.services.compute.json import agents_client
from tempest.tests import base
from tempest.tests import fake_auth_provider
from tempest.tests import fake_config


class TestAgentsClient(base.TestCase):

def setUp(self):
super(TestAgentsClient, self).setUp()
self.useFixture(fake_config.ConfigFixture())
fake_auth = fake_auth_provider.FakeAuthProvider()
self.client = agents_client.AgentsClient(fake_auth,
'compute', 'regionOne')

def _test_list_agents(self, bytes_body=False):
body = '{"agents": []}'
if bytes_body:
body = bytes(body.encode('utf-8'))
body = body.encode('utf-8')
expected = []
response = (httplib2.Response({'status': 200}), body)
self.useFixture(mockpatch.Patch(
'tempest.common.service_client.ServiceClient.get',
return_value=response))
self.assertEqual(expected, self.client.list_agents())

def _test_create_agent(self, bytes_body=False):
expected = {"url": "http://foo.com", "hypervisor": "kvm",
"md5hash": "md5", "version": "2", "architecture": "x86_64",
"os": "linux", "agent_id": 1}
serialized_body = json.dumps({"agent": expected})
if bytes_body:
serialized_body = serialized_body.encode('utf-8')

mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
self.useFixture(mockpatch.Patch(
'tempest.common.service_client.ServiceClient.post',
return_value=mocked_resp))
resp = self.client.create_agent(
url="http://foo.com", hypervisor="kvm", md5hash="md5",
version="2", architecture="x86_64", os="linux"
)
self.assertEqual(expected, resp)

def _test_delete_agent(self):
mocked_resp = (httplib2.Response({'status': 200}), None)
self.useFixture(mockpatch.Patch(
'tempest.common.service_client.ServiceClient.delete',
return_value=mocked_resp))
self.client.delete_agent("1")

def _test_update_agent(self, bytes_body=False):
expected = {"url": "http://foo.com", "md5hash": "md5", "version": "2",
"agent_id": 1}
serialized_body = json.dumps({"agent": expected})
if bytes_body:
serialized_body = serialized_body.encode('utf-8')

mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
self.useFixture(mockpatch.Patch(
'tempest.common.service_client.ServiceClient.put',
return_value=mocked_resp))
resp = self.client.update_agent(
"1", url="http://foo.com", md5hash="md5", version="2"
)
self.assertEqual(expected, resp)

def test_list_agents_with_str_body(self):
self._test_list_agents()

def test_list_agents_with_bytes_body(self):
self._test_list_agents(bytes_body=True)

def test_create_agent_with_str_body(self):
self._test_create_agent()

def test_create_agent_with_bytes_body(self):
self._test_create_agent(bytes_body=True)

def test_delete_agent(self):
self._test_delete_agent()

def test_update_agent_with_str_body(self):
self._test_update_agent()

def test_update_agent_with_bytes_body(self):
self._test_update_agent(bytes_body=True)

0 comments on commit 02753ee

Please sign in to comment.