Porting existing compute tests to metatests

1. Ported all compute unittests to metatests
2. Ported all compute client integration tests to
   metatests

Change-Id: Ia80e2afcb1cca3921338392ed3cc6c0489eb1a2c
This commit is contained in:
Sumanth Nagadavalli 2013-06-20 16:35:53 +05:30
parent 661925b0a3
commit 6218cf8cf6
40 changed files with 564 additions and 498 deletions

4
.gitignore vendored
View File

@ -32,3 +32,7 @@ pip-log.txt
# vim
*.swp
#py.test logger
cc.master.log
metatests*.log

View File

@ -34,7 +34,7 @@ class IpRange(AutoMarshallingModel):
@classmethod
def _xml_ele_to_obj(cls, xml_ele):
cidr = xml_ele.find('cidr').text
return IpRange(cidr)
return IpRange(cidr=cidr)
class SecurityGroupRule(AutoMarshallingModel):

View File

@ -54,7 +54,7 @@ class Quota(AutoMarshallingModel):
quota_dict.get('metadata_items'),
quota_dict.get('ram'),
quota_dict.get('security_group_rules'),
quota_dict.get('security_group_rules'))
quota_dict.get('security_groups'))
@classmethod
def _json_to_obj(cls, serialized_str):

View File

@ -1,79 +0,0 @@
"""
Copyright 2013 Rackspace
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.
"""
class HostsMockResponse():
def __init__(self, format):
self.format = format
def list_hosts(self):
return getattr(self, '_{0}_hosts'.format(self.format))()
def get_host(self):
return getattr(self, '_{0}_host'.format(self.format))()
def _json_hosts(self):
return '{"hosts":[{' \
'"host_name": "787f4f6dda1b409bb8b2f9082349690e",' \
'"service": "compute",' \
'"zone": "nova"},' \
'"{host_name": "a98b433151084aee8b1a986e28823b36",' \
'"service": "cert",' \
'"zone": "internal"}]}'
def _xml_hosts(self):
return '<?xml version="1.0" encoding="UTF-8"?>' \
'<hosts>' \
'<host host_name="461697a871354212908d82bbb0f9f5ee"' \
' service="compute"/>' \
'<host host_name="272ab5d262994ebdaf228935c8ecf57e"' \
' service="cert"/>' \
'<host host_name="2d1bdd671b5d41fd89dec74be5770c63"' \
' service="network"/>' \
'<host host_name="7c2dd5ecb7494dd1bf4240b7f7f9bf3a"' \
' service="scheduler"/>' \
'<host host_name="f9c273d8e03141a2a01def0ad18e5be4"' \
' service="conductor"/>' \
'<host host_name="2b893569cd824b979bd80a2c94570a1f"' \
' service="cells"/>' \
'</hosts>'
def _xml_host(self):
return '<?xml version="1.0" encoding="UTF-8"?>' \
'<host>' \
'<resource>' \
'<project>(total)</project>' \
'<memory_mb>8192</memory_mb>' \
'<host>ecf3458ac6bf4a299cc2e0efa740f426</host>' \
'<cpu>1</cpu>' \
'<disk_gb>1028</disk_gb>' \
'</resource>' \
'</host>'
def _json_host(cls):
return '{"host":' \
' [{"resource":' \
' {"cpu": 1,' \
'"disk_gb": 1028,' \
'"host": "787f4f6dda1b409bb8b2f9082349690e",' \
'"memory_mb": 8192,"project": "(total)"}},' \
'{"resource":' \
' {"cpu": 0,' \
'"disk_gb": 0,' \
'"host": "787f4f6dda1b409bb8b2f9082349690e",' \
'"memory_mb": 512,' \
'"project": "(used_now)"}}]}'

View File

@ -1,50 +0,0 @@
"""
Copyright 2013 Rackspace
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.
"""
class SecurityGroupRulesMockResponse():
def __init__(self, format):
self.format = format
def _get_sec_group_rule(self):
return getattr(self, '_{0}_sec_group_rule'.format(self.format))()
def _json_sec_group_rule(self):
return '{"security_group_rule":' \
' {"from_port": 80,' \
' "ip_protocol": "tcp",' \
' "to_port": 8080,' \
' "parent_group_id": 2,' \
' "ip_range": {"cidr": "0.0.0.0/0"},' \
' "id": 1' \
' "group": {}}}'
def _xml_sec_group_rule(self):
return '<?xml version=\'1.0\' encoding=\'UTF-8\'?>' \
'<security_group_rule ' \
'parent_group_id=2 id=1>' \
'<from_port>80</from_port>' \
'<ip_protocol>tcp</ip_protocol>' \
'<to_port>8080</to_port>' \
'<ip_range>' \
'<cidr>0.0.0.0/0</cidr>' \
'</ip_range>' \
'<group>' \
'<name>None</name>' \
'<tenant_id>None</tenant_id>' \
'</group>' \
'</security_group_rule>'

View File

