Ken'ichi Ohmichi | ad0dfb4 | 2015-07-14 08:52:25 +0000 | [diff] [blame] | 1 | # Copyright 2015 NEC Corporation. All rights reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
Ken'ichi Ohmichi | ad0dfb4 | 2015-07-14 08:52:25 +0000 | [diff] [blame] | 15 | from tempest.services.compute.json import agents_client |
Ken'ichi Ohmichi | ad0dfb4 | 2015-07-14 08:52:25 +0000 | [diff] [blame] | 16 | from tempest.tests import fake_auth_provider |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 17 | from tempest.tests.services.compute import base |
Ken'ichi Ohmichi | ad0dfb4 | 2015-07-14 08:52:25 +0000 | [diff] [blame] | 18 | |
| 19 | |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 20 | class TestAgentsClient(base.BaseComputeServiceTest): |
| 21 | FAKE_CREATE_AGENT = { |
| 22 | "agent": |
| 23 | { |
| 24 | "url": "http://foo.com", |
| 25 | "hypervisor": "kvm", |
| 26 | "md5hash": "md5", |
| 27 | "version": "2", |
| 28 | "architecture": "x86_64", |
| 29 | "os": "linux", |
| 30 | "agent_id": 1 |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | FAKE_UPDATE_AGENT = { |
| 35 | "agent": |
| 36 | { |
| 37 | "url": "http://foo.com", |
| 38 | "hypervisor": "kvm", |
| 39 | "md5hash": "md5", |
| 40 | "version": "2", |
| 41 | "architecture": "x86_64", |
| 42 | "os": "linux", |
| 43 | "agent_id": 1 |
| 44 | } |
| 45 | } |
Ken'ichi Ohmichi | ad0dfb4 | 2015-07-14 08:52:25 +0000 | [diff] [blame] | 46 | |
| 47 | def setUp(self): |
| 48 | super(TestAgentsClient, self).setUp() |
Ken'ichi Ohmichi | ad0dfb4 | 2015-07-14 08:52:25 +0000 | [diff] [blame] | 49 | fake_auth = fake_auth_provider.FakeAuthProvider() |
| 50 | self.client = agents_client.AgentsClient(fake_auth, |
| 51 | 'compute', 'regionOne') |
| 52 | |
| 53 | def _test_list_agents(self, bytes_body=False): |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 54 | self.check_service_client_function( |
| 55 | self.client.list_agents, |
Ken'ichi Ohmichi | ad0dfb4 | 2015-07-14 08:52:25 +0000 | [diff] [blame] | 56 | 'tempest.common.service_client.ServiceClient.get', |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 57 | {"agents": []}, |
| 58 | bytes_body) |
Ken'ichi Ohmichi | ad0dfb4 | 2015-07-14 08:52:25 +0000 | [diff] [blame] | 59 | |
Ken'ichi Ohmichi | 14bf424 | 2015-07-17 02:28:21 +0000 | [diff] [blame] | 60 | def _test_create_agent(self, bytes_body=False): |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 61 | self.check_service_client_function( |
| 62 | self.client.create_agent, |
Ken'ichi Ohmichi | 14bf424 | 2015-07-17 02:28:21 +0000 | [diff] [blame] | 63 | 'tempest.common.service_client.ServiceClient.post', |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 64 | self.FAKE_CREATE_AGENT, |
| 65 | bytes_body, |
Ken'ichi Ohmichi | 14bf424 | 2015-07-17 02:28:21 +0000 | [diff] [blame] | 66 | url="http://foo.com", hypervisor="kvm", md5hash="md5", |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 67 | version="2", architecture="x86_64", os="linux") |
Ken'ichi Ohmichi | 14bf424 | 2015-07-17 02:28:21 +0000 | [diff] [blame] | 68 | |
| 69 | def _test_delete_agent(self): |
Anusha Ramineni | c254c7a | 2015-09-07 15:32:23 +0530 | [diff] [blame] | 70 | self.check_service_client_function( |
| 71 | self.client.delete_agent, |
Ken'ichi Ohmichi | 14bf424 | 2015-07-17 02:28:21 +0000 | [diff] [blame] | 72 | 'tempest.common.service_client.ServiceClient.delete', |
Anusha Ramineni | c254c7a | 2015-09-07 15:32:23 +0530 | [diff] [blame] | 73 | {}, agent_id="1") |
Ken'ichi Ohmichi | 14bf424 | 2015-07-17 02:28:21 +0000 | [diff] [blame] | 74 | |
| 75 | def _test_update_agent(self, bytes_body=False): |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 76 | self.check_service_client_function( |
| 77 | self.client.update_agent, |
Ken'ichi Ohmichi | 14bf424 | 2015-07-17 02:28:21 +0000 | [diff] [blame] | 78 | 'tempest.common.service_client.ServiceClient.put', |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 79 | self.FAKE_UPDATE_AGENT, |
| 80 | bytes_body, |
| 81 | agent_id="1", url="http://foo.com", md5hash="md5", version="2") |
Ken'ichi Ohmichi | 14bf424 | 2015-07-17 02:28:21 +0000 | [diff] [blame] | 82 | |
Ken'ichi Ohmichi | ad0dfb4 | 2015-07-14 08:52:25 +0000 | [diff] [blame] | 83 | def test_list_agents_with_str_body(self): |
| 84 | self._test_list_agents() |
| 85 | |
| 86 | def test_list_agents_with_bytes_body(self): |
| 87 | self._test_list_agents(bytes_body=True) |
Ken'ichi Ohmichi | 14bf424 | 2015-07-17 02:28:21 +0000 | [diff] [blame] | 88 | |
| 89 | def test_create_agent_with_str_body(self): |
| 90 | self._test_create_agent() |
| 91 | |
| 92 | def test_create_agent_with_bytes_body(self): |
| 93 | self._test_create_agent(bytes_body=True) |
| 94 | |
| 95 | def test_delete_agent(self): |
| 96 | self._test_delete_agent() |
| 97 | |
| 98 | def test_update_agent_with_str_body(self): |
| 99 | self._test_update_agent() |
| 100 | |
| 101 | def test_update_agent_with_bytes_body(self): |
| 102 | self._test_update_agent(bytes_body=True) |