@ -1,106 +0,0 @@
"""
Copyright 2013 Rackspace
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.
"""
import unittest2 as unittest
from cloudcafe.compute.hypervisors_api.model.hypervisors import Hypervisor
class HypervisorDomainTest(object):
def test_hypervisor_attr(self):
self.assertEqual(self.hypervisor[0].id, "1")
self.assertEqual(self.hypervisor[0].hypervisor_hostname,
"hypervisor_test")
class HypervisorDomainJSONTest(unittest.TestCase, HypervisorDomainTest):
@classmethod
def setUp(cls):
cls.hypervisor_json = '{"hypervisors": [{' \
'"id": "1", ' \
'"hypervisor_hostname": "hypervisor_test"}]}'
cls.hypervisor = Hypervisor.deserialize(cls.hypervisor_json, "json")
class HypervisorDomainXMLTest(unittest.TestCase, HypervisorDomainTest):
@classmethod
def setUp(cls):
cls.hypervisor_xml = '<?xml version="1.0" encoding="UTF-8"?>' \
'<hypervisors><hypervisor id="1" ' \
'hypervisor_hostname="hypervisor_test"/>' \
'</hypervisors>'
cls.hypervisor = Hypervisor.deserialize(cls.hypervisor_xml, "xml")
class HypervisorServerCollectionDomainTest(object):
def test_hypervisor_servers_length(self):
self.assertEqual(len(self.hypervisor.servers), 2)
def test_hypervisor_servers_attr(self):
self.assertTrue("server_one" in
[server.name for server in self.hypervisor.servers])
self.assertTrue("server_two" in
[server.name for server in self.hypervisor.servers])
self.assertTrue("b1ea4f1b-201c-47c5-95b9-c6fe2df39af0"
in [server.id
for server in self.hypervisor.servers])
self.assertTrue("9327b134-b1f5-43ec-a8f1-2b6eb153c739"
in [server.id
for server in self.hypervisor.servers])
class ServersDomainCollectionJSONTest(unittest.TestCase,
HypervisorServerCollectionDomainTest):
@classmethod
def setUp(cls):
cls.hypervisor_json = '{"hypervisors": [{' \
'"id": 1, ' \
'"hypervisor_hostname": "hypervisor_test", ' \
'"servers": [{' \
'"uuid": ' \
'"b1ea4f1b-201c-47c5-95b9-c6fe2df39af0", ' \
'"name": "server_one"}, ' \
'{"uuid": ' \
'"9327b134-b1f5-43ec-a8f1-2b6eb153c739", ' \
'"name": "server_two"}]}]}'
cls.hypervisor = Hypervisor.deserialize(cls.hypervisor_json, "json")
class ServersDomainCollectionXMLTest(unittest.TestCase,
HypervisorServerCollectionDomainTest):
@classmethod
def setUp(cls):
cls.hypervisor_xml = '<?xml version="1.0" encoding="UTF-8"?>' \
'<hypervisors>' \
'<hypervisor ' \
'id="1" ' \
'hypervisor_hostname="hypervisor_test">' \
'<servers>' \
'<server name="server_one" ' \
'uuid="b1ea4f1b-201c-47c5-95b9-c6fe2df39af0"/>' \
'<server name="server_two" ' \
'uuid="9327b134-b1f5-43ec-a8f1-2b6eb153c739"/>' \
'</servers></hypervisor></hypervisors>'
cls.hypervisor = Hypervisor.deserialize(cls.hypervisor_xml,
"xml")
if __name__ == '__main__':
unittest.main()

View File

@ -1,84 +0,0 @@
"""
Copyright 2013 Rackspace
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.
"""
import unittest2 as unittest
from cloudcafe.compute.extensions.security_groups_api.models.\
security_group_rule import SecurityGroupRule
class SecurityGroupRuleDomainTest(object):
def test_security_group_rule_attributes(self):
self.assertEqual(str(self.sec_group_rule.from_port), '80')
self.assertEqual(str(self.sec_group_rule.to_port), '8080')
self.assertEqual(self.sec_group_rule.ip_protocol, 'tcp')
self.assertEqual(self.sec_group_rule.id,
'bf57c853-cdf2-4c99-9f9a-79b3e9dc13a8')
self.assertEqual(self.sec_group_rule.parent_group_id,
'b32c047d-5efc-42ab-8476-3ac9f3681af2')
self.assertEqual(self.sec_group_rule.ip_range.cidr, '0.0.0.0/0')
class SecurityGroupRuleDomainJSONTest(unittest.TestCase,
SecurityGroupRuleDomainTest):
@classmethod
def setUpClass(cls):
cls.sec_group_rule_json = '{"security_group_rule":' \
' {"from_port": 80,' \
'"group": {},' \
'"ip_protocol": "tcp",' \
'"to_port": 8080,' \
'"parent_group_id":' \
' "b32c047d-5efc-42ab-8476-3ac9f3681af2",' \
'"ip_range": {"cidr": "0.0.0.0/0"},' \
'"id":' \
' "bf57c853-cdf2-4c99-9f9a-79b3e9dc13a8"}}'
cls.sec_group_rule = SecurityGroupRule.\
deserialize(cls.sec_group_rule_json, "json")
class SecurityGroupRuleDomainXMLTest(unittest.TestCase,
SecurityGroupRuleDomainTest):
@classmethod
def setUpClass(cls):
cls.sec_group_rule_xml = '<?xml version="1.0" encoding="UTF-8"?>' \
'<security_group_rule ' \
'xmlns=' \
'"http://docs.openstack.org/' \
'compute/api/v1.1"' \
'parent_group_id=' \
'"b32c047d-5efc-42ab-8476-3ac9f3681af2" ' \
'id=' \
'"bf57c853-cdf2-4c99-9f9a-79b3e9dc13a8">' \
'<ip_protocol>tcp</ip_protocol>' \
'<from_port>80</from_port>' \
'<to_port>8080</to_port>' \
'<group>' \
'<name>None</name>' \
'<tenant_id>None</tenant_id>' \
'</group>' \
'<ip_range>' \
'<cidr>0.0.0.0/0</cidr>' \
'</ip_range>' \
'</security_group_rule>'
cls.sec_group_rule = SecurityGroupRule.\
deserialize(cls.sec_group_rule_xml, "xml")
if __name__ == '__main__':
unittest.main()

View File

@ -14,12 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
"""
import unittest2 as unittest
from httpretty import HTTPretty
from cafe.drivers.unittest.fixtures import BaseTestFixture
class IntegrationTestFixture(BaseTestFixture):
class ClientTestFixture(unittest.TestCase):
AUTH_TOKEN = 'dda0e9d0a1084f67bb9ea4e91abcd4ec'
COMPUTE_API_ENDPOINT = 'http://localhost:5000/v1'
@ -29,16 +28,16 @@ class IntegrationTestFixture(BaseTestFixture):
CONTENT_TYPE = 'application/{0}'.format(FORMAT)
ACCEPT = 'application/{0}'.format(FORMAT)
@classmethod
def setUp(cls):
super(IntegrationTestFixture, cls).setUp()
HTTPretty.reset()
HTTPretty.enable()
@classmethod
def tearDown(cls):
super(IntegrationTestFixture, cls).tearDown()
HTTPretty.disable()
def _assert_default_headers_in_request(self, request):
self.assertEqual(request.headers['X-Auth-Token'], self.AUTH_TOKEN)
self.assertEqual(request.headers['Content-Type'], self.CONTENT_TYPE)
self.assertEqual(request.headers['Accept'], self.ACCEPT)
assert request.headers['X-Auth-Token'] == self.AUTH_TOKEN
assert request.headers['Content-Type'] == self.CONTENT_TYPE
assert request.headers['Accept'] == self.ACCEPT

View File

@ -0,0 +1,79 @@
"""
Copyright 2013 Rackspace
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.
"""
class HostsMockResponse():
def __init__(self, format):
self.format = format
def list_hosts(self):
return getattr(self, '_{0}_hosts'.format(self.format))()
def get_host(self):
return getattr(self, '_{0}_host'.format(self.format))()
def _json_hosts(self):
return ('{"hosts":[{'
'"host_name": "787f4f6dda1b409bb8b2f9082349690e",'
'"service": "compute",'
'"zone": "nova"},'
'"{host_name": "a98b433151084aee8b1a986e28823b36",'
'"service": "cert",'
'"zone": "internal"}]}')
def _xml_hosts(self):
return ('<?xml version="1.0" encoding="UTF-8"?>'
'<hosts>'
'<host host_name="461697a871354212908d82bbb0f9f5ee"'
' service="compute"/>'
'<host host_name="272ab5d262994ebdaf228935c8ecf57e"'
' service="cert"/>'
'<host host_name="2d1bdd671b5d41fd89dec74be5770c63"'
' service="network"/>'
'<host host_name="7c2dd5ecb7494dd1bf4240b7f7f9bf3a"'
' service="scheduler"/>'
'<host host_name="f9c273d8e03141a2a01def0ad18e5be4"'
' service="conductor"/>'
'<host host_name="2b893569cd824b979bd80a2c94570a1f"'
' service="cells"/>'
'</hosts>')
def _xml_host(self):
return ('<?xml version="1.0" encoding="UTF-8"?>'
'<host>'
'<resource>'
'<project>(total)</project>'
'<memory_mb>8192</memory_mb>'
'<host>ecf3458ac6bf4a299cc2e0efa740f426</host>'
'<cpu>1</cpu>'
'<disk_gb>1028</disk_gb>'
'</resource>'
'</host>')
def _json_host(cls):
return ('{"host":'
' [{"resource":'
' {"cpu": 1,'
'"disk_gb": 1028,'
'"host": "787f4f6dda1b409bb8b2f9082349690e",'
'"memory_mb": 8192,"project": "(total)"}},'
'{"resource":'
' {"cpu": 0,'
'"disk_gb": 0,'
'"host": "787f4f6dda1b409bb8b2f9082349690e",'
'"memory_mb": 512,'
'"project": "(used_now)"}}]}')

View File

@ -14,19 +14,18 @@ See the License for the specific language governing permissions and
limitations under the License.
"""
import unittest2 as unittest
import httpretty
from httpretty import HTTPretty
from cloudcafe.compute.hosts_api.client import HostsClient
from cloudcafe.compute.tests.integration.fixtures import IntegrationTestFixture
from cloudcafe.compute.tests.integration.hosts.responses\
from metatests.cloudcafe.compute.fixtures import ClientTestFixture
from metatests.cloudcafe.compute.hosts.client.responses \
import HostsMockResponse
HOST_NAME = "787f4f6dda1b409bb8b2f9082349690e"
class HostsClientTest(IntegrationTestFixture):
class HostsClientTest(ClientTestFixture):
@classmethod
def setUpClass(cls):
@ -42,20 +41,15 @@ class HostsClientTest(IntegrationTestFixture):
cls.mock_response = HostsMockResponse(cls.FORMAT)
def test_list_hosts(self):
httpretty.register_uri(httpretty.GET, self.hosts_uri,
HTTPretty.register_uri(HTTPretty.GET, self.hosts_uri,
body=self.mock_response.list_hosts())
response = self.hosts_client.list_hosts()
self.assertEqual(200, response.status_code)
self.assertEqual(self.mock_response.list_hosts(),
response.content)
self.assertEqual(self.mock_response.list_hosts(), response.content)
def test_get_host(self):
httpretty.register_uri(httpretty.GET, self.host_uri,
HTTPretty.register_uri(HTTPretty.GET, self.host_uri,
body=self.mock_response.get_host())
response = self.hosts_client.get_host(HOST_NAME)
self.assertEqual(200, response.status_code)
self.assertEqual(self.mock_response.get_host(), response.content)
if __name__ == '__main__':
unittest.main()

View File

@ -44,12 +44,12 @@ class HostDomainJSONTest(unittest.TestCase, HostDomainTest):
@classmethod
def setUpClass(cls):
cls.host_json = '{"host":[{"resource":' \
'{"cpu": "1",' \
'"disk_gb": "1028", ' \
' "host": "nova", ' \
'"memory_mb": "8192", ' \
'"project": "(total)"}}]}'
cls.host_json = ('{"host":[{"resource":'
'{"cpu": "1",'
'"disk_gb": "1028", '
' "host": "nova", '
'"memory_mb": "8192", '
'"project": "(total)"}}]}')
cls.host = Host.deserialize(cls.host_json, "json")
@ -57,13 +57,13 @@ class HostDomainXMLTest(unittest.TestCase, HostDomainTest):
@classmethod
def setUpClass(cls):
cls.host_xml = '<?xml version="1.0" encoding="UTF-8"?>' \
'<host> <resource>' \
' <project>(total)</project>' \
' <memory_mb>8192</memory_mb>' \
' <host>nova</host> <cpu>1</cpu>' \
' <disk_gb>1028</disk_gb>' \
' </resource> </host>'
cls.host_xml = ('<?xml version="1.0" encoding="UTF-8"?>'
'<host> <resource>'
' <project>(total)</project>'
' <memory_mb>8192</memory_mb>'
' <host>nova</host> <cpu>1</cpu>'
' <disk_gb>1028</disk_gb>'
' </resource> </host>')
cls.host = Host.deserialize(cls.host_xml, "xml")
@ -71,19 +71,19 @@ class HostDomainXMLTest(unittest.TestCase, HostDomainTest):
class HostDomainCollectionTest(object):
def test_hosts_length(self):
self.assertEqual(len(self.hosts), 2)
assert len(self.hosts) == 2
def test_host_names(self):
self.assertEqual(self.hosts[0].host_name, "host_name1")
self.assertEqual(self.hosts[1].host_name, "host_name2")
assert self.hosts[0].host_name == "host_name1"
assert self.hosts[1].host_name == "host_name2"
def test_host_services(self):
self.assertEqual(self.hosts[0].service, "compute1")
self.assertEqual(self.hosts[1].service, "compute2")
assert self.hosts[0].service == "compute1"
assert self.hosts[1].service == "compute2"
def test_host_zones(self):
self.assertEqual(self.hosts[0].zone, "nova1")
self.assertEqual(self.hosts[1].zone, "nova2")
assert self.hosts[0].zone == "nova1"
assert self.hosts[1].zone == "nova2"
class HostDomainCollectionJSONTest(unittest.TestCase,
@ -91,12 +91,12 @@ class HostDomainCollectionJSONTest(unittest.TestCase,
@classmethod
def setUpClass(cls):
cls.hosts_json = '{"hosts":' \
'[{"host_name":' \
' "host_name1","service": "compute1",' \
'"zone": "nova1"},' \
'{"host_name": "host_name2",' \
'"service": "compute2","zone": "nova2"}]}'
cls.hosts_json = ('{"hosts":'
'[{"host_name":'
' "host_name1","service": "compute1",'
'"zone": "nova1"},'
'{"host_name": "host_name2",'
'"service": "compute2","zone": "nova2"}]}')
cls.hosts = Host.deserialize(cls.hosts_json, "json")
@ -104,15 +104,11 @@ class HostDomainCollectionXMLTest(unittest.TestCase, HostDomainCollectionTest):
@classmethod
def setUpClass(cls):
cls.hosts_xml = '<?xml version="1.0" encoding="UTF-8"?>' \
'<hosts>' \
'<host host_name="host_name1" ' \
'service="compute1" zone="nova1"/>' \
'<host host_name="host_name2"' \
' service="compute2" zone="nova2"/>' \
'</hosts>'
cls.hosts_xml = ('<?xml version="1.0" encoding="UTF-8"?>'
'<hosts>'
'<host host_name="host_name1" '
'service="compute1" zone="nova1"/>'
'<host host_name="host_name2"'
' service="compute2" zone="nova2"/>'
'</hosts>')
cls.hosts = Host.deserialize(cls.hosts_xml, "xml")
if __name__ == '__main__':
unittest.main()

View File

@ -19,18 +19,18 @@ class HypervisorsClientMockResponse(object):
@classmethod
def list_hypervisors(cls):
return '{"hypervisors": [{' \
'"id": 1, ' \
'"hypervisor_hostname": "hypervisor_test"}' \
']}'
return ('{"hypervisors": [{'
'"id": 1, '
'"hypervisor_hostname": "hypervisor_test"}'
']}')
@classmethod
def list_hypervisor_servers(cls):
return '{"hypervisors": [{ '\
'"id": 1,' \
'"hypervisor_hostname": "hypervisor_test",' \
'"servers":' \
'[{"uuid": "b1ea4f1b-201c-47c5-95b9-c6fe2df39af0",' \
'"name": "instance-00000003"},' \
'{"uuid": "9327b134-b1f5-43ec-a8f1-2b6eb153c739",' \
'"name": "instance-00000005"}}]}]}'
return ('{"hypervisors": [{ '
'"id": 1,'
'"hypervisor_hostname": "hypervisor_test",'
'"servers":'
'[{"uuid": "b1ea4f1b-201c-47c5-95b9-c6fe2df39af0",'
'"name": "instance-00000003"},'
'{"uuid": "9327b134-b1f5-43ec-a8f1-2b6eb153c739",'
'"name": "instance-00000005"}}]}]}')

View File

@ -14,18 +14,17 @@ See the License for the specific language governing permissions and
limitations under the License.
"""
import unittest2 as unittest
import httpretty
from httpretty import HTTPretty
from cloudcafe.compute.hypervisors_api.client import HypervisorsClient
from cloudcafe.compute.tests.integration.fixtures import IntegrationTestFixture
from cloudcafe.compute.tests.integration.hypervisors.responses \
from metatests.cloudcafe.compute.fixtures import ClientTestFixture
from metatests.cloudcafe.compute.hypervisors.client.responses \
import HypervisorsClientMockResponse
HYPERVISOR_HOSTNAME = "hypervisor_test"
class HypervisorsClientTest(IntegrationTestFixture):
class HypervisorsClientTest(ClientTestFixture):
@classmethod
def setUpClass(cls):
@ -42,31 +41,24 @@ class HypervisorsClientTest(IntegrationTestFixture):
HYPERVISOR_HOSTNAME)
cls.mock_response = HypervisorsClientMockResponse()
@httpretty.activate
def test_list_hypervisors(self):
httpretty.register_uri(httpretty.GET, self.hypervisors_uri,
HTTPretty.register_uri(HTTPretty.GET, self.hypervisors_uri,
body=self.mock_response.
list_hypervisors())
response = self.hypervisor_client.list_hypervisors()
self.assertEqual(200, response.status_code)
self._assert_default_headers_in_request()
self._assert_default_headers_in_request(HTTPretty.last_request)
self.assertEqual(HypervisorsClientMockResponse.list_hypervisors(),
response.content)
@httpretty.activate
def test_list_hypervisor_servers(self):
httpretty.register_uri(httpretty.GET, self.hypervisor_servers_uri,
HTTPretty.register_uri(HTTPretty.GET, self.hypervisor_servers_uri,
body=self.mock_response.
list_hypervisor_servers())
response = self.hypervisor_client.\
list_hypervisor_servers(HYPERVISOR_HOSTNAME)
self.assertEqual(200, response.status_code)
self._assert_default_headers_in_request()
self.assertEqual(HypervisorsClientMockResponse.
list_hypervisor_servers(),
response.content)
if __name__ == '__main__':
unittest.main()
self._assert_default_headers_in_request(HTTPretty.last_request)
self.assertEqual(
HypervisorsClientMockResponse.list_hypervisor_servers(),
response.content)

View File

@ -0,0 +1,105 @@
"""
Copyright 2013 Rackspace
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.
"""
import unittest2 as unittest
from cloudcafe.compute.hypervisors_api.model.hypervisors import Hypervisor
class HypervisorDomainTest(object):
def test_hypervisor_attr(self):
self.assertEqual(self.hypervisor[0].id, "1")
self.assertEqual(self.hypervisor[0].hypervisor_hostname,
"hypervisor_test")
class HypervisorDomainJSONTest(unittest.TestCase, HypervisorDomainTest):
@classmethod
def setUp(cls):
cls.hypervisor_json = ('{"hypervisors": [{'
'"id": "1", '
'"hypervisor_hostname": "hypervisor_test"}]}')
cls.hypervisor = Hypervisor.deserialize(cls.hypervisor_json, "json")
class HypervisorDomainXMLTest(unittest.TestCase, HypervisorDomainTest):
@classmethod
def setUp(cls):
cls.hypervisor_xml = ('<?xml version="1.0" encoding="UTF-8"?>'
'<hypervisors><hypervisor id="1" '
'hypervisor_hostname="hypervisor_test"/>'
'</hypervisors>')
cls.hypervisor = Hypervisor.deserialize(cls.hypervisor_xml, "xml")
class HypervisorServerCollectionDomainTest(object):
def test_hypervisor_servers_length(self):
self.assertEqual(len(self.hypervisor.servers), 2)
def test_hypervisor_servers_attr(self):
self.assertTrue(
"server_one" in
[server.name for server in self.hypervisor.servers])
self.assertTrue(
"server_two" in
[server.name for server in self.hypervisor.servers])
self.assertTrue(
"b1ea4f1b-201c-47c5-95b9-c6fe2df39af0" in
[server.id for server in self.hypervisor.servers])
self.assertTrue(
"9327b134-b1f5-43ec-a8f1-2b6eb153c739" in
[server.id for server in self.hypervisor.servers])
class ServersDomainCollectionJSONTest(unittest.TestCase,
HypervisorServerCollectionDomainTest):
@classmethod
def setUp(cls):
cls.hypervisor_json = ('{"hypervisors": [{'
'"id": 1, '
'"hypervisor_hostname": "hypervisor_test", '
'"servers": [{'
'"uuid": '
'"b1ea4f1b-201c-47c5-95b9-c6fe2df39af0", '
'"name": "server_one"}, '
'{"uuid": '
'"9327b134-b1f5-43ec-a8f1-2b6eb153c739", '
'"name": "server_two"}]}]}')
cls.hypervisor = Hypervisor.deserialize(cls.hypervisor_json, "json")
class ServersDomainCollectionXMLTest(unittest.TestCase,
HypervisorServerCollectionDomainTest):
@classmethod
def setUp(cls):
cls.hypervisor_xml = ('<?xml version="1.0" encoding="UTF-8"?>'
'<hypervisors>'
'<hypervisor '
'id="1" '
'hypervisor_hostname="hypervisor_test">'
'<servers>'
'<server name="server_one" '
'uuid="b1ea4f1b-201c-47c5-95b9-c6fe2df39af0"/>'
'<server name="server_two" '
'uuid="9327b134-b1f5-43ec-a8f1-2b6eb153c739"/>'
'</servers></hypervisor></hypervisors>')
cls.hypervisor = Hypervisor.deserialize(cls.hypervisor_xml,
"xml")

View File

@ -14,16 +14,15 @@ See the License for the specific language governing permissions and
limitations under the License.
"""
import unittest2 as unittest
from httpretty import HTTPretty
from cloudcafe.compute.quotas_api.client import QuotasClient
from cloudcafe.compute.tests.integration.fixtures import IntegrationTestFixture
from cloudcafe.compute.tests.integration.quotas.responses\
from metatests.cloudcafe.compute.fixtures import ClientTestFixture
from metatests.cloudcafe.compute.quotas.client.responses \
import QuotasMockResponse
class QuotasClientTest(IntegrationTestFixture):
class QuotasClientTest(ClientTestFixture):
@classmethod
def setUpClass(cls):
@ -33,10 +32,11 @@ class QuotasClientTest(IntegrationTestFixture):
auth_token=cls.AUTH_TOKEN,
serialize_format=cls.FORMAT,
deserialize_format=cls.FORMAT)
cls.quotas_uri = "{0}/os-quota-sets/{1}".\
format(cls.COMPUTE_API_ENDPOINT, cls.TENANT_ID)
cls.default_quotas_uri = "{0}/os-quota-sets/{1}/defaults".\
format(cls.COMPUTE_API_ENDPOINT, cls.TENANT_ID)
cls.quotas_uri = ("{0}/os-quota-sets/{1}".
format(cls.COMPUTE_API_ENDPOINT, cls.TENANT_ID))
cls.default_quotas_uri = ("{0}/os-quota-sets/{1}/defaults".
format(cls.COMPUTE_API_ENDPOINT,
cls.TENANT_ID))
cls.mock_response = QuotasMockResponse(cls.FORMAT)
def test_get_quota(self):
@ -62,14 +62,13 @@ class QuotasClientTest(IntegrationTestFixture):
def test_update_quota(self):
HTTPretty.register_uri(HTTPretty.PUT, self.quotas_uri,
body=self.mock_response._get_quota())
actual_response = self.quotas_client.\
update_quota(self.TENANT_ID, security_groups=45)
actual_response = (self.quotas_client.
update_quota(self.TENANT_ID, security_groups=45))
expected_request_body = '{"quota_set": {"security_group_rules": 45}}'
expected_request_body = '{"quota_set": {"security_groups": 45}}'
self._assert_default_headers_in_request(HTTPretty.last_request)
self.assertEqual(200, actual_response.status_code)
self.assertEqual(HTTPretty.last_request.body,
expected_request_body)
self.assertEqual(HTTPretty.last_request.body, expected_request_body)
self.assertEqual(self.mock_response._get_quota(),
actual_response.content)
@ -78,7 +77,3 @@ class QuotasClientTest(IntegrationTestFixture):
actual_response = self.quotas_client.delete_quota(self.TENANT_ID)
self.assertEqual(202, actual_response.status_code)
if __name__ == '__main__':
unittest.main()

View File

@ -24,17 +24,14 @@ class QuotaRequestsTest(unittest.TestCase):
def test_serialize_host_update_request_to_json(self):
quota_obj = UpdateQuotaRequest(security_groups=45)
json_serialized_quota = quota_obj.serialize("json")
expected_json = '{"quota_set": {"security_group_rules": 45}}'
expected_json = '{"quota_set": {"security_groups": 45}}'
self.assertEqual(json_serialized_quota, expected_json)
def test_serialize_host_update_request_to_xml(self):
quota_obj = UpdateQuotaRequest(security_groups=45, id='fake_tenant')
xml_serialized_quota = quota_obj.serialize("xml")
expected_xml = '<?xml version=\'1.0\' encoding=\'UTF-8\'?>' \
'<quota_set id="fake_tenant">' \
'<security_group_rules>45</security_group_rules>' \
'</quota_set>'
expected_xml = ('<?xml version=\'1.0\' encoding=\'UTF-8\'?>'
'<quota_set id="fake_tenant">'
'<security_groups>45</security_groups>'
'</quota_set>')
self.assertEqual(xml_serialized_quota, expected_xml)
if __name__ == '__main__':
unittest.main()

View File

@ -19,9 +19,10 @@ import unittest2 as unittest
from cloudcafe.compute.quotas_api.models.quotas import Quota
class QuotaDomainTest(object):
class QuotaDomainTest():
def test_quota_attributes(self):
self.assertEqual(str(self.quota.cores), '20')
self.assertEqual(str(self.quota.cores), '20')
self.assertEqual(str(self.quota.floating_ips), '10')
self.assertEqual(str(self.quota.id), 'fake_tenant')
@ -40,19 +41,19 @@ class QuotaDomainJSONTest(unittest.TestCase, QuotaDomainTest):
@classmethod
def setUpClass(cls):
cls.quota_json = '{"quota_set":' \
' {"cores": 20,' \
'"floating_ips": 10,' \
'"id": "fake_tenant",' \
'"injected_file_content_bytes": 10240,' \
'"injected_file_path_bytes": 255,' \
'"injected_files": 5,' \
'"instances": 10,' \
'"key_pairs": 100,' \
'"metadata_items": 128,' \
'"ram": 51200,' \
'"security_group_rules": 20,' \
'"security_group_rules": 10}}'
cls.quota_json = ('{"quota_set":'
' {"cores": 20,'
'"floating_ips": 10,'
'"id": "fake_tenant",'
'"injected_file_content_bytes": 10240,'
'"injected_file_path_bytes": 255,'
'"injected_files": 5,'
'"instances": 10,'
'"key_pairs": 100,'
'"metadata_items": 128,'
'"ram": 51200,'
'"security_group_rules": 20,'
'"security_groups": 10}}')
cls.quota = Quota.deserialize(cls.quota_json, "json")
@ -60,23 +61,20 @@ class QuotaDomainXMLTest(unittest.TestCase, QuotaDomainTest):
@classmethod
def setUpClass(cls):
cls.quota_xml = '<?xml version="1.0" encoding="UTF-8"?>' \
'<quota_set id="fake_tenant">' \
'<cores>20</cores>' \
'<floating_ips>10</floating_ips>' \
'<injected_file_content_bytes>10240' \
'</injected_file_content_bytes>' \
'<injected_file_path_bytes>255' \
'</injected_file_path_bytes>' \
'<injected_files>5</injected_files>' \
'<instances>10</instances>' \
'<key_pairs>100</key_pairs>' \
'<metadata_items>128</metadata_items>' \
'<ram>51200</ram>' \
'<security_group_rules>20</security_group_rules>' \
'<security_group_rules>10</security_group_rules>' \
'</quota_set>'
cls.quota_xml = ('<?xml version="1.0" encoding="UTF-8"?>'
'<quota_set id="fake_tenant">'
'<cores>20</cores>'
'<floating_ips>10</floating_ips>'
'<injected_file_content_bytes>10240'
'</injected_file_content_bytes>'
'<injected_file_path_bytes>255'
'</injected_file_path_bytes>'
'<injected_files>5</injected_files>'
'<instances>10</instances>'
'<key_pairs>100</key_pairs>'
'<metadata_items>128</metadata_items>'
'<ram>51200</ram>'
'<security_group_rules>20</security_group_rules>'
'<security_groups>10</security_groups>'
'</quota_set>')
cls.quota = Quota.deserialize(cls.quota_xml, "xml")
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
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.
"""

View File

@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
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.
"""

View File

@ -0,0 +1,50 @@
"""
Copyright 2013 Rackspace
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.
"""
class SecurityGroupRulesMockResponse():
def __init__(self, format):
self.format = format
def _get_sec_group_rule(self):
return getattr(self, '_{0}_sec_group_rule'.format(self.format))()
def _json_sec_group_rule(self):
return ('{"security_group_rule":'
' {"from_port": 80,'
' "ip_protocol": "tcp",'
' "to_port": 8080,'
' "parent_group_id": 2,'
' "ip_range": {"cidr": "0.0.0.0/0"},'
' "id": 1'
' "group": {}}}')
def _xml_sec_group_rule(self):
return ('<?xml version=\'1.0\' encoding=\'UTF-8\'?>'
'<security_group_rule '
'parent_group_id=2 id=1>'
'<from_port>80</from_port>'
'<ip_protocol>tcp</ip_protocol>'
'<to_port>8080</to_port>'
'<ip_range>'
'<cidr>0.0.0.0/0</cidr>'
'</ip_range>'
'<group>'
'<name>None</name>'
'<tenant_id>None</tenant_id>'
'</group>'
'</security_group_rule>')

View File

@ -14,18 +14,17 @@ See the License for the specific language governing permissions and
limitations under the License.
"""
import unittest2 as unittest
from httpretty import HTTPretty
from cloudcafe.compute.extensions.security_groups_api.client\
import SecurityGroupRulesClient
from cloudcafe.compute.tests.integration.fixtures\
import IntegrationTestFixture
from cloudcafe.compute.tests.integration.\
security_group_rules.responses import SecurityGroupRulesMockResponse
from metatests.cloudcafe.compute.fixtures \
import ClientTestFixture
from metatests.cloudcafe.compute.security_group_rules.\
client.responses import SecurityGroupRulesMockResponse
class SecurityGroupRulesClientTest(IntegrationTestFixture):
class SecurityGroupRulesClientTest(ClientTestFixture):
@classmethod
def setUpClass(cls):
@ -58,7 +57,3 @@ class SecurityGroupRulesClientTest(IntegrationTestFixture):
self.assertEqual(HTTPretty.last_request.body, expected_request_body)
self.assertEqual(self.mock_response._get_sec_group_rule(),
actual_response.content)
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
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.
"""

View File

@ -30,14 +30,13 @@ class CreateSecurityGroupRuleRequestTest(unittest.TestCase):
group_id=1,
parent_group_id=2)
json_serialized_obj = create_sec_group_rule_obj.serialize("json")
print json_serialized_obj
expected_json = '{"security_group_rule":' \
' {"from_port": 80,' \
' "ip_protocol": "tcp",' \
' "to_port": 8080,' \
' "parent_group_id": 2,' \
' "cidr": "0.0.0.0/0",' \
' "group_id": 1}}'
expected_json = ('{"security_group_rule":'
' {"from_port": 80,'
' "ip_protocol": "tcp",'
' "to_port": 8080,'
' "parent_group_id": 2,'
' "cidr": "0.0.0.0/0",'
' "group_id": 1}}')
self.assertEqual(json_serialized_obj, expected_json)
def test_serialize_host_update_request_to_xml(self):
@ -48,16 +47,13 @@ class CreateSecurityGroupRuleRequestTest(unittest.TestCase):
group_id=1,
parent_group_id=2)
xml_serialized_obj = create_sec_group_rule_obj.serialize("xml")
expected_xml = '<?xml version=\'1.0\' encoding=\'UTF-8\'?>' \
'<security_group_rule>' \
'<from_port>80</from_port>' \
'<ip_protocol>tcp</ip_protocol>' \
'<to_port>8080</to_port>' \
'<parent_group_id>2</parent_group_id>' \
'<cidr>0.0.0.0/0</cidr>' \
'<group_id>1</group_id>' \
'</security_group_rule>'
expected_xml = ('<?xml version=\'1.0\' encoding=\'UTF-8\'?>'
'<security_group_rule>'
'<from_port>80</from_port>'
'<ip_protocol>tcp</ip_protocol>'
'<to_port>8080</to_port>'
'<parent_group_id>2</parent_group_id>'
'<cidr>0.0.0.0/0</cidr>'
'<group_id>1</group_id>'
'</security_group_rule>')
self.assertEqual(xml_serialized_obj, expected_xml)
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1,80 @@
"""
Copyright 2013 Rackspace
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.
"""
import unittest2 as unittest
from cloudcafe.compute.extensions.security_groups_api.models.\
security_group_rule import SecurityGroupRule
class SecurityGroupRuleDomainTest(object):
def test_security_group_rule_attributes(self):
self.assertEqual(str(self.sec_group_rule.from_port), '80')
self.assertEqual(str(self.sec_group_rule.to_port), '8080')
self.assertEqual(self.sec_group_rule.ip_protocol, 'tcp')
self.assertEqual(self.sec_group_rule.id,
'bf57c853-cdf2-4c99-9f9a-79b3e9dc13a8')
self.assertEqual(self.sec_group_rule.parent_group_id,
'b32c047d-5efc-42ab-8476-3ac9f3681af2')
self.assertEqual(self.sec_group_rule.ip_range.cidr, '0.0.0.0/0')
class SecurityGroupRuleDomainJSONTest(unittest.TestCase,
SecurityGroupRuleDomainTest):
@classmethod
def setUpClass(cls):
cls.sec_group_rule_json = ('{"security_group_rule":'
' {"from_port": 80,'
'"group": {},'
'"ip_protocol": "tcp",'
'"to_port": 8080,'
'"parent_group_id":'
' "b32c047d-5efc-42ab-8476-3ac9f3681af2",'
'"ip_range": {"cidr": "0.0.0.0/0"},'
'"id":'
' "bf57c853-cdf2-4c99-9f9a-79b3e9dc13a8"}}')
cls.sec_group_rule = (SecurityGroupRule.
deserialize(cls.sec_group_rule_json, "json"))
class SecurityGroupRuleDomainXMLTest(unittest.TestCase,
SecurityGroupRuleDomainTest):
@classmethod
def setUpClass(cls):
cls.sec_group_rule_xml = ('<?xml version="1.0" encoding="UTF-8"?>'
'<security_group_rule'
' xmlns='
'"http://docs.openstack.org/'
'compute/api/v1.1"'
' parent_group_id='
'"b32c047d-5efc-42ab-8476-3ac9f3681af2"'
' id="bf57c853-cdf2-4c99-9f9a-79b3e9dc13a8">'
'<ip_protocol>tcp</ip_protocol>'
'<from_port>80</from_port>'
'<to_port>8080</to_port>'
'<group>'
'<name>None</name>'
'<tenant_id>None</tenant_id>'
'</group>'
'<ip_range>'
'<cidr>0.0.0.0/0</cidr>'
'</ip_range>'
'</security_group_rule>')
cls.sec_group_rule = (SecurityGroupRule.
deserialize(cls.sec_group_rule_xml, "xml"))

View File

@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
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.
"""

View File

@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
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.
"""

View File

@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
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.
"""

View File

@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
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.
"